Class: AudioStream::Fx::PeakingFilter
- Inherits:
-
BiquadFilter
- Object
- BiquadFilter
- AudioStream::Fx::PeakingFilter
- Defined in:
- lib/audio_stream/fx/peaking_filter.rb
Constant Summary
Constants inherited from BiquadFilter
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:, bandwidth: 1.0, gain: 40.0) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/audio_stream/fx/peaking_filter.rb', line 30 def self.create(soundinfo, freq:, bandwidth: 1.0, gain: 40.0) filter = new(soundinfo) filter.update_coef(freq: freq, bandwidth: bandwidth, gain: gain) filter end |
Instance Method Details
#update_coef(freq:, bandwidth:, gain:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/audio_stream/fx/peaking_filter.rb', line 5 def update_coef(freq:, bandwidth:, gain:) freq = Rate.freq(freq) gain = Decibel.db(gain) omega = freq.sample_phase(@soundinfo) alpha = Math.sin(omega) * Math.sinh(Math.log(2.0) / 2.0 * bandwidth * omega / Math.sin(omega)) a = Decibel.db(gain.db / 2.0).mag a0 = 1.0 + alpha / a a1 = -2.0 * Math.cos(omega) a2 = 1.0 - alpha / a b0 = 1.0 + alpha * a b1 = -2.0 * Math.cos(omega) b2 = 1.0 - alpha * a @coef = Vdsp::Biquad::Coefficient.new(b0/a0, b1/a0, b2/a0, a1/a0, a2/a0) @biquads.each {|biquad| biquad.coefficients = @coef } end |