Skip to content

Instantly share code, notes, and snippets.

@jturcotte
Last active October 20, 2024 17:40
Show Gist options
  • Save jturcotte/3adba9f9cddaf60ad1cacf41027b10a5 to your computer and use it in GitHub Desktop.
Save jturcotte/3adba9f9cddaf60ad1cacf41027b10a5 to your computer and use it in GitHub Desktop.

Robocop (GB) - Title Theme - #chiptrack

Play this song

  • In the Chiptrack Web Player.
  • In the desktop version from a command line prompt:
    chiptrack https://gist.github.com/jturcotte/3adba9f9cddaf60ad1cacf41027b10a5

What is this?

This gist is a Chiptrack song encoded in Markdown. It contains the following files:

  • This file: Chiptrack looks for the first .ct.md file in the gist and parses its "Song" and "Pattern [N]" and "Settings" sections.
  • instruments.wat: Contains the compiled instruments as a WebAssembly Text file. The name must be referred from the .ct.md file's Settings section.
  • instruments.zig (Optional): This is the source code for the instruments. This is attached to the gist to allow modifying and recompiling them.
  • build.zig (Optional): A zig build file that instructs the Zig compiler how to produce instruments.wat out of instruments.zig.

Other songs?

Try the GitHub Gist search.

Song

Pattern 1

S1 T1 W1 N1 N2 N3
A-4 A-2 E-5 0/8 - C-2. -
- - - - - -
A-4 - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
- - - - C-2. -
- - - - - -
A-4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
B-4 - - - C-2. -
- - - - - -

Pattern 2

S1 W1 N1 N2 N3 N4
- - - C-2. - -
- - - - - -
B-4 - C-2. - - -
- - - - - -
- - C-2. - - -
- - - - - -
B-4 - - C-2. - -
- - - - - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
- - - - - C-2.
- - . - - - -

Pattern 3

S1 T1 W1 N1 N2 N3
G#4 F#2 C#5 0/8 - C-2. -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
- - - - C-2. -
- - - - - -
G#4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - - C-2. -
- - - - - -

Pattern 4

S1 T1 W1 N1 N2 N3 N4
- - - - C-2. - -
- - - - - - -
G#4 - - C-2. - - -
- - - - - - -
- - - - C-2. - -
- - - - - - -
G#4 - - - C-2. - -
- - - - - - -
G#4 - - - - C-2. -
- - - - - - -
- - - - - - C-2.
- - - - - - -
G#4 - - - - C-2. -
- - - - - - -
- - - - - C-2. -
- - . - . - - - -

Pattern 5

S1 T1 W1 N1 N2 N3
A-4 D-2 A-4 0/8 - C-2. -
- - - - - -
A-4 - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
- - - - C-2. -
- - - - - -
A-4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
B-4 - - - C-2. -
- - - - - -

Pattern 6

S1 T1 W1 N1 N2 N3
G#4 E-2 B-4 2/8 - C-2. -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
- - - - C-2. -
- - - - - -
G#4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - - C-2. -
- - - - - -

Pattern 7

S1 T1 W1 N1 N2 N3
A-4 A-2 E-5 0/8 - C-2. -
- - - - - -
A-4 - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
- - - - C-2. -
- - - - - -
A-4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 - - C-2. - -
- - - - - -
B-4 - - - C-2. -
- - . - - - -

Pattern 8

S1 T2 N1 N2 N3
A-4 A-2 - C-2. -
- - - - -
A-4 - C-2. - -
- - - - -
A-4 A-2 C-2. - -
- - - - -
- A-2 - C-2. -
- - - - -
A-4 - - - C-2.
- - - - -
- - C-2. - -
- - - - -
A-4 E-2 C-2. - -
- - - - -
B-4 E-2 - C-2. -
- - - - -

Pattern 9

S1 T2 N1 N2 N3 N4
- A-2 - C-2. - -
- - - - - -
B-4 - C-2. - - -
- - - - - -
- A-2 C-2. - - -
- - - - - -
B-4 A-2 - C-2. - -
- - - - - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 D-2 C-2. - - -
- - - - - -
- E-2 - - - C-2.
- - - - - -

Pattern 10

S1 T2 N1 N2 N3
G#4 F#2 - C-2. -
- - - - -
G#4 - C-2. - -
- - - - -
G#4 F#2 C-2. - -
- - - - -
- F#2 - C-2. -
- - - - -
G#4 - - - C-2.
- - - - -
- - C-2. - -
- - - - -
G#4 C#2 C-2. - -
- - - - -
G#4 C#2 - C-2. -
- - - - -

Pattern 11

S1 T2 W3 N1 N2 N3 N4
- F#2 - - C-2. - -
- - - - - - -
G#4 - - C-2. - - -
- - - - - - -
- F#2 - - C-2. - -
- - - - - - -
G#4 F#2 - - C-2. - -
- - - - - - -
G#4 - - - - C-2. -
- - - - - - -
- - - - - - C-2.
- - - - - - -
G#4 C#2 - - - C-2. -
- - - - - - -
- C#2 - - - C-2. -
- - - . - - - -

Pattern 12

S1 T2 N1 N2 N3
A-4 D-2 - C-2. -
- - - - -
A-4 - C-2. - -
- - - - -
A-4 D-2 C-2. - -
- - - - -
- D-2 - C-2. -
- - - - -
A-4 - - - C-2.
- - - - -
- - C-2. - -
- - - - -
A-4 D-2 C-2. - -
- - - - -
B-4 D-2 - C-2. -
- - - - -

Pattern 13

S1 T2 N1 N2 N3 N4
- D-2 - C-2. - -
- - - - - -
B-4 - C-2. - - -
- - - - - -
- D-2 C-2. - - -
- - - - - -
B-4 D-2 - C-2. - -
- - - - - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 D-2 C-2. - - -
- - - - - -
- D-2 - - - C-2.
- - - - - -

Pattern 14

S1 T2 N1 N2 N3
G#4 E-2 - C-2. -
- - - - -
G#4 - C-2. - -
- - - - -
G#4 E-2 C-2. - -
- - - - -
- E-2 - C-2. -
- - - - -
G#4 - - - C-2.
- - - - -
- - C-2. - -
- - - - -
G#4 E-2 C-2. - -
- - - - -
G#4 E-2 - C-2. -
- - - - -

Pattern 15

S1 T2 T3 W3 N1 N2 N3 N4
- E-2 - - - C-2. - -
- - - - - - - -
G#4 - - - C-2. - - -
- - - - - - - -
- E-2 - - - C-2. - -
- - . - - - - - -
G#4 - C-4 - - C-2. - -
- - - - - - - -
G#4 - C-4 - - - C-2. -
- - - - - - - -
- - - - - - - C-2.
- - - - - - - -
G#4 - A#3 - - - C-2. -
- - - - - - - -
- - A-3 - - - C-2. -
- - - . - . - - - -

Pattern 16

S1 T2 W2 N1 N2 N3
A-4 A-2 B-3 - C-2. -
- - - - - -
A-4 - C#4 C-2. - -
- - - - - -
A-4 A-2 E-4 C-2. - -
- - - - - -
- A-2 C#4 - C-2. -
- - - - - -
A-4 - E-4 - - C-2.
- - - - - -
- - F#4 C-2. - -
- - - - - -
A-4 E-2 E-4 C-2. - -
- - - - - -
B-4 E-2 F#4 - C-2. -
- - - - - -

Pattern 17

S1 T2 W2 N1 N2 N3 N4
- A-2 A-4 - C-2. - -
- - - - - - -
B-4 - F#4 C-2. - - -
- - - - - - -
- A-2 A-4 C-2. - - -
- - - - - - -
B-4 A-2 B-4 - C-2. - -
- - - - - - -
A-4 - A-4 - - C-2. -
- - - - - - -
- - B-4 C-2. - - -
- - - - - - -
A-4 D-2 C#5 C-2. - - -
- - - - - - -
- E-2 - - - - C-2.
- - - . - - - -

