Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How do I play music B after A ends?

This thread is locked; no one can reply to it. rss feed Print
How do I play music B after A ends?
amarillion
Member #940
January 2001
avatar

I have background music consisting of two Ogg files. One is an intro, the other is a loop. So the two should be played like A,B,B,B,... The gap between A and B should be as short as possible.

What is the best way to start audio stream B directly after audio stream A ends? I don't think there is a way to generate an event when an audio stream has finished, and respond to that, right?

I can think of two other ways. One is to carefully set a timer at exactly the moment A is supposed to end, and start playing B at the right moment.

The other is to take control of how the audio buffer is filled. First fill it with data from stream A, until it runs out, then fill it with data from stream B. That's a bit more involved that loading and playing a stream, but it will probably give the most glitchless result.

What do you think is the best approach? Or is there another option?

torhu
Member #2,727
September 2002
avatar

RmBeer2
Member #16,660
April 2017
avatar

Ideally, you have the music ready and prepared before playing it, so you just stop the above and reproduce the new in 2 lines quickly. Although you could also reproduce the new and then stop the old.

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

SiegeLord
Member #7,827
October 2006
avatar

The other is to take control of how the audio buffer is filled. First fill it with data from stream A, until it runs out, then fill it with data from stream B. That's a bit more involved that loading and playing a stream, but it will probably give the most glitchless result.

This is the only way that will have no playback gaps. We have an issue open to make the loading bit easier: https://github.com/liballeg/allegro5/issues/1046

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

dthompson
Member #5,749
April 2005
avatar

If the oggs aren't absolutely huge - and you're happy with that A,B,B,B pattern - I guess you could do this:

  • Concatenate A and B into a single file with ffmpeg or somesuch

  • Load the file

  • Call al_set_audio_stream_loop_secs, setting start to the original length of A

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Go to: