# sfx
Synthesised 8-bit sound effects for platformers and arcade games: jump, land, hard landing, dash, wall jump, gem, checkpoint, death, game over, level clear and UI click. Each sound is built from square (with duty cycle), stepped triangle and 15-bit LFSR noise voices with pitch sweeps, vibrato and a chip-style stepped envelope, baked once into a soundClip under `chipSfx.sounds` and shipped with the package. `chipSfx.bake` regenerates them from `Sfx.PRESETS`.
twoDKit plays them itself (through `twoDKit.juice`) on every peer for the moments that peer sees: your own at full volume, other players' quieter and fading out with distance. Nothing goes over the network.
## API
- `Sfx.play(name, opts?) -> boolean`: play one sound on this peer. `opts`: `isLocal` (false for someone else's moment), `x`, `y`, `listenerX`, `listenerY` (distance fade), `volume`, `pitch` (a small random pitch jitter is the default). Each sound has a short cooldown so a burst never stacks.
- `Sfx.volume` (default 0.55) and `Sfx.setVolume(v)`, `Sfx.muted` and `Sfx.setMuted(b)`: this peer's master volume and mute. twoDKit's `Player2D.sfxVolume` sets it too.
- `Sfx.remoteVolume` (0.45) and `Sfx.hearing` (18 tiles): how loud other players are, and how far away they fade out.
- `Sfx.render(nameOrPreset) -> { number }`: the mono samples at `Sfx.RATE` (22050 Hz), for your own sounds, e.g. `Sfx.render({ voices = { { wave = "square", duty = 0.25, dur = 0.1, f0 = 300, f1 = 900, decay = true } } })`.
- `Sfx.PRESETS`, `Sfx.NAMES`, `Sfx.duration(name)`, `Sfx.peak(pcm)`, `Sfx.note(midi)`, `Sfx.clipId(name)`.
```luau
local Sfx = require("chipSfx.sfx")
Sfx.setVolume(0.3)
Sfx.play("click")
```
# chipSfx: 8-bit sound effects for platformers
Eleven ready-made 8-bit sound effects for any Zero game, made the way an old console sound chip makes them: **jump, land, hard landing, dash, wall jump, gem, checkpoint, death, game over, level clear and a UI click**. Each one is synthesised from square (with duty cycle), stepped triangle and 15-bit noise voices with pitch sweeps, vibrato and a stepped envelope, and shipped as a soundClip, so playing one costs nothing. Play a sound on this peer with one call; another player's sounds come out quieter and fade with distance, and nothing goes over the network.
It is the sound of **twoDKit** (the 2D pixel platformer kit), which installs it.
## Install
`zero zeromind installAsset 08ec245b-eb89-41f3-a761-1e92b71c1bac` in the engine shell, or search ZeroMind for "chipSfx" or "8-bit sound effects". No dependencies.
## Play a sound
```luau
local Sfx = require("chipSfx.sfx")
Sfx.play("jump") -- your own moment, full volume
Sfx.play("gem", { isLocal = false, x = 12, y = 3, -- someone else's: quieter,
listenerX = 4, listenerY = 3 }) -- fading with distance
Sfx.setVolume(0.4) -- this peer's master volume
```
## Make your own sound
Add a preset (voices of `square`, `triangle` or `noise` with a duration, start and end pitch, duty, vibrato and decay), hear its samples with `Sfx.render`, and bake it into a clip with `chipSfx.bake`:
```luau
local Sfx = require("chipSfx.sfx")
local pcm = Sfx.render({ voices = { { wave = "square", duty = 0.25, dur = 0.1, f0 = 300, f1 = 900, decay = true } } })
```
`sfx.module`'s README lists every field and function.
## Changelog
- **1.0.1**: the install line names this package's id.
- **1.0.0**: first release, split out of twoDKit (where it was `twoDKit.sfx` and `twoDKit.artgen.sfx`, which still work).