Class: AudioStream::Fx::Tremolo

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_stream/fx/tremolo.rb

Instance Method Summary collapse

Constructor Details

#initialize(soundinfo, freq:, depth:) ⇒ Tremolo

Returns a new instance of Tremolo.

Parameters:



7
8
9
10
11
12
# File 'lib/audio_stream/fx/tremolo.rb', line 7

def initialize(soundinfo, freq:, depth:)
  @freq = Rate.freq(freq)
  @depth = depth.to_f
  @phase = 0
  @period = @freq.sample_phase(soundinfo)
end

Instance Method Details

#process(input) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/audio_stream/fx/tremolo.rb', line 14

def process(input)
  window_size = input.window_size

  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