Adding a LowPassFilter to PWMOscillator in AudioKit v5

I am playing around with AKv5, and I am trying to add a LowPassFilter after an PWMOscillator, using the PWMOscillator recipe in the cookbook as a base.

[PWMOscillator] -> [LowPassFilter] -> Out

It seems like it should be pretty straight forward, and I have added the code below to the basic PWMOscillator Cookbook recipe. But the LowPassFilters doesn't seem to have any effect, like it is being bypassed.

I have compared this with the LowPassFilter Recipe in the cookbook, and there does not seem to be anything I am missing compared to that example.

So I am hoping people have and idea why I cannot hear the LowPassFilter do anything?

Am I missing something super obvious?

Thanks in Advance.

struct PWMOscillatorData { var isPlaying: Bool = false /// Pulse Width ranges from 0.001 to .5 (Default: .5) var pulseWidth: AUValue = 0.5 /// Frequency (Hz) ranges from 10 to 22050 (Default: 6900) var frequency: AUValue = 440 /// Amplitude ranges from 0 to 1 var amplitude: AUValue = 0.1 /// Ramp Duration ranges from 0 to ? Seconds var rampDuration: AUValue = 1 /// Cutoff Frequency (Hz) ranges from 10 to 22050 (Default: 6900) var cutoff: AUValue = 20 /// Resonance (dB) ranges from -20 to 40 (Default: 0) var resonance: AUValue = 0
}
class PWMOscillatorConductor: ObservableObject, KeyboardDelegate {
... let engine = AudioEngine() var osc: PWMOscillator var lpFilter: LowPassFilter
... @Published var data = PWMOscillatorData() { didSet { if data.isPlaying { osc.start() osc.$pulseWidth.ramp(to: data.pulseWidth, duration: data.rampDuration) osc.$frequency.ramp(to: data.frequency, duration: data.rampDuration) osc.$amplitude.ramp(to: data.amplitude, duration: 0.01) } else { osc.amplitude = 0.0 } lpFilter.$cutoffFrequency.ramp(to: data.cutoff, duration: 0.01) lpFilter.$resonance.ramp(to: data.resonance, duration: 0.01) } }
... init() { osc = PWMOscillator() lpFilter = LowPassFilter(osc) engine.output = lpFilter }
... ParameterSlider(text: "Cutoff", parameter: self.$pwmConductor.data.cutoff, range: 10...11500).padding(5) ParameterSlider(text: "Resonance", parameter: self.$pwmConductor.data.resonance, range: -20...40 ).padding(5)

Test

1 Answer

Seems like the LowPassFilter wasn't too happy with the Binded Variables.

I had to change the var = data as such.

@Published var data = PWMOscillatorData() { didSet { if data.isPlaying { osc.start() osc.$pulseWidth.ramp(to: data.pulseWidth, duration: data.rampDuration) osc.$frequency.ramp(to: data.frequency, duration: data.rampDuration) osc.$amplitude.ramp(to: data.amplitude, duration: 0.01) } else { osc.amplitude = 0.0 } lpFilter.cutoffFrequency = data.cutoff lpFilter.resonance = data.resonance }
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like