I am working on a project that uses the Audio Toolbox to record and play PCM data, and I'm having trouble playing back. In the simulator, I can record and play sound just fine, using a special class to handle storage and retrieval of PCM bytes for recording and playback buffers as needed. On the device (iPhone (3.0.1) and iPod 2G (3.1.2)), recording works fine, sound files play correctly, but playback in the application stutters as if it plays only part of each playback buffer. My buffers are one second long and I have 3 buffers that are preloaded before playback starts; stuttering occurs within the first three seconds, which, I think, eliminates the problem with the delay.
I have written the Audio Toolbox code before this, and I am not doing anything strange here, except that I use my own class for the PCM source data instead of AudioFileReadBytes ()
I know that the data that comes from my source is good, because it plays directly in the sim, and it writes to disk as the correct audio file
I played a little with the sampling rate; I usually use 11025 Hz sampling to reduce the file size (all this is voice, so it sounds great). at a frequency of 44100 Hz, but with the same buffer size, I get the same stuttering problem, but the sound segments go much faster, about 4 times faster. That is why I believe that it plays only part of each buffer.
The only reason I can imagine that it will play only part of each buffer is a delay problem ... for example, in the codec code, the full buffers end up while I still fill up the empty one. But that would make him load pre-loaded buffers correctly, and then start stuttering, and this does not happen, he stutters all the way through
I tried bulky buffers like 10 MB buffers and I just get silence and one stuttering sound at the end of playback. I also tried presetting more buffers than usual, for example, 10 seconds of audio, and it behaves the same. An audio session is set using AVAudioSession, not to calls to the Audio Toolbox, and a playback category for playback is set for it.
, , , , .
: http://pastebin.com/mfaa546c