WavePlayerJS is a simple web app that allows you to enter a math formula for a custom waveform and hear what it sounds like. If you want to convert a wave equation to audio, then this app is for you. I made this because I couldn't find any programs like this and I thought it should exist.
ChatGPT helped me with a lot of this program.
Type or paste your wave formula into the big text box. Make sure you include the variables vf and va in your formula (these are for setting frequency and amplitude). If you want to, you can also include an optional parameter variable in your formula with vp. This can do whatever you want, but it's usually used to change the shape of the wave.
Inside the presets folder, you will find some markdown files that contain some wave formulas that you can try. For the preset that you want to use, copy the formula labelled as JS and paste it into the web app.
If you want to see what one of these preset waveforms looks like, open GeoGebra in your web browser (or use the desktop app) and copy the formula labelled GGB into the input box in the left sidebar.
You can also access some of the presets with the Load Preset button, but not all presets are included in this feature.
Converting a GeoGebra formula into JavaScript that this web app will recognize is pretty easy. I recommend looking at the Presets.md file and comparing the GGB and JS versions of one of the presets, but here's a quick guide:
- Change
sin()toMath.sin()- This also applies to
cos(),tan(), and other functions.
- This also applies to
- Change
sin^(-1)()toMath.asin- This also applies to inverse cosine and tangent (and their hyperbolic versions).
- Change
Pi(or the Pi symbol) toMath.PI(make surePIis all-caps) - Replace blank space with
*- In a place where multiplication should be performed, use an asterisk. GeoGebra defaults to using a blank space when you copy to clipboard, and this won't work.
- Change exponents to
**- GeoGebra uses the caret symbol (
^) for exponents, but JavaScript uses 2 asterisks. JS treats^as a bitwise XOR operation.
- GeoGebra uses the caret symbol (
- Add extra brackets (if you need to)
Again, it's probably best to compare GGB and JS versions of the same formula in the Presets.md file. I found it easier to learn that way.