Pattern 18

S1 T2 W3 N1 N2 N3
G#4 F#2 C#5 2/12 - C-2. -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 F#2 - C-2. - -
- - - - - -
- F#2 - - C-2. -
- - - - - -
G#4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
G#4 C#2 - C-2. - -
- - - - - -
G#4 C#2 - - C-2. -
- - - - - -

Pattern 19

S1 T2 W3 N1 N2 N3
A-4 D-2 B-4 0/12 - C-2. -
- - - - - -
A-4 - - C-2. - -
- - - - - -
A-4 D-2 - C-2. - -
- - - - - -
- D-2 - - C-2. -
- - - - - -
A-4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 D-2 - C-2. - -
- - - - - -
B-4 D-2 - - C-2. -
- - - . - - -

Pattern 20

S1 T2 W3 N1 N2 N3 N4
- D-2 C#5 1/12 - C-2. - -
- - - - - - -
B-4 - - C-2. - - -
- - - - - - -
- D-2 - C-2. - - -
- - - - - - -
B-4 D-2 - - C-2. - -
- - - - - - -
A-4 - - - - C-2. -
- - - - - - -
- - - C-2. - - -
- - - - - - -
A-4 D-2 - C-2. - - -
- - - - - - -
- D-2 - - - - C-2.
- - - . - - - -

Pattern 21

S1 T2 W3 W4 N1 N2 N3
G#4 E-2 A-4 0/0 - - C-2. -
- - - - - - -
G#4 - - - C-2. - -
- - - - - - -
G#4 E-2 - - C-2. - -
- - - - - - -
- E-2 - - - C-2. -
- - - . - - - -
G#4 - - G#4 - - C-2.
- - - - - - -
- - - - C-2. - -
- - - - . - - -
G#4 E-2 E-4 0/12 - C-2. - -
- - - - - - -
G#4 E-2 - - - C-2. -
- - - - - - -

Pattern 22

S1 T2 W2 N1 N2 N3
A-4 A-2 B-3 - C-2. -
- - - - - -
A-4 - C#4 C-2. - -
- - - - - -
A-4 A-2 E-4 C-2. - -
- - - - - -
- A-2 C#4 - C-2. -
- - - - - -
A-4 - E-4 - - C-2.
- - - - - -
- - F#4 C-2. - -
- - - - - -
A-4 E-2 E-4 C-2. - -
- - - - - -
B-4 E-2 F#4 - C-2. -
- - - . - - -

Pattern 23

S1 T2 W5 N1 N2 N3
A-4 A-2 C#5 0/0 - C-2. -
- - - - - -
A-4 - E-5 0/0 C-2. - -
- - - - - -
A-4 A-2 C#5 0/0 C-2. - -
- - - - - -
- A-2 B-4 0/0 - C-2. -
- - - . - - -
A-4 - C#5 2/12 - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 E-2 - C-2. - -
- - - - - -
B-4 E-2 - - C-2. -
- - - - - -

Pattern 24

S1 T2 W5 N1 N2 N3 N4
- A-2 - - C-2. - -
- - - - - - -
B-4 - - C-2. - - -
- - - - - - -
- A-2 - C-2. - - -
- - - - - - -
B-4 A-2 - - C-2. - -
- - - - - - -
A-4 - - - - C-2. -
- - - - - - -
- - - C-2. - - -
- - - - - - -
A-4 D-2 A-4 0/0 C-2. - - -
- - - - - - -
- E-2 B-4 0/0 - - - C-2.
- - - - - - -

Pattern 25

S1 T2 W5 N1 N2 N3
G#4 F#2 C#5 0/0 - C-2. -
- - - - - -
G#4 - E-5 0/0 C-2. - -
- - - - - -
G#4 F#2 C#5 0/0 C-2. - -
- - - - - -
- F#2 B-4 0/0 - C-2. -
- - - . - - -
G#4 - C#5 2/12 - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
G#4 C#2 - C-2. - -
- - - - - -
G#4 C#2 - - C-2. -
- - - - - -

Pattern 26

S1 T2 W5 N1 N2 N3 N4
- F#2 - - C-2. - -
- - - - - - -
G#4 - - C-2. - - -
- - - - - - -
- F#2 - - C-2. - -
- - - - - - -
G#4 F#2 - - C-2. - -
- - - - - - -
G#4 - - - - C-2. -
- - - - - - -
- - - - - - C-2.
- - - - - - -
G#4 C#2 A-4 0/0 - - C-2. -
- - - - - - -
- C#2 B-4 0/0 - - C-2. -
- - - . - - - -

Pattern 27

S1 T2 W5 N1 N2 N3
A-4 D-2 C#5 0/12 - C-2. -
- - - - - -
A-4 - - C-2. - -
- - - - - -
A-4 D-2 - C-2. - -
- - - - - -
- D-2 - - C-2. -
- - - - - -
A-4 - - - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 D-2 - C-2. - -
- - - - - -
B-4 D-2 - - C-2. -
- - - . - - -

Pattern 28

S1 T2 W5 N1 N2 N3 N4
- D-2 E-5 0/12 - C-2. - -
- - - - - - -
B-4 - - C-2. - - -
- - - - - - -
- D-2 - C-2. - - -
- - - - - - -
B-4 D-2 - - C-2. - -
- - - - - - -
A-4 - - - - C-2. -
- - - - - - -
- - - C-2. - - -
- - - - - - -
A-4 D-2 - C-2. - - -
- - - - - - -
- D-2 - - - - C-2.
- - - . - - - -

Pattern 29

S1 T2 W6 N1 N2 N3
G#4 E-2 C#5 - C-2. -
- - B-4 - - -
G#4 - A-4 C-2. - -
- - B-4 - - -
G#4 E-2 A-4 C-2. - -
- - F#4 - - -
- E-2 A-4 - C-2. -
- - F#4 - - -
G#4 - E-4 - - C-2.
- - F#4 - - -
- - E-4 C-2. - -
- - C#4 - - -
G#4 E-2 E-4 C-2. - -
- - C#4 - - -
G#4 E-2 B-3 - C-2. -
- - C#4 - - -

Pattern 30

S1 T2 W5 N1 N2 N3
A-4 A-2 C#5 0/0 - C-2. -
- - - - - -
A-4 - E-5 0/0 C-2. - -
- - - - - -
A-4 A-2 C#5 0/0 C-2. - -
- - - - - -
- A-2 B-4 0/0 - C-2. -
- - - . - - -
A-4 - C#5 2/12 - - C-2.
- - - - - -
- - - C-2. - -
- - - - - -
A-4 E-2 - C-2. - -
- - - - - -
B-4 E-2 - - C-2. -
- - - - - -

Pattern 31

S1 W1 N1 N2 N3 N4
A-4 E-5 0/8 - C-2. - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - C-2. - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
B-4 - - - - C-2.
- - - - - -

Pattern 32

S1 W1 N1 N2 N3 N4
- - - C-2. - -
- - - - - -
B-4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - - - -
B-4 - - C-2. - -
- - - - - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
- - - - - C-2.
- - . - - - -

Pattern 33

S1 W1 N1 N2 N3 N4
G#4 C#5 0/8 - C-2. - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - C-2. - -
G#4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
G#4 - - - - C-2.
- - - - - -

Pattern 34

S1 W1 N1 N2 N3 N4
- - - C-2. - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - - - C-2.
- - . - - - -

Pattern 35

S1 W1 N1 N2 N3 N4
A-4 A-4 0/8 - C-2. - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - C-2. - -
A-4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
A-4 - C-2. - - -
- - - - - -
B-4 - - - - C-2.
- - - - - -

Pattern 36

S1 W1 N1 N2 N3 N4
G#4 B-4 2/8 - C-2. - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - C-2. - -
G#4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
G#4 - - - - C-2.
- - - - - -

Pattern 37

