Skip to content

ClaytonTDM/funcbeat-player

Repository files navigation

Funcbeat Player

Funcbeat is a statement-based sound synthesizer inspired by SArpnt's Funcbeat.

Features

  • Interactive code editor with syntax highlighting
  • Real-time sound synthesis and playback
  • Customizable presets and settings

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/funcbeat.git
  2. Navigate to the project directory:

    cd funcbeat
  3. Install the dependencies:

    npm install

Usage

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

How to Use

Funcbeat uses JavaScript to generate audio in real-time. Here's how to create sounds:

  1. Your code should return a function that takes time and sampleRate parameters
  2. Static variables can be declared outside the function for persistent state
  3. 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

License

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.

Acknowledgements

About

Funcbeat is a statement-based sound synthesizer inspired by SArpnt's Funcbeat.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published