I have a module titled WaveRecorderCtrl that seems to have nearly 2000 lines to it. I don't think I should post all of that here. There's another titled WaveRecorderDlg that is about the same length.
Here is an excerpt. Does this help?
Code:
int CWaveRecorderCtrl::Record()
{
if (m_bMonitoringInputLevel)
{
// Set the start recording flag
m_bStartRecording = true;
// Stop monitoring the input level
StopInputLevelMonitoring();
return TRUE;
}
// Make sure we aren't recording
if (m_bRecording)
return FALSE;
// Make sure we aren't already playing
if (m_bPlaying)
return FALSE;
// Check the handle to the window
if (!this->m_hWnd)
return FALSE;
// Allocate buffer memory
if (m_pBuffer1)
delete [] m_pBuffer1;
if (m_pBuffer2)
delete [] m_pBuffer2;
m_pBuffer1 = new BYTE[INPUT_BUFFER_SIZE];
m_pBuffer2 = new BYTE[INPUT_BUFFER_SIZE];
if (!m_pBuffer1 || !m_pBuffer2)
{
if (m_pBuffer1) delete [] m_pBuffer1;
if (m_pBuffer2) delete [] m_pBuffer2;
return FALSE;
}
// Open waveform audio device for input
m_WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
m_WaveFormat.nChannels = 1;
m_WaveFormat.nSamplesPerSec = SAMPLE_RATE;
m_WaveFormat.nAvgBytesPerSec = SAMPLE_RATE;
m_WaveFormat.nBlockAlign = 1;
m_WaveFormat.wBitsPerSample = BITS_PER_SAMPLE;
m_WaveFormat.cbSize = 0;
if (waveInOpen(&m_hWaveIn, WAVE_MAPPER, &m_WaveFormat, (DWORD)this->m_hWnd, 0, CALLBACK_WINDOW))
{
delete [] m_pBuffer1;
delete [] m_pBuffer2;
return FALSE;
}
// Setup and prepare headers
m_pWaveHdr1->lpData = (char *)m_pBuffer1;
m_pWaveHdr1->dwBufferLength = INPUT_BUFFER_SIZE;
m_pWaveHdr1->dwBytesRecorded = 0;
m_pWaveHdr1->dwUser = 0;
m_pWaveHdr1->dwFlags = 0;
m_pWaveHdr1->dwLoops = 0;
m_pWaveHdr1->lpNext = NULL;
m_pWaveHdr1->reserved = 0;
waveInPrepareHeader(m_hWaveIn, m_pWaveHdr1, sizeof(WAVEHDR));
m_pWaveHdr2->lpData = (char *)m_pBuffer2;
m_pWaveHdr2->dwBufferLength = INPUT_BUFFER_SIZE;
m_pWaveHdr2->dwBytesRecorded = 0;
m_pWaveHdr2->dwUser = 0;
m_pWaveHdr2->dwFlags = 0;
m_pWaveHdr2->dwLoops = 0;
m_pWaveHdr2->lpNext = NULL;
m_pWaveHdr2->reserved = 0;
waveInPrepareHeader(m_hWaveIn, m_pWaveHdr2, sizeof(WAVEHDR));
// Invalidate the loaded from file flag
m_loaded_from_file = FALSE;
return TRUE;