javascript - 用于 Web 音频 API 的数学相关 Javascript

标签 javascript web-audio-api

我无法解决这个与数学相关的问题。

我正在使用jogDial.js项目的插件。

用它,我试图模拟一个控制网络音频 api 的增益节点的音量旋钮。

插件可以通过以下方式返回表盘的度数:

console.log("event.target.degree: "+event.target.degree); 
//between +220 and +140 

它还可以通过以下方式返回旋转:

console.log("event.target.rotation: "+ event.target.rotation);
//between -140 and +140

我发现旋转更容易使用。

模拟 Harman/Karmon 接收器的真实现有表盘,下限为 -140 旋转,中间为 0,上限为旋转140

这是表盘的实际图像,以便您直观地了解(忽略图像中的数字 0 和 40):

enter image description here

我的 GainNode 限制为 01,其中 1 表示 100% 音量,0 表示静音。

-140 度时,音量应该为 0%。网络音频 api GainNode.gain.value 将为 0

当表盘位于0 度时,即为中间点。音量应为 50%,或 GainNode.gain 的 0.50 值。

当旋钮位于 +140 度时,音量应为 100%,或者网络音频 API 的增益值为 1

我无法找出适用于我的 on("mousemove", function(event){});

的公式

我尝试过这个:

var volumeDial = JogDial(document.getElementById('volume-knob'), {
    debug: true,
    wheelSize: '90%',
    zIndex: '100',
    touchMode: 'wheel',
    knobSize: '3%',
    minDegree: -140,
    maxDegree: 140,
    degreeStartAt: 0
}).on("mousemove", function(event){
    var volume = event.target.rotation;
    console.log("event.target.rotation: "+ event.target.rotation);
    console.log("event.target.degree: "+event.target.degree);
    var theGain;
    theGain = Math.abs(50-(volume*0.3575)-100) *0.01;
    gainNode.gain.value = theGain;
console.log("gainNode.gain.value: "+gainNode.gain.value);
    source.connect(gainNode);
}).on("mouseup", function(event){
    console.log("event.target.rotation: "+event.target.rotation);
    console.log("event.target.degree: "+event.target.degree);
});

问题是它不准确。很接近,但没有达到预期的效果。 0%时仍有声音,0%到100%听上去没有太大区别。

在 0% 时,我的增益值为“0.0005000000237487257”。声音一点也不安静,相当响亮。

在 50% 时,我的增益值为 0.5,这是正确的。

在 100% 时,我的增益值为 1.000499963760376。

最佳答案

你真正需要的是

(event.target.rotation + 140) / 280

我什至不确定你从哪里得到这个乘数。

关于javascript - 用于 Web 音频 API 的数学相关 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29021851/

相关文章:

javascript - Javascript 只匹配一个 URL

javascript - 错误: Connection lost: The server closed the connection. mysql Node

streaming - 通过客户端 XHR 打开 Soundcloud Track 的 stream_url?

javascript - 从浏览器访问麦克风 - Javascript

javascript - 对跨多行的数据应用正则表达式 - "gm"标志不起作用

javascript - CKEDITOR 图像插件可以绕过 'Send to the Server' 按钮功能吗?

javascript - 如何使用 Web Audio API 移动/调制音频缓冲频率

javascript - 取消音频淡出然后淡入 - Web Audio API

javascript - Yesod 和 Coffeescript

javascript - 为什么AudioBufferNode中的stop方法会破坏它?