more engines

This commit is contained in:
2025-10-12 11:04:54 +02:00
parent 94a36b1a29
commit 7b99dc0f0d
4371 changed files with 2187 additions and 92 deletions

View File

@ -189,6 +189,23 @@ export class FourOpFM implements SynthEngine<FourOpFMParams> {
lfoPhaseR += (TAU * params.lfo.rate) / sampleRate;
}
// Peak normalization with headroom
let peakL = 0;
let peakR = 0;
for (let i = 0; i < numSamples; i++) {
peakL = Math.max(peakL, Math.abs(leftBuffer[i]));
peakR = Math.max(peakR, Math.abs(rightBuffer[i]));
}
const peak = Math.max(peakL, peakR);
if (peak > 0.001) {
const normalizeGain = 0.85 / peak;
for (let i = 0; i < numSamples; i++) {
leftBuffer[i] *= normalizeGain;
rightBuffer[i] *= normalizeGain;
}
}
return [leftBuffer, rightBuffer];
}