static inline void calc_freqmod(uint8_t chn) /* Calculates frequency change for SQ1, SQ2 and TRI based on detuning, LFOs and envelope modulation. */ { int16_t sum = 0; for (uint8_t j = 0; j < 3; j++) { if (mod_lfo_modmatrix[chn][j] > 0) sum += mod_lfo_modmatrix[chn][j] * lfo[j].value; } if (chn <= CHN_TRI) { int16_t dc = get_coarse_tune(chn); dc += get_pitchbend(chn); dc += sum / 128; // Add detune frequency delta dc += mod_detune[chn]; // Add envelope modulation, if set dc += (int16_t)4 * mod_envmod[chn] * env[chn].value; // Store total dc value, which will be applied by apply_freqmod dc_temp[chn] = dc; } else if (chn == CHN_NOISE) { noise_period += (env[2].value * (-mod_envmod[chn])) / 8; } }
static inline void calc_freqmod(uint8_t chn) /* Calculates frequency change for SQ1, SQ2 and TRI based on detuning, LFOs and envelope modulation. */ { // Define some helper arrays static const LFO* lfos[] = {&lfo1, &lfo2, &lfo3}; int16_t sum = 0; for (uint8_t j = 0; j < 3; j++) { if (mod_lfo_modmatrix[chn][j] > 0) sum += mod_lfo_modmatrix[chn][j] * lfos[j]->value; } if (chn <= CHN_TRI) { int16_t dc = get_coarse_tune(chn); dc += get_pitchbend(chn); dc += sum / 128; // Add detune frequency delta dc += get_detune(chn); // For square channels, also add in the envelope modulation, if any int8_t env_fmod_val = (int8_t)envelopes[chn]->value - (int8_t)envelopes[chn]->sustain; if (env_fmod_val > 0) dc += env_fmod_val * get_envmod(chn); // Store total dc value, which will be applied by apply_freqmod dc_temp[chn] = dc; } }