Method: AudioStream::Fx::LowShelfFilter#update_coef

Defined in:
lib/audio_stream/fx/low_shelf_filter.rb

#update_coef(freq:, q:, gain:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/audio_stream/fx/low_shelf_filter.rb', line 5

def update_coef(freq:, q:, gain:)
  if Decibel===gain
    gain = gain.db
  end

  omega = 2.0 * Math::PI * freq / @samplerate
  alpha = Math.sin(omega) / (2.0 * q)
  a = 10.0 ** (gain / 40.0)
  beta = Math.sqrt(a) / q

  a0 = (a+1) + (a-1) * Math.cos(omega) + beta * Math.sin(omega)
  a1 = -2.0 * ((a-1) + (a+1) * Math.cos(omega))
  a2 = (a+1) + (a-1) * Math.cos(omega) - beta * Math.sin(omega)
  b0 = a * ((a+1) - (a-1) * Math.cos(omega) + beta * Math.sin(omega))
  b1 = 2.0 * a * ((a-1) - (a+1) * Math.cos(omega))
  b2 = a * ((a+1) - (a-1) * Math.cos(omega) - beta * Math.sin(omega))

  @coef = Vdsp::Biquad::Coefficient.new(b0/a0, b1/a0, b2/a0, a1/a0, a2/a0)
  @biquads.each {|biquad|
    biquad.coefficients = @coef
  }
end