Click here to Skip to main content
13,256,841 members (52,461 online)
Click here to Skip to main content
Add your own
alternative version


48 bookmarked
Posted 27 Oct 2001

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 -->


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!

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.


  1. include the Mixer.h and Mixer.cpp into your project;
  2. add code like this:


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:


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
  CMixer m_mixer;


if you have any suggestion or improvement, plz let me know:


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


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

Generalgetting slider value Pin
tmf690228-Aug-03 9:12
membertmf690228-Aug-03 9:12 
GeneralRe: getting slider value Pin
Whoo28-Aug-03 20:35
memberWhoo28-Aug-03 20:35 
GeneralRe: getting slider value Pin
tmf29-Aug-03 9:25
susstmf29-Aug-03 9:25 
GeneralRe: getting slider value Pin
Whoo29-Aug-03 19:11
memberWhoo29-Aug-03 19:11 
GeneralRe: getting slider value Pin
SohailB15-Jun-05 22:14
memberSohailB15-Jun-05 22:14 
GeneralRecord Sound Volume Control Pin
Efrain Munoz7-Jul-03 7:45
memberEfrain Munoz7-Jul-03 7:45 
GeneralRe: Record Sound Volume Control Pin
Whoo8-Jul-03 2:15
memberWhoo8-Jul-03 2:15 
GeneralRe: Record Sound Volume Control Pin
Efrain Munoz9-Jul-03 10:35
memberEfrain Munoz9-Jul-03 10:35 
i put this code in
void SetMyVolume(int i)

and in mixer.h
class CMixer
DWORD GetVolume();
void SetVolume(DWORD dwVol);
void SetMyVolume(int i);
// Destination Kind;
enum DestKind
{ Record,
CMixer(DWORD ComponentType, DestKind dkKind);
virtual ~CMixer();
DWORD m_dwChannels;
DWORD m_dwControlID;
bool m_bOK;

when i compile the cvolume.dll i have the following warning:

LINK : warning LNK4089: all references to "WINMM.dll" discarded by /OPT:REF
cvolumen.dll - 0 error(s), 1 warning(s)
i suppose that the dll is well created.

in a vbasic 6.0 empty project i put:

Public Declare Function SetMyVolume Lib "C:\volumen\cvolumen\Release\cvolumen.dll" (ByVal vol As Long)

and call the function in this manner:
Call SetMyVolume(100)

when in run the visual basic application i have:"Error 453".
No se encuentra la función de biblioteca DLL especificada (Error 453)

what i should do?
sorry for my bad english.
Efrain Munoz

GeneralRe: Record Sound Volume Control Pin
Whoo15-Apr-04 17:58
memberWhoo15-Apr-04 17:58 
GeneralMixer.obj : error LNK2001: unresolved external symbol __imp__mixerGetLineControlsA@12 Pin
tvhead802-Apr-03 3:56
membertvhead802-Apr-03 3:56 
GeneralRe: Add Winmm.lib.:laugh: Pin
tvhead802-Apr-03 4:01
membertvhead802-Apr-03 4:01 
GeneralRe:How to Add Winmm.lib? Pin
severeight1-Apr-04 18:16
membersevereight1-Apr-04 18:16 
GeneralRe:How to Add Winmm.lib? Pin
mmjd11-Apr-04 23:20
membermmjd11-Apr-04 23:20 
GeneralRe:Thank you for your help!! Pin
severeight13-Apr-04 18:22
membersevereight13-Apr-04 18:22 
Generalquesions,thanks Pin
NeverGrief21-Nov-02 7:09
memberNeverGrief21-Nov-02 7:09 
GeneralRe: quesions,thanks Pin
Whoo22-Nov-02 6:33
memberWhoo22-Nov-02 6:33 
GeneralDirectSound Pin
Rainer Schmidt18-Mar-02 0:30
memberRainer Schmidt18-Mar-02 0:30 
GeneralRe: DirectSound Pin
Whoo22-Nov-02 6:35
memberWhoo22-Nov-02 6:35 
General#include "send.h" Pin
vila8-Dec-01 10:12
membervila8-Dec-01 10:12 
GeneralRe: #include "send.h" Pin
Whoo8-Dec-01 19:24
memberWhoo8-Dec-01 19:24 
GeneralRTFM Pin
Alexander Fedorov29-Oct-01 5:28
memberAlexander Fedorov29-Oct-01 5:28 
GeneralRe: RTFM Pin
Anonymous29-Oct-01 16:01
memberAnonymous29-Oct-01 16:01 
GeneralRe: RTFM Pin
PackRat12-Dec-01 5:14
memberPackRat12-Dec-01 5:14 
GeneralRe: RTFM Pin
Anonymous220-Dec-01 21:33
memberAnonymous220-Dec-01 21:33 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 28 Oct 2001
Article Copyright 2001 by Whoo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid