Source: http://www.borg.com/~jglatt/tech/mixer.htm
In order to understand how the Mixer API works, it's important to first understand the hardware layout of a typical audio card. It's necessary to be able to visualize an audio card as having distinct, but interconnected, components upon it.
Let's consider a typical, basic audio card. First of all, if the audio card is capable of recording digital audio, then it typically has a microphone input jack (with some sort of pre-amp), and it also has an analog-to -digital converter (ADC) to convert that analog microphone signal to a digital stream Therefore, it has two components -.. the Microphone input component, and the ADC component The Microphone input is piped into the ADC So, we can represent the. Layout with The Following Block Diagram Showing Two Components, The Signal Flow Between Them (IE, THE Arrow)
A typical audio card is also capable of playing back digital audio, so it has a DAC to convert the digital stream back to an analog signal, and also it has a speaker output jack (ie, with some sort of analog amplifier). Therefore, IT Has Two More Components - The Dac Component, And The Speaker Component. The Dac Output Is Piped to the speakers.
A typical audio card may have some other components. For example, it may have a built-in sound module (ie, synth) capable of playing MIDI data. The audio output of this component would typically be piped to the speaker output just like the DAC. So, Our Block Diagram No Looks Like SO:
So too, a typical audio card has a connector to (internally) attach the audio out of the computer's CDROM drive (so that an audio CD played in that CDROM drive will sound through the computer's speakers). This component is also piped to the speaker output, just like the Synth and DAC Now, our block diagram looks like this:. Finally, let's assume that this audio card has a Line In component so that the audio signal from an external tape deck or musical instrument or external hardware mixer can be . attached to this jack and digitized This component is piped to the ADC component just like the Microphone Input component Here is our finished block diagram which contains 7 components (and 5 signal flows - the arrows that interconnect them).:
Typically, each one of these components has its own, individual parameters. For example, the Synth will usually have its own volume (gain) level. The Internal CD Audio will have its own volume level. And the DAC (ie, digital audio, or WAVE playback) will have its own volume level. In this way, if the user is playing an audio CD, playing a MIDI file, and playing back a WAVE file, simultaneously, he can balance out the volumes of all 3 components as they Are Being Output to The Speaker Jack. SO TOO, The Speaker Component Will Typically Have ITS OWN VOLUME - A Master Volume That Affects The Overall Mix of The 3 Components Piped to the speaker out.
Likewise, the Line In and Microphone Input typically have separate volume levels so they can be balanced when recording simultaneously from both jacks. And the ADC may have some sort of Master Volume which affects the overall recording level of the 2 components piped to it.
A given component may have other parameters that are controllable. For example, each of the above components may have its own Mute switch so that the component's sound can be quickly turned on / off.The Mixer device
A given audio card has one Mixer device associated with it. All of the various components on that card are controlled through that card's one Mixer device. The Windows Mixer API is used to access the card's Mixer device. The Mixer API has functions to get a listing of all the various components on a particular card, and to adjust all of their parameters. This is a new API added to Win95 / 98 and WinNT (4.X and above), although an add-on to Windows 3.1 makes it available That Older OS.
NOTE: A Card's Device Driver Needs Extra Support to Work with The Mixer API. NOT All Win95 and Winnt Drivers Have this support. Win3.1 Drivers Typically do Not.
In any computer, there can be more than one installed audio card. You already discovered that Windows maintains lists of all of the WAVE and MIDI input / output devices in a system. Since each installed audio card has its own Mixer device too (as long as its driver supports such), Windows also maintains a list of Mixer devices installed in a system. So for example, if you have two audio cards installed in a given system, then there should be two Mixer devices installed as well (assuming that the Drivers for Both Audio Cards Support The Mixer API.
Just like with the WAVE and MIDI input / output devices, Windows assigns a numeric ID to each Mixer device. So, the Mixer device with an ID of 0 is the first (default) mixer in the system. If there is a second audio card The1re sales be a second mixer device with an iD of 1.
Just like with other devices, in order to use a Mixer device, you must first open it (with mixerOpen ()), and then you may call other Mixer APIs to control the card's line inputs / outputs. When finished, you must close the device (with mixerClose ()) Opening a Mixer deviceHow does your program choose a mixer device to manipulate? There are several different approaches you can take, depending upon how fancy and flexible you want your program to be.
IF you simply want to open the preferred mixer device, the use a device id of 0 with mixeropen () AS SO:
UNSIGNED Long Err;
HMixer MixerHandle;
/ * Open the mixer associated with the default
Audio / Midi Card in The Computer * /
Err = Mixeropen (& MixerHandle, 0, 0, 0, 0);
IF (ERR)
{
Printf ("Error: Can't Open Mixer Device! -% 08X / N", ERR);
}
Else
{
/ * The Mixer Device Is Now Open, And ITS
Handle is in the variable 'mixerhandle'.
You May Now Use it with Other Mixer API
Functions * /
}
Of course, if the user has no Mixer device installed, the above call returns an error, so always check that return value. (The expected error numbers from the Mixer API's are listed in MMSYSTEM.H. Unfortunately, unlike with the Wave and Midi Low Level API's, There is no API Function To Translate To Present To The user.
So what actually is the preferred Mixer device? Well, that's whatever Mixer device happened to have been installed first in a system. If there is only one audio card in the system, then it's a good bet that you have the mixer device you want. But, what if you're trying to use the Wave Output on a second audio card? you definitely do not want to be using the Mixer device for the first card to control the second card's Wave Out volume. (The first card's Mixer doesn 't control the second card's Wave Output) .So, how do you open the Mixer for the desired card? fortunately, mixerOpen () allows you to pass the device ID or the open handle of some other device associated with desired card. In that case, mixerOpen () will ensure that it returns the Mixer device associated with that card's other device. So for example, here's how you would open the default WAVE OUT device (ie, the WAVE OUT on the default card), and then get the Handle to That Card's Mixer Device:
UNSIGNED Long Err;
HMixer MixerHandle;
Waveformatex waveformat;
Hwaveout hwaveout;
/ * Open the default Wave out device, Specifying My Callback.
Assume That Waveformat Has Already Been Initialized As Desired * /
Err = Waveoutopen (& Hwaveout, Wave_Mapper, & Waveformat, (DWORD) WaveoutProc, 0, Callback_Function;
IF (ERR)
{
Printf ("Error: Can't Open Wave Out Device! -% 08x / N", ERR);
}
Else
{
/ * Open the Mixer Associated with the Wave Out Device
Opened Above. Note That I Pass the Handle Obtained
Via Waveoutopen () Above * /
Err = Mixeropen (& MixerHandle, Hwaveout, 0, 0, Mixer_Objectf_hwaveout);
IF (ERR)
{
Printf ("Error: Can't Open Mixer Device! -% 08X / N", ERR);
}
}
The key above is in passing not only the handle that you obtain with waveOutOpen () (or waveInOpen (), or midiOutOpen (), or midiInOpen ()) but also the last parameter of mixerOpen () must be MIXER_OBJECTF_HWAVEOUT (or MIXER_OBJECTF_HWAVEIN, or Mixer_Objectf_hmidiout, or mixer_objectf_hmidiin) To indeicate what kind of device handle is being passed to mixeropen ()
Alternately, if you know the device ID number of the desired WAVE OUT device (but have not yet opened its via waveOutOpen handle ()), you can pass that device ID to mixerOpen () and instead specify MIXER_OBJECTF_WAVEOUT. MixerOpen () will find The Mixer That Corresponds to That Wave Out Device with the specified ID.
If desired, you can the get the Above mixer's id (number) from its handle, using mixergetid () AS SO:
Unsigned long mixerid;
Err = MixergetId (MixerHandle, & Mixerid, Mixer_Objectf_hmixer);
IF (ERR)
{
Printf ("Error: can't get mixer device ID! -% 08x / n", err);
}
Else
{
Printf ("Mixer Device ID =% D / N", Mixerid);
}
Listing all of the Mixer devicesIf you're writing an application where you need to list all of the Mixer devices in the system, Windows has a function that you can call to determine how many Mixer devices are in the list. This function is called mixerGetNumDevs (). This returns the number of Mixer devices in the list. Remember that the Device IDs start with 0 and increment. So if Windows says that there are 3 devices in the list, then you know that their Device IDs are 0, 1, and 2 respectively. you then use these Device IDs with other Windows functions. For example, there is a function you can call to get information about one of the devices in the list, such as its name, and what sort of other features it has such as how many components it contains, and what type of component each one is. you pass the Device ID of the Mixer device which you want to get information about (as well as a pointer to a special structure called a MIXERCAPS into which Windows puts THE INFO ABOUT The Device, T He Name of the Function To Get Information About a Particular Mixer Device Is MixergetDevcaps (). Here Tan Is An Example of Going Through The List of Mixer Devices, and Printing The Name of Each ONE:
Mixercaps mixcaps;
Unsigned long inumdevs, i;
/ * Get the number of mixer defices in this computer * /
Inumdevs = mixergetnumdevs ();
/ * Go through all of those devices, displaying their ids / names * /
For (i = 0; i { / * GET INFO About the next defic- / IF (! MixergetDevCaps (i, & mixcaps, sizeof (mixercaps))) { / * DISPLAY ITS ID NUMBER AND NAME * / Printf ("Device ID #% U:% S / R / N", I, Mixcaps.szpname; } } About Lines and Controls Up to this point, I have been using the term "component" to refer to a hardware section that has its own individual, adjustable parameters. The Mixer API actually concerns itself with signal flows. (Ie, In our block diagram, the signal flows are the 5 arrows which connect the components) The Microsoft documention refers to each signal flow (ie, each arrow in our block diagram) as a "source line" So, a Mixer device controls "source lines" -.. not components per SE. IT IS Each "Source Line" Which Has ITS OWN Individual, Adjustable Parameters - Not a Component Per SE. Our Example Audio Card Has 5 Source Lines As Far As a Mixer IS Concerned. from here, WHENEVER you see the word "source line", think of the signal flow between componentsI have also been using the term "parameters" to refer to settings that are adjustable on a "line", for example a volume level or a mute switch or a bass boast or a pan Setting, etc. The Microsoft Documentation Refers To these Parameters as "controls" (White ICH CAN Be a confusing term since a program of a graphical window - Part of His Graphical Interface. But in The Case of Mixers, We mean "Audio Controls"). So for example, it's not really the "Microphone Input" component itself which concerns the Mixer API. Rather, it's the signal flow between the "Microphone Input" and "ADC" components. The "Microphone Input" volume control adjusts the volume of this Signal Flowing Between The Microphone Input and ADC Components. For further illustration of the difference between components and source lines, let's add another feature to our example sound card. Sometimes, you'd like the Microphone Input to not only pipe through the ADC (so that you can record it), but also to pipe through the speakers (so that you can monitor the signal that you're actually recording, and hear what it sounds like through the speakers). So, let's adjust our block diagram to show the signal from the "Microphone Input" as going to Both the adc and the speakers .. Notice that we now have 6 "source lines" (arrows). And there are two source lines from the "Microphone Input", even though it is only one component on our card. Each source line has its own settings. For example, there is a volume control for the "Microphone Input" source line going into the ADC (so that you can set the recording level for your WAVE recording software). There is another, separate volume control for the "Microphone Input" source line going to the speakers (so that you can set the monitor level of the microphone, separate from the recording level). These source lines may each have their own mute switches (so that you can, for example, have the "Microphone Input" signal going to only The ADC, But Not The Speakers. They May Have Other Controls AS Well, And Each Line's Controls Will Be Separate from The Other Line's Controls. .. There is another important concept to discuss in regard to lines There are such things as "destination lines", and we differentiate between source lines and destination lines What are those Well, a destination line has other lines -? Source lines - Flowing Into It. in Our Block Diagram, The "Speaker Out" IS A Destination Line, Since It Has Signals from The "Internal CD Audio", "Synth", "DAC WAVE OUT" and "MicroPut" Flowing Into It. and the latter 4 are source lines. They are source lines to the "Speaker Out" destination line since their signals flow into the "Speaker Out" line. Source lines always have to flow into some destination line. (ie, A source line can not exist WITHOUT Being Attached to One Destination Line). So, WHEREAS Source Lines Are The Arrows IN Our Block Diagram, Destination Lines Are Actual Components in Our Block Diagram. SO TOO, THE "ADC WAVE INPUT" IS A DESTINATION LINE IN OUR EXAMPLE CARD. IT HAS 2 Source Lines Flowing Into It - The "Microphone INPUT" and "line in". Those TWO LINES Are Not Source Lines to the "Speaker OUT "SINCE The DO NOT FLOW INTO IT" SIMILIARLY, THE 4 Source Lines Flowing Into The "Speaker Out" Are Not Source Lines to the "ADC WAVE INPUT" DESTINATION LINE, SINCE They Don't flow Into the latter. Like source lines, destination lines can have controls. And each destination line's controls are separate from the other lines' controls. For example, the "Speaker Out" may have a volume control. This would function as a master volume for all 4 source lines going to the Speaker Out destination line (And each of those 4 source lines has its own individual volume level control) .NOTE:. Although a card may have a stereo component (for example, typically the "Speaker Out" upon most cards is stereo ), this is considered one line. It has 2 channels, but it nevertheless is one line on the Mixer device. Indeed, a component could have more than 2 channels, and still be considered only one line. In conclusion, lines are not the same thing as channels. In some ways, it may be helpful to think of a line like a MIDI cord. One MIDI cord connects two components, but there can be several channels going over that one cord. The same thing is true of a line . In conclusion, our example card has 6 source lines and 2 destination lines. The 4 source lines labeled "Internal CD Audio", "Synth", "DAC Wave Out" and "Microphone Input" are attached to the "Speaker Out" destination line ............................ LINE IDS and TYPES Every line in a mixer must have a unique ID number. Every line also has a type. This is just a numeric value that describes what type of line it is. These are defined in the MMSYSTEM.H include file. For example, a line May Have a type of mixerline_componenttype_src_synthesizer to indeicate That IS A Signal from a Built-in Sound Module. The allowable types for source lines are as so:. MIXERLINE_COMPONENTTYPE_SRC_DIGITALA digital source, for example, a SPDIF input jack.MIXERLINE_COMPONENTTYPE_SRC_LINEA line input source Typically used for a line input jack, if there is a separate microphone input (ie, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE) .MIXERLINE_COMPONENTTYPE_SRC_MICROPHONEMicrophone input (but also used for a combination of Mic / Line input if there is not a separate line input source) .MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZERMusical synth. Typically used for a card that contains a synth capable of playing MIDI. This would be the audio out of that built -in synth.MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISCThe audio feed from an internal CDROM drive (connected to the sound card) .MIXERLINE_COMPONENTTYPE_SRC_TELEPHONETypically used for a telephone line's incoming audio to be piped through the computer's speakers, or the telephone line in jack for a built-in modem.MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKERTypically , to allow Sound, that normally goes to the computer's built-in speaker, to instead be routed through the card's speaker output. The motherboard's system speaker connector would be internally connected to some connector on the sound card for this purpose.MIXERLINE_COMPONENTTYPE_SRC_WAVEOUTWave playback (ie, this is the card ' s DAC) .MIXERLINE_COMPONENTTYPE_SRC_AUXILIARYAn aux jack meant to be routed to the Speaker Out, or to the ADC (for WAVE recording). Typically, this is used to connect external, analog equipment (such as tape decks, the audio outputs of musical instruments, etc) for digitalizing or playback through the sound card.MIXERLINE_COMPONENTTYPE_SRC_ANALOGMay be used similiarly to MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY (although I have seen some mixers use this like MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER). In general, this would be some analog connector on the sound card which is only accessible internally, to be used to internally connect some analog component inside of the computer case so that it plays through the speaker out.MIXERLINE_COMPONENTTYPE_SRC_UNDEFINEDUndefined type of source If none of the others above are applicable.The allowable types for destination lines are as so.: MIXERLINE_COMPONENTTYPE_DST_DIGITALA digital destination, for example, a SPDIF output jack.MIXERLINE_COMPONENTTYPE_DST_LINEA line output destination. Typically used for a line output jack, if there is a separate speaker output (ie, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS) .MIXERLINE_COMPONENTTYPE_DST_MONITORTypically a "Monitor Out" jack to be used for a speaker system separate from the main speaker out. Or, it could be some built-in monitor speaker on the sound card itself, such as a speaker for a built-in modem.MIXERLINE_COMPONENTTYPE_DST_SPEAKERSThe audio output to a pair of speakers (ie, the " Speaker Out "jack) .MIXERLINE_COMPONENTTYPE_DST_HEADPHONESTypically, a headphone output jack.MIXERLINE_COMPONENTTYPE_DST_TELEPHONETypically used to daisy-chain a telephone to an analog modem's" telephone out "jack.MIXERLINE_COMPONENTTYPE_DST_WAVEINThe card's ADC (to digitize analog sources, for example, in recording WAVE files of such) .MixerLine_componenttype_dst_voiceinmay become sort of hardware used for voice recognition. Typically, a microphone source line would be attached to this.MIXERLINE_COMPONENTTYPE_DST_UNDEFINEDUndefined type of destination. If none of the others above are applicable.Control IDs and Types Each line can have one or more adjustable "audio controls". (But, it's possible that a line could have no controls at all). For example, the Synth line may have a volume fader and a mute switch. Each control has a type . These are defined in the MMSYSTEM.H include file. For example, the volume fader would have a type of MIXERCONTROL_CONTROLTYPE_VOLUME. The Mute switch would have a type of MIXERCONTROL_CONTROLTYPE_MUTE. Every control also has a unique ID number. No two controls may have the same ID number, even if they belong to 2 different lines.The control types are divided up into classes. These classes are roughly based upon what type of value a control adjusts , and therefore what kind of graphical user interface you would normally present to the enduser to let him adjust that control's value. For example, you would normally present a graphical fader to allow the user to adjust a control of the type MIXERCONTROL_CONTROLTYPE_VOLUME. On the other Hand, You'D Typically Use a graphical (Checkmark) Button to Allow Him To Adjust A Control of Type MixerControl_ControlType_Mute (Since That Control Has Only Two Possible Values, or States). The ALLOWABLE CLASSES for Controls Are As SO: MIXERCONTROL_CT_CLASS_FADERA control that is adjusted by a vertical fader, with a linear scale of positive values (ie, 0 is the lowest possible value). A MIXERCONTROLDETAILS_UNSIGNED structure is used to retrieve or set the control's value.MIXERCONTROL_CT_CLASS_LISTA control is adjusted by a listbox containing that numerous "values" to be selected. The user will single-select, or perhaps multiple-select if desired, his choice of value (s). A MIXERCONTROLDETAILS_BOOLEAN structure is used to retrieve or set the control's value. A MIXERCONTROLDETAILS_LISTTEXT structure is also used to retrieve the text description of each item of this control.MIXERCONTROL_CT_CLASS_METERA control that is adjusted by a graphical meter. A MIXERCONTROLDETAILS_BOOLEAN, MIXERCONTROLDETAILS_SIGNED, or MIXERCONTROLDETAILS_UNSIGNED structure is used to retrieve or set the control's value.MIXERCONTROL_CT_CLASS_NUMBERA control that is adjusted by numeric entry. The User Enters A Signed Integer, Unsigned Integer, OR I nteger decibel value. A MIXERCONTROLDETAILS_SIGNED or MIXERCONTROLDETAILS_UNSIGNED structure is used to retrieve or set the control's value.MIXERCONTROL_CT_CLASS_SLIDERA control that is adjusted by a horizontal slider with a linear scale of negative and positive values. (ie, Generally, 0 is the mid or "neutral "point). A MIXERCONTROLDETAILS_SIGNED structure is used to retrieve or set the control's value.MIXERCONTROL_CT_CLASS_SWITCHA control that is has only two states (ie, values), and is therefore adjusted via a button. A MIXERCONTROLDETAILS_BOOLEAN structure is used to retrieve or set the control ' s value.MIXERCONTROL_CT_CLASS_TIMEA control that allows the user to enter a time value, such as Reverb Decay Time. It is a positive, integer value.MIXERCONTROL_CT_CLASS_CUSTOMA custom class of control. If none of the others above are applicable.Each class has certain types associated With it. for example, the mixerControl_ct_class_fader class Has The Following 5 Types Associated with IT: MIXERCONTROL_CONTROLTYPE_VOLUMEVolume fader. The range of allowable values is 0 through 65,535.MIXERCONTROL_CONTROLTYPE_BASSBass boost fader. The range of allowable values is 0 through 65,535.MIXERCONTROL_CONTROLTYPE_TREBLETreble boost fader. The range of allowable values is 0 through 65,535.MIXERCONTROL_CONTROLTYPE_EQUALIZERA graphic EQ. The range of allowable values for each band is 0 through 65,535. A MIXERCONTROLDETAILS_LISTTEXT structure is used to retrieve the text label for each band of the EQ. Typically, this control will also have its MIXERCONTROL_CONTROLF_MULTIPLE flag set, since the EQ will likely have numerous bands.MIXERCONTROL_CONTROLTYPE_FADERA generic fader, TO BE Used When None of the Above Are Applicable. The Range Of Allowable Values IS 0 THROUGH 65, 535. In fact, if you look at MMSYSTEM.H, you'll note that a control with a type of MIXERCONTROL_CONTROLTYPE_VOLUME is defined as MIXERCONTROL_CT_CLASS_FADER |. MIXERCONTROL_CT_UNITS_UNSIGNED 1. The class is actually contained in the top 4 bits of the type So if you know a control's type, then you determine its class by masking off the top 4 bits. For example, assume that you've queried a control's type, and stored the value returned by the Mixer API in your variable named "type". Here's how you 'D Figure out it's class: Unsigned long type; / * figure out the class based upon the top 4 bits of its type * / Switch (MixerControl_CT_CLASS_MASK & TYPE) { Case MixerControl_ct_class_fader: { Printf ("IT's A Fader Class."); Break; } Case MixerControl_ct_class_list: { Printf ("IT's a list class."); Break; } Case MixerControl_ct_class_meter: { Printf ("IT's A Meter Class."); Break; } Case MixerControl_ct_class_number: { Printf ("IT's A Number Class."); Break; } Case MixerControl_ct_class_slider: { Printf ("IT's A Slider Class."); Break; } Case MixerControl_ct_class_time: { Printf ("IT's A Time Class."); Break; } Case MixerControl_ct_class_custom: { Printf ("IT's a Custom Class."); Break; } } The MixerControl_ct_class_switch class Has The Following 7 Types Associated with IT: MIXERCONTROL_CONTROLTYPE_BOOLEANA control with a boolean value. The value is an integer that is either 0 (FALSE) or non-zero (TRUE) .MIXERCONTROL_CONTROLTYPE_BUTTONA control whose value is 1 when the button is pressed (ie, some feature / action is enabled), or . 0 if not pressed (ie, no action is taken) For example, this type of control may be used by a talkback button or pedal sustain - the action / feature is on only while the button is pressed, and otherwise is not applicable .MIXERCONTROL_CONTROLTYPE_LOUDNESSA control whose value is 1 to boost bass frequencies, or 0 for normal (ie, no boost). (A MIXERCONTROL_CONTROLTYPE_BASS fader control may be used to set the actual amount of boost, in conjunction with this control turning the boost on / off ) MIXERCONTROL_CONTROLTYPE_MONOA control whose value is 1 for mono operation (ie, all channels are summed into one), or 0 for normal (ie, stereo or multi-channel) .MIXERCONTROL_CONTROLTYPE_MUTEA control whose value is 1 to mute some feature, or 0 for no rmal (ie, no mute) .MIXERCONTROL_CONTROLTYPE_ONOFFA control whose value is 1 to enable some feature / action, or 0 to disable that feature / action. The difference between this and MIXERCONTROL_CONTROLTYPE_BUTTON is that the latter's 0 value does not disable the feature / action per se, but rather, simply represents a "not applicable" state for the feature / action. MIXERCONTROL_CONTROLTYPE_ONOFF would be similiar to a real on / off switch (ie, a checkmark button in Windows parlance) whereas MIXERCONTROL_CONTROLTYPE_BUTTON would be more akin to a " Momentary Switch " (Ie, a pushbutton). The difference between MIXERCONTROL_CONTROLTYPE_ONOFF and MIXERCONTROL_CONTROLTYPE_BOOLEAN is merely the labeling / grahics that would be shown on the user interface. The former is "ON" when its value is 1. The latter is "TRUE" when its value is 1. So typically, the two buttons would be represented by different labels and / or graphics to reflect that difference in semantics.MIXERCONTROL_CONTROLTYPE_STEREOENHA control whose value is 1 to enable a stereo enhance feature (ie, increase stereo separation), or 0 for normal ( IE, no enhance) .THE MixerControl_ct_class_list class Has The Following 4 Types Associated with IT: MIXERCONTROL_CONTROLTYPE_SINGLESELECTAllows one selection out of a choice of many selections. For example, this can be used to select a reverb type out of choice of many types (ie, Hall, Plate, Room, etc) .MIXERCONTROL_CONTROLTYPE_MULTIPLESELECTLike MIXERCONTROL_CONTROLTYPE_SINGLESELECT, but allows the selection of more . than one item simultaneously.MIXERCONTROL_CONTROLTYPE_MUXAllows the selection of one audio line out of several choices of audio lines For example, to allow a source line to be routed to one of several possible destination lines - this control could list all of the possible choices of destination lines, and allow one to be chosen.MIXERCONTROL_CONTROLTYPE_MIXERLike MIXERCONTROL_CONTROLTYPE_MUX, but allows the selection of more than one audio line simultaneously. for example, this control could be for a reverb component which allows several source lines to be simultaneously routed to it, and this Control determines Which Source Lines Are SELECTED For Routing to the Reverb . The MixerControl_ct_class_meter class has the folload 4 Types Associated with it: MIXERCONTROL_CONTROLTYPE_BOOLEANMETERA meter whose integer value is either 0 (ie, FALSE) or non-zero (TRUE). A MIXERCONTROLDETAILS_BOOLEAN struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_PEAKMETERA control with a value that is an integer whose allowable, maximum range is -32,768 (lowest) through 32,767 (highest). In other words, its value is a SHORT. A MIXERCONTROLDETAILS_SIGNED struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_SIGNEDMETERA control with a value that is an integer whose allowable, maximum range is -2,147,483,648 (lowest ) through 2,147,483,647 (highest) inclusive. In other words, its value is a LONG. A MIXERCONTROLDETAILS_SIGNED struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETERLike MIXERCONTROL_CONTROLTYPE_SIGNEDMETER, but its allowable, maximum value range is from 0 (lowest) to 4,294,967,295. In Other Words, ITS Value IS A Ulong. a MixerControlDetails_unsigned struct is buy to set / retrieve its value.some O f the allowable types for the MIXERCONTROL_CT_CLASS_NUMBER class are similiar to the MIXERCONTROL_CT_CLASS_METER class types. But with the MIXERCONTROL_CT_CLASS_NUMBER class, you would typically use an Edit control for the graphical user interface to allow him to enter a value. The MIXERCONTROL_CT_CLASS_METER would typically use some sort of Graphical Display Similiar To An Audio Meter. MixerControl_ct_class_number Class Has The Following 4 Types Associated with IT: MIXERCONTROL_CONTROLTYPE_SIGNEDA control with a value that is an integer whose allowable, maximum range is -2,147,483,648 (lowest) through 2,147,483,647 (highest) inclusive. In other words, its value is a LONG. A MIXERCONTROLDETAILS_SIGNED struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_UNSIGNEDLike MIXERCONTROL_CONTROLTYPE_SIGNEDMETER, but its allowable, maximum value range is from 0 (lowest) to 4,294,967,295. In other words, its value is a ULONG. A MIXERCONTROLDETAILS_UNSIGNED struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_PERCENTA control whose integer value is a percent. A MIXERCONTROLDETAILS_UNSIGNED struct is used to set / retrieve its value.MIXERCONTROL_CONTROLTYPE_DECIBELSA control with a value that is an integer whose allowable, maximum range is -32,768 (lowest) through 32,767 (highest). In other words, its value is a SHORT. Each increment is a tenth of a decibel. a MixerControlDetails_signed struct is buy to set / retrieve it.The Mixer Control_ct_class_slider class has the folload 3 Types Associated with IT: MIXERCONTROL_CONTROLTYPE_SLIDERA slider with a value that is an integer whose allowable, maximum range is -32,768 (lowest) through 32,767 (highest). In other words, its value is a SHORT.MIXERCONTROL_CONTROLTYPE_PANA slider with a value that is an integer whose allowable, maximum range is -32,768 (far left) through 32,767 (far right). in other words, its value is a SHORT. It represents pan position in the stereo spectrum, where 0 is center position.MIXERCONTROL_CONTROLTYPE_QSOUNDPANA slider with a value that is an integer whose allowable , maximum range is -15 (lowest) through 15 (highest) In other words, its value is a SHORT It represents Qsound's expanded sound setting.The MIXERCONTROL_CT_CLASS_TIME class has the following 2 types associated with it..: MIXERCONTROL_CONTROLTYPE_MICROTIMEA control with a value that is an integer whose allowable, maximum range is 0 (lowest) through 4,294,967,295. In other words, its value is a ULONG. Its value represents an amount of time in microseconds.MIXERCONTROL_CONTROLTYPE_MILLITIMEA control with a value that is an Integer Whose Allowable, Maximum Range IS 0 (Lowest) Through 4,294,967,295. in Other Words, ITS Value Is A Ulong. Its Value Represents An Amount of Time IN MilliseConds. The MIXERCONTROL_CT_CLASS_CUSTOM class is a proprietary class. A Mixer that uses such a type of control could expect only an application that is written specifically for that Mixer to understand what types of controls are in this class, and what structures to use to set / retrieve their (Perhaps Even Proprietary Structures Could BE Used) MIXERLINE structures, and enumerating linesOne way to get information about a mixer's lines, if you do not know what particular lines it has (ie, you do not know the types of lines it has, nor know their ID numbers), is to first call mixerGetDevCaps () to fetch information about that Mixer device into a MIXERCAPS structure. Using information in this structure, you can determine how many destination lines are on the card. From there, you can enumerate (ie, fetch information about) each destination line, and the source lines to each destination line. and after you enumerate the lines, you can enumerate the controls for each line.Let's examine such an approach and study the structures that are associated with the Mixer API. In order to better understand the Mixer API, we should take a peek inside of the Mixer Device for our example audio card, and examine its internal structures which are used with the Mixer API. We'll assume that this Mixer Device is written in C , and therefore buy c structures. As noted previously, the Mixer API mixerGetDevCaps () is used to fetch information about a Mixer Device. It fills in a MIXERCAPS structure. In particular, the cDestinations field of the MIXERCAPS tells you how many destination lines are on the card. It doesn ' T Tell You How Many Total Lines (IE, Destination and Source Lines) There. It Count Only Destination Lines. As You'll Recall, Our Example Audio Card Has 2 Destination Lines. We'll Fill in The Other Fields, Such As the Mixer name and product ID with arbitrary values for the purposes of this tutorial. Assume that this mixer is the first installed mixer in the system (ie, ID = 0). Here then is our Mixer Device's MIXERCAPS structure (which is defined in MMSYSTEM .H): Mixercaps Mixercaps = { 0, / * manufacturer id * / 0, / * product id * / 0x0100, / * driver version #. Note That The High 8-bits Are The Version, And Low 8-Bits Are Revision. SO, Our Driver Version IS 1.0 * / "EXAMPLE SOUND CARD", / * Product Name * / 0, / * support bits. None Are Currently Defined * / 2, / * # of destination lines * / } Here is an example of passing a MIXERCAPS to mixerGetDevCaps () and letting Windows fill it in with the above values. (Assume that we have already opened the mixer and stored its handle into our variable "mixerHandle"). Mixercaps mixcaps; MmResult ERR; / * GET INFO ABOUT The First Mixer Device * / IF (! (ERR = MixergetDevcaps ((uint) MixerHandle, & Mixcaps, SizeOf (MixerCaps)))))))))) { / * Success. We can continue on with our tutorial below * / } Else { / * An error * / Printf ("Error #% D Calling MixergetDevcaps () / N", ERR); } Information about a line is contained in a MIXERLINE structure (as defined in MMSYSTEM.H) Let's assume that our "Speaker Out" destination line has two controls -. A volume slider (to control the overall mix to the speakers) and a mute Switch (To Mute THE OVERALL MIX). Here's The Mixerline Structure for Our "Speaker Out" Destination: Mixerline MixerLine_sp Krout = { Sizeof (Mixerline), / * size of mixerline structure * / 0, / * zero based index of destination line * / 0, / * Zero Based Source INDEX (Used Only IF this is a source line * / 0xffff0000, / * unique ID # for this line * / MixerLine_Linef_Active, / * State / Information About line * / 0, / * driver specifications * / Mixerline_componenttype_dst_speakers, / * Component Type * / 2, / * # of channels this line supports * / 4, / * # of source lines connect (used) Only if this is a destination line * / 2, / * # of controls in this line * / "Spkr out", / * short name for this line * / "Speaker Out", / * long name for this line * / Mixerline_targettype_waveout, / * mixerline_targettype_xxxxx * / / * The folowing info is just some info about the mixer device for THIS Line, prepended to the Above info. it's mostjust for reference. * / 0, / * Device ID of Our Mixer * / 0, / * manufacturer id * / 0, / * product id * / 0x0100, / * driver version # * / "EXAMPLE SOUND CARD", / * Product Name * / } There are a few things to note here First, notice that the dwComponentType for the "Speaker Out" destination line is one of the types for a destination line -.. Appropriately, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS to indicate that it's a speaker output I've chosen a value of 0xFFFF0000 for the dwLineID. The Mixer Device programmer may chose any value he wishes for this field, but no other line in this mixer may have the same value for its dwLineID (as you'll notice later). Also, note that since our speaker output is stereo, the cChannels field is 2. As you'll recall, there are 4 source lines connected to our "Speaker Out" destination line, so the cConnections field is 4. The name fields are nul-terminated strings. They can be anything that the Mixer Device programmer chooses, but the shorter name is meant to be used as a label for any tightly spaced graphical controls. When the MIXERLINE_LINEF_ACTIVE bit is set in the fdwLine field, this simply means that the line has not been disabled Such as what may happen if it were muted. The dwDestination field is an index value based from 0. The first destination line in a mixer will have an index value of 0 (as in our example above). The second destination line will have an index of 1. The third destination line will have an index of 2. Etc. This is the same concept as how Windows enumerates Mixer Devices (ie, where the first installed Mixer Device has an ID of 0). The index value is not necessarily the same as a line's ID number (as you can see from the example above). What is the purpose of an index, and why do we need both an index and an ID number? As you may guess, the index number is primarily used when you need to enumerate what lines a Mixer has . Until you enumerate the lines (ie, fetch information about each line), you do not know the ID numbers of any of the lines. So, you need to use indexes with the mixer API to enumerate lines. But once you have retrieved Info About a line, and therefore know ITS ID Number, The You can alter its settings more directly. s o, index numbers are primarily useful for initially enumerating lines and controls to find their ID numbers and types. And then the ID numbers are primarily useful for subsequently performing direct manipulation of the lines and controls.Now let's take a look at the MIXERLINE structure for our "ADC Wave Input" destination line Let's assume that it also has two controls -. a volume slider (to control the overall mix to the ADC) and a mute switch (to mute the overall mix) Here's the MIXERLINE structure for our. "ADC WAVE INPUT" DESTINATION: MixerLine Mixerline_wavein = { Sizeof (Mixerline), / * size of mixerline structure * / 1, / * Zero based index of destination line * / 0, / * zero based source index (useless " this is a source line * / 0xffff0001, / * unique ID # for this line * / MixerLine_Linef_Active, / * State / Information About line * / 0, / * driver specifications * / Mixerline_componenttype_dst_wavein, / * component type * / 2, / * # of channels this line supports * / 2, / * # of source Lines Connected Only if this is a destination line * / 2, / * # of controls in this line * / "Wave IN", / * short name for this line * / "Wave INPUT", / * long name for this line * / Mixerline_targettype_wavein, / * mixerline_targettype_xxxx * / / * The folowing info is just some info about the mixer device for THIS Line, prepended to the Above info. it's mostwust for reference and is only validiffiff10 Target Type Field Is Not MixerLine_TargetType_undefined. * / 0, 0, 0, 0x0100, "Example Sound Card", } Notice that the dwComponentType for the "ADC Wave Input" destination line is MIXERLINE_COMPONENTTYPE_DST_WAVEIN to indicate that it's a wave input Also, I've chosen a value of 0xFFFF0001 for the dwLineID -. A different value than the "Speaker Out" destination line. Also, note that since our sound card is capable of digitizing in stereo, the cChannels field is 2. As you'll recall, there are 2 source lines connected to our "ADC Wave Input" destination line, so the cConnections field is 2. Finally, note that the dwDestination field is 1, since this is the second destination line in the Mixer.The mixer API mixerGetLineInfo () fills in a MIXERLINE struct for a specified line. This is how you retrieve info about a line. If you don 't know a line's ID number (as would be the case when you're first enumerating the lines), then you can reference it by index. you pass mixerGetLineInfo () the value MIXER_GETLINEINFOF_DESTINATION to notify it that you want to reference the line by ITS INDEX VALUE. f or example, here's how you would retrieve info about the first destination line in our example Mixer. Before calling mixerGetLineInfo () and passing it a MIXERLINE to fill in, you must initialize 2 fields. The cbStruct field must be set to the size of the MIXERLINE struct you're passing, and the dwDestination field must be set to the index value of the line whose info you wish to retrieve. Remember that the first destination line has an index of 0, so to retrieve its info, we set dwDestination to 0. Mixerline Mixerline; MmResult ERR; / * GET INFO ABOUT The First Destination Line By ITS INDEX * / MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = 0; IF ((Err = MixergetLineInfo ((HMixerobj) MixerHandle, & MixerLine, Mixer_getLineInfof_DESTINATION)))) { / * An error * / Printf ("Error #% D Calling MixergetLineInfo () / N", ERR); } When the above call returns, mixerGetLineInfo () will have filled in our MIXERLINE struct as per the "Speaker Out" (mixerline_SpkrOut) MIXERLINE struct shown above (After all, the "Speaker Out" is the first line in our example Mixer. - IT HAS An Index Of 0). Now, if you want to fetch info About the second destination line in the mixer, The only Thing Different Is The Index Value You Stuff Inx The Dwdestination Field, AS SO: / * GET INFO About The Second Destination Line By ITS INDEX * / MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = 1; IF ((Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Destination)))))))) { / * An error * / Printf ("Error #% D Calling MixergetLineInfo () / N", ERR); } When the above call returns, mixerGetLineInfo () will have filled in our MIXERLINE struct as per the "ADC Wave Input" (mixerline_WaveIn) MIXERLINE struct shown above. (After all, the "ADC Wave Input" is the second line in our example Mixer - IT HAS ANDEX OF 1). NOW, You Should See How You Can Enumerate The Destination Lines by Their Indexes. Here IS An Example of Printing Out The Names of All Destination Lines in Our Mixer: Mixercaps mixcaps; Mixerline Mixerline; MmResult ERR; Unsigned long i; / * GET INFO ABOUT The First Mixer Device * / IF (! (ERR = MixergetDevcaps ((uint) MixerHandle, & Mixcaps, SizeOf (MixerCaps)))))))))) { / * Print Out the name of each destination line * / For (i = 0; i MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = i; IF (! (Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Destination)))))))) { Printf ("Destination #% lu =% s / n", i, mixerline.szname; } } } Now, we need to enumerate the source lines for each destination line. We also use an index value to reference each source line. The first source line, for a given destination line, has an index value of 0. The second source line, for That Destination Line, Has An Index of 1. The Third Source Line Has An Index of 2. etc. Remember That The "Speaker Out" Had 4 Source Lines Going Into It: "Internal CD Audio", "Synth", "DAC WAVE Out "and" Microphone Input ". So their respective index values are 0, 1, 2, and 3. Let's look at the MIXERLINE structs for those 4 source lines. Assume that each one of them has 2 controls, a volume slider and a Mute Switch. Also, Assume That Each One IS A Stereo Source. MixerLine Mixerline_CD = { Sizeof (Mixerline), 0, / * zero based index of destination line * / 0, / * Zero Based Source Index * / 0x00000000, / * unique ID # for this line * / MixerLine_Linef_Active | MixerLine_LineF_Source, / * State / Information About line * / 0, MixerLine_componenttype_src_compactdisc, / * Component Type * / 2, / * # of channels this line supports * / 0, / * NOT Applicable for Source Lines * / 2, / * # of controls in this line * / "CD AUDIO", / * Short name for this line * / "infernal cd Audio", / * long name for this line * / MixerLine_targettype_undefined, / * mixerline_targettype_xxxx * / 0, 0, 0, 0x0100, "Example Sound Card", } MixerLine Mixerline_SYNTH = { Sizeof (Mixerline), 0, / * zero based index of destination line * / 1, / * Zero based Source Index * / 0x00000001, / * Unique ID # for this line * / MixerLine_Linef_Active | MixerLine_LineF_Source, 0, MixerLine_componenttype_src_synthesizer, / * Component Type * / 2, / * # of channels this line supports * / 0, / * NOT Applicable for Source Lines * / 2, / * # of controls in this line * / "Synth", / * short name for this line * / "Synth", / * long name for this line * / MixerLine_targettype_undefined, / * mixerline_targettype_xxxx * / 0, 0, 0, 0x0100, "Example Sound Card", } MixerLine Mixerline_waveout = { Sizeof (Mixerline), 0, / * zero based index of destination line * / 2, / * Zero based Source Index * / 0x00000002, / * Unique ID # for this line * / MixerLine_Linef_Active | MixerLine_LineF_Source, 0, MixerLine_componentType_src_waveout, / * component type * / 2, / * # of channels this line supports * / 0, / * NOT Applicable for Source Lines * / 2, / * # of controls in this line * / "Wave out", / * short name for this line * / "dac Wave out", / * long name for this line * / Mixerline_targettype_waveout, / * mixerline_targettype_xxxxx * / 0, 0, 0, 0x0100, "Example Sound Card", } Mixerline MixerLine_Mic = { Sizeof (Mixerline), 0, / * zero based index of destination line * / 3, / * Zero based Source Index * / 0x00000003, / * Unique ID # for this line * / MixerLine_Linef_Active | MixerLine_LineF_Source, 0, MixerLine_componenttype_src_microphone, / * Component Type * / 2, / * # of channels this line supports * / 0, / * NOT Applicable for Source Lines * / 2, / * # of controls in this line * / "MIC", / * short name for this line * / "Microphone INPUT", / * long name for this line * / Mixerline_targettype_wavein, / * mixerline_targettype_xxxx * / 0, 0, 0, 0x0100, "Example Sound Card", } One thing that you'll note is, unlike with the destination lines, the MIXERLINEs for all source lines have their MIXERLINE_LINEF_SOURCE flag bit set. When this bit is set, you know that you have info on a source line. Secondly, note that the zero-based index for the destination line is 0. That's because all of the above source lines connect to the "Speaker Out" destination line, which is the first line in our mixer (and therefore has an index value of 0). Next, Note That The Zero-Based Source Indexes for the 4 Source Lines Are 0, 1, 2, And 3, Respective, FinalLine IS Unique - Unlike Any Other Line, Including Any of The Destination Lines .The mixer API mixerGetLineInfo () fills in a MIXERLINE struct for a source line too. Again, you can reference a source line by its index, but you also need to know the index of its respective destination line. you pass mixerGetLineInfo () the Value mixer_getlineinfof_source to notiesi it That you want to reasoning the line by its index value. For example, here's how you would retrieve info about the first source line (of the "Speaker Out" destination line) in our example Mixer. Before calling mixerGetLineInfo () and passing it a MIXERLINE to fill in, you must initialize 3 fields. The cbStruct field must be set to the size of the MIXERLINE struct you're passing, the dwSource field must be set to the index value of the source line whose info you wish to retrieve, and the dwDestination field must be Set to the index value of the destination line to which this source line connects. Mixerline Mixerline; MmResult ERR; / * GET INFO About The First Source Line (of The First Destination Line) BY ITS INDEX * / Mixerline.cbstruct = sizeof (mixerline); MixerLine.dwdestination = 0; MixerLine.dwsource = 0; IF ((Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Source)))))))) { / * An error * / Printf ("Error #% D Calling MixergetLineInfo () / N", ERR); } When the above call returns, mixerGetLineInfo () will have filled in our MIXERLINE struct as per the "Internal CD Audio" (mixerline_CD) MIXERLINE struct shown above. So for example, you can extract its line ID number from the MIXERLINE's dwLineID field. Now, if you want to fetch info about the second source line of the "speaker out" destination line, The only Thing Different is The Index Value You Stuff Into The DWSource Field, AS SO: / * Get Info About The Second Source Line By ITS INDEX * / MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = 0; MixerLine.dwsource = 1; IF ((Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Source)))))))) { / * An error * / Printf ("Error #% D Calling MixergetLineInfo () / N", ERR); } . NOW, You Should See How You Can Enumerate The Source Lines (of Each Destination Line) by Their Indexes. Here INDEXES. Here is An Example of Printing Out The Names of All Destination Lines, And Their Source Lines, IN Our Mixer: Mixercaps mixcaps; Mixerline Mixerline; MmResult ERR; Unsigned long i, n, numsrc / * GET INFO ABOUT The First Mixer Device * / IF (! (ERR = MixergetDevcaps ((uint) MixerHandle, & Mixcaps, SizeOf (MixerCaps)))))))))) { / * Print Out the name of each destination line * / for (i = 0; i { MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = i; IF (! (Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Destination)))))))) { Printf ("Destination #% lu =% s / n", i, mixerline.szname; / * Print Out the name of each source line in this destination * / Numsrc = mixerline.cconnections; For (n = 0; n { MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwdestination = i; MixerLine.dwsource = n; IF (! (Err = MixergetLineInfo ((HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_Source))))))) { Printf ("/ tsource #% lu =% s / n", i, mixerline.szname); } } } } } Getting info about a line by its IDOnce you know a line's ID number (which you can extract from the MIXERLINE's dwLineID after enumerating the line as shown above), you can later retrieve info on it by referencing its ID (instead of its index). If you're dealing with a source line, you do not need, to know, you,,,,,,, "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" DWLINEID FIELD To The ID Number of the Desired Line, and Then Specify Mixer_getLineInfof_Lineid When Calling MixergetLineInfo () AS SO: / * GET INFO About The "microphone input" Source Line By ITS ID * / MixerLine.cbstruct = sizeof (Mixerline); MixerLine.dwlineId = 0x00000003; / * The id for "microphone input" * / IF ((Err = MixergetLineInfo (HMixerobj) MixerHandle, & Mixerline, Mixer_getLineInfof_LineId)))))) { / * An error * / Printf ("Error #% D calling mixergetlineinfo () / n", err); The Above Works with Both Destination and Source Lines. Once You Know A Line's ID, You Can Directly Retrieve Info On It WITHOUT NEEDING to KNOW Anything About Indexes. Getting info about a line by its TypeOften, you do not need to know about all of the lines in a Mixer. You may be writing a program that would deal only with a specific type of line. For example, let's say that you ' re writing a simple MIDI file player. Now, certain components of our example sound card are of no use to you at all. MIDI is not digital audio data, so the "DAC Wave In" component (and all source lines running into it) are of no concern to you. Likewise, the "Internal CD Audio", "DAC Wave Out" and "Microphone Input" source lines to the "Speaker Out" destination line are of no concern to you. The only component on our card which IS Capable of DEALING WITH THE "SYNTH" Component That Goes To The "Speaker Out". It is this Line's Controls That Will Affect The Playback of MIDI DATA. So, rather than enumerating all of the lines in the mixer until you come to the one with the MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER type, mixerGetLineInfo () lets you directly get info about a line that matches your desired type. You merely initialize the MIXERLINE's dwComponentType field to the desired TYPE OF LINE, AND THEN SPECIFY MIXER_GETLINFOF_COMPONENTTYE CALLING MIXERGETLINFO () AS SO: / * GET INFO ABOUT A "Synth" Type of Source Line * / MixerLine.cbstruct = sizeof (Mixerline); mixerline.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER; / * We want a Synth type * / if ((err = mixerGetLineInfo ((HMIXEROBJ) mixerHandle, & mixerline, MIXER_GETLINEINFOF_COMPONENTTYPE))) { / * An error * / Printf ("Error #% D Calling MixergetLineInfo () / N", ERR); } This will fill in the MIXERLINE struct with info about the first line in the Mixer which has a type of MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER. (If there are no such lines in the Mixer, a MIXERR_INVALLINE error is returned). Once you have that info, you can then . MIXERCONTROL structures, and enumerating controlsYou use the mixer API mixerGetLineControls () to retrieve info about controls for a line. This API fills in a MIXERCONTROL struct with info about a control. . Let's examine the MIXERCONTROL struct As mentioned before, our "Speaker Out" destination line has 2 controls; a volume slider, and a mute switch Each one of these controls will have one MIXERCONTROL associated with it Let's examine the MIXERCONTROL for each of.. THESE CONTROLS: MixerControl Mixerctl_spkr_vol = { SizeOf (MixerControl), / * size of a mixerControl * / 0x00000000, / * unique ID # for this control * / MixerControl_ControlType_Volume, / * type of control * / MixerControl_Controlf_Uniform, / * flag bits * / 0, / * # of items per channel (useless only if the MixerControl_Controlf_Multiple Flag Bit Is Also Set * / "Volume", / * Short name for this control * / "Speaker Out Volume", / * Long Name for this Control * / 0, / * minimum value to which this control can be set * / 65535, / * Maximum Value to Which this Control Can Be set * / 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / 31, / * step amount for the value * / 0, 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / } MixerControl Mixerctl_sp Kr_Mute = { SizeOf (MixerControl), 0x00000001, / * Unique ID # for this control * / MixerControl_ControlTyPE_Mute, / * Type of Control * / MixerControl_Controlf_Uniform, 0, "Mute", / * short name for this control * / "Speaker Out Mute", / * Long Name for this Control * / 0, / * minimum value to which this control can be set * / 1, / * Maximum Value to Which this Control Can Be set * / 0, 0, 0, 0, 0, / * step amount for the value * / 0, 0, 0, 0, 0, } There are several things to note above. First, note that each control has a unique ID. These ID numbers do not have to be unique with regard to the IDs of lines. (For example, the control ID of the mixerctl_Spkr_Vol control happens to be the same as the line ID of the mixerline_CD line). But, each control must have an ID unique from any other control, including the controls of other lines. (For example, the volume slider of the "Speaker Out" line can ' T Have The Same ID Number As The Mute Switch of The "ADC WAVE IN" LINE). I have set the MIXERCONTROL_CONTROLF_UNIFORM flag. What this means is that, although the "Speaker Out" is stereo (ie, it has 2 channels), there is not a separate volume control for each channel. (There are not individual, left channel and right channel volume settings). There is only one volume setting for both channels, and therefore both channels will be set to the same volume always. (Later, we'll study controls that are not uniform) .Also note that each control has An Appropriate Type. The Volume Slider Has A MixerControl_ControlType_Volume Type, And The Mute Switch Has A MixerControl_ControlTyPE_Mute Type. The MIXERCONTROL tells you what the min and max values can be for the control. For example, the volume slider can be set to any value inbetween 0 and 65,535. 0 is the minimum setting (ie, volume is lowest), and 65,535 is the maximum setting (ie, volume is loudest). So, does that mean that the volume slider has 65,535 discrete steps? (ie, Can it be set to any value from 0 to 65,535, inclusive)? Not necessarily. You also have to look .. at the step amount field This tells you how many valid steps the control has In this case, we have 31 valid steps This means that the first valid setting is 0, but the second valid setting is 65,535 -. (65,535 / 31) and the third valid setting is 65,535 - (65,535 / (31 * 2)), etc. in other words, we have only 31 valid settings within that 0 to 65,535 range (NOTE:. the dwMinimum / dwMaximum fields are declared in a union WITH The LMINIMUM / LMAXIMUM FIELDS. You'll Reference The Former Two WHEN DEALING WITH A Control Type with an unsigned value - IE, A Control Type W hose value is set with a MIXERCONTROLDETAILS_BOOLEAN or MIXERCONTROLDETAILS_UNSIGNED struct You'll reference the latter two when dealing with a control type with a signed value -. ie, a control type whose value is set with a MIXERCONTROLDETAILS_SIGNED struct) .Enumerating controls is a bit different than enumerating lines. for one thing, you do not employ indexes with controls. Secondly, you can retrieve info about a single control only if you already know its control ID number. Otherwise, you must simultaneously retrieve info for all the controls for a given line. Obviously, when you're first enumerating the controls for a line, you do not know the ID of each control. So you need to retrieve info on all of the controls with a single call to mixerGetLineControls (). In this case, you need to pass mixerGetLineControls () an array of MIXERCONTROL structs There must be one struct for every control in the line.For example, we know that our "Speaker Out" destination line has 2 controls;. a volume slider, and a mute switch. (Remember that its MIXERLINE's cControls field is 2). So, to retrieve information about them, we must pass mixerGetLineControls () an array containing 2 MIXERCONTROL structs. We must also pass the value MIXER_GETLINECONTROLSF_ALL to indicate we want info on all the controls. We also pass a special structure called a MIXERLINECONTROLS which we must first initialize. This structure tells mixerGetLineControls () for which line we want to receive info about its controls. We also provide the pointer to our array of via MIXERCONTROL structs th IS additional struct. Here the an an esample of retrieving Info About All The Controls in The "Speaker Out" LINE. / * Let's just declare an array of 2 MixerControl Structs Since WE KNOW That The "Speaker Out" HAS 2 Controls. For A Real Program, You Typically Won't Know Ahead of Time How Big An Array You'll NEED, And Therefore Would Instead Allocate An Appropriately Size Array * / MixerControl MixerControlarray [2]; MixerLineControls MixerLineControls; MmResult ERR; MixerLineControls.cbstruct = sizeof (MixerLineControls); / * The "Speaker Out" Line Has A Total of 2 Controls. And That's how much we want to retrieve info for here * / MixerLineControls.cControls = 2; / * Tell MixergetLineControls () for Which Line We're RetrieVing Info. We do this by putting the desired line's id number in dwlineid. The "Speaker Out" line HAS AN ID OF 0xFFFFF0000 * / MixerLineControls.dwlineId = 0xffff0000; / * Give mixergetLineControls () The Address of Our Array Of MixerControl Structs Big Enough To Hold Info on All Controls * / MixerLineControls.Pamxctrl = & MixerControlarray [0]; / * Tell MixergetLineControls () How Big Each MixerControl IS. This Saves Having to Initialize The CBStruct of Each Individual MixerControl in the array * / MixerLineControls.cbmxctrl = sizeof (MixerControl); / * Retrieve Info on All Controls for this line simultaneously * / IF ((Err = MixergetLineControls ((HMixerobj) MixerHandle, & MixerLineControls, Mixer_GetLineControlsf_all)))))) { / * An error * / Printf ("Error #% D calling mixergetLineControls () / n", ERR); } When mixerGetLineControls () returns above, our mixerControlArray [] array will have been filled in. MixerControlArray [0] will have been filled in as per the mixerctl_Spkr_Vol MIXERCONTROL struct shown above, and mixerControlArray [1] will have been filled in as per the mixerctl_Spkr_Mute . It's possible to retrieve info on only one control, if you know its ID or Type. But it is not possible to retrieve info on more than one control, but less than the total number of controls. For example, assume that our "Speaker Out "Had 5 Controls (Instead of Only 2). You COULDN '' RETRIEVE INFO ON ONLY THE FIRST 3, for Example. You Can Either Retrieve Info On One (ORA) AT A TIME, ORL 5 of THEM AT ONCE . (ie, It's either one at a time, or all) .Getting info about a control by its IDOnce you know a control's ID number (which you can extract from its MIXERCONTROL's dwControlID field after enumerating the control as shown above), you can later retrieve info on just this one control by referencing its ID. you do not even need to know the ID of the line to which this control belongs. And you are not forced to retrieve info for all of the other controls in this line You melely Initialize the MixerLineControls's DWControlid Field to the ID Number of the Desired Control, and then specify mixer_getlinecontrolsf_onebyid when calling mixergetlineControls () AS SO: / * WE NEED ONLY 1 MIXERCONTROL STRUCT SINCE We're Fetching Info for Only 1 Control * / MixerControl MixerControlarray; MixerLineControls MixerLineControls; MmResult ERR; MixerLineControls.cbstruct = sizeof (MixerLineControls); / * WE Want to Fetch Info On Only 1 Control * / MixerLineControls.cControls = 1; / * Tell MixergetLineControls () for Which Control We're RetrieVing Info. we do this by putting the desired control's id number in DWControlid. The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerLineControls.dwcontrolid = 0x00000000; / * Give mixergetLineControls () The Address of ThemixerControl Struct to Hold Info * / MixerLineControls.Pamxctrl = & MixerControlarray; / * Tell MixergetLineControls () How big the mixerControl is. THIS. THIS. Saves Having to Initialize The Cbstruct of The MixerControl itself * / MixerLineControls.cbmxctrl = sizeof (MixerControl); / * Retrieve Info On Only The Volume Slider Control for The Volume Slider Control for the "Speaker Out" Line * / IF ((Err = MixergetLineControls ((hmixerobj) MixerHandle, & MixerLineControls, Mixer_GetLineControlsf_onebyid))))) { / * An error * / Printf ("Error #% D calling mixergetLineControls () / n", ERR); } Getting info about a control by its TypeOften, you do not need to know about all of the controls in a line. You may be writing a program that would deal only with a specific type of control. For example, let's say that you ' re writing a simple MIDI file player and the only control you want to present to the enduser is the volume slider of the "Synth". you saw earlier how you could search for that MIDI playback component by Type and fill in a MIXERLINE struct with info About IT, Such As ITS Line ID. You can one, one, for a part, for example, you can search for a control with a type of mixerControl_controlType_volume. So, rather than enumerating all of the controls in the line until you come to the one with the MIXERCONTROL_CONTROLTYPE_VOLUME type, mixerGetLineControls () lets you directly get info about a line that matches your desired type. You merely initialize the MIXERLINECONTROLS's dwControlType field to the desired type of control, and then specify MIXER_GETLINECONTROLSF_ONEBYTYPE when calling mixerGetLineControls () as so (Assume that you've already fetched the line ID for the "Synth" line, and stored it in "SynthID") MIXERCONTROL mixerControlArray..; MixerLineControls MixerLineControls; MmResult ERR; MixerLineControls.cbstruct = sizeof (MixerLineControls); / * Tell MixergetLineControls () for Which Line We're RetrieVing Info. We do this by putting the desired line's id number in dwlineid * / MixerLineControls.dwlineid = SYNTHID; / * WE Want to Fetch Info On Only 1 Control * / MixerLineControls.cControls = 1; / * Tell MixergetLineControls () for Which Type of Control WE'RE Retrieving info. we do this by putting the desired control type. IPETING TYPE In dwcontroltype * / MixerLineControls.dwcontrolType = MixerControl_ControlType_Volume; / * Give MixergetLineControls () The Address of The MixerControl struct to hold info * / MixerLineControls.Pamxctrl = & MixerControlarray; / * Tell MixergetLineControls () How big the mixerControl is. THIS. THIS. Saves Having to Initialize The Cbstruct of The MixerControl itself * / MixerLineControls.cbmxctrl = sizeof (MixerControl); / * Retrieve Info On Only Any Volume Slider Control for this line * / IF ((Err = MixergetLineControls ((HMixerobj) MixerHandle, & MixerLineControls, Mixer_GetLineControlsf_onebytype))))))) { / * An error * / Printf ("Error #% D calling mixergetLineControls () / n", ERR); } This will fill in the MIXERCONTROL struct with info about the first control in the line which has a type of MIXERCONTROL_CONTROLTYPE_VOLUME. (If there are no such controls in the line, a MIXERR_INVALCONTROL error is returned). Once you have that info, you can then directly manipulate that control. for example, you can extract its control ID number from the MIXERCONTROL's dwControlID field. This saves having to enumerate and search for a desired control when your needs are specific. Retrieving and setting a control's valueNow we're getting to the whole purpose of a mixer; to retrieve a control's value (so that you can display its current setting to the enduser), and to set a control's value (so that you can allow the Enduser to adjounce it). To retrieve or set a control's value, you must know its control ID. You use mixerGetControlDetails () to retrieve its current value, and mixerSetControlDetails () to set it to a specific value. These functions utilize a MIXERCONTROLDETAILS struct. You initialize certain fields to Tell MixergetControlDetails () / MixerSetControlDetails () / MixersetControlDetails () What Control whose value You're retrieving / setting, and you also support / setting, and you also supply a point. For example, let's consider retrieving the current value of the "Speaker Out" line's volume slider. By now, you know how to get info on that control, for example, its ID number. In order to retrieve a control's value, we need to supply a special structure into which its value is returned. What kind of structure do we use? Well, that depends upon what type of control it is. The volume slider is a MIXERCONTROL_CONTROLTYPE_VOLUME type. If you go back to the chart about the fader class of controls, it tells you that its value is retrieved using a MIXERCONTROLDETAILS_UNSIGNED struct This struct has only one field into which the control's value is returned;... dwValue So we supply a MIXERCONTROLDETAILS_UNSIGNED struct to mixerGetControlDetails () (via the MIXERCONTROLDETAILS struct) Here THEN IS An Example, of Retrieving and Printing The Current Value of The "Speaker Out" Line's Volume Slider: / * We Need A MixerControlDails_unsigned Struct To Retrieve T Value of a control whose type is mixerControl_ControlType_volume * / MixerControlDetails_unsigned value; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixergetControlDetails () Which Control Whose Value WE Want to Retrieve. We do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * This is always 1 for a mixerControl_Controlf_uniform control * / MixerControlDetails.cchannels = 1; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * give mixergetControlDetails () The address of the MixerControlDetails_unsigned struct into which to return the value * / MixerControlDetails.padetails = & value; / * Tell MixergetControlDetails () How big the mixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Retrieve The Current Value of The Volume Slider Control for this line * / IF ((Err = MixergetControlDetails, & MixerControlDetails, Mixer_GetControlDetailsf_value))))))) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { Printf ("IT's Value IS% Lu / N", Value.dwValue); } To set a control's value, you simply fill in the special structure that contains the value, and pass it to mixerSetControlDetails (). You also specify MIXER_SETCONTROLDETAILSF_VALUE. Here is an example of setting the "Speaker Out" line's volume slider to a value of 31 : MixerControlDetails_unsigned value; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixersetControlDetails () Which Control Whose Value WE Want to set. we do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * This is always 1 for a mixerControl_Controlf_uniform control * / MixerControlDetails.cchannels = 1; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * Give MixersetControlDetails () The Address of ThemixerControlDetails_unsigned Struct Into Which We Place the value * / MixerControlDetails.padetails = & value; / * Tell MixersetControlDetails () How big the mixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * STORE the value * / Value.dwvalue = 31; / * SET the value of the volume slider control for this line * / IF ((Err = MixersetControlDetails ((hmixerobj) MixerHandle, & MixerControlDetails, Mixer_SetControlDetailsf_Value)))))) { / * An error * / Printf ("Error #% D calling mixersetControlDetails () / N", ERR); } Multi-channel controlsAs mentioned, when a control's MIXERCONTROL_CONTROLF_UNIFORM flag bit is set, then it does not have individual values for each one of its channels. For example, with the "Speaker Out", there is not a separate volume for the left and Right Channels of this Stereo Line. But if a control's MIXERCONTROL_CONTROLF_UNIFORM flag bit is not set, and it has more than one channel, then each channel has its own value. For this reason, you'll need more than one of the special structures to retrieve / set the values for all channels. for example, let's assume that the volume slider for the "Speaker Out" does not have its MIXERCONTROL_CONTROLF_UNIFORM flag bit set. Since the Speaker Out line has 2 channels, that means that we need 2 MIXERCONTROLDETAILS_UNSIGNED structs to retrieve / set the value for the Left and Right channels' volumes respectively. We need to use an array of MIXERCONTROLDETAILS_UNSIGNED structs. The first MIXERCONTROLDETAILS_UNSIGNED struct will be for the first (ie, Left) channel, and the second MIXERCONTROLDETAILS_UNSIGNED struct will be for the second (ie, Right) Channel. Here is an esample of retrieving the value of our volume slider for the "speaker out" line: / * We need 2 MixerControlDetails_unsigned Structs to r Etrieve the VALUES OF A Stereo Control That IS Not MixerControl_Controlf_Uniform * / MixerControlDetails_unsigned value [2]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixergetControlDetails () Which Control Whose Value WE Want to Retrieve. We do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * WE Want to Retrieve Values for Both Channels * / MixerControlDetails.cchannels = 2; / * This is always 0 Except for a mixerControl_Controlf_multiple control * / mixerControlDetails.cmultipleitems = 0; / * Give mixergetControlDetails () The address of the MixerControlDetails_unsigned array into which to return the value * / MixerControlDetails.padetails = & value [0]; / * Tell MixergetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Retrieve The Current Values Of Both Channels * / IF ((Err = MixergetControlDetails, & MixerControlDetails, Mixer_GetControlDetailsf_value))))))) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { Printf ("The Left Channel's Volume IS% Lu / N", Value [0] .dwvalue); Printf ("THE Right Channel's Volume IS% Lu / N", Value [1] .dwvalue); } To set the values of both channels, you fill in the values of both MIXERCONTROLDETAILS_UNSIGNED structs. Here is an example of setting the left channel's volume to 31 and the right channel's volume to 0. / * WE NEED 2 MIXERCONTROLDETAILS_UNSIGNED STRUCTS TO SET THE VALUES OF A Stereo Control That IS Not MixerControl_Controlf_Uniform * / MixerControlDetails_unsigned value [2]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixersetControlDetails () Which Control Whose Value WE Want to set. we do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * We want to set value for Both Channels * / MixerControlDetails.cchannels = 2; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * Give MixersetControlDetails () The Address of The MixerControlDetails_unsigned structs Into Which We Place the values * / MixerControlDetails.padetails = & value [0]; / * Tell MixersetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Store The Left Channel's Value * / Value [0] .dwvalue = 31; / * Store The Right Channel's Value * / Value [1] .dwvalue = 0; / * SET The Left / Right Values of the Volume Slider Control for this line * / IF ((Err = MixersetControlDetails ((hmixerobj) MixerHandle, & MixerControlDetails, Mixer_SetControlDetailsf_Value)))))) { / * An error * / Printf ("Error #% D calling mixersetControlDetails () / N", ERR); } Of course, a control may have even more than 2 channels. You always need an array of special structures large enough to accomodate all channels for a given control, so typically, you'll allocate the array as needed. It is not legal to retrieve or set only some of the channels. For example, if a control has 8 channels, it's not legal to try to retrieve the values of only the first 2 channels. You must always retrieve / set the values of all channels simultaneously. But there is one caveat to this rule. It concerns setting a value. If you set only the value for the first channel, then mixerSetControlDetails () automatically treats the control as if it was MIXERCONTROL_CONTROLF_UNIFORM. The net result is that all channels get set to that one value. So, you can quickly set all channels to the same value just by setting the value of only the first channel.Multi-item controlsYou will not often encounter multi-item controls. A multi-item control is one that has several values associated with each channel An example could be a graphic equalizer control Let's study a simple example Assume that you have the following 3 band graphic equalizer built into a sound card...: This Control Has Three Values Associated with It - The value for the "low" band, the value for the "mid" band, and the value for the "high" band. (IE, IT IS Assumed That Each Band Can Be Set To a Different Value, Otherwise It Would Be a fairly useless graphic EQ). The Way That 10Em Control. It has it. It, values. Associated with it. Let's Further Assume That THIS Control is in the "speaker out" line. Let's examine its MIXERCONTROL struct. A multi-item control has the MIXERCONTROL_CONTROLF_MULTIPLE bit set of its MIXERCONTROL's dwControlType field. The MIXERCONTROL's cMultipleItems field will also tell how many items are in each channel. MixerControl Mixerctl_eq = { Sizeof (MixerControl), / * Size of a mixerControl * / 0x00000002, / * unique ID # for this control * / MixerControl_ControlType_equalizer, / * Type of Control * / MixerControl_Controlf_uniform | MixerControl_Controlf_Multiple, / * flag bits * / 3, / * # of items per channel * / "EQ", / * short name for this control * / "Graphic Equalizer", / * long name for this control * / 0, / * minimum value to which this control can be set * / 65535, / * Maximum Value to Which this Control Can Be set * / 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / 31, / * step amount for the value * / 0, 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / } First of all, note that the ID is different than all of the other controls for this Mixer. Also, note that its MIXERCONTROL_CONTROLF_MULTIPLE flag bit is set. The cMultipleItems field is set to 3 to indicate that there are 3 items per channel. (But Since I Made this Control MixerControl_Controlf_uniform, IT Still Has Only 3 Values Total, Even Though The "Speaker Out" Line Is Stereo. In Other Words, The Value for Each Band Affects Both Channels Equally. To query the values for all 3 bands, we need an array of 3 structures to fetch the values. What kind of structures? Well, the MIXERCONTROL_CONTROLTYPE_EQUALIZER control type is of the fader class, and you'll remember that all the types in that class Use a mixercontroldetails_unsigned struct to set / fetch value. Here's how we query the current value of the 3 bands: / * WE NEED 3 MIXERCONTROLDETAILS_UNSIGNED STRUCTS TO RETRIEVE THE VALUE OF A Control Whose Type Is MixerControl_ControlType_Volume * / MIXERCONTROLDETAILS_UNSIGNED value; MIXERCONTROLDETAILS mixerControlDetails; MMRESULT err; mixerControlDetails.cbStruct = sizeof (MIXERCONTROLDETAILS); / * Tell mixerGetControlDetails () which control whose value we want to retrieve We do this by putting the desired control's ID number in dwControlID Remember that the ".. Speaker Out "line's volume slider has an ID of 0x00000000 * / mixerControlDetails.dwControlID = 0x00000000; / * This is always 1 for a MIXERCONTROL_CONTROLF_UNIFORM control * / mixerControlDetails.cChannels = 1; / * This is always 0 except for a MIXERCONTROL_CONTROLF_MULTIPLE control * / mixerControlDetails.cMultipleItems = 0; / * Give mixerGetControlDetails () the address of the MIXERCONTROLDETAILS_UNSIGNED struct into which to return the value * / mixerControlDetails.paDetails = & value; / * Tell mixerGetControlDetails () how big the MIXERCONTROLDETAILS_UNSIGNED is * / mixerControlDetails.cbDetails = sizeof (MixerControlDetails_unsigned; / * Retrieve The Current Value of The Volume slider control for this line * / if ((err = mixerGetControlDetails ((HMIXEROBJ) mixerHandle, & mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE))) {/ * An error * / printf ( "Error #% d calling mixerGetControlDetails () / n", err); } else {printf ( "It's value is% lu / n", value.dwValue);} 90 to set a control's value, you simply fill in the special structure that contains the value, and pass it to mixerSetControlDetails () you also. . specify MIXER_SETCONTROLDETAILSF_VALUE Here is an example of setting the "Speaker Out" line's volume slider to a value of 31: MIXERCONTROLDETAILS_UNSIGNED value; mIXERCONTROLDETAILS mixerControlDetails; MmResult Err; MixerControlDetails.cbstruct = SizeOf (MixerControlDetails); / * Tell MixersetControlDetails () Which Control Whose Value WE Want to set. we do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * This is always 1 for a mixerControl_Controlf_uniform control * / MixerControlDetails.cchannels = 1; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * Give MixersetControlDetails () The Address of The MixerControlDetails_unsigned struct Into Which We Place the value * / MixerControlDetails.padetails = & value; / * Tell MixersetControlDetails () How big the mixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * STORE the value * / Value.dwvalue = 31; / * SET the value of the volume slider control for this line * / IF ((Err = MixersetControlDetails ((hmixerobj) MixerHandle, & MixerControlDetails, Mixer_SetControlDetailsf_Value)))))) { / * An error * / Printf ("Error #% D calling mixersetControlDetails () / N", ERR); } Multi-channel controls As mentioned, when a control's MIXERCONTROL_CONTROLF_UNIFORM flag bit is set, then it does not have individual values for each one of its channels. For example, with the "Speaker Out", there is not a separate volume for the left and right channels of this stereo line. But if a control's MIXERCONTROL_CONTROLF_UNIFORM flag bit is not set, and it has more than one channel, then each channel has its own value. For this reason, you'll need more than one of the special structures to retrieve / set the values for all channels. for example, let's assume that the volume slider for the "Speaker Out" does not have its MIXERCONTROL_CONTROLF_UNIFORM flag bit set. Since the Speaker Out line has 2 channels, that means that we need 2 MIXERCONTROLDETAILS_UNSIGNED structs to retrieve / set the value for the Left and Right channels' volumes respectively. We need to use an array of MIXERCONTROLDETAILS_UNSIGNED structs. The first MIXERCONTROLDETAILS_UNSIGNED struct will be for the first . (Ie, Left) channel, and the second MIXERCONTROLDETAILS_UNSIGNED struct will be for the second (ie, Right) channel Here is an example of retrieving the values of the left and right channels of our volume slider for the "Speaker Out" line: / * WE NEED 2 MIXERCONTROLDETAILS_UNSIGNED STRUCTS TO RETRIEVE Thevalues of a Stereo Control That Is Not MixerControl_Controlf_Uniform * / MixerControlDetails_unsigned value [2]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixergetControlDetails () Which Control Whose Value WE Want to Retrieve. We do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That the "Speaker Out" line'svolume slider has an id of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * WE Want to Retrieve Values for Both Channels * / MixerControlDetails.cchannels = 2; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * Give mixergetControlDetails () The address of the MixerControlDetails_unsigned array into which to return the value * / MixerControlDetails.padetails = & value [0]; / * Tell MixergetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Retrieve The Current Values Of Both Channels * / IF ((Err = MixergetControlDetails, & MixerControlDetails, Mixer_GetControlDetailsf_value))))))) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { Printf ("The Left Channel's Volume IS% Lu / N", Value [0] .dwvalue); Printf ("THE Right Channel's Volume IS% Lu / N", Value [1] .dwvalue); } To set the values of both channels, you fill in the values of both MIXERCONTROLDETAILS_UNSIGNED structs. Here is an example of setting the left channel's volume to 31 and the right channel's volume to 0. / * We need 2 MIXERCONTROLDETAILS_UNSIGNED structs to set the VALUES OF A Stereo Control That IS Not MixerControl_Controlf_Uniform * / MixerControlDetails_unsigned value [2]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixersetControlDetails () Which Control Whose Value WE Want to set. we do this by Putting The Desired Control's ID Number in dwcontrolid. Remember That The "Speaker Out" Line's Volume Slider Has An ID Of 0x00000000 * / MixerControlDetails.dwcontrolid = 0x00000000; / * WE Want to set value for Both Channels * / MixerControlDetails.cchannels = 2; / * This is always 0 except for a mixerControl_Controlf_multiple control * / MixerControlDetails.cmultipleitems = 0; / * Give MixersetControlDetails () The Address of The MixerControlDetails_unsigned structs Into Which We Place the values * / MixerControlDetails.padetails = & value [0]; / * Tell MixersetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Store The Left Channel's Value * / Value [0] .dwvalue = 31; / * Store The Right Channel's Value * / Value [1] .dwvalue = 0; / * SET The Left / Right Values of the Volume Slider Control for this line * / IF ((Err = MixersetControlDetails ((hmixerobj) MixerHandle, & MixerControlDetails, Mixer_SetControlDetailsf_Value)))))) { / * An error * / Printf ("Error #% D calling mixersetControlDetails () / N", ERR); } Of course, a control may have even more than 2 channels. You always need an array of special structures large enough to accomodate all channels for a given control, so typically, you'll allocate the array as needed. It is not legal to retrieve or set only some of the channels. For example, if a control has 8 channels, it's not legal to try to retrieve the values of only the first 2 channels. You must always retrieve / set the values of all channels simultaneously. But there is one caveat to this rule. It concerns setting a value. If you set only the value for the first channel, then mixerSetControlDetails () automatically treats the control as if it was MIXERCONTROL_CONTROLF_UNIFORM. The net result is that all channels get set to that one value . So, you can quickly set all channels to the same value just by setting the value of only the first channel. Multi-item controls you will not often encounter multi-item controls. A multi-item control is one that has several values Associated with Each Channel. AN Equalizer COULD BE A Graphic Equalizer Control. Assume That You Have The Following 3 Band Graphic Equalizer Built INTO A Sound Card: This Control Has Three Values Associated with It - The value for the "low" band, the value for the "mid" band, and the value for the "high" band. (IE, IT IS Assumed That Each Band Can Be Set to a different value, otherwise it would be a fairly useless graphic EQ). The way that this would be represented is aa multi-item control. It has 3 items (ie, values) associated with it. Let's further assume that this control is in the "Speaker Out" line. Let's examine its MIXERCONTROL struct. A multi-item control has the MIXERCONTROL_CONTROLF_MULTIPLE bit set of its MIXERCONTROL's dwControlType field. The MIXERCONTROL's cMultipleItems field will also tell how many items are in each channel. MIXERCONTROL mixerctl_EQ = {sizeof (MixerControl), / * Size of a mixerControl * / 0x00000002, / * Unique ID # for this control * / MixerControl_ControlType_equalizer, / * Type of Control * / MixerControl_Controlf_uniform | MixerControl_Controlf_Multiple, / * flag bits * / 3, / * # of items per channel * / "EQ", / * short name for this control * / "Graphic Equalizer", / * long name for this control * / 0, / * minimum value to which this control can be set * / 65535, / * Maximum Value to Which this Control Can Be set * / 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / 31, / * step amount for the value * / 0, 0, 0, 0, 0, / * THESE FIELDS Are Reserved for Future Use * / } First of all, note that the ID is different than all of the other controls for this Mixer. Also, note that its MIXERCONTROL_CONTROLF_MULTIPLE flag bit is set. The cMultipleItems field is set to 3 to indicate that there are 3 items per channel. (But since I made this control MIXERCONTROL_CONTROLF_UNIFORM, it still has only 3 values total, even though the "Speaker Out" line is stereo. In other words, the value for each band affects both channels equally). To query the values for all 3 bands, we need an array of 3 structures to fetch the values. What kind of structures? Well, the MIXERCONTROL_CONTROLTYPE_EQUALIZER control type is of the fader class, and you'll remember that all the types in that class use a MIXERCONTROLDETAILS_UNSIGNED struct to set / fetch values . Here's how we query the current value of the 3 Bands: / * We need 3 MixerControlDetails_unsigned structs to retrieve thevalues of this control * / MixerControlDetails_unsigned value [3]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixergetControlDetails () Which Control Whose Value WE Want to Retrieve * / MixerControlDetails.dwcontrolid = 0x00000002; / * It's a MixerControl_Controlf_uniform Control, So The Values For All Channels Are The Same as the first * / MixerControlDetails.cchannels = 1; / * There Are 3 items per channel * / MixerControlDetails.cmultipleitems = 3; / * Give mixergetControlDetails () The address of the MixerControlDetails_unsigned array into which to return the value * / MixerControlDetails.padetails = & value [0]; / * Tell MixergetControlDetails () How Big Each MixerControlDetails_unsigned is * / mixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Retrieve The Current Values Of All 3 Bands * / IF ((Err = MixergetControlDetails, & MixerControlDetails, Mixer_GetControlDetailsf_value))))))) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { Printf ("THE LOW BAND IS% Lu / N", Value [0] .dwvalue); Printf ("THE MID BAND IS% Lu / N", Value [1] .dwvalue; Printf ("THE HIGH BAND IS% Lu / N", Value [2] .dwvalue); } To set the values of all 3 bands, you fill in the values of the MIXERCONTROLDETAILS_UNSIGNED structs. Here is an example of setting the Low band to 31, the Mid band to 0, and the High band to 62. / * We need 3 MIXERCONTROLDETAILS_UNSIGNED Structs to set the Values of the 3 bands * / MixerControlDetails_unsigned value [3]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixersetControlDetails () Which Control Whose Values WE Want to set * / MixerControlDetails.dwcontrolid = 0x00000002; / * The value for all channel channel channel * / MixerControlDetails.cchannels = 1; / * We're setting all 3 bands * / MixerControlDetails.cmultipleitems = 3; / * Give MixersetControlDetails () The Address of The MixerControlDetails_unsigned structs Into Which We Place the values * / MixerControlDetails.padetails = & value [0]; / * Tell MixersetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Store the Low Band's Value * / Value [0] .dwvalue = 31; / * Store the Mid Band's Value * / Value [1] .dwvalue = 0; / * Store the High Band's value * / Value [2] .dwvalue = 62; / * SET the VALUES of the 3 Bands for this Control * / IF ((Err = MixersetControlDetails ((hmixerobj) MixerHandle, & MixerControlDetails, Mixer_SetControlDetailsf_Value)))))) { / * An error * / Printf ("Error #% D calling mixersetControlDetails () / N", ERR); } Now let's remove that MIXERCONTROL_CONTROLF_UNIFORM flag bit of the MIXERCONTROL. Now, each channel's items have individual values. Since the "Speaker Out" has 2 channels, that means we have a total of 2 (channels) * 3 (items), or 6 values Total for this Control. Our Graphic Eq Now Looks Like this: Left Channelright Channel We're going to need 6 MIXERCONTROLDETAILS_UNSIGNED structs to fetch the values of all items in all channels. Oh, and in the preceding example, I assumed what the labels were for those items. What you really should do is ask the Mixer to provide you with the labels if you wish to print them out. to do this, you must supply an array of MIXERCONTROLDETAILS_LISTTEXT structs, just like how you use an array of MIXERCONTROLDETAILS_UNSIGNED structs to fetch the values of all items in all channels / * We need 6 MIXERCONTROLDETAILS_UNSIGNED Structs to Retrieve the Values of this control * / MixerControlDetails_unsigned value [6]; / * WE NEED 6 MIXERCONTROLDETAILS_LISTTEXT STRUCTS TO RETRIEVE THE Labels of all items * / MixerControlDetails_ListText Label [6]; MixerControlDetails MixerControlDetails; MmResult ERR; MixerControlDetails.cbstruct = sizeof (MixerControlDetails); / * Tell MixergetControlDetails () Which Control Whose Value Wewant To Retrieve * / MixerControlDetails.dwcontrolid = 0x00000002; / * OUR "Speaker Out" HAS 2 Channels * / MixerControlDetails.cchannels = 2; / * There Are 3 items per channel * / MixerControlDetails.cmultipleitems = 3; / * Give mixergetControlDetails () The address of the MixerControlDetails_unsigned array into which to return the value * / MixerControlDetails.padetails = & value [0]; / * Tell MixergetControlDetails () How Big Each MixerControlDetails_unsigned is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_unsigned); / * Retrieve The Current Values Of All 3 Bands for Both Channels * / IF ((Err = MixergetControlDetails, & MixerControlDetails, Mixer_GetControlDetailsf_value))))))) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { Unsigned long i, n; / * Let's fetch the lambs of all the items * / MixerControlDetails.cbstruct = sizeof (MixerControlDetails); MixerControlDetails.dwcontrolid = 0x00000002; MixerControlDetails.cchannels = 2; MixerControlDetails.cmultipleitems = 3; / * Give mixergetControlDetails () The address of the MixerControlDetails_ListText Array Into Which To Return The Labels * / MixerControlDetails.padetails = & label [0]; / * Tell MixergetControlDetails () How Big Each MixerControlDetails_listText is * / MixerControlDetails.cbdetails = sizeof (MixerControlDetails_listtext); / * Retrieve The Labels of All Items for Both Channels, Note That I specify mixer_getcontroldetailsf_listtext * / IF ((Err = MixergetControlDetails) ((HMixerobj) MixerHandle, & MixerControlDetails, Mixer_GetControlDetailsf_listtext)) { / * An error * / Printf ("Error #% D Calling MixergetControlDetails () / N", ERR); } Else { / * Print The Values of All Items * / For (i = 0; i <2; i ) { Printf ("CHANNEL% lu: / n", i 1); For (n = 0; n <3; n ) { Printf ("/ TTHE% S Item IS% lu / n", label [3 * i n] .szname, Value [3 * i n] .dwvalue); } } } } It is not legal to retrieve or set only some of items of a control. For example, if a control has 8 items, it's not legal to try to retrieve the values of only the first 2 items. You must always retrieve / set the values of all items for all channels simultaneously. The one caveat to this rule is that if you set only the items for the first channel, then mixerSetControlDetails () automatically treats the control as if it was MIXERCONTROL_CONTROLF_UNIFORM. The net result is that the items for all channels get set to the same values as the first channel. So, you can quickly set all channels to the same values just by setting the items of only the first channel. Notification of changes In my above examples, I have shown that the mixer device is always opened with mixerOpen () and its handle retrieved for use with other mixer functions. This is not always necessary. In fact, the mixer API has been designed so that, instead of passing a handle to an open mixer wherever any mixer function specif ies such an arg, you can instead pass the mixer ID number of the desired mixer. So, you do not need to open a mixer explicitly. But there are advantages to explicitly opening a mixer (with mixerOpen ()) for as long as you need to do operations upon it. First, this prevents the mixer from somehow being "unloaded" (presumably by the audio card's driver). Secondly, when you have a mixer open, you can instruct Windows to send you a special message (to the window procedure of some window that you've created) whenever any line's state has changed (for example, if the line is muted), or the value of some control has been changed. you get sent such a message not only when you change a Line's State or A Control ' s value, but also when any other program also opens that mixer (ie, more than one program can open the same mixer simultaneously) and changes a line or control. So, you can keep your program in sync with any changes made to the mixer by any other program. When you call mixerOpen (), you specify the handle to your own window which you wish Windows to send its special "mixer messages". Pass your window handle as the third arg to mixerOpen (). Also specify CALLBACK_WINDOW as the last arg. There are 2 special "mixer messages". MM_MIXM_LINE_CHANGE is sent to your window procedure whenever a line's state is changed. MM_MIXM_CONTROL_CHANGE is sent whenever a control's value is changed. For MM_MIXM_LINE_CHANGE, the WPARAM argument to your window procedure is the handle of the open mixer whose line has changed. The LPARAM argument is the ID number of the line whose state has changed. For MM_MIXM_CONTROL_CHANGE, the WPARAM argument to your window procedure is the handle of the open mixer whose lin e has changed. The LPARAM argument is the ID number of the control whose value has changed. Conclusion The Mixer API is one of the most complicated APIs regarding Windows multi-media. It may take awhile to absorb this tutorial and apply it to your needs . But the Mixer API gives you a way to make adjustments to the settings of any sound card without needing to be specifically written for that card. for more information about structures and APIs about mixers, see Microsoft Developer Network '