In wave data samples alternate. This means that the data is organized as follows.
Sample 1 Left | Sample 1 Right | Sample 2 Left | Sample 2 right ... Sample n Left | Sample n right
Since each pattern is 16-bit (2 bytes), the first 2-channel pattern (i.e., for the left and right) is 4 bytes in size.
Thus, you know that the last sample in the wave data block is as follows:
wavDataSize - 4
You can then load each sample at a time by copying it to another buffer, starting at the end of the recording and counting backward. When you get to the start of the wave data, you change the wave data and the playback will be canceled.
Edit: If you need easy ways to read wave files in iOS, refer to the Audio File Reference .
Edit 2:
readPoint = waveDataSize; writePoint = 0; while( readPoint > 0 ) { readPoint -= 4; Uint32 bytesToRead = 4; Uint32 sample; AudioFileReadBytes( inFile, false, maxData, &bytesToRead &sample ); AudioFileWriteBytes( outFile, false, writePoint, &bytesToRead, &sample ); writePoint += 4; }
Goz source share