Class: AudioStream::Fx::Chorus
- Inherits:
-
Object
- Object
- AudioStream::Fx::Chorus
- Defined in:
- lib/audio_stream/fx/chorus.rb
Instance Method Summary collapse
-
#initialize(soundinfo, depth: 100, rate: 4) ⇒ Chorus
constructor
A new instance of Chorus.
- #lerp(start, stop, step) ⇒ Object
- #process(input) ⇒ Object
Constructor Details
#initialize(soundinfo, depth: 100, rate: 4) ⇒ Chorus
Returns a new instance of Chorus.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/audio_stream/fx/chorus.rb', line 7 def initialize(soundinfo, depth: 100, rate: 4) @depth = depth @rate = Rate.sec(rate) @delaybufs = [ RingBuffer.new(@depth * 3, 0.0), RingBuffer.new(@depth * 3, 0.0) ] @phase = 0 @speed = @rate.sample_phase(soundinfo) end |
Instance Method Details
#lerp(start, stop, step) ⇒ Object
47 48 49 |
# File 'lib/audio_stream/fx/chorus.rb', line 47 def lerp(start, stop, step) (stop * step) + (start * (1.0 - step)) end |
#process(input) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/audio_stream/fx/chorus.rb', line 20 def process(input) window_size = input.window_size channels = input.channels streams = channels.times.map {|ch| delaybuf = @delaybufs[ch] input.streams[ch].map.with_index {|f, i| tau = @depth * (Math.sin(@speed * (@phase + i)) + 1) t = i - tau m = t.floor delta = t - m wet = delta * delaybuf[i-m+1] + (1.0 - delta) * delaybuf[i-m] f = (f + wet) * 0.5 delaybuf.current = f delaybuf.rotate f } } @phase = (@phase + window_size) % (window_size / @speed) Buffer.new(*streams) end |