Class: AudioStream::Fx::Tremolo
- Inherits:
-
Object
- Object
- AudioStream::Fx::Tremolo
- Defined in:
- lib/audio_stream/fx/tremolo.rb
Instance Method Summary collapse
-
#initialize(soundinfo, freq:, depth:) ⇒ Tremolo
constructor
A new instance of Tremolo.
- #process(input) ⇒ Object
Constructor Details
#initialize(soundinfo, freq:, depth:) ⇒ Tremolo
Returns a new instance of Tremolo.
4 5 6 7 8 9 |
# File 'lib/audio_stream/fx/tremolo.rb', line 4 def initialize(soundinfo, freq:, depth:) @samplerate = soundinfo.samplerate @freq = freq.to_f @depth = depth.to_f @phase = 0 end |
Instance Method Details
#process(input) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/audio_stream/fx/tremolo.rb', line 11 def process(input) window_size = input.window_size period = 2 * Math::PI * @freq / @samplerate streams = input.streams.map {|stream| stream.map.with_index {|f, i| f * (1.0 + @depth * Math.sin((i + @phase) * period)) } } @phase = (@phase + window_size) % (window_size / period) Buffer.new(*streams) end |