在 Mac OS X 上,我尝试从用户选择的声卡中获取音频流,并使用 PCM 缓冲区来做一些事情。
这时候,我可以访问好设备并使用aAudioDeviceIOProc
来获取硬件本机流描述处的缓冲区。
现在我想使用AUGraph
我选择的设备将我的缓冲区转换为自定义 ASBD 并在AURenderCallback
.
这是我的设置代码(NSString* deviceUID and AudioStreamBasicDescription streamDescription
在参数中传递给我的设置函数):
// get the AudioDeviceID
AudioValueTranslation avt = {&deviceUID,
sizeof(deviceUID),
&_inDevice,
sizeof(_inDevice)};
UInt32 avt_len = sizeof(avt);
osstat = AudioHardwareGetProperty(kAudioHardwarePropertyDeviceForUID, &avt_len, &avt);
osstat = NewAUGraph(&_inputGraph);
AudioComponentDescription streamConverterDesc;
streamConverterDesc.componentType = kAudioUnitType_FormatConverter;
streamConverterDesc.componentSubType = kAudioUnitSubType_AUConverter;
streamConverterDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
streamConverterDesc.componentFlags = streamConverterDesc.componentFlagsMask = 0;
AUNode streamConverterNode;
osstat = AUGraphAddNode(_inputGraph, &streamConverterDesc, &streamConverterNode);
AudioUnit streamConverterUnit;
osstat = AUGraphNodeInfo(_inputGraph, streamConverterNode, NULL, &streamConverterUnit);
osstat = AudioUnitSetProperty(streamConverterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamDescription, sizeof(streamDescription));
osstat = AudioUnitSetProperty(streamConverterUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &_inDevice, sizeof(_inDevice));
AudioComponentDescription streamReaderDesc;
streamReaderDesc.componentType = kAudioUnitType_Output;
streamReaderDesc.componentSubType = kAudioUnitSubType_GenericOutput;
streamReaderDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
streamReaderDesc.componentFlags = streamReaderDesc.componentFlagsMask = 0;
AUNode streamReaderNode;
osstat = AUGraphAddNode(_inputGraph, &streamReaderDesc, &streamReaderNode);
AudioUnit streamReaderUnit;
osstat = AUGraphNodeInfo(_inputGraph, streamReaderNode, NULL, &streamReaderUnit);
AURenderCallbackStruct callback;
callback.inputProc = EIRenderCallback;
callback.inputProcRefCon = self;
osstat = AudioUnitSetProperty(streamReaderUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Output, 0, &callback, sizeof(callback));
osstat = AudioUnitSetProperty(streamReaderUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamDescription, sizeof(streamDescription));
osstat = AUGraphConnectNodeInput(_inputGraph, streamConverterNode, 1, streamReaderNode, 0);
osstat = AUGraphOpen(_inputGraph);
osstat = AUGraphInitialize(_inputGraph);
我开始我的AUGraph
晚点。
实际上我得到了一个错误AudioUnitSetProperty
-50 streamConverterUnit
。
我想从习惯的人那里得到反馈CoreAudio
,这个设置流程好吗?为什么会出现此错误 -50,我应该怎么做才能完成工作设置?
最好的问候, 约安