Class: SynthBlocks::Core::StateVariableFilter
- Inherits:
-
Object
- Object
- SynthBlocks::Core::StateVariableFilter
- Defined in:
- lib/synth_blocks/core/state_variable_filter.rb
Overview
Simple State Variable filter
source: http://www.musicdsp.org/en/latest/Filters/23-state-variable.html More info: https://www.earlevel.com/main/2003/03/02/the-digital-state-variable-filter/
Instance Method Summary collapse
-
#initialize(sfreq) ⇒ StateVariableFilter
constructor
Create new filter instance.
-
#run(input, frequency, q, type: :lowpass) ⇒ Object
run the filter from input value [frequency] cutoff freq in Hz [q] resonance, from 0 to ...
Constructor Details
#initialize(sfreq) ⇒ StateVariableFilter
Create new filter instance
11 12 13 14 15 |
# 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 |
Instance Method Details
#run(input, frequency, q, type: :lowpass) ⇒ Object
run the filter from input value [frequency] cutoff freq in Hz [q] resonance, from 0 to ... [type] can be :lowpass, :highpass, :bandpass and :notch
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |