Click here to Skip to main content
15,886,101 members
Articles / Desktop Programming / MFC

A simple record and playback volume control class

Rate me:
Please Sign up or sign in to vote.
3.64/5 (11 votes)
27 Oct 20012 min read 292.6K   3.7K   48  
A class to make setting the record and playback volume easier
  Sometimes we need to control the volume, and Microsoft really provided
a api waveOutSetVolume() to do this. but unfortunately, this can only set
the waveout tunnle of the playback volume.when we want to set the volume of
other line, such as mic , midi of the playback or linein of the record, there
is NO api can help work!
  At first, I think that DirectMedia may provide a interface to do this, and 
it really dose, but after I coded it and tested, the result is not so good,
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 in different machine!!

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

  I tried many ways and at last I work it out with MIXER.

  There may be some people that feel headache about the same quetion, so I released 
my solution, hope it help you.

usage:
  include the Mixer.h and Mixer.cpp into your project;

  add code like this:

  CMixer mixer(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, CMixer::Record);

  ......
  mixer.GetVolume();
  mixer.SetVolume(...);


remark:
  the constructor take two parameters, the first is ComponentType
from MIXERLINE(see MSDN for all), the second is a enum type, which
can be Record or Play.
  the above control the record(waveIn) volume, you can alse control 
the playback(waveout) volume by code like this:

  CMixer mixer(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, CMixer::Play);


  notice that there is no default constructor take zero params, 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


Whoo
Oct.1 2001

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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
Architect
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions