Затухание звука с использованием exponentialRampToValueAtTime в Chrome или Firefox ненадежно.Javascript

Форум по Javascript
Anonymous
Затухание звука с использованием exponentialRampToValueAtTime в Chrome или Firefox ненадежно.

Сообщение Anonymous »

Следующий код соответствует документации MDN, но приводит к резкому отключению звука вместо двухсекундного затухания:

< 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

Вернуться в «Javascript»