Форум по 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);
});
Как правильно выполнить затухание в JS Web Audio API?
Подробнее здесь:
https://stackoverflow.com/questions/793 ... is-not-rel
1736806415
Anonymous
Следующий код соответствует документации MDN, но приводит к резкому отключению звука вместо двухсекундного затухания:
< div class="snippet-code">
[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);
});[/code]
[code]Play Frequency Sweep
Fade Out[/code]
[b]Как правильно выполнить затухание в JS Web Audio API? [/b]
Подробнее здесь: [url]https://stackoverflow.com/questions/79353552/audio-fadeout-using-exponentialramptovalueattime-in-chrome-or-firefox-is-not-rel[/url]