music

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

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. The same Params always produce the same samples, so a game can ship a seed instead of an audio file.

The design follows the classic NES conventions: a square lead built from a short motif arranged in an AABA form over a chord progression, a triangle bass on chord roots, and noise percussion on euclidean patterns. Mood picks scale, progression, tempo and timbre together.

Index

Constants

View Source
const (
	MuteLead = 1 << iota
	MuteEcho
	MuteBass
	MuteKick
	MuteSnare
	MuteHat
)

Mute bits: set a bit in Params.Mute to silence that instrument — for isolating a voice in the workbench, or shipping a reduced arrangement. The bit order matches the internal voice order.

Variables

View Source
var Moods = map[string]Mood{
	"upbeat": Upbeat,
	"heroic": Heroic,
	"dark":   Dark,
	"chill":  Chill,
	"battle": Battle,
	"boss":   Boss,
}

Moods maps the mood names to their values, for CLIs and UIs.

Functions

This section is empty.

Types

type Mood

type Mood int

Mood selects the musical character: scale, chord progression, default tempo, lead timbre and swing.

const (
	Upbeat Mood = iota
	Heroic
	Dark
	Chill
	Battle
	Boss
)

type Params

type Params struct {
	Seed  int64
	Mood  Mood
	Tempo float64 // BPM; 0 = the mood's tempo
	Bars  int     // loop length; 0 = 16 (an AABA of 4-bar phrases)
	Root  float64 // tonic frequency in Hz; 0 = 220 (A3)
	Gain  float64 // output level (0..1); 0 = 0.6
	Mute  int     // bitmask of silenced instruments (MuteLead, MuteBass, ...)

	// Mixer levels per instrument group, multiplying the built-in balance.
	// 0 means 1.0 (unchanged); the workbench exposes them as sliders so the
	// mix can be set by ear and saved with the track.
	LeadVol float64
	BassVol float64
	DrumVol float64
}

Params describes one track. Zero fields fall back to the mood's defaults (or the package defaults for Bars, Root and Gain); use New for a ready set.

func New

func New(mood Mood, seed int64) Params

New returns the default track parameters for a mood and seed.

func (Params) Render

func (p Params) Render(rate int) []int16

Render composes and synthesizes the track as mono 16-bit samples at the given rate (gion.DefaultRate when rate <= 0). The sample count is derived from tempo and bars alone, and note tails wrap around to the start of the buffer, so the result loops seamlessly by construction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL