views:

153

answers:

0

I have a sound file I play using AVAudioPlayer. Simultaneously I record using AVAudioRecorder, both at 44.1kHz. I prepare the player/recorder, call play/record one right after the other, and have the recorder stop when AVAudioPlayers delegate audioPlayerDidFinishPlaying is called.

When I look at the recorded audio file I see the recording starts slightly before the player actually starts playing, which is not too surprising, but the problem is the recording stops slightly before the playing does. I have tracked it down to audioPlayerDidFinishPlaying being called before all the audio is done playing I believe. If I put the call to stop the recorder in an NSTimer for long enough I can get the full recording of the played sound. Why is the delegate method audioPlayerDidFinishPlaying being called and passing a successful BOOL when it is in fact not done playing? Is the function simply returning that it's done as soon as it sends the last buffer to be played out but before the buffer is actually played through the hardware?

I use AVAudioSessionCategoryPlayAndRecord, I call prepareToPlay and prepareToRecord before I use them, I have tried using .caf and .wav as the source audio file, I have tried both the simulator and 3GS, I have tried everything I can think of and the result is always the same. What could cause the delegate to say it's successfully done when it's not?