0

我尝试播放void * data以长度存储的音频,data_size但收到消息:“缓冲区下溢!”

int callback(void * data, long data_size) {
  QBuffer audio_buffer;
  audio_buffer.setData(static_cast<const char*>(data), data_size);

  audio_buffer.open(QIODevice::ReadOnly);

  QAudioFormat format;
  format.setSampleSize(16);
  format.setSampleRate(44100);
  format.setChannelCount(1);
  format.setCodec("audio/pcm");
  format.setByteOrder(QAudioFormat::LittleEndian);
  format.setSampleType(QAudioFormat::SignedInt);

  // get default output device
  QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

  // start playback
  QAudioOutput output(info, format);
  output.start(&audio_buffer);
  // ...then wait for the sound to finish
  QEventLoop loop;
  QObject::connect(&output, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
  do {
    loop.exec();
  } while(output.state() == QAudio::ActiveState);
}
4

1 回答 1

0

在下面尝试一些更改

。轮廓

QT+=  multimedia

还要检查是否支持格式

  // get default output device
  QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

  if (!info.isFormatSupported(format))
    format = info.nearestFormat(format);

  // start playback
  QAudioOutput output(info, format);
  output.start(&audio_buffer);
于 2016-03-29T14:20:46.133 回答