waveOutSetVolume -> doesn't change the volume

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From what I can find, the best way to change the volume of a device is
through "waveOutSetVolume". All my attempts to use do not actually effect
the volume of sound files played on the device. My code is below. I'm
calling it from C# and I know that the values range from 0 - 0xFFFF.
However, even 0xFFFF sounds the same 0.

Any ideas what I've done wrong? Thanks for looking at this!

EXTERN_C _declspec(dllexport) void SetVolume(int val)
{

DWORD dwVolumeOut = val * 13107;
WAVEFORMATEX wf;
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.nChannels = 1;
wf.nSamplesPerSec = 8000 * 1000;
wf.wBitsPerSample = 8;
wf.nBlockAlign = wf.nChannels * wf.wBitsPerSample / 8;
wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
wf.cbSize = 0;
HWAVEOUT hwo;

for (UINT id = 0; id < waveOutGetNumDevs(); id++)
{
if (waveOutOpen(&hwo, id, &wf, 0, 0, CALLBACK_NULL) == MMSYSERR_NOERROR)
{
waveOutSetVolume(hwo, dwVolumeOut);
waveOutClose(hwo);
break;

}
}
}
 
waveOutSetVolume only affects the current playback that you are doing via
waveOutWrite, etc. the way you've used it there. Try waveOutSetVolume( 0,
<your volume );, instead.

Paul T.
 
Thanks! That worked great!

Paul G. Tobey said:
waveOutSetVolume only affects the current playback that you are doing via
waveOutWrite, etc. the way you've used it there. Try waveOutSetVolume( 0,
<your volume );, instead.

Paul T.
 
Back
Top