简体   繁体   中英

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];
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM