/** test: to play audio
usage:
AudioPlay()->write(qIODevice->read(PCM_BUFFER_SIZE));
*/
QIODevice *AudioPlay()
{
static QIODevice* qIODev = nullptr;
if (!qIODev) {
QAudioFormat qAudioFormat;
QAudioOutput *out = nullptr;;
qAudioFormat.setSampleRate(8000);
qAudioFormat.setChannelCount(1);
qAudioFormat.setSampleSize(16);
qAudioFormat.setCodec("audio/pcm");
qAudioFormat.setByteOrder(QAudioFormat::LittleEndian);
qAudioFormat.setSampleType(QAudioFormat::SignedInt);
out = new QAudioOutput(qAudioFormat);
if (!!out) {
out->setBufferSize(1000000);
qIODev = out->start();
}
}
if (!qIODev) {
qWarning() << "[AudioPlay] nullptr of QIODevice* for play";
exit(1);
}
return qIODev;
}
QT采集PCM时,用于测试的实时播放
最新推荐文章于 2023-08-16 16:26:53 发布