Stuttering during playback

I'm using AVAudioEngine to play audio tracks with the added ability to change their playback rate and pitch. I'm finding that the audio will stutter or crackle when I do things like open a full-screen view, present a blurred visualEffectView, or basically anything that uses up standard main thread UI resources.


In the past I used the system music player and AVAudioPlayer and they seem immune to these kinds of issues, presumably because they're both buffering and using their own threads to stay responsive.


Is there any way to achieve the same solid performance with AVAudioEngine?

Post not yet marked as solved Up vote post of asdfasdf Down vote post of asdfasdf
652 views

Replies

Are you providing the audio in a callback? If so you are probably doing too many things you shouldn't do in the audio thread. You should not be allocating memory or calling Obj-C in the callback.


Making your buffer bigger is another help.


Hard to know what's wrong with the little info you have given.

No, I'm not using a callback, just the most basic file setup. Here's what I'm doing, slightly truncated for clarity:


engine = [[AVAudioEngine alloc] init];
player = [[AVAudioPlayerNode alloc] init];
[engine attachNode:player];
file = [[AVAudioFile alloc] initForReading:_mediaItem.assetURL error:nil];
[engine connect:player to:engine.mainMixerNode format:file.processingFormat];
[engine startAndReturnError:nil];
[player scheduleFile:file atTime:nil completionHandler:nil];