How to play sound effects simultaneously in SDL3_mixer?

Hi,

I’m fairly new to SDL and game development, so apologies if this is a newbie question. I’m using SDL3 and SDL3_mixer and I want to layer game sfx. Let’s say I swing a weapon, and it hits an enemy. The weapon swing has its own independent sfx, and the enemy being hit has its own independent sfx. Is there a way to get them to play simultaneously? I can get the tracks to play individually, and they’ll play one, after the other. But I’m not sure how to get them to play simultaneously.

edit: To add a little more context, the sounds will play simultaneously if the function calls to play the tracks are right next to each other in the same code block:

MIX_PlayTrack(swordSwingTrack, 0);
MIX_PlayTrack(enemyOuchTrack, 0);

But let’s say, I have an sfx for specifically sword swing that triggers when I press the space key, and an sfx for specifically enemy ouch that triggers when anything hits it. The functions to play the two tracks are in different parts of code. And when I’m in the situation where the sword swing hits an enemy, the tracks will play one after the other, instead of simultaneously (or at least near simultaneously). I’ve started to build out a separate simple sound manager to attempt to place the tracks in a queue of sorts, but the sounds are still triggering separately. Not sure how to approach this using SDL3_mixer.

Thank you.

Multiple sounds can be started at the exact same sample frame with MIX_PlayTag, but this is kind of heavyweight for two throwaway sounds, so we’re talking about adding an API to do this better (perhaps adding a MIX_PlayTracks() that takes an array of tracks, or a way to lock the mixer, so multiple unrelated operations happen atomically).

Stay tuned for more on that!