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