From: Larry on 23 Dec 2009 18:09 "ScottMcP [MVP]" <scottmcp(a)mvps.org> ha scritto nel messaggio news:90e0fd36-f591-411e-a020-80c5a0ea4180(a)v7g2000vbd.googlegroups.com... > If you are going to reuse the buffer do not call waveInUnprepareHeader > and do not delete the buffer! By the way, I have just found this chunk of code: http://home.elka.pw.edu.pl/~mroj/h323/homepage/works/mroj/html/audio/waveform.htm It shows the regular way to open an input device and create some buffers. Yet, it has a different way to allocate buffers with the use of malloc: pwf.wBitsPerSample= 16; pwf.wf.nChannels = 1; pwf.wf.nSamplesPerSec = 8000; pwf.wf.wFormatTag = WAVE_FORMAT_PCM; pwf.wf.nBlockAlign = pwf.wf.nChannels * pwf.wBitsPerSample / 8; pwf.wf.nAvgBytesPerSec = pwf.wf.nSamplesPerSec * pwf.wf.nBlockAlign; if (waveInOpen(&rip->hwi, /*WAVE_MAPPER*/ 0, (LPWAVEFORMATEX)&pwf, (DWORD) rip->eventh, 0, CALLBACK_EVENT )) { printf("Couldn't open sound device. Leaving..\n"); goto problem; } /* Preparing system buffers */ sb = (WAVEHDR**) malloc(sizeof(WAVEHDR**) * system_buf_num); if(!sb) goto problem; for (i = 0; i < system_buf_num; i++) sb[i] = NULL; for (i = 0; i < system_buf_num; i++) { count = i; sb[i] = (WAVEHDR*) malloc(sizeof(WAVEHDR)); if (sb[i] == NULL) { put_debug_message("malloc() error!\n"); goto problem; } sb[i]->lpData = (LPBYTE) malloc(system_buf_len); sb[i]->dwBufferLength = system_buf_len; sb[i]->dwBytesRecorded = 0; sb[i]->dwUser = 0; sb[i]->dwFlags = 0; sb[i]->dwLoops = 0; if(!sb[i]->lpData) goto problem; if (waveInPrepareHeader(rip->hwi, sb[i], sizeof(WAVEHDR))) { put_debug_message("waveInPrepareHeader problem!\n"); goto problem; } if (waveInAddBuffer(rip->hwi, sb[i], sizeof(WAVEHDR))) { put_debug_message("waveInAddBuffer problem!\n"); goto problem; } } Do you think there much difference between this code and mine? can this be more smooth? thanks
First
|
Prev
|
Pages: 1 2 3 4 Prev: using lame encoder Next: InternetOpenUrl and retrieving protocol FTP data-size |