开发者

Problems capturing audio from the second sound card

开发者 https://www.devze.com 2022-12-15 17:24 出处:网络
I have written a program that captures sound via waveInOpen() in Wuindows. It works great on t开发者_运维问答he michrophone-device on the main-board, but when I try to capture from the second sound-ca

I have written a program that captures sound via waveInOpen() in Wuindows. It works great on t开发者_运维问答he michrophone-device on the main-board, but when I try to capture from the second sound-card, I get only [static] noise. Recording with SoundRecorder works great on both cards. Does any1 know if there are any known problems with waveInOpen() and multiple input-devices?

The code that opens the input-device looks like this:

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;
}


Did you check the microphone gain settings, mixer settings, that the microphone hardware you're using is compatible with the input you have it hooked to, etc? Hooking most microphones to a line in connection does not work well. The microphone doesn't have enough output voltage to drive that kind of input.


My guess (purely a guess) is that the bit depth or sample rate is somehow incorrect. If you are using 16/44100, then I would assume it is supported (pretty common). But maybe the sound card is not set for those rates. I have an external Edirol sound card that I have to physically turn on and off when I change bit depth (and adjust a separate switch on it).

0

精彩评论

暂无评论...
验证码 换一张
取 消