celebrations
This commit is contained in:
@@ -260,6 +260,38 @@ class SoundEngine {
|
||||
osc.stop(now + delay + 0.36);
|
||||
});
|
||||
}
|
||||
|
||||
// Triumphant fanfare for a perfect board: rising arpeggio, big chord, sparkles
|
||||
playPerfect() {
|
||||
if (this.muted) return;
|
||||
this.initContext();
|
||||
if (!this.ctx) return;
|
||||
|
||||
const now = this.ctx.currentTime;
|
||||
const tone = (freq, start, dur, type = 'triangle', vol = 0.12) => {
|
||||
const osc = this.ctx.createOscillator();
|
||||
const gain = this.ctx.createGain();
|
||||
osc.type = type;
|
||||
osc.frequency.setValueAtTime(freq, now + start);
|
||||
gain.gain.setValueAtTime(0.0001, now + start);
|
||||
gain.gain.exponentialRampToValueAtTime(vol, now + start + 0.02);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + start + dur);
|
||||
osc.connect(gain);
|
||||
gain.connect(this.ctx.destination);
|
||||
osc.start(now + start);
|
||||
osc.stop(now + start + dur + 0.05);
|
||||
};
|
||||
|
||||
// C major arpeggio climbing two octaves
|
||||
[523.25, 659.25, 783.99, 1046.5, 1318.51, 1567.98].forEach((f, i) => tone(f, i * 0.09, 0.3));
|
||||
|
||||
// Sustained final chord (C - E - G - C)
|
||||
[523.25, 659.25, 783.99, 1046.5].forEach(f => tone(f, 0.6, 1.6, 'triangle', 0.1));
|
||||
tone(261.63, 0.6, 1.6, 'sine', 0.12);
|
||||
|
||||
// High sparkle shimmer
|
||||
[2093, 2637, 3136, 2637, 3520, 4186].forEach((f, i) => tone(f, 0.75 + i * 0.11, 0.25, 'sine', 0.04));
|
||||
}
|
||||
}
|
||||
|
||||
export const sound = new SoundEngine();
|
||||
|
||||
Reference in New Issue
Block a user