Audio Mixer Functions Demo

Environment: Visual C++ 6.0 with Service Pack 3, Windows 9x, Windows NT 4.0 with Service Pack 6a, and Windows 2000

Audio Mixer Functions are a set of functions that control the routing of audio lines to a destination device for playing or recording. They can also control volume and other effects. Although there are only ten functions and two messages in this API, some people feel it's a little difficult to use them because of the flexibility. Here I am going to present four simple programs to demonstrate how to use this powerful API. I kept these four programs as simple as possible and one program does one thing only so that you can understand them easily. I also tried to separate the actual operations from the user interface as much as possible. All the functions related to Audio Mixer Functions have the prefix "amd". I did not write C++ classes for those functions as the main purpose here is to give you a tutorial. To master this API, you may read the Platform SDK documentation on Audio Mixers and play around with these four programs. You may also wish to check out the Platform SDK Audio Sample Mixapp: Sample Mixer Application," which is not so easy to read.

To better understand Audio Mixer Functions, keep in mind the following key facts.

  • There are zero, one, or more audio mixer devices in a system.
  • Each audio mixer device has one or more destination audio lines.
  • Each destination audio line has zero, one, or more source audio lines associated with it.
  • Each (destination or source) audio line has zero, one, or more mixer controls associated with it. A mixer control can perform any number of functions (such as control volume), depending on the characteristics of the associated audio line.

All four programs are MFC dialog-based. For the sake of brevity, they always use the first mixer device if there is more than one mixer device present in the system. The mixerOpen function is called with the CALLBACK_WINDOW flag in the fdwOpen parameter and a window handle in the dwCallback parameter in Programs 1, 2, and 4 so that the MM_MIXM_CONTROL_CHANGE message can be received in order to refresh the state of the controls.

Program 1. Master Mute

Master Mute

This program is equivalent to the "Mute all" check box of the Windows Volume Control for Playback. The Master Mute control is the MIXERCONTROL_CONTROLTYPE_MUTE control of the MIXERLINE_COMPONENTTYPE_DST_SPEAKERS destination audio line. It belongs to the switch controls (MIXERCONTROL_CT_CLASS_SWITCH), which are two-state switches. It uses the MIXERCONTROLDETAILS_BOOLEAN structure to retrieve and set control properties. Whenever the check box is clicked, CMuteDlg::amdSetMasterMuteValue is called to set the Master Mute value accordingly. The MM_MIXM_CONTROL_CHANGE message is received once the state of the Master Mute control has changed. In this case, CMuteDlg::amdGetMasterMuteValue is called to retrieve the current value of the Master Mute control and update the state of the check box accordingly.

Download Program 1 - 77 Kb

Program 2. Master Volume

Master Volume

This program is equivalent to the "Volume Control" trackbar of the Windows Volume Control for Playback. The Master Volume control is the MIXERCONTROL_CONTROLTYPE_VOLUME control of the MIXERLINE_COMPONENTTYPE_DST_SPEAKERS destination audio line. It belongs to the fader controls (MIXERCONTROL_CT_CLASS_FADER), which have a linear scale. It uses the MIXERCONTROLDETAILS_UNSIGNED structure to retrieve and set control properties. Whenever the trackbar is clicked, CVolumeDlg::amdSetMasterVolumeValue is called to set the Master Volume value accordingly. The MM_MIXM_CONTROL_CHANGE message is received once the state of the Master Volume control has changed. In this case, CVolumeDlg::amdGetMasterVolumeValue is called to retrieve the current value of the Master Volume control and update the state of the trackbar accordingly.

Download Program 2 - 77 Kb

Program 3. Wave Meter

Wave Meter

This program is equivalent to the "Wave Meter" control of the Windows Volume Control for Playback. The Wave Meter control is the MIXERCONTROL_CONTROLTYPE_PEAKMETER control of the MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT source audio line associated with the MIXERLINE_COMPONENTTYPE_DST_SPEAKERS destination audio line. It belongs to the meter controls (MIXERCONTROL_CT_CLASS_METER), which measure data passing through an audio line. It uses the MIXERCONTROLDETAILS_SIGNED structure to retrieve and set control properties. A timer is created to monitor the value of the Wave Meter control. CMeterDlg::amdGetWaveMeterValue is called to retrieve the current value of the Wave Meter control and update the state of the progress bar accordingly once a WM_TIMER message is received.

Run it and play a sound file using other applications; you can see it dancing. Note that the sound from MIDI or CD Audio is not reflected here because it passes through the MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER or MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC source audio lines respectively.

Download Program 3 - 76 Kb

Program 4. Microphone Select

Microphone Select

This program is equivalent to the "Microphone Select" check box of the Windows Volume Control for Recording. The Microphone Select control is one of the items of the MIXERCONTROL_CONTROLTYPE_MIXER or MIXERCONTROL_CONTROLTYPE_MUX controls of the MIXERLINE_COMPONENTTYPE_DST_WAVEIN destination audio line. It belongs to the list controls (MIXERCONTROL_CT_CLASS_LIST), which provide single-select or multiple-select states for complex audio lines. It uses the MIXERCONTROLDETAILS_BOOLEAN structure to retrieve and set control properties. Whenever the check box is clicked, CSelectDlg::amdSetMicSelectValue is called to set the Microphone Select value accordingly. The MM_MIXM_CONTROL_CHANGE message is received once the state of the Microphone Select control has changed. In this case, CSelectDlg::amdGetMicSelectValue is called to retrieve the current value of the Microphone Select control and update the state of the check box accordingly.

Download Program 4 - 78 Kb


Happy programming and good luck!



Comments

  • Same code is not working in Windows vista, windows 7

    Posted by praveena.pb on 05/29/2012 03:36am

    HI!! Thank you so much for this code. This code is working in Windows XP, but wanted to work in Windows vista and Windows 7 too. If you have the code which supports Windows XP, Windows Vista and Windows 7 please share to me. Thank you so much. cheers, praveena.

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

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Flash technology is becoming more prominent in the storage industry. Offering superior speed and reliability when compared to traditional hard disk drives – flash storage is a flexible and increasingly cost-effective technology that can be used to optimize enterprise storage environments. This ebook explores the many uses and benefits of flash storage technology in the enterprise. Check it out to discover and learn all you need to: Optimize storage performance Leverage server flash as storage cache …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds