Register
handmade.network»Forums»XAudio2 How to Get Multiple Sounds to Play at the Same Time
12 posts
XAudio2 How to Get Multiple Sounds to Play at the Same Time
11 months ago Edited by Blu342 on March 27, 2019, 7:19 a.m. Reason: Initial post
https://pastebin.com/q300rp98

hey guys I have been working on trying to learn XAudio2, but I have been having a lot of trouble getting my proof-of-concept working. I have gotten 2 sounds playing simultaneously (bg music and fire effect); however, I can't seem to figure out how to get 2 sounds to play simultaneously. I tried making a Pool of SourceVoices, then calling GetState to see if that voice currently has UINT32 BuffersQueued != 0; if it did I would choose another Voice from the pool. Unfortunately, I can't seem to get it to work. Anyone with XAudio experience have any tips? Code posted above but of course don't feel like you need to read it, I would appreciate both specific and non-specific advice.
Mārtiņš Možeiko
2000 posts / 1 project
XAudio2 How to Get Multiple Sounds to Play at the Same Time
11 months ago Edited by Mārtiņš Možeiko on March 27, 2019, 7:33 a.m.
To do that you create another IXAudio2SourceVoice, submit its buffer and call Start on it. Basically you create one master voice and then as many source voices as you want simultaneously playing music/sounds.
12 posts
XAudio2 How to Get Multiple Sounds to Play at the Same Time
11 months ago Edited by Blu342 on March 27, 2019, 7:49 a.m.
hmmm i believe i tried that and it didn't quite work, but maybe i went wrong somewhere. i'll give it another try tomorrow and post back if i encounter some error.

is GetState the best way to know if a clip ends, because i want to use a Pool of these things and I tried using GetState to figure out whether I could reuse that element.
12 posts
XAudio2 How to Get Multiple Sounds to Play at the Same Time
11 months ago Edited by Blu342 on March 27, 2019, 10:20 a.m.
ok it works now. thanks. i probably just made a mistake when writing my first version.