old school music tracker audio backend
1taken from: https://github.com/schismtracker/schismtracker/wiki/ITTECH.TXT
2
3Header Layout:
4 0 1 2 3 4 5 6 7 8 9 A B C D E F
5 ┌───┬───┬───┬───┬───────────────────────────────────────────────┐
60000: │'I'│'M'│'P'│'M'│ Song Name, max 26 characters, includes NULL │
7 ├───┴───┴───┴───┴───────────────────────────────────────┬───────┤
80010: │.......................................................│PHiligt│
9 ├───────┬───────┬───────┬───────┬───────┬───────┬───────┼───────┤
100020: │OrdNum │InsNum │SmpNum │PatNum │ Cwt/v │ Cmwt │ Flags │Special│
11 ├───┬───┼───┬───┼───┬───┼───────┼───────┴───────┼───────┴───────┤
120030: │GV │MV │IS │IT │Sep│PWD│MsgLgth│Message Offset │ Reserved │
13 ├───┴───┴───┴───┴───┴───┴───────┴───────────────┴───────────────┤
140040: │ Chnl Pan (64 bytes)...........................................│
15 ├───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┤
16
17 ├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┤
180080: │ Chnl Vol (64 bytes)...........................................│
19 ├───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┤
20
21 ├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┤
2200C0: │ Orders, Length = OrdNum │
23 ├───────────────────────────────────────────────────────────────┤
24xxxx: │ 'Long' Offset of instruments, Length = InsNum*4 (1) │
25 ├───────────────────────────────────────────────────────────────┤
26xxxx: │ 'Long' Offset of samples headers, Length = SmpNum*4 (2) │
27 ├───────────────────────────────────────────────────────────────┤
28xxxx: │ 'Long' Offset of patterns, Length = PatNum*4 (3) │
29 └───────────────────────────────────────────────────────────────┘
30
31 (1) Offset = 00C0h+OrdNum
32 (2) Offset = 00C0h+OrdNum+InsNum*4
33 (3) Offset = 00C0h+OrdNum+InsNum*4+SmpNum*4
34
35 Note that if the (long) offset to a pattern = 0, then the
36 pattern is assumed to be a 64 row empty pattern.
37
38 PHiliht = Pattern row hilight information. Only relevant for pattern
39 editing situations.
40
41 Cwt: Created with tracker.
42 Impulse Tracker y.xx = 0yxxh
43 Cmwt: Compatible with tracker with version greater than value.
44 (ie. format version)
45 OrdNum: Number of orders in song.
46 InsNum: Number of instruments in song
47 SmpNum: Number of samples in song
48 PatNum: Number of patterns in song
49 Flags: Bit 0: On = Stereo, Off = Mono
50 Bit 1: Vol0MixOptimizations - If on, no mixing occurs if
51 the volume at mixing time is 0 (redundant v1.04+)
52 Bit 2: On = Use instruments, Off = Use samples.
53 Bit 3: On = Linear slides, Off = Amiga slides.
54 Bit 4: On = Old Effects, Off = IT Effects
55 Differences:
56 - Vibrato is updated EVERY frame in IT mode, whereas
57 it is updated every non-row frame in other formats.
58 Also, it is two times deeper with Old Effects ON
59 - Command Oxx will set the sample offset to the END
60 of a sample instead of ignoring the command under
61 old effects mode.
62 - (More to come, probably)
63 Bit 5: On = Link Effect G's memory with Effect E/F. Also
64 Gxx with an instrument present will cause the
65 envelopes to be retriggered. If you change a
66 sample on a row with Gxx, it'll adjust the
67 frequency of the current note according to:
68
69 NewFrequency = OldFrequency * NewC5 / OldC5;
70 Bit 6: Use MIDI pitch controller, Pitch depth given by PWD
71 Bit 7: Request embedded MIDI configuration
72 (Coded this way to permit cross-version saving)
73
74 Special: Bit 0: On = song message attached.
75 Song message:
76 Stored at offset given by "Message Offset" field.
77 Length = MsgLgth.
78 NewLine = 0Dh (13 dec)
79 EndOfMsg = 0
80
81 Note: v1.04+ of IT may have song messages of up to
82 8000 bytes included.
83 Bit 1: Reserved
84 Bit 2: Reserved
85 Bit 3: MIDI configuration embedded
86 Bit 4-15: Reserved
87
88 GV: Global volume. (0->128) All volumes are adjusted by this
89 MV: Mix volume (0->128) During mixing, this value controls
90 the magnitude of the wave being mixed.
91 IS: Initial Speed of song.
92 IT: Initial Tempo of song
93 Sep: Panning separation between channels (0->128, 128 is max sep.)
94 PWD: Pitch wheel depth for MIDI controllers
95 Chnl Vol: Volume for each channel. Ranges from 0->64
96 Chnl Pan: Each byte contains a panning value for a channel. Ranges from
97 0 (absolute left) to 64 (absolute right). 32 = central pan,
98 100 = Surround sound.
99 +128 = disabled channel (notes will not be played, but note
100 that effects in muted channels are
101 still processed)
102 Orders: This is the order in which the patterns are played.
103 Valid values are from 0->199.
104 255 = "---", End of song marker
105 254 = "+++", Skip to next order
106
107Instrument Format:
108 0 1 2 3 4 5 6 7 8 9 A B C D E F
109 ┌───┬───┬───┬───┬───────────────────────────────────────────────┐
1100000: │'I'│'M'│'P'│'I'│ DOS FileName (12345678.123) │
111 ├───┼───┼───┼───┼───────┬───┬───┬───┬───┬───┬───┬───────┬───┬───┤
1120010: │00h│NNA│DCT│DCA│FadeOut│PPS│PPC│GbV│DfP│RV │RP │TrkVers│NoS│ x │
113 ├───┴───┴───┴───┴───────┴───┴───┴───┴───┴───┴───┴───────┴───┴───┤
1140020: │ Instrument Name, max 26 bytes, includes NUL...................│
115 ├───────────────────────────────────────┬───┬───┬───┬───┬───────┤
1160030: │.......................................│IFC│IFR│MCh│MPr│MIDIBnk│
117 ├───────────────────────────────────────┴───┴───┴───┴───┴───────┤
1180040: │ Note-Sample/Keyboard Table, Length = 240 bytes................│
119 ├───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┤
120
121 ├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┤
1220130: │ Envelopes.....................................................│
123 ├───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┤
124
125 IFC = Initial Filter cutoff
126 IFR = Initial Filter resonance
127
128 NNA = New Note Action
129 0 = Cut 1 = Continue
130 2 = Note off 3 = Note fade
131
132 DCT = Duplicate Check Type
133 0 = Off 1 = Note
134 2 = Sample 3 = Instrument
135
136 DCA: Duplicate Check Action
137 0 = Cut
138 1 = Note Off
139 2 = Note fade
140
141 FadeOut: Ranges between 0 and 128, but the fadeout "Count" is 1024
142 See the Last section on how this works.
143 Fade applied when:
144 1) Note fade NNA is selected and triggered (by another note)
145 2) Note off NNA is selected with no volume envelope
146 or volume envelope loop
147 3) Volume envelope end is reached
148
149 PPS: Pitch-Pan separation, range -32 -> +32
150 PPC: Pitch-Pan center: C-0 to B-9 represented as 0->119 inclusive
151
152 GbV: Global Volume, 0->128
153 DfP: Default Pan, 0->64, &128 => Don't use
154 RV: Random volume variation (percentage)
155 RP: Random panning variation (panning change - not implemented yet)
156
157 MCh = MIDI Channel
158 MPr = MIDI Program (Instrument)
159
160 TrkVers: Tracker version used to save the instrument. This is only
161 used in the instrument files.
162 NoS: Number of samples associated with instrument. This is only
163 used in the instrument files.
164
165 Note-Sample/Keyboard Table.
166 Each note of the instrument is first converted to a sample number
167 and a note (C-0 -> B-9). These are stored as note/sample byte pairs
168 (note first, range 0->119 for C-0 to B-9, sample ranges from
169 1-99, 0=no sample)
170
171Envelope Layout:
172 Envelopes: 3 structures, first for volume (130h), second for
173 panning (182h), third for pitch (1D4h).
174
175 Each is structured as such:
176
177 0 1 2 3 4 5 6.......
178 ┌───┬───┬───┬───┬───┬───┬───────────────────────────────────┬───┐
179xxxx: │Flg│Num│LpB│LpE│SLB│SLE│ Node points, 25 sets, 75 bytes....│ x │
180 ├───┼───┼───┼───┼───┼───┼───┬───┬───┬───┬───┬───┬───┬───┬───┼───┤
181
182 Flg: Bit 0: Envelope on/off, 1 = on, 0 = off
183 Bit 1: Loop on/off, 1 = on, 0 = off
184 Bit 2: SusLoop on/off, 1 = on, 0 = off
185
186 For Pitch envelope only:
187 Bit 7: Use pitch envelope as filter envelope instead.
188
189 Num = Number of node points
190
191 LpB = Loop beginning SLB = Sustain loop beginning
192 LpE = Loop end SLE = Sustain loop end
193
194 Node point = 1 byte for y-value
195 (0->64 for vol, -32->+32 for panning or pitch)
196 1 word (2 bytes) for tick number (0->9999)
197
198 Total length of an instrument is 547 bytes, but 554 bytes are
199 written, just to simplify the loading of the old format. (Hence
200 there are 7 'wasted' bytes per instrument)
201
202Sample Header Layout:
203 0 1 2 3 4 5 6 7 8 9 A B C D E F
204 ┌───┬───┬───┬───┬───────────────────────────────────────────────┐
2050000: │'I'│'M'│'P'│'S'│ DOS Filename (12345678.123) │
206 ├───┼───┼───┼───┼───────────────────────────────────────────────┤
2070010: │00h│GvL│Flg│Vol│ Sample Name, max 26 bytes, includes NUL.......│
208 ├───┴───┴───┴───┴───────────────────────────────────────┬───┬───┤
2090020: │.......................................................│Cvt│DfP│
210 ├───────────────┬───────────────┬───────────────┬───────┴───┴───┤
2110030: │ Length │ Loop Begin │ Loop End │ C5Speed │
212 ├───────────────┼───────────────┼───────────────┼───┬───┬───┬───┤
2130040: │ SusLoop Begin │ SusLoop End │ SamplePointer │ViS│ViD│ViR│ViT│
214 └───────────────┴───────────────┴───────────────┴───┴───┴───┴───┘
215
216The cache file has the following pieces of information added on:
217
218 0 1 2 3 4 5 6 7 8 9 A B C D E F
219 ┌───────────────┬───────┬───────┬───┬───────────────────────────┐
2200050: │ File Size │ Date │ Time │Fmt│...........................│
221 └───────────────┴───────┴───────┴───┴───────────────────────────┘
222
223 Fmt. 0 = unchecked. 1 = directory, 2 = it sample, 3 = st sample
224
225 GvL: Global volume for instrument, ranges from 0->64
226 Flg: Bit 0. On = sample associated with header.
227 Bit 1. On = 16 bit, Off = 8 bit.
228 Bit 2. On = stereo, Off = mono. Stereo samples not supported yet
229 Bit 3. On = compressed samples.
230 Bit 4. On = Use loop
231 Bit 5. On = Use sustain loop
232 Bit 6. On = Ping Pong loop, Off = Forwards loop
233 Bit 7. On = Ping Pong Sustain loop, Off = Forwards Sustain loop
234 Vol: Default volume for instrument
235
236 Length: Length of sample in no. of samples NOT no. of bytes
237 LoopBeg: Start of loop (no of samples in, not bytes)
238 Loop End: Sample no. AFTER end of loop
239 C5Speed: Number of bytes a second for C-5 (ranges from 0->9999999)
240 SusLBeg: Start of sustain loop
241 SusLEnd: Sample no. AFTER end of sustain loop
242
243 SmpPoint: 'Long' Offset of sample in file.
244
245 ViS: Vibrato Speed, ranges from 0->64
246 ViD: Vibrato Depth, ranges from 0->64
247 ViT: Vibrato waveform type.
248 0=Sine wave
249 1=Ramp down
250 2=Square wave
251 3=Random (speed is irrelevant)
252 ViR: Vibrato Rate, rate at which vibrato is applied (0->64)
253
254 The depth of the vibrato at any point is worked out in the following
255 way:
256 Every processing cycle, the following occurs:
257 1) Mov AX, [SomeVariableNameRelatingToVibrato]
258 2) Add AL, Rate
259 3) AdC AH, 0
260 4) AH contains the depth of the vibrato as a fine-linear slide.
261 5) Mov [SomeVariableNameRelatingToVibrato], AX ; For the next
262 ; cycle.
263
264 For those that don't understand assembly, then the depth is
265 basically the running-sum of the rate divided by 256.
266
267 Sample vibrato uses a table 256-bytes long
268
269 Convert - bits other than bit 0 are used internally for the loading
270 of alternative formats.
271 Bit 0:
272 Off: Samples are unsigned } IT 2.01 and below use unsigned samples
273 On: Samples are signed } IT 2.02 and above use signed samples
274 Bit 1:
275 Off: Intel lo-hi byte order for 16-bit samples } Safe to ignore
276 On: Motorola hi-lo byte order for 16-bit samples } these values...
277 Bit 2: }
278 Off: Samples are stored as PCM values }
279 On: Samples are stored as Delta values }
280 Bit 3: }
281 On: Samples are stored as byte delta values }
282 (for PTM loader) }
283 Bit 4: }
284 On: Samples are stored as TX-Wave 12-bit values }
285 Bit 5: }
286 On: Left/Right/All Stereo prompt }
287 Bit 6: Reserved
288 Bit 7: Reserved
289
290 DfP - Default Pan. Bits 0->6 = Pan value, Bit 7 ON to USE (opposite of inst)
291
292
293Pattern Layout:
294 0 1 2 3 4 5 6 7 8 9 A B C D E F
295 ┌───────┬───────┬───┬───┬───┬───┬───────────────────────────────┐
2960000: │Length │ Rows │ x │ x │ x │ x │ Packed data................ │
297 ├───┬───┼───┬───┼───┼───┼───┼───┼───┬───┬───┬───┬───┬───┬───┬───┤
298
299 Length: Length of packed pattern, not including the 8 byte header
300 Note that the pattern + the 8 byte header will ALWAYS
301 be less than 64k
302 Rows: Number of rows in this pattern (Ranges from 32->200)
303
304 Patterns are unpacked by the following pseudocode... (this may look
305 horrible, but in practise, it's just as convenient as the S3M
306 pattern format for playback (but not for display))
307
308 GetNextChannelMarker:
309 Read byte into channelvariable.
310 if(channelvariable = 0) then end of row
311 Channel = (channelvariable-1) & 63 ; Channel is 0 based.
312 if(channelvariable & 128) then read byte into maskvariable
313 else maskvariable = previousmaskvariable for current channel
314
315 if(maskvariable & 1), then read note. (byte value)
316 // Note ranges from 0->119 (C-0 -> B-9)
317 // 255 = note off, 254 = notecut
318 // Others = note fade (already programmed into IT's player
319 // but not available in the editor)
320
321 if(maskvariable & 2), then read instrument (byte value)
322 // Instrument ranges from 1->99
323
324 if(maskvariable & 4), then read volume/panning (byte value)
325 // Volume ranges from 0->64
326 // Panning ranges from 0->64, mapped onto 128->192
327 // Prepare for the following also:
328 // 65->74 = Fine volume up
329 // 75->84 = Fine volume down
330 // 85->94 = Volume slide up
331 // 95->104 = Volume slide down
332 // 105->114 = Pitch Slide down
333 // 115->124 = Pitch Slide up
334 // 193->202 = Portamento to
335 // 203->212 = Vibrato
336
337 Effects 65 is equivalent to D0F, 66 is equivalent to D1F -> 74 = D9F
338 Similarly for 75-84 (DFx), 85-94 (Dx0), 95->104 (D0x).
339
340 (Fine) Volume up/down all share the same memory (NOT shared with Dxx
341 in the effect column tho).
342
343 Pitch slide up/down affect E/F/(G)'s memory - a Pitch slide
344 up/down of x is equivalent to a normal slide by x*4
345
346 Portamento to (Gx) affects the memory for Gxx and has the equivalent
347 slide given by this table:
348
349 SlideTable DB 1, 4, 8, 16, 32, 64, 96, 128, 255
350
351 Vibrato uses the same 'memory' as Hxx/Uxx.
352
353 if(maskvariable & 8), then read command (byte value) and commandvalue
354 // Valid ranges from 0->31 (0=no effect, 1=A, 2=B, 3=C, etc.)
355
356 if(maskvariable & 16), then note = lastnote for channel
357 if(maskvariable & 32), then instrument = lastinstrument for channel
358 if(maskvariable & 64), then volume/pan = lastvolume/pan for channel
359 if(maskvariable & 128), then {
360 command = lastcommand for channel and
361 commandvalue = lastcommandvalue for channel
362 }
363 Goto GetNextChannelMarker
364