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