网络音频的数学相关 Javascript API
Math related Javascript for Web Audio API
我无法解决这个与数学相关的问题。
我正在为项目使用 jogDial.js 插件。
有了它,我正在尝试模拟一个控制网络音频增益节点的音量旋钮 api。
插件可以return刻度盘的度数是这样的:
console.log("event.target.degree: "+event.target.degree);
//between +220 and +140
也可以return这样旋转:
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%,或 0.50 值 gainNode.gain.
当拨盘在+140度时,音量应该是100%,或者网络增益值1音频 api.
我无法找出适用于我的 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
我什至不确定你从哪里得到那个乘数。
我无法解决这个与数学相关的问题。
我正在为项目使用 jogDial.js 插件。
有了它,我正在尝试模拟一个控制网络音频增益节点的音量旋钮 api。
插件可以return刻度盘的度数是这样的:
console.log("event.target.degree: "+event.target.degree);
//between +220 and +140
也可以return这样旋转:
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%,或 0.50 值 gainNode.gain.
当拨盘在+140度时,音量应该是100%,或者网络增益值1音频 api.
我无法找出适用于我的 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
我什至不确定你从哪里得到那个乘数。