Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play
Forum Updated to NodeBB v4.3 + New Features

I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 2.5k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    prabhatjha
    wrote on last edited by
    #1

    I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on last edited by
      #2

      Hi,
      You can convert your data array to floats and use QAudioOutput from QtMultimedia module to play the sound. You can inform QAudioOutput of the format of your data (sampling frequency, number of channels, data type, ...) via a QAudioFormat.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        prabhatjha
        wrote on last edited by
        #3

        hey unai_i thanks for reply .....i ahve no experience on Qaudiooutput and QtMultimedia can u provide some sample code in which i can get step by step solution.........

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Simple example:
          http://qt-project.org/doc/qt-5/qtmultimedia-audiooutput-example.html

          Advanced example:
          http://qt-project.org/doc/qt-5/qtmultimedia-spectrum-example.html

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • U Offline
            U Offline
            unai_i
            wrote on last edited by
            #5

            Hi,
            something along the lines of the snippet below adapted from the "documentation":http://qt-project.org/doc/qt-5/qaudiooutput.html example should work. Note that I have not tested this so it may require some changes.
            @
            QVector<double> yourData;
            QBuffer buffer;
            float tmp = 0;
            for(int i=0; i < yourData.count(); i++)
            {
            tmp = yourData[i];
            buffer.write((char*) &tmp, 4);
            }
            buffer.seek(0);

            QAudioOutput* audio;
            QAudioFormat format;
            // Set up the format, eg.
            format.setSampleRate(8000); // adapt this to your needs
            format.setChannelCount(1); // adapt this to your needs
            format.setSampleSize(32); // float32
            format.setCodec("audio/pcm");
            format.setByteOrder(QAudioFormat::LittleEndian); // adapt this to your needs
            format.setSampleType(QAudioFormat::Float);

            QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
            if (!info.isFormatSupported(format)) {
            qWarning() << "Raw audio format not supported by backend, cannot play audio.";
            return;
            }

            audio = new QAudioOutput(format); // don't forget to delete when not needed anymore
            audio.start(&buffer);
            @

            1 Reply Last reply
            0
            • P Offline
              P Offline
              prabhatjha
              wrote on last edited by
              #6

              hey thanks a lot but when i included QAudiooutput class that show no such file and directory...after that i included QT+ = multimedia in my .pro file but getting same error ...i am using qt 4.7.....

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                Which OS are you on? Capitalization might matter (QAudioOutput, not QAudiooutput)

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  prabhatjha
                  wrote on last edited by
                  #8

                  working on windows7

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    Which compiler?

                    Qt 4.7 is very old, but I got multimedia working with the MinGW 4.4 compiler before.

                    Can you please post your .pro file?

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    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