I have encountered an error.
I just want kAudioFormatXXX
not PCM
, but there are errors.
Error: Error Domain=NSOSStatusErrorDomain Code=1718449215 "The operation
couldn’t be completed. (OSStatus error 1718449215.)"
Error Code responded 1718449215 in file
/Users/breaklee/Documents/project/ginav/ginav-
mobile/ginav-mobile/AudioProcessor.m on line 281
281 line is the end of code.
how can i initialize this code properly?
I want to use iLBC
or other codecs not PCM
.
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = SAMPLE_RATE;
audioFormat.mFormatID = kAudioFormatAC3;
audioFormat.mFormatFlags = kAudioFormatFlagIsPacked |
kAudioFormatFlagIsSignedInteger;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 1;
audioFormat.mBitsPerChannel = 8;
audioFormat.mBytesPerPacket = 1;
audioFormat.mBytesPerFrame = 1;
// set the format on the output stream
status = AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
kInputBus,
&audioFormat,
sizeof(audioFormat));
[self hasError:status file:__FILE__ line:__LINE__];
// set the format on the input stream
status = AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
kOutputBus,
&audioFormat,
sizeof(audioFormat));
[self hasError:status file:__FILE__ line:__LINE__];
/**
We need to define a callback structure which holds
a pointer to the recordingCallback and a reference to
the audio processor object
*/
AURenderCallbackStruct callbackStruct;
// set recording callback
callbackStruct.inputProc = recordingCallback; // recordingCallback pointer
callbackStruct.inputProcRefCon = (__bridge void*)(self);
// set input callback to recording callback on the input bus
status = AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global,
kInputBus,
&callbackStruct,
sizeof(callbackStruct));
[self hasError:status file:__FILE__ line:__LINE__];
/*
We do the same on the output stream to hear what is coming
from the input stream
*/
callbackStruct.inputProc = playbackCallback;
callbackStruct.inputProcRefCon = (__bridge void*)(self);
// set playbackCallback as callback on our renderer for the output bus
status = AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Global,
kOutputBus,
&callbackStruct,
sizeof(callbackStruct));
[self hasError:status file:__FILE__ line:__LINE__];
// reset flag to 0
flag = 0;
/*
we need to tell the audio unit to allocate the render buffer,
that we can directly write into it.
*/
status = AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_ShouldAllocateBuffer,
kAudioUnitScope_Output,
kInputBus,
&flag,
sizeof(flag));
// kAudioFormatUnsupportedDataFormatError
// Initialize the Audio Unit and cross fingers =)
status = AudioUnitInitialize(_audioUnit);
NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain
code:status
userInfo:nil];
NSLog(@"Error: %@", [error description]);
[self hasError:status file:__FILE__ line:__LINE__];
NSLog(@"Started");