Search code examples
iosopenalobjectal

Playing buffer in ObjectAL


I am new to ObjectAL. I use it to play mp3 with changed pitch.

I cannot figure out how to "properly" play a loaded buffer in ObjectAL. When I call [source play:buffer] the sound only comes a fraction of a second. To constantly "play" a buffer I can embed it in infinite loop and then the buffer is played correctly. I assume I miss some fundamental point, can you point me in the right direction?

My code:

[OALSimpleAudio sharedInstance].reservedSources = 0;

ALSource *source = [ALSource source];

ALBuffer *buffer = [[OpenALManager sharedInstance] bufferFromFile:@"video.mp3" reduceToMono:YES];
source.pitch = 1;

for (;;) {   // infinite loop because otherwise only a millisecond of buffer is played
    [source play:buffer];
}

Solution

  • Calling pitchTo or similar function actually makes the buffer play constantly, fx:

    [source pitchTo:1 duration:1 target:nil selector:nil];
    

    This does not qualify as a perfect explanation, however at least it solves the problem.