comparison jssmod.c @ 56:8725853609db

Remove the floating point mixing .. it wasn't so good idea after all.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 06:59:00 +0300
parents 36e2f910219c
children a17e54015bd9
comparison
equal deleted inserted replaced
55:e0e470c3fc8e 56:8725853609db
195 } 195 }
196 } 196 }
197 return TRUE; 197 return TRUE;
198 } 198 }
199 199
200 #ifdef JSS_MIX_FP
201 /* Convert sample data from S16 or U8 to floating point
202 */
203 int jssConvertSampleToFP(void **dst, void * src, const size_t len, const int flags)
204 {
205 size_t count = len;
206 float *out;
207
208 *dst = out = dmMalloc(sizeof(float) * len);
209 if (out == NULL)
210 return DMERR_MALLOC;
211
212 if (flags & jsf16bit)
213 {
214 Sint16 *in = (Sint16 *) src;
215 while (count--)
216 {
217 *(out++) = (float) (*(in++)) / 32768.0f;
218 }
219 }
220 else
221 {
222 Uint8 *in = (Uint8 *) src;
223 while (count--)
224 {
225 *(out++) = ((float) *(in++) - 128.0f) / 56.0f;
226 }
227 }
228
229 return DMERR_OK;
230 }
231
232 #endif
233 200
234 /* Convert sample data from U8 to S16 201 /* Convert sample data from U8 to S16
235 */ 202 */
236 int jssConvertSampleTo16(void **dst, void * src, const size_t len) 203 int jssConvertSampleTo16(void **dst, void * src, const size_t len)
237 { 204 {
250 217
251 return DMERR_OK; 218 return DMERR_OK;
252 } 219 }
253 220
254 /* Converts the given module in preparation for playing it. 221 /* Converts the given module in preparation for playing it.
255 * This involves sample format conversion (8 to 16 bit, or 222 * This involves sample format conversion (8 to 16 bit, etc.)
256 * if floating point mixing is enabled, 8/16 bit to FP.)
257 * 223 *
258 * NOTICE! The converted module can only be saved in JSSMOD 224 * NOTICE! The converted module can only be saved in JSSMOD
259 * format, but this is not recommended. 225 * format, but this is not recommended.
260 */ 226 */
261 int jssConvertModuleForPlaying(JSSModule *module) 227 int jssConvertModuleForPlaying(JSSModule *module)
270 JSSInstrument *inst = module->instruments[i]; 236 JSSInstrument *inst = module->instruments[i];
271 if (inst != NULL && inst->data != NULL) 237 if (inst != NULL && inst->data != NULL)
272 { 238 {
273 int res; 239 int res;
274 void *data = NULL; 240 void *data = NULL;
275 #ifdef JSS_MIX_FP 241
276 if (inst->flags & jsfFP)
277 continue;
278
279 if ((res = jssConvertSampleToFP(&data, inst->data, inst->size, inst->flags)) != DMERR_OK)
280 return res;
281
282 inst->flags &= !(jsf16bit);
283 inst->flags |= jsfFP;
284 #else
285 if (inst->flags & jsf16bit) 242 if (inst->flags & jsf16bit)
286 continue; 243 continue;
287 244
288 if ((res = jssConvertSampleTo16(&data, inst->data, inst->size)) != DMERR_OK) 245 if ((res = jssConvertSampleTo16(&data, inst->data, inst->size)) != DMERR_OK)
289 return res; 246 return res;
290 247
291 inst->flags |= jsf16bit; 248 inst->flags |= jsf16bit;
292 #endif
293 dmFree(inst->data); 249 dmFree(inst->data);
294 inst->data = data; 250 inst->data = data;
295 } 251 }
296 } 252 }
297 253