Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 Web音频API:用于实现任意数量源的平移的布局_Javascript_Audio_Web_Web Audio Api - Fatal编程技术网

Javascript Web音频API:用于实现任意数量源的平移的布局

Javascript Web音频API:用于实现任意数量源的平移的布局,javascript,audio,web,web-audio-api,Javascript,Audio,Web,Web Audio Api,我试图实现用户控制的任意数量的同时网络音频源的平移。源本身是单声道的。我正在使用Javascript和web音频API() 目前,我遇到的问题是,我试图使用多通道输出(每个源一个),但通道解释覆盖了我的平移尝试(请参阅),这使我认为我在架构上做了一些错误的事情 我想把事情放在一个概念层面上,因为我相信这就是我的问题所在 当前设置 我的方法是让一个节点处理每个源的所有处理,这里称为“scriptNode”。创建的通道数量等于音频源的数量,同样创建的平移节点数量也相同。图表如下所示: The bun

我试图实现用户控制的任意数量的同时网络音频源的平移。源本身是单声道的。我正在使用Javascript和web音频API()

目前,我遇到的问题是,我试图使用多通道输出(每个源一个),但通道解释覆盖了我的平移尝试(请参阅),这使我认为我在架构上做了一些错误的事情

我想把事情放在一个概念层面上,因为我相信这就是我的问题所在

当前设置

我的方法是让一个节点处理每个源的所有处理,这里称为“scriptNode”。创建的通道数量等于音频源的数量,同样创建的平移节点数量也相同。图表如下所示:

The bundle size (the '=' segments) is the number of channels, set to be equal to the number of sources.

scriptNode == splitter =+-- panner1 --+= merger == destination
                        \-- panner. --/
                        \-- panner. --/
                        \-- pannerN --/
一些杂项,我调用此函数来设置scriptNode:

scriptNode = firstPart.audioCtx.createScriptProcessor(2048, 0, numParts);
其中numParts是源的数量。我还将scriptNode的channelCountMode设置为“显式”,将ChannelTranslation设置为“演讲者”。这些设置中的一个最终可能很重要,但我在尝试摆弄这些设置时找不到任何东西

问题

当我实际使用这个架构测试代码时,我将根据我选择的部分数量得到以下行为。平移滑块与每个源的平移器节点的“平移”值相关联

  • numParts=1:Mono输出,使用滑块平移只会影响输出的音量(向中间偏大)。我想这是从调音台降混音到单声道的副产品
  • numParts=2:立体声输出,一个硬左,一个硬右。用滑块平移两个通道没有任何作用
  • numParts=3:与=2相同,但第三个通道是静默的
  • numParts=4:类似于=2,现在所有通道都重新工作,它们按L/R/L/R顺序进行了严格平移。再次使用滑块平移不会产生任何效果
这种行为似乎符合ChannelExplation的描述,但我想要的是对每个源分别进行平移,而不管我使用了多少个通道。我仍然希望使用通道,因为我的每个源都希望写入单声道缓冲区

是否有一个架构上的调整,我可以保持这种多渠道战略,并实现我所期待的

代码片段

当前代码的相关部分基于我上面的陈述,并试图解决这个问题。 编辑:由于下面的评论,我设法找到了问题。我调用了单行修复程序,以便以后可以将此代码用作参考

音频处理功能。只有第一个synth(源)设置此回调:

function customAudioProcessCallback( audioProcessingEvent )
{
    // First synth - process audio for all synths!

    const outputBuffer = audioProcessingEvent.outputBuffer;

    for ( var i = 0; i < numParts; i++ ) {

    // Each part writes to one channel.

    synthParts[ i ].synthesize(outputBuffer.getChannelData( i ), outputBuffer.length);

    }
}
函数customAudioProcessCallback(audioProcessingEvent)
{
//第一个合成器-处理所有合成器的音频!
const outputBuffer=audioProcessingEvent.outputBuffer;
对于(变量i=0;i
播放函数的相关片段:

function play()
{
    const contextClass = (window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext || window.msAudioContext);
    synthParts[ 0 ].audioCtx = new contextClass();

    synthParts[ 0 ].scriptNode = synthParts[ 0 ].audioCtx.createScriptProcessor ? synthParts[ 0 ].audioCtx.createScriptProcessor(2048, 0, numParts+1) : synthParts[ 0 ].audioCtx.createJavaScriptNode(2048, 0, numParts+1); // 2048, 0 input channels, ? outputs
    synthParts[ 0 ].scriptNode.onaudioprocess = customAudioProcessCallback;
    synthParts[ 0 ].scriptNode.channelCountMode = 'explicit';
    synthParts[ 0 ].scriptNode.channelInterpretation = 'speakers';

    // Set up splitter and panners for all channels
    var splitter = synthParts[ 0 ].audioCtx.createChannelSplitter( numParts+1 );

    for ( var i = 0; i < numParts; i++ ) {

        panList[ i ] = synthParts[ 0 ].audioCtx.createStereoPanner();
        panList[ i ].pan = panValues[ i ];

    }

    // Connection:
    // scriptNode -- splitter -+-- panner1 --+- destination
    //                         \-- panner. --/
    //                         \-- pannerN --/

    synthParts[ 0 ].scriptNode.connect(splitter);

    for ( var i = 0; i < numParts; i++ ) {

        splitter.connect( panList[ i ], i);

        // This line used to read: 
        //    panList[ i ].connect( synthParts[ 0 ].audioCtx.destination, 0, i );
        // However, this was connecting multiple parts to the input of the audio context destination, which is limited to 1 input. The correct call is below.
        panList[ i ].connect( synthParts[ 0 ].audioCtx.destination );

    }
}
函数播放()
{
const contextClass=(window.AudioContext | | window.webkitadiocontext | | window.mozadiocontext | | window.oAudioContext | window.msAudioContext);
synthParts[0]。audioCtx=新上下文类();
synthParts[0]。scriptNode=synthParts[0]。audioCtx.createScriptProcessor?synthParts[0]。audioCtx.createScriptProcessor(2048,0,numParts+1):synthParts[0]。audioCtx.createJavaScriptNode(2048,0,numParts+1);//2048,0个输入通道,输出
synthParts[0].scriptNode.onaudioprocess=customAudioProcessCallback;
synthParts[0].scriptNode.channelCountMode='explicit';
synthParts[0].scriptNode.ChannelExpression='speakers';
//为所有通道设置拆分器和平移器
var splitter=synthParts[0].audioCtx.createChannelSplitter(numParts+1);
对于(变量i=0;i
A
PannerNode
总是产生立体声输出。当您将平移器输出连接到合并的一个输入时,平移器的立体声输出将向下混合为单声道,从而有效地消除了大部分平移效果


有些信息缺失,但我不明白你为什么需要合并。您可以将每个窗格的立体声输出直接发送到目标。目标将适当地混合来自每个平移器的立体声输出,从而保留平移效果。

我尝试了此方法,但在尝试连接平移器时出错。似乎这个问题以前就被发现过:(甚至是你,我刚刚注意到!)。在那个例子中,我的建议是像我现在这样使用合并,但我愿意接受一些建议,在不合并的情况下避免这个错误,以避免单声道下混音问题。与链接问题相同,即“Uncaught IndexSizeError:未能在“AudioNode”上执行“connect”:输入索引(1)超过输入数(1)。”尝试时会看到此消息