2

I am building a streaming system for audio playback, and every so often, the audio either glitches or starts stuttering for a second or two.

I am running a single output audioQueue with 3 allocated buffers of 1024 samples with a sample rate of 22050.

I hold a separate list of buffers ready to stream, and that buffer is never empty (logs always show at least one filled buffer there whenever a playback_callback is called). playback_callback just memcpy-s a ready buffer into one of the three AudioBuffers with no locks or other weirdness.

playback_callback takes at most 0.9ms to run (measured via mach_absolute_time), which is far below the 1.0/(22050/1024) = 46.4 ms.

I initiate the queue with either CFRunLoopGetMain () or NULL (which should use an "internal thread") and get the same behavior in both cases.

If buffer size is turned absurdly high (16384 instead of 1024), glitches go away. If the nuber of AudioBuffers is turned from 3 to 8, it practically goes away (happens ~20x more rarely). However, neither of those settings is workable for me as it is not ok for the system to take a second to react to a stream switch (0.1 - 0.2s would still be tolerable)

Any help and ideas on the matter would be greatly appreciated.

velochy
  • 371
  • 2
  • 12
  • Did you solved it? – AndaluZ May 08 '18 at 14:21
  • I did, but I believe the issue was that the system I used to generate the samples had a slow garbage collector that caused this, i.e. it turned to not have anything to do with iOS audio system. – velochy May 09 '18 at 14:45
  • Ok thnx. My issue is that the Callback for the recording is called after 1024 samples is buffered in AudioQueue's internal memory. While I correctly allocated 160 bytes buffers to fill in 20 ms samples at 8 KHz. So after every 128 ms (=1024 samples) it calls the callback like 6 times after each other to pass approximately 1024 samples. See: https://stackoverflow.com/questions/50251620/audioqueue-recording-at-8-khz-not-calling-callback-every-20-ms – AndaluZ May 09 '18 at 15:44

0 Answers0