Larry
2010-01-15 15:17:53 UTC
WAVEHDR allocationg several buffers
Hi,
I'm dealing with WAVEHDR from the waveForm API. I'd like to know which of
the following is the best approach to set up some buffers:
1)
// Define WAVEHDR Structure:
WAVEHDR *buff = new WAVEHDR[num_buffers];
for (int i = 0; i<num_buffers; i++)
{
ZeroMemory(&buff[i], sizeof(buff[i]));
buff[i].lpData = (LPSTR) malloc(system_buf_len);
buff[i].dwBufferLength = system_buf_len;
buff[i].dwBytesRecorded = 0;
buff[i].dwUser = 0;
buff[i].dwFlags = 0;
buff[i].dwLoops = 0;
if(waveInPrepareHeader(hwi, &buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInPrepareHedare: ERROR!\n"); // return -1;
if(waveInAddBuffer(hwi, &buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInAddBuffer: ERROR!\n"); // return -1;
}
2)
// Define WAVEHDR Structure:
WAVEHDR **buff = new WAVEHDR*[num_buffers];
for (int i = 0; i<num_buffers; i++)
{
buff[i] = new WAVEHDR;
ZeroMemory(buff[i],sizeof(WAVEHDR));
buff[i]->lpData = new char[system_buf_len;]
buff[i]->dwBufferLength = system_buf_len;
buff[i]->dwBytesRecorded = 0;
buff[i]->dwUser = 0;
buff[i]->dwFlags = 0;
buff[i]->dwLoops = 0;
if(waveInPrepareHeader(hwi, buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInPrepareHedare: ERROR!\n"); // return -1;
if(waveInAddBuffer(hwi, buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInAddBuffer: ERROR!\n"); // return -1;
}
thanks
NB: both of them seems to be working fine!
Hi,
I'm dealing with WAVEHDR from the waveForm API. I'd like to know which of
the following is the best approach to set up some buffers:
1)
// Define WAVEHDR Structure:
WAVEHDR *buff = new WAVEHDR[num_buffers];
for (int i = 0; i<num_buffers; i++)
{
ZeroMemory(&buff[i], sizeof(buff[i]));
buff[i].lpData = (LPSTR) malloc(system_buf_len);
buff[i].dwBufferLength = system_buf_len;
buff[i].dwBytesRecorded = 0;
buff[i].dwUser = 0;
buff[i].dwFlags = 0;
buff[i].dwLoops = 0;
if(waveInPrepareHeader(hwi, &buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInPrepareHedare: ERROR!\n"); // return -1;
if(waveInAddBuffer(hwi, &buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInAddBuffer: ERROR!\n"); // return -1;
}
2)
// Define WAVEHDR Structure:
WAVEHDR **buff = new WAVEHDR*[num_buffers];
for (int i = 0; i<num_buffers; i++)
{
buff[i] = new WAVEHDR;
ZeroMemory(buff[i],sizeof(WAVEHDR));
buff[i]->lpData = new char[system_buf_len;]
buff[i]->dwBufferLength = system_buf_len;
buff[i]->dwBytesRecorded = 0;
buff[i]->dwUser = 0;
buff[i]->dwFlags = 0;
buff[i]->dwLoops = 0;
if(waveInPrepareHeader(hwi, buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInPrepareHedare: ERROR!\n"); // return -1;
if(waveInAddBuffer(hwi, buff[i], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
printf("waveInAddBuffer: ERROR!\n"); // return -1;
}
thanks
NB: both of them seems to be working fine!