< div class="snippet-code">
Код: Выделить всё
const audioContext = new window.AudioContext();
let oscillator;
let gainNode;
document.getElementById("playSweep").addEventListener("click", () => {
oscillator = audioContext.createOscillator();
oscillator.type = "sine"; // Sine wave
oscillator.frequency = 200;
gainNode = audioContext.createGain();
gainNode.gain.setValueAtTime(1, audioContext.currentTime);
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.start();
});
document.getElementById("fadeOut").addEventListener("click", () => {
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 2);
});Код: Выделить всё
Play Frequency Sweep
Fade OutКак правильно выполнить затухание в JS Web Audio API?
Подробнее здесь: https://stackoverflow.com/questions/793 ... is-not-rel