On Mac OS X, I try to get a audio stream from a user selected sound card and do some stuff with PCM buffer coming out.
At this time, I can access to the good device and use a AudioDeviceIOProc
to get buffer at the hardware native stream description.
Now I want to use a AUGraph
with my selected device to convert my buffer to a custom ASBD and get it on a AURenderCallback
.
Here is my setup code (NSString* deviceUID and AudioStreamBasicDescription streamDescription
are pass in argument to my setup function):
// 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);
And I start my AUGraph
later.
Actually I got a error -50 on each AudioUnitSetProperty
with streamConverterUnit
.
I would like to have a feedback from people used to CoreAudio
, is this setup flow is good? Why this error -50 and what should I do to finish on a working setup?
Best regards, Yoann