nesmus
NES Music Programming Language
by Bob Rost

Version: March 20, 2004

Contents:

 

Description

The nesmus language allows a musician to compose or transcribe music for the NES in a programming language that resembles sheet music in form. It accomodates the 4 NES sound channels, over a 6 octave range. It also allows definition of tempo in beats per minute, and note lengths in terms of the current tempo. Additionally, it has support for musical loops.

Your game is expected to run at 30 frames per second and update the music loop once per frame. The nesmus language internally uses fractional time values and will play your notes on the closest frame to their actual time, so that your music, when played back, is timed as accurately as possible.

NES Music Channels:
    0: square wave 1
    1: square wave 2
    2: triangle wave
    3: noise channel

The nesmus application is command-line only. Learn how to use the command line on your operating system. Windows users will have to download cygwin1.dll in order to use nesmus. The dll can be downloaded from Bob Rost's NES development webpage.

 

Using nesmus Data in Your Game (for programmers):

Include the file nesmus.bas in your nbasic game. This top of this file contains comments that describe important usage notes. Look at the source of the example provided with nesmus. You can change the build script to use main2.bas for a demo of detecting the ends of songs and swapping between two of them.

 

Testing Your Music Data (for musicians):

You must have nesmus and nesasm on your system, as well as the music.asm file included with nesmus. Look in the example/music folder. You can open the mus files with a standard text editor. Create your own nesmus file, and create a data file called "music.dat". Then rebuild the rom. From a command line in the root example directory, creating the data file and rebuilding the rom should be similar to this for OSX and Linux style systems:

    nesmus music/mysong.mus music/music.dat
    ./build

or, for Windows:

    nesmus music\mysong.mus music\music.dat
    build

 

Music Syntax (for musicians):
  
txxx Tempo change. xxx (1-3 digits) is the beats per minute of a quarter note.

vxx Volume change. xx is the volume level (0-15) Note that on the square wave channels, a volume in the range 16-31 will actually alter the degree of "pong" in the sound, rather than the volume.

ox Absolute octave change. x is the octave number (0-6)

> Relative octave change. Raise the current octave by 1

< Relative octave change. Lower the current octave by 1

lx Current note length change, which affects the following notes until the next note length change. Valid x values are 1,2,4,8, and 16, to specify whole note, half note, quarter note, 1/8 note, and 1/16 note.

px Rest (pause). The value of x (1,2,4,8, or 16) specifies how long to rest, the same as for the note length change.

cdefgab Play the specified note in the current octave, with the current length.

# Placed directly after a note, makes it sharp.

- Placed directly after a note, makes it flat.

. Dot a note. When placed after a note (including after the sharp or flat), it extends the note's length by 50%.

channel x Signal that the following music commands apply to channel x, which must be 0, 1, 2, or 3. It is not necessary to use all 4 channels in a song.

loop x Start a music loop. The value x must be in the range 1 to 255. The loop command must be on a line by itself. You may not nest loops within each other, but you may have parts for all four channels defined inside the loop.

end End the current music loop.

; Starting a line with a semicolon turns that line into a comment. You can write notes for yourself or anyone else reading the music source, and the language will not try to interpret it.

 

nesmus Binary Data Format

The nesmus binary format, which is parsed by the nesmus.bas file, is a string of commands, ranging in length from 1 to 18 bytes. All variables mentioned below are one byte, unless otherwise specified. These are the commands allowed.
 

Start Music Loop
 255command id number
 loopnumber of times the following section will play

End Music Loop
 254command id number

Note Data
 waitnumber of frames until the next command after this
 bitmaskwhich sound channels are updated in this command
  
bit 0channel 0 data follows
bit 1reserved, set to value of bit 0
bit 2channel 1 data follows
bit 3reserved, set to value of bit 2
bit 4channel 2 data follows
bit 5reserved, set to value of bit 4
bit 6channel 3 data follows
bit 7reserved, set to value of bit 6
 Whether the note data command contains any of the following fields is dependent on the value of the bitmask.
 4 bytesRegister data for channel 0, if bitmask has bits 0 and 1 set
 4 bytesRegister data for channel 1, if bitmask has bits 2 and 3 set
 4 bytesRegister data for channel 2, if bitmask has bits 4 and 5 set
 4 bytesRegister data for channel 3, if bitmask has bits 6 and 7 set