Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 42 additions & 27 deletions src/assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ window.playSound = function playSound(type) {
osc.start(now);
osc.stop(now + 1.5);
} else {
const config = LAYERED_SOUND_CONFIGS[type];
const config = LAYERED_SOUND_CONFIGS[type];
if (!config) return;

osc.type = config.oscillatorType;
Expand Down Expand Up @@ -482,50 +482,65 @@ function updateThemeIcon(theme) {
/**
* 5. EASTER EGG LOGIC & TRIGGERS
*/
function playForceSoundtrack(duration = 8000) {
window.playForceSoundtrack = function (duration = 8000) {
initAudio();
if (!audioCtx) return;

// 1. Create a Master Compressor to prevent distortion
const now = audioCtx.currentTime;
const seconds = duration / 1000;

// Master compressor: gentle settings to avoid pumping/crackle
const compressor = audioCtx.createDynamicsCompressor();
compressor.threshold.setValueAtTime(-24, audioCtx.currentTime);
compressor.knee.setValueAtTime(40, audioCtx.currentTime);
compressor.ratio.setValueAtTime(12, audioCtx.currentTime);
compressor.attack.setValueAtTime(0, audioCtx.currentTime);
compressor.release.setValueAtTime(0.25, audioCtx.currentTime);
compressor.threshold.setValueAtTime(-24, now);
compressor.knee.setValueAtTime(30, now);
compressor.ratio.setValueAtTime(4, now);
compressor.attack.setValueAtTime(0.01, now);
compressor.release.setValueAtTime(0.25, now);
compressor.connect(audioCtx.destination);

const now = audioCtx.currentTime;
const masterGain = audioCtx.createGain();
masterGain.connect(compressor);
// Lowpass filter: removes harsh high frequencies
const filter = audioCtx.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.setValueAtTime(800, now);
filter.connect(compressor);

// Smooth volume swell
masterGain.gain.setValueAtTime(0, now);
masterGain.gain.linearRampToValueAtTime(0.6, now + 1.5);
masterGain.gain.setValueAtTime(0.6, now + duration / 1000 - 2);
masterGain.gain.exponentialRampToValueAtTime(0.001, now + duration / 1000);
// Master volume: smooth swell in and fade out
const masterGain = audioCtx.createGain();
masterGain.connect(filter);
masterGain.gain.setValueAtTime(0.0001, now);
masterGain.gain.linearRampToValueAtTime(0.25, now + 1.5);
masterGain.gain.setValueAtTime(0.25, now + seconds - 2);
masterGain.gain.exponentialRampToValueAtTime(0.001, now + seconds);

// Harmonic stack: each oscillator has its own small gain so the sum never clips
const layers = [
{ freq: 55, type: "triangle", level: 0.5 },
{ freq: 110, type: "triangle", level: 0.3 },
{ freq: 164.81, type: "sine", level: 0.3 },
];

// Create the "Harmonic Stack" (Multiple notes for a rich sound)
[55, 110, 164.81].forEach((freq, i) => {
layers.forEach(({ freq, type, level }, i) => {
const osc = audioCtx.createOscillator();
osc.type = i === 0 ? "sawtooth" : "triangle"; // Mix textures
osc.frequency.setValueAtTime(freq, now);
const oscGain = audioCtx.createGain();

// Add a slight "wobble" (detune) for realism
osc.detune.setValueAtTime(i * 5, now);
osc.type = type;
osc.frequency.setValueAtTime(freq, now);
osc.detune.setValueAtTime(i * 5, now); // slight wobble
oscGain.gain.setValueAtTime(level, now);

osc.connect(masterGain);
osc.connect(oscGain);
oscGain.connect(masterGain);
osc.start(now);
osc.stop(now + duration / 1000);
osc.stop(now + seconds);
});
}

function triggerForceSurge() {
window.triggerForceSurge = function () {
if (isSurging) return;
isSurging = true;

// 1. Audio
playForceSoundtrack(8000);
window.playForceSoundtrack(8000);

// 2. Add Overlay
const overlay = document.createElement("div");
Expand Down Expand Up @@ -1397,7 +1412,7 @@ function handleFooterDotClick() {
// 3. Update the global unlockedEggs array
if (!unlockedEggs.includes("secret_footer_surge")) {
// Trigger the main function
triggerForceSurge();
window.triggerForceSurge();

unlockedEggs.push("secret_footer_surge");
localStorage.setItem("unlockedEggs", JSON.stringify(unlockedEggs));
Expand Down