STF

Introduction

This is the original uncompiled module of Sound Tracker Pro, an AY music editor for ZX Spectrum, author Stanislav Kuzin (KSA). It was developed by improving the capabilities of Sound Tracker, so in many ways it retained backward compatibility with it.

Just like ST1, the STF module file is a dump of the editor's memory from the address 25000, but pre-prepared for saving and compressed. It may contain some patterns and all internal structures, samples and ornaments.

The original files on TR-DOS disks can be identified by the extension 'F' with the download address 25000.

General notes on data compression

One of the disadvantages of the source Sound Tracker is the large size of uncompiled modules. The KSA solution turned out to be quite straightforward: excluding not used in positions' list patterns and packing the data using the RLE method.

The packing algorithm may not be very successful, since after unpacking usually more data is obtained than necessary. However, this does not lead to a failure, and the extra data can simply be ignored.

Structure of compressed data

The RLE type compression method is applied. In order to understand how to unpack a compressed block, it is enough to study it bit by bit using the following pseudocode.

first byte – to the stack
next byte
bit0
1{bit1
1{bit2
1{(bit3-7)-1->[decompression buffer]x2 times
}
0{first byte from the stack to [decompression buffer], end
}
}
0{bit2-4->B,bit5-7->C,move C bytes from [decompression buffer-(B*256+next byte)] to [decompression buffer]
}
}
0{bit1
1{bit2
1{bit3-7->C,move (C+1) bytes to [decompression buffer]
}
0{bit3-7->B,next byte->C,move C bytes from [decompression buffer-(B*256+next byte)] to [decompression buffer]
}
}
0{bit2
1{bit3-7->C,next byte->[decompression buffer]x(C+3) times
}
0{bit3-7->B,next byte->C,next byte->[decompression buffer]x(BC+3) times
}
}
}

Excluded patterns

The patterns' bodies have the same size and follow each other in the editor's memory. It's determining the patterns used in the positions' list before compression, and only they get into the saved file.

All the used patterns turn out to be next to each other after unpacking (for example, if the second pattern is not used, then the first pattern will be immediately followed by the third one in the unpacked data). Therefore, the reverse operation is performed in the native editor's memory: the unpacked patterns are moved in their places.

Structure of unpacked data

OffsetDescription
0x0000Samples 1-15 (15 items), 0x82 bytes each:
+0x0032 bytes amplitudes.
+0x2032 bytes noises and masks (bits0-4 – noise period, bit7 – noise, бит6 – tone, bit5 – env).
+0x4032 words tones (bit0-11 – ton deviation, bit12 – deviation sign, 1 – shown as minus, but acts as plus).
+0x80Loop begin (numeration not from 0, but from 1), if 0 then not looped and all 32 ticks are played.
+0x81Loop body length (decreased by 1).
0x079E256 positions (byte pairs "pattern_number[1..31]:transposition[-128..127])", patterns removed before compression if they absent in this list, next patterns moved to their place, and vice versa, all moved back after unpacking.
0x099EThe number of active positions has been reduced by 1.
0x099FEmpty zero ornament? (32 zeros).
0x09B1Ornaments 1-15 (15 items), 32 bytes each:
+0Loop.
+1Length-1.
+230 deviations in semitones.
0x0B9FEmpty zero ornament? (32 zeros).
0x0BBFPlayback speed.
0x0BC0Patterns lengths (total 31 patterns).
0x0BDFLoop position.
0x0BE0Title (25 chars).
0x0BF9Patterns (3 bytes per channel's line, 3*3*64=576 bytes per pattern), unused patterns are removed before compressing (see upper).
Pattern channel's line format:
+00xF0 – R--, otherwise bits4-7 – note (0 – no note, 1 – A, 2 – B, 3 – C), bits0-2 – octave starting from 0, bit3 – sharp.
+1bits4-7 – sample, bits0-3: 1/2 – tone frequency down/up, 3-7 – turn on ornament 0 (though officially do nothing), 8-Е envelope (if with note then volume is set to F), F – ornament, at the same time 3-F turn off tone slide.
+2bits4-7 – volume, bits0-3 – ornament (if F prefix) or all bits – either envelope period (0..FF), or addition to tone for slide (0..7F as in manual, but can be 80..FF in fact, just is changing slide direction).

Sound Tracker Pro 48K

This is the 48K mode adaptation of Sound Tracker Pro, made in 1998 by Oleg Ivanov (Saruman).

Saves uncompiled modules with extension 'f' and load address 25000. I haven't looked inside yet, but due the program docs, they should have the structure of an unpacked STF module.