How to play raw audio with QBuffer and QAudioOutput?
-
Here's my code
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QBuffer buffer; buffer.open(QIODevice::ReadWrite); QDataStream opt(&buffer); Decoder dcdr;//this is my class, convert silkv3 to raw.it works. dcdr.decodeSilk("msg1.amr",&opt); qDebug()<<buffer.buffer().length(); QAudioFormat fmt; fmt.setCodec("audio/pcm"); fmt.setSampleRate(24000); fmt.setSampleSize(8); fmt.setChannelCount(1); fmt.setSampleType(QAudioFormat::UnSignedInt); fmt.setByteOrder(QAudioFormat::LittleEndian); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(fmt)) { qWarning()<<"raw audio format not supported by backend, cannot play audio."; } QAudioOutput *player=new QAudioOutput(fmt); //player->setVolume(1); player->start(&buffer); qDebug()<<player->state(); return 0; }
But I can't hear any sound while it running.
Thanks!
-
Hi,
You're not letting the event loop run so basically, you start the player and the program ends right after that.
-
Here's my code
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QBuffer buffer; buffer.open(QIODevice::ReadWrite); QDataStream opt(&buffer); Decoder dcdr;//this is my class, convert silkv3 to raw.it works. dcdr.decodeSilk("msg1.amr",&opt); qDebug()<<buffer.buffer().length(); QAudioFormat fmt; fmt.setCodec("audio/pcm"); fmt.setSampleRate(24000); fmt.setSampleSize(8); fmt.setChannelCount(1); fmt.setSampleType(QAudioFormat::UnSignedInt); fmt.setByteOrder(QAudioFormat::LittleEndian); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(fmt)) { qWarning()<<"raw audio format not supported by backend, cannot play audio."; } QAudioOutput *player=new QAudioOutput(fmt); //player->setVolume(1); player->start(&buffer); qDebug()<<player->state(); return 0; }
But I can't hear any sound while it running.
Thanks!
Hi, @BBFAG3 thanks for post, do you get any source of information for this Que. post, If you get any reference, request you to share it here.
-
Hi, @BBFAG3 thanks for post, do you get any source of information for this Que. post, If you get any reference, request you to share it here.
@Dilip_Patel
Hi
I recentently help other poster with playing raw sounds
https://forum.qt.io/topic/86218/trouble-playing-sound-directly-out-of-raw-data-vectors/12
Maybe it can help. -
Santa brought me the Audio Programming Book, written in 2010, and I'm quite surprised to find it's mostly "C" and contains "goto" statements and the like. There has been a lot of Audio questions here recently, I'd like to see a good bloody Qt Tutorial on all things Audio.