ios - 无法在格式转换器音频单元上设置格式
<p><p>我正在尝试设置一个非常简单的 AU 图形 - 只是一个 RemoteIO 附加到它的变速以用于输出。不幸的是,我似乎无法在变速单元上设置音频格式。我见过的其他例子似乎只是设置格式没有问题。我得到的确切错误是不支持的格式。但是,RemoteIO 单元内的格式转换器会很高兴地采用我的格式,这是一种非常简单的 16khz mono 16bit signed int PCM 格式。</p>
<p>这是我目前正在尝试制作的代码:</p>
<pre><code> // Describe the output unit.
AudioComponentDescription inputDescription = {0};
inputDescription.componentType = kAudioUnitType_Output;
inputDescription.componentSubType = kAudioUnitSubType_RemoteIO;
inputDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
AUNode ioNode;
CheckError(self, AUGraphAddNode(_graph, &inputDescription, &ioNode), "Couldn't add ioNode to AU graph");
AudioComponentDescription varispeedDescription = {0};
varispeedDescription.componentType = kAudioUnitType_FormatConverter;
varispeedDescription.componentSubType = kAudioUnitSubType_Varispeed;
varispeedDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
AUNode varispeedNode;
CheckError(self, AUGraphAddNode(_graph, &varispeedDescription, &varispeedNode), "Couldn't add varispeed node to AU graph");
CheckError(self, AUGraphOpen(_graph), "Couldn't open AU graph");
AudioUnit varispeedUnit;
CheckError(self, AUGraphNodeInfo(_graph, varispeedNode, NULL, &varispeedUnit), "Couldn't get varispeed audio unit");
CheckError(self, AUGraphNodeInfo(_graph, ioNode, NULL, &_ioUnit), "Couldn't get io unit");
// Enable input
// TODO: Conditionally disable input if option has not been specified
UInt32 one = 1;
CheckError(self, AudioUnitSetProperty(_ioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&one,
sizeof(one)), "Couldn't enable IO on the input scope of output unit");
// TODO: check this works on iOS!
_format.mBitsPerChannel = 16;
_format.mBytesPerFrame = 2;
_format.mBytesPerPacket = 2;
_format.mChannelsPerFrame = 1;
_format.mFramesPerPacket = 1;
_format.mReserved = 0;
_format.mSampleRate = 16000.0;
_format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
_format.mFormatID = kAudioFormatLinearPCM;
self.samplingRate = _format.mSampleRate;
UInt32 size;
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(_ioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
kInputBus,
&_format,
size),
"Couldn't set the ASBD on the audio unit (after setting its sampling rate)");
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(varispeedUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
0,
&_format,
size),
"Couldn't set the ASBD on the audio unit (after setting its sampling rate)");
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(varispeedUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&_format,
size),
"Couldn't set the ASBD on the audio unit (after setting its sampling rate)");
</code></pre>
<p>我也尝试过简单地设置 RemoteIO 输出总线的输入格式,这对于转换器的输出格式效果很好,但它仍然不接受我的格式作为转换器的输入格式。</p>
<p>如何将变速和 RemoteIO 与我想要的格式联系起来?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我在一个旧邮件列表中发现 Varispeed 单元仅是 float ,实际上并不进行格式转换,尽管主要类型是 FormatConverter。解决方案是使用具有专用转换器子类型的另一个转换器将我自己的格式转换为 Varispeed 想要的 FP 格式。 Varispeed 的格式限制实际上并没有据我所知在任何地方都有记录,所以我不知道它真正想要什么格式,除了扬声器输出格式对我有用,它应该是浮点线性 PCM 格式。</p>
<p>仅供引用,Varispeed 单元不会进行任何音高校正,这在更改播放速率时听起来很荒谬。您可以改用 NewTimePitch 单元,它响应相同的变速参数,但结果听起来不像废话。</p></p>
<p style="font-size: 20px;">关于ios - 无法在格式转换器音频单元上设置格式,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32518697/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32518697/
</a>
</p>
页:
[1]