Sample Rate Conversion Sync Issue

I'm having an interesting issue with the frames requested and produced when sample rate conversion is happening on iOS. When I downsample from 48000 to 44100 as expected every 5th interrupt 236 frames are requested instead of 235 due to 256 *(44100/48000) = 235.2. However when the input produces 236 and the output requests 236 is out of sync by one interrupt. In that, the output will request 235 and when the AudioUnitRender is called on the input it produces 236 frames and then in the next interrupt the output requests 236 but only 235 is produced. I've currently solved the issue by inserting a buffer which then saves the extra from the first and adds it to the beginning of the second. However, this merely solves the symptom and not the actual cause.


I'm using a modified version of the Amazing Audio Engine 2 to which I added the stream format specifications to the remoteIO. In it has a specified InputCallback which just grabs the input timestamp and stores it. However, even if this input callback doesn't exist the issues still does. Unfortunately, the offending code is included with some proprietary code so I'm starting with the question in case someone has experienced this and knows why it's happening. I'm trying to create a simple project that replicates the issue I can include code

Replies

The filtering and resampling from 48k to 44.1 has to occur before the input buffer is created, and the 44.1 to 48k resampling and filtering occurs after the output buffer request is fulfilled. So it may be that the buffer sizes are not intended to be in sync, but are based on the needs of the two different resampling processes.


You should check to see if when the display goes dark/locked, whether the app may need to handle a much larger difference in input and output buffer sizes (512 input samples provided with 2048 output samples requested, etc.)