comparison src/xs_sidplayfp.cpp @ 862:011ba70e271e

Major cleanups, make SIDPlayFP backend compile with libSIDPlayFP v1.0.0 alphas .. does not work for some reason yet, though. (Only plays silence.)
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 02:11:21 +0200
parents 1f97cd026465
children fa926296e161
comparison
equal deleted inserted replaced
861:c6cf203be443 862:011ba70e271e
32 #ifdef HAVE_SIDPLAYFP_V1 32 #ifdef HAVE_SIDPLAYFP_V1
33 # include <sidplayfp/SidTune.h> 33 # include <sidplayfp/SidTune.h>
34 # include <sidplayfp/sidplayfp.h> 34 # include <sidplayfp/sidplayfp.h>
35 # include <sidplayfp/event.h> 35 # include <sidplayfp/event.h>
36 # include <sidplayfp/SidConfig.h> 36 # include <sidplayfp/SidConfig.h>
37 # include <sidplayfp/SidTuneInfo.h> 37 # include <sidplayfp/SidInfo.h>
38 #else 38 #else
39 # include <sidplayfp/sidplay2.h> 39 # include <sidplayfp/sidplay2.h>
40 # include <sidplayfp/SidTuneMod.h> 40 # include <sidplayfp/SidTuneMod.h>
41 # include <sidplayfp/event.h> 41 # include <sidplayfp/event.h>
42 #endif 42 #endif
49 SidConfig config; 49 SidConfig config;
50 #else 50 #else
51 sidplay2 emu; 51 sidplay2 emu;
52 sid2_config_t config; 52 sid2_config_t config;
53 #endif 53 #endif
54 SidTuneMod tune; 54 SidTune tune;
55 55
56 XSSIDPlayFP(void); 56 XSSIDPlayFP(void);
57 virtual ~XSSIDPlayFP(void); 57 virtual ~XSSIDPlayFP(void);
58 }; 58 };
59 59
71 #endif 71 #endif
72 72
73 73
74 XSSIDPlayFP::XSSIDPlayFP(void) : tune(0) 74 XSSIDPlayFP::XSSIDPlayFP(void) : tune(0)
75 { 75 {
76 emu.load(NULL);
76 } 77 }
77 78
78 79
79 XSSIDPlayFP::~XSSIDPlayFP(void) 80 XSSIDPlayFP::~XSSIDPlayFP(void)
80 { 81 {
86 extern "C" { 87 extern "C" {
87 88
88 89
89 /* Return song information 90 /* Return song information
90 */ 91 */
91 #define TFUNCTION xs_sidplayfp_getinfo
92 #define TFUNCTION2 xs_sidplayfp_updateinfo
93 #define TENGINE XSSIDPlayFP
94 #define TTUNEINFO SidTuneInfo
95 #define TTUNE SidTune
96
97 #ifdef HAVE_SIDPLAYFP_V1 92 #ifdef HAVE_SIDPLAYFP_V1
98 #define sid2_mono SidConfig::MONO 93 #define sid2_mono SidConfig::MONO
99 #define sid2_stereo SidConfig::STEREO 94 #define sid2_stereo SidConfig::STEREO
95
96 #define SID2_INTERPOLATE SidConfig::INTERPOLATE
97 #define SID2_RESAMPLE_INTERPOLATE SidConfig::RESAMPLE_INTERPOLATE
98
100 #define SID2_MOS8580 SidConfig::MOS8580 99 #define SID2_MOS8580 SidConfig::MOS8580
101 #define SID2_MOS6581 SidConfig::MOS6581 100 #define SID2_MOS6581 SidConfig::MOS6581
101
102 #define SID2_CLOCK_PAL SidConfig::CLOCK_PAL 102 #define SID2_CLOCK_PAL SidConfig::CLOCK_PAL
103 #define SID2_CLOCK_NTSC SidConfig::CLOCK_NTSC 103 #define SID2_CLOCK_NTSC SidConfig::CLOCK_NTSC
104
104 #define SIDTUNE_CLOCK_UNKNOWN SidTuneInfo::CLOCK_UNKNOWN 105 #define SIDTUNE_CLOCK_UNKNOWN SidTuneInfo::CLOCK_UNKNOWN
105 #define SIDTUNE_CLOCK_PAL SidTuneInfo::CLOCK_PAL 106 #define SIDTUNE_CLOCK_PAL SidTuneInfo::CLOCK_PAL
106 #define SIDTUNE_CLOCK_NTSC SidTuneInfo::CLOCK_NTSC 107 #define SIDTUNE_CLOCK_NTSC SidTuneInfo::CLOCK_NTSC
107 #define SIDTUNE_CLOCK_ANY SidTuneInfo::CLOCK_ANY 108 #define SIDTUNE_CLOCK_ANY SidTuneInfo::CLOCK_ANY
108 #define SIDTUNE_SPEED_VBI SidTuneInfo::SPEED_VBI 109 #define SIDTUNE_SPEED_VBI SidTuneInfo::SPEED_VBI
109 #define SIDTUNE_SPEED_CIA_1A SidTuneInfo::SPEED_CIA_1A 110 #define SIDTUNE_SPEED_CIA_1A SidTuneInfo::SPEED_CIA_1A
110 #endif 111 #endif
111 112
112 #include "xs_sidplay.h"
113
114 113
115 /* Check if we can play the given file 114 /* Check if we can play the given file
116 */ 115 */
117 gboolean xs_sidplayfp_probe(XSFile *f) 116 gboolean xs_sidplayfp_probe(XSFile *f)
118 { 117 {
179 178
180 #ifndef HAVE_SIDPLAYFP_V1 179 #ifndef HAVE_SIDPLAYFP_V1
181 engine->config.sidSamples = TRUE; 180 engine->config.sidSamples = TRUE;
182 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; 181 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT;
183 engine->config.clockSpeed = xs_cfg.forceSpeed ? engine->config.clockDefault : SID2_CLOCK_CORRECT; 182 engine->config.clockSpeed = xs_cfg.forceSpeed ? engine->config.clockDefault : SID2_CLOCK_CORRECT;
184 #endif
185 183
186 /* Initialize builder object */ 184 /* Initialize builder object */
187 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids); 185 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids);
186 #else
187 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids());
188 #endif
188 189
189 switch (xs_cfg.sid2Builder) 190 switch (xs_cfg.sid2Builder)
190 { 191 {
191 #ifdef HAVE_RESID_BUILDER 192 #ifdef HAVE_RESID_BUILDER
192 case XS_BLD_RESID: 193 case XS_BLD_RESID:
193 { 194 {
194 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder"); 195 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
195 #ifdef HAVE_SIDPLAYFP_V1 196 #ifdef HAVE_SIDPLAYFP_V1
196 if (rs && rs->getStatus()) 197 if (rs && rs->getStatus())
197 { 198 {
199 engine->config.sidEmulation = rs;
200 if (!rs->getStatus()) return FALSE;
201 rs->create((engine->emu.info()).maxsids());
202 if (!rs->getStatus()) return FALSE;
198 } 203 }
199 #else 204 #else
200 if (rs && *rs) 205 if (rs && *rs)
201 { 206 {
202 engine->config.sidEmulation = rs; 207 engine->config.sidEmulation = rs;
203 if (!(*rs)) return FALSE; 208 if (!*rs) return FALSE;
204 rs->create((engine->emu.info()).maxsids); 209 rs->create((engine->emu.info()).maxsids);
205 if (!(*rs)) return FALSE; 210 if (!*rs) return FALSE;
206 rs->bias(0.0f); 211 }
207 } 212 #endif
208 #endif // HAVE_SIDPLAYFP_V1 213 rs->bias(0.0f);
209 } 214 }
210 break; 215 break;
211 #endif // HAVE_RESID_BUILDER 216 #endif // HAVE_RESID_BUILDER
212 217
213 218
214 #ifdef HAVE_RESID_FP_BUILDER 219 #ifdef HAVE_RESID_FP_BUILDER
215 case XS_BLD_RESID_FP: 220 case XS_BLD_RESID_FP:
216 { 221 {
217 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!"); 222 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!");
223 #ifdef HAVE_SIDPLAYFP_V1
224 if (rs && rs->getStatus())
225 {
226 engine->config.sidEmulation = rs;
227 if (!rs->getStatus()) return FALSE;
228 rs->create((engine->emu.info()).maxsids());
229 if (!rs->getStatus()) return FALSE;
230 }
231 #else
218 if (rs && *rs) 232 if (rs && *rs)
219 { 233 {
220 engine->config.sidEmulation = rs; 234 engine->config.sidEmulation = rs;
221 if (!(*rs)) return FALSE; 235 if (!*rs) return FALSE;
222 rs->create((engine->emu.info()).maxsids); 236 rs->create((engine->emu.info()).maxsids);
223 if (!(*rs)) return FALSE; 237 if (!*rs) return FALSE;
224 238 }
225 rs->filter6581Curve(0.0); 239 #endif
226 rs->filter8580Curve(0.0); 240 rs->filter6581Curve(0.0);
227 } 241 rs->filter8580Curve(0.0);
228 } 242 }
229 break; 243 break;
230 #endif 244 #endif
231 245
232 #ifdef HAVE_HARDSID_BUILDER 246 #ifdef HAVE_HARDSID_BUILDER
233 case XS_BLD_HARDSID: 247 case XS_BLD_HARDSID:
234 { 248 {
235 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); 249 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)");
236 engine->config.sidEmulation = (sidbuilder *) hs; 250 engine->config.sidEmulation = (sidbuilder *) hs;
237 if (hs) 251 #ifdef HAVE_SIDPLAYFP_V1
252 if (hs && hs->getStatus())
253 {
254 hs->create((engine->emu.info()).maxsids());
255 if (!hs->getStatus()) return FALSE;
256 }
257 #else
258 if (hs && *hs)
238 { 259 {
239 hs->create((engine->emu.info()).maxsids); 260 hs->create((engine->emu.info()).maxsids);
240 if (!*hs) 261 if (!*hs) return FALSE;
241 { 262 }
242 xs_error("hardSID->create() failed.\n"); 263 #endif
243 return FALSE;
244 }
245 }
246 } 264 }
247 break; 265 break;
248 #endif 266 #endif
249 267
250 default: 268 default:
258 return FALSE; 276 return FALSE;
259 } 277 }
260 278
261 // Setup filter 279 // Setup filter
262 engine->config.sidEmulation->filter(xs_cfg.emulateFilters); 280 engine->config.sidEmulation->filter(xs_cfg.emulateFilters);
281 #ifdef HAVE_SIDPLAYFP_V1
282 if (!engine->config.sidEmulation->getStatus())
283 #else
263 if (!*(engine->config.sidEmulation)) 284 if (!*(engine->config.sidEmulation))
285 #endif
264 { 286 {
265 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); 287 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters);
266 return FALSE; 288 return FALSE;
267 } 289 }
268 290
331 XSSIDPlayFP *engine = (XSSIDPlayFP *) state->internal; 353 XSSIDPlayFP *engine = (XSSIDPlayFP *) state->internal;
332 354
333 if (!engine) 355 if (!engine)
334 return 0; 356 return 0;
335 357
336 #if 1 358 return engine->emu.play((short *) audioBuffer, audioBufSize / sizeof(short)) * sizeof(short);
337 int nsamples = audioBufSize / sizeof(short);
338 return engine->emu.play((short *) audioBuffer, nsamples) * sizeof(short);
339 #else
340 int nsamples = audioBufSize / sizeof(short);
341 fprintf(stderr, "%p, %d -> %d\n", audioBuffer, audioBufSize, nsamples);
342 return 0;
343 #endif
344 } 359 }
345 360
346 361
347 /* Load a given SID-tune file 362 /* Load a given SID-tune file
348 */ 363 */
352 367
353 if (!engine || !filename) 368 if (!engine || !filename)
354 return FALSE; 369 return FALSE;
355 370
356 engine->tune.load(filename); 371 engine->tune.load(filename);
372 #ifdef HAVE_SIDPLAYFP_V1
373 if (!engine->tune.getStatus())
374 #else
357 if (!engine->tune) 375 if (!engine->tune)
358 { 376 #endif
359 xs_error("Could not load file '%s': %s\n", 377 {
360 filename, (engine->tune.getInfo()).statusString); 378 xs_error("Could not load file '%s'\n", filename);
361 return FALSE; 379 return FALSE;
362 } 380 }
363 381
364 return TRUE; 382 return TRUE;
365 } 383 }
387 } 405 }
388 #endif 406 #endif
389 } 407 }
390 408
391 409
410 /* This function gets most of the information, though we do miss some
411 * (those variables that are only set by libSIDPlay when tune is initialized).
412 * Rest of the information is acquired in xs_sidplayfp_updateinfo()
413 */
414 XSTuneInfo *xs_sidplayfp_getinfo(const gchar *filename)
415 {
416 XSTuneInfo *res;
417 SidTune *tune;
418
419 /* Check if the tune exists and is readable */
420 if ((tune = new SidTune(filename)) == NULL)
421 {
422 XSDEBUG("could not initialize tune from '%s'.\n", filename);
423 return NULL;
424 }
425
426 if (!tune->getStatus())
427 {
428 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename);
429 delete tune;
430 return NULL;
431 }
432
433 /* Get general tune information */
434 #ifdef HAVE_SIDPLAYFP_V1
435 const SidTuneInfo *info = tune->getInfo();
436
437 res = xs_tuneinfo_new(filename,
438 info->songs(), info->startSong(),
439 info->infoString(0), info->infoString(1), info->infoString(2),
440 info->loadAddr(), info->initAddr(), info->playAddr(),
441 info->dataFileLen(), info->formatString(),
442 info->sidModel1()
443 );
444 #else
445 const SidTuneInfo info = tune->getInfo();
446
447 res = xs_tuneinfo_new(filename,
448 info.songs, info.startSong,
449 info.infoString[0], info.infoString[1], info.infoString[2],
450 info.loadAddr, info.initAddr, info.playAddr,
451 info.dataFileLen, info.formatString,
452 info.sidModel1
453 );
454 #endif
455
456 delete tune;
457 return res;
458 }
459
460
461 /* Updates the information of currently playing tune
462 */
463 gboolean xs_sidplayfp_updateinfo(XSEngineState *state)
464 {
465 XSSIDPlayFP *engine;
466
467 /* Check if we have required structures initialized */
468 if (!state || !state->tuneInfo || !state->internal)
469 return FALSE;
470
471 engine = (XSSIDPlayFP *) state->internal;
472
473 #ifdef HAVE_SIDPLAYFP_V1
474 if (!engine->tune.getStatus())
475 return FALSE;
476
477 const SidTuneInfo *info = engine->tune.getInfo();
478
479 state->tuneInfo->sidModel = info.sidModel1();
480
481 if (state->currSong > 0 && state->currSong <= state->tuneInfo->nsubTunes)
482 {
483 gint tmpSpeed = info->clockSpeed();
484 switch (info->clockSpeed())
485 {
486 case SIDTUNE_CLOCK_PAL: tmpSpeed = XS_CLOCK_PAL; break;
487 case SIDTUNE_CLOCK_NTSC: tmpSpeed = XS_CLOCK_NTSC; break;
488 case SIDTUNE_CLOCK_ANY: tmpSpeed = XS_CLOCK_ANY; break;
489 case SIDTUNE_CLOCK_UNKNOWN:
490 switch (info->songSpeed())
491 {
492 case SIDTUNE_SPEED_VBI: tmpSpeed = XS_CLOCK_VBI; break;
493 case SIDTUNE_SPEED_CIA_1A: tmpSpeed = XS_CLOCK_CIA; break;
494 default: tmpSpeed = info->songSpeed(); break;
495 }
496 break;
497 }
498 state->tuneInfo->subTunes[state->currSong - 1].tuneSpeed = tmpSpeed;
499 }
500 #else
501 if (!(engine->tune))
502 return FALSE;
503
504 const SidTuneInfo info = engine->tune.getInfo();
505
506 state->tuneInfo->sidModel = info.sidModel1;
507
508 if (state->currSong > 0 && state->currSong <= state->tuneInfo->nsubTunes)
509 {
510 gint tmpSpeed = info.clockSpeed;
511 switch (info.clockSpeed)
512 {
513 case SIDTUNE_CLOCK_PAL: tmpSpeed = XS_CLOCK_PAL; break;
514 case SIDTUNE_CLOCK_NTSC: tmpSpeed = XS_CLOCK_NTSC; break;
515 case SIDTUNE_CLOCK_ANY: tmpSpeed = XS_CLOCK_ANY; break;
516 case SIDTUNE_CLOCK_UNKNOWN:
517 switch (info.songSpeed)
518 {
519 case SIDTUNE_SPEED_VBI: tmpSpeed = XS_CLOCK_VBI; break;
520 case SIDTUNE_SPEED_CIA_1A: tmpSpeed = XS_CLOCK_CIA; break;
521 default: tmpSpeed = info.songSpeed; break;
522 }
523 break;
524 }
525 state->tuneInfo->subTunes[state->currSong - 1].tuneSpeed = tmpSpeed;
526 }
527 #endif
528
529 return TRUE;
530 }
531
532
392 } /* extern "C" */ 533 } /* extern "C" */
393 #endif /* HAVE_SIDPLAYFP */ 534 #endif /* HAVE_SIDPLAYFP */