我已經編寫了一個程序,通過Wuindows中的waveInOpen()捕獲聲音。它在主板上的麥克風設備上效果很好,但是當我嘗試從第二張聲卡捕捉時,我只能聽到[靜態]噪音。使用SoundRecorder進行錄音對兩張卡片都很有效。 any1是否知道waveInOpen()和多個輸入設備是否存在任何已知問題?從第二張聲卡中捕獲音頻的問題
打開的輸入裝置的代碼如下所示:
void Audio::OpenDevice(const int device,
const Audio::SamplingRate samplingRate)
throw (Exception, std::exception)
{
switch(samplingRate)
{
...
case AUDIO_16BIT_44KHZ_STEREO:
bits_per_sample_ = 16;
hertz_ = 44100;
channels_ = 2;
break;
...
default:
throw Exception("Audio::OpenDevice(): Invalid enum value");
}
// Open the device
const UINT_PTR dev = (-1 == device) ? (UINT_PTR)WAVE_MAPPER : (UINT_PTR)device;
WAVEFORMATEX wf = {0};
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.nChannels = channels_;
wf.wBitsPerSample = bits_per_sample_;
wf.nSamplesPerSec = hertz_;
wf.nBlockAlign = wf.nChannels * wf.wBitsPerSample/8;
`
const MMRESULT result = waveInOpen(&hwi_, dev, &wf,
(DWORD_PTR)OnWaveEvent, (DWORD_PTR)this, CALLBACK_FUNCTION);
if (MMSYSERR_NOERROR != result)
throw Exception("waveInOpen()");
std::cout << "Audio: Sampling at " << hertz_ << " hertz from "
<< channels_ << " channel(s) with " << bits_per_sample_
<< " bits per sample. "
<< std::endl;
}
喲!請重新格式化您的代碼。你將有更多的人閱讀它的機會。 :) – 2010-01-08 18:55:26