Skip to content

AudioAPI reference

Class Song

Namespace: MicroEngine.Audio.Retro
Assembly: MicroEngine.Audio.dll
Guide: Synthesized sound effects

A tiny step sequencer. Patterns are whitespace-separated tokens, one per step: a note (“C4”, “F#3”, “Bb5”), “-” to hold the previous note, “.” to rest, “|” is ignored (bar lines). Drum tracks use “k” (kick), “s” (snare), “h” (hat), “o” (open hat) and “.” for rests. Shorter tracks loop to the song length, so a four-step drum loop can drive a long melody.

C#
public sealed class Song

Inheritance

object ← Song

Constructors

Song(float, int)

Creates an empty song.

C#
public Song(float bpm, int stepsPerBeat = 4)

Parameters

bpm float

Tempo in beats per minute; must be positive.

stepsPerBeat int

Pattern steps per beat; must be positive.

Exceptions

ArgumentOutOfRangeException

bpm or stepsPerBeat is not positive.

Properties

Bpm

Tempo in beats per minute.

C#
public float Bpm { get; }

Property Value

float

DrumVolume

Volume of the drum tracks (default 0.5).

C#
public float DrumVolume { get; set; }

Property Value

float

Echo

Feedback echo mix (0 disables). Adds space to otherwise dry chip voices.

C#
public float Echo { get; set; }

Property Value

float

EchoDelayBeats

Delay of the echo in beats (default 0.75).

C#
public float EchoDelayBeats { get; set; }

Property Value

float

LengthInSteps

Number of steps in the longest track; the rendered song is this long.

C#
public int LengthInSteps { get; }

Property Value

int

StepSeconds

Length of one step in seconds.

C#
public float StepSeconds { get; }

Property Value

float

StepsPerBeat

Pattern steps per beat (4 by default: each step is a sixteenth note in 4/4).

C#
public int StepsPerBeat { get; }

Property Value

int

Methods

Drums(params string[])

Adds a drum track of “k”, “s”, “h”, “o” and “.” tokens; the patterns are joined in order.

C#
public Song Drums(params string[] patterns)

Parameters

patterns string[]

Returns

Song

This song, for chaining.

Render(int)

Renders the whole song to stereo PCM, sized to loop seamlessly (echo tails wrap around).

C#
public AudioClip Render(int sampleRate = 44100)

Parameters

sampleRate int

Returns

AudioClip

Exceptions

InvalidOperationException

The song has no steps.

FormatException

A track has an invalid note or a drum track an unknown drum.

Track(Instrument, params string[])

Adds a melodic track. The patterns are joined in order into one sequence of steps.

C#
public Song Track(Instrument instrument, params string[] patterns)

Parameters

instrument Instrument

The voice that plays the notes.

patterns string[]

Note patterns (see the class remarks for the token format).

Returns

Song

This song, for chaining.