Mercurial > hg > dmlib
annotate minijss/jloadxm.c @ 1132:d4512925b4f9
Modularize some more.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2015 07:00:27 +0200 |
parents | b349646f19a0 |
children | 1ed8af15581a |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Fast Tracker ][ (XM) module loader | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1125 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 * |
6 * TO DO: | |
7 * - Add support for 1.02/1.03 XM-format versions. | |
8 * (Not very useful, but if it's not too hard, then do it) | |
9 */ | |
10 #include "jssmod.h" | |
11 #include <string.h> | |
12 | |
13 | |
14 /* XM value limit definitions | |
15 */ | |
16 #define XM_MaxChannels (32) | |
17 #define XM_MaxPatterns (256) | |
18 #define XM_MaxOrders (255) | |
19 #define XM_MaxInstruments (128) | |
20 #define XM_MaxInstSamples (16) | |
21 #define XM_MaxEnvPoints (12) | |
22 #define XM_MaxNotes (96) | |
23 #define XM_MaxSampleVolume (64) | |
24 | |
25 | |
26 /* XM format structures | |
27 */ | |
28 typedef struct | |
29 { | |
30 char idMagic[17]; // XM header ID "Extended Module: " | |
31 char songName[20]; // Module song name | |
32 Uint8 unUsed1A; // ALWAYS 0x1a | |
33 char trackerName[20]; // ID-string of tracker software | |
34 Uint16 version; // XM-version 0x0104 | |
35 Uint32 headSize; // Module header size, FROM THIS POINT! | |
36 Uint16 norders, // Number of orders | |
37 defRestartPos, // Default song restart position | |
38 nchannels, // Number of channels | |
39 npatterns, // Number of patterns | |
40 ninstruments, // Number of instruments | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
41 flags, // Module flags: |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
42 // bit0: 0 = Amiga frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
43 // 1 = Linear frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
44 // |
0 | 45 defSpeed, // Default speed |
46 defTempo; // Default tempo | |
47 Uint8 orderList[256]; // Order list | |
48 } XMHeader; | |
49 | |
50 | |
51 typedef struct | |
52 { | |
53 Uint32 headSize; // Instrument header size (see docs!) | |
54 char instName[22]; // Name/description | |
55 Uint8 instType; // Type | |
56 Uint16 nsamples; // Number of samples | |
57 } XMInstrument1; | |
58 | |
59 | |
60 typedef struct | |
61 { | |
62 Uint16 frame, value; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
63 } XMEnvPoint; |
0 | 64 |
65 | |
66 typedef struct | |
67 { | |
68 Uint8 flags, npoints, sustain, loopS, loopE; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
69 XMEnvPoint points[XM_MaxEnvPoints]; |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
70 } XMEnvelope; |
0 | 71 |
72 | |
73 typedef struct | |
74 { | |
75 Uint32 headSize; // Header size | |
76 Uint8 sNumForNotes[XM_MaxNotes]; // Sample numbers for notes | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
77 XMEnvelope volumeEnv, panningEnv; |
0 | 78 Uint8 vibratoType, vibratoSweep, vibratoDepth, vibratoRate; |
79 | |
80 Uint16 fadeOut, ARESERVED; | |
81 } XMInstrument2; | |
82 | |
83 | |
84 typedef struct | |
85 { | |
86 Uint32 size, loopS, loopL; | |
87 Uint8 volume; | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
88 Sint8 fineTune; |
0 | 89 Uint8 type, panning; |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
90 Sint8 relNote; |
0 | 91 Uint8 ARESERVED; |
92 char sampleName[22]; | |
93 } XMSample; | |
94 | |
95 | |
96 typedef struct | |
97 { | |
98 Uint32 headSize; | |
99 Uint8 packing; | |
100 Uint16 nrows, size; | |
101 } XMPattern; | |
102 | |
103 | |
104 | |
105 /* Unpack XM-format pattern from file-stream into JSS-pattern structure | |
106 */ | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
107 #define JSGETBYTE(XV) do { \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
108 size--; \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
109 if (size < 0) \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
110 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
111 "Unexpected end of packed pattern data.\n"); \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
112 XV = dmfgetc(inFile); \ |
0 | 113 } while (0) |
114 | |
115 | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
116 static int jssXMConvertNote(int val) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
117 { |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
118 if (val < 1 || val > 97) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
119 return jsetNotSet; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
120 else if (val == 97) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
121 return jsetNoteOff; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
122 else |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
123 return val - 1; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
124 } |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
125 |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
126 |
0 | 127 static int jssXMUnpackPattern(DMResource *inFile, int size, JSSPattern *pattern) |
128 { | |
129 int packb, row, channel, tmp; | |
130 JSSNote *pnote; | |
131 assert(pattern != NULL); | |
132 | |
133 pnote = pattern->data; | |
134 | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
135 for (row = 0; row < pattern->nrows && size > 0; row++) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
136 for (channel = 0; channel < pattern->nchannels && size > 0; channel++) |
0 | 137 { |
138 JSGETBYTE(packb); | |
139 if (packb & 0x80) | |
140 { | |
141 if (packb & 0x01) | |
142 { | |
143 // PACK 0x01: Read note | |
144 JSGETBYTE(tmp); | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
145 pnote->note = jssXMConvertNote(tmp); |
0 | 146 } |
147 | |
148 if (packb & 0x02) | |
149 { | |
150 // PACK 0x02: Read instrument | |
151 JSGETBYTE(tmp); | |
152 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
153 } | |
154 | |
155 if (packb & 0x04) | |
156 { | |
157 // PACK 0x04: Read volume | |
158 JSGETBYTE(tmp); | |
159 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
160 } | |
161 | |
162 if (packb & 0x08) | |
163 { | |
164 // PACK 0x08: Read effect | |
165 JSGETBYTE(pnote->effect); | |
166 pnote->param = 0; | |
167 } | |
168 | |
169 if (packb & 0x10) | |
170 { | |
171 // PACK 0x10: Read effect parameter | |
172 JSGETBYTE(pnote->param); | |
173 if (pnote->effect == jsetNotSet && pnote->param != 0) | |
174 pnote->effect = 0; | |
175 } | |
176 } | |
177 else | |
178 { | |
179 // All data available | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
180 pnote->note = jssXMConvertNote(packb & 0x7f); |
0 | 181 |
182 // Get instrument | |
183 JSGETBYTE(tmp); | |
184 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
185 | |
186 // Get volume | |
187 JSGETBYTE(tmp); | |
188 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
189 | |
190 // Get effect | |
191 JSGETBYTE(pnote->effect); | |
192 | |
193 // Get parameter | |
194 JSGETBYTE(pnote->param); | |
195 if (pnote->effect == 0 && pnote->param == 0) | |
196 pnote->effect = pnote->param = jsetNotSet; | |
197 } | |
198 pnote++; | |
199 } | |
200 | |
201 // Check the state | |
202 if (size > 0) | |
203 { | |
204 // Some data left unparsed | |
205 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
206 "Unparsed data after pattern (%d bytes), possibly broken file.\n", size); |
0 | 207 } |
208 | |
209 return DMERR_OK; | |
210 } | |
211 | |
212 | |
213 /* Convert XM envelope structure to JSS envelope structure | |
214 */ | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
215 static int jssXMConvertEnvelope(JSSEnvelope * d, XMEnvelope * s, char * e, int instr) |
0 | 216 { |
217 int i; | |
218 (void) e; (void) instr; | |
219 | |
220 // Convert envelope points | |
221 for (i = 0; i < XM_MaxEnvPoints; i++) | |
222 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
223 d->points[i].frame = s->points[i].frame; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
224 d->points[i].value = s->points[i].value; |
0 | 225 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
226 |
0 | 227 // Convert other values |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
228 d->npoints = s->npoints; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
229 d->sustain = s->sustain; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
230 d->loopS = s->loopS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
231 d->loopE = s->loopE; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
232 |
0 | 233 // Check if the envelope is used |
234 if (s->flags & 0x01) | |
235 { | |
236 // Convert envelope flags | |
237 d->flags = jenvfUsed; | |
238 if (s->flags & 0x02) | |
239 d->flags |= jenvfSustain; | |
240 | |
241 if (s->flags & 0x04) | |
242 d->flags |= jenvfLooped; | |
243 | |
244 // Check other values | |
245 if (s->npoints > XM_MaxEnvPoints) | |
246 { | |
247 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
248 "Inst#%d/%s-env: nPoints > MAX, possibly broken file.\n", instr, e); |
0 | 249 s->npoints = XM_MaxEnvPoints; |
250 } | |
251 | |
252 if ((d->flags & jenvfSustain) && s->sustain > s->npoints) | |
253 { | |
254 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
255 "Inst#%d/%s-env: iSustain > nPoints (%d > %d), possibly broken file.\n", |
0 | 256 instr, e, s->sustain, s->npoints); |
257 s->sustain = s->npoints; | |
258 } | |
259 | |
260 if ((d->flags & jenvfLooped) && s->loopE > s->npoints) | |
261 { | |
262 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
263 "Inst#%d/%s-env: loopE > nPoints (%d > %d), possibly broken file.\n", |
0 | 264 instr, e, s->loopE, s->npoints); |
265 s->loopE = s->npoints; | |
266 } | |
267 | |
268 if ((d->flags & jenvfLooped) && s->loopS > s->loopE) | |
269 { | |
270 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
271 "Inst#%d/%s-env: loopS > loopE (%d > %d), possibly broken file.\n", |
0 | 272 instr, e, s->loopS, s->loopE); |
273 s->loopS = 0; | |
274 } | |
275 } | |
276 | |
277 return DMERR_OK; | |
278 } | |
279 | |
280 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
281 static int jssXMLoadInstrument(DMResource *inFile, JSSModule *module, int ninst, int nsample, int *xmConvTable) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
282 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
283 XMSample xmS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
284 JSSInstrument *inst; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
285 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
286 // Read header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
287 if (!dmf_read_le32(inFile, &xmS.size) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
288 !dmf_read_le32(inFile, &xmS.loopS) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
289 !dmf_read_le32(inFile, &xmS.loopL) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
290 !dmf_read_byte(inFile, &xmS.volume) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
291 !dmf_read_byte(inFile, (Uint8 *) &xmS.fineTune) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
292 !dmf_read_byte(inFile, &xmS.type) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
293 !dmf_read_byte(inFile, &xmS.panning) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
294 !dmf_read_byte(inFile, (Uint8 *) &xmS.relNote) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
295 !dmf_read_byte(inFile, &xmS.ARESERVED) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
296 !dmf_read_str(inFile, &xmS.sampleName, sizeof(xmS.sampleName))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
297 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
298 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
299 "Error reading instrument sample header #%d/%d [%d]", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
300 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
301 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
302 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
303 if (xmS.size <= 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
304 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
305 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
306 // Allocate sample instrument |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
307 JSSDEBUG("Allocating sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
308 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
309 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
310 xmConvTable[nsample] = module->ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
311 inst = module->instruments[module->ninstruments] = jssAllocateInstrument(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
312 if (inst == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
313 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
314 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
315 "Could not allocate sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
316 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
317 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
318 module->ninstruments++; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
319 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
320 // Copy values |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
321 if (xmS.volume > XM_MaxSampleVolume) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
322 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
323 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
324 "Samp #%d/%d: volume > MAX\n", ninst, nsample); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
325 xmS.volume = XM_MaxSampleVolume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
326 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
327 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
328 inst->volume = xmS.volume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
329 inst->ERelNote = xmS.relNote; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
330 inst->EFineTune = xmS.fineTune; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
331 inst->EPanning = xmS.panning; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
332 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
333 inst->desc = jssASCIItoStr(xmS.sampleName, 0, sizeof(xmS.sampleName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
334 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
335 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
336 // Convert flags |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
337 switch (xmS.type & 0x03) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
338 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
339 case 0: inst->flags = 0; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
340 case 1: inst->flags = jsfLooped; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
341 case 2: inst->flags = jsfLooped | jsfBiDi; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
342 default: |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
343 inst->flags = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
344 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
345 "Samp #%d/%d: Invalid sample type 0x%x\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
346 ninst, nsample, xmS.type); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
347 break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
348 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
349 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
350 if (xmS.type & 0x10) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
351 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
352 // 16-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
353 JSFSET(inst->flags, jsf16bit); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
354 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
355 inst->size = xmS.size / sizeof(Uint16); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
356 inst->loopS = xmS.loopS / sizeof(Uint16); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
357 inst->loopE = ((xmS.loopS + xmS.loopL) / sizeof(Uint16)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
358 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
359 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
360 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
361 // 8-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
362 inst->size = xmS.size; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
363 inst->loopS = xmS.loopS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
364 inst->loopE = (xmS.loopS + xmS.loopL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
365 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
366 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
367 if (xmS.loopL == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
368 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
369 // Always unset loop, if loop length is zero |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
370 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
371 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
372 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
373 if (inst->flags & jsfLooped) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
374 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
375 if (inst->loopS >= inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
376 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
377 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
378 "Samp #%d/%d: loopS >= size (%d >= %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
379 ninst, nsample, inst->loopS, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
380 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
381 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
382 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
383 if (inst->loopE > inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
384 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
385 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
386 "Samp #%d/%d: loopE > size (%d > %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
387 ninst, nsample, inst->loopE, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
388 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
389 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
390 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
391 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
392 // Allocate memory for sample data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
393 if (inst->flags & jsf16bit) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
394 inst->data = dmCalloc(inst->size, sizeof(Uint16)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
395 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
396 inst->data = dmCalloc(inst->size, sizeof(Uint8)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
397 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
398 if (inst->data == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
399 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
400 "Could not allocate sample data #%d/%d.\n", ninst, nsample); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
401 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
402 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
403 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
404 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
405 |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
406 static int jssXMLoadInstrumentData(DMResource *inFile, JSSInstrument *inst, int ninst, int nsample) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
407 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
408 int ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
409 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
410 JSSDEBUG("desc....: '%s'\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
411 "size....: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
412 "loopS...: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
413 "loopE...: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
414 "volume..: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
415 "flags...: %x\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
416 inst->desc, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
417 inst->size, inst->loopS, inst->loopE, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
418 inst->volume, inst->flags); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
419 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
420 if (inst->flags & jsf16bit) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
421 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
422 // Read sampledata |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
423 if (dmfread(inst->data, sizeof(Uint16), inst->size, inFile) != (size_t) inst->size) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
424 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
425 "Error reading sampledata for instrument #%d/%d, %d words.\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
426 ninst, nsample, inst->size); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
427 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
428 // Convert data |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
429 if ((ret = jssDecodeSample16((Uint16 *) inst->data, inst->size, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
430 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
431 (jsampDelta | jsampSwapEndianess) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
432 #else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
433 (jsampDelta) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
434 #endif |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
435 )) != DMERR_OK) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
436 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
437 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
438 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
439 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
440 // Read sampledata |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
441 if (dmfread(inst->data, sizeof(Uint8), inst->size, inFile) != (size_t) inst->size) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
442 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
443 "Error reading sampledata for instrument #%d/%d, %d bytes.\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
444 ninst, nsample, inst->size); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
445 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
446 // Convert data |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
447 if ((ret = jssDecodeSample8((Uint8 *) inst->data, inst->size, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
448 (jsampDelta | jsampFlipSign))) != DMERR_OK) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
449 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
450 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
451 return DMERR_OK; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
452 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
453 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
454 |
1132 | 455 static BOOL jssXMLoadEnvelopePoints(DMResource *inFile, XMEnvelope *env) |
1131
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
456 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
457 int i; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
458 for (i = 0; i < XM_MaxEnvPoints; i++) |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
459 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
460 if (!dmf_read_le16(inFile, &(env->points[i].frame)) || |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
461 !dmf_read_le16(inFile, &(env->points[i].value))) |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
462 return FALSE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
463 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
464 return TRUE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
465 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
466 |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
467 |
1132 | 468 static BOOL jssXMLoadEnvelopeData(DMResource *inFile, XMEnvelope *env) |
469 { | |
470 return | |
471 dmf_read_byte(inFile, &(env->sustain)) && | |
472 dmf_read_byte(inFile, &(env->loopS)) && | |
473 dmf_read_byte(inFile, &(env->loopE)); | |
474 } | |
475 | |
476 | |
0 | 477 /* Load XM-format extended instrument from file-stream into JSS module's given inst |
478 */ | |
479 static int jssXMLoadExtInstrument(DMResource *inFile, int ninst, JSSModule *module) | |
480 { | |
481 XMInstrument1 xmI1; | |
1126 | 482 off_t remainder, pos = dmftell(inFile); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
483 int xmConvTable[XM_MaxInstruments + 1]; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
484 JSSExtInstrument *pEInst; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
485 XMInstrument2 xmI2; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
486 int i, nsample, ret; |
0 | 487 |
488 // Get instrument header #1 | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
489 if (!dmf_read_le32(inFile, &xmI1.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
490 !dmf_read_str(inFile, &xmI1.instName, sizeof(xmI1.instName)) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
491 !dmf_read_byte(inFile, &xmI1.instType) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
492 !dmf_read_le16(inFile, &xmI1.nsamples)) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
493 return DMERR_FREAD; |
0 | 494 |
495 // If there are samples, there is header #2 | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
496 if (xmI1.nsamples == 0) |
0 | 497 { |
498 // We may STILL need to skip extra data after 1st instr. header | |
499 remainder = xmI1.headSize - (dmftell(inFile) - pos); | |
500 if (remainder > 0) | |
501 { | |
98 | 502 JSSDEBUG("xmI1#2 Skipping: %li\n", remainder); |
0 | 503 dmfseek(inFile, remainder, SEEK_CUR); |
504 } | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
505 return DMERR_OK; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
506 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
507 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
508 // Allocate instrument |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
509 if ((pEInst = jssAllocateExtInstrument()) == NULL) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
510 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
511 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
512 "Could not allocate extended instrument structure #%d\n", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
513 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
514 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
515 module->extInstruments[ninst] = pEInst; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
516 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
517 // Get instrument header #2 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
518 if (!dmf_read_le32(inFile, &xmI2.headSize) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
519 !dmf_read_str(inFile, &xmI2.sNumForNotes, sizeof(xmI2.sNumForNotes))) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
520 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
521 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1132 | 522 "Could not read secondary instrument header part #1 for #%d.\n", ninst); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
523 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
524 |
1132 | 525 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) || |
526 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv)) | |
527 { | |
528 JSSERROR(DMERR_FREAD, DMERR_FREAD, | |
529 "Could not read envelope point data for instrument #%d.\n", ninst); | |
530 } | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
531 |
1132 | 532 if (!dmf_read_byte(inFile, &xmI2.volumeEnv.npoints) || |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
533 !dmf_read_byte(inFile, &xmI2.panningEnv.npoints) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
534 |
1132 | 535 !jssXMLoadEnvelopeData(inFile, &xmI2.volumeEnv) || |
536 !jssXMLoadEnvelopeData(inFile, &xmI2.panningEnv) || | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
537 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
538 !dmf_read_byte(inFile, &xmI2.volumeEnv.flags) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
539 !dmf_read_byte(inFile, &xmI2.panningEnv.flags) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
540 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
541 !dmf_read_byte(inFile, &xmI2.vibratoType) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
542 !dmf_read_byte(inFile, &xmI2.vibratoSweep) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
543 !dmf_read_byte(inFile, &xmI2.vibratoDepth) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
544 !dmf_read_byte(inFile, &xmI2.vibratoRate) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
545 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
546 !dmf_read_le16(inFile, &xmI2.fadeOut) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
547 !dmf_read_le16(inFile, &xmI2.ARESERVED)) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
548 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
549 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1132 | 550 "Could not read secondary instrument header part #2 for #%d.\n", ninst); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
551 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
552 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
553 // Skip the extra data after header #2 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
554 remainder = xmI1.headSize - (dmftell(inFile) - pos); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
555 if (remainder > 0) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
556 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
557 JSSDEBUG("xmI1#1 Skipping: %li\n", remainder); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
558 dmfseek(inFile, remainder, SEEK_CUR); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
559 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
560 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
561 // Check and convert all ext instrument information |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
562 #ifndef JSS_LIGHT |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
563 pEInst->desc = jssASCIItoStr(xmI1.instName, 0, sizeof(xmI1.instName)); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
564 #endif |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
565 jssXMConvertEnvelope(&pEInst->volumeEnv, &xmI2.volumeEnv, "vol", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
566 jssXMConvertEnvelope(&pEInst->panningEnv, &xmI2.panningEnv, "pan", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
567 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
568 switch (xmI2.vibratoType) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
569 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
570 case 0: pEInst->vibratoType = jvibSine; break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
571 case 1: pEInst->vibratoType = jvibRamp; break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
572 case 2: pEInst->vibratoType = jvibSquare; break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
573 case 3: pEInst->vibratoType = jvibRandom; break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
574 default: |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
575 pEInst->vibratoType = jvibSine; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
576 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
577 "Invalid extinstrument vibrato type %d for inst #%d\n", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
578 break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
579 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
580 pEInst->vibratoSweep = xmI2.vibratoSweep; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
581 pEInst->vibratoDepth = xmI2.vibratoDepth; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
582 pEInst->vibratoRate = xmI2.vibratoRate; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
583 pEInst->fadeOut = xmI2.fadeOut; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
584 pEInst->nsamples = xmI1.nsamples; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
585 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
586 // Initialize the SNumForNotes conversion table |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
587 for (i = 0; i < XM_MaxInstruments; i++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
588 xmConvTable[i] = jsetNotSet; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
589 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
590 // Read sample headers |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
591 for (nsample = 0; nsample < xmI1.nsamples; nsample++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
592 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
593 if ((ret = jssXMLoadInstrument(inFile, module, ninst, nsample, xmConvTable)) != DMERR_OK) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
594 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
595 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
596 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
597 // Read sample data |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
598 for (nsample = 0; nsample < xmI1.nsamples; nsample++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
599 if (xmConvTable[nsample] != jsetNotSet) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
600 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
601 JSSInstrument *inst = module->instruments[xmConvTable[nsample]]; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
602 if ((ret = jssXMLoadInstrumentData(inFile, inst, ninst, nsample)) != DMERR_OK) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
603 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
604 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
605 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
606 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
607 // Apply new values to sNumForNotes values |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
608 for (i = 0; i < XM_MaxNotes; i++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
609 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
610 int tmp = xmI2.sNumForNotes[i]; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
611 if (tmp >= 0 && tmp < xmI1.nsamples) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
612 pEInst->sNumForNotes[i] = xmConvTable[tmp]; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
613 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
614 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
615 pEInst->sNumForNotes[i] = jsetNotSet; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
616 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
617 "Ext.instrument #%d sNumForNotes[%d] out of range (%d).\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
618 ninst, i, tmp); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
619 } |
0 | 620 } |
621 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
622 return DMERR_OK; |
0 | 623 } |
624 | |
625 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
626 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH) |
0 | 627 { |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
628 int index, result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
629 XMPattern xmP; |
0 | 630 |
631 for (index = 0; index < module->npatterns; index++) | |
632 { | |
633 // Get the pattern header | |
1126 | 634 off_t remainder, pos = dmftell(inFile); |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
635 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
636 if (!dmf_read_le32(inFile, &xmP.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
637 !dmf_read_byte(inFile, &xmP.packing) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
638 !dmf_read_le16(inFile, &xmP.nrows) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
639 !dmf_read_le16(inFile, &xmP.size)) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
640 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
641 "Could not read pattern header data #%d.\n", |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
642 index); |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
643 |
0 | 644 |
645 // Check the header | |
646 if (xmP.packing != 0) | |
647 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
648 "Pattern #%d packing type unsupported (%d)\n", |
0 | 649 index, xmP.packing); |
650 | |
651 if (xmP.nrows == 0) | |
652 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
653 "Pattern #%d has %d rows, invalid data.\n", |
0 | 654 index, xmP.nrows); |
655 | |
656 if (xmP.size > 0) | |
657 { | |
658 // Allocate and unpack pattern | |
659 module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels); | |
660 if (module->patterns[index] == NULL) | |
661 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
662 "Could not allocate memory for pattern #%d\n", index); |
0 | 663 |
664 result = jssXMUnpackPattern(inFile, xmP.size, module->patterns[index]); | |
665 if (result != 0) | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
666 JSSERROR(result, result, "Error in unpacking pattern #%d data\n", index); |
0 | 667 } |
668 | |
669 // Skip extra data (if the file is damaged) | |
88 | 670 remainder = xmP.headSize - (dmftell(inFile) - pos); |
671 if (remainder > 0) | |
0 | 672 { |
98 | 673 JSSDEBUG("xmP Skipping: %li\n", remainder); |
88 | 674 dmfseek(inFile, remainder, SEEK_CUR); |
0 | 675 } |
676 } | |
677 | |
678 // Allocate the empty pattern | |
679 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); | |
680 | |
681 /* Convert song orders list by replacing nonexisting patterns | |
682 * with pattern number jsetMaxPatterns. | |
683 */ | |
684 for (index = 0; index < module->norders; index++) | |
685 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
686 int tmp = xmH->orderList[index]; |
1126 | 687 if (tmp >= module->npatterns || |
688 module->patterns[tmp] == NULL) | |
0 | 689 tmp = jsetMaxPatterns; |
690 | |
691 module->orderList[index] = tmp; | |
692 } | |
693 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
694 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
695 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
696 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
697 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
698 static int jssXMLoadInstruments(DMResource *inFile, JSSModule *module) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
699 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
700 int index; |
0 | 701 for (index = 0; index < module->nextInstruments; index++) |
702 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
703 int result = jssXMLoadExtInstrument(inFile, index, module); |
0 | 704 if (result != 0) |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
705 JSSERROR(result, result, "Errors while reading instrument #%d\n", index); |
0 | 706 } |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
707 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
708 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
709 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
710 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
711 /* Load XM-format module from given file-stream |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
712 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
713 int jssLoadXM(DMResource *inFile, JSSModule **ppModule, BOOL probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
714 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
715 JSSModule *module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
716 XMHeader xmH; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
717 int index, result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
718 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
719 assert(ppModule != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
720 assert(inFile != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
721 *ppModule = NULL; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
722 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
723 // Try to get the XM-header |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
724 if (!dmf_read_str(inFile, &xmH.idMagic, sizeof(xmH.idMagic)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
725 !dmf_read_str(inFile, &xmH.songName, sizeof(xmH.songName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
726 !dmf_read_byte(inFile, &xmH.unUsed1A) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
727 !dmf_read_str(inFile, &xmH.trackerName, sizeof(xmH.trackerName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
728 !dmf_read_le16(inFile, &xmH.version) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
729 !dmf_read_le32(inFile, &xmH.headSize) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
730 !dmf_read_le16(inFile, &xmH.norders) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
731 !dmf_read_le16(inFile, &xmH.defRestartPos) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
732 !dmf_read_le16(inFile, &xmH.nchannels) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
733 !dmf_read_le16(inFile, &xmH.npatterns) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
734 !dmf_read_le16(inFile, &xmH.ninstruments) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
735 !dmf_read_le16(inFile, &xmH.flags) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
736 !dmf_read_le16(inFile, &xmH.defSpeed) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
737 !dmf_read_le16(inFile, &xmH.defTempo)) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
738 return DMERR_FREAD; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
739 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
740 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
741 // Check the fields, none of these are considered fatal |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
742 if (strncmp(xmH.idMagic, "Extended Module: ", 17) != 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
743 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
744 if (probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
745 return DMERR_NOT_SUPPORTED; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
746 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
747 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
748 "Not a FT2 Extended Module (XM), header signature mismatch!\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
749 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
750 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
751 if (xmH.unUsed1A != 0x1a) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
752 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
753 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
754 "Possibly modified or corrupted XM [%x]\n", xmH.unUsed1A); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
755 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
756 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
757 if (xmH.norders > XM_MaxOrders) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
758 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
759 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
760 "Number of orders %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
761 xmH.norders, XM_MaxOrders); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
762 xmH.norders = XM_MaxOrders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
763 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
764 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
765 if (xmH.norders == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
766 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
767 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
768 "Number of orders was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
769 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
770 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
771 if (xmH.npatterns > XM_MaxPatterns) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
772 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
773 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
774 "Number of patterns %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
775 xmH.npatterns, XM_MaxPatterns); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
776 xmH.npatterns = XM_MaxPatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
777 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
778 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
779 if (xmH.npatterns == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
780 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
781 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
782 "Number of patterns was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
783 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
784 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
785 if (xmH.nchannels <= 0 || xmH.nchannels > XM_MaxChannels) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
786 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
787 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
788 "Number of channels was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
789 xmH.nchannels, XM_MaxChannels); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
790 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
791 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
792 if (xmH.ninstruments <= 0 || xmH.ninstruments > XM_MaxInstruments) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
793 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
794 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
795 "Number of instruments was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
796 xmH.ninstruments, XM_MaxInstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
797 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
798 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
799 if (!dmf_read_str(inFile, &xmH.orderList, sizeof(xmH.orderList))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
800 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
801 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
802 "Error reading pattern order list.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
803 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
804 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
805 /* Okay, allocate a module structure |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
806 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
807 module = jssAllocateModule(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
808 if (module == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
809 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
810 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
811 "Could not allocate memory for module structure.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
812 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
813 *ppModule = module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
814 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
815 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
816 // Convert and check the header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
817 module->moduleType = jmdtXM; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
818 module->intVersion = xmH.version; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
819 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
820 module->moduleName = jssASCIItoStr(xmH.songName, 0, sizeof(xmH.songName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
821 module->trackerName = jssASCIItoStr(xmH.trackerName, 0, sizeof(xmH.trackerName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
822 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
823 module->defSpeed = xmH.defSpeed; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
824 module->defTempo = xmH.defTempo; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
825 module->nextInstruments = xmH.ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
826 module->ninstruments = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
827 module->npatterns = xmH.npatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
828 module->norders = xmH.norders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
829 module->nchannels = xmH.nchannels; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
830 module->defFlags = jmdfStereo | jmdfFT2Replay; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
831 module->defRestartPos = xmH.defRestartPos; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
832 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
833 if ((xmH.flags & 1) == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
834 module->defFlags |= jmdfAmigaPeriods; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
835 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
836 // Setup the default pannings |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
837 for (index = 0; index < jsetNChannels; index++) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
838 module->defPanning[index] = jchPanMiddle; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
839 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
840 // Load rest of the module |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
841 if ((result = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
842 return result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
843 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
844 if ((result = jssXMLoadInstruments(inFile, module)) != DMERR_OK) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
845 return result; |
0 | 846 |
847 return DMERR_OK; | |
848 } |