Build 29079087

This commit is contained in:
Renan LE CARO 2025-04-15 21:28:00 +02:00
parent 06843047d2
commit 8e4e67e33b
17 changed files with 199 additions and 234 deletions

View file

@ -33,7 +33,7 @@ export const sounds = {
plouf: (volume: number, pan: number) => {
if (!isOptionOn("sound")) return;
createSingleBounceSound(500, pan, volume*0.5);
createSingleBounceSound(500, pan, volume * 0.5);
// createWaterDropSound(800, pan, volume*0.2, 0.2,'triangle')
},
@ -277,44 +277,3 @@ function createOscillator(
oscillator.frequency.setValueAtTime(frequency, context.currentTime);
return oscillator;
}
// TODO
function createWaterDropSound(
baseFreq = 500,
pan = 0.5,
volume = 1,
duration = 0.6,
type: OscillatorType = "sine"
) {
const context = getAudioContext();
if (!context) return;
const oscillator = createOscillator(context, baseFreq, type);
const gainNode = context.createGain();
const panner = context.createStereoPanner();
// Connect nodes
oscillator.connect(gainNode);
gainNode.connect(panner);
panner.connect(context.destination);
panner.connect(audioRecordingTrack);
// Panning
panner.pan.setValueAtTime(pan * 2 - 1, context.currentTime);
const now = context.currentTime;
// Volume envelope: soft plop -> fade out
gainNode.gain.setValueAtTime(0.0001, now);
gainNode.gain.exponentialRampToValueAtTime(0.7 * volume, now + duration/100); // Quick swell
gainNode.gain.exponentialRampToValueAtTime(0.1, now + duration/3); // Fade out
gainNode.gain.exponentialRampToValueAtTime(0.001, now + duration); // Fade out
// Pitch envelope: slight downward pitch bend to simulate water tension
oscillator.frequency.setValueAtTime(baseFreq, now);
oscillator.frequency.exponentialRampToValueAtTime(baseFreq * 0.5, now + duration);
// Start and stop
oscillator.start(now);
oscillator.stop(now + duration);
}