Documentation
¶
Overview ¶
Package gion synthesizes 8-bit style game sound effects from a small, serializable set of parameters. Rendering is deterministic: the same Params always produce the same samples, so a game can ship tiny presets and generate the audio at runtime instead of shipping files. Inspired by sfxr/bfxr, not a port.
Index ¶
Constants ¶
const DefaultRate = 44100
DefaultRate is the sample rate used when a caller passes a rate <= 0.
Variables ¶
var ErrTooLong = errors.New("gion: too many samples for a WAV file")
ErrTooLong reports a sample slice whose WAV encoding would overflow the format's 32-bit sizes.
var Presets = map[string]func(seed int64) Params{ "blip": Blip, "explosion": Explosion, "hit": Hit, "jump": Jump, "laser": Laser, "pickup": Pickup, "powerup": Powerup, }
Presets maps each preset name to its generator, so CLIs and UIs can offer the catalog without hardcoding it.
Functions ¶
func Spectrogram ¶ added in v0.0.2
Spectrogram slices the samples into frames spread evenly across the sound and returns a frames x bins grid of spectral magnitudes, normalized to 0..1 and log-compressed so quiet detail stays visible next to the peaks. Each bin keeps the peak of its frequency range, which preserves narrow tones. It is the data behind the app's waterfall view, exported so a game can drive its own visualizer from the same sounds.
Types ¶
type Params ¶
type Params struct {
Wave Wave
Freq float64 // starting frequency in Hz
FreqSlide float64 // frequency change in Hz per second
FreqLimit float64 // stop the sound when a downward slide crosses this; 0 = never
Attack float64 // seconds fading in
Sustain float64 // seconds at full level
Punch float64 // extra level at the start of the sustain, fading across it (0..1)
Decay float64 // seconds fading out
Duty float64 // square duty cycle (0..1]; 0 means 0.5
Vibrato float64 // vibrato depth in Hz
VibratoHz float64 // vibrato speed in cycles per second
ArpMult float64 // multiply the frequency by this once, after ArpDelay; 0 = off
ArpDelay float64 // seconds before the arpeggio jump
LowPass float64 // one-pole low-pass cutoff in Hz; 0 = off
Bits int // quantize the output to this many bits (1..15); 0 = off
Gain float64 // output level (0..1)
Seed int64 // noise stream seed
}
Params describes one sound effect. The zero value renders silence; start from a preset and tweak. All fields are plain data, so a Params can be serialized (e.g. JSON) and shipped with a game.
func Mutate ¶ added in v0.0.2
Mutate returns a deterministic sibling of p: each non-zero numeric field has a coin-flip chance of drifting up to ±10%, relative to its value, so the sound keeps its character — a mutated laser is still that laser. Fields that are off (zero) stay off, and the wave, bit depth, gain and noise seed are left alone. The same p and seed always produce the same sibling.
Besides sculpting sounds in the editor, this is useful at runtime: mutate a base effect with a varying seed and repeated explosions, hits or footsteps stop sounding identical, at zero asset cost.
func Pickup ¶
Pickup is the classic coin: a short square blip that jumps up a musical interval after a moment.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gion
command
Command gion is the sound-effect workbench over the gion library: preset buttons roll seeded variations, sliders shape the parameters, the result plays as soon as a drag is released, and the current sound can be saved as a WAV file.
|
Command gion is the sound-effect workbench over the gion library: preset buttons roll seeded variations, sliders shape the parameters, the result plays as soon as a drag is released, and the current sound can be saved as a WAV file. |
|
gion-render
command
Command gion-render writes sounds to WAV files: the ear-first check of the synth core, and the baked-assets path for games that skip runtime synthesis.
|
Command gion-render writes sounds to WAV files: the ear-first check of the synth core, and the baked-assets path for games that skip runtime synthesis. |
|
Package effects reads and writes gion documents.
|
Package effects reads and writes gion documents. |
|
Package music generates short, perfectly-looping chiptune tracks from a small deterministic parameter set, rendered entirely through the gion synthesis core: every note is a gion.Params scheduled on a step grid and mixed into one buffer.
|
Package music generates short, perfectly-looping chiptune tracks from a small deterministic parameter set, rendered entirely through the gion synthesis core: every note is a gion.Params scheduled on a step grid and mixed into one buffer. |
