How to Make Procedural Game Sound Effects with Code (sfxr, Web Audio and Python)
Make game sound effects with code: sfxr-style tools, Web Audio, Python and engine APIs, plus copyable prompts for jump, coin, hit and UI sounds.
To make game sound effects with code, start from a simple recipe (an oscillator or noise source, a pitch sweep, and a volume envelope) and render it with a tool like jsfxr, the Web Audio API in the browser, Python with numpy, or your engine's audio API. Change a few numbers and you get a jump, a coin, a laser or a hit, each in a few lines.
Procedural sounds are small, consistent and easy to vary. That suits jams, prototypes and retro styles especially well.
Procedural audio is sound generated from code and parameters (oscillators, noise, filters, envelopes) at runtime or render time, rather than played back from recorded files.
Two related terms:
- An oscillator is a signal source that repeats a waveform, such as a sine, square, triangle or sawtooth, at a set frequency.
- A pitch sweep (or slide) changes an oscillator's frequency over time, which is what makes a jump go "bwoop" upward or a laser go "pew" downward.
sfxr. DrPetter made sfxr for the 10th Ludum Dare competition in December 2007, so jam entrants could get basic sound effects in without hunting for them. You press a randomize button or a button for a standard sound type, listen, and export the ones you like to WAV.
jsfxr. jsfxr is an HTML5 port of sfxr that runs in the browser. Its GitHub repo shows how to use it as a JavaScript library, so you can generate sounds inside a web game.
Bfxr. Bfxr is an open-source tool based on sfxr, with more waveforms and controls.
ChipTone. ChipTone is a free sound effect generator by SFBGames, mainly for games, now in HTML5.
The Web Audio API builds sounds from nodes. An OscillatorNode gives you a waveform, a gain node shapes the volume, and exponentialRampToValueAtTime creates natural-sounding sweeps and decays.
A coin pickup in a few lines:
const ctx = new AudioContext();
function coin() {
const t = ctx.currentTime;
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.type = "square";
osc.frequency.setValueAtTime(988, t); // B5
osc.frequency.setValueAtTime(1319, t + 0.08); // E6, second note
gain.gain.setValueAtTime(0.25, t);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.3);
osc.connect(gain).connect(ctx.destination);
osc.start(t);
osc.stop(t + 0.3);
}
Browsers require a user gesture (a click or key press) before audio can start, so call coin() from an input handler.
In Unity, AudioClip.Create builds a clip from sample data you provide. You can also create a streamed clip whose callback generates data on the fly, which is how you'd do runtime synthesis.
For any engine, the simplest route is to render WAV files offline with code and import them like normal assets. You keep the generator script in the repo, so changing a sound means editing a number and re-rendering.
If you ask an LLM to write the synthesis code, give it the waveform, pitch path, envelope and exact length. These prompts render WAVs with Python. The first is a jump sound:
Make a 0.25 s retro jump sound for a 2D platformer.
Output: one WAV, 48 kHz / 16-bit / mono, exactly 12000 samples.
Python + numpy/scipy only. Synthesise everything (no samples, no downloads). Fixed random seed.
Sound: square wave (25% duty cycle) sweeping 220 Hz -> 660 Hz on an exponential curve over 180 ms,
2 ms attack, linear decay to silence by 250 ms. Light low-pass at 6 kHz to soften the edges.
Master: true peak <= -1 dBTP.
Verify: print the sample count, measure true peak with ffmpeg ebur128, render a spectrogram.
Fix and re-render until every check passes.
A heavier hit or explosion, close to this entry on Opus Sounds Directory:
Make a 1.2 s explosion/hit for a game.
Output: one WAV, 48 kHz / 16-bit / stereo, exactly 57600 samples.
Python + numpy/scipy only. Synthesise everything. Fixed random seed.
Sound: white noise burst through a low-pass sweeping 8 kHz -> 300 Hz over 600 ms, plus a sine
thump sweeping 120 Hz -> 40 Hz in 200 ms. 1 ms attack, exponential decay, slight stereo width
on the noise only. Ends at exactly 0.
Master: true peak <= -1 dBTP. Verify with ffmpeg ebur128 and report the numbers.
For menu and UI feedback in a game, the same structure works. These two entries are a matched pair:
Each entry shows its prompt, Python code, spectrogram and measured loudness. The success chime was the directory's first sound generated by Claude Opus 5.5, and every entry is now Opus 5.5 output: the model writes the Python code that renders each sound.
Players hear the same footstep or gunshot hundreds of times, so add small variation at play time:
- Pitch: randomize by a few percent per play.
- Volume: vary by a decibel or two.
- Timbre: pick from 3 to 5 pre-rendered variants with different seeds.
- Timing: for rapid repeats, add a few milliseconds of jitter.
Keep a fixed seed per variant so your builds stay reproducible.
Kenney publishes game assets, including audio packs. Its support page says assets on its asset pages are public domain (CC0) and usable in commercial projects. OpenGameArt hosts community-made audio under various licenses. Freesound has many game-ready effects, each with its own Creative Commons license.
The directory also has two CC0 game cues you can download as they are or re-render from their code:
FAQ
- What is procedural audio?
- Procedural audio is sound generated at runtime or render time from code and parameters, such as oscillators, noise and envelopes, instead of played back from recordings.
- What is sfxr?
- sfxr is a small tool by DrPetter, made for the 10th Ludum Dare in December 2007, that generates retro game sound effects from a few parameters and presets.
- Are there free browser tools for game sound effects?
- Yes. jsfxr is an HTML5 port of sfxr, Bfxr is an open-source tool based on sfxr, and ChipTone is a free sound effect generator by SFBGames.
- Can I generate sounds inside Unity?
- Yes. Unity's AudioClip.Create lets you create a clip from sample data, including a streamed clip whose callback generates data on the fly.
- Where can I get free game sound effects?
- Kenney's game assets are released as CC0, OpenGameArt hosts community audio under various licenses, and you can synthesize your own with code.