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

Play sine wave

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 4.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.
  • C Offline
    C Offline
    cpper
    wrote on 28 Mar 2017, 19:47 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 28 Mar 2017, 19:57 last edited by
      #2

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

      1 Reply Last reply
      2
      • C Offline
        C Offline
        cpper
        wrote on 28 Mar 2017, 20:01 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 :)

        J 1 Reply Last reply 29 Mar 2017, 01:48
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Mar 2017, 20:44 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
          • C cpper
            28 Mar 2017, 20:01

            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 :)

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 29 Mar 2017, 01:48 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 29 Mar 2017, 06:51 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...

              J 1 Reply Last reply 29 Mar 2017, 09:04
              0
              • M mostefa
                29 Mar 2017, 06:51

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

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 29 Mar 2017, 09:04 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 29 Mar 2017, 09:21
                0
                • J JKSH
                  29 Mar 2017, 09:04

                  @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 29 Mar 2017, 09:21 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

                  1/8

                  28 Mar 2017, 19:47

                  • Login

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