Skip to content

Commit 9ca9a1b

Browse files
committed
fix: soften Force Surge soundtrack peaks
1 parent c36dd6c commit 9ca9a1b

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎src/assets/js/script.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,12 @@ function playForceSoundtrack(duration = 8000) {
471471
initAudio();
472472
if (!audioCtx) return;
473473

474-
// 1. Create a Master Compressor to prevent distortion
474+
// Catch peaks without flattening the whole soundtrack.
475475
const compressor = audioCtx.createDynamicsCompressor();
476-
compressor.threshold.setValueAtTime(-24, audioCtx.currentTime);
477-
compressor.knee.setValueAtTime(40, audioCtx.currentTime);
478-
compressor.ratio.setValueAtTime(12, audioCtx.currentTime);
479-
compressor.attack.setValueAtTime(0, audioCtx.currentTime);
476+
compressor.threshold.setValueAtTime(-12, audioCtx.currentTime);
477+
compressor.knee.setValueAtTime(12, audioCtx.currentTime);
478+
compressor.ratio.setValueAtTime(3, audioCtx.currentTime);
479+
compressor.attack.setValueAtTime(0.01, audioCtx.currentTime);
480480
compressor.release.setValueAtTime(0.25, audioCtx.currentTime);
481481
compressor.connect(audioCtx.destination);
482482

@@ -486,14 +486,15 @@ function playForceSoundtrack(duration = 8000) {
486486

487487
// Smooth volume swell
488488
masterGain.gain.setValueAtTime(0, now);
489-
masterGain.gain.linearRampToValueAtTime(0.6, now + 1.5);
490-
masterGain.gain.setValueAtTime(0.6, now + duration / 1000 - 2);
489+
// Three oscillators can add together; keep the sum below full scale.
490+
masterGain.gain.linearRampToValueAtTime(0.15, now + 1.5);
491+
masterGain.gain.setValueAtTime(0.15, now + duration / 1000 - 2);
491492
masterGain.gain.exponentialRampToValueAtTime(0.001, now + duration / 1000);
492493

493494
// Create the "Harmonic Stack" (Multiple notes for a rich sound)
494495
[55, 110, 164.81].forEach((freq, i) => {
495496
const osc = audioCtx.createOscillator();
496-
osc.type = i === 0 ? "sawtooth" : "triangle"; // Mix textures
497+
osc.type = i === 0 ? "sine" : "triangle"; // Keep the bass warm, without sawtooth buzz.
497498
osc.frequency.setValueAtTime(freq, now);
498499

499500
// Add a slight "wobble" (detune) for realism

0 commit comments

Comments
 (0)