3,248
社区成员




if(!m_strRecDev.empty()) {
IMMDevice *dev;
HRESULT hr;
if(!_get_device(m_strRecDev, WAVEIN, &dev))
return ERR_AUDIO_NODEVICE;
hr = dev->Activate(IID_IDirectSoundCapture8, CLSCTX_ALL, NULL, (void **)&m_dsc);
dev->Release();
if(FAILED(hr))
return ERR_AUDIO_OPEN;
}
else {
GUID guid = DSDEVID_DefaultCapture;
if(FAILED(DirectSoundCaptureCreate8(&guid, &m_dsc, NULL)))
return ERR_AUDIO_OPEN;
}
IDirectSoundCaptureBuffer *dscb;
DSCBUFFERDESC dscbd = {0};
WAVEFORMATEX wfx;
dscbd.dwSize = sizeof(DSCBUFFERDESC);
dscbd.dwBufferBytes = m_RecBlock * 2;
dscbd.lpwfxFormat = &wfx;
_fill_waveformat(&wfx, m_RecChannel, m_RecSampleRate, m_RecSampleBits);
if(FAILED(m_dsc->CreateCaptureBuffer(&dscbd, &dscb, NULL)))
return ERR_AUDIO_OPEN;
// error occurs here
HRESULT hr = dscb->QueryInterface(IID_IDirectSoundCaptureBuffer8, (void **)&m_dscb);
dscb->Release();
if(FAILED(hr)) // hr = NOINTERFACE if error occurs
return ERR_AUDIO_OPEN;