"Extension" Sound Generator for Retro Gdevelop HTML 5 [WIP]

Now you can generate a simple tone in Gdevelop HTML 5 which may suit some retro games.

Download the sound generator project file here, you will need it to copy the function to your own project:
mega.nz/#!Hog0wYjL!4-uPN960C-xp … E-UoFf1jlc

2 simplest example scenes are attached. You don’t need to copy them, but can copy one of them in your project as well, if needed.

[size=200]How to use:[/size]

[size=150]1: Open the project together with your own project in Gdevelop, and copy the “CreateSound” external event to your project.[/size]

[size=150]2: In your scene, declare a few variables, and then finally call the sound generator by linking it.[/size]

Here’s an example:

This will generate a simple sine wave tone of 850 hertz frequency, lasting only 1 second.
“Trigger once” is added to play the tone only once, you can use other conditions, timers, etc.

Variables explained:

This will set the type of the wave.
You can choose from “sine” “square” “sawtooth” and “triangle”.

Each will sound different. All other than sine are more “sharp”, e.g. “square” or “sawtooth” combined with the right notes might sound a bit like some retro game music.

This will set the frequency of the sound. Change this to play different notes.

Here is a simple list of frequencies to use for specific notes:

E.g. if you use: 523.25 followed by 587.33 followed by 659.25 you would get “C > D > E” notes.

This is the simplest way to do it (you could also pause the timer on the last call, or use child values as arrays to define as a set of notes and iterate through notes).

How long the note should play for, in seconds, e.g. 1 for 1 second, 10 for 10 seconds, etc.

[size=150]Polyphony (multiple notes at same time)[/size]
Yes, you can play multiple notes at the same time.

The example below will play a “C” and “D” based simple chord.

(Note I repeated all of the variables because of copying, but you only need to define those variables that actually change before each link to CreateSound). E.g. if you only want to change frequency, set all variables for the first time, but for the second, third, etc. note you only need to set the frequency before linking.

There is no volume setup yet or any other special features. Please feel to contribute by changing the JavaScript code in "CreateSound"event, and post the update here with instructions on how to use. This is also untested on various platforms and browsers and may not work on Android export or similar other applications. Please let me know if you find it does or does not work in a specific export method. Thanks!

Now, create some music or sound effects and share the code here!

Wow, what immediately come in to my mind, we could even make a sound editor out of this :mrgreen:
We could actually create a layer with a bunch of object and we could change the frequency by dragging the objects and create a nice tone in real time this way, then just go through each object on the layer and get the frequency of each object and play the tone… I don’t know how much the performance would be effected this way, but alternatively we could store the frequencies in a JSON file and just read them in to a variable (maybe :smiley: )

Sure, there are (theoretically) countless possibilities. :smiley: In reality, performance might not be perfect especially with this simplest possible implementation. But, it works… and if you made a retro style game like Pong, you could use it to generate “beep” sounds instead of loading actual wav files and making the game size larger. Or you could make a little “piano” or other instrument player that generates tones on click, drag, keypress, etc (although you may find that it lags quite a bit, even professional programs can lag when played with a PC keyboard) For actual complex music, even retro-like, midi file loading would be much much easier to use.