use of waveOutOpen, waveOutPrepareHeader APIs. 
Author Message
 use of waveOutOpen, waveOutPrepareHeader APIs.

why can't I play the sound out?

I have created a wave , and want to play it with waveOutWrite function, But when it run to

waveOutPrepareHeader, there is always an error, I can't solve it.

below is the code:

 WAVEFORMATEX wfSrc;
 memset(&wfSrc,0,sizeof(wfSrc));
 wfSrc.cbSize=0;
 wfSrc.wFormatTag=WAVE_FORMAT_PCM;
 wfSrc.nChannels=1;
 wfSrc.nSamplesPerSec=11025;
 wfSrc.wBitsPerSample=8;
 wfSrc.nBlockAlign=wfSrc.nChannels*wfSrc.wBitsPerSample/8;
 wfSrc.nAvgBytesPerSec=wfSrc.nChannels*wfSrc.nSamplesPerSec*wfSrc.nBlockAlign;

 DWORD dwSrcSamples=wfSrc.nSamplesPerSec;
 BYTE *pSrcData=new BYTE[dwSrcSamples]; //1 second duration
 BYTE *pData=pSrcData;
 double f=1000.0;
 double pi=4.0*atan(1.0);
 double w=2.0*pi*f;
 for (DWORD dw=0;dw<dwSrcSamples;dw++)
 {
  double t=(double)dw/(double)wfSrc.nSamplesPerSec;
  *pData++=128+(BYTE)(127.0*sin(w*t));
 }

 //open
 HWAVEOUT hPlay;
 MMRESULT mmResult=::waveOutOpen(&hPlay, WAVE_MAPPER,&wfSrc,0,0,CALLBACK_NULL);

 //prepare the wave header
 LPWAVEHDR lpHdr = new WAVEHDR;
 ZeroMemory(lpHdr, sizeof(WAVEHDR));

 lpHdr->lpData = (char *) pData;
 lpHdr->dwBufferLength = dwSrcSamples;

 mmResult = ::waveOutPrepareHeader(hPlay, lpHdr, sizeof(WAVEHDR));//error in this statement
 if(mmResult)
  TRACE("error from waveoutprepareheader\n");

//waveOut
 mmResult = ::waveOutWrite(hPlay, lpHdr, sizeof(WAVEHDR));
 if(mmResult)
  TRACE("error from waveoutwrite\n");

Thank you.



Thu, 03 Mar 2005 23:13:18 GMT  
 use of waveOutOpen, waveOutPrepareHeader APIs.

Quote:
>why can't I play the sound out?

You should post this question in the multimedia group. What is the return
value of the function that fails?

Regards,
Will



Fri, 04 Mar 2005 00:07:04 GMT  
 use of waveOutOpen, waveOutPrepareHeader APIs.

Quote:

> why can't I play the sound out?

> I have created a wave , and want to play it with waveOutWrite
> function, But when it run to

> waveOutPrepareHeader, there is always an error, I can't solve it.

> below is the code:

Hello zhaoyandong,

Your code looks OK, so I tested it.  On my machine (Win 2000) it fails
(MMSYSERR_INVALPARAM) with your 11025 byte buffer but works with a 2048
byte buffer.  Apparently a driver limitation.  If this is your problem
you could use a loop that prepares and outputs several small buffers
instead of one big one.

--
Scott McPhillips [VC++ MVP]



Fri, 04 Mar 2005 01:38:05 GMT  
 use of waveOutOpen, waveOutPrepareHeader APIs.
Thank you! It succeeded!


Quote:

> > why can't I play the sound out?

> > I have created a wave , and want to play it with waveOutWrite
> > function, But when it run to

> > waveOutPrepareHeader, there is always an error, I can't solve it.

> > below is the code:

> Hello zhaoyandong,

> Your code looks OK, so I tested it.  On my machine (Win 2000) it fails
> (MMSYSERR_INVALPARAM) with your 11025 byte buffer but works with a 2048
> byte buffer.  Apparently a driver limitation.  If this is your problem
> you could use a loop that prepares and outputs several small buffers
> instead of one big one.

> --
> Scott McPhillips [VC++ MVP]



Fri, 04 Mar 2005 15:42:50 GMT  
 use of waveOutOpen, waveOutPrepareHeader APIs.

Quote:
> >why can't I play the sound out?

> You should post this question in the multimedia group. What is the return
> value of the function that fails?

> Regards,
> Will

The return value is 0x0b.

msdn explanation for waveOutPrepareHeader says the return value should be

MMSYSERR_INVALHANDLE
MMSYSERR_NODRIVER
MMSYSERR_NOMEM

but return value is not any of them.

should I say msdn has a mistake?



Fri, 04 Mar 2005 16:08:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. waveOutOpen callback event

2. can't use both waveInOpen and waveOutOpen under '95

3. waveOutOpen ..can anyone offer any help

4. SB Live & waveOutOpen

5. callback address to waveOutOpen

6. waveOutOpen error

7. Help with WaveOutOpen

8. waveOutOpen

9. waveOutOpen - Sound recording

10. using a win32 api in managed code

11. How printing in landscape mode using win32 api?

12. Using SystemParameterInfo API call

 

 
Powered by phpBB® Forum Software