Hi there,
I'm using the waveOut* functions to play out some audio using double
buffering and I'm using a callback event to tell me when each buffer
is done.
However, I am unable to call waveOutWrite as I get and
MMSYSERR_INVALHANDLE error each time. Any idea what the problem could
be?
Here's the relevant code:
/* declarations */
WAVEHDR wh1, wh2;
HWAVEOUT hwaveout;
WAVEFORMATEX wfx;
eventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (eventHandle == NULL)
{
mexErrMsgTxt("failed to create event"
;
}
if (eventHandle == NULL)
{
mexErrMsgTxt("failed to create event"
;
}
/* initialise the wave player */
/* I fill in the WAVEFORMATEX (wfx) structure here */
errors = waveOutOpen ( &hwaveout,
WAVE_MAPPER,
&wfx,
(unsigned long) &eventHandle,
0,
CALLBACK_EVENT | WAVE_ALLOWSYNC );
if (errors != MMSYSERR_NOERROR)
{
mxFree (&wh1);
mxFree (&wh2);
switch (errors)
{
case MMSYSERR_ALLOCATED: mexWarnMsgTxt("MMSYSERR_ALLOCATED"
;
break;
case MMSYSERR_BADDEVICEID: mexWarnMsgTxt("MMSYSERR_BADDEVICEID"
;
break;
case MMSYSERR_NODRIVER: mexWarnMsgTxt("MMSYSERR_NODRIVER"
;
break;
case MMSYSERR_NOMEM: mexWarnMsgTxt("MMSYSERR_NOMEM"
; break;
case WAVERR_BADFORMAT: mexWarnMsgTxt("WAVERR_BADFORMAT"
;
break;
case WAVERR_SYNC: mexWarnMsgTxt("WAVERR_SYNC"
; break;
default: mexWarnMsgTxt("default with waveoutopen"
; break;
}
CloseHandle(eventHandle);
mexErrMsgTxt("error in opening wave device"
;
return 1;
}
and then the call to waveOutWrite:
errors = waveOutWrite (hwaveout, &wh1,
sizeof(WAVEHDR));
if (errors != 0)
{
switch (errors)
{
case MMSYSERR_INVALHANDLE:
mexErrMsgTxt("MMSYSERR_INVALHANDLE"
;
case MMSYSERR_NODRIVER:
mexErrMsgTxt("MMSYSERR_NODRIVER"
;
case MMSYSERR_NOMEM:
mexErrMsgTxt("MMSYSERR_NOMEM"
;
case WAVERR_UNPREPARED:
mexErrMsgTxt("WAVERR_UNPREPARED"
;
default: mexErrMsgTxt("default error with
waveOutWrite"
;
}
mexErrMsgTxt("error in using waveoutwrite"
;
}
and I receive the MMSYSERR_INVALHANDLE error.
It worked when I used a callback thread but I've been forced to change
from that to a callback event.
Thanks in advance!
Su-Lin Lee
sulinlee@nospam.lycos.co.uk
remove nospam to email
I'm using the waveOut* functions to play out some audio using double
buffering and I'm using a callback event to tell me when each buffer
is done.
However, I am unable to call waveOutWrite as I get and
MMSYSERR_INVALHANDLE error each time. Any idea what the problem could
be?
Here's the relevant code:
/* declarations */
WAVEHDR wh1, wh2;
HWAVEOUT hwaveout;
WAVEFORMATEX wfx;
eventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (eventHandle == NULL)
{
mexErrMsgTxt("failed to create event"
}
if (eventHandle == NULL)
{
mexErrMsgTxt("failed to create event"
}
/* initialise the wave player */
/* I fill in the WAVEFORMATEX (wfx) structure here */
errors = waveOutOpen ( &hwaveout,
WAVE_MAPPER,
&wfx,
(unsigned long) &eventHandle,
0,
CALLBACK_EVENT | WAVE_ALLOWSYNC );
if (errors != MMSYSERR_NOERROR)
{
mxFree (&wh1);
mxFree (&wh2);
switch (errors)
{
case MMSYSERR_ALLOCATED: mexWarnMsgTxt("MMSYSERR_ALLOCATED"
break;
case MMSYSERR_BADDEVICEID: mexWarnMsgTxt("MMSYSERR_BADDEVICEID"
break;
case MMSYSERR_NODRIVER: mexWarnMsgTxt("MMSYSERR_NODRIVER"
break;
case MMSYSERR_NOMEM: mexWarnMsgTxt("MMSYSERR_NOMEM"
case WAVERR_BADFORMAT: mexWarnMsgTxt("WAVERR_BADFORMAT"
break;
case WAVERR_SYNC: mexWarnMsgTxt("WAVERR_SYNC"
default: mexWarnMsgTxt("default with waveoutopen"
}
CloseHandle(eventHandle);
mexErrMsgTxt("error in opening wave device"
return 1;
}
and then the call to waveOutWrite:
errors = waveOutWrite (hwaveout, &wh1,
sizeof(WAVEHDR));
if (errors != 0)
{
switch (errors)
{
case MMSYSERR_INVALHANDLE:
mexErrMsgTxt("MMSYSERR_INVALHANDLE"
case MMSYSERR_NODRIVER:
mexErrMsgTxt("MMSYSERR_NODRIVER"
case MMSYSERR_NOMEM:
mexErrMsgTxt("MMSYSERR_NOMEM"
case WAVERR_UNPREPARED:
mexErrMsgTxt("WAVERR_UNPREPARED"
default: mexErrMsgTxt("default error with
waveOutWrite"
}
mexErrMsgTxt("error in using waveoutwrite"
}
and I receive the MMSYSERR_INVALHANDLE error.
It worked when I used a callback thread but I've been forced to change
from that to a callback event.
Thanks in advance!
Su-Lin Lee
sulinlee@nospam.lycos.co.uk
remove nospam to email