Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Sounds not playing repeating properly

This thread is locked; no one can reply to it. rss feed Print
Sounds not playing repeating properly
AgentBaron
Member #16,630
January 2017

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
Member #10,824
March 2009
avatar

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Polybios
Member #12,293
October 2010

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
Member #7,827
October 2006
avatar

I feel like it needs a picture...

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Chris Katko
Member #1,881
January 2002
avatar

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}

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

SiegeLord
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Chris Katko
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Polybios
Member #12,293
October 2010

It's very nice. :)

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

SiegeLord
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Polybios
Member #12,293
October 2010

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

Go to: