const glitchySynth = synth.def((phase, env, tick) => { return (Math.sin(phase * Math.PI * 3) + Math.random() * 0.5) * Math.exp(-tick * 0.001) * env.value; }, { attack: 0.01, release: 0.05, env: adsr2 }); const noisySynth = synth.def((phase, env, tick) => { return (Math.random() - 0.5) * Math.exp(-tick * 0.1) * env.value; }, { attack: 0.005, release: 0.05, env: adsr2 }); const lowFreq = [60, 65, 70, 75, 80]; const highFreq = [2000, 2200, 2400, 2600, 2800]; function randomSequence() { const freq = Math.random() > 0.5 ? lowFreq : highFreq; const note = freq[Math.floor(Math.random() * freq.length)]; return note; } loop(() => { ditty.bpm = lerp(40, 180, Math.random()); for (let i = 0; i < 50; i++) { glitchySynth.play(randomSequence(), { amp: Math.random() * 2, pan: Math.random() * 2 - 1 }); sleep(60 / ditty.bpm * Math.random() * 0.5); } for (let i = 0; i < 30; i++) { noisySynth.play(randomSequence(), { amp: Math.random() * 0.5, pan: Math.random() * 2 - 1 }); sleep(60 / ditty.bpm * 0.2); } for (let i = 0; i < 40; i++) { glitchySynth.play(randomSequence(), { amp: Math.random() * 4, pan: Math.random() * 2 - 1 }); sleep(60 / ditty.bpm * 0.1); } for (let i = 0; i < 20; i++) { glitchySynth.play(randomSequence(), { amp: Math.random() * 3, pan: Math.random() * 2 - 1 }); noisySynth.play(randomSequence(), { amp: Math.random() * 1.5, pan: Math.random() * 2 - 1 }); sleep(60 / ditty.bpm * 0.15); } for (let i = 0; i < 10; i++) { glitchySynth.play(randomSequence(), { amp: Math.random() * 6, pan: Math.random() * 2 - 1 }); noisySynth.play(randomSequence(), { amp: Math.random() * 2, pan: Math.random() * 2 - 1 }); sleep(60 / ditty.bpm * Math.random() * 0.2); } });