I'm very new to DSP and working on a FM VST. It's mostly up and running, or at least it generates FM-like sounds. I want to be able to change various parameters dynamically while audio is generated, such as the modulation index, for automations and later for LFOs.
I had a problem with clicks and pops when changing values, and solved it by interpolating the values over a small number of samples. However, this doesn't seem to work when dynamically changing the frequency of the modulator. It just causes strange frequencies during the transition, which is not what I want.
I'm speculating that maybe I could introduce the new frequency immediately just when the carrier has completed a sine cycle, and implemented that, but that doesn't remove the clicks (which might be because of some bug in my code, or because this is the wrong approach completely.)
As you might have noticed, I'm mostly unaware of the mathematics involved.
A very simplified version of my (Rust) code, which should however show the basic method I'm using, is:
let mut time = 0.0; // EDIT: is not reset with each buffer loop
let time_per_sample = 1.0 / 44100.0;
let carrier_frequency = 440.0;
let modulator_frequency = 880.0;
let beta = 2.0;
for sample in buffer.iter_mut(){
*sample = (
(carrier_frequency * time * 2 * PI) +
beta * (modulator_frequency * time * 2 * PI).sin()
).sin();
time += time_per_sample;
}
I'm currently not scaling beta with modulator frequency, if that matters.
In FM synthesis, how do I change the modulator frequency while a sound is playing without clicks or pops?
time
when you change the modulator frequency? $\endgroup$ – Marcus Müller Mar 2 '19 at 18:33