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: Select all
// FM Implementation
float 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 part
delta[carrier] *= modulator;
// The above modified delta is then added to the carrier tone generator's phase variable
phase[carrier] += delta[carrier];
// Modulator tone generator's phase is also updated
phase [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
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!