- WaveInOpen Multiple buffer problem
- Posted by Agam Mehta on July 11th, 2003
Hi
My problem comes when i try to addin more buffer in callback function.
When i receive MM_WIM_DATA in CALLBACK Function i unprepareheader than
again preparehearder and than when i try to use Addinbuffer it just
stops executing. I don't understand where the problem is. I am using
two buffers. Below is my code please help.
void CALLBACK mwaveInProc(
HWAVEIN hwi,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
)
{
LPWAVEHDR r_Data;
r_Data = (LPWAVEHDR)dwParam1;
switch(uMsg)
{
case MM_WIM_DATA:
//printf("Buffer ADDR: %s SIZE: %X VALUE: %u USER: %X FLAG:
%X\n",r_Data->lpData,r_Data->dwBufferLength,r_Data->dwBytesRecorded,r_Data->dwUser,r_Data->dwFlags);
doAddBuffer((char *) r_Data->lpData,hwi,(LPWAVEHDR)dwParam1);
//saveMessage(r_Data->lpData,(LPWAVEHDR)dwParam1);
//if (lpUserData == "")
sendBuffer((LPWAVEHDR)dwParam1);
//else
// sendBuffer((LPWAVEHDR)dwParam1);
//waveInBuffer(hwi,r_Data);
//datactr++;
//GlobalFree((LPWAVEHDR)dwParam1);
//waveInReset(hwi);
//waveInClose(hwi);
break;
}
}
doAddBuffer is use to unprepareheader, prepareheader and addin more
buffer. As i had read in SDK that you shouldn't use those function
insdie MM_WIM_DATA and that's the reason i am calling this function.
Below is the function.
void doAddBuffer(char *user_data,HWAVEIN m_hwi,LPWAVEHDR dwwaveHdr)
{
MMRESULT rmmResult;
DWORD bsize = 0;
bsize = 90L * (LONG)InFormat.nAvgBytesPerSec/8L;
if (m_hwi == NULL)
return;
if (dwwaveHdr == NULL)
return;
if ((rmmResult = waveInUnprepareHeader(m_hwi,dwwaveHdr,sizeof(WAVEH DR)))
== MMSYSERR_NOERROR)
{
printf("unprepare header successfully \n");
}
if (user_data != "")
{
//dwwaveHdr->dwFlags = 0;
//dwwaveHdr->dwBufferLength = buffersize;
//dwwaveHdr->lpData = (LPSTR) dwwaveHdr->lpData;
//dwwaveHdr->lpNext = dwwaveHdr;
//dwwaveHdr = (LPWAVEHDR) GlobalFree(dwwaveHdr);
//dwwaveHdr = (LPWAVEHDR) GlobalLock(GlobalAlloc(GPTR,bsize +
sizeof(totalsize)));
if (dwwaveHdr != NULL)
{
rmmResult = waveInPrepareHeader(m_hwi,dwwaveHdr,sizeof(WAVEHDR ));
if(rmmResult)
{
MessageBox(NULL,"Error preparing header. Please try
later.","Error",MB_OK);
return;
}
rmmResult = waveInAddBuffer(m_hwi,dwwaveHdr,sizeof(WAVEHDR));
if(rmmResult)
{
MessageBox(NULL,"Error preparing header. Please try
later.","Error",MB_OK);
return;
}
}
}
}
Please help
Thanks,
Agam
- Posted by Carsten Neubauer on July 11th, 2003
hi,
not long ago i stepped into the same trap...
when using CALLBACK_FUCTION you
can't perform preparing and adding from
there or from a subroutine.
try using CALLBACK_WINDOW, this way your
window will receive all the audio-messages, like
MM_WIM_DATA. there you are allowed to call
the necessary functions to unprepare, prepare
and add new buffers.
hope it helps,
carsten neubauer
http://www.c14sw.com/
- Posted by Agam Mehta on July 14th, 2003
Thanks carsten for your response. Actually i am using console
application. When i try to use CALLBACK_WINDOW it returns me error
number 11 every time.
I declare HWND variable which i assume won't work and it didn't. So
sill i am stuck to CALLBACK_FUNCTION and not callback_window. And
actually i create thread everytime the recording is done and this can
be used simultaneously on different phones. Actually i haven't work
much on threading. so if u or anyone can help me with that.. i would
really appreciate..
thanks,
Agam
cneubau@aol.comNOJUNK (Carsten Neubauer) wrote in message news:<20030711103837.25267.00000122@mb-m21.aol.com>...
- Posted by Carsten Neubauer on July 14th, 2003
hi agam,
if you have a console-program, CALLBACK_WINDOW is of course
not an option.
unfortunately i only have experience with CALLBACK_WINDOW.
all i found out in newsgroups about the CALLBACK_FUNCTION is,
that it was designed only to set some flag or invoke a thread, which
is waiting.
all the preparing and stuff must be done in your main loop
or within the invoked thread.
so i think you are on the right track with using threads.
i never tried that myself, but i remember finding example-sources
by googling for WaitForMultipleObjects and WaveAPI.
hope it helps a bit,
carsten
http://www.c14sw.com/
- Posted by Tim Robinson on July 14th, 2003
CALLBACK_WINDOW will work fine in a console program. Just create a window
and don't show it.
--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/
"Carsten Neubauer" <cneubau@aol.comNOJUNK> wrote in message
news:20030714160453.03679.00000254@mb-m16.aol.com...
- Buffer Overrun Problem (Help and Support) by Ota Custes
- Hyperterminal Scroll buffer problem (Microsoft Windows) by Tom
- buffer problem when burning (Video & DVD) by mqq13
- Buffer problem Vuescan (Scanners) by I. Ordejon
- Buffer Overrun Problem in USB Device. (Drivers) by Nazim

