Playing buffer in ObjectAL correctly

38 views
Skip to first unread message

Maksim Sorokin

unread,
Jan 7, 2015, 6:13:26 AM1/7/15
to objectal-...@googlegroups.com

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


Karl Stenerud

unread,
Jan 7, 2015, 11:57:53 AM1/7/15
to objectal-...@googlegroups.com
You need to retain a reference to the source. Otherwise it will get deallocated as soon as the method ends, and the sound will stop playing.

--
You received this message because you are subscribed to the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-ip...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages