Click here to Skip to main content
13,147,376 members (27,123 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 9 Jan 2000

Simple Mixer Control Wrapper

, 9 Jan 2000
Rate this:
Please Sign up or sign in to vote.
A small audio mixer control wrapper
  • Download source files - 2.7 Kb
  • <!-- Article Starts -->

    This is small and useful C++ class which can encapsulate any windows multimedia mixer control.

    I wrote a simple class CAlexfMixer to wrap any multimedia mixer control. You can manipulate the Master Volume, Mute or someone elses mixer control with this class, as long as the control support these operations. You can also retrieve information such as the Peak Meter.

    Let's look at class definition:

    class CAlexfMixer
      HMIXER m_HMixer;
      INT m_iMixerControlID;
      MMRESULT mmr;
      DWORD m_dwChannels;
      BOOL m_bSuccess;
      void ZeroAll();
      BOOL IsOk() {return m_bSuccess;};
      BOOL On();
      BOOL Off();
      DWORD GetControlValue();
      BOOL SetControlValue(DWORD dw);
      CAlexfMixer(DWORD DstType, DWORD SrcType, DWORD ControlType);
      CAlexfMixer(HWND hwnd, DWORD DstType, DWORD SrcType, DWORD ControlType);
      virtual ~CAlexfMixer();

    The class has two constructors - with and without the callback window.

    The class has member IsOk to check whether the specified control can be manipulated, and member functions to get and set the control's state.

    How it works

    Example 1. Master Volume Control.

    if (!mixer.IsOk()) 

    First we create an object associated with the Master Volume meter control. The third parameter NO_SOURCE is a constant defined in the header file. It means that the control does not have a source line, only a destination line.

    Second we check if is this type of control available or not.

    Finally, we set the volume to 500.

    Example 2. Master Mute.


    Here we create an object associated with Master Mute control, and turn it off.


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

    A list of licenses authors might use can be found here


    About the Author

    Alexander Fedorov
    Web Developer SEO
    Russian Federation Russian Federation
    AlexF's Blog in Russian
    Owner Spy competition analysis
    Rating Burner Rating of blogs

    You may also be interested in...


    Comments and Discussions

    QuestionSolved balance problem? Pin
    geert jacobs8-May-03 22:39
    membergeert jacobs8-May-03 22:39 
    AnswerRe: Solved balance problem? Pin
    geert jacobs8-May-03 22:57
    membergeert jacobs8-May-03 22:57 
    GeneralRe: Solved balance problem? Pin
    AkikoAkikoChan17-Oct-04 17:42
    memberAkikoAkikoChan17-Oct-04 17:42 
    AnswerRe: Solved balance problem? [modified] Pin
    ultraVBCoder25-Jun-06 17:26
    memberultraVBCoder25-Jun-06 17:26 
    Basically, it works like this:
    1) controls which have the UNIFORM flag set (found by ANDing the controlType with &H1) have only one adjustable channel. Take DST_SPEAKERS, for example, (usually) 2 channels, but one adjustable mute control for both channels
    2) If you set only the first structure for a control, (controls are set by the number of items AND the number of channels for non-UNIFORM controls) all items and channels are set to that value, regardless of the number of each of these
    3) By changing the cchannels to 1, you can 'force' it to return one structure (by the way, also change the 'item' to 1) - however, even returning all shouldn't crash VS.NET.

    Likely, you are assigning the amount of memory (the pamctrl, I believe) using AllocHGlobal to only the size of the structure. To remedy this, allocate the structureSize*numChannels*numItems memory. You can set up a loop to grab all the structures with PtrToStructure by offsetting the ptr address by the structure size for each sequential mixercontroldetails_xxxx structure to contruct a managed array (unsafe, but works)

    This is off the top of my head, but if anyone has any questions or corrections, feel free to comment

    Happy windows API coding :->

    EDIT: sorry, I'm thinking about this in a managed environment, I'll leave it for info as the proposed solution should still be revlevant

    -- modified at 23:26 Sunday 25th June, 2006

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

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web03 | 2.8.170915.1 | Last Updated 10 Jan 2000
    Article Copyright 2000 by Alexander Fedorov
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid