Suppose the code is:
...
status = AudioUnitSetProperty(
unit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, element,
&format,
sizeof(AudioStreamBasicDescription));
...
status = AudioUnitInitialize(unit);
The error manifests in AudioUnitInitialize
returning kAudioUnitErr_InvalidPropertyValue
and the following message being printed in the debugger console:
[pool] <aurioc> 806: failed: -10851 (enable 2, outf< 2 ch, 48000 Hz, Int16, inter> inf< 2 ch, 0 Hz, Float32, non-inter>)
If you've set a stream format for kAudioUnitScope_Input
as well, then a variation of this message will be:
[pool] <aurioc> 806: failed: -10851 (enable 2, outf< 2 ch, 48000 Hz, Int16, inter> inf< 2 ch, 48000 Hz, Int16, inter>)
Error code -10851 corresponds to
kAudioUnitErr_InvalidPropertyValue
.Apparently, the error is solved by performing this initialization before doing AudioUnitInitialize:
Additionally, Apple recommends setting the sampling rate that you intend to use throughout the app:
This problem mostly occurs when you didn't set category and mode for AudioSession. Try to update like below:
}
Don't use ActivateSession line, below line responsible to generate error.