Windows Mixer Control in C#


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


In this article, I'll show you how to use a Windows Mixer from C#.

For some time, I tried to get information about how to program the mixer from C#. I didn't have too much luck, and the few examples found were in C++. So, I took the hard and fun way... doing it myself.

This library is part of my Audio library to control Wave Audio (Playback/Recording), Mixer, Playback/Recording compressed files using ACM, basic speech recognition, and some other stuff that I'll release in future articles.

AudioMixer Namespace

Hierarchical objects view

The hierarchical view shows how the classes are organized.

A main object Mixers contains two objects: Mixer Playback and Recording. Those will work with default devices, but can be changed by setting the Mixers.Playback.DeviceId or Mixers.Recording.DeviceId properties.

I made it as simple as possible, hiding all the flat Win32 API implementation from the developer and creating a hierarchical set of objects.

Every mixer is autonomous to each other. This means that you can have a Playback mixer set to one sound card and a Recording mixer to another one. Also, each one contains two array or MixerLines (Lines, UserLines).

The Lines object contains all lines inside the mixer; for example, all the lines that don't have controls associated with them or lines that are not source lines.

UserLines will contain all lines that the developer can interact with, having controls like volume, Mute, Fadder, Bass, and so on (basically, is the same as a Lines object but a filter was applied to it).

Every Line will contain a collection of controls, such as Mute, Volume, Bass, Fader, and the like.

If you are interested in knowing more about how Windows Mixer works, here is an excellent link with all the information about it: http://www.borg.com/~jglatt/tech/mixer.htm.

Here Is Some Code

To get the audio devices in the computer:

foreach(MixerDetail mixerDetail in mMixers.Devices)

To get the input devices:

foreach(MixerDetail mixerDetail in mMixers.Recording.Devices)

To change the output mixer device:

Mixers mixers = new Mixers();
foreach(MixerDetail mixerDetail in mixers.Playback.Devices)
   if (mixerDetail.MixerName == "Sound Blaster Live")
       mixers.Playback.DeviceId = mixerDetail.DeviceId;

To change the output mixer device to the default device:

Mixers mixers = new Mixers();
mixers.Playback.DeviceId = -1;


mixers.Playback.DeviceId = mixers.Playback.DeviceIdDefault;

Getting the Playback Speaker Master volume:


Setting the Playback Speaker Master volume for the left channel only:

MixerLine line = mixers.Playback.Lines.
line.Channel = Channel.Left;
line.Volume  = 32000;

Selecting the Microphone as the default input:


Getting callback notifications when a line has changed:

/* Initialization */
mMixers = new Mixers();
mMixers.Playback.MixerLineChanged +=
   new WaveLib.AudioMixer.Mixer.
mMixers.Recording.MixerLineChanged +=
   new WaveLib.AudioMixer.Mixer.
/* Events */
private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
   Console.WriteLine("Mixer: " + mixer.DeviceDetail.MixerName);
   Console.WriteLine("Mixer Type: " + mixer.MixerType);
   Console.WriteLine("Mixer Line: " + line.Name);

Getting and Setting Rare Controls

Specific controls like Fadder, Microphone Boost, bass, treble, and so forth can be accessed via the MixerControl object using ValueAsSigned, ValueAsUnsigned, and ValueAsBoolean properties, but they are not implemented as standard properties because they don't belong to all controls.


All the current functionality is tested and working. I tried to not include bugs, but they are there and I find them every once in a while. If you find bugs, I'll be grateful to get the feedback to update the article.

For now, I don't need anything else from the library, but if you think of something not included in it that could could make it better, just let me know and I'll try to include it.

If you have a problem with it, just feel free to write me an e-mail.

About the Author

Gustavo Franco

started with programming about 19 years ago as a teenager, from my old Commodore moving to PC/Server environment Windows/UNIX SQLServer/Oracle doing gwBasic, QBasic, Turbo Pascal, Assembler, Turbo C, BC, Clipper, Fox, SQL, C/C++, Pro*C, VB3/5/6, Java, and today loving C#. Currently working on VOIP/SIP technology. Passion for most programming languages and my son Aidan.



  • Thanks a lot!

    Posted by NinjaSquirrel on 06/07/2013 12:44pm

    You sir, are a hero, thank you very very much for this! I have been searching for a windows mixer control library for ages now and somehow I have always overlooked yours. My old WinXP machine has a TV card installed which I still use frequently but cannot get to work on Win7. Its audio signal is passed through my audio card's line-in channel. The audio card's driver in turn is not (and never was) perfect so my TV card's audio output only came through undistorted after muting Line-In and unmuting it again after every system reboot. I always wanted to automate this ... and now the penny finally dropped. Thanks again for your work (and giving it away for free), my soul is at peace now. ;)

  • Great

    Posted by CLS on 01/03/2013 11:27pm

    Thank you very mach for this product. I found it firmly useful. The only question I have is that, why Microsoft did not implement this in the DotNet framework, and mainly why are the internal dll calls so deeply complicated?

  • Download failure

    Posted by Lorenzo on 04/28/2012 02:09pm

    Hi, download failure!

  • giving thanks

    Posted by ipey22 on 09/12/2011 11:23am

    For me as a new C# programmer that was a great help. By the way I'm working on a simple VOIP software over LAN but I can not multicast a stream of audio. Could you please help me. thank you very much in advance.

  • Reference from other article

    Posted by fmonroy on 09/26/2006 05:30am

    Thank you CastorTiu, I used this information to write a windows service that saves volume control levels from users when they logon/logoff, this is at http://www.codeguru.com/csharp/csharp/cs_graphics/sound/article.php/c12643/

    • Reference from other article

      Posted by CastorTiu on 09/26/2006 06:38am

      I'm glad it was useful. Regards.

  • Windows x64 .net 2.0 volume control not working

    Posted by milesj on 04/13/2006 01:04am

    would like to get my volume control working on x64. Anyone have any headers that will work with x64? Can't get explicit to work, would even like sequential layout to work as well.

  • Excellent

    Posted by TheFrog on 12/05/2005 07:50pm

    This is the code, which I've searched for a long time. I know, that it must be a very hard work. Thanks so much.

    • Re: Excellent

      Posted by CastorTiu on 12/05/2005 08:51pm

      Your welcome, I'm glad it is useful for you. After you get the understanding of Mixer API is not so hard to do it, it is just a little confusing at the beginning. The Mixer is very good explained here http://www.borg.com/~jglatt/tech/mixer.htm Regards, Gustavo

  • IT Developer

    Posted by Bo3po on 11/25/2005 10:41am

    This is extremmly nice code. From a designers point of view this is 100% the way to do it I would say. A rather complex structure but with the UML class diagram there was no trouble understanding the code. The thing that impressed me is the way everyting is well coded. Nice. The GUI generation can be tricky to figure out but it's not that hard. I had no problems with it at all ... Keep it up :)

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date