使用QAudioInput在linux中录制并在Windows中播放

Ari*_*Ari 5 c++ audio qt alsa

为了我的目的,我想以原始格式(仅样本),8kHz,16bit(小端)和1个通道录制声音.然后,我想将这些样本传输到窗口并使用QAudioOutput播放它.所以我有两个独立的程序:一个用于使用QAudioInput录制语音,另一个用于提供包含一些样本的文件,然后我用QAudioOutput播放它.下面是我创建QAudioInput和QAudioOutput的源代码.

//Initialize audio
void AudioBuffer::initializeAudio()
{
  m_format.setFrequency(8000); //set frequency to 8000
  m_format.setChannels(1); //set channels to mono
  m_format.setSampleSize(16); //set sample sze to 16 bit
  m_format.setSampleType(QAudioFormat::UnSignedInt ); //Sample type as usigned integer sample
  m_format.setByteOrder(QAudioFormat::LittleEndian); //Byte order
  m_format.setCodec("audio/pcm"); //set codec as simple audio/pcm

  QAudioDeviceInfo infoIn(QAudioDeviceInfo::defaultInputDevice());
  if (!infoIn.isFormatSupported(m_format))
  {
      //Default format not supported - trying to use nearest
      m_format = infoIn.nearestFormat(m_format);
  }

  QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());

  if (!infoOut.isFormatSupported(m_format))
  {
     //Default format not supported - trying to use nearest
     m_format = infoOut.nearestFormat(m_format);
  }
  createAudioInput();
  createAudioOutput();
}

void AudioBuffer::createAudioOutput()
{
  m_audioOutput = new QAudioOutput(m_Outputdevice, m_format, this);
}

void AudioBuffer::createAudioInput()
{
   if (m_input != 0) {
     disconnect(m_input, 0, this, 0);
     m_input = 0;
   } 

   m_audioInput = new QAudioInput(m_Inputdevice, m_format, this);

}
Run Code Online (Sandbox Code Playgroud)

这些程序在Windows和Linux中分别运行良好.但是,当我在Linux中录制语音并在Windows中播放时,它会产生很多噪音.

我在Windows中找出捕获的样本,Linux也不同.第一张图片与Linux中的捕获声音有关,第二张图片与Windows相关.

Linux中捕获的声音: 在Linux中捕获声音

Windows中捕获的声音: 在Windows中捕获声音

关于细节的更多信息是Windows和Linux中的静默是不同的.我尝试了很多东西,包括交换字节,即使我在两个平台上都设置了小端.

现在,我对alsa配置有疑问.有错过的设置吗?

如果我不使用QAudioInput直接录制语音,你认为会更好吗?

小智 3

声音是UnSignedInt,但是样本值有负值和正值!看来你在捕捉时遇到了麻烦。改成。QAudioFormat::UnSignedIntQAudioFormat::SignedInt