diff src/xs_sidplayfp.cpp @ 847:5b93bd8c7814

Cleanups, adjust backend configuration sequences, more error checking, improved debug output.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Nov 2012 22:44:36 +0200
parents ae1f6418d093
children 2663b1ac9ce6
line wrap: on
line diff
--- a/src/xs_sidplayfp.cpp	Thu Nov 08 22:43:45 2012 +0200
+++ b/src/xs_sidplayfp.cpp	Thu Nov 08 22:44:36 2012 +0200
@@ -130,13 +130,15 @@
 }
 
 
-/* Initialize SIDPlay2
+/* Initialize SIDPlayFP
  */
 gboolean xs_sidplayfp_init(XSEngineState * state)
 {
     XSSIDPlayFP *engine;
     assert(state);
 
+    XSDEBUG("SIDPlayFP backend initializing.\n");
+
     /* Allocate internal structures */
     engine = new XSSIDPlayFP();
     state->internal = engine;
@@ -144,6 +146,7 @@
         return FALSE;
 
     /* Get current configuration */
+    XSDEBUG("SIDPlayFP emulation configuration\n");
     engine->config = engine->emu.config();
 
     /* Configure channels and stuff */
@@ -154,11 +157,37 @@
     engine->config.samplingMethod = SID2_RESAMPLE_INTERPOLATE;
     engine->config.frequency = state->audioFrequency;
 
+    /* Clockspeed settings */
+    switch (xs_cfg.clockSpeed)
+    {
+        case XS_CLOCK_NTSC:
+            engine->config.clockDefault = SID2_CLOCK_NTSC;
+            break;
+
+        default:
+        case XS_CLOCK_PAL:
+            engine->config.clockDefault = SID2_CLOCK_PAL;
+            xs_cfg.clockSpeed = XS_CLOCK_PAL;
+            break;
+    }
+
+
+    /* Configure rest of the emulation */
+    engine->config.sidDefault  = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581;
+    engine->config.clockForced = xs_cfg.forceSpeed;
+
+#ifndef HAVE_SIDPLAYFP_V1
+    engine->config.sidSamples  = TRUE;
+    engine->config.sidModel    = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT;
+    engine->config.clockSpeed  = xs_cfg.forceSpeed ? engine->config.clockDefault : SID2_CLOCK_CORRECT;
+#endif
+
     /* Initialize builder object */
     XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids);
 
     switch (xs_cfg.sid2Builder)
     {
+#if 0
 #ifdef HAVE_RESID_BUILDER
         case XS_BLD_RESID:
             {
@@ -168,30 +197,30 @@
                 {
                 }
 #else
-                if (rs)
+                if (rs && *rs)
                 {
                     engine->config.sidEmulation = rs;
-                    if (!*rs) return FALSE;
+                    if (!(*rs)) return FALSE;
                     rs->create((engine->emu.info()).maxsids);
-                    if (!*rs) return FALSE;
+                    if (!(*rs)) return FALSE;
                     rs->bias(0.0f);
                 }
 #endif // HAVE_SIDPLAYFP_V1
             }
             break;
 #endif // HAVE_RESID_BUILDER
-
+#endif
 
 #ifdef HAVE_RESID_FP_BUILDER
         case XS_BLD_RESID_FP:
             {
                 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!");
-                if (rs)
+                if (rs && *rs)
                 {
                     engine->config.sidEmulation = rs;
-                    if (!*rs) return FALSE;
+                    if (!(*rs)) return FALSE;
                     rs->create((engine->emu.info()).maxsids);
-                    if (!*rs) return FALSE;
+                    if (!(*rs)) return FALSE;
 
                     rs->filter6581Curve(0.0);
                     rs->filter8580Curve(0.0);
@@ -219,13 +248,13 @@
 #endif
         
         default:
-            xs_error("[SIDPlay2] Invalid or unsupported builder selected.\n");
-            break;
+            xs_error("[SIDPlayFP] Invalid or unsupported builder selected.\n");
+            return FALSE;
     }
 
     if (!engine->config.sidEmulation)
     {
-        xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n");
+        xs_error("[SIDPlayFP] Could not initialize SIDBuilder object.\n");
         return FALSE;
     }
 
@@ -239,41 +268,19 @@
 
     XSDEBUG("%s\n", engine->config.sidEmulation->credits());
 
-    /* Clockspeed settings */
-    switch (xs_cfg.clockSpeed)
-    {
-        case XS_CLOCK_NTSC:
-            engine->config.clockDefault = SID2_CLOCK_NTSC;
-            break;
-
-        default:
-        case XS_CLOCK_PAL:
-            engine->config.clockDefault = SID2_CLOCK_PAL;
-            xs_cfg.clockSpeed = XS_CLOCK_PAL;
-            break;
-    }
-
-
-    /* Configure rest of the emulation */
-    engine->config.sidDefault  = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581;
-    engine->config.clockForced = xs_cfg.forceSpeed;
-
-#ifndef HAVE_SIDPLAYFP_V1
-    engine->config.sidSamples  = TRUE;
-    engine->config.sidModel    = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT;
-    engine->config.clockSpeed  = xs_cfg.forceSpeed ? engine->config.clockDefault : SID2_CLOCK_CORRECT;
-#endif
     
     return TRUE;
 }
 
 
-/* Close SIDPlay2 engine
+/* Close SIDPlayFP engine
  */
 void xs_sidplayfp_close(XSEngineState * state)
 {
     XSSIDPlayFP *engine = (XSSIDPlayFP *) state->internal;
 
+    XSDEBUG("SIDPlayFP backend shutdown.\n");
+
     xs_sidplayfp_delete(state);
 
     if (engine)
@@ -297,19 +304,19 @@
 
     if (!engine->tune.selectSong(state->currSong))
     {
-        xs_error("[SIDPlay2] tune.selectSong() failed\n");
+        xs_error("[SIDPlayFP] tune.selectSong() failed\n");
         return FALSE;
     }
 
     if (engine->emu.load(&(engine->tune)) < 0)
     {
-        xs_error("[SIDPlay2] emu.load() failed\n");
+        xs_error("[SIDPlayFP] emu.load() failed\n");
         return FALSE;
     }
 
     if (engine->emu.config(engine->config) < 0)
     {
-        xs_error("[SIDPlay2] Emulator engine configuration failed!\n");
+        xs_error("[SIDPlayFP] Emulator engine configuration failed!\n");
         return FALSE;
     }