class SynthBlocks::Core::StateVariableFilter
Simple State Variable filter
source: www.musicdsp.org/en/latest/Filters/23-state-variable.html More info: www.earlevel.com/main/2003/03/02/the-digital-state-variable-filter/
Public Class Methods
new(sfreq)
click to toggle source
Create new filter instance
# File lib/synth_blocks/core/state_variable_filter.rb, line 11 def initialize(sfreq) @sampling_frequency = sfreq.to_f @delay_1 = 0.0 @delay_2 = 0.0 end
Public Instance Methods
run(input, frequency, q, type: :lowpass)
click to toggle source
run the filter from input value
- frequency
-
cutoff freq in Hz
- q
-
resonance, from 0 to …
- type
-
can be :lowpass, :highpass, :bandpass and :notch
# File lib/synth_blocks/core/state_variable_filter.rb, line 21 def run(input, frequency, q, type: :lowpass) # derived parameters q1 = 1.0 / q.to_f f1 = 2.0 * Math::PI * frequency.to_f / @sampling_frequency # calculate filters lowpass = @delay_2 + f1 * @delay_1 highpass = input - lowpass - q1 * @delay_1 bandpass = f1 * highpass + @delay_1 notch = highpass + lowpass # store delays @delay_1 = bandpass @delay_2 = lowpass results = { lowpass: lowpass, highpass: highpass, bandpass: bandpass, notch: notch } results[type] end