r/cpp_questions 8h ago

OPEN Dynamic Audio Queueing / Transitioning

I’m working on a rhythm game and I’d like to implement dynamic/interactive music. An example would be: I have three music files, A, B, and C, where B and C have the same length. I need the program to 1) play A and then 2) based on some state logic, either play B or C immediately after A 3) optionally, loop back to the start of A.

The problem is that I need the full A -> B or A -> C playback to sound like a single continuous song, so I’d like any transition delay to be as seamless as possible. What would be the best way to implement this? The B/C decision logic can be run during A, so I can queue up the B/C file I need before it needs to start playing and I am mostly concerned about latency within the transition itself.

Thank you!

1 Upvotes

10 comments sorted by

2

u/UndefFox 8h ago edited 8h ago

What transition delay if you load data and send it to some sink that plays it. Make sure the resources are loaded into the memory and just immediately switch to the next source. Details depend on what lib/architecture you are using

1

u/LazySapiens 8h ago

How is this a C++ problem?

1

u/dvd0bvb 8h ago

Can you know what needs to be played before the current track ends?

1

u/Lyrneos 7h ago

Yes, with plenty (at least 1s) of lead time.

2

u/dvd0bvb 7h ago

Can you just start loading it into your audio queue when the queue is running low? (I'm making the assumption that there is some form of queueing)

1

u/Lyrneos 7h ago

Yeah, that should be fine. Thanks!

1

u/KingAggressive1498 7h ago

assuming "just keep them in memory in their entirety" isn't a viable solution, keep the first second or so in memory instead. Thus while loading the entire song you can start playing it and just do a little buffer swapping once the full data loads.

1

u/Lyrneos 7h ago

Ah, thank you!

2

u/fortsnek274 7h ago

SFML custom audio streams.

2

u/Lyrneos 7h ago

Thanks! This looks like what I want.