Click here to Skip to main content
15,893,487 members
Articles / Desktop Programming / MFC
Article

Simple Mixer Control Wrapper

Rate me:
Please Sign up or sign in to vote.
4.54/5 (12 votes)
9 Jan 2000 215.3K   2.6K   42   38
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


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

    Comments and Discussions

     
    GeneralQuestion about using this class Pin
    Member 70847920-Aug-02 3:22
    Member 70847920-Aug-02 3:22 
    QuestionAbout Recording Control? Pin
    Anonymous8-Aug-02 20:26
    Anonymous8-Aug-02 20:26 
    AnswerRe: About Recording Control? Pin
    Anonymous11-Aug-02 5:43
    Anonymous11-Aug-02 5:43 
    Generalmix several wav fils Pin
    6-Jan-02 9:55
    suss6-Jan-02 9:55 
    GeneralRe: mix several wav fils Pin
    PeteCIS5-Feb-02 7:47
    PeteCIS5-Feb-02 7:47 
    GeneralRe: mix several wav fils Pin
    mice16-Aug-02 22:54
    mice16-Aug-02 22:54 
    GeneralRe: mix several wav fils Pin
    begray14-Oct-05 21:45
    begray14-Oct-05 21:45 
    GeneralGREAT! And yet so simple! Amazing Pin
    3-Oct-01 16:54
    suss3-Oct-01 16:54 
    I'm a grad student working on creating a simple 2 person voice chat system with which to measure voice quality under a variety of undesireable network conditions. Since I needed to simulate conditions like packet loss, packet delay, and packet jitter I couldn't just jump on board and use DirectX's DirectPlay Voice API.

    I decided to go with DirectSound since I can get the audio in PCM format, packetize it and send it across the network. However complex DirectSound may be it seems to lack the simple ability to MUTE or UNMUTE the microphone! Maybe I missed something, but I doubt it.

    To make matters worse, the stupid unmute example I found in the MSDN Library did not work at all! Not wanting/having time to learn the Windows sound API I went to the web.

    I found Alexander Fedorov's CAlexfMixer library and literally had a mute and unmute button working in less than 10 minutes.

    Obviously I want to make this a toggle button, but who cares, I wanted to proove it worked first!

    I'll list below the simple code needed to mute/unmute the microphone.

    Anyway, once I'm done with my project I'll be sure to post it here.

    Here's the code:

    void CMuteTestDlg::OnMuteMic()
    {
    CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
    MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_MUTE );
    mixer.Off();
    }

    void CMuteTestDlg::OnUnmuteMic()
    {
    CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
    MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_MUTE );
    mixer.On();

    }
    GeneralDoes not work Pin
    2-Jul-01 10:30
    suss2-Jul-01 10:30 
    GeneralRecording information Pin
    22-Nov-00 6:14
    suss22-Nov-00 6:14 
    GeneralWhere can i Find...... Pin
    Jon13-Jul-00 5:18
    Jon13-Jul-00 5:18 
    GeneralMessage Closed Pin
    11-Jan-00 22:04
    Member 479611-Jan-00 22:04 

    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.