Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ConstantSourceNode设置的振荡器频率错误_Javascript_Audio_Web Audio Api - Fatal编程技术网

Javascript ConstantSourceNode设置的振荡器频率错误

Javascript ConstantSourceNode设置的振荡器频率错误,javascript,audio,web-audio-api,Javascript,Audio,Web Audio Api,我正在创建一个包含三个振荡器的synth voice,正如您在下面的代码片段中看到的 const ctx=newaudiocontext(); const osc1=ctx.create振荡器(); osc1.type=“锯齿”; osc1.start(); const osc2=ctx.create振荡器(); osc2.type=“锯齿”; osc2.失谐设定值时间(1200,ctx.currentTime); osc2.start(); const osc3=ctx.create振荡器(

我正在创建一个包含三个振荡器的synth voice,正如您在下面的代码片段中看到的

const ctx=newaudiocontext();
const osc1=ctx.create振荡器();
osc1.type=“锯齿”;
osc1.start();
const osc2=ctx.create振荡器();
osc2.type=“锯齿”;
osc2.失谐设定值时间(1200,ctx.currentTime);
osc2.start();
const osc3=ctx.create振荡器();
osc3.type=“锯齿”;
osc3.失谐设定值时间(1900,ctx.currentTime);
osc3.start();
常量增益=ctx.createGain();
增益.增益.值=0.2;
增益连接(ctx目的地);
osc1.连接(增益);
osc2.连接(增益);
osc3.连接(增益);
osc1.frequency.value=160;
osc2.frequency.value=160;

osc3.frequency.value=160振荡器节点频率的默认值为440,但您正在将默认偏移设置为160。

振荡器节点频率的默认值为440,但是您将默认偏移设置为160。

我认为问题在于,当您将AudioNode连接到AudioParam时,AudioNode的输出信号与AudioParam的固有值混合

在您的特定示例中,这意味着实际频率将为600。振荡器的默认频率为440。这与来自ConstantSourceNode的值混合在一起

440 + 160 === 600
为了达到您想要的结果,您可以将每个振荡器的值设置为零

osc1.frequency.setValueAtTime(0, ctx.currentTime);
osc2.frequency.setValueAtTime(0, ctx.currentTime);
osc3.frequency.setValueAtTime(0, ctx.currentTime);

这里有一个指向规范中描述此行为的部分的链接:

我认为问题在于,当您将AudioNode连接到AudioParam时,AudioNode的输出信号与AudioParam的固有值混合

在您的特定示例中,这意味着实际频率将为600。振荡器的默认频率为440。这与来自ConstantSourceNode的值混合在一起

440 + 160 === 600
为了达到您想要的结果,您可以将每个振荡器的值设置为零

osc1.frequency.setValueAtTime(0, ctx.currentTime);
osc2.frequency.setValueAtTime(0, ctx.currentTime);
osc3.frequency.setValueAtTime(0, ctx.currentTime);
以下是一个指向规范中描述此行为的部分的链接: