setting audio "default device"

Posted on 2005-05-04
Last Modified: 2008-02-01
Hi there,

I am trying to set the "default device" for sound playback and recording, ie the one that you see in the combo box if you look at the Audio tab under Control Panel->Sounds and Audio. I can get the current default device by using mixerGetID but I don't know how to change it. Does anyone know how?  
Question by:wilsonian
    LVL 11

    Expert Comment

    If I remember correctly, it can be set using the waveOutOpen function, but the change does not propogate properly.  In other words, to make Windows genuinely switch is an undocumented (as of a year ago) function.

    If all you need to do is control where playback ocurrs, you can use mciSendString to specify an output device.

    Hope this helps.

    Author Comment

    Sorry, are you saying that you can't change the default devices, but you can change the devices used inside your program for both playback and recording?  Or are you saying it will work for playback but not recording?

    How do you use mciSendString to specify an output device?
    Thank you.
    LVL 11

    Expert Comment

    I'm saying that you cannot change the default device, but you can change the playback and recording devices that your program uses.  Actually, you can change the default device (after all, the control panel does it) but the interface is undocumented and even forcing the change requires a reboot without that undocumented interface.

    If you know the device number you can specify the output device in mciSendString using the output command.  For example, to play the system "ding" sound to device 6:

    mciSendString(_T("open \"c:\\winnt\\media\\ding.wav\" type waveaudio alias mywav wait"), 0, 0, 0);
    mciSendString(_T("set mywav output 6 wait"), 0, 0, 0);
    mciSendString(_T("play mywav wait"), 0, 0, 0);

    You can use the waveOutOpen function to get device characteristics or to find a device by number:

    Author Comment

    Oh ok. We are using directSound to play and record our sound.  I guess that doesn't work then?
    LVL 11

    Accepted Solution

    If you are using directSound then you can just enumerate the devices to choose which one you want to use:

    Of course, this won't solve the setting of the default device, but unless the recent agreement with the EU changes the situation, Microsoft is keeping that technique secret.

    Author Comment

    Thanks, that looks like it should work.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Focus not getting shifted out of  editbox 2 46
    PDF library for Delphi 2 82
    Getting IP address 8 56
    Unresolved External Symbols 3 37
    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now