Ok, here is the scenario: I have a real-time recording application using ExtAudioFileWriteAsync designed for iOS 4.3. The first time I record an application, it works fine. If I click on the stop and then record again, better than half the time when I get EXC_BAD_ACCESS in AudioRingBuffer :: GetTimeBounds right at the start of recording.
That is, ExtAudioFileWriteAsync fails on GetTimeBounds when the second record starts. Here is a bit of code that runs when recording starts, which creates an ExtAudioFile link:
- (void) setActive:(NSString *) file { if (mExtAFRef) { ExtAudioFileDispose(mExtAFRef); mExtAFRef = nil; NSLog(@"mExtAFRef Disposed."); } if (mOutputAudioFile) { ExtAudioFileDispose(mOutputAudioFile); mOutputAudioFile = nil; NSLog(@"mOutputAudioFile Disposed."); } NSURL *outUrl = [NSURL fileURLWithPath:file]; OSStatus setupErr = ExtAudioFileCreateWithURL((CFURLRef)outUrl, kAudioFileWAVEType, &mOutputFormat, NULL, kAudioFileFlags_EraseFile, &mOutputAudioFile); NSAssert(setupErr == noErr, @"Couldn't create file for writing"); setupErr = ExtAudioFileSetProperty(mOutputAudioFile, kExtAudioFileProperty_ClientDataFormat, sizeof(AudioStreamBasicDescription), &audioFormat); NSAssert(setupErr == noErr, @"Couldn't create file for format"); setupErr = ExtAudioFileWriteAsync(mOutputAudioFile, 0, NULL); NSAssert(setupErr == noErr, @"Couldn't initialize write buffers for audio file"); isActive = TRUE; }
Does anyone have any thoughts on what might be causing this? I believe, given that EXC_BAD_ACCESS, that this is a memory leak or some number of links that have been knocked down from scratch, but I can’t understand for a lifetime that this could be, and Google draws a complete space. I posted the same topic on the Apple dev forum for CoreAudio, but not a single soul regretted me, even to make a lasting comment. HALP!
EDIT: Problem detected. The error occurred when ExtAudioFileWriteAsync tried to write a new file before the old file was “optimized”. Little love with a mutex solved the problem.
source share