Issues when playing different files at a high BPM

edited August 2016

Hey there,

I've been using The Amazing Audio Engine for quite a while (and I've got to admit it's really amazing). I've been trying different things and have come to a dead end with one problem.

Basically, what I'm trying to do is to have a certain file play repeatedly (not loop) at a certain BPM. What I did was use a timer set at that frequency, which would call my "play" method. This is how my play method looks like:

- (void)playInstrumentWithAudioFilename:(NSString *)fileName {
    NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];

    NSURL *pathAsURL = [NSURL fileURLWithPath:audioFilePath];

    AEAudioFilePlayer *player = [AEAudioFilePlayer audioFilePlayerWithURL:pathAsURL error:nil];
    player.volume = 1.0f;

    player.removeUponFinish = YES;
    [self.audioController addChannels:@[player] toChannelGroup:self.audioGroup];

Here's where the problem appears: when using the same file repeatedly, i can go from 50 to 400 BPM without experiencing any glitch of any sort. However, when I try to use several different files (with very small length difference, something like 0.50 to 0.70), I'm experiencing huge glitches (situations where sounds are not played at the right time and as if they try to catch up with the rest of the playback).

I've been trying different ways to handle this problem - I tried to cache the file players, the file names, to increase the preferred buffer duration of the audio controller (currently set at 0.005, increasing it would crash the app, decreasing it would not play my sounds), to use other ways of playing the sounds - by adding the players beforehand and muting/unmuting the current player, depending on their turn to be played and others. However, everything I tried and researched has not led me to a solution yet.

Where do you think I should look next? What do you feel might be the problem here? Is it something related to the fact that multiple files might add too much overhead to the I/O operation and trying to play them at such a high rate affects the reading process? If it is the latter, is there any way to store the file content in memory and have it available for the AEAudioFilePlayer object on the go?

If there's anything else needed please let me know.



Sign In or Register to comment.