Custom music sequence

For Super Mario 64 hacking, there are several ways to create a custom music sequence.

Text file (decomp)

If you are working with the decompilation project, you may write down a music sequence in assembly. The decompilation project provides macros that helps writing music files. See includes/seq_marcos.inc for available commands.

The following code snippet is a short version of the popular Tetris theme. Put this file into the sequences folder (e.g. sound/sequences/us), give it a unique hexadecimal ID in the filename or replace an existing track. Use .s (assembly) for the file extension. In sound/sequences.json you need to choose a sound bank to use. Since this snippet is using instrument 0 only, it works well with most sound banks by default.

23_custom_tetris.s
.include "seq_macros.inc"
.section .rodata
.align 0
 
# instruments to use
.eqv INSTR_MELODY, 0
.eqv INSTR_BASS, 0
 
# note values
.eqv WHOLE, 192
.eqv QUARTER, 48
.eqv EIGHTH, 24
.eqv QUARTER_DOTTET, 72
.eqv HALF, 96
 
# note pitches
.eqv A4, 48
.eqv G4, 46
.eqv F4, 44
.eqv E4, 43
.eqv D4, 41
.eqv C4, 39
.eqv B3, 38
.eqv A3, 36
.eqv E3, 31
.eqv D3, 29
.eqv B2, 26
.eqv A2, 24
.eqv E2, 19
 
sequence_start: # this label is required at the beginning of the sequence
seq_settempo 125 # in BPM (beats per minute)
seq_setvol 127 # 0..255
seq_initchannels 0x03 # bitmask; use channel 0 and 1
 
seq_startchannel 0, .channel0 # we play melody here
seq_startchannel 1, .channel1 # we play bass here
 
seq_delay WHOLE * 8
seq_jump sequence_start # endless loop
 
seq_end
 
.channel0:
chan_largenoteson
chan_setvol 127
chan_setinstr INSTR_MELODY
 
chan_setlayer 0, .layer_melody1
chan_delay WHOLE * 4
 
chan_setlayer 0, .layer_melody2
chan_delay WHOLE * 4
 
chan_end
 
.channel1:
chan_largenoteson
chan_setvol 127
chan_setinstr INSTR_BASS
 
chan_setlayer 0, .layer_bass1
chan_delay WHOLE * 4
 
chan_setlayer 0, .layer_bass2
chan_delay WHOLE * 4
 
chan_end
 
.layer_melody1:
layer_note1 E4, QUARTER, 100
layer_note1 B3, EIGHTH, 100
layer_note1 C4, EIGHTH, 100
layer_note1 D4, QUARTER, 100
layer_note1 C4, EIGHTH, 100
layer_note1 B3, EIGHTH, 100
 
layer_note1 A3, QUARTER_DOTTET, 100
layer_note1 C4, EIGHTH, 100
 
layer_note1 E4, QUARTER, 100
layer_note1 D4, EIGHTH, 100
layer_note1 C4, EIGHTH, 100
layer_note1 B3, QUARTER_DOTTET, 100
 
layer_note1 C4, EIGHTH, 100
layer_note1 D4, QUARTER, 100
layer_note1 E4, QUARTER, 100
 
layer_note1 C4, QUARTER, 100
layer_note1 A3, QUARTER, 100
layer_note1 A3, HALF, 100
 
layer_end
 
.layer_melody2:
layer_delay EIGHTH
layer_note1 D4, QUARTER, 100
layer_note1 F4, EIGHTH, 100
layer_note1 A4, QUARTER, 100
layer_note1 G4, EIGHTH, 100
layer_note1 F4, EIGHTH, 100
 
layer_note1 E4, QUARTER_DOTTET, 100
layer_note1 C4, EIGHTH, 100
layer_note1 E4, QUARTER, 100
layer_note1 D4, EIGHTH, 100
layer_note1 C4, EIGHTH, 100
 
layer_note1 B3, QUARTER, 100
layer_note1 B3, EIGHTH, 100
layer_note1 C4, EIGHTH, 100
layer_note1 D4, QUARTER, 100
layer_note1 E4, QUARTER, 100
 
layer_note1 C4, QUARTER, 100
layer_note1 A3, QUARTER, 100
layer_note1 A3, QUARTER, 100
layer_delay QUARTER
 
layer_end
 
.layer_bass1:
layer_call .layer_fn_bass_e
layer_call .layer_fn_bass_a
layer_call .layer_fn_bass_e
layer_call .layer_fn_bass_a
layer_end
 
.layer_bass2:
layer_call .layer_fn_bass_d
layer_call .layer_fn_bass_a
layer_call .layer_fn_bass_e
layer_call .layer_fn_bass_a
layer_end
 
.layer_fn_bass_e:
layer_loop 4
layer_note1 E2, EIGHTH, 100
layer_note1 B2, EIGHTH, 100
layer_loopend
layer_end
 
.layer_fn_bass_a:
layer_loop 4
layer_note1 A2, EIGHTH, 100
layer_note1 E3, EIGHTH, 100
layer_loopend
layer_end
 
.layer_fn_bass_d:
layer_loop 4
layer_note1 D3, EIGHTH, 100
layer_note1 A3, EIGHTH, 100
layer_loopend
layer_end