Mercurial > hg > xmms-sid
comparison src/xs_sidplay2.cc @ 795:3e305ce076e8
Make old libSIDPlay2 support work again, the one available in most distros, such as Debian.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Nov 2012 11:05:24 +0200 |
parents | 0995fa233462 |
children | c83c08b2ede4 |
comparison
equal
deleted
inserted
replaced
794:3012740d014c | 795:3e305ce076e8 |
---|---|
33 # include <sidplayfp/sidplay2.h> | 33 # include <sidplayfp/sidplay2.h> |
34 # include <sidplayfp/SidTuneMod.h> | 34 # include <sidplayfp/SidTuneMod.h> |
35 # include <sidplayfp/event.h> | 35 # include <sidplayfp/event.h> |
36 #else | 36 #else |
37 # include <sidplay/sidplay2.h> | 37 # include <sidplay/sidplay2.h> |
38 # include <sidplay/sidlazyiptr.h> | |
39 # if G_BYTE_ORDER == G_BIG_ENDIAN | 38 # if G_BYTE_ORDER == G_BIG_ENDIAN |
40 # define SID2_NATIVE_UNSIGNED SID2_BIG_UNSIGNED | 39 # define SID2_NATIVE_UNSIGNED SID2_BIG_UNSIGNED |
41 # define SID2_NATIVE_SIGNED SID2_BIG_SIGNED | 40 # define SID2_NATIVE_SIGNED SID2_BIG_SIGNED |
42 # elif G_BYTE_ORDER == G_LITTLE_ENDIAN | 41 # elif G_BYTE_ORDER == G_LITTLE_ENDIAN |
43 # define SID2_NATIVE_UNSIGNED SID2_LITTLE_UNSIGNED | 42 # define SID2_NATIVE_UNSIGNED SID2_LITTLE_UNSIGNED |
48 #endif | 47 #endif |
49 | 48 |
50 | 49 |
51 class XSSIDPlay2 { | 50 class XSSIDPlay2 { |
52 public: | 51 public: |
53 #ifdef HAVE_SIDPLAY2_FP | |
54 sidplay2 emu; | 52 sidplay2 emu; |
55 #else | |
56 SidIPtr<ISidplay2> emu; | |
57 #endif | |
58 sid2_config_t config; | 53 sid2_config_t config; |
59 SidTune *tune; | 54 SidTune *tune; |
55 gboolean tuneLoaded; | |
60 | 56 |
61 XSSIDPlay2(void); | 57 XSSIDPlay2(void); |
62 virtual ~XSSIDPlay2(void) { ; } | 58 virtual ~XSSIDPlay2(void); |
63 }; | 59 }; |
64 | 60 |
65 | 61 |
66 #ifdef HAVE_RESID_BUILDER | 62 #ifdef HAVE_RESID_BUILDER |
67 # ifdef HAVE_SIDPLAY2_FP | 63 # ifdef HAVE_SIDPLAY2_FP |
82 | 78 |
83 | 79 |
84 XSSIDPlay2::XSSIDPlay2(void) | 80 XSSIDPlay2::XSSIDPlay2(void) |
85 { | 81 { |
86 tune = NULL; | 82 tune = NULL; |
83 } | |
84 | |
85 | |
86 XSSIDPlay2::~XSSIDPlay2(void) | |
87 { | |
88 if (tune) | |
89 delete tune; | |
90 | |
91 tuneLoaded = FALSE; | |
87 } | 92 } |
88 | 93 |
89 | 94 |
90 /* We need to 'export' all this pseudo-C++ crap */ | 95 /* We need to 'export' all this pseudo-C++ crap */ |
91 extern "C" { | 96 extern "C" { |
259 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids); | 264 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids); |
260 | 265 |
261 switch (xs_cfg.sid2Builder) | 266 switch (xs_cfg.sid2Builder) |
262 { | 267 { |
263 #ifdef HAVE_RESID_BUILDER | 268 #ifdef HAVE_RESID_BUILDER |
264 #ifdef HAVE_SIDPLAY2_FP | |
265 case XS_BLD_RESID: | 269 case XS_BLD_RESID: |
266 { | 270 { |
267 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder"); | 271 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder"); |
268 if (rs) | 272 if (rs) |
269 { | 273 { |
270 engine->config.sidEmulation = rs; | 274 engine->config.sidEmulation = rs; |
271 if (!*rs) return FALSE; | 275 if (!*rs) return FALSE; |
272 rs->create((engine->emu.info()).maxsids); | 276 rs->create((engine->emu.info()).maxsids); |
273 if (!*rs) return FALSE; | 277 if (!*rs) return FALSE; |
278 #ifdef HAVE_SIDPLAY2_FP | |
274 rs->bias(0.0f); | 279 rs->bias(0.0f); |
280 #endif | |
275 } | 281 } |
276 } | 282 } |
277 break; | 283 break; |
278 | 284 #endif |
285 | |
286 #ifdef HAVE_RESID_FP_BUILDER | |
279 case XS_BLD_RESID_FP: | 287 case XS_BLD_RESID_FP: |
280 { | 288 { |
281 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!"); | 289 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!"); |
282 if (rs) | 290 if (rs) |
283 { | 291 { |
284 engine->config.sidEmulation = rs; | 292 engine->config.sidEmulation = rs; |
285 if (!*rs) return FALSE; | 293 if (!*rs) return FALSE; |
286 rs->create((engine->emu.info()).maxsids); | 294 rs->create((engine->emu.info()).maxsids); |
287 if (!*rs) return FALSE; | 295 if (!*rs) return FALSE; |
288 | 296 |
289 /* | 297 rs->filter6581Curve(0.0); |
290 if (m_filter.filterCurve6581) | 298 rs->filter8580Curve(0.0); |
291 rs->filter6581Curve(m_filter.filterCurve6581); | |
292 if (m_filter.filterCurve8580) | |
293 rs->filter8580Curve((double)m_filter.filterCurve8580); | |
294 */ | |
295 } | 299 } |
296 } | 300 } |
297 break; | 301 break; |
298 #else | |
299 case XS_BLD_RESID: | |
300 { | |
301 engine->config.sidEmulation = ReSIDBuilderCreate("ReSID builder"); | |
302 SidLazyIPtr<IReSIDBuilder> rs(engine->config.sidEmulation); | |
303 if (rs) | |
304 { | |
305 engine->config.sidEmulation = rs->iaggregate(); | |
306 rs->create((engine->emu.info()).maxsids); | |
307 if (!*rs) return FALSE; | |
308 } | |
309 } | |
310 break; | |
311 #endif | |
312 #endif | 302 #endif |
313 | 303 |
314 #ifdef HAVE_HARDSID_BUILDER | 304 #ifdef HAVE_HARDSID_BUILDER |
315 case XS_BLD_HARDSID: | 305 case XS_BLD_HARDSID: |
316 #ifdef HAVE_SIDPLAY2_FP | |
317 { | 306 { |
318 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); | 307 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); |
319 engine->config.sidEmulation = (sidbuilder *) hs; | 308 engine->config.sidEmulation = (sidbuilder *) hs; |
320 if (hs) | 309 if (hs) |
321 { | 310 { |
322 #else | |
323 engine->config.sidEmulation = HardSIDBuilderCreate("HardSID builder"); | |
324 SidLazyIPtr<IHardSIDBuilder> hs(engine->config.sidEmulation); | |
325 if (hs) | |
326 { | |
327 engine->config.sidEmulation = hs->iaggregate(); | |
328 #endif | |
329 /* Builder object created, initialize it */ | |
330 hs->create((engine->emu.info()).maxsids); | 311 hs->create((engine->emu.info()).maxsids); |
331 if (!*hs) | 312 if (!*hs) |
332 { | 313 { |
333 xs_error("hardSID->create() failed.\n"); | 314 xs_error("hardSID->create() failed.\n"); |
334 return FALSE; | 315 return FALSE; |
347 { | 328 { |
348 xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); | 329 xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); |
349 return FALSE; | 330 return FALSE; |
350 } | 331 } |
351 | 332 |
333 #ifdef HAVE_SIDPLAY2_FP | |
352 // Setup filter | 334 // Setup filter |
353 engine->config.sidEmulation->filter(xs_cfg.emulateFilters); | 335 engine->config.sidEmulation->filter(xs_cfg.emulateFilters); |
354 if (!*(engine->config.sidEmulation)) | 336 if (!*(engine->config.sidEmulation)) |
355 { | 337 { |
356 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); | 338 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); |
357 return FALSE; | 339 return FALSE; |
358 } | 340 } |
359 | 341 #endif |
360 #ifdef HAVE_SIDPLAY2_FP | 342 |
361 engine->config.sidEmulation = engine->config.sidEmulation; | |
362 XSDEBUG("%s\n", engine->config.sidEmulation->credits()); | 343 XSDEBUG("%s\n", engine->config.sidEmulation->credits()); |
363 #endif | |
364 | 344 |
365 /* Clockspeed settings */ | 345 /* Clockspeed settings */ |
366 switch (xs_cfg.clockSpeed) | 346 switch (xs_cfg.clockSpeed) |
367 { | 347 { |
368 case XS_CLOCK_NTSC: | 348 case XS_CLOCK_NTSC: |
403 | 383 |
404 engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581; | 384 engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581; |
405 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; | 385 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; |
406 engine->config.sidSamples = TRUE; | 386 engine->config.sidSamples = TRUE; |
407 | 387 |
408 /* Now set the emulator configuration */ | |
409 if (engine->emu.config(engine->config) < 0) | |
410 { | |
411 xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); | |
412 return FALSE; | |
413 } | |
414 | |
415 return TRUE; | 388 return TRUE; |
416 } | 389 } |
417 | 390 |
418 | 391 |
419 /* Close SIDPlay2 engine | 392 /* Close SIDPlay2 engine |
424 | 397 |
425 xs_sidplay2_delete(state); | 398 xs_sidplay2_delete(state); |
426 | 399 |
427 if (engine) | 400 if (engine) |
428 { | 401 { |
429 #ifdef HAVE_SIDPLAY2_FP | |
430 if (engine->config.sidEmulation) | |
431 { | |
432 sidbuilder *builder = engine->config.sidEmulation; | |
433 engine->config.sidEmulation = NULL; | |
434 engine->emu.config(engine->config); | |
435 delete builder; | |
436 } | |
437 #endif | |
438 | |
439 delete engine; | 402 delete engine; |
440 engine = NULL; | 403 engine = NULL; |
441 } | 404 } |
442 | 405 |
443 state->internal = NULL; | 406 state->internal = NULL; |
457 { | 420 { |
458 xs_error("[SIDPlay2] tune->selectSong() failed\n"); | 421 xs_error("[SIDPlay2] tune->selectSong() failed\n"); |
459 return FALSE; | 422 return FALSE; |
460 } | 423 } |
461 | 424 |
425 if (engine->emu.config(engine->config) < 0) | |
426 { | |
427 xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); | |
428 return FALSE; | |
429 } | |
430 | |
431 engine->tuneLoaded = TRUE; | |
462 if (engine->emu.load(engine->tune) < 0) | 432 if (engine->emu.load(engine->tune) < 0) |
463 { | 433 { |
464 xs_error("[SIDPlay2] emu.load() failed\n"); | 434 xs_error("[SIDPlay2] emu.load() failed\n"); |
465 return FALSE; | 435 return FALSE; |
466 } | 436 } |
467 | 437 |
468 return TRUE; | 438 return TRUE; |
469 } | 439 } |
470 | 440 |
471 | 441 |
472 /* Emulate and render audio data to given buffer | 442 /* Emulate and render audio data to given buffer |
476 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; | 446 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; |
477 | 447 |
478 if (!engine) | 448 if (!engine) |
479 return 0; | 449 return 0; |
480 | 450 |
481 int len = audioBufSize / sizeof(short); | 451 #if 1 |
482 if (len > 512) len = 512; | 452 #ifdef HAVE_SIDPLAY2_FP |
483 return engine->emu.play((short *) audioBuffer, len) * sizeof(short); | 453 int nsamples = audioBufSize / sizeof(short); |
454 return engine->emu.play((short *) audioBuffer, nsamples) * sizeof(short); | |
455 #else | |
456 return engine->emu.play(audioBuffer, audioBufSize); | |
457 #endif | |
458 #else | |
459 int nsamples = audioBufSize / sizeof(short); | |
460 fprintf(stderr, "%p, %d -> %d\n", audioBuffer, audioBufSize, nsamples); | |
461 return 0; | |
462 #endif | |
484 } | 463 } |
485 | 464 |
486 | 465 |
487 /* Load a given SID-tune file | 466 /* Load a given SID-tune file |
488 */ | 467 */ |
490 { | 469 { |
491 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; | 470 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; |
492 | 471 |
493 if (!engine) | 472 if (!engine) |
494 return FALSE; | 473 return FALSE; |
495 | 474 |
496 if (!(engine->tune = new SidTune(filename))) | 475 if (!(engine->tune = new SidTune(filename))) |
497 return FALSE; | 476 return FALSE; |
477 | |
478 engine->tuneLoaded = FALSE; | |
498 | 479 |
499 return TRUE; | 480 return TRUE; |
500 } | 481 } |
501 | 482 |
502 | 483 |
506 { | 487 { |
507 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; | 488 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; |
508 | 489 |
509 if (engine) | 490 if (engine) |
510 { | 491 { |
511 if (engine->tune) | 492 if (engine->tuneLoaded) |
512 { | 493 { |
513 delete engine->tune; | 494 engine->emu.load(0); |
514 engine->tune = NULL; | |
515 } | 495 } |
496 | |
497 delete engine->tune; | |
498 engine->tune = NULL; | |
499 engine->tuneLoaded = FALSE; | |
516 } | 500 } |
517 } | 501 } |
518 | 502 |
519 | 503 |
520 /* Hardware backend flushing | 504 /* Hardware backend flushing |