1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| // Create IDirectSoundCapture using the preferred capture device
RUN( DirectSoundCaptureCreate( &DSDEVID_DefaultVoiceCapture, &m_SoundCapture, NULL ), "Can't create DirectSoundCapture", return; );
// Set data format
m_WaveFormat.nSamplesPerSec = 16000; // 16kHz
m_WaveFormat.wBitsPerSample = 16;
m_WaveFormat.nChannels = 1; // Mono Channels
m_WaveFormat.wFormatTag = WAVE_FORMAT_PCM; // format : uniformaly sized sample
m_WaveFormat.nBlockAlign = m_WaveFormat.nChannels * ( m_WaveFormat.wBitsPerSample / 8 ); // given in the DirectSound Documentation (don't have to change if using WAVE_FORMAT_PCM)
m_WaveFormat.nAvgBytesPerSec = m_WaveFormat.nBlockAlign * m_WaveFormat.nSamplesPerSec; // given in the DirectSound Documentation (don't have to change if using WAVE_FORMAT_PCM)
m_WaveFormat.cbSize = 0; // additional information per sample (0)
// Calculate buffer caracteristics
m_dwNotificationSize = max( 1024 , m_WaveFormat.nAvgBytesPerSec / 8 );
m_dwNotificationSize -= m_dwNotificationSize % m_WaveFormat.nBlockAlign;
m_dwBufferSize = m_dwNotificationSize * NUM_REC_NOTIFICATIONS;
// Create buffer
DSCBUFFERDESC bufferDescr; ZeroMemory( &bufferDescr, sizeof(bufferDescr) );
bufferDescr.dwFlags = DSCBCAPS_WAVEMAPPED;
bufferDescr.dwSize = sizeof(bufferDescr);
bufferDescr.dwBufferBytes = m_dwBufferSize;
bufferDescr.lpwfxFormat = &m_WaveFormat;
RUN( m_SoundCapture->CreateCaptureBuffer( &bufferDescr, &m_Buffer, NULL ), "Impossible to create sound buffer", return; );
g_dwNextCaptureOffset = 0; |
Partager