Wave file recording program
-
Thursday, April 05, 2012 7:30 AM
Hi! to everyone..,
>>I am trying to write a program to record wave file from mic connected to audio in port, and save it as .wav file in current directory
>> So as I am searching on Internet I found following ways to do my program
1. Using DirectX sdk
2. Wave form API
>> I am using the Wave Form API to do my project
>> I read the whole document, but I am new to programming and vc++.
>>So any one please give me the steps to do my project. I mean before use waveInOpen() function, what are the various things to consider like when to create buffer, when to create WAVEFORMATEX structure.
>> Please anyone tell me design flow.Don't hesitate leave your valuable comments.
Srinath Adepu
- Edited by srinath adepu Thursday, April 05, 2012 7:57 AM
All Replies
-
Thursday, April 05, 2012 1:54 PM
Your function that is going to call waveInOpen should initialize a WAVEFORMATEX member variable before you call waveInOpen.
If you need to record continuously then for seamless transistions at the end of a buffer you need several buffers. Send two or more buffers to the device driver before you start recording so it will always have a fresh buffer available when it fills a buffer. The startup should look something like this:
m_nBufferSize = m_Format.nAvgBytesPerSec / BLOCK_PER_SECOND; for (i = 0; i < NUM_BUFFERS; i++) { m_pWaveHdr[i] = (LPWAVEHDR) new char[sizeof(WAVEHDR) + m_nBufferSize]; m_pWaveHdr[i]->lpData = (char *)(m_pWaveHdr[i] + 1); m_pWaveHdr[i]->dwBufferLength = m_nBufferSize; m_pWaveHdr[i]->dwBytesRecorded = 0; m_pWaveHdr[i]->dwUser = 0; m_pWaveHdr[i]->dwFlags = 0; m_pWaveHdr[i]->dwLoops = 0; if (waveInPrepareHeader(m_hDevice, m_pWaveHdr[i], sizeof(WAVEHDR))) return FALSE; if (waveInAddBuffer(m_hDevice, m_pWaveHdr[i], sizeof(WAVEHDR))) return FALSE; } waveInStart(m_hDevice);- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Thursday, April 12, 2012 8:59 AM

