Print the size of each buffer in the number of samples (via "reading" readerOuput while loop) and repeat in the "write" writerInput for-loop. This way you can see all buffer sizes and see if they add up.
For example, you skip or skip the if (writerInput.readyForMoreMediaData) buffer if (writerInput.readyForMoreMediaData) is false, you are "sleeping", but then proceed to the next inverted template in reverseedsamples files (this buffer is effectively removed from writerInput)
UPDATE (based on comments): I found two problems in the code:
- Incorrect output settings (the input file is mono ( 1 ), but the output parameters are configured as 2. It should be:
[NSNumber numberWithInt:1], AVNumberOfChannelsKey . Look at the information on the output and input files:


- The second problem is that you are reversing 643 buffers of 8192 audio samples instead of changing the index of each audio sample. To see each buffer, I changed your debugging by looking at the size of each sample to look at the size of the buffer, which is 8192. So, now line 76:
size_t sampleSize = CMSampleBufferGetNumSamples(sample);
The result is as follows:
2015-03-19 22:26:28.171 audioReverse[25012:4901250] Reading [0]: 8192 2015-03-19 22:26:28.172 audioReverse[25012:4901250] Reading [1]: 8192 ... 2015-03-19 22:26:28.651 audioReverse[25012:4901250] Reading [640]: 8192 2015-03-19 22:26:28.651 audioReverse[25012:4901250] Reading [641]: 8192 2015-03-19 22:26:28.651 audioReverse[25012:4901250] Reading [642]: 5056 2015-03-19 22:26:28.651 audioReverse[25012:4901250] Writing [0]: 5056 2015-03-19 22:26:28.652 audioReverse[25012:4901250] Writing [1]: 8192 ... 2015-03-19 22:26:29.134 audioReverse[25012:4901250] Writing [640]: 8192 2015-03-19 22:26:29.135 audioReverse[25012:4901250] Writing [641]: 8192 2015-03-19 22:26:29.135 audioReverse[25012:4901250] Writing [642]: 8192
This shows that you are reordering each buffer of 8192 samples, but in each buffer the sound is still “facing forward”. We can see this in this screenshot, which I took correctly canceled (sample by sample) compared to your buffer spread:

I think that your current circuit can work if you also cancel each sample of each 8192 buffer. I personally would not recommend using NSMray enumerations for signal processing, but it can work if you work at the sample level.
source share