S1 W1 N1 N2 N3 N4
- - - C-2. - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - C-2. - -
- - - - - -
G#4 - - C-2. - -
- - - - - -
G#4 - - - C-2. -
- - - - - -
- - C-2. - - -
- - - - - -
G#4 - C-2. - - -
- - - - - -
- - - - - C-2.
- - . - - - -

Pattern 38

S1 W1 N1 N2 N3
A-4 E-5 0/8 - C-2 -
- . - - - . -
A-4 - C-2 - -
- . - - . - -
A-4 - C-2 - -
- - - . - -
- - - C-2 -
- . - - - . -
A-4 - - - C-2
- - - - - .
- - C-2 - -
- . - - . - -
A-4 - C-2 - -
- . - - . - -
A-4 - - C-2 -
- - - - . -

Pattern 39

S1 W1 N1 N2 N3 N4
- - - C-2 - -
- - - - . - -
A-4 - C-2 - - -
- - - . - - -
- - C-2 - - -
- . - - . - - -
A-4 - - C-2 - -
- . - - - . - -
A-4 - - - C-2 -
- - - - - . -
- - C-2 - - -
- . - - . - - -
A-4 - C-2 - - -
- - - . - - -
- - - - - C-2
- . - . - - - - .

Pattern 40

S1 W1 N1 N2 N3
A-4 C#5 0/8 - C-2 -
- . - - - . -
A-4 - C-2 - -
- . - - . - -
A-4 - C-2 - -
- - - . - -
- - - C-2 -
- . - - - . -
A-4 - - - C-2
- - - - - .
- - C-2 - -
- . - - . - -
A-4 - C-2 - -
- . - - . - -
A-4 - - C-2 -
- - - - . -

Pattern 41

S1 W1 N1 N2 N3 N4
- - - C-2 - -
- - - - . - -
A-4 - C-2 - - -
- - - . - - -
- - - C-2 - -
- . - - - . - -
A-4 - - C-2 - -
- . - - - . - -
A-4 - - - C-2 -
- - - - - . -
- - - - - C-2
- . - - - - - .
A-4 - - - C-2 -
- - - - - . -
- - - - C-2 -
- . - . - - - . -

Pattern 42

S1 W1 N1 N2 N3
A-4 A-4 0/8 - C-2 -
- . - - - . -
A-4 - C-2 - -
- . - - . - -
A-4 - C-2 - -
- - - . - -
- - - C-2 -
- . - - - . -
A-4 - - - C-2
- - - - - .
- - C-2 - -
- . - - . - -
A-4 - C-2 - -
- . - - . - -
A-4 - - C-2 -
- - - - . -

Pattern 43

S1 W1 N1 N2 N3
A-4 B-4 2/8 - C-2 -
- . - - - . -
A-4 - C-2 - -
- . - - . - -
A-4 - C-2 - -
- - - . - -
- - - C-2 -
- . - - - . -
A-4 - - - C-2
- - - - - .
- - C-2 - -
- . - - . - -
A-4 - C-2 - -
- . - - . - -
A-4 - - C-2 -
- - - - . -

Pattern 44

S2 T1 W7 N1 N2 N3
C#5 A-2 E-3 - C-2 -
- - - - - . -
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- - - - - . -
- - - - - C-2
- - - - - - .
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- . - . - - - . -

Pattern 45

N1 N2 N3 N4
- C-2 - -
- - . - -
C-2 - - -
- . - - -
C-2 - - -
- . - - -
- C-2 - -
- - . - -
- - C-2 -
- - - . -
C-2 - - -
- . - - -
C-2 - - -
- . - - -
- - - C-2
- - - - .

Pattern 46

S2 T1 W7 N1 N2 N3
C#5 F#2 F#3 - C-2 -
- - - - - . -
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- - - - - . -
- - - - - C-2
- - - - - - .
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- . - . - - - . -

Pattern 47

W7 N1 N2 N3 N4
- - C-2 - -
- - - . - -
- C-2 - - -
- - . - - -
- - C-2 - -
- - - . - -
- - C-2 - -
- - - . - -
- - - C-2 -
- - - - . -
- - - - C-2
- - - - - .
- - - C-2 -
- - - - . -
- - - C-2 -
- . - - - . -

Pattern 48

S2 T1 W7 N1 N2 N3
C#5 D-2 A-3 - C-2 -
- - - - - . -
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- - - - - . -
- - - - - C-2
- - - - - - .
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- . - . - - - . -

Pattern 49

S2 T1 W7 N1 N2 N3
C#5 E-2 E-3 - C-2 -
- - - - - . -
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- - - - - . -
- - - - - C-2
- - - - - - .
- - - C-2 - -
- - - - . - -
- - - C-2 - -
- - - - . - -
- - - - C-2 -
- . - . - - - . -

Pattern 50

S1 T2 T3 W6 N1 N2 N3 N4
- E-2 - B-3 - C-2. - -
- - - A-3 - - - -
G#4 - - B-3 C-2. - - -
- - - A-3 - - - -
- E-2 - F#3 - C-2. - -
- - . - A-3 - - - -
G#4 - C-4 F#3 - C-2. - -
- - - E-3 - - - -
G#4 - C-4 F#3 - - C-2. -
- - - E-3 - - - -
- - - C#3 - - - C-2.
- - - E-3 - - - -
G#4 - A#3 C#3 - - C-2. -
- - - B-2 - - - -
- - A-3 C#3 - - C-2. -
- - - . B-2. - - - -

Settings

  • InstrumentsFile: instruments.wat
  • FramesPerStep: 7
// Copyright © 2024 Jocelyn Turcotte <[email protected]>
// SPDX-License-Identifier: CC0-1.0
//
// After modifying the instruments Zig source code, you must re-compile the WebAssembly file that can be executed by Chiptrack.
// This file instructs the Zig compiler how to compile it and for this you need
// - The Zig compiler, available at https://ziglang.org/download/
// - ct.zig, the Chiptrack instruments support module, available at https://raw.githubusercontent.com/jturcotte/chiptrack/v0.4/instruments/ct.zig
// - wasm2wat in your PATH, available at https://github.com/WebAssembly/wabt/releases
//
// Then to rebuild the instruments .wat file from modified source code:
// zig build
//
// The compiled instruments.wat file will be in the source folder, beside the zig file.
// Chiptrack will reload it automatically if the song is currently loaded.
const std = @import("std");
pub fn build(b: *std.Build) void {
// Build options, "zig build --help" will show their usage.
const source_file =
b.option([]const u8, "source", "Instruments source file to compile (default: instruments.zig).") orelse "instruments.zig";
const ct_zig_path =
b.option([]const u8, "ct.zig", "Path to ct.zig (default: ct.zig).") orelse "ct.zig";
const wat_out =
b.option(bool, "wat", "Compile the instruments to WAT (Web Assembly Text Format) instead of binary WASM. Chiptrack can load either format but this is better for GitHub gist uploads and requires wasm2wat in PATH (default: true).") orelse true;
if (std.fs.cwd().access(ct_zig_path, .{}) == std.fs.Dir.AccessError.FileNotFound)
@panic("ct.zig was not found but is necessary to build. You can download it from https://raw.githubusercontent.com/jturcotte/chiptrack/v0.4/instruments/ct.zig .");
// Listing the module here also allows editors like VSCode with Zig language support to discover it and provide code completion.
const ct_module = b.addModule("ct", .{ .root_source_file = .{ .cwd_relative = ct_zig_path } });
// Build the wasm file.
const wasm = b.addExecutable(.{
.name = std.fs.path.stem(source_file),
.root_source_file = .{ .cwd_relative = source_file },
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.optimize = .ReleaseFast,
});
wasm.rdynamic = true;
wasm.export_table = true;
wasm.max_memory = 65536;
wasm.stack_size = 8192;
wasm.root_module.addImport("ct", ct_module);
const wf = b.addWriteFiles();
b.getInstallStep().dependOn(&wf.step);
if (wat_out) {
// Generate the wat file by calling wasm2wat on the compiled wasm.
const wasm2wat = b.addSystemCommand(&.{ "wasm2wat", "-f" });
wasm2wat.addFileArg(wasm.getEmittedBin());
const final_url = std.fmt.allocPrint(b.allocator, "{s}.wat", .{wasm.name}) catch unreachable;
// Copy the output wat file into the source folder, beside the zig file.
wf.addCopyFileToSource(wasm2wat.captureStdOut(), final_url);
} else {
// Copy the wasm file into the source folder, beside the zig file.
wf.addCopyFileToSource(wasm.getEmittedBin(), std.fmt.allocPrint(b.allocator, "{s}.wasm", .{wasm.name}) catch unreachable);
}
}
(module $instruments.wasm
(type (;0;) (func (param i32 i32 i32 i32 i32 i32) (result i32)))
(type (;1;) (func (param i32 i32 i32 i32 i32 i32 i32)))
(type (;2;) (func (param i32 i32)))
(type (;3;) (func))
(type (;4;) (func (param i32 i32 i32 i32)))
(type (;5;) (func (param i32 i32 i32)))
(import "env" "set_instrument_at_column" (func $set_instrument_at_column (type 0)))
(import "env" "define_param" (func $define_param (type 1)))
(import "env" "gba_set_sound_reg" (func $gba_set_sound_reg (type 2)))
(import "env" "gba_set_wave_table" (func $gba_set_wave_table (type 2)))
(func $_start (type 3)
(local i32)
(drop
(call $set_instrument_at_column
(i32.const 8252)
(i32.const 0)
(i32.const 0)
(i32.const 1)
(i32.const 0)
(i32.const 2)))
(drop
(call $set_instrument_at_column
(i32.const 8240)
(i32.const 0)
(i32.const 0)
(i32.const 3)
(i32.const 0)
(i32.const 4)))
(drop
(call $set_instrument_at_column
(i32.const 8249)
(i32.const 0)
(i32.const 0)
(i32.const 5)
(i32.const 0)
(i32.const 6)))
(drop
(call $set_instrument_at_column
(i32.const 8237)
(i32.const 0)
(i32.const 0)
(i32.const 7)
(i32.const 0)
(i32.const 8)))
(drop
(call $set_instrument_at_column
(i32.const 8228)
(i32.const 1)
(i32.const 0)
(i32.const 9)
(i32.const 0)
(i32.const 10)))
(call $define_param
(local.tee 0
(i32.and
(call $set_instrument_at_column
(i32.const 8246)
(i32.const 1)
(i32.const 0)
(i32.const 11)
(i32.const 12)
(i32.const 13))
(i32.const 255)))
(i32.const 0)
(i32.const 8258)
(i32.const 1)
(i32.const 0)
(i32.const 12)
(i32.const 0))
(call $define_param
(local.get 0)
(i32.const 1)
(i32.const 8192)
(i32.const 8)
(i32.const 0)
(i32.const 127)
(i32.const 0))
(drop
(call $set_instrument_at_column
(i32.const 8234)
(i32.const 1)
(i32.const 0)
(i32.const 14)
(i32.const 0)
(i32.const 15)))
(call $define_param
(local.tee 0
(i32.and
(call $set_instrument_at_column
(i32.const 8225)
(i32.const 1)
(i32.const 0)
(i32.const 16)
(i32.const 12)
(i32.const 13))
(i32.const 255)))
(i32.const 0)
(i32.const 8258)
(i32.const 1)
(i32.const 0)
(i32.const 12)
(i32.const 0))
(call $define_param
(local.get 0)
(i32.const 1)
(i32.const 8192)
(i32.const 8)
(i32.const 0)
(i32.const 127)
(i32.const 0))
(drop
(call $set_instrument_at_column
(i32.const 8219)
(i32.const 2)
(i32.const 0)
(i32.const 17)
(i32.const 18)
(i32.const 19)))
(call $define_param
(local.tee 0
(i32.and
(call $set_instrument_at_column
(i32.const 8216)
(i32.const 2)
(i32.const 0)
(i32.const 20)
(i32.const 12)
(i32.const 13))
(i32.const 255)))
(i32.const 0)
(i32.const 8258)
(i32.const 1)
(i32.const 0)
(i32.const 12)
(i32.const 0))
(call $define_param
(local.get 0)
(i32.const 1)
(i32.const 8192)
(i32.const 8)
(i32.const 0)
(i32.const 127)
(i32.const 0))
(drop
(call $set_instrument_at_column
(i32.const 8213)
(i32.const 2)
(i32.const 0)
(i32.const 21)
(i32.const 18)
(i32.const 0)))
(drop
(call $set_instrument_at_column
(i32.const 8210)
(i32.const 2)
(i32.const 0)
(i32.const 22)
(i32.const 18)
(i32.const 23)))
(drop
(call $set_instrument_at_column
(i32.const 8255)
(i32.const 3)
(i32.const 0)
(i32.const 24)
(i32.const 0)
(i32.const 25)))
(drop
(call $set_instrument_at_column
(i32.const 8243)
(i32.const 3)
(i32.const 0)
(i32.const 26)
(i32.const 0)
(i32.const 27)))
(drop
(call $set_instrument_at_column
(i32.const 8231)
(i32.const 3)
(i32.const 0)
(i32.const 28)
(i32.const 0)
(i32.const 29)))
(drop
(call $set_instrument_at_column
(i32.const 8222)
(i32.const 3)
(i32.const 0)
(i32.const 30)
(i32.const 0)
(i32.const 31))))
(func $instruments.square1_1.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108962)
(i32.const 45760))
(call $gba_set_sound_reg
(i32.const 67108964)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.square1_1.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.lt_u
(local.get 2)
(i32.const 2)))
(block ;; label = @2
(block ;; label = @3
(block ;; label = @4
(block ;; label = @5
(br_table 2 (;@3;) 3 (;@2;) 0 (;@5;) 1 (;@4;) 2 (;@3;)
(i32.and
(local.get 2)
(i32.const 3))))
(local.set 0
(i32.const 142182))
(br 2 (;@2;)))
(local.set 0
(i32.const 169472))
(br 1 (;@2;)))
(local.set 0
(i32.shl
(local.get 0)
(i32.const 1))))
(call $gba_set_sound_reg
(i32.const 67108964)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047)))))
(func $instruments.square1_2.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108962)
(i32.const 55232))
(call $gba_set_sound_reg
(i32.const 67108964)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.square1_2.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.rem_u
(local.get 2)
(i32.const 14)))
(call $gba_set_sound_reg
(i32.const 67108964)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(select
(i32.shr_u
(i32.mul
(local.get 0)
(i32.const 271))
(i32.const 8))
(local.get 0)
(i32.rem_u
(local.get 2)
(i32.const 28)))))
(i32.const 2047)))))
(func $instruments.square2_1.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108968)
(i32.const 63296))
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(i32.shl
(local.get 0)
(i32.const 1))))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.square2_1.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(block ;; label = @2
(block ;; label = @3
(br_if 0 (;@3;)
(i32.le_u
(local.get 2)
(i32.const 36)))
(local.set 0
(i32.add
(i32.add
(i32.sub
(local.get 0)
(i32.div_u
(local.get 0)
(i32.const 36)))
(i32.mul
(i32.sub
(i32.xor
(local.tee 2
(i32.add
(i32.and
(i32.add
(local.get 2)
(i32.const 2))
(i32.const 7))
(i32.const -4)))
(local.tee 2
(i32.shr_s
(local.get 2)
(i32.const 31))))
(local.get 2))
(i32.div_u
(local.get 0)
(i32.const 72))))
(i32.const 1)))
(br 1 (;@2;)))
(br_if 1 (;@1;)
(i32.ne
(local.get 2)
(i32.const 2))))
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047)))))
(func $instruments.square2_2.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108968)
(i32.const 54336))
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(i32.shl
(local.get 0)
(i32.const 1))))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.square2_2.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(block ;; label = @2
(block ;; label = @3
(br_if 0 (;@3;)
(i32.le_u
(local.get 2)
(i32.const 15)))
(local.set 0
(i32.add
(i32.add
(i32.sub
(local.get 0)
(i32.div_u
(local.get 0)
(i32.const 36)))
(i32.mul
(i32.sub
(i32.xor
(local.tee 2
(i32.add
(i32.and
(i32.add
(local.get 2)
(i32.const -1))
(i32.const 7))
(i32.const -4)))
(local.tee 2
(i32.shr_s
(local.get 2)
(i32.const 31))))
(local.get 2))
(i32.div_u
(local.get 0)
(i32.const 72))))
(i32.const 1)))
(br 1 (;@2;)))
(br_if 1 (;@1;)
(i32.ne
(local.get 2)
(i32.const 2))))
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047)))))
(func $instruments.square2_3.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108968)
(i32.const 62080))
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.square2_3.frame (type 5) (param i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108972)
(i32.and
(i32.sub
(i32.mul
(local.get 2)
(i32.const 2000))
(i32.div_u
(i32.const 33554432)
(local.get 0)))
(i32.const 2047))))
(func $instruments.wave_1.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8276)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(i32.store offset=8512
(i32.const 0)
(i32.div_u
(i32.shl
(local.get 0)
(i32.const 7))
(i32.load
(i32.add
(i32.shl
(local.tee 0
(i32.rem_u
(local.get 2)
(i32.const 13)))
(i32.const 2))
(i32.const 8356)))))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 8192))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.load offset=8512
(i32.const 0))))
(i32.const 2047))
(i32.const 32768)))
(i32.store16 offset=8508
(i32.const 0)
(local.get 3))
(i32.store offset=8500
(i32.const 0)
(i32.shl
(local.get 0)
(i32.const 3))))
(func $instruments.wave_glide_vibrato_r (type 5) (param i32 i32 i32)
(local i32 i32)
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 0))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047))
(i32.const 32768)))
(block ;; label = @1
(br_if 0 (;@1;)
(i32.eqz
(local.tee 3
(i32.load offset=8500
(i32.const 0)))))
(br_if 0 (;@1;)
(i32.lt_u
(local.get 3)
(local.get 2)))
(br_if 0 (;@1;)
(i32.eqz
(local.tee 4
(i32.load offset=8512
(i32.const 0)))))
(local.set 0
(i32.add
(i32.div_s
(i32.mul
(i32.sub
(local.get 0)
(local.get 4))
(local.get 2))
(local.get 3))
(local.get 4))))
(i32.store offset=8504
(i32.const 0)
(local.get 0)))
(func $instruments.wave_glide_vibrato_f (type 5) (param i32 i32 i32)
(local i32 i32)
(block ;; label = @1
(block ;; label = @2
(block ;; label = @3
(br_if 0 (;@3;)
(i32.eqz
(local.tee 3
(i32.load offset=8500
(i32.const 0)))))
(br_if 0 (;@3;)
(i32.lt_u
(local.get 3)
(local.get 2)))
(br_if 1 (;@2;)
(i32.eqz
(local.tee 4
(i32.load offset=8512
(i32.const 0)))))
(local.set 0
(i32.add
(i32.div_s
(i32.mul
(i32.sub
(local.get 0)
(local.get 4))
(local.get 2))
(local.get 3))
(local.get 4)))
(br 1 (;@2;)))
(br_if 1 (;@1;)
(i32.lt_u
(local.get 2)
(i32.const 50)))
(br_if 1 (;@1;)
(i32.eqz
(local.tee 3
(i32.load16_u offset=8508
(i32.const 0)))))
(local.set 0
(i32.add
(i32.add
(i32.sub
(local.get 0)
(local.tee 4
(i32.div_u
(local.get 0)
(i32.const 36))))
(i32.mul
(i32.sub
(i32.xor
(local.tee 0
(i32.add
(i32.sub
(local.tee 2
(i32.rem_s
(local.tee 0
(i32.add
(i32.add
(local.tee 2
(i32.rem_s
(local.tee 0
(i32.add
(i32.sub
(local.get 2)
(i32.shr_u
(local.get 3)
(i32.const 2)))
(i32.const -49)))
(local.get 3)))
(local.get 3))
(select
(i32.and
(i32.shr_s
(local.get 0)
(i32.const 31))
(local.get 3))
(i32.const 0)
(local.get 2))))
(local.get 3)))
(i32.shr_u
(local.get 3)
(i32.const 1)))
(select
(i32.and
(i32.shr_s
(local.get 0)
(i32.const 31))
(local.get 3))
(i32.const 0)
(local.get 2))))
(local.tee 0
(i32.shr_s
(local.get 0)
(i32.const 31))))
(local.get 0))
(i32.div_u
(i32.shl
(local.get 4)
(i32.const 2))
(local.get 3))))
(i32.const 1))))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047)))))
(func $instruments.wave_2.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8292)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 8192))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.shl
(local.get 0)
(i32.const 1))))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.wave_2.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.ne
(local.get 2)
(i32.const 1)))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047))
(i32.const 32768)))))
(func $instruments.wave_3.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8292)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(i32.store offset=8512
(i32.const 0)
(i32.div_u
(i32.shl
(local.get 0)
(i32.const 7))
(i32.load
(i32.add
(i32.shl
(local.tee 0
(i32.rem_u
(local.get 2)
(i32.const 13)))
(i32.const 2))
(i32.const 8356)))))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 8192))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.load offset=8512
(i32.const 0))))
(i32.const 2047))
(i32.const 32768)))
(i32.store16 offset=8508
(i32.const 0)
(local.get 3))
(i32.store offset=8500
(i32.const 0)
(i32.shl
(local.get 0)
(i32.const 3))))
(func $instruments.wave_4.press (type 4) (param i32 i32 i32 i32)
(local i32)
(i32.store offset=8512
(i32.const 0)
(select
(select
(local.tee 4
(i32.load offset=8504
(i32.const 0)))
(local.get 0)
(i32.gt_u
(local.get 4)
(local.get 0)))
(local.get 0)
(local.get 4)))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8292)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 8192))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.load offset=8512
(i32.const 0))))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.wave_simple_r (type 5) (param i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 0))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047))
(i32.const 32768)))
(i32.store offset=8504
(i32.const 0)
(local.get 0)))
(func $instruments.wave_4.frame (type 5) (param i32 i32 i32)
(local i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.gt_u
(local.get 2)
(i32.const 12)))
(br_if 0 (;@1;)
(i32.eqz
(local.tee 3
(i32.load offset=8512
(i32.const 0)))))
(local.set 4
(i32.sub
(local.get 3)
(local.get 0)))
(block ;; label = @2
(block ;; label = @3
(br_if 0 (;@3;)
(i32.le_u
(local.get 2)
(i32.const 3)))
(local.set 2
(i32.sub
(local.tee 3
(i32.add
(local.get 4)
(local.get 3)))
(i32.div_u
(i32.mul
(i32.sub
(local.get 3)
(local.get 0))
(i32.add
(local.get 2)
(i32.const -3)))
(i32.const 9))))
(br 1 (;@2;)))
(local.set 2
(i32.add
(i32.div_u
(i32.mul
(local.get 4)
(local.get 2))
(i32.const 3))
(local.get 3))))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 2)))
(i32.const 2047)))))
(func $instruments.wave_5.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8308)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(i32.store offset=8512
(i32.const 0)
(i32.div_u
(i32.shl
(local.get 0)
(i32.const 7))
(i32.load
(i32.add
(i32.shl
(local.tee 0
(i32.rem_u
(local.get 2)
(i32.const 13)))
(i32.const 2))
(i32.const 8356)))))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 8192))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.load offset=8512
(i32.const 0))))
(i32.const 2047))
(i32.const 32768)))
(i32.store16 offset=8508
(i32.const 0)
(local.get 3))
(i32.store offset=8500
(i32.const 0)
(i32.shl
(local.get 0)
(i32.const 3))))
(func $instruments.wave_6.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8324)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 16384))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.wave_7.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 0))
(call $gba_set_wave_table
(i32.const 8340)
(i32.const 16))
(call $gba_set_sound_reg
(i32.const 67108976)
(i32.const 192))
(call $gba_set_sound_reg
(i32.const 67108978)
(i32.const 24576))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.or
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(local.get 0)))
(i32.const 2047))
(i32.const 32768))))
(func $instruments.wave_7.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.le_u
(local.get 2)
(i32.const 49)))
(call $gba_set_sound_reg
(i32.const 67108980)
(i32.and
(i32.sub
(i32.const 0)
(i32.div_u
(i32.const 16777216)
(i32.add
(i32.add
(i32.sub
(local.get 0)
(i32.div_u
(local.get 0)
(i32.const 36)))
(i32.mul
(i32.sub
(i32.xor
(local.tee 2
(i32.add
(i32.and
(i32.add
(local.get 2)
(i32.const 5))
(i32.const 7))
(i32.const -4)))
(local.tee 2
(i32.shr_s
(local.get 2)
(i32.const 31))))
(local.get 2))
(i32.div_u
(local.get 0)
(i32.const 72))))
(i32.const 1))))
(i32.const 2047)))))
(func $instruments.noise_1.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108984)
(i32.const 28928))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.const 32768)))
(func $instruments.noise_1.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.gt_u
(local.get 2)
(i32.const 8)))
(br_if 0 (;@1;)
(i32.eqz
(i32.and
(i32.shr_u
(i32.const 479)
(i32.and
(local.get 2)
(i32.const 65535)))
(i32.const 1))))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.load
(i32.add
(i32.shl
(local.get 2)
(i32.const 2))
(i32.const 8408))))))
(func $instruments.noise_2.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108984)
(i32.const 41216))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.const 32768)))
(func $instruments.noise_2.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.gt_u
(local.get 2)
(i32.const 5)))
(br_if 0 (;@1;)
(i32.eqz
(i32.and
(i32.shr_u
(i32.const 59)
(i32.and
(local.get 2)
(i32.const 255)))
(i32.const 1))))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.load
(i32.add
(i32.shl
(local.get 2)
(i32.const 2))
(i32.const 8444))))))
(func $instruments.noise_3.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108984)
(i32.const 41472))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.const 32768)))
(func $instruments.noise_3.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.gt_u
(local.get 2)
(i32.const 7)))
(br_if 0 (;@1;)
(i32.eqz
(i32.and
(i32.shr_u
(i32.const 239)
(i32.and
(local.get 2)
(i32.const 255)))
(i32.const 1))))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.load
(i32.add
(i32.shl
(local.get 2)
(i32.const 2))
(i32.const 8468))))))
(func $instruments.noise_4.press (type 4) (param i32 i32 i32 i32)
(call $gba_set_sound_reg
(i32.const 67108984)
(i32.const 29184))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.const 32768)))
(func $instruments.noise_4.frame (type 5) (param i32 i32 i32)
(block ;; label = @1
(br_if 0 (;@1;)
(i32.gt_u
(local.get 2)
(i32.const 4)))
(call $gba_set_sound_reg
(i32.const 67108988)
(i32.add
(local.get 2)
(i32.const 17)))))
(table (;0;) 32 32 funcref)
(memory (;0;) 1 1)
(global $__stack_pointer (mut i32) (i32.const 8192))
(export "memory" (memory 0))
(export "_start" (func $_start))
(export "__indirect_function_table" (table 0))
(elem (;0;) (i32.const 1) func $instruments.square1_1.press $instruments.square1_1.frame $instruments.square1_2.press $instruments.square1_2.frame $instruments.square2_1.press $instruments.square2_1.frame $instruments.square2_2.press $instruments.square2_2.frame $instruments.square2_3.press $instruments.square2_3.frame $instruments.wave_1.press $instruments.wave_glide_vibrato_r $instruments.wave_glide_vibrato_f $instruments.wave_2.press $instruments.wave_2.frame $instruments.wave_3.press $instruments.wave_4.press $instruments.wave_simple_r $instruments.wave_4.frame $instruments.wave_5.press $instruments.wave_6.press $instruments.wave_7.press $instruments.wave_7.frame $instruments.noise_1.press $instruments.noise_1.frame $instruments.noise_2.press $instruments.noise_2.frame $instruments.noise_3.press $instruments.noise_3.frame $instruments.noise_4.press $instruments.noise_4.frame)
(data $.rodata (i32.const 8192) "VP Vibrato Period\00W7\00W6\00W5\00W4\00N4\00W3\00T3\00N3\00W2\00T2\00S2\00N2\00W1\00T1\00S1\00N1\00Glide (semitones)\00\01#Eg\89\ab\cd\ef\fe\dc\ba\98vT2\10\fe\dc\ba\98vT2\10\00\00\00\00\11\11\11\11\fe\dc\ba\98vT2\10\00\00\00\00\ff\ff\ff\ff\ff\88\00\88\ff\88\00\88\08\07\06\05\06\07\08\09\ff\ff\00\00\ff\ff\00\00\ff\ff\00\00\ff\ff\00\00\80\00\00\00\88\00\00\00\90\00\00\00\98\00\00\00\a1\00\00\00\ab\00\00\00\b5\00\00\00\c0\00\00\00\cb\00\00\00\d7\00\00\00\e4\00\00\00\f2\00\00\00\00\01\00\00\10\00\00\00 \00\00\00\10\00\00\00 \00\00\00\10\00\00\00\10\00\00\00 \00\00\00\10\00\00\00 \00\00\00Y\00\00\00[\00\00\00Y\00\00\00]\00\00\00_\00\00\00`\00\00\00Y\00\00\00y\00\00\00i\00\00\00P\00\00\00Y\00\00\00Q\00\00\00A\00\00\00Q\00\00\00"))
// This file contains the source code for the instruments executed by the song patterns
// as press, release and frame (held) events.
// Compiling this file using the provided build.zig will generate instruments.wat,
// which is referred by the song's InstrumentsFile setting.
const std = @import("std");
const math = std.math;
const ct = @import("ct");
const gba = ct.gba;
fn toIntFreq(comptime float_freq: f32) u32 {
return @intFromFloat(float_freq * 256);
}
// Approximation of semitone frequency ratios using integer fractions
// at compile time to avoid floating point operations on the GBA.
const semitone_128th = [_]u32{
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 0.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 1.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 2.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 3.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 4.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 5.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 6.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 7.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 8.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 9.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 10.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 11.0 / 12.0))),
@intFromFloat(math.round(128.0 * math.pow(f32, 2, 12.0 / 12.0))),
};
fn arpeggio_cs5_e5(freq: u32, t: u32, chan: gba.Channel) void {
if (t > 1) {
const f = switch (t % 4) {
1 => freq,
2 => toIntFreq(555.4),
3 => toIntFreq(662.0),
0 => freq * 2,
else => unreachable,
};
gba.CtrlFreq.init().withSquareFreq(f).writeTo(chan);
}
}
fn vibrato(delay: u32, p: u16, freq: u32, t: u32) u32 {
// Use almost half a semitone (0.475) amplitude for the delta triangle wave.
const ratio = comptime @as(u32, @intFromFloat(math.round(1 / (math.pow(f32, 1.0594630943592953, 0.475) - 1))));
const a = freq / ratio;
const delta = 1 + 4 * a / p * @abs(@mod((@mod(@as(i32, @intCast(t - delay)) - p / 4, p) + p), p) - p / 2) - a;
return freq + delta;
}
var glide_base_freq: u32 = 0;
var glide_next_freq: u32 = 0;
fn glide(period: u32, freq: u32, t: u32) u32 {
if (glide_base_freq != 0) {
const s_freq: i32 = @intCast(freq);
const s_base: i32 = @intCast(glide_base_freq);
const s_t: i32 = @intCast(t);
const s_period: i32 = @intCast(period);
return @intCast(@divTrunc((s_freq - s_base) * s_t, s_period) + s_base);
} else {
return freq;
}
}
const square1_1 = struct {
pub const id: [*:0]const u8 = "S1";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(11)
.withEnvDir(gba.env_dec)
.withEnvInterval(2)
.withDuty(gba.dut_3_4)
.writeTo(gba.square1);
gba.CtrlFreq.init()
.withTrigger(1)
.withSquareFreq(freq)
.writeTo(gba.square1);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
arpeggio_cs5_e5(freq, t, gba.square1);
}
};
const square1_2 = struct {
pub const id: [*:0]const u8 = "S2";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(13)
.withEnvDir(gba.env_dec)
.withEnvInterval(7)
.withDuty(gba.dut_3_4)
.writeTo(gba.square1);
gba.CtrlFreq.init()
.withTrigger(1)
.withSquareFreq(freq)
.writeTo(gba.square1);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
if (t % 14 == 0) {
if (t % 28 == 0)
gba.CtrlFreq.init().withSquareFreq(freq).writeTo(gba.square1)
else
gba.CtrlFreq.init().withSquareFreq(freq * 271 / 256).writeTo(gba.square1);
}
}
};
const square2_1 = struct {
pub const id: [*:0]const u8 = "T1";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(15)
.withEnvDir(gba.env_dec)
.withEnvInterval(7)
.withDuty(gba.dut_1_4)
.writeTo(gba.square2);
gba.CtrlFreq.init()
.withSquareFreq(freq * 2)
.withTrigger(1)
.writeTo(gba.square2);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
const delay = 36;
if (t > delay) {
gba.CtrlFreq.init()
.withSquareFreq(vibrato(delay, 8, freq, t))
.writeTo(gba.square2);
} else if (t == 2) {
gba.CtrlFreq.init()
.withSquareFreq(freq)
.writeTo(gba.square2);
}
}
};
const square2_2 = struct {
pub const id: [*:0]const u8 = "T2";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(13)
.withEnvDir(gba.env_dec)
.withEnvInterval(4)
.withDuty(gba.dut_1_4)
.writeTo(gba.square2);
gba.CtrlFreq.init()
.withSquareFreq(freq * 2)
.withTrigger(1)
.writeTo(gba.square2);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
const delay = 15;
if (t > delay) {
gba.CtrlFreq.init()
.withSquareFreq(vibrato(delay, 8, freq, t))
.writeTo(gba.square2);
} else if (t == 2) {
gba.CtrlFreq.init()
.withSquareFreq(freq)
.writeTo(gba.square2);
}
}
};
const square2_3 = struct {
pub const id: [*:0]const u8 = "T3";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(15)
.withEnvDir(gba.env_dec)
.withEnvInterval(2)
.withDuty(gba.dut_2_4)
.writeTo(gba.square2);
gba.CtrlFreq.init()
.withSquareFreq(freq)
.withTrigger(1)
.writeTo(gba.square2);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
gba.CtrlFreq.init()
.withFreq(gba.square2.encodeFreq(freq) - @as(u11, @truncate(0x30 * t)))
.writeTo(gba.square2);
}
};
const triangle_table = gba.wav(0x0123456789abcdeffedcba9876543210);
const angled_flat_table = gba.wav(0xfedcba98765432100000000011111111);
const angled_square_table = gba.wav(0xfedcba987654321000000000ffffffff);
const square_table = gba.wav(0xffff0000ffff0000ffff0000ffff0000);
const jaggy_table = gba.wav(0xff880088ff8800880807060506070809);
// Single wave release implementation.
fn wave_simple_r(freq: u32, _: u8, _: u32) callconv(.C) void {
gba.WaveVolLen.init()
.withVolume(gba.vol_0)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(freq)
.withTrigger(1)
.writeTo(gba.wave);
glide_next_freq = freq;
}
var wave_glide_period: u32 = 0;
var wave_vibrato_period: u16 = 0;
/// Common glide+vibrato implementation shared by instruments differing only by their wave table.
fn wave_glide_vibrato_p(freq: u32, _: u8, p0: i8, p1: i8) callconv(.C) void {
glide_base_freq = freq * 128 / semitone_128th[@as(usize, @intCast(p0)) % semitone_128th.len];
gba.WaveVolLen.init()
.withVolume(gba.vol_100)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(glide_base_freq)
.withTrigger(1)
.writeTo(gba.wave);
wave_glide_period = @intCast((@as(usize, @intCast(p0)) % semitone_128th.len) * 8);
wave_vibrato_period = @intCast(p1);
}
fn wave_glide_vibrato_r(freq: u32, _: u8, t: u32) callconv(.C) void {
gba.WaveVolLen.init()
.withVolume(gba.vol_0)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(freq)
.withTrigger(1)
.writeTo(gba.wave);
if (wave_glide_period != 0 and t <= wave_glide_period) {
// Adjust the next glide base if we released within the glide.
glide_next_freq = glide(wave_glide_period, freq, t);
} else {
glide_next_freq = freq;
}
}
fn wave_glide_vibrato_f(freq: u32, _: u8, t: u32) callconv(.C) void {
const vibrato_delay = 49;
if (wave_glide_period != 0 and t <= wave_glide_period) {
gba.CtrlFreq.init()
.withWaveFreq(glide(wave_glide_period, freq, t))
.writeTo(gba.wave);
} else if (t > vibrato_delay and wave_vibrato_period > 0) {
gba.CtrlFreq.init()
.withWaveFreq(vibrato(vibrato_delay, wave_vibrato_period, freq, t))
.writeTo(gba.wave);
}
}
const wave_1 = struct {
pub const id: [*:0]const u8 = "W1";
pub fn press(freq: u32, note: u8, p0: i8, p1: i8) callconv(.C) void {
gba.WaveRam.setTable(&triangle_table);
wave_glide_vibrato_p(freq, note, p0, p1);
}
pub const release = wave_glide_vibrato_r;
pub const frame = wave_glide_vibrato_f;
pub const param_0 = ct.Parameter{ .name = "Glide (semitones)", .min = 0, .max = 12, .default = 1 };
pub const param_1 = ct.Parameter{ .name = "VP Vibrato Period", .min = 0, .default = 8 };
};
const wave_2 = struct {
pub const id: [*:0]const u8 = "W2";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.WaveRam.setTable(&angled_flat_table);
gba.WaveVolLen.init()
.withVolume(gba.vol_100)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(freq * 2)
.withTrigger(1)
.writeTo(gba.wave);
}
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
if (t == 1)
gba.CtrlFreq.init()
.withWaveFreq(freq)
.withTrigger(1)
.writeTo(gba.wave);
}
};
const wave_3 = struct {
pub const id: [*:0]const u8 = "W3";
pub fn press(freq: u32, note: u8, p0: i8, p1: i8) callconv(.C) void {
gba.WaveRam.setTable(&angled_flat_table);
wave_glide_vibrato_p(freq, note, p0, p1);
}
pub const release = wave_glide_vibrato_r;
pub const frame = wave_glide_vibrato_f;
pub const param_0 = ct.Parameter{ .name = "Glide (semitones)", .min = 0, .max = 12, .default = 1 };
pub const param_1 = ct.Parameter{ .name = "VP Vibrato Period", .min = 0, .default = 8 };
};
const wave_4 = struct {
pub const id: [*:0]const u8 = "W4";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
// Only bounce and glide if we got a next base freq and if it's higher than freq
glide_base_freq = if (glide_next_freq != 0 and glide_next_freq > freq) glide_next_freq else freq;
gba.WaveRam.setTable(&angled_flat_table);
gba.WaveVolLen.init()
.withVolume(gba.vol_100)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(glide_base_freq)
.withTrigger(1)
.writeTo(gba.wave);
}
pub const release = wave_simple_r;
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
const period_up = 3;
const period_down = 9;
if (t <= period_up + period_down) {
if (glide_base_freq != 0) {
const up_freq = glide_base_freq + (glide_base_freq - freq);
if (t <= period_up) {
// Bounce up from freq (not implemented)
const f = (up_freq - glide_base_freq) * t / period_up + glide_base_freq;
gba.CtrlFreq.init()
.withWaveFreq(f)
.writeTo(gba.wave);
} else {
// Interpolate to back into freq
const f = up_freq - (up_freq - freq) * (t - period_up) / period_down;
gba.CtrlFreq.init()
.withWaveFreq(f)
.writeTo(gba.wave);
}
}
}
}
};
const wave_5 = struct {
pub const id: [*:0]const u8 = "W5";
pub fn press(freq: u32, note: u8, p0: i8, p1: i8) callconv(.C) void {
gba.WaveRam.setTable(&angled_square_table);
wave_glide_vibrato_p(freq, note, p0, p1);
}
pub const release = wave_glide_vibrato_r;
pub const frame = wave_glide_vibrato_f;
pub const param_0 = ct.Parameter{ .name = "Glide (semitones)", .min = 0, .max = 12, .default = 1 };
pub const param_1 = ct.Parameter{ .name = "VP Vibrato Period", .min = 0, .default = 8 };
};
const wave_6 = struct {
pub const id: [*:0]const u8 = "W6";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.WaveRam.setTable(&jaggy_table);
gba.WaveVolLen.init()
.withVolume(gba.vol_50)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(freq)
.withTrigger(1)
.writeTo(gba.wave);
}
pub const release = wave_simple_r;
};
const wave_7 = struct {
pub const id: [*:0]const u8 = "W7";
pub fn press(freq: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.WaveRam.setTable(&square_table);
gba.WaveVolLen.init()
.withVolume(gba.vol_25)
.writeTo(gba.wave);
gba.CtrlFreq.init()
.withWaveFreq(freq)
.withTrigger(1)
.writeTo(gba.wave);
}
pub const release = wave_simple_r;
pub fn frame(freq: u32, _: u8, t: u32) callconv(.C) void {
const delay = 49;
if (t > delay)
gba.CtrlFreq.init()
.withWaveFreq(vibrato(delay, 8, freq, t))
.writeTo(gba.wave);
}
};
const noise_1 = struct {
pub const id: [*:0]const u8 = "N1";
pub fn press(_: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(7)
.withEnvDir(gba.env_dec)
.withEnvInterval(1)
.writeTo(gba.noise);
gba.NoiseCtrlFreq.init()
.withTrigger(1)
.writeTo(gba.noise);
}
pub fn frame(_: u32, _: u8, t: u32) callconv(.C) void {
switch (t) {
0 => (gba.NoiseCtrlFreq{ .freq = 1 }).writeTo(gba.noise),
1 => (gba.NoiseCtrlFreq{ .freq = 2 }).writeTo(gba.noise),
2 => (gba.NoiseCtrlFreq{ .freq = 1 }).writeTo(gba.noise),
3 => (gba.NoiseCtrlFreq{ .freq = 2 }).writeTo(gba.noise),
4 => (gba.NoiseCtrlFreq{ .freq = 1 }).writeTo(gba.noise),
// 5
6 => (gba.NoiseCtrlFreq{ .freq = 2 }).writeTo(gba.noise),
7 => (gba.NoiseCtrlFreq{ .freq = 1 }).writeTo(gba.noise),
8 => (gba.NoiseCtrlFreq{ .freq = 2 }).writeTo(gba.noise),
else => {},
}
}
};
const noise_2 = struct {
pub const id: [*:0]const u8 = "N2";
pub fn press(_: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(10)
.withEnvDir(gba.env_dec)
.withEnvInterval(1)
.writeTo(gba.noise);
gba.NoiseCtrlFreq.init()
.withTrigger(1)
.writeTo(gba.noise);
}
pub fn frame(_: u32, _: u8, t: u32) callconv(.C) void {
switch (t) {
0 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_7, .freq_div = gba.div_16 }).writeTo(gba.noise),
1 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_7, .freq_div = gba.div_48 }).writeTo(gba.noise),
// 2
3 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_7, .freq_div = gba.div_80 }).writeTo(gba.noise),
4 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_7, .freq_div = gba.div_112 }).writeTo(gba.noise),
5 => (gba.NoiseCtrlFreq{ .freq = 6, .width = gba.wid_15, .freq_div = gba.div_8 }).writeTo(gba.noise),
else => {},
}
}
};
const noise_3 = struct {
pub const id: [*:0]const u8 = "N3";
pub fn press(_: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(10)
.withEnvDir(gba.env_dec)
.withEnvInterval(2)
.writeTo(gba.noise);
gba.NoiseCtrlFreq.init()
.withTrigger(1)
.writeTo(gba.noise);
}
pub fn frame(_: u32, _: u8, t: u32) callconv(.C) void {
switch (t) {
0 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_7, .freq_div = gba.div_16 }).writeTo(gba.noise),
1 => (gba.NoiseCtrlFreq{ .freq = 7, .width = gba.wid_7, .freq_div = gba.div_16 }).writeTo(gba.noise),
2 => (gba.NoiseCtrlFreq{ .freq = 6, .width = gba.wid_7, .freq_div = gba.div_16 }).writeTo(gba.noise),
3 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_15, .freq_div = gba.div_8 }).writeTo(gba.noise),
// 4
5 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_15, .freq_div = gba.div_16 }).writeTo(gba.noise),
6 => (gba.NoiseCtrlFreq{ .freq = 4, .width = gba.wid_15, .freq_div = gba.div_16 }).writeTo(gba.noise),
7 => (gba.NoiseCtrlFreq{ .freq = 5, .width = gba.wid_15, .freq_div = gba.div_16 }).writeTo(gba.noise),
else => {},
}
}
};
const noise_4 = struct {
pub const id: [*:0]const u8 = "N4";
pub fn press(_: u32, _: u8, _: i8, _: i8) callconv(.C) void {
gba.EnvDutyLen.init()
.withEnvStart(7)
.withEnvDir(gba.env_dec)
.withEnvInterval(2)
.writeTo(gba.noise);
gba.NoiseCtrlFreq.init()
.withTrigger(1)
.writeTo(gba.noise);
}
pub fn frame(_: u32, _: u8, t: u32) callconv(.C) void {
switch (t) {
0 => (gba.NoiseCtrlFreq{ .freq = 1, .freq_div = gba.div_16 }).writeTo(gba.noise),
1 => (gba.NoiseCtrlFreq{ .freq = 1, .freq_div = gba.div_32 }).writeTo(gba.noise),
2 => (gba.NoiseCtrlFreq{ .freq = 1, .freq_div = gba.div_48 }).writeTo(gba.noise),
3 => (gba.NoiseCtrlFreq{ .freq = 1, .freq_div = gba.div_64 }).writeTo(gba.noise),
4 => (gba.NoiseCtrlFreq{ .freq = 1, .freq_div = gba.div_80 }).writeTo(gba.noise),
else => {},
}
}
};
pub fn main() void {
ct.registerInstrument(square1_1, 0);
ct.registerInstrument(square1_2, 0);
ct.registerInstrument(square2_1, 0);
ct.registerInstrument(square2_2, 0);
ct.registerInstrument(square2_3, 1);
ct.registerInstrument(wave_1, 1);
ct.registerInstrument(wave_2, 1);
ct.registerInstrument(wave_3, 1);
ct.registerInstrument(wave_4, 2);
ct.registerInstrument(wave_5, 2);
ct.registerInstrument(wave_6, 2);
ct.registerInstrument(wave_7, 2);
ct.registerInstrument(noise_1, 3);
ct.registerInstrument(noise_2, 3);
ct.registerInstrument(noise_3, 3);
ct.registerInstrument(noise_4, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment