Tracker 4.42

## 8.2: Decoding pattern information

Each pattern holds 64 sets of 4 events, one for each Amiga track, numbered 0 to 3 in the usual Amiga way (0-3: left channels, 1-2: right channels, see Amiga audio hardware). Some modules programmed on PC have a special signature `6CHN` or `8CHN`, and accordingly, they feature more channels.

The four bytes per event are to be decoded as follows:

          _____byte 1_____   byte2_    _____byte 3_____   byte4_
         |                | |      |  |                | |      |
         0000          0000-00000000  0000          0000-00000000

         Upper four    12 bits for    Lower four    Effect/parameters
         bits of sam-  note period.   bits of sam-
         ple number.                  ple number.

Sample number should be in the range 0-31... anything else is an error, and should be flagged as such. For standard protracker modules, the note period can be converted to a note n with the following lookup table[1]:

`C-1 to B-1`
  856,808,762,720,678,640,604,570,538,508,480,453
`C-2 to B-2`
  428,404,381,360,339,320,302,285,269,254,240,226
`C-3 to B-3`
  214,202,190,180,170,160,151,143,135,127,120,113

Older tracker modules may use highly non-standard periods. I have yet to encounter some, though. [2] As a result tracker converts these pitch values to notes and stores notes internally. These pitch values are Amiga-dependent. See Amiga audio hardware, for further details.

The effect command has two parts: an effect and parameters. You should actually decode it as three independent nibbles: e (effect) phi (parameter, hi-part), plow (parameter, low-part). The interpretation is very dependent of the actual command involved. In many cases, phi and plow are read as a single byte parameter (para=phi<<4 | plow)

[1] Actually, tracker doesn't use this exact table, but builds a precise well-tempered scale using powers of 2, see ``notes.c`'

[2] It would be easy to add some heuristics to the virtual player to detect these modules, and build the corresponding well-tempered scale on the fly. The hardest decisions would be to adjust the table because of limited precision (values stored as integer arithmetic) and possible distinct scales for each sample.