Quantcast
Channel: KVR Audio
Viewing all articles
Browse latest Browse all 5134

DSP and Plugin Development • Frequency Modulation (FM) - How to use Modulation Index in my implementation

$
0
0
I'm working on a VST3 synthesizer. It has 8 Tone Generator Modules selectable from any of 10 engines, 8 Envelope Modules appliable to virtually all voice parameters, 8 Effect Module slots, 8 LFO Modules appliable to virtually all voice parameters, and many processor parameters, plus finally 8 Filter Modules each appliable to one or more tone generators. Each tone generator can be set to octave, semitone, or fine +/- pitch offset from norm as in middle A = 440Hz.

I have designed my synth so one sample is first gathered for each active tone generators. After that I apply modulation selectable by user, AM, RM, FM, PD, or PM.

Depended on the order you arrange carrier tone generator and modulation tone generator, a modulation tone generator can itself be modulation from another tone generator.

Anyways my implementation below, simplified to better illustrate my post question, works fine, however I don't know how, if even possible to fit in the Modulation Index.

As I understand it the modulation index is max carrier frequency deviation / modulator frequency, and the max carrier frequency deviation is carrier frequency * modulation level.

My tone generators, no matter what engine used, supply samples in the range of -1.0f to 1.0f.

Code:

// FM Implementationfloat modulator = sampleValue[modSource];// I am below adding 1.0f to change the modulator * modLevel from -1 to 1, into 0 - 2.0// modLevel is in the range of 0 (no modulation), to 1 (max modulation)modulator = 1.0f + modulator * modLevel;// The modulator is now multiplied with the carrier tone generator's Delta, which is reset // to proper relation between note frequency, table size, and sample rate, before // the modulation code partdelta[carrier] *= modulator;// The above modified delta is then added to the carrier tone generator's phase variablephase[carrier] += delta[carrier];// Modulator tone generator's phase is also updatedphase [modSource] += delta[modSource];// And yes I check and adjust all tone generator's phase as needed when they go beyond // max phase, which for any engine is 2047, omitted here for simplicity
So if for example the both the carrier and modulator's octave, semitone, and fine controls are set to '0', and I play a middle 'A', the frequency of both are 440Hz.

The max carrier frequency deviation would then be 440Hz * 2 (Multiply by 2 because a modulator sample is in the range from -1.0f to 1.0f, and I then add 1.0f later to adjust to 0.0f to 2.0f) * modLevel right?

If the above is correct, the Modulation Index would then be above result / modulation frequency (In this case 440Hz) right?

So if I calculated the Modulation Index right, how can I incorporate that into my above algorithm? Any advice, except to format my hard drive, is much appreciated, thanks!

Statistics: Posted by DKDiveDude — Thu Feb 22, 2024 7:04 pm — Replies 0 — Views 28



Viewing all articles
Browse latest Browse all 5134

Trending Articles