Change timbre of shepard tone: overtones are now nearly harmonic

This commit is contained in:
yaw-man 2022-09-14 19:05:04 -04:00
parent a629a65194
commit 18acf9eb95
1 changed files with 11 additions and 11 deletions

View File

@ -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<double>(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);
}