diff --git a/src/yaw-shepard/synth.cpp b/src/yaw-shepard/synth.cpp index cbb5f5e..1dbeff3 100644 --- a/src/yaw-shepard/synth.cpp +++ b/src/yaw-shepard/synth.cpp @@ -40,13 +40,13 @@ void Synth::process(float* output, const uint32_t frames) phase += hz * sampleInterval; phase = frac(phase); - //Don't bother rendering anything over the Nyquist rate. + //Anti-aliasing: don't bother rendering anything over the Nyquist rate. if( hz > hzNyq ) break; - output[i] += getAmplitude(hz) * (phase > 0.5); // * sin(2.0 * M_PI * phase); + output[i] += getAmplitude(hz) * sin(2.0 * M_PI * phase); //Remember phase, move to higher overtone. phases[(voice + idxFund) & VOICE_MASK] = phase; - hz *= ratio; + hz *= ratio * (voice + 1.0) / (voice + 2.0); } output[i] *= volume / static_cast(NUM_VOICES); @@ -60,8 +60,8 @@ void Synth::process(float* output, const uint32_t frames) && getAmplitude(hzFund) < MIN_VOLUME) { ++idxFund; - hz *= ratio; - hzFund *= ratio; + hz *= 2.0 * ratio; + hzFund *= 2.0 * ratio; } } @@ -72,8 +72,8 @@ void Synth::process(float* output, const uint32_t frames) && getAmplitude(hzFund) > MIN_VOLUME) { --idxFund; - hz /= ratio; - hzFund /= ratio; + hz /= 2.0 * ratio; + hzFund /= 2.0 * ratio; } } } @@ -93,10 +93,10 @@ void Synth::setFrequencyShift(double in){ } static constexpr double minRatio = 1.0; -static constexpr double maxRatio = 3.0; -//Slew to given ratio. -//0 : next voice is one fifth above previous voice. -//1 : next voice is one octave above previous voice. +static constexpr double maxRatio = 1.05; +//Slew to given inharmonicity ratio. +//0 : next voice is exactly harmonic. +//1 : next voice is 5% inharmonic. void Synth::setTargetRatio(double in){ targetRatio = minRatio + in * (maxRatio - minRatio); }