Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting the volume level of master volume control

4 views
Skip to first unread message

Pat Henderson

unread,
Aug 16, 2000, 3:00:00 AM8/16/00
to
I need to be able to set the volume level from within my BCB3 application.
I initially tried using the waveOutSetVolume command, but that only affects
the volume level for the Wave Out control, and didn't produce any noticeable
effect on the actual volume level of the wav file playback. I think I need
to work with the Mixer API in order to set the volume level of the master
volume control. I've tried using some sample code that Damon Chandler
posted on 12/24/99. It compiles and executes OK, but doesn't change the
volume level of the master volume control. Here's the code that I'm using.
Any pointers would be greatly appreciated.

// From within my application program:
qSetMasterVolume( (DWORD)0xFFFFFFFFUL);

// Function in sound routine program:
void qSetMasterVolume(unsigned long newValue)
{
HMIXER HMixer;
MIXERCONTROLDETAILS mcd;
MIXERCONTROLDETAILS_UNSIGNED mcdMeter;
MIXERLINE ml;
MIXERCONTROL mc;
MIXERLINECONTROLS mlc;
ZeroMemory(&mc, sizeof(MIXERCONTROL));
ZeroMemory(&ml, sizeof(MIXERLINE));
ZeroMemory(&mlc, sizeof(MIXERLINECONTROLS));
ZeroMemory(&mcd, sizeof(mcd));

// Open mixer device and grab its handle
if (mixerOpen(&HMixer, 0, 0, 0, 0) == MMSYSERR_NOERROR)
{
// Initialize the MIXERCONTROL structure
mc.cbStruct = sizeof(MIXERCONTROL);

// Initialize the MIXERLINE structure
ml.cbStruct = sizeof(MIXERLINE);
ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

// Fill the mixerline info
if (mixerGetLineInfo(HMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE)
==
MMSYSERR_NOERROR)
{
// Find the source for the master volume component
int num_devices = ml.cConnections;
for (int index = 0; index < num_devices; index++)
{
ml.dwSource = index;
mixerGetLineInfo(HMixer, &ml, MIXER_GETLINEINFOF_SOURCE);
if (ml.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_FIRST)
break;
}

// Initialize the MIXERLINECONTROL structure
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
mlc.dwLineID = ml.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
mlc.pamxctrl = (LPMIXERCONTROL)&mc;

// Find the level display associated with this source
if (mixerGetLineControls(HMixer, &mlc,
MIXER_GETLINECONTROLSF_ONEBYTYPE)
== MMSYSERR_NOERROR)
{
// Initialize the MIXERCONTROLDETAILS structure
mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mcd.dwControlID = mc.dwControlID;
mcd.cChannels = 1;
mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mcd.paDetails = &mcdMeter;

// Set the new volume value
mcdMeter.dwValue = newValue;
mixerSetControlDetails(HMixer, &mcd,
MIXER_GETCONTROLDETAILSF_VALUE);
}
}
}

// Close mixer handle
mixerClose(HMixer);
}

Michael Warner

unread,
Aug 17, 2000, 3:00:00 AM8/17/00
to
On Wed, 16 Aug 2000 14:56:16 -0700, "Pat Henderson"
<phe...@flash.net> wrote:

>Any pointers would be greatly appreciated.

You probably don't want to hear this, but armed with this code you
should go back to the help file and figure out what's going on.
There's no substitute for a little understanding :-)

Jonathan Buzzard

unread,
Aug 17, 2000, 3:00:00 AM8/17/00
to

Sure, the help file documents contain everything you need to know.
Having been writing a sound program that uses the low level
waveIn/Out routines, I can tell you that the documentation from
Microsoft does not contain everything you need to know to write
a working program.

JAB.

--
Jonathan A. Buzzard Email: jonathan...@sund.ac.uk
University of Sunderland, U.K. Tel: +44(0)191-5153447

Michael Warner

unread,
Aug 18, 2000, 3:00:00 AM8/18/00
to
On Thu, 17 Aug 2000 10:40:20 +0100, Jonathan Buzzard
<jonathan...@sunderland.ac.uk> wrote:

>> You probably don't want to hear this, but armed with this code you
>> should go back to the help file and figure out what's going on.
>> There's no substitute for a little understanding :-)
>
>Sure, the help file documents contain everything you need to know.
>Having been writing a sound program that uses the low level
>waveIn/Out routines, I can tell you that the documentation from
>Microsoft does not contain everything you need to know to write
>a working program.

I've learnt to use a variety of sections of the API, such as wave
in/out and the audio mixer, with nothing but the help file for
assistance. Certainly potted code can solve immediate problems more
quickly (if it's correct and applicable!) but if you really understand
how something works you can take it much further.


0 new messages