class AudioStream::Fx::BandPassFilter
Public Class Methods
create(soundinfo, freq:, bandwidth: 1.0)
click to toggle source
@param soundinfo [AudioStream::SoundInfo] @param freq [Float] Center frequency @param bandwidth [Float] bandwidth (octave)
# File lib/audio_stream/fx/band_pass_filter.rb, line 25 def self.create(soundinfo, freq:, bandwidth: 1.0) filter = new(soundinfo) filter.update_coef(freq: freq, bandwidth: bandwidth) filter end
Public Instance Methods
update_coef(freq:, bandwidth:)
click to toggle source
# File lib/audio_stream/fx/band_pass_filter.rb, line 5 def update_coef(freq:, bandwidth:) omega = 2.0 * Math::PI * freq / @samplerate 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