Skip to content
Snippets Groups Projects
Commit 059d3f70 authored by Eric Rosenbaum's avatar Eric Rosenbaum
Browse files

Use a waveshaper to hard limit samples

parent 26ca5da7
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,16 @@ class VolumeEffect {
this.gain.gain.setValueAtTime(volume, endSeconds);
this.gain.gain.exponentialRampToValueAtTime(1.0, endSeconds + this.rampLength);
// Use a waveshaper node to prevent sample values from exceeding -1 or 1.
// Without this, gain can cause samples to exceed this range, then they
// are clipped on save, and the sound is distorted on load.
this.waveShaper = this.audioContext.createWaveShaper();
this.waveShaper.curve = new Float32Array([-1, 1]);
this.waveShaper.oversample = 'none';
this.input.connect(this.gain);
this.gain.connect(this.output);
this.gain.connect(this.waveShaper);
this.waveShaper.connect(this.output);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment