Sounds not playing repeating properly
AgentBaron

Hey there! I'm trying to have my game play a gunshot every time a shot is fired, but the shots fire more frequently than the sound can play. Instead, the sound will allow itself the time to finish playing before repeating itself.

My current implementation is a vector of sample instances, and whenever I want to play them I just use al_play_sample_instance(m_sfx[track]). However, simply using that function won't allow the sound to be played multiple times on top of itself.

I've tried reserving a larger numbers of samples and this seems to yield nothing. ???

Dizzy Egg
Polybios

I'd like to add that there's a summary about the underlying concepts of the audio addon here, below the TOC. It's not in the a.cc version of the manual yet, as this is still 5.0.

SiegeLord

I feel like it needs a picture...

Chris Katko

There's a few sections of the Allegro 5 manual that could use tweaking. Like handling events and events using timers. I couldn't find any obvious usage of allegro timer causing an event, and in your event loop you check to ensure the timer is the correct one you're responding to. I just had to guess at the structure/comparison a few times until it finally worked. (Actually, on further inspection, I never figured it out. The line was commented out.)

#SelectExpand
1 2ALLEGRO_TIMER *fps_timer; 3 4// ... 5 6switch(event) 7{ 8case ALLEGRO_EVENT_TIMER: //we have a timer 9 { 10 //is it the right timer? 11 if(event.timer.source == fps_timer){} //nope, this code isn't right. But it compiles. 12 if(event.timer == fps_timer) //nope. 13 if(event.timer.source == al_get_timer_event_source(fps_timer)) //nope. 14 15}

SiegeLord

I couldn't find any obvious usage of allegro timer causing an event, and in your event loop you check to ensure the timer is the correct one you're responding to.

The first one is the correct one, and the last one will work if you do event.any.source instead.

I made this picture for the manual, what do you guys think? It'll have some text attached to it but that's just adding to the 1000 words this adds, right?

{"name":"610805","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/c\/8c90f365a014deb6ebfd6d50a6e2f35b.png","w":757,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/c\/8c90f365a014deb6ebfd6d50a6e2f35b"}610805

Edgar Reynaldo

It's a nice addition I say.

Chris Katko
SiegeLord said:

The first one is the correct one, and the last one will work if you do event.any.source instead.

Thanks, again! I made a terrible mistake (and I'm surprised the compiler didn't warn me...). I had a global fps_timer, and in haste/late-night change, I actually wrote:

ALLEGRO_TIMER *fps_timer = ...

in my initializing function, instead of

fps_timer = ...

So I was actually creating a new local variable pointer (instead of referencing the global), setting up the timer, then letting that pointer disappear when the function returns while the global fps_timer was still set to null!

Ugh.

Polybios

It's very nice. :)

There's also ex_audio_chain. I'm not sure whether the docs reference any examples at all, though.

SiegeLord

Mentioning the example is a good idea, but I think it should be done more generally. It probably isn't too difficult to replica what allegro.cc has and just link every example an API entry appears on.

Polybios

That would be cool, although every example will call al_init and at least many of them will have some sort of event loop.

Thread #616771. Printed from Allegro.cc