【发布时间】:2015-03-13 06:58:03
【问题描述】:
我无法解决这个与数学相关的问题。
我正在为一个项目使用jogDial.js 插件。
有了它,我正在尝试模拟一个控制网络音频 api 的 gainNode 的音量刻度盘。
插件可以用这个返回表盘的度数:
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):
我的 GainNode 限制是 0 和 1,其中 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。
【问题讨论】: