LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Anyway to change the speaker volume when using StartPCSound?

Hi,

I'm using StartPCSound() from Programmer's Toolbox, it does work but the result is quite loud and I didn't find anyway to reduce the volume.
No way by code, no way by Volume Control of Windows.
Anybody can help me?

Thanks
Sergio
0 Kudos
Message 1 of 4
(3,652 Views)
Hello Laser,

hope this helps:

#include <mmsystem.h>

/*---------------------------------------------------------------------------*/
/* Get volume
*/
/*---------------------------------------------------------------------------*/
int CVI_waveOutGetVolume (void)
{
unsigned int result;
unsigned int volume;

result = waveOutGetVolume (
0, //HWAVEOUT hwo, // First (and only) audio device
&volume //DWORD dwVolume
);
volume &= 0xFFFF; // Extract left value only
return volume;
}

/*---------------------------------------------------------------------------*/
/* Set volume
*/
/*---------------------------------------------------------------------------*/
void CVI_waveOutSetVolume (unsigned int volume)
{
unsigned int result;
unsigned int level;

// Level for both channels (high byte ignored of monophone)
level = volume * 0x10000 + volume;
// Set volume
result = waveOutSetVolume (
0, //HWAVEOUT hwo,
level //DWORD dwVolume
);
sprintf(temp_str,"Volume: 0x%04X", volume);
WriteToLogfile("CVI_waveOutSetVolume", temp_str);
}


Greetings from Bremerhaven, Germany

Norbert Rieper

"Laser" <x@no.email> schrieb im Newsbeitrag
news:1190194814309-582454@exchange.ni.com...
> Hi, I'm using StartPCSound() from Programmer's Toolbox, it does work but
> the result is quite loud and I didn't find anyway to reduce the volume.No
> way by code, no way by Volume Control of Windows.Anybody can help
> me?ThanksSergio


0 Kudos
Message 2 of 4
(3,642 Views)
StartPCSound and StopPCSound work by manipulating the registers of the sound chip on the motherboard. I don't think there is a way to control the volume in this case. You should use the PlaySound or sndPlaySound Windows SDK function instead. See samples/sdk/audio. With this function, Norbert's code above should also be able to control the volume - or you can set the volume in the Windows Volume control panel.
0 Kudos
Message 3 of 4
(3,638 Views)
Norbert's code works, but only if I use SDK functions such as sndPlaySound, as suggested by Mohan.
So I'll manage to replace StartPCSound with SDK functions and wave files in my code.

Thank you All

Sergio
0 Kudos
Message 4 of 4
(3,608 Views)