gpt4 book ai didi

c++ - Qt缓冲区欠载播放RAW音频

转载 作者:行者123 更新时间:2023-12-03 01:55:05 35 4
gpt4 key购买 nike

我尝试播放存储在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);
}

最佳答案

请尝试以下更改

.pro文件

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

关于c++ - Qt缓冲区欠载播放RAW音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36286712/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com