Mercurial > hg > xmms-sid
comparison src/xs_sidplay2.cc @ 657:acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 02 Apr 2008 19:46:59 +0300 |
parents | fdddab8f0c1b |
children | b0743dc9165d |
comparison
equal
deleted
inserted
replaced
656:e9257f006f41 | 657:acaba070cf49 |
---|---|
43 sidbuilder *currBuilder; | 43 sidbuilder *currBuilder; |
44 sid2_config_t currConfig; | 44 sid2_config_t currConfig; |
45 SidTune *currTune; | 45 SidTune *currTune; |
46 guint8 *buf; | 46 guint8 *buf; |
47 size_t bufSize; | 47 size_t bufSize; |
48 } t_xs_sidplay2; | 48 } xs_sidplay2_t; |
49 | 49 |
50 | 50 |
51 /* We need to 'export' all this pseudo-C++ crap */ | 51 /* We need to 'export' all this pseudo-C++ crap */ |
52 extern "C" { | 52 extern "C" { |
53 | 53 |
56 */ | 56 */ |
57 #define TFUNCTION xs_sidplay2_getinfo | 57 #define TFUNCTION xs_sidplay2_getinfo |
58 #define TFUNCTION2 xs_sidplay2_updateinfo | 58 #define TFUNCTION2 xs_sidplay2_updateinfo |
59 #define TTUNEINFO SidTuneInfo | 59 #define TTUNEINFO SidTuneInfo |
60 #define TTUNE SidTune | 60 #define TTUNE SidTune |
61 #define TENGINE t_xs_sidplay2 | 61 #define TENGINE xs_sidplay2_t |
62 #include "xs_sidplay.h" | 62 #include "xs_sidplay.h" |
63 | 63 |
64 | 64 |
65 /* Check if we can play the given file | 65 /* Check if we can play the given file |
66 */ | 66 */ |
67 gboolean xs_sidplay2_probe(t_xs_file *f) | 67 gboolean xs_sidplay2_probe(xs_file_t *f) |
68 { | 68 { |
69 gchar tmpBuf[4]; | 69 gchar tmpBuf[4]; |
70 | 70 |
71 if (!f) return FALSE; | 71 if (!f) return FALSE; |
72 | 72 |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 /* Initialize SIDPlay2 | 83 /* Initialize SIDPlay2 |
84 */ | 84 */ |
85 gboolean xs_sidplay2_init(t_xs_status * myStatus) | 85 gboolean xs_sidplay2_init(xs_status_t * myStatus) |
86 { | 86 { |
87 gint tmpFreq, i; | 87 gint tmpFreq, i; |
88 t_xs_sidplay2 *myEngine; | 88 xs_sidplay2_t *myEngine; |
89 sid_filter_t tmpFilter; | 89 sid_filter_t tmpFilter; |
90 t_xs_sid2_filter *f; | 90 t_xs_sid2_filter *f; |
91 assert(myStatus); | 91 assert(myStatus); |
92 | 92 |
93 /* Allocate internal structures */ | 93 /* Allocate internal structures */ |
94 myEngine = (t_xs_sidplay2 *) g_malloc0(sizeof(t_xs_sidplay2)); | 94 myEngine = (xs_sidplay2_t *) g_malloc0(sizeof(xs_sidplay2_t)); |
95 myStatus->sidEngine = myEngine; | 95 myStatus->sidEngine = myEngine; |
96 if (!myEngine) return FALSE; | 96 if (!myEngine) return FALSE; |
97 | 97 |
98 /* Initialize the engine */ | 98 /* Initialize the engine */ |
99 myEngine->currEng = new sidplay2; | 99 myEngine->currEng = new sidplay2; |
100 if (!myEngine->currEng) { | 100 if (!myEngine->currEng) { |
101 xs_error(_("[SIDPlay2] Could not initialize emulation engine.\n")); | 101 xs_error("[SIDPlay2] Could not initialize emulation engine.\n"); |
102 return FALSE; | 102 return FALSE; |
103 } | 103 } |
104 | 104 |
105 /* Get current configuration */ | 105 /* Get current configuration */ |
106 myEngine->currConfig = myEngine->currEng->config(); | 106 myEngine->currConfig = myEngine->currEng->config(); |
171 case FMT_U16_BE: | 171 case FMT_U16_BE: |
172 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED; | 172 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED; |
173 break; | 173 break; |
174 | 174 |
175 case FMT_U16_NE: | 175 case FMT_U16_NE: |
176 #ifdef WORDS_BIGENDIAN | 176 #if G_BYTE_ORDER == G_BIG_ENDIAN |
177 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED; | 177 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED; |
178 #else | 178 #else |
179 #if G_BYTE_ORDER == G_LITTLE_ENDIAN | |
179 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED; | 180 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED; |
181 #else | |
182 #error Unsupported endianess! | |
183 #endif | |
180 #endif | 184 #endif |
181 break; | 185 break; |
182 | 186 |
183 case FMT_S16_LE: | 187 case FMT_S16_LE: |
184 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED; | 188 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED; |
188 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED; | 192 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED; |
189 break; | 193 break; |
190 | 194 |
191 default: | 195 default: |
192 myStatus->audioFormat = FMT_S16_NE; | 196 myStatus->audioFormat = FMT_S16_NE; |
193 #ifdef WORDS_BIGENDIAN | 197 #if G_BYTE_ORDER == G_BIG_ENDIAN |
194 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED; | 198 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED; |
195 #else | 199 #else |
200 #if G_BYTE_ORDER == G_LITTLE_ENDIAN | |
196 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED; | 201 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED; |
202 #else | |
203 #error Unsupported endianess! | |
204 #endif | |
197 #endif | 205 #endif |
198 break; | 206 break; |
199 | 207 |
200 } | 208 } |
201 break; | 209 break; |
203 | 211 |
204 /* Convert filter */ | 212 /* Convert filter */ |
205 f = &(xs_cfg.sid2Filter); | 213 f = &(xs_cfg.sid2Filter); |
206 XSDEBUG("using filter '%s', %d points\n", f->name, f->npoints); | 214 XSDEBUG("using filter '%s', %d points\n", f->name, f->npoints); |
207 if (f->npoints > XS_SIDPLAY2_NFPOINTS) { | 215 if (f->npoints > XS_SIDPLAY2_NFPOINTS) { |
208 xs_error(_("[SIDPlay2] Invalid number of filter curve points (%d > %d)\n"), | 216 xs_error("[SIDPlay2] Invalid number of filter curve points (%d > %d)\n", |
209 f->npoints, XS_SIDPLAY2_NFPOINTS); | 217 f->npoints, XS_SIDPLAY2_NFPOINTS); |
210 f->npoints = XS_SIDPLAY2_NFPOINTS; | 218 f->npoints = XS_SIDPLAY2_NFPOINTS; |
211 } | 219 } |
212 | 220 |
213 tmpFilter.points = f->npoints; | 221 tmpFilter.points = f->npoints; |
224 myEngine->currBuilder = (sidbuilder *) rs; | 232 myEngine->currBuilder = (sidbuilder *) rs; |
225 if (rs) { | 233 if (rs) { |
226 /* Builder object created, initialize it */ | 234 /* Builder object created, initialize it */ |
227 rs->create((myEngine->currEng->info()).maxsids); | 235 rs->create((myEngine->currEng->info()).maxsids); |
228 if (!*rs) { | 236 if (!*rs) { |
229 xs_error(_("reSID->create() failed.\n")); | 237 xs_error("reSID->create() failed.\n"); |
230 return FALSE; | 238 return FALSE; |
231 } | 239 } |
232 | 240 |
233 rs->filter(xs_cfg.emulateFilters); | 241 rs->filter(xs_cfg.emulateFilters); |
234 if (!*rs) { | 242 if (!*rs) { |
235 xs_error(_("reSID->filter(%d) failed.\n"), xs_cfg.emulateFilters); | 243 xs_error("reSID->filter(%d) failed.\n", xs_cfg.emulateFilters); |
236 return FALSE; | 244 return FALSE; |
237 } | 245 } |
238 | 246 |
239 // FIXME FIX ME: support other configurable parameters ... | 247 // FIXME FIX ME: support other configurable parameters ... |
240 // ... WHEN/IF resid-builder+libsidplay2 gets fixed | 248 // ... WHEN/IF resid-builder+libsidplay2 gets fixed |
241 rs->sampling(tmpFreq); | 249 rs->sampling(tmpFreq); |
242 if (!*rs) { | 250 if (!*rs) { |
243 xs_error(_("reSID->sampling(%d) failed.\n"), tmpFreq); | 251 xs_error("reSID->sampling(%d) failed.\n", tmpFreq); |
244 return FALSE; | 252 return FALSE; |
245 } | 253 } |
246 | 254 |
247 if (tmpFilter.points > 0) | 255 if (tmpFilter.points > 0) |
248 rs->filter((sid_filter_t *) &tmpFilter); | 256 rs->filter((sid_filter_t *) &tmpFilter); |
249 else | 257 else |
250 rs->filter((sid_filter_t *) NULL); | 258 rs->filter((sid_filter_t *) NULL); |
251 | 259 |
252 if (!*rs) { | 260 if (!*rs) { |
253 xs_error(_("reSID->filter(NULL) failed.\n")); | 261 xs_error("reSID->filter(NULL) failed.\n"); |
254 return FALSE; | 262 return FALSE; |
255 } | 263 } |
256 } | 264 } |
257 } | 265 } |
258 #endif | 266 #endif |
262 myEngine->currBuilder = (sidbuilder *) hs; | 270 myEngine->currBuilder = (sidbuilder *) hs; |
263 if (hs) { | 271 if (hs) { |
264 /* Builder object created, initialize it */ | 272 /* Builder object created, initialize it */ |
265 hs->create((myEngine->currEng->info()).maxsids); | 273 hs->create((myEngine->currEng->info()).maxsids); |
266 if (!*hs) { | 274 if (!*hs) { |
267 xs_error(_("hardSID->create() failed.\n")); | 275 xs_error("hardSID->create() failed.\n"); |
268 return FALSE; | 276 return FALSE; |
269 } | 277 } |
270 | 278 |
271 hs->filter(xs_cfg.emulateFilters); | 279 hs->filter(xs_cfg.emulateFilters); |
272 if (!*hs) { | 280 if (!*hs) { |
273 xs_error(_("hardSID->filter(%d) failed.\n"), xs_cfg.emulateFilters); | 281 xs_error("hardSID->filter(%d) failed.\n", xs_cfg.emulateFilters); |
274 return FALSE; | 282 return FALSE; |
275 } | 283 } |
276 } | 284 } |
277 } | 285 } |
278 #endif | 286 #endif |
279 | 287 |
280 if (!myEngine->currBuilder) { | 288 if (!myEngine->currBuilder) { |
281 xs_error(_("[SIDPlay2] Could not initialize SIDBuilder object.\n")); | 289 xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); |
282 return FALSE; | 290 return FALSE; |
283 } | 291 } |
284 | 292 |
285 XSDEBUG("%s\n", myEngine->currBuilder->credits()); | 293 XSDEBUG("%s\n", myEngine->currBuilder->credits()); |
286 | 294 |
290 case XS_CLOCK_NTSC: | 298 case XS_CLOCK_NTSC: |
291 myEngine->currConfig.clockDefault = SID2_CLOCK_NTSC; | 299 myEngine->currConfig.clockDefault = SID2_CLOCK_NTSC; |
292 break; | 300 break; |
293 | 301 |
294 default: | 302 default: |
295 xs_error(_("[SIDPlay2] Invalid clockSpeed=%d, falling back to PAL.\n"), | 303 xs_error("[SIDPlay2] Invalid clockSpeed=%d, falling back to PAL.\n", |
296 xs_cfg.clockSpeed); | 304 xs_cfg.clockSpeed); |
297 | 305 |
298 case XS_CLOCK_PAL: | 306 case XS_CLOCK_PAL: |
299 myEngine->currConfig.clockDefault = SID2_CLOCK_PAL; | 307 myEngine->currConfig.clockDefault = SID2_CLOCK_PAL; |
300 xs_cfg.clockSpeed = XS_CLOCK_PAL; | 308 xs_cfg.clockSpeed = XS_CLOCK_PAL; |
314 } | 322 } |
315 | 323 |
316 if ((xs_cfg.sid2OptLevel >= 0) && (xs_cfg.sid2OptLevel <= SID2_MAX_OPTIMISATION)) | 324 if ((xs_cfg.sid2OptLevel >= 0) && (xs_cfg.sid2OptLevel <= SID2_MAX_OPTIMISATION)) |
317 myEngine->currConfig.optimisation = xs_cfg.sid2OptLevel; | 325 myEngine->currConfig.optimisation = xs_cfg.sid2OptLevel; |
318 else { | 326 else { |
319 xs_error(_("Invalid sid2OptLevel=%d, falling back to %d.\n"), | 327 xs_error("Invalid sid2OptLevel=%d, falling back to %d.\n", |
320 xs_cfg.sid2OptLevel, SID2_DEFAULT_OPTIMISATION); | 328 xs_cfg.sid2OptLevel, SID2_DEFAULT_OPTIMISATION); |
321 | 329 |
322 xs_cfg.sid2OptLevel = | 330 xs_cfg.sid2OptLevel = |
323 myEngine->currConfig.optimisation = SID2_DEFAULT_OPTIMISATION; | 331 myEngine->currConfig.optimisation = SID2_DEFAULT_OPTIMISATION; |
324 } | 332 } |
338 myEngine->currConfig.sidSamples = TRUE; | 346 myEngine->currConfig.sidSamples = TRUE; |
339 | 347 |
340 | 348 |
341 /* Now set the emulator configuration */ | 349 /* Now set the emulator configuration */ |
342 if (myEngine->currEng->config(myEngine->currConfig) < 0) { | 350 if (myEngine->currEng->config(myEngine->currConfig) < 0) { |
343 xs_error(_("[SIDPlay2] Emulator engine configuration failed!\n")); | 351 xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); |
344 return FALSE; | 352 return FALSE; |
345 } | 353 } |
346 | 354 |
347 /* Create the sidtune */ | 355 /* Create the sidtune */ |
348 myEngine->currTune = new SidTune(0); | 356 myEngine->currTune = new SidTune(0); |
349 if (!myEngine->currTune) { | 357 if (!myEngine->currTune) { |
350 xs_error(_("[SIDPlay2] Could not initialize SIDTune object.\n")); | 358 xs_error("[SIDPlay2] Could not initialize SIDTune object.\n"); |
351 return FALSE; | 359 return FALSE; |
352 } | 360 } |
353 | 361 |
354 return TRUE; | 362 return TRUE; |
355 } | 363 } |
356 | 364 |
357 | 365 |
358 /* Close SIDPlay2 engine | 366 /* Close SIDPlay2 engine |
359 */ | 367 */ |
360 void xs_sidplay2_close(t_xs_status * myStatus) | 368 void xs_sidplay2_close(xs_status_t * myStatus) |
361 { | 369 { |
362 t_xs_sidplay2 *myEngine; | 370 xs_sidplay2_t *myEngine; |
363 assert(myStatus); | 371 assert(myStatus); |
364 | 372 |
365 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; | 373 myEngine = (xs_sidplay2_t *) myStatus->sidEngine; |
366 | 374 |
367 /* Free internals */ | 375 /* Free internals */ |
368 if (myEngine->currBuilder) { | 376 if (myEngine->currBuilder) { |
369 delete myEngine->currBuilder; | 377 delete myEngine->currBuilder; |
370 myEngine->currBuilder = NULL; | 378 myEngine->currBuilder = NULL; |
387 } | 395 } |
388 | 396 |
389 | 397 |
390 /* Initialize current song and sub-tune | 398 /* Initialize current song and sub-tune |
391 */ | 399 */ |
392 gboolean xs_sidplay2_initsong(t_xs_status * myStatus) | 400 gboolean xs_sidplay2_initsong(xs_status_t * myStatus) |
393 { | 401 { |
394 t_xs_sidplay2 *myEngine; | 402 xs_sidplay2_t *myEngine; |
395 assert(myStatus); | 403 assert(myStatus); |
396 | 404 |
397 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; | 405 myEngine = (xs_sidplay2_t *) myStatus->sidEngine; |
398 if (!myEngine) return FALSE; | 406 if (!myEngine) return FALSE; |
399 | 407 |
400 if (!myEngine->currTune->selectSong(myStatus->currSong)) { | 408 if (!myEngine->currTune->selectSong(myStatus->currSong)) { |
401 xs_error(_("[SIDPlay2] currTune->selectSong() failed\n")); | 409 xs_error("[SIDPlay2] currTune->selectSong() failed\n"); |
402 return FALSE; | 410 return FALSE; |
403 } | 411 } |
404 | 412 |
405 if (myEngine->currEng->load(myEngine->currTune) < 0) { | 413 if (myEngine->currEng->load(myEngine->currTune) < 0) { |
406 xs_error(_("[SIDPlay2] currEng->load() failed\n")); | 414 xs_error("[SIDPlay2] currEng->load() failed\n"); |
407 return FALSE; | 415 return FALSE; |
408 } | 416 } |
409 | 417 |
410 myStatus->isInitialized = TRUE; | 418 myStatus->isInitialized = TRUE; |
411 | 419 |
413 } | 421 } |
414 | 422 |
415 | 423 |
416 /* Emulate and render audio data to given buffer | 424 /* Emulate and render audio data to given buffer |
417 */ | 425 */ |
418 guint xs_sidplay2_fillbuffer(t_xs_status * myStatus, gchar * audioBuffer, guint audioBufSize) | 426 guint xs_sidplay2_fillbuffer(xs_status_t * myStatus, gchar * audioBuffer, guint audioBufSize) |
419 { | 427 { |
420 t_xs_sidplay2 *myEngine; | 428 xs_sidplay2_t *myEngine; |
421 assert(myStatus); | 429 assert(myStatus); |
422 | 430 |
423 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; | 431 myEngine = (xs_sidplay2_t *) myStatus->sidEngine; |
424 if (!myEngine) return 0; | 432 if (!myEngine) return 0; |
425 | 433 |
426 return myEngine->currEng->play(audioBuffer, audioBufSize); | 434 return myEngine->currEng->play(audioBuffer, audioBufSize); |
427 } | 435 } |
428 | 436 |
429 | 437 |
430 /* Load a given SID-tune file | 438 /* Load a given SID-tune file |
431 */ | 439 */ |
432 gboolean xs_sidplay2_load(t_xs_status * myStatus, gchar * pcFilename) | 440 gboolean xs_sidplay2_load(xs_status_t * myStatus, gchar * pcFilename) |
433 { | 441 { |
434 t_xs_sidplay2 *myEngine; | 442 xs_sidplay2_t *myEngine; |
435 assert(myStatus); | 443 assert(myStatus); |
436 myStatus->isInitialized = FALSE; | 444 myStatus->isInitialized = FALSE; |
437 | 445 |
438 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; | 446 myEngine = (xs_sidplay2_t *) myStatus->sidEngine; |
439 if (!myEngine) return FALSE; | 447 if (!myEngine) return FALSE; |
440 | 448 |
441 /* Try to get the tune */ | 449 /* Try to get the tune */ |
442 if (!pcFilename) return FALSE; | 450 if (!pcFilename) return FALSE; |
443 | 451 |
451 } | 459 } |
452 | 460 |
453 | 461 |
454 /* Delete INTERNAL information | 462 /* Delete INTERNAL information |
455 */ | 463 */ |
456 void xs_sidplay2_delete(t_xs_status * myStatus) | 464 void xs_sidplay2_delete(xs_status_t * myStatus) |
457 { | 465 { |
458 t_xs_sidplay2 *myEngine; | 466 xs_sidplay2_t *myEngine; |
459 assert(myStatus); | 467 assert(myStatus); |
460 | 468 |
461 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; | 469 myEngine = (xs_sidplay2_t *) myStatus->sidEngine; |
462 if (!myEngine) return; | 470 if (!myEngine) return; |
463 | 471 |
464 g_free(myEngine->buf); | 472 g_free(myEngine->buf); |
465 myEngine->buf = NULL; | 473 myEngine->buf = NULL; |
466 myEngine->bufSize = 0; | 474 myEngine->bufSize = 0; |
467 } | 475 } |
468 | 476 |
469 | 477 |
470 /* Hardware backend flushing | 478 /* Hardware backend flushing |
471 */ | 479 */ |
472 void xs_sidplay2_flush(t_xs_status * myStatus) | 480 void xs_sidplay2_flush(xs_status_t * myStatus) |
473 { | 481 { |
474 assert(myStatus); | 482 assert(myStatus); |
475 | 483 |
476 #ifdef HAVE_HARDSID_BUILDER | 484 #ifdef HAVE_HARDSID_BUILDER |
477 #ifdef HSID_SID2_COM | 485 #ifdef HSID_SID2_COM |