Mercurial > hg > dmlib
annotate jssmod.c @ 44:064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 30 Sep 2012 23:23:08 +0300 |
parents | 048536ad01e0 |
children | 033c660c25f5 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Module structure and handling routines | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2006-2007 Tecnic Software productions (TNSP) | |
5 */ | |
6 #include "jssmod.h" | |
7 #include <string.h> | |
8 | |
9 | |
10 #ifndef JSS_LIGHT | |
11 /* Take given data until maxlen reached, make a string | |
12 */ | |
13 char *jssASCIItoStr(char * sdata, const char endByte, const size_t maxLen) | |
14 { | |
15 size_t i, k; | |
16 char *res; | |
17 | |
18 for (i = 0; sdata[i] && i < maxLen; i++); | |
19 | |
20 res = (char *) dmMalloc(i + 1); | |
21 if (res == NULL) | |
22 return NULL; | |
23 | |
24 for (k = 0; sdata[k] != endByte && k < i; k++) | |
25 res[k] = sdata[k]; | |
26 | |
27 res[k] = 0; | |
28 | |
29 return res; | |
30 } | |
31 | |
32 | |
33 /* Encodes a given 8-bit sample | |
34 */ | |
43 | 35 BOOL jssEncodeSample8(Uint8 * data, const size_t len, const int ops) |
0 | 36 { |
43 | 37 size_t count = len; |
0 | 38 Sint8 t, value = 0; |
39 | |
43 | 40 while (count--) |
0 | 41 { |
43 | 42 t = *data; |
0 | 43 |
44 if (ops & jsampFlipSign) | |
45 t ^= 0x80; | |
46 | |
47 if (ops & jsampDelta) | |
48 { | |
49 int n = t - value; | |
50 value = t; | |
51 t = n; | |
52 } | |
53 | |
43 | 54 *(data++) = t; |
0 | 55 } |
56 | |
57 return TRUE; | |
58 } | |
59 | |
60 | |
61 /* Decodes a given 16-bit sample | |
62 */ | |
43 | 63 BOOL jssEncodeSample16(Uint16 * data, const size_t len, const int ops) |
0 | 64 { |
65 // "Split" the 16-bit samples into 8-bit halves | |
66 if (ops & jsampSplit) | |
67 { | |
68 // Allocate temporary processing buffer | |
43 | 69 size_t count, bufSize = len * sizeof(Sint16); |
0 | 70 Uint8 *bp1, *bp2; |
43 | 71 Sint16 *sdata, *tmpBuf = dmMalloc(bufSize); |
0 | 72 if (tmpBuf == NULL) return FALSE; |
73 | |
74 sdata = tmpBuf; | |
43 | 75 bp1 = (Uint8 *) data; |
76 bp2 = bp1 + len; | |
77 count = len; | |
0 | 78 |
43 | 79 while (count--) |
0 | 80 { |
43 | 81 Sint16 t = (*sdata++); |
0 | 82 *bp1++ = t >> 8; |
83 *bp2++ = t & 0xff; | |
84 } | |
85 | |
43 | 86 memcpy(data, tmpBuf, bufSize); |
0 | 87 dmFree(tmpBuf); |
88 | |
43 | 89 return jssEncodeSample8((Uint8 *) data, bufSize, ops); |
0 | 90 } |
91 else | |
92 { | |
43 | 93 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; |
94 size_t count = len; | |
0 | 95 |
43 | 96 while (count--) |
0 | 97 { |
98 if (ops & jsampSwapEndianess) | |
99 { | |
100 p = *sdata; | |
101 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); | |
102 } else | |
103 t = *sdata; | |
104 | |
105 if (ops & jsampDelta) | |
106 { | |
107 int n = t - value; | |
108 value = t; | |
109 t = n; | |
110 } | |
111 | |
112 if (ops & jsampFlipSign) | |
113 t ^= 0x8000; | |
114 | |
115 *(sdata++) = t; | |
116 } | |
117 } | |
118 return TRUE; | |
119 } | |
44
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
120 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
121 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
122 int jssConvertSampleFromFP(void **dst, void * src, const size_t len, const int flags) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
123 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
124 // Convert from floating point to 8/16bit |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
125 size_t count = len; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
126 float *in = (float *) src; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
127 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
128 if (flags & jsf16bit) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
129 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
130 Sint16 *out; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
131 *dst = out = dmMalloc(sizeof(sizeof(Sint16)) * len); |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
132 if (out == NULL) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
133 return DMERR_MALLOC; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
134 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
135 while (count--) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
136 *(out++) = (*(in++) * 32767.0f); |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
137 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
138 else |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
139 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
140 Uint8 *out; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
141 *dst = out = dmMalloc(sizeof(sizeof(Uint8)) * len); |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
142 if (out == NULL) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
143 return DMERR_MALLOC; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
144 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
145 while (count--) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
146 *(out++) = 128 + (int) (*(in++) * 127.0f); |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
147 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
148 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
149 return DMERR_OK; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
150 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
151 |
0 | 152 #endif |
153 | |
154 | |
155 /* Decodes a given 8-bit sample | |
156 */ | |
43 | 157 BOOL jssDecodeSample8(Uint8 * data, const size_t len, const int ops) |
0 | 158 { |
43 | 159 size_t count = len; |
0 | 160 Sint8 t, value = 0; |
161 | |
43 | 162 while (count--) |
0 | 163 { |
43 | 164 t = *data; |
0 | 165 |
166 if (ops & jsampDelta) | |
167 t = value = t + value; | |
168 | |
169 if (ops & jsampFlipSign) | |
170 t ^= 0x80; | |
171 | |
43 | 172 *(data++) = t; |
0 | 173 } |
174 return TRUE; | |
175 } | |
176 | |
177 | |
178 /* Decodes a given 16-bit sample | |
179 */ | |
43 | 180 BOOL jssDecodeSample16(Uint16 * data, const size_t len, const int ops) |
0 | 181 { |
182 if (ops & jsampSplit) | |
183 { | |
43 | 184 size_t count, bufSize = len * sizeof(Uint16); |
0 | 185 Uint8 *bp1, *bp2; |
186 Sint16 *tmpBuf, *sdata; | |
187 | |
43 | 188 if (!jssDecodeSample8((Uint8 *) data, bufSize, ops)) |
0 | 189 return FALSE; |
190 | |
191 tmpBuf = dmMalloc(bufSize); | |
192 if (tmpBuf == NULL) return FALSE; | |
43 | 193 memcpy(tmpBuf, data, bufSize); |
0 | 194 |
43 | 195 sdata = (Sint16 *) data; |
0 | 196 bp1 = (Uint8 *) tmpBuf; |
43 | 197 bp2 = bp1 + len; |
198 count = len; | |
199 while (count--) | |
0 | 200 { |
201 *sdata++ = (*bp1++ << 8) | (*bp2++ & 0xff); | |
202 } | |
203 | |
204 dmFree(tmpBuf); | |
205 } | |
206 else | |
207 { | |
43 | 208 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; |
209 size_t count = len; | |
210 while (count--) | |
0 | 211 { |
212 if (ops & jsampSwapEndianess) | |
213 { | |
214 p = *sdata; | |
215 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); | |
216 } else | |
217 t = *sdata; | |
218 | |
219 if (ops & jsampDelta) | |
220 t = value = t + value; | |
221 | |
222 if (ops & jsampFlipSign) | |
223 t ^= 0x8000; | |
224 | |
225 *(sdata++) = t; | |
226 } | |
227 } | |
228 return TRUE; | |
229 } | |
230 | |
231 | |
44
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
232 int jssConvertSampleToFP(void **dst, void * src, const size_t len, const int flags) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
233 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
234 // Convert from 8/16bit to floating point |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
235 size_t count = len; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
236 float *out; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
237 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
238 *dst = out = dmMalloc(sizeof(float) * len); |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
239 if (out == NULL) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
240 return DMERR_MALLOC; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
241 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
242 if (flags & jsf16bit) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
243 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
244 Sint16 *in = (Sint16 *) src; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
245 while (count--) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
246 *(out++) = (float) (*(in++)) / 32768.0f; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
247 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
248 else |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
249 { |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
250 Uint8 *in = (Uint8 *) src; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
251 while (count--) |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
252 *(out++) = (float) (*(in++) - 128) / 128.0f; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
253 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
254 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
255 return DMERR_OK; |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
256 } |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
257 |
064d1d1d5b0f
Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
258 |
0 | 259 /* Allocates a new module structure or returns errorvalue if failed. |
260 * Memory is allocated only for the basic structure. Sample- and pattern | |
261 * areas must be allocated separately with appropriate routines. | |
262 */ | |
263 JSSModule *jssAllocateModule(void) | |
264 { | |
265 int i; | |
266 JSSModule *module; | |
267 | |
268 // Allocate module structure | |
269 module = dmMalloc0(sizeof(JSSModule)); | |
270 if (module == NULL) | |
271 return NULL; | |
272 | |
273 // Initialize structure | |
274 for (i = 0; i < jsetNChannels; i++) | |
275 module->defPanning[i] = jchPanMiddle; | |
276 | |
277 for (i = 0; i < jsetMaxOrders; i++) | |
278 module->orderList[i] = jsetOrderEnd; | |
279 | |
280 // Allocate mutex | |
281 #ifdef JSS_SUP_THREADS | |
282 module->mutex = dmCreateMutex(); | |
283 #endif | |
284 | |
285 return module; | |
286 } | |
287 | |
288 | |
289 /* Frees a given module structure, freeing all memory areas | |
290 * that were allocated for it (including patterns, samples, etc.) | |
291 */ | |
292 int jssFreeModule(JSSModule * module) | |
293 { | |
294 int i; | |
295 | |
296 if (module == NULL) | |
297 return DMERR_NULLPTR; | |
298 | |
299 // Free strings | |
300 #ifndef JSS_LIGHT | |
301 dmFree(module->moduleName); | |
302 dmFree(module->trackerName); | |
303 #endif | |
304 | |
305 // Free patterns | |
306 for (i = 0; i < module->npatterns; i++) | |
307 { | |
308 if (module->patterns[i]) | |
309 { | |
310 JSSPattern *pat = module->patterns[i]; | |
311 dmFree(pat->data); | |
312 dmFree(pat); | |
313 module->patterns[i] = NULL; | |
314 } | |
315 } | |
316 | |
317 // Free instruments | |
318 for (i = 0; i < module->ninstruments; i++) | |
319 { | |
320 if (module->instruments[i]) | |
321 { | |
322 JSSInstrument *inst = module->instruments[i]; | |
323 #ifndef JSS_LIGHT | |
324 dmFree(inst->desc); | |
325 #endif | |
326 dmFree(inst->data); | |
327 dmFree(inst); | |
328 module->instruments[i] = NULL; | |
329 } | |
330 } | |
331 | |
332 // Free extended instruments | |
333 for (i = 0; i < module->nextInstruments; i++) | |
334 { | |
335 if (module->extInstruments[i]) | |
336 { | |
337 JSSExtInstrument *ext = module->extInstruments[i]; | |
338 #ifndef JSS_LIGHT | |
339 dmFree(ext->desc); | |
340 #endif | |
341 dmFree(ext); | |
342 module->extInstruments[i] = NULL; | |
343 } | |
344 } | |
345 | |
346 // Free mutex | |
347 #ifdef JSS_SUP_THREADS | |
348 dmDestroyMutex(module->mutex); | |
349 #endif | |
350 | |
351 // Free the module structure | |
352 memset(module, 0, sizeof(JSSModule)); | |
353 dmFree(module); | |
354 | |
355 return DMERR_OK; | |
356 } | |
357 | |
358 | |
359 /* Allocates and initializes a internal pattern structure. | |
360 */ | |
361 JSSPattern *jssAllocatePattern(int nrows, int nchannels) | |
362 { | |
363 int i, j; | |
364 JSSPattern *res; | |
365 JSSNote *pnote; | |
366 | |
367 // Check arguments | |
368 if (nrows <= 0 || nchannels <= 0) | |
369 JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%i or nchannels=%i.\n", nrows, nchannels); | |
370 | |
371 // Allocate a pattern structure | |
372 res = dmMalloc0(sizeof(JSSPattern)); | |
373 if (res == NULL) | |
374 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern structure.\n"); | |
375 | |
376 // Allocate notedata | |
377 res->data = dmCalloc(nrows * nchannels, sizeof(JSSNote)); | |
378 if (res->data == NULL) | |
379 { | |
380 dmFree(res); | |
381 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%i, nchannels=%i).\n", nrows, | |
382 nchannels); | |
383 } | |
384 | |
385 // Initialize | |
386 res->nrows = nrows; | |
387 res->nchannels = nchannels; | |
388 | |
389 pnote = res->data; | |
390 for (j = 0; j < nrows; j++) | |
391 { | |
392 for (i = 0; i < nchannels; i++) | |
393 { | |
394 pnote->note = pnote->instrument = pnote->volume = | |
395 pnote->effect = pnote->param = jsetNotSet; | |
396 | |
397 pnote++; | |
398 } | |
399 } | |
400 | |
401 // OK, return pointer to struct | |
402 return res; | |
403 } | |
404 | |
405 | |
406 /* Allocates and initializes internal "normal" instrument structure. | |
407 */ | |
408 JSSInstrument *jssAllocateInstrument(void) | |
409 { | |
410 JSSInstrument *res; | |
411 | |
412 // Allocate a instrument structure | |
413 res = dmMalloc0(sizeof(JSSInstrument)); | |
414 if (res == NULL) | |
415 return NULL; | |
416 | |
417 return res; | |
418 } | |
419 | |
420 | |
421 /* Allocates and initializes "extended" instrument structure. | |
422 */ | |
423 JSSExtInstrument *jssAllocateExtInstrument(void) | |
424 { | |
425 int i; | |
426 JSSExtInstrument *res; | |
427 | |
428 // Allocate a instrument structure | |
429 res = dmMalloc0(sizeof(JSSExtInstrument)); | |
430 if (res == NULL) | |
431 return NULL; | |
432 | |
433 for (i = 0; i < jsetNNotes; i++) | |
434 { | |
435 res->sNumForNotes[i] = jsetNotSet; | |
436 } | |
437 | |
438 return res; | |
439 } |