0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ are you maybe resetting time when you change the modulator frequency? $\endgroup$ – Marcus Müller Mar 2 at 18:33
  • $\begingroup$ No, but thanks. The above code is just a very simple example, in case I'm doing something stupid in the modulation part and to simplify giving an answer I can understand easily. In the real code, time is only set to 0.0 once when the VST is initiated, and is incremented properly. $\endgroup$ – J.F. Mar 2 at 19:22
  • $\begingroup$ I don't know VST at all, but can you get a recording out of it to analyze what exactly causes the clicks or pops? $\endgroup$ – Marcus Müller Mar 2 at 20:17
0
$\begingroup$

If you change modulator frequency, do note that it changes a sudden jump in phase, as it changes the result of the equation where the phase is calculated from frequency. This is largely unnecessary, as having a certain frequency means the phase change is constant per sample. Thus, if you change the frequency to be a phase increment per sample, then changing the frequency does not cause a sudden phase jump but just changes the phase increment from that point on. That's how FM synth chips work.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.