Fix clicky distortion - proper gain staging and reduced saturation

- Reduced channel gains: pulse 0.12, wave 0.18, noise 0.08
- Total max gain now ~1.0 instead of 2.7 (was clipping)
- More aggressive limiter: -12dB threshold, ratio 20
- Reduced saturation from 0.2-0.3 to 0.08-0.1 in all presets
- Should eliminate clicky distortion during playback
This commit is contained in:
b1rdmania
2026-01-20 19:55:03 +00:00
parent 9311e82538
commit dd4e1cfebd
2 changed files with 19 additions and 15 deletions
+10 -6
View File
@@ -97,33 +97,37 @@ export class GameBoyAPU {
/**
* Initialize all 8 channels with their gain nodes.
*
* Gain staging: Keep total under 1.0 to avoid clipping
* With 8 channels potentially active: each should be ~0.1-0.15
*/
private initializeChannels(): void {
// Create pulse channels
// Create pulse channels (4 × 0.12 = 0.48 max)
for (const config of CHANNEL_CONFIG.pulse) {
const gain = this.createChannelGain(config.id, 0.25);
const gain = this.createChannelGain(config.id, 0.12);
const channel = new PulseChannel(this.audioContext, gain, config.hasSweep);
channel.setDutyCycle(config.defaultDuty);
this.pulseChannels.set(config.id, channel);
this.initChannelState(config.id);
}
// Create wave channels (higher gain for bass)
// Create wave channels - slightly higher for bass presence (2 × 0.18 = 0.36 max)
for (const config of CHANNEL_CONFIG.wave) {
const gain = this.createChannelGain(config.id, 0.55); // Boosted for bass
const gain = this.createChannelGain(config.id, 0.18);
const channel = new WaveChannel(this.audioContext, gain, config.preset);
this.waveChannels.set(config.id, channel);
this.initChannelState(config.id);
}
// Create noise channels
// Create noise channels (2 × 0.08 = 0.16 max)
for (const config of CHANNEL_CONFIG.noise) {
const gain = this.createChannelGain(config.id, 0.3);
const gain = this.createChannelGain(config.id, 0.08);
const channel = new NoiseChannel(this.audioContext, gain, config.mode);
this.noiseChannels.set(config.id, channel);
this.initChannelState(config.id);
}
}
// Total max: 0.48 + 0.36 + 0.16 = 1.0
/**
* Create a gain node for a channel and connect to master.