Optimize audio playing

Hello everyone,

I’m creating an application that can play from 1 to the number you want of sounds at the same time and when they sound create a visual effect for each sound (so, if you play 10 sounds at the same time you’ll see 10 visual effects at that time). The problem is that when more than 5 audios plays together the app lag so much. I tried .wav and .caf files and all of them make the same problem.

How can I optimize the app to play them without lag?.

PS: I have all of them in one class together and when I want to play them just call the method play.

Thank you so much.

Have you checked that it’s actually the audio playing that’s causing the problems? Try removing the visual component and seeing if that makes a difference.

Also, if you could post a bit of the relevant code it’d be easier to figure out what might be the issue.

Hey admsyn thanks for the reply.

Yes, pretty sure it’s because the audio. The code it’s very simple, I created a class just for the audios and all the methods are like this:

void Audios::kickPlay(){    

and the others audios are equal just changing the name, then when I have to play the sound I call this method


The visual effect is, when the audios is playing this will run too

 if (executaAudio == true){    
//tamany quadrat
            for (int j = 0; j < 1; j++){
            ofSetColor(230,126,34, alpha--);
            //vertex superior esquerra
            ofVertex( x - augmentQuadrat/2, y - augmentQuadrat/2, 0);
            //vertex superior dreta
            ofVertex( x  + 60 + augmentQuadrat/2, y - augmentQuadrat/2  , 0);
            //vertex inferior dreta
            ofVertex( x  + 60 + augmentQuadrat/2, y + 60 + augmentQuadrat/2, 0);
            //vertex inferior esquerra
            ofVertex( x - augmentQuadrat/2 , y + 60 + augmentQuadrat/2, 0);

The lag problem could be because I load the sound every time I want to play it?.

Thanks :).


Hi noobie,

I use ofxOpenALSoundPlayer sounds on iOS and no ofSoundPlayer, which cause here delays, more details here Forum entry



Thank you MikeFromMoon, I tried but I couldn’t play any sound, I imported the addon to the project, then create an instance of the class and when I tried to loadSound it didn’t work. I tried loadSound(“000.WAV”) and loadSound(“000.WAV”, true) and anyone works.

Do you know who to use it?.

Thanks you so much.

Hi noobie,

no idea, but I use only caf-files for ofxOpenALSoundPlayer, which works here.



Hi Mike, yes, i’m using .caf files with ima4 compression. I tried a .wav file (as I posted before) and the same audio but in .caf file.

How do you load the sound an then play it?. Thank you.

The issue in xcode is: "Virtual function “loadSound” has a different return type (‘void’) than the function it overrides (which has a return type ‘bool’).

PS: Whats the difference between of"x"OpenALSoundPlayer and ofOpenALSoundPlayer?

Hi noobie,

sorry, I am not the sound expert. I load all my CAF-sound files at program startup in global static ofxOpenALSoundPlayer variables, and play them when needed with no delay.



Can you paste a little bit of the code to show me exactly how do you do it?.

Thank you so much :).

Hi noobie,

attached an of 0.8.0 project.emptyExample.zip (98.5 KB)



Perfect! This is what I was looking for! Thank you Mike :slight_smile: