菜鸟教程小白 发表于 2022-12-11 20:24:34

iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph


                                            <p><p>我正在尝试将 kAudioUnitSubType 添加到 iOS 5 中的 AUGraph,但是当我添加它并调用 AUGraphInitialize 时,会返回错误代码 -10868 (kAudioUnitErr_FormatNotSupported)。</p>

<p>这是我的 AudioComponentDescription:</p>

<pre><code>AudioComponentDescription varispeedDescription;
varispeedDescription.componentType = kAudioUnitType_FormatConverter;
varispeedDescription.componentSubType = kAudioUnitSubType_Varispeed;
varispeedDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
varispeedDescription.componentFlags = 0;
varispeedDescription.componentFlagsMask = 0;
</code></pre>

<p>如果我在初始化图表之前打印图表的状态,我会得到以下信息:</p>

<pre><code>AudioUnitGraph 0x918000:
    Member Nodes:
    node 1: &#39;auou&#39; &#39;rioc&#39; &#39;appl&#39;, instance 0x16dba0 O
    node 2: &#39;aumx&#39; &#39;mcmx&#39; &#39;appl&#39;, instance 0x1926f0 O
    node 3: &#39;aufc&#39; &#39;vari&#39; &#39;appl&#39;, instance 0x193b00 O
    Connections:
    node   2 bus   0 =&gt; node   3 bus   0[ 2 ch,44100 Hz, &#39;lpcm&#39; (0x00000C2C)   8.24-bit little-endian signed integer, deinterleaved]
    node   3 bus   0 =&gt; node   1 bus   0[ 2 ch,      0 Hz, &#39;lpcm&#39; (0x00000029) 32-bit little-endian float, deinterleaved]
    Input Callbacks:
    {0x39a5, 0x172e24} =&gt; node   2 bus   0
    {0x39a5, 0x172e24} =&gt; node   2 bus   1
CurrentState:
    mLastUpdateError=0, eventsToProcess=F, isRunning=F
</code></pre>

<p>正如您所见,从变速单元到远程 IO 单元的连接显示出一种非常奇怪的格式。更奇怪的是,如果我在模拟器上而不是在我的开发设备上运行它,则显示的格式是 16 位小端整数,去交错。如果我尝试在 Varispeed 单元的输入或输出范围上设置流格式,我会得到相同的错误代码 -10868。</p>

<p>我在输入范围的每个多 channel 混音器总线上设置为流格式的 asbd 如下:</p>

<pre><code>stereoFormat.mSampleRate = sampleRate;
stereoFormat.mFormatID = kAudioFormatLinearPCM;
stereoFormat.mFormatFlags = kAudioFormatFlagsCanonical;
stereoFormat.mFramesPerPacket = 1;
stereoFormat.mChannelsPerFrame = 2;
stereoFormat.mBitsPerChannel = 16;
stereoFormat.mBytesPerPacket = 4;
stereoFormat.mBytesPerFrame = 4;
</code></pre>

<p>我没有对音频单元使用规范格式的原因是因为我正在从 AVAssetReader 读取样本,我无法将其配置为输出 8.24 Signed Integer 样本。</p>

<p>如果我从图表中取出 Varispeed 单元并将多 channel 混音器单元连接到远程 IO 单元的输入,则图表会初始化并正常播放。知道我做错了什么吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您的 io 单元要求 32 位 float 并从变速单元接收 8.24,因此出现格式错误。</p>

<p>您可以在 varispeed 的输出上设置流格式以匹配 io 单元的输入格式,如下所示:</p>

<pre><code>AudioStreamBasicDescription asbd;
UInt32 asbdSize = sizeof (asbd);
memset (&amp;asbd, 0, sizeof (asbd));

AudioUnitGetProperty(ioaudiounit , kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &amp;asbd, &amp;asbdSize);

AudioUnitSetProperty(varipseedaudiounit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &amp;asbd, sizeof(asbd));
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7905889/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7905889/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph