Below lists the format of the Protracker Studio 16 (PS16) header. This can change if it doesn't allow for enough flexibility for the time being. ХННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННё і PS16 Header Format: і ФННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННѕ Description Length Data Type Information ДДДДДДДДДДДДДДДДДД ДДДДДД ДДДДДДДДД ДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДД Sig 5 Character This contains the string "PS16ю" which acts as both an identifier to determine the file, but also serves as part of the text string which can be done by TYPEing the file to the screen. SongName 75 Character This contains the 75-character name of the music file. This may contain the MODule name if converted from a MOD, or it may contain information on number of channels or whatever. The final byte, 75, MUST have a ^Z in it. TypeOfFile 1 Byte This field holds what type of music file the file is. If this field contains a 0, then it is a module with self-contained instruments. If it is a 1, then it is a song with the header and patterns, but not the samples. CommentOfs 4 Longint The Comment Offset field points to the offset of the file where comments begin. The comments contain all text and information pertinent to the music. The sample names are also stored here. See below for parsing information. This field DOESN'T need to be used. Just store a zero here if there are no comments. Version 1 Byte This is the version identifier for the PS16 file. All versions of PS16 formats will have the header structure as described thus far. The format from here on can change, although it isn't likely. The format described below is a Version 0 format. ДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДД Version 0 Header NumPatterns 1 Byte Contains the number of patterns (max 256) in the file. totalPatternSize 4 Longint For quick reads off the disk, the TOTAL pattern length is stored here. The maximum total size of patterns for any given music file is 3075 bytes per pattern * 256 patterns. With the current player, this is simply not possible. SongLen 1 Byte This contains the number of sequences in the PS16 file. Sequences 128 Byte These are the sequences for the entire PS16 music. Samples 31*PS16Sample These are the 31 individual sample structures, described below. ХННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННё і PS16 Sample Header Format, Version 0: і ФННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННѕ Description Length Data Type Information ДДДДДДДДДДДДДДДДДД ДДДДДД ДДДДДДДДД ДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДД BitStruc 1 Bit Field These are bits that may be set for each sample. The default for a MOD file is: Bit 0 - Digital, Bit 1 - 0, Bit 2 - 8-bit. 7 6 5 4 3 2 1 0 і і АД 0 - Digital, 1 - Synthesized і АДДД (if bit 0=1) 0 - FM, 1 - Waveform АДДДДД 0 - 8-bit, 1 - 16-bit. Volume 1 Byte Default volume for the sample. Range is 0 to 64 decimal. Please, ALWAYS make it default to this range. FineTune 1 Byte This field must contain one of the following values: 0 - Tuning 0 1 - Tuning 1 2 - Tuning 2 3 - Tuning 3 4 - Tuning 4 5 - Tuning 5 6 - Tuning 6 7 - Tuning 7 8 - Tuning -8 9 - Tuning -7 10 - Tuning -6 11 - Tuning -5 12 - Tuning -4 13 - Tuning -3 14 - Tuning -2 15 - Tuning -1 Length 4 Longint This contains the length of the sample. Currently, my player doesn't support greater than 64k samples, and I really don't see the need. It's here in case it's needed. Repeat 4 Longint This contains the repeat start for the sample. Again, this can be >64k RepeatLength 4 Longint This contains the repeat length for the sample. If the sample Length is greater than the sample Repeat plus the sample RepLen, then the sample can be clipped to Repeat+ RepLen. If you didn't get that, don't worry about it. C-2 Freq 2 Word The default playback frequency of a sample's C on octave 2. This can be used to fine tune a sample, but it defaults to 8448. ХННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННё і PS16 Pattern Format, Version 0: і ФННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННѕ Immediately following the version 0 header structure are the patterns. The reason that the offset of the patterns in the file is not contained in the header is because it was felt that the patterns would probably not be relocated. When converting from the MODule format, this format will always be a minimum of 253 bytes smaller than the patterns in a MODule. A MODule's pattern is always 1,024 bytes. This is obvious since a MODule note and effect occupies four bytes, and there are four channels per row. With 64 rows in a file, this equation becomes: 4 bytes * 4 channels * 64 rows = 1,024 bytes. A PS16 note occupies three bytes. A "note" in PS16 consists of the actual note, an instrument, and a special effect and its data. A PS16 note will use the following table to convert from Amiga periods to its own notes, and they will be stored as such: ЪДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДВДДДДДї і 1і 2і 3і 4і 5і 6і 7і 8і 9і 10і 11і 12і і 1712і 1616і 1524і 1440і 1356і 1280і 1208і 1140і 1076і 1016і 960і 906і і C-0і C#0і D-0і D#0і E-0і F-0і F#0і G-0і G#0і A-0і A#0і B-0і ГДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДґ і 13і 14і 15і 16і 17і 18і 19і 20і 21і 22і 23і 24і і 856і 808і 762і 720і 678і 640і 604і 570і 538і 508і 480і 453і і C-1і C#1і D-1і D#1і E-1і F-1і F#1і G-1і G#1і A-1і A#1і B-1і ГДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДґ і 25і 26і 27і 28і 29і 30і 31і 32і 33і 34і 35і 36і і 428і 404і 381і 360і 339і 320і 302і 285і 269і 254і 240і 226і і C-2і C#2і D-2і D#2і E-2і F-2і F#2і G-2і G#2і A-2і A#2і B-2і ГДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДґ і 37і 38і 39і 40і 41і 42і 43і 44і 45і 46і 47і 48і і 214і 202і 190і 180і 170і 160і 151і 143і 135і 127і 120і 113і і C-3і C#3і D-3і D#3і E-3і F-3і F#3і G-3і G#3і A-3і A#3і B-3і ГДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДЕДДДДДґ і 49і 50і 51і 52і 53і 54і 55і 56і 57і 58і 59і 60і і 107і 101і 95і 90і 85і 80і 75і 71і 67і 63і 60і 56і і C-4і C#4і D-4і D#4і E-4і F-4і F#4і G-4і G#4і A-4і A#4і B-4і АДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДБДДДДДЩ A zero is stored in the event a period was not found or approximated or when there is not an actual period being played. The note field requires 6 bits. Version 0 only handles 31 instruments. Thus, the instrument field requires 5 bits. The special effect field can range from 0 to F in hexadecimal and requires 4 bits. The special effects data field is a whole byte and can have 8 bits. Thus, with this information, we are able to construct the following bitfields: Byte 1 Byte 2 Byte 3 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 і і АДДДДДДДДДЩ АДДВДДЩ АДДДДДЩ АДДДДДДДДДДДДДЩ і і Note і Effect Effect Data і А Bit 5 of instrument АДД Bits 1-4 of the instrument і АДД Follow previous line bit. Reconstruction algorithms are as follows: Get the ЪДДДGet Byte 1 Note АДДДAND it with binary 00111111b ЪДДДGet Byte 1 again. і AND it with binary 01000000b і Shift it right twice. Get the і Store as result #1. Instr. і Get Byte 2. і AND it with binary 11110000b і Shift it right four times. АДДДOR it with Result #1. Get the ЪДДДGet Byte 2 again. Effect. АДДДAND it with binary 00001111b Efx DataДДДДGet Byte 3. Bit 7 requires a bit of additional explanation. As aforementioned, patterns can be a MINIMUM of 253 bytes smaller than their MOD counterparts. This is due to three special compression methods. One) Instead of ordering the patterns as Track 1, Track 2, Track 3, Track 4, then Track 1, Track 2 again and so on until the end, the Tracks are grouped together as all of Track 1 and all of Track 2 and so on. Two) If a note appears on row 0 and another note appears on row 5 with Three) nothing in between, why not get rid of the blank rows? For instance, a situation such as this may appear as: Module Track MOD Data PS16 Data 00 C-1 01 F06 0358 1F06 8D 1F 06 01 --- 00 000 0000 0000 02 --- 00 000 0000 0000 03 --- 00 000 0000 0000 04 --- 00 000 0000 0000 05 E-3 03 C40 00AA 3C40 05 29 3C 40 06 E-3 01 A01 00AA 1A01 A9 1A 01 07 --- 00 000 0000 0000 . . . . . . 63 --- 00 000 0000 0000 FF ДДДДДДДДДДДД ДДДДДДДДДДДДДД 1024 bytes 11 bytes Two and three are combined for two reasons. As can be seen, MODs store extra information for blank pattern lines. This was remedied in PS16 by two methods. If the jump between one line and another was greater than one, then the new line number was written out (see row 5 of the PS16 Data, first byte). However, if the two lines were right by each other (5 & 6), then the pattern row was not written out. Here's why. As you recall from the above diagrams of PS16 notes, it can be seen that Bit 7 is named "Follow Previous Line." This means that if the new PS16 line follows the previous line, there is no need to store a row number in front. All that needs be done is have this bit set. Let's break down the PS16 data from above: Row 0: 8D 1F 06 -- Bit 7 is set here. The first line of a pattern is always assumed to follow Byte 255 (which is what the line counter is initialized). A byte of 255 plus 1 = 0. Otherwise, the 0Dh in 8Dh specifies note 0Dh, which is C-1. The 1F 06 specifies instrument 1, special effect F (speed) 06. Row 5: 05 29 3C 40 -- Since there was a large skip here, and row 5 does not immediately follow row 0, the 5 was stored in first here. How does the interpreter know the difference between a row number and a note? A note ALWAYS follows a row number and if a row number is not present, then bit 7 MUST be set in the note. Bit 7 is NEVER set in a row except for the ONE exception below. Row 6: A9 1A 01 -- Immediately follows Row 5, so bit 7 is set. Final Byte: FF -- This is a -1 which means terminate track. A -1 always terminates the current track. Bear in mind that ALL 16 tracks are stored per pattern, so if converting from a MOD, tracks 5-16 are automatically set to -1. The discussion thus far has been centered around the general pattern format. Two other factors are introduced into the PS16 pattern. The format of a pattern is this: Byte Name Description ДДДДДД ДДДДДДДДДДДДДДД ДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДД 0-1 Size (Word) Size is the total size of the ENTIRE pattern, INCLUDING bytes 0 through 2. This number is paragraph aligned. This means that if a pattern is 253 bytes long, its actual size is 256. If the size is 256, no change takes place. 2 NumLines (Byte) This is the number of pattern lines in the pattern. If a pattern only uses 30 lines and the pattern must terminate to the next pattern at this point, store a 30 here. Otherwise, ALWAYS store a 64 so the entire pattern will play. 3-?? Track This is Track 1, terminated with a -1. The other tracks follow immediately after this. See routine MOD_LoadSavePatterns in MODLOAD.ASM. ХННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННё і PS16 Sample Format, Version 0: і ФННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННѕ Only the digital sample format has been defined thus far. In order to appeal to archivers more, the sample storage format has changed. Instead of being stored as raw data as in all trackers I am aware of, the format was changed to use "deltas." The algorithm for converting a sample to deltas is: Get the number of sample bytes to process. Call this SamplesLeft. Set Delta counter to 0. DO Get a byte from the buffer. Store the byte in Temp. Subtract the Delta counter from the byte. Store it in the buffer. Move the Temp byte into the Delta Counter Decrement SamplesLeft. WHILE(SamplesLeft <> 0) See routine MOD_ConvertSample in MODLOAD.ASM. The technique for conversion back to the raw data is: Get the number of sample bytes to process. Call this SamplesLeft. Set Delta counter to 0. DO Get a byte from the buffer. Add onto the byte the Delta Counter. Store the byte in Delta Counter. Store the byte in Temp. Decrement SamplesLeft. WHILE(SamplesLeft <> 0) ХННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННё і PS16 Comment Format, Version 0: і ФННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННННѕ This format resembles an ILBM format. Only two things are currently defined in this format. Signature Description ДДДДДДДДД ДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДД INST Immediately following this four character identifier is a byte indicating the length of each instrument name. After that is a byte describing how many samples names are stored in this text. Example for the MOD format: I N S T [Chr 22] [Chr 2, normally 31] [Instrument name #1 padded to 22 chars] [Instrument name #2 padded to 22 chars] See MOD_ConvertComments in MODLOAD.ASM. TEXT Immediately following this four character identifier is a WORD describing the length of the upcoming text.