Funcbeat is a statement-based sound synthesizer inspired by SArpnt's Funcbeat.
- Interactive code editor with syntax highlighting
- Real-time sound synthesis and playback
- Customizable presets and settings
-
Clone the repository:
git clone https://github.com/yourusername/funcbeat.git
-
Navigate to the project directory:
cd funcbeat
-
Install the dependencies:
npm install
Start the development server (Linux and macOS):
npm dev
And if you're on Windows:
npm run dev:windows
Build the project for production:
npm run build
Funcbeat uses JavaScript to generate audio in real-time. Here's how to create sounds:
- Your code should return a function that takes
time
andsampleRate
parameters - Static variables can be declared outside the function for persistent state
- The function should return a value between -1 and 1 for each sample
Example (created by SArpnt):
let lastSample = 0; // variables here are static and can always be accessed
let resonanceMomentum = 0;
const notedata = "$$$000,,,,,,,,''"; // this is a good place to store constants like note values because creating arrays and such constantly ruins performance
// note that this is a bad example, a string like this isn't an issue
// this is also a good place to do decompression calculations, for storing things like samples efficiently
return function (time, sampleRate) { // time is in secs, note that samplerate can still change the sound when static variables are used, this is why samplerate is given
const pitch = 2 ** ((notedata.charCodeAt(time * 4.3 & 15) + 22) / 12); // grab values from string and convert semitones to hz
const pulse = ((time * pitch % 1 > (time / 2 % 1) * .6 + .2) - .5) / 2; // generate pulse wave
lastSample += resonanceMomentum += (pulse - lastSample - resonanceMomentum * 3) / (cos(time / 5) * 170 + 200); // lowpass with resonance, doesn't work on other samplerates
const kick = (sin((time * 4.3 % 2 + .01) ** .3 * 180)) / 4;
return lastSample + kick;
}
Key Concepts:
- Use static variables outside the function for persistent state
- Time is in seconds
- Sample rate may vary, affecting sound when using static variables
- Store constants like note values outside the function for better performance
- Return values should stay within the [-1, 1] range
This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.
This project uses the Inter font, which is licensed under the SIL Open Font License.
- Inspired by and (mostly) compatible with SArpnt's Funcbeat
- CodeMirror for the code editor
- Tailwind CSS for the styling