• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Snippet Waveform generator

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
Here's a simple example how to generate waves using Sin.
Touch the screen sideways or use a mouse to visually generate different frequencies.

Screenshot 2020-12-29 at 08.27.02.png


Cerberus:
#HTML5_CANVAS_WIDTH = 1280            ' ----------------------------------------
#HTML5_CANVAS_HEIGHT = 720           '
#GLFW_WINDOW_WIDTH = 1280            '
#GLFW_WINDOW_HEIGHT = 720            '   Excercise in using trigonometry
Strict                                ' 
Import mojo2                            '   Create a waveform using sinewave
                                    '
Function Main : Int()                    '
    New Game()                        ' ----------------------------------------
    Return 0
End

Class Game Extends App
    Field canvas : Canvas
    Field w : Int = 1280
    Field h : Int = 720 
    Field hz : Float = 440.0            ' Frequency that the waveform is stored in the array
    Field amplitude : Int = 32000        ' Volume that the waveform is stored in the array
    Field samplerate : Int = 44100
    Field seconds : Float = 10
    Field samples : Int
    Field waveform : Float[]
    Field t : Float
    Field i : Int
  
    Method OnCreate : Int()
        canvas=New Canvas
        samples = samplerate * seconds
        waveform = New Float[samples]
        Return 0
    End
  
    Method OnRender : Int()
        canvas.Clear
        hz = MouseX()
        canvas.SetColor 0,1,0
        canvas.DrawText "Hz = " + hz , 0 , 0
        For i = 0 Until samples            ' Create waveform
            t = Float(i) / Float(samplerate)
            waveform[i] = amplitude * Sin(hz * t * 360.0)
        Next
        canvas.DrawLine 0,h/2,w-1,h/2    ' Draw waveform     
        For i = 0 Until 44100
            canvas.DrawPoint i/(44100/w) , h/2+(waveform[i]/(32000.0/(h/2))*0.9)
        Next
        canvas.Flush
        Return 0
    End
  
    Method OnUpdate:Int()
        If KeyHit(KEY_ESCAPE) Then EndApp
        Return 0
    End
  
End

1609363982083.png
 
Last edited by a moderator:
Back
Top Bottom