Class: AudioStream::Fx::LowShelfFilter

Inherits:
BiquadFilter show all
Defined in:
lib/audio_stream/fx/low_shelf_filter.rb

Constant Summary

Constants inherited from BiquadFilter

BiquadFilter::DEFAULT_Q

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BiquadFilter

#initialize, #plot, #plot_data, #process

Constructor Details

This class inherits a constructor from AudioStream::Fx::BiquadFilter

Class Method Details

.create(soundinfo, freq:, q: DEFAULT_Q, gain: 1.0) ⇒ Object

Parameters:



31
32
33
34
35
36
# File 'lib/audio_stream/fx/low_shelf_filter.rb', line 31

def self.create(soundinfo, freq:, q: DEFAULT_Q, gain: 1.0)
  filter = new(soundinfo)
  filter.update_coef(freq: freq, q: q, gain: gain)

  filter
end

Instance Method Details

#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
# File 'lib/audio_stream/fx/low_shelf_filter.rb', line 5

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

  omega = freq.sample_phase(@soundinfo)
  alpha = Math.sin(omega) / (2.0 * q)
  a = Decibel.db(gain.db / 2.0).mag
  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