How to use multiple ofxALSoundPlayer

is this procedure correct
in .h i declare:

vector sons;

then in .cpp

void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data) {  
ofxALSoundPlayer som;  
switch (circleProto.soundPulseDef) {  
	case 0:  
		som.loadLoopingSound(ofToDataPath("radio.caf", false));  
	case 1:  
		som.loadLoopingSound(ofToDataPath("radio1.caf", false));  
		som.loadLoopingSound(ofToDataPath("radio.caf", false));  

i’m not getting any sound, but the radio.caf file plays if i do the loadLoopingSound in the setup(){} part and i hear sound, so it’s not a problem of the files being badly encoded, but a code problem…

that’s weird that the code doesnt work.
ofxAlSoundPlayer has some weird issues, but I would say that you probably shouldnt be loading your sounds on the fly like that.

The best way to do it is declare all your sound instances in your .h file (either as seperate variables, or as an array, not as a vector, and then load your sounds into them in setup()

thanks for the quick reply.

i’ve tried before doing this to load the sounds first and then have a ofxALSoundPlayer in my custom class objects which i then did

customClass.sound = som; (being som the ofxALSoundPlayer declared in the setup phase)
and didn’t get it to work.
what i am trying to do is have 28 sounds, and have them associated to different objects i create. these objects might have the same looping sound.


create object1 - define associated sound1 (sound 1) - put object1 on screen - play looping sound1

create object2 - define associated sound2 (sound 2) - put object2 on screen - play looping sound2

a minute after, with sound1 still looping:

create objec3t - define associated sound (sound 1) - put object3 on screen - play looping sound

and at this time sound1 associated with object1 has looped 5 times and a half but the sound of object 3 which is the same as sound one starts playing so i have the same sound playing 2 times at different positions.

kinda like synthPond, where you have circles with the same sound (same color) that can overlap (one is already playing and the other has just started playing it but are the same sound)

I think loading in sounds live might cause framerate issues in your program

The way I did it with synthpond was to have looping tones. If the tone was already playing from one node, I ignored the play command from the other node, unless the second node was closer to the listener. If it was closer, then I moved the sound closer, but kept it playing looped instead of playing a second same tone.

synthpond loaded in tones for each sound at the start, but only needed one of each because of how I managed them. it works as long as the sounds are looping.