comparison src/xs_sidplay2.cc @ 770:72e58ecb1a2c

Still not working. Urgh.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Nov 2012 01:28:10 +0200
parents 120d6f247f1b
children 45108b3d88db
comparison
equal deleted inserted replaced
769:120d6f247f1b 770:72e58ecb1a2c
49 49
50 50
51 class XSSIDPlay2 { 51 class XSSIDPlay2 {
52 public: 52 public:
53 #ifdef HAVE_SIDPLAY2_FP 53 #ifdef HAVE_SIDPLAY2_FP
54 sidplay2 *emu; 54 sidplay2 emu;
55 sidbuilder *builder;
56 #else 55 #else
57 SidIPtr<ISidplay2> emu; 56 SidIPtr<ISidplay2> emu;
58 SidLazyIPtr<ISidUnknown> builder;
59 #endif 57 #endif
60 sid2_config_t config; 58 sid2_config_t config;
61 SidTune *tune; 59 SidTune *tune;
62 60
63 guint8 *buf; 61 guint8 *buf;
84 # endif 82 # endif
85 #endif 83 #endif
86 84
87 85
88 XSSIDPlay2::XSSIDPlay2(void) 86 XSSIDPlay2::XSSIDPlay2(void)
89 #ifdef HAVE_SIDPLAY2_FP
90 :emu(NULL)
91 #else
92 :emu(sidplay2::create())
93 #endif
94 { 87 {
95 tune = NULL; 88 tune = NULL;
96 buf = NULL; 89 buf = NULL;
97 bufSize = 0; 90 bufSize = 0;
98 builder = NULL;
99 } 91 }
100 92
101 93
102 /* We need to 'export' all this pseudo-C++ crap */ 94 /* We need to 'export' all this pseudo-C++ crap */
103 extern "C" { 95 extern "C" {
144 assert(state); 136 assert(state);
145 137
146 /* Allocate internal structures */ 138 /* Allocate internal structures */
147 engine = new XSSIDPlay2(); 139 engine = new XSSIDPlay2();
148 state->internal = engine; 140 state->internal = engine;
149 if (!engine) return FALSE; 141 if (!engine)
150 142 return FALSE;
151 /* Initialize the engine */
152 #ifdef HAVE_SIDPLAY2_FP
153 engine->emu = new sidplay2;
154 #endif
155 if (!engine->emu)
156 {
157 xs_error("[SIDPlay2] Could not initialize emulation engine.\n");
158 return FALSE;
159 }
160 143
161 /* Get current configuration */ 144 /* Get current configuration */
162 engine->config = engine->emu->config(); 145 engine->config = engine->emu.config();
163 146
164 /* Configure channels and stuff */ 147 /* Configure channels and stuff */
165 switch (state->audioChannels) 148 switch (state->audioChannels)
166 { 149 {
167 case XS_CHN_AUTOPAN: 150 case XS_CHN_AUTOPAN:
275 tmpFilter.cutoff[i][1] = f->points[i].y; 258 tmpFilter.cutoff[i][1] = f->points[i].y;
276 } 259 }
277 #endif 260 #endif
278 261
279 /* Initialize builder object */ 262 /* Initialize builder object */
280 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu->info()).maxsids); 263 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids);
281 264
282 switch (xs_cfg.sid2Builder) 265 switch (xs_cfg.sid2Builder)
283 { 266 {
284 #ifdef HAVE_RESID_BUILDER 267 #ifdef HAVE_RESID_BUILDER
285 case XS_BLD_RESID: 268 case XS_BLD_RESID:
286 #ifdef HAVE_SIDPLAY2_FP 269 #ifdef HAVE_SIDPLAY2_FP
287 { 270 {
288 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!"); 271 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!");
289 if (rs) 272 if (rs)
290 { 273 {
291 engine->builder = rs; 274 engine->config.sidEmulation = rs;
292 if (!*rs) return FALSE; 275 if (!*rs) return FALSE;
293 rs->create((engine->emu->info()).maxsids); 276 rs->create((engine->emu.info()).maxsids);
294 if (!*rs) return FALSE; 277 if (!*rs) return FALSE;
295 278
296 /* 279 /*
297 if (m_filter.filterCurve6581) 280 if (m_filter.filterCurve6581)
298 rs->filter6581Curve(m_filter.filterCurve6581); 281 rs->filter6581Curve(m_filter.filterCurve6581);
299 if (m_filter.filterCurve8580) 282 if (m_filter.filterCurve8580)
300 rs->filter8580Curve((double)m_filter.filterCurve8580); 283 rs->filter8580Curve((double)m_filter.filterCurve8580);
301 */ 284 */
302 } 285 }
303 #else 286 #else
304 engine->builder = ReSIDBuilderCreate("ReSID builder"); 287 engine->config.sidEmulation = ReSIDBuilderCreate("ReSID builder");
305 SidLazyIPtr<IReSIDBuilder> rs(engine->builder); 288 SidLazyIPtr<IReSIDBuilder> rs(engine->config.sidEmulation);
306 if (rs) 289 if (rs)
307 { 290 {
308 engine->config.sidEmulation = rs->iaggregate(); 291 engine->config.sidEmulation = rs->iaggregate();
309 rs->create((engine->emu->info()).maxsids); 292 rs->create((engine->emu.info()).maxsids);
310 if (!*rs) return FALSE; 293 if (!*rs) return FALSE;
311 } 294 }
312 #endif 295 #endif
313 } 296 }
314 break; 297 break;
317 #ifdef HAVE_HARDSID_BUILDER 300 #ifdef HAVE_HARDSID_BUILDER
318 case XS_BLD_HARDSID: 301 case XS_BLD_HARDSID:
319 #ifdef HAVE_SIDPLAY2_FP 302 #ifdef HAVE_SIDPLAY2_FP
320 { 303 {
321 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); 304 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)");
322 engine->builder = (sidbuilder *) hs; 305 engine->config.sidEmulation = (sidbuilder *) hs;
323 if (hs) 306 if (hs)
324 { 307 {
325 #else 308 #else
326 engine->builder = HardSIDBuilderCreate("HardSID builder"); 309 engine->config.sidEmulation = HardSIDBuilderCreate("HardSID builder");
327 SidLazyIPtr<IHardSIDBuilder> hs(engine->builder); 310 SidLazyIPtr<IHardSIDBuilder> hs(engine->config.sidEmulation);
328 if (hs) 311 if (hs)
329 { 312 {
330 engine->config.sidEmulation = hs->iaggregate(); 313 engine->config.sidEmulation = hs->iaggregate();
331 #endif 314 #endif
332 /* Builder object created, initialize it */ 315 /* Builder object created, initialize it */
333 hs->create((engine->emu->info()).maxsids); 316 hs->create((engine->emu.info()).maxsids);
334 if (!*hs) 317 if (!*hs)
335 { 318 {
336 xs_error("hardSID->create() failed.\n"); 319 xs_error("hardSID->create() failed.\n");
337 return FALSE; 320 return FALSE;
338 } 321 }
344 default: 327 default:
345 xs_error("[SIDPlay2] Invalid or unsupported builder selected.\n"); 328 xs_error("[SIDPlay2] Invalid or unsupported builder selected.\n");
346 break; 329 break;
347 } 330 }
348 331
349 if (!engine->builder) 332 if (!engine->config.sidEmulation)
350 { 333 {
351 xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); 334 xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n");
352 return FALSE; 335 return FALSE;
353 } 336 }
354 337
355 // Setup filter 338 // Setup filter
356 engine->builder->filter(xs_cfg.emulateFilters); 339 engine->config.sidEmulation->filter(xs_cfg.emulateFilters);
357 if (!*(engine->builder)) 340 if (!*(engine->config.sidEmulation))
358 { 341 {
359 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); 342 xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters);
360 return FALSE; 343 return FALSE;
361 } 344 }
362 345
363 #ifdef HAVE_SIDPLAY2_FP 346 #ifdef HAVE_SIDPLAY2_FP
364 engine->config.sidEmulation = engine->builder; 347 engine->config.sidEmulation = engine->config.sidEmulation;
365 XSDEBUG("%s\n", engine->builder->credits()); 348 XSDEBUG("%s\n", engine->config.sidEmulation->credits());
366 #endif 349 #endif
367 350
368 /* Clockspeed settings */ 351 /* Clockspeed settings */
369 switch (xs_cfg.clockSpeed) 352 switch (xs_cfg.clockSpeed)
370 { 353 {
371 case XS_CLOCK_NTSC: 354 case XS_CLOCK_NTSC:
372 engine->config.clockDefault = SID2_CLOCK_NTSC; 355 engine->config.clockDefault = SID2_CLOCK_NTSC;
373 break; 356 break;
374 357
375 default: 358 default:
376 xs_error("[SIDPlay2] Invalid clockSpeed=%d, falling back to PAL.\n",
377 xs_cfg.clockSpeed);
378
379 case XS_CLOCK_PAL: 359 case XS_CLOCK_PAL:
380 engine->config.clockDefault = SID2_CLOCK_PAL; 360 engine->config.clockDefault = SID2_CLOCK_PAL;
381 xs_cfg.clockSpeed = XS_CLOCK_PAL; 361 xs_cfg.clockSpeed = XS_CLOCK_PAL;
382 break; 362 break;
383 } 363 }
410 engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581; 390 engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581;
411 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; 391 engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT;
412 engine->config.sidSamples = TRUE; 392 engine->config.sidSamples = TRUE;
413 393
414 /* Now set the emulator configuration */ 394 /* Now set the emulator configuration */
415 if (engine->emu->config(engine->config) < 0) 395 if (engine->emu.config(engine->config) < 0)
416 { 396 {
417 xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); 397 xs_error("[SIDPlay2] Emulator engine configuration failed!\n");
418 return FALSE; 398 return FALSE;
419 } 399 }
420 400
426 */ 406 */
427 void xs_sidplay2_close(XSEngineState * state) 407 void xs_sidplay2_close(XSEngineState * state)
428 { 408 {
429 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; 409 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal;
430 410
431 411 if (engine)
432 /* Free internals */ 412 {
433 if (engine->builder) { 413 #ifdef HAVE_SIDPLAY2_FP
434 #ifdef HAVE_SIDPLAY2_FP 414 if (engine->config.sidEmulation)
435 delete engine->builder; 415 {
436 #endif 416 sidbuilder *builder = engine->config.sidEmulation;
437 engine->builder = NULL; 417 engine->config.sidEmulation = NULL;
438 } 418 engine->emu.config(engine->config);
439 419 delete builder;
440 #ifdef HAVE_SIDPLAY2_FP 420 }
441 if (engine->emu) 421 #endif
442 { 422
443 delete engine->emu; 423 delete engine;
444 engine->emu = NULL; 424 }
445 }
446 #endif
447 425
448 xs_sidplay2_delete(state); 426 xs_sidplay2_delete(state);
449
450 delete engine;
451 state->internal = NULL; 427 state->internal = NULL;
452 } 428 }
453 429
454 430
455 /* Initialize current song and sub-tune 431 /* Initialize current song and sub-tune
465 { 441 {
466 xs_error("[SIDPlay2] tune->selectSong() failed\n"); 442 xs_error("[SIDPlay2] tune->selectSong() failed\n");
467 return FALSE; 443 return FALSE;
468 } 444 }
469 445
470 if (engine->emu->load(engine->tune) < 0) { 446 if (engine->emu.load(engine->tune) < 0)
471 xs_error("[SIDPlay2] emu->load() failed\n"); 447 {
448 xs_error("[SIDPlay2] emu.load() failed\n");
472 return FALSE; 449 return FALSE;
473 } 450 }
474 451
475 state->isInitialized = TRUE; 452 state->isInitialized = TRUE;
476 453