Click here to Skip to main content
Click here to Skip to main content

Audio Mixer Functions Demo

By , 25 Oct 2002
 

Introduction

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 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. In order 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 the four programs are MFC dialog based. For the sake of brevity, they always use the first mixer device if there are 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 the Program 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 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.

Program 2. Master Volume

Master Volume

This program is equivalent to the "Volume Control" trackbar of 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.

Program 3. Wave Meter

Wave Meter

This program is equivalent to the "Wave Meter" control of 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 in order 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 since it passes through the MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER or MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC source audio lines respectively.

Program 4. Microphone Select

Microphone Select

This program is equivalent to the "Microphone Select" check box of 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.

Happy programming and good luck!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Chen Su
Software Developer
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionMusic Mixing.... Pinmembershashikant.inext@gmail.com16 Jan '13 - 0:41 
GeneralMy vote of 5 Pinmembermanoj kumar choubey26 Feb '12 - 20:58 
Generalcan you help PinmemberMember 779661522 Apr '11 - 19:37 
GeneralSetting the volume of the microphone PinmemberAyandorias15 Feb '11 - 3:36 
GeneralOnMixerCtrlChange PinmemberAdeel Mirza10 Jan '11 - 16:54 
GeneralMicrophone Boost PinmemberAdeel Mirza7 Jan '11 - 1:41 
General2 Mixers [modified] PinmemberAdeel Mirza6 Jan '11 - 22:34 
QuestionRight-Left Balance of Speaker Output: Can't finde control for it PinmemberMichael Ruhl4 Nov '09 - 9:02 
QuestionRouting Audio Channels Pinmemberezcodez26 Jul '09 - 19:06 
GeneralRecording Audio Output Pinmembersairamdp12 Jun '09 - 23:38 
GeneralMute affects other applications Pinmemberkundan kumar das15 Oct '07 - 23:08 
GeneralAnother Code Project article on volume control Pinmemberdaluu5 Sep '07 - 9:08 
Questioncan u guide me i am new for mixer control Pinmemberrajneshmalik30 Aug '07 - 2:30 
Questionhow can i add balancer to control volume of left and right speaker Pinmemberrajneshmalik5 Aug '07 - 20:02 
GeneralNo Mixer present?!! PinmemberDexterND14 May '07 - 3:22 
Generalaudio mix PinmemberCANDIBANE3 May '07 - 21:59 
Generalaudio balance PinmemberCANDIBANE3 May '07 - 21:50 
Generalaudio mix, PinmemberCANDIBANE3 May '07 - 21:48 
QuestionMic Boost Pinmemberrathan6 Nov '06 - 6:22 
GeneralThe control does not exist. Pinmemberjosh9984ako24 Oct '06 - 5:32 
Questionaudio controls Pinmembersunpak24 Sep '06 - 7:44 
QuestionC# Pinmembervikas_ksharma23 Aug '06 - 9:29 
GeneralI need a win32 API to set the default recording device for windows PinmemberHung In26 Jul '06 - 16:02 
General"Microphone" instead of "Rear Mic" PinmemberScubaDave16 Jun '06 - 3:09 
QuestionHow to diffirent center and subwoofer Pinmemberasdfghjklu11 Jun '06 - 19:44 
Questioncould you can explain more how to select any recording device - super cool code Pinmemberhaitham hamed housin26 May '06 - 8:30 
GeneralSpeaker Capture Pinmemberjiffthomson21 May '06 - 18:45 
QuestionProgram 3. Wave Meter can't work on High Definition Audio Pinmemberenjoyfood22 Mar '06 - 19:58 
Generalabout audio mix Pinmemberextraf20 Oct '05 - 3:37 
GeneralMix audio channel Pinmembervizdev6 Oct '05 - 2:52 
GeneralSetting Pan Control PinsussL.A Fernando16 Sep '05 - 17:56 
Generalsome help with a soundmixer with 8 inp, 8 outp Pinmemberaaron7723 Aug '05 - 10:57 
GeneralProject 3 failed PinmemberCore.Lance19 Aug '05 - 2:03 
GeneralRegarding capturing audio from two USb headsets PinmemberGauravSae8 Aug '05 - 6:45 
GeneralSelect Recording Source in VB PinmemberTheNamelessOne19 Jun '05 - 20:20 
GeneralWith USB Headset and DSP> cant find input Pinmemberbartouze20 Apr '05 - 23:38 
GeneralAudio mixing to another WAV file PinmemberNightfox16 Feb '05 - 15:53 
Generalkey binding Pinmemberfireflame4 Feb '05 - 8:02 
GeneralAudio Balance PinmemberShilpa Maheshwari24 Nov '04 - 19:42 
GeneralProblems matching MIXERCONTROLDETAILS_BOOLEAN and the list of source lines Pinmemberdit6a922 Sep '04 - 8:54 
GeneralProblem with ESS Maestro 3 Pinmembercrystalmanticore6 Jul '04 - 0:53 
GeneralI NEED FEEDBACK Pinmemberhernan2210 May '04 - 15:42 
GeneralMicrophone Select will do nothing. Pinmemberdeer@webmail.hebut.edu.cn27 Apr '04 - 5:03 
QuestionHow to Select Mono mix like program 4. PinmemberKenlin42730 Mar '04 - 16:06 
Generaladjust balance Pinmemberavia29 Mar '04 - 21:36 
GeneralRoute mixed data back to application PinsussRobBoy26 Feb '04 - 2:38 
Generalrequest for Code to mute microphone and adjust the mic. volume PinmemberNamipage6 Feb '04 - 6:42 
GeneralMicrophone in Visual C PinsussAnonymous7 Oct '03 - 21:01 
GeneralPatch for CMedia driver PinmemberDungKee30 Sep '03 - 15:59 
GeneralControlling All Recording Vaolume control.. PinsussAnonynmous19 Aug '03 - 16:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 26 Oct 2002
Article Copyright 2002 by Chen Su
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid