Ios 无法在格式转换器音频单元上设置格式
我正试图建立一个非常简单的AU图——简单地说就是一个带有varispeed的RemoteIO,用于输出。不幸的是,我似乎无法在varispeed装置上设置音频格式。我看到的其他例子似乎只是设置了格式,没有任何问题。我返回的确切错误是不支持的格式。然而,RemoteIO单元内的格式转换器将很乐意采用我的格式,这是一种非常简单的16khz单16位有符号整数PCM格式 以下是我目前正在努力实现的代码:Ios 无法在格式转换器音频单元上设置格式,ios,core-audio,Ios,Core Audio,我正试图建立一个非常简单的AU图——简单地说就是一个带有varispeed的RemoteIO,用于输出。不幸的是,我似乎无法在varispeed装置上设置音频格式。我看到的其他例子似乎只是设置了格式,没有任何问题。我返回的确切错误是不支持的格式。然而,RemoteIO单元内的格式转换器将很乐意采用我的格式,这是一种非常简单的16khz单16位有符号整数PCM格式 以下是我目前正在努力实现的代码: // Describe the output unit. AudioComponentDescri
// 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)");
我还尝试简单地设置RemoteIO的输出总线的输入格式,这对转换器的输出格式很有效,但它仍然不接受我的格式作为转换器的输入格式
如何将varispeed和RemoteIO连接到我想要的格式?我在一个旧邮件列表中发现,varispeed单元仅为浮点型,实际上不进行格式转换,尽管主要类型是FormatConverter。解决方案是使用另一个具有专用转换器子类型的转换器将我自己的格式转换为Varispeed需要的FP格式。Varispeed的格式限制在我能说的任何地方都没有实际记录,因此我几乎不知道它实际需要什么格式,除了扬声器输出格式适合我,它应该是浮点线性PCM格式 仅供参考,Varispeed单元不做任何音调校正,这在改变播放速率时听起来很可笑。您可以使用NewTimePitch单元,它响应相同的varispeed参数,但结果听起来不像废话