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. Play sine wave
Qt 6.11 is out! See what's new in the release blog

Play sine wave

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 5.2k Views 4 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.
  • cpperC Offline
    cpperC Offline
    cpper
    wrote on last edited by
    #1

    Good evening :)
    I'm looking for a method to play a sine wave, or whatever tone, at a specific frequency ? How could I achieve this ?

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

      Hi! AFAIK, our framework doesn't provide such low-level audio stuff.

      1 Reply Last reply
      2
      • cpperC Offline
        cpperC Offline
        cpper
        wrote on last edited by
        #3

        That's strange. Meanwhile I found this post but I'm not sure what happens there, there's too much maths. I'll take a deeper look though.
        Thanks :)

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

          Hi,

          The sine wave generation is indeed out of Qt's scope, however you can use QAudioOutput to send the data to your sound card.

          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
          4
          • cpperC cpper

            That's strange. Meanwhile I found this post but I'm not sure what happens there, there's too much maths. I'll take a deeper look though.
            Thanks :)

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @cpper said in Play sine wave:

            I found this post but I'm not sure what happens there, there's too much maths.

            The maths is for calculating the values of different samples in a digital sine wave.

            Let's say you take a single cycle of a sine wave, and split it into N samples. The simplest way to generate this wave is:

            double samples[N];
            for (int n = 0; n < N; ++n)
                samples[n] = sin( 2*PI * n/N );
            

            For example, if you want to split your wave cycle into 1000 samples, then N = 1000 and

            samples[  0] = sin( 2*PI *   0/1000 );
            samples[  1] = sin( 2*PI *   1/1000 );
            samples[  2] = sin( 2*PI *   2/1000 );
            ...
            samples[997] = sin( 2*PI * 997/1000 );
            samples[998] = sin( 2*PI * 998/1000 );
            samples[999] = sin( 2*PI * 999/1000 );
            

            That's it, you now have an array of samples that represents one cycle of a sine wave.

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

            1 Reply Last reply
            3
            • M Offline
              M Offline
              mostefa
              wrote on last edited by mostefa
              #6

              Hi @cpper

              One original way can be to use QML and shadereffect (only if you have to use QML , and have knowledge in GPU programming)

              http://doc.qt.io/qt-5/qml-qtquick-shadereffect.html

              You can use this shader effect for example

              http://glslsandbox.com/e#36864.2

              You can have a look at this link :

              http://stackoverflow.com/questions/27118049/qml-need-idea-how-to-animate-waves

              and this link :

              http://qmlbook.github.io/ch09/index.html

              But for me shaders are not simple and intuitive ,

              And i don't even know if what I propose is recommended...

              JKSHJ 1 Reply Last reply
              0
              • M mostefa

                Hi @cpper

                One original way can be to use QML and shadereffect (only if you have to use QML , and have knowledge in GPU programming)

                http://doc.qt.io/qt-5/qml-qtquick-shadereffect.html

                You can use this shader effect for example

                http://glslsandbox.com/e#36864.2

                You can have a look at this link :

                http://stackoverflow.com/questions/27118049/qml-need-idea-how-to-animate-waves

                and this link :

                http://qmlbook.github.io/ch09/index.html

                But for me shaders are not simple and intuitive ,

                And i don't even know if what I propose is recommended...

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @mostefa said in Play sine wave:

                Hi @cpper

                One original way can be to use QML and shadereffect (only if you have to use QML , and have knowledge in GPU programming)

                http://doc.qt.io/qt-5/qml-qtquick-shadereffect.html

                You can use this shader effect for example

                http://glslsandbox.com/e#36864.2

                You can have a look at this link :

                http://stackoverflow.com/questions/27118049/qml-need-idea-how-to-animate-waves

                and this link :

                http://qmlbook.github.io/ch09/index.html

                But for me shaders are not simple and intuitive ,

                And i don't even know if what I propose is recommended...

                I believe @cpper is asking about sound waves, not graphical waves

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

                M 1 Reply Last reply
                0
                • JKSHJ JKSH

                  @mostefa said in Play sine wave:

                  Hi @cpper

                  One original way can be to use QML and shadereffect (only if you have to use QML , and have knowledge in GPU programming)

                  http://doc.qt.io/qt-5/qml-qtquick-shadereffect.html

                  You can use this shader effect for example

                  http://glslsandbox.com/e#36864.2

                  You can have a look at this link :

                  http://stackoverflow.com/questions/27118049/qml-need-idea-how-to-animate-waves

                  and this link :

                  http://qmlbook.github.io/ch09/index.html

                  But for me shaders are not simple and intuitive ,

                  And i don't even know if what I propose is recommended...

                  I believe @cpper is asking about sound waves, not graphical waves

                  M Offline
                  M Offline
                  mostefa
                  wrote on last edited by
                  #8

                  @JKSH said in Play sine wave:

                  @mostefa said in Play sine wave:

                  Hi @cpper

                  One original way can be to use QML and shadereffect (only if you have to use QML , and have knowledge in GPU programming)

                  http://doc.qt.io/qt-5/qml-qtquick-shadereffect.html

                  You can use this shader effect for example

                  http://glslsandbox.com/e#36864.2

                  You can have a look at this link :

                  http://stackoverflow.com/questions/27118049/qml-need-idea-how-to-animate-waves

                  and this link :

                  http://qmlbook.github.io/ch09/index.html

                  But for me shaders are not simple and intuitive ,

                  And i don't even know if what I propose is recommended...

                  I believe @cpper is asking about sound waves, not graphical waves

                  Ah , i think that you are right , sorry !

                  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