Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Simple Mixer Control Wrapper

0.00/5 (No votes)
9 Jan 2000 7  
A small audio mixer control wrapper
  • Download source files - 2.7 Kb
  • 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
    {
    protected:
      HMIXER m_HMixer;
      INT m_iMixerControlID;
      MMRESULT mmr;
      DWORD m_dwChannels;
      BOOL m_bSuccess;
      void ZeroAll();
    public:
      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.

    CAlexfMixer mixer(m_hWnd, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                      NO_SOURCE, MIXERCONTROL_CONTROLTYPE_VOLUME);
    if (!mixer.IsOk()) 
       return;
    
    mixer.SetControlValue(500);
    

    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.

    CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                      NO_SOURCE, MIXERCONTROL_CONTROLTYPE_MUTE );
    mixer.Off();
    

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

    License

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

    A list of licenses authors might use can be found here