Mercurial > hg > dmlib
comparison minijss/jssmod.c @ 1127:e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2015 06:11:37 +0200 |
parents | 698ee83bac98 |
children | e466d10dae6d |
comparison
equal
deleted
inserted
replaced
1126:0888764d01cd | 1127:e22d4ceb6414 |
---|---|
36 */ | 36 */ |
37 BOOL jssEncodeSample8(Uint8 * data, const size_t len, const int ops) | 37 BOOL jssEncodeSample8(Uint8 * data, const size_t len, const int ops) |
38 { | 38 { |
39 size_t count = len; | 39 size_t count = len; |
40 Sint8 t, value = 0; | 40 Sint8 t, value = 0; |
41 | 41 |
42 while (count--) | 42 while (count--) |
43 { | 43 { |
44 t = *data; | 44 t = *data; |
45 | 45 |
46 if (ops & jsampFlipSign) | 46 if (ops & jsampFlipSign) |
47 t ^= 0x80; | 47 t ^= 0x80; |
48 | 48 |
49 if (ops & jsampDelta) | 49 if (ops & jsampDelta) |
50 { | 50 { |
51 int n = t - value; | 51 int n = t - value; |
52 value = t; | 52 value = t; |
53 t = n; | 53 t = n; |
54 } | 54 } |
55 | 55 |
56 *(data++) = t; | 56 *(data++) = t; |
57 } | 57 } |
58 | 58 |
59 return TRUE; | 59 return TRUE; |
60 } | 60 } |
82 { | 82 { |
83 Sint16 t = (*sdata++); | 83 Sint16 t = (*sdata++); |
84 *bp1++ = t >> 8; | 84 *bp1++ = t >> 8; |
85 *bp2++ = t & 0xff; | 85 *bp2++ = t & 0xff; |
86 } | 86 } |
87 | 87 |
88 memcpy(data, tmpBuf, bufSize); | 88 memcpy(data, tmpBuf, bufSize); |
89 dmFree(tmpBuf); | 89 dmFree(tmpBuf); |
90 | 90 |
91 return jssEncodeSample8((Uint8 *) data, bufSize, ops); | 91 return jssEncodeSample8((Uint8 *) data, bufSize, ops); |
92 } | 92 } |
93 else | 93 else |
94 { | 94 { |
95 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; | 95 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; |
96 size_t count = len; | 96 size_t count = len; |
97 | 97 |
98 while (count--) | 98 while (count--) |
99 { | 99 { |
100 if (ops & jsampSwapEndianess) | 100 if (ops & jsampSwapEndianess) |
101 { | 101 { |
102 p = *sdata; | 102 p = *sdata; |
103 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); | 103 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); |
104 } | 104 } |
105 else | 105 else |
106 t = *sdata; | 106 t = *sdata; |
107 | 107 |
108 if (ops & jsampDelta) | 108 if (ops & jsampDelta) |
109 { | 109 { |
110 int n = t - value; | 110 int n = t - value; |
111 value = t; | 111 value = t; |
112 t = n; | 112 t = n; |
113 } | 113 } |
114 | 114 |
115 if (ops & jsampFlipSign) | 115 if (ops & jsampFlipSign) |
116 t ^= 0x8000; | 116 t ^= 0x8000; |
117 | 117 |
118 *(sdata++) = t; | 118 *(sdata++) = t; |
119 } | 119 } |
120 } | 120 } |
121 return TRUE; | 121 return TRUE; |
122 } | 122 } |
128 */ | 128 */ |
129 BOOL jssDecodeSample8(Uint8 * data, const size_t len, const int ops) | 129 BOOL jssDecodeSample8(Uint8 * data, const size_t len, const int ops) |
130 { | 130 { |
131 size_t count = len; | 131 size_t count = len; |
132 Sint8 t, value = 0; | 132 Sint8 t, value = 0; |
133 | 133 |
134 while (count--) | 134 while (count--) |
135 { | 135 { |
136 t = *data; | 136 t = *data; |
137 | 137 |
138 if (ops & jsampDelta) | 138 if (ops & jsampDelta) |
139 t = value = t + value; | 139 t = value = t + value; |
140 | 140 |
141 if (ops & jsampFlipSign) | 141 if (ops & jsampFlipSign) |
142 t ^= 0x80; | 142 t ^= 0x80; |
143 | 143 |
144 *(data++) = t; | 144 *(data++) = t; |
145 } | 145 } |
146 return TRUE; | 146 return TRUE; |
147 } | 147 } |
148 | 148 |
154 if (ops & jsampSplit) | 154 if (ops & jsampSplit) |
155 { | 155 { |
156 size_t count, bufSize = len * sizeof(Uint16); | 156 size_t count, bufSize = len * sizeof(Uint16); |
157 Uint8 *bp1, *bp2; | 157 Uint8 *bp1, *bp2; |
158 Sint16 *tmpBuf, *sdata; | 158 Sint16 *tmpBuf, *sdata; |
159 | 159 |
160 if (!jssDecodeSample8((Uint8 *) data, bufSize, ops)) | 160 if (!jssDecodeSample8((Uint8 *) data, bufSize, ops)) |
161 return FALSE; | 161 return FALSE; |
162 | 162 |
163 tmpBuf = dmMalloc(bufSize); | 163 tmpBuf = dmMalloc(bufSize); |
164 if (tmpBuf == NULL) return FALSE; | 164 if (tmpBuf == NULL) return FALSE; |
165 memcpy(tmpBuf, data, bufSize); | 165 memcpy(tmpBuf, data, bufSize); |
166 | 166 |
167 sdata = (Sint16 *) data; | 167 sdata = (Sint16 *) data; |
168 bp1 = (Uint8 *) tmpBuf; | 168 bp1 = (Uint8 *) tmpBuf; |
169 bp2 = bp1 + len; | 169 bp2 = bp1 + len; |
170 count = len; | 170 count = len; |
171 while (count--) | 171 while (count--) |
172 { | 172 { |
173 *sdata++ = (*bp1++ << 8) | (*bp2++ & 0xff); | 173 *sdata++ = (*bp1++ << 8) | (*bp2++ & 0xff); |
174 } | 174 } |
175 | 175 |
176 dmFree(tmpBuf); | 176 dmFree(tmpBuf); |
177 } | 177 } |
178 else | 178 else |
179 { | 179 { |
180 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; | 180 Sint16 t, p, value = 0, *sdata = (Sint16 *) data; |
186 p = *sdata; | 186 p = *sdata; |
187 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); | 187 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8); |
188 } | 188 } |
189 else | 189 else |
190 t = *sdata; | 190 t = *sdata; |
191 | 191 |
192 if (ops & jsampDelta) | 192 if (ops & jsampDelta) |
193 t = value = t + value; | 193 t = value = t + value; |
194 | 194 |
195 if (ops & jsampFlipSign) | 195 if (ops & jsampFlipSign) |
196 t ^= 0x8000; | 196 t ^= 0x8000; |
197 | 197 |
198 *(sdata++) = t; | 198 *(sdata++) = t; |
199 } | 199 } |
200 } | 200 } |
201 return TRUE; | 201 return TRUE; |
202 } | 202 } |
211 Sint16 *out; | 211 Sint16 *out; |
212 | 212 |
213 *dst = out = dmMalloc(sizeof(Sint16) * len); | 213 *dst = out = dmMalloc(sizeof(Sint16) * len); |
214 if (out == NULL) | 214 if (out == NULL) |
215 return DMERR_MALLOC; | 215 return DMERR_MALLOC; |
216 | 216 |
217 while (count--) | 217 while (count--) |
218 { | 218 { |
219 *(out++) = (*(in++) * 256) - 32768; | 219 *(out++) = (*(in++) * 256) - 32768; |
220 } | 220 } |
221 | 221 |
222 return DMERR_OK; | 222 return DMERR_OK; |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 /* Converts the given module in preparation for playing it. | 226 /* Converts the given module in preparation for playing it. |
253 inst->flags |= jsf16bit; | 253 inst->flags |= jsf16bit; |
254 dmFree(inst->data); | 254 dmFree(inst->data); |
255 inst->data = data; | 255 inst->data = data; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 return DMERR_OK; | 259 return DMERR_OK; |
260 } | 260 } |
261 | 261 |
262 | 262 |
263 /* Allocates a new module structure or returns errorvalue if failed. | 263 /* Allocates a new module structure or returns errorvalue if failed. |
297 { | 297 { |
298 int i; | 298 int i; |
299 | 299 |
300 if (module == NULL) | 300 if (module == NULL) |
301 return DMERR_NULLPTR; | 301 return DMERR_NULLPTR; |
302 | 302 |
303 // Free strings | 303 // Free strings |
304 #ifndef JSS_LIGHT | 304 #ifndef JSS_LIGHT |
305 dmFree(module->moduleName); | 305 dmFree(module->moduleName); |
306 dmFree(module->trackerName); | 306 dmFree(module->trackerName); |
307 #endif | 307 #endif |
358 | 358 |
359 // Free mutex | 359 // Free mutex |
360 #ifdef JSS_SUP_THREADS | 360 #ifdef JSS_SUP_THREADS |
361 dmDestroyMutex(module->mutex); | 361 dmDestroyMutex(module->mutex); |
362 #endif | 362 #endif |
363 | 363 |
364 // Free the module structure | 364 // Free the module structure |
365 memset(module, 0, sizeof(JSSModule)); | 365 memset(module, 0, sizeof(JSSModule)); |
366 dmFree(module); | 366 dmFree(module); |
367 | 367 |
368 return DMERR_OK; | 368 return DMERR_OK; |
445 | 445 |
446 for (i = 0; i < jsetNNotes; i++) | 446 for (i = 0; i < jsetNNotes; i++) |
447 { | 447 { |
448 res->sNumForNotes[i] = jsetNotSet; | 448 res->sNumForNotes[i] = jsetNotSet; |
449 } | 449 } |
450 | 450 |
451 return res; | 451 return res; |
452 } | 452 } |