I have this following render callback for a remoteIO audio unit. Simply accessing the 0th element of the ioData
parameter results in a crash. Very simply put, this works with no headphone jack connection but as soon as I plug a jack into my iphone6+, I get a bad access error when accessing the buffer.
If I plug it in while the app is running it crashes. If I plug it in first, and then build and run the app, it still crashes. I checked to see if inNumberFrames
perhaps is changing based on a line out connection but it remains consistently at 512 frames.
OSStatus playbackCallback(void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData) {
float * output = (float*)ioData->mBuffers[0].mData;
output[0] = 1;
return noErr;
}
Apparently an AVAudioSession
route change callback is called even if the headphones are plugged in before app launch. One of the things I tried was to delay remoteIO start until that point. However, the following code produces an error:
- (void)handleRouteChange:(NSNotification *)notification {
OSStatus err = AudioOutputUnitStart(remoteIOUnit);
}
The error:
Error: should alloc (-10849)