Class: AudioStream::Fx::Phaser

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

Instance Method Summary collapse

Constructor Details

#initialize(soundinfo, rate:, depth:, freq:, dry: -6.0,, wet: -6.0)) ⇒ Phaser

Returns a new instance of Phaser.

Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/audio_stream/fx/phaser.rb', line 11

def initialize(soundinfo, rate:, depth:, freq:, dry: -6.0, wet: -6.0)
  @soundinfo = soundinfo

  @filters = [
    AllPassFilter.new(soundinfo),
    AllPassFilter.new(soundinfo),
  ]

  rate = Rate.sec(rate)
  @speed = rate.frame_phase(soundinfo)
  @phase = 0

  @depth = depth
  @freq = freq

  @dry = Decibel.db(dry).mag
  @wet = Decibel.db(wet).mag
end

Instance Method Details

#process(input) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/audio_stream/fx/phaser.rb', line 30

def process(input)
  window_size = input.window_size
  @phase = (@phase + @speed) % (2.0 * Math::PI)

  a = Math.sin(@phase) * 0.5 + 0.5
  apf_freq = Rate.freq(@freq * (1.0 + a * @depth))

  wet = input
  @filters.each {|filter|
    filter.update_coef(freq: apf_freq, q: BiquadFilter::DEFAULT_Q)
    wet = filter.process(wet)
  }

  streams = wet.streams.map.with_index {|wet_stream, i|
    dry_stream = input.streams[i]
    dry_stream * @dry + wet_stream * @wet
  }

  Buffer.new(*streams)
end