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: 0.25) ⇒ Chorus
constructor
A new instance of Chorus.
- #lerp(start, stop, step) ⇒ Object
- #process(input) ⇒ Object
Constructor Details
#initialize(soundinfo, depth: 100, rate: 0.25) ⇒ Chorus
Returns a new instance of Chorus.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/audio_stream/fx/chorus.rb', line 4 def initialize(soundinfo, depth: 100, rate: 0.25) @soundinfo = soundinfo @depth = depth @rate = rate @delaybufs = [ RingBuffer.new(@depth * 3, 0.0), RingBuffer.new(@depth * 3, 0.0) ] @phase = 0 @speed = (2.0 * Math::PI * @rate) / @soundinfo.samplerate end |
Instance Method Details
#lerp(start, stop, step) ⇒ Object
46 47 48 |
# File 'lib/audio_stream/fx/chorus.rb', line 46 def lerp(start, stop, step) (stop * step) + (start * (1.0 - step)) end |
#process(input) ⇒ Object
19 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 |
# File 'lib/audio_stream/fx/chorus.rb', line 19 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 |