Click here to Skip to main content
Click here to Skip to main content

A simple record and playback volume control class

, 27 Oct 2001
Rate this:
Please Sign up or sign in to vote.
A class to make setting the record and playback volume easier
<!-- Download Links --> <!-- Main HTML starts here -->

Introduction

Sometimes we need to control the volume of our soundcard and Microsoft has provided an API waveOutSetVolume() to do this. Unfortunately this can only set the playback volume. When we want to set the volume of other lines such as mic or MIDI or the line-in for recording, there is NO API to help!

At first I thought that DirectMedia may provide an interface to do this, and it does, but after I coded it and tested, the result is not so good. The interface IAMAudioInputMixer can only handle the record, not the playback, and most of all:

"The name of each pin, such as "Line in" or "Microphone", reflects the type of input"

but the name is not the same on different machines!

eg:
I want to set the volume of the microphone, so I find the pin by name "Microphone" and control it, it works on my computer. When I tested it at another machine, it failed because the name of the pin is "Mic Volume"!

I tried many ways and at last I worked out how to do it using MIXER.

There may be some people that have had a headache over the same quetion, so I released my solution. I hope it helps you.

Usage

  1. include the Mixer.h and Mixer.cpp into your project;
  2. add code like this:
      CMixer mixer(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, CMixer::Record);
    
      ......
      mixer.GetVolume();
      mixer.SetVolume(...);
    

Remarks

The constructor takes two parameters, the first is ComponentType from MIXERLINE (see MSDN for all possible values), and the second is an enum type, which can be Record or Play. The above controls the record (waveIn) volume, you can also control the playback (waveout) volume using:

CMixer mixer(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, CMixer::Play);

Notice that there is no default constructor takes no parameters, so if you use it in a C++ class, you should code it like this:

// MyClass.h
//////////////////////////
class CMixer;
class CMyClass
{
  CMyClass();
private:
  CMixer m_mixer;
....
}

//MyClass.cpp
///////////////////////////
CMyClass::CMyClass():m_mixer(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, CMixer::Play)
{
}
....

if you have any suggestion or improvement, plz let me know: whoo@isWhoo.com

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

Share

About the Author

Whoo
Architect
China China
No Biography provided

Comments and Discussions

 
QuestionHow to choose FrontPanel MIC or BackPanel MIC? Pinmemberguzeliang9-Oct-06 21:48 
AnswerRe: How to choose FrontPanel MIC or BackPanel MIC? Pinmemberknightriderjon30-May-07 23:21 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 28 Oct 2001
Article Copyright 2001 by Whoo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid