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