How to play a sound through specified playback device?

The topic pretty much says what I want. I would like to create an executable file which plays a sound from the playback device I want. For example, I want my music to be played through my headphones and while the music is playing, I would like the .exe to play a specified sound file through speakers.

Is this even possible to do with C++? I'm very new to programming, so I don't know much about this kind of stuff. I've looked from around the internet, but I couldn't get a simple answer how to do this, so any help would be highly appreciated.
Last edited on
I'm assuming you're on Windows here....

The first step would be to see if it's even possible to do this on your hardware.

Go in the control panel and open up "Hardware and Sound"... then open up "Sound".

The playback tab will list all of your output devices. If you do not have a different device for your speaker and your headphone jack... then it simply is not possible with your hardware/drivers.


If you DO have separate devices (which is extremely unlikely).... then I'm pretty sure this is possible with DirectSound by enumerating the available output devices and selecting which one you want your output buffer to use.

Most abstracted audio libs simplify the process of playback by assuming only 1 output device (the "default" device.. which is typically your speakers but can be changed by the above mentioned Sound dialog)... so you'll probably have to use DirectSound directly. You might not be able to use something like Bass/FMod (though you might... I haven't looked into the details... these libs might let you select a device). You definitely won't be able to use beginner friendly libs like SDL/SFML for this.

I don't consider any aspect of DirectX to be "Beginner" friendly, though. I'm going to go out on a limb and say this might not be worth pursuing.
Last edited on
If you DO have separate devices (which is extremely unlikely)


I have. Other device is plugged via 3,5mm jack and the other with USB. Maybe should have mentioned that... And yes, I'm on Windows.

Is there some kind of guide how to do this? I can't imagine how it could be too hard to do, because all I want is one audio file to be played through different playback device than the default... If it is possible to select a device that the program uses when playing sounds, I'll have all I need.


Edit (because new reply would be unnecessary): I tried for quite some time to get this work without any results. Maybe I'll have to get some experience in programming first, or maybe I just missed some really simple thing at some point. However, thanks for the effort anyway :)
Last edited on
Is there some kind of guide how to do this?


Here's an outline for how to enumerate devices in DirectSound:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee417545%28v=vs.85%29.aspx


When you create your DirectSound instance... for example with DirectSoundCreate8:

http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.directsoundcreate8%28v=vs.85%29.aspx


You would specify which GUID of the device you want to output to as the first parameter... whereas most programs just use the default device.

In your case, you'd have to create two instances... one for music and one for sound effects. And use the appropriate instance when playing stuff.


I can't imagine how it could be too hard to do


DirectX has a way of making things very complicated when they seem conceptually simple. It's one of the reasons why I avoid it.
Last edited on
Topic archived. No new replies allowed.