55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
export const pling = () => {
|
|
const maxGain = 0.4;
|
|
const duration = 0.22;
|
|
const fadeDuration = 0.1;
|
|
const secondBeepOffset = fadeDuration;
|
|
|
|
const ctx = new AudioContext();
|
|
|
|
const firstBeepGain = ctx.createGain();
|
|
firstBeepGain.connect(ctx.destination);
|
|
firstBeepGain.gain.setValueAtTime(0.01, ctx.currentTime);
|
|
firstBeepGain.gain.exponentialRampToValueAtTime(
|
|
maxGain,
|
|
ctx.currentTime + fadeDuration
|
|
);
|
|
firstBeepGain.gain.setValueAtTime(
|
|
maxGain,
|
|
ctx.currentTime + (duration - fadeDuration)
|
|
);
|
|
firstBeepGain.gain.exponentialRampToValueAtTime(
|
|
0.01,
|
|
ctx.currentTime + duration
|
|
);
|
|
|
|
const firstBeep = ctx.createOscillator();
|
|
firstBeep.connect(firstBeepGain);
|
|
firstBeep.frequency.value = 400;
|
|
firstBeep.type = "sine";
|
|
|
|
const secondBeepGain = ctx.createGain();
|
|
secondBeepGain.connect(ctx.destination);
|
|
secondBeepGain.gain.setValueAtTime(0.01, ctx.currentTime + secondBeepOffset);
|
|
secondBeepGain.gain.exponentialRampToValueAtTime(
|
|
maxGain,
|
|
ctx.currentTime + secondBeepOffset + fadeDuration
|
|
);
|
|
secondBeepGain.gain.setValueAtTime(
|
|
maxGain,
|
|
ctx.currentTime + secondBeepOffset + (duration - fadeDuration)
|
|
);
|
|
secondBeepGain.gain.exponentialRampToValueAtTime(
|
|
0.01,
|
|
ctx.currentTime + secondBeepOffset + duration
|
|
);
|
|
|
|
const secondBeep = ctx.createOscillator();
|
|
secondBeep.connect(secondBeepGain);
|
|
secondBeep.frequency.value = 600;
|
|
secondBeep.type = "sine";
|
|
|
|
firstBeep.start(ctx.currentTime);
|
|
firstBeep.stop(ctx.currentTime + duration);
|
|
secondBeep.start(ctx.currentTime + secondBeepOffset);
|
|
secondBeep.stop(ctx.currentTime + (secondBeepOffset + duration));
|
|
};
|