Mercurial > hg > dmlib
annotate minijss/jssmod.h @ 1231:a275b7382ffa
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Mar 2015 12:34:35 +0200 |
parents | 9a07415e395e |
children | b8c9af10b7fd |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Module structure and handling routines | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1163 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #ifndef JSSMOD_H | |
7 #define JSSMOD_H | |
8 | |
9 #include "jss.h" | |
10 #include "dmres.h" | |
11 | |
358 | 12 #ifdef __cplusplus |
13 extern "C" { | |
14 #endif | |
0 | 15 |
16 // Max data size definitions | |
1220 | 17 #define jsetMaxChannels (128) |
18 #define jsetMaxRows (16*1024) // Number of rows checked against | |
19 #define jsetMaxPatterns (1024) // Max patterns | |
1215
66c79bae8704
Bump up some maximum values for JSS module data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1210
diff
changeset
|
20 #define jsetMaxInstruments (1024) |
66c79bae8704
Bump up some maximum values for JSS module data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1210
diff
changeset
|
21 #define jsetMaxOrders (512) |
0 | 22 #define jsetNNotes (11 * 12) |
1220 | 23 #define jsetMinNote (0) // Smallest note number |
0 | 24 #define jsetMaxNote (jsetNNotes - 1) |
1220 | 25 #define jsetMaxEnvPoints (64) // Max number of envelope points |
0 | 26 |
27 // Instrument envelope flags | |
28 #define jenvfUsed (0x01) // Envelope is used | |
29 #define jenvfSustain (0x02) // Envelope has a sustain point (XM) or has sustain loop (IT) | |
30 #define jenvfLooped (0x04) // Envelope is looped | |
31 | |
32 // Instrument vibrato waveform types | |
33 #define jvibSine (0) | |
34 #define jvibRamp (1) | |
35 #define jvibSquare (2) | |
36 #define jvibRandom (3) | |
37 | |
38 // General stuff | |
39 #define jsetNoteOff (-2) | |
40 #define jsetOrderEnd (-1) | |
41 #define jsetOrderSkip (-2) | |
42 | |
43 | |
44 // General module flags | |
45 #define jmdfAmigaPeriods (0x0001) // Use non-linear periods (Amiga) | |
46 #define jmdfAmigaLimits (0x0002) // Use Amiga-styled valuelimits | |
47 #define jmdfStereo (0x0008) // Use stereo output, if possible | |
48 | |
49 #define jmdfFT2Replay (0x0010) // Use FT2 replaying bugs/features | |
50 #define jmdfST300Slides (0x0020) // Use Scream Tracker 3.00 slides | |
51 #define jmdfByteLStart (0x0040) // LStart is in BYTES instead of WORDS (MOD only) | |
52 | |
53 | |
54 // Module format types | |
55 enum JMDT | |
56 { | |
57 jmdtMOD = 1, | |
58 jmdtS3M, | |
59 jmdtXM, | |
60 jmdtIT | |
61 }; | |
62 | |
63 | |
64 // Bits for sample conversion routines | |
65 #define jsampDelta (0x01) | |
66 #define jsampFlipSign (0x02) | |
67 #define jsampSwapEndianess (0x04) | |
68 #define jsampSplit (0x08) | |
69 | |
70 | |
71 // Internal instrument structure | |
72 typedef struct | |
73 { | |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
74 int size, // Length in units |
0 | 75 loopS, // Loop start position in units |
76 loopE; // Loop end position in units | |
77 int volume, // Volume [jsetMinVol...jsetMaxVol] | |
78 flags, // Flags - see jss.h jsfXXXX | |
79 C4BaseSpeed, // C4BaseSpeed | |
80 ERelNote, // Extended: Relative note value | |
81 EFineTune, // Extended: Fine-tune value | |
82 EPanning; // Extended: Panning | |
83 #ifndef JSS_LIGHT | |
84 char *desc; | |
85 #endif | |
86 void *data; // Sample data | |
87 | |
88 BOOL hasData; | |
89 int convFlags; | |
90 } JSSInstrument; | |
91 | |
92 | |
93 // Envelope point structure | |
94 typedef struct | |
95 { | |
96 int frame, value; | |
97 } JSSEnvelopePoint; | |
98 | |
99 | |
100 // Envelope structure | |
101 typedef struct | |
102 { | |
103 int flags, | |
104 npoints, | |
105 sustain, | |
106 loopS, | |
107 loopE; | |
108 JSSEnvelopePoint points[jsetMaxEnvPoints]; | |
109 } JSSEnvelope; | |
110 | |
111 | |
112 // Extended instrument | |
113 typedef struct | |
114 { | |
115 #ifndef JSS_LIGHT | |
116 char *desc; | |
117 #endif | |
1178
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
118 int nsamples, |
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
119 sNumForNotes[jsetNNotes], |
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
120 instConvTable[jsetNNotes]; |
0 | 121 JSSEnvelope volumeEnv, panningEnv; |
122 int vibratoType, | |
123 vibratoSweep, | |
124 vibratoDepth, | |
125 vibratoRate, | |
126 fadeOut; | |
127 } JSSExtInstrument; | |
128 | |
129 | |
130 // Internal pattern structures | |
131 typedef struct | |
132 { | |
133 int note, | |
134 instrument, | |
135 volume, | |
136 effect, | |
137 param; | |
138 } JSSNote; | |
139 | |
140 | |
141 typedef struct | |
142 { | |
143 int nrows, nchannels; | |
144 JSSNote *data; | |
145 } JSSPattern; | |
146 | |
147 | |
148 // Module structure | |
149 typedef struct | |
150 { | |
151 int moduleType; // Type of the module | |
152 char *moduleName; // Title/name | |
153 char *trackerName; // Tracker software name | |
154 int defSpeed, // Initial values | |
155 defTempo, | |
156 defFlags, | |
157 defRestartPos, | |
158 intVersion, // Format's internal version | |
159 nchannels, | |
160 ninstruments, | |
161 nextInstruments, | |
162 npatterns, | |
163 norders; | |
164 | |
165 int defPanning[jsetNChannels]; | |
166 int orderList[jsetMaxOrders]; | |
167 JSSPattern *patterns[jsetMaxPatterns + 1]; | |
168 JSSInstrument *instruments[jsetMaxInstruments]; | |
169 JSSExtInstrument *extInstruments[jsetMaxInstruments]; | |
170 | |
171 #ifdef JSS_SUP_THREADS | |
172 DMMutex *mutex; | |
173 #endif | |
174 | |
175 } JSSModule; | |
176 | |
177 | |
178 #ifdef JSS_SUP_JSSMOD | |
179 | |
1230 | 180 #define JSSMOD_VERSION (0x20) |
0 | 181 |
182 enum | |
183 { | |
184 PATMODE_RAW_HORIZ = 1, | |
185 PATMODE_COMP_HORIZ, | |
186 PATMODE_RAW_VERT, | |
187 PATMODE_COMP_VERT, | |
188 PATMODE_RAW_ELEM, | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
189 PATMODE_LAST |
0 | 190 }; |
191 | |
192 /* JSSMOD typedefs | |
193 */ | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
194 typedef struct __attribute__((__packed__)) |
0 | 195 { |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
196 char idMagic[2]; // "JM" |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
197 Uint8 idVersion; // 0x10 for 1.0, etc. |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
198 Uint16 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
199 defFlags, // Flags field: see jmdf* flags |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
200 intVersion, // Internal version, format dependant |
0 | 201 norders, // Number of orders in orderlist |
202 npatterns, // Number of patterns | |
203 nextInstruments, // Number of extended instruments | |
204 ninstruments, // Number of sample-instruments | |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
205 defRestartPos; // Default restart position in orderlist |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
206 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
207 Uint8 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
208 nchannels, // Number of channels |
0 | 209 defSpeed, // Default speed (ticks/row) |
210 defTempo, // Default tempo (BPM) | |
211 patMode; // Pattern data format mode | |
212 | |
213 /* | |
214 - After this, norders long orders table will follow, of type: | |
215 Sint16 orderList[norders]; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
216 |
0 | 217 - Pattern data, format depends on patMode. |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
218 |
0 | 219 - Extended instruments (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
220 |
0 | 221 - Sample instrument headers (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
222 |
0 | 223 - Sample data (format depends) (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
224 |
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
225 (*) Items are optional and may have been omitted. Fields in the |
0 | 226 module and other headers are used to indicate if these items exist. |
227 */ | |
228 } JSSMODHeader; | |
229 | |
230 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
231 typedef struct __attribute__((__packed__)) |
0 | 232 { |
233 Uint16 frame, value; | |
234 } JSSMODEnvelopePoint; | |
235 | |
236 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
237 typedef struct __attribute__((__packed__)) |
0 | 238 { |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
239 Uint32 |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
240 flags, |
0 | 241 npoints, |
242 sustain, | |
243 loopS, | |
244 loopE; | |
245 JSSMODEnvelopePoint points[jsetMaxEnvPoints]; | |
246 } JSSMODEnvelope; | |
247 | |
248 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
249 typedef struct __attribute__((__packed__)) |
0 | 250 { |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
251 Uint8 nsamples, |
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
252 vibratoType; |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
253 Uint16 vibratoSweep, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
254 vibratoDepth, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
255 vibratoRate, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
256 fadeOut; |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
257 Uint32 sNumForNotes[jsetNNotes]; // 32bit because internally we use global indices |
0 | 258 JSSMODEnvelope volumeEnv, panningEnv; |
259 } JSSMODExtInstrument; | |
260 | |
261 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
262 typedef struct __attribute__((__packed__)) |
0 | 263 { |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
264 Sint32 size, // Length in units |
0 | 265 loopS, // Loop start position in units |
266 loopE; // Loop end position in units | |
1209 | 267 Sint16 volume, // Volume [jsetMinVol...jsetMaxVol] |
0 | 268 flags, // Flags - see jss.h jsfXXXX |
269 C4BaseSpeed, // C4BaseSpeed | |
270 ERelNote, // Extended: Relative note value | |
271 EFineTune, // Extended: Fine-tune value | |
272 EPanning; // Extended: Panning | |
1209 | 273 Uint8 convFlags, // Conversion flags .. jsampXXXX |
0 | 274 hasData; // != 0 if there is sample data |
275 } JSSMODInstrument; | |
276 | |
277 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
278 #define JM_COMP_NOTE (0x01) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
279 #define JM_COMP_INSTRUMENT (0x02) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
280 #define JM_COMP_VOLUME (0x04) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
281 #define JM_COMP_EFFECT (0x08) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
282 #define JM_COMP_PARAM (0x10) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
283 #define JM_COMP_ALL (JM_COMP_NOTE | JM_COMP_INSTRUMENT | JM_COMP_VOLUME | JM_COMP_EFFECT | JM_COMP_PARAM) |
0 | 284 |
285 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
286 typedef struct __attribute__((__packed__)) |
0 | 287 { |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
288 Uint32 size; |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
289 Uint16 nrows; |
0 | 290 } JSSMODPattern; |
291 | |
292 #endif | |
293 | |
1216 | 294 |
0 | 295 #ifndef JSS_LIGHT |
948 | 296 char * jssASCIItoStr(const char *src, const char endByte, const size_t len); |
0 | 297 BOOL jssEncodeSample8(Uint8 *, const size_t, const int); |
298 BOOL jssEncodeSample16(Uint16 *, const size_t, const int); | |
299 #endif | |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
300 int jssDecodeSample8(Uint8 *, const size_t, const int); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
301 int jssDecodeSample16(Uint16 *, const size_t, const int); |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
302 int jssConvertModuleForPlaying(JSSModule *module); |
1231 | 303 |
0 | 304 JSSModule * jssAllocateModule(void); |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
305 int jssFreeModule(JSSModule * module); |
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
306 JSSPattern * jssAllocatePattern(const int nrows, const int nchannels); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
307 void jssFreePattern(JSSPattern *pattern); |
0 | 308 JSSInstrument * jssAllocateInstrument(void); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
309 void jssFreeInstrument(JSSInstrument *inst); |
0 | 310 JSSExtInstrument * jssAllocateExtInstrument(void); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
311 void jssFreeExtInstrument(JSSExtInstrument *inst); |
0 | 312 |
313 #ifdef JSS_SUP_XM | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
314 int jssLoadXM(DMResource *file, JSSModule **pmodule, BOOL probe); |
0 | 315 #endif |
316 | |
317 #ifdef JSS_SUP_JSSMOD | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
318 int jssLoadJSSMOD(DMResource *file, JSSModule **pmodule, BOOL probe); |
0 | 319 #endif |
320 | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
321 |
358 | 322 #ifdef __cplusplus |
323 } | |
324 #endif | |
325 | |
0 | 326 #endif // JSSMOD_H |