Simple Mixer Control Wrapper

Environment: VC6, Unicode

This is small and usefull C++ class which can encapsulate any windows multimedia mixer control. I wrote a simple class, named CAlexfMixer which can wrap any multimedia mixer control. You can manipulate with Master Volume, Mute or someone else mixer control with this class if control support this operations. You can retrieve information from Peak Meter and other controls like this.

There is some mixers here, but all of them are not so clear, simple and universal like my own... ;-)

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 callback window. The class has the member IsOk() to check ability of manipulation of specified control and members to get and set control state.

Using the class.

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 object associated with Master Volume meter control. Third parameter - NO_SOURCE - is a constant, defined in .h file, it mean than control have not a source line but only destination line. Second we check - is this type of control available or not? Third - if yes we set volume to 500.

Example 2. Master Mute.


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

Here we create object associated with Master Mute control. And next we switch it off.

Check for latest versions at http://members.xoom.com/lamer2000/.

Downloads

Download source - 3 Kb


Comments

  • This is Cool, but...

    Posted by Jerronimo on 05/27/2006 05:59pm

    Hello, nice job, this is similar to what i am looking for. I need a piece of soft to switch between audio devices. I have a rear and a front driver, just like i had two sound cards. But only one can be set as default so when i want to put my headphones i must goto ControlPanet->... etc. Could you please tell me how to change DEFAULT device to another? Should i go looking something about rundll32.exe? And where to look (a book?)? Any ideas?

    Reply
  • Good!!!

    Posted by Legacy on 10/13/2003 12:00am

    Originally posted by: Stefano Vaccari

    I found it very useful. Thanks a lot.

    Reply
  • Very good!

    Posted by Legacy on 10/29/2001 12:00am

    Originally posted by: Rogerio Silva

    Thank you !
    

    Reply
  • Where is Demo Project Source?

    Posted by Legacy on 10/08/2000 12:00am

    Originally posted by: hosang

    Where is Demo Project Source?

    Reply
  • Functions do nothing

    Posted by Legacy on 09/22/2000 12:00am

    Originally posted by: Clinton Morell

    I compiled a program using the demo examples and ran the demo code. Nothing happened. The volume level remained unchanged and unmuted.

    I am using the VC5.0 compiler; perhaps this code has no effect when compiled under v5.0.

    Reply
  • My mixer's maximum value is 65535

    Posted by Legacy on 03/29/2000 12:00am

    Originally posted by: Wuncheol Heo

    At first time, my program always set volume to zero.
    I try to find what's wrong. at last I know I set volume value to low (500 <- this value is from your example). My mixer's maximum is 65535 (0xffff).

    so I have one question.
    All mixer has maximum 65535 ? or differ each other?

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds