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