增益节点通过 HTML 输入类型“范围”连接到 UI slider 。当我拖动时它成功地改变了音量,但无论我如何设置步长,当我拖动 slider 时我都会听到噪音。
HTML 看起来像这样:
<input id="slider6Volume" type="range" min="0.0008" max="1.0008" step="0.0001" value="0.0008" oninput="changeGain(this.value)"/>
.js 是这样的:
function changeGain(newValue) {
document.getElementById('slider6Volume').addEventListener('input', function() {
gainNode6.gain.setValueAtTime(newValue, audioCtx.currentTime);
console.log ("Channel 6: ", this.value);
}, "false");
我从不太小的浮点值开始,但这导致增益值之间出现可听见的阶梯声。听起来它的增益更新有冲突,但我连接的控制台转储看起来没问题。稳定不间断的有序流中的浮点值。我错过了什么?
最佳答案
不要使用 setValueAtTime - 使用 setTargetAtTime,并使用较小的 timeConstant 值(例如,尝试以 0.01 作为起点)。这将解压设置。
关于javascript - 当我拖动连接到 Web Audio API 增益节点的 slider 时,它会弹出并单击。拖动时音量没有平滑变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35353974/