gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:20:16 25 4
gpt4 key购买 nike

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

我正在使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com