PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Trying to set ppc volume

I got a snippet of code off of pocketpcdn.com for changing volume via waveOutSetVolume that returns an unknown error code. I'm putting the code below in the hope that someone out there has done this before and knows what the problem is.

Code:

void CWave::setSoundVolume(DWORD dwVolume)
{
#ifdef _DEBUG
extern FILE *g_fp;
#endif
#ifndef _WIN32_WCE
waveOutSetVolume((HWAVEOUT) WAVE_MAPPER, dwVolume);
#else
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;
UINT devs = waveOutGetNumDevs();
for (UINT id = 0; id < devs; id++) {
MMRESULT mmr = waveOutOpen(&hwo, id, &wf, 0, 0, CALLBACK_NULL);
#ifdef _DEBUG
if(g_fp) { (void)fprintf(g_fp, "mmr = %d\n", mmr); (void)fflush(g_fp); }
if(g_fp) { (void)fprintf(g_fp, "MMSYSERR_NOERROR = %d\n", MMSYSERR_NOERROR); (void)fflush(g_fp); }
if(g_fp) { (void)fprintf(g_fp, "MMSYSERR_INVALHANDLE = %d\n", MMSYSERR_INVALHANDLE); (void)fflush(g_fp); }
if(g_fp) { (void)fprintf(g_fp, "MMSYSERR_NODRIVER = %d\n", MMSYSERR_NODRIVER); (void)fflush(g_fp); }
if(g_fp) { (void)fprintf(g_fp, "MMSYSERR_NOMEM = %d\n", MMSYSERR_NOMEM); (void)fflush(g_fp); }
if(g_fp) { (void)fprintf(g_fp, "MMSYSERR_NOTSUPPORTED = %d\n", MMSYSERR_NOTSUPPORTED); (void)fflush(g_fp); }
#endif
if (mmr == MMSYSERR_NOERROR) {
waveOutSetVolume(hwo, dwVolume);
waveOutClose(hwo);
break;
}
}
#endif
}


The error code comes from waveOutOpen and is a value of 32. MMSYSERR_NOERROR = 0, MMSYSERR_INVALHANDLE = 5, MMSYSERR_NODRIVER = 6, MMSYSERR_NOMEM = 7, and MMSYSERR_NOTSUPPORTED = 8. This works on the desktop PC by just using the waveOutSetVolume with WAVE_MAPPER as the device.

Thanks for any help you might provide. -- GR
Just a short update to this problem. After countless hours looking at this yesterday, a fresh approach led me to looking in the ppc version of mmsystem.h which showed the error 32 from waveOutOpen is a WAVERR_BADFORMAT so there is something wrong with the WAVEFORMATEX structure I'm using. More info to come as I figure it out. -- GR
Your nSamplesPerSec field looks suspect... I think it should be 8000. Why the "*1000" ?
Check wf.nSamplesPerSec.
Yep, I found that this morning while tinkering with it. That was the setting that was used in the sample on pocketpcdn (and the same used in several newsgroup posts) and I assumed (there's that word again) that it was correct. That's what I get for just pasting code that was supposed to be correct. I'll post a little tutorial on how to adjust the sound volume on our website today or tomorrow. Thanks for everyone's help. =)

-- GR