Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to play raw audio with QBuffer and QAudioOutput?
QtWS25 Last Chance

How to play raw audio with QBuffer and QAudioOutput?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BBFAG3
    wrote on last edited by
    #1

    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!

    D 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You're not letting the event loop run so basically, you start the player and the program ends right after that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B BBFAG3

        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!

        D Offline
        D Offline
        Dilip_Patel
        wrote on last edited by
        #3

        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.

        mrjjM 1 Reply Last reply
        0
        • D Dilip_Patel

          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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by A Former User
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved