changeset 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 3012740d014c
children dfda3d47baf7
files acinclude.m4 configure.ac src/config.h.in src/xs_sidplay2.cc
diffstat 4 files changed, 57 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/acinclude.m4	Wed Nov 07 11:04:34 2012 +0200
+++ b/acinclude.m4	Wed Nov 07 11:05:24 2012 +0200
@@ -228,16 +228,16 @@
             fi
 
             dnl *** Check for new COMI API
-            xs_api_ok="no"
+            xs_api_ok="yes"
             AC_MSG_CHECKING([libSIDPlay2 API compatibility])
             tmp_CPPFLAGS="$CPPFLAGS"
             if test -d "$xs_sidplay2_includes"; then
                     CPPFLAGS="$CPPFLAGS -I${xs_sidplay2_includes}"
             fi
             AC_EGREP_HEADER([::Iid], [sidplay/sidplay2.h],
-                    [xs_have_sidplay2_api="yes"], [
+                    [xs_api_ok="no"], [
                     AC_EGREP_HEADER([SIDIID], [sidplay/sidplay2.h], [
-                            AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <sidplay/sidunknown.h>], [ISidUnknown *i;])], [xs_api_ok="yes"], [])])
+                            AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <sidplay/sidunknown.h>], [ISidUnknown *i;])], [xs_api_ok="no"], [])])
                     ])
 
             if test "x$xs_api_ok" = "xyes"; then
--- a/configure.ac	Wed Nov 07 11:04:34 2012 +0200
+++ b/configure.ac	Wed Nov 07 11:05:24 2012 +0200
@@ -106,9 +106,10 @@
 	AC_DEFINE([HAVE_SIDPLAY2_FP])
 	AC_DEFINE([HAVE_HARDSID_BUILDER])
 	AC_DEFINE([HAVE_RESID_BUILDER])
+	AC_DEFINE([HAVE_RESID_FP_BUILDER])
 
 elif test "x$xs_have_sidplay2" = "xyes"; then
-	xs_have_sidplay2_api="(normal COMI)"
+	xs_have_sidplay2_api="(non-COMI)"
 	xs_have_sidplay2_lib="yes"
 	AC_DEFINE([HAVE_SIDPLAY2])
 
@@ -116,6 +117,7 @@
 	
 	XS_BUILDERS_CHECK
         xs_builders_available="no"
+	XS_BUILDERS_FIND([reSID_FP], [residfp-builder], [residfp.h], [ReSIDfpBuilder])
 	XS_BUILDERS_FIND([reSID], [resid-builder], [resid.h], [ReSIDBuilder])
 	XS_BUILDERS_FIND([HardSID], [hardsid-builder], [hardsid.h], [HardSID])
 	if test "x$xs_builders_available" = "xno"; then
--- a/src/config.h.in	Wed Nov 07 11:04:34 2012 +0200
+++ b/src/config.h.in	Wed Nov 07 11:05:24 2012 +0200
@@ -40,6 +40,9 @@
 /* Define if you have reSID for libSIDPlay 2 */
 #undef HAVE_RESID_BUILDER
 
+/* Define if you have reSID_FP for libSIDPlay 2 */
+#undef HAVE_RESID_FP_BUILDER
+
 /* Define if you have and want to use libSIDPlay1 */
 #undef HAVE_SIDPLAY1
 
--- a/src/xs_sidplay2.cc	Wed Nov 07 11:04:34 2012 +0200
+++ b/src/xs_sidplay2.cc	Wed Nov 07 11:05:24 2012 +0200
@@ -35,7 +35,6 @@
 #  include <sidplayfp/event.h>
 #else
 #  include <sidplay/sidplay2.h>
-#  include <sidplay/sidlazyiptr.h>
 #  if G_BYTE_ORDER == G_BIG_ENDIAN
 #    define SID2_NATIVE_UNSIGNED SID2_BIG_UNSIGNED
 #    define SID2_NATIVE_SIGNED SID2_BIG_SIGNED
@@ -50,16 +49,13 @@
 
 class XSSIDPlay2 {
 public:
-#ifdef HAVE_SIDPLAY2_FP
     sidplay2 emu;
-#else
-    SidIPtr<ISidplay2> emu;
-#endif
     sid2_config_t config;
     SidTune *tune;
+    gboolean tuneLoaded;
 
     XSSIDPlay2(void);
-    virtual ~XSSIDPlay2(void) { ; }
+    virtual ~XSSIDPlay2(void);
 };
 
 
@@ -87,6 +83,15 @@
 }
 
 
+XSSIDPlay2::~XSSIDPlay2(void)
+{
+    if (tune)
+        delete tune;
+
+    tuneLoaded = FALSE;
+}
+
+
 /* We need to 'export' all this pseudo-C++ crap */
 extern "C" {
 
@@ -261,7 +266,6 @@
     switch (xs_cfg.sid2Builder)
     {
 #ifdef HAVE_RESID_BUILDER
-#ifdef HAVE_SIDPLAY2_FP
         case XS_BLD_RESID:
             {
                 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
@@ -271,11 +275,15 @@
                     if (!*rs) return FALSE;
                     rs->create((engine->emu.info()).maxsids);
                     if (!*rs) return FALSE;
+#ifdef HAVE_SIDPLAY2_FP
                     rs->bias(0.0f);
+#endif
                 }
             }
             break;
+#endif
 
+#ifdef HAVE_RESID_FP_BUILDER
         case XS_BLD_RESID_FP:
             {
                 ReSIDfpBuilder *rs = new ReSIDfpBuilder("ReSID builder FP!");
@@ -286,47 +294,20 @@
                     rs->create((engine->emu.info()).maxsids);
                     if (!*rs) return FALSE;
 
-/*
-                    if (m_filter.filterCurve6581)
-                        rs->filter6581Curve(m_filter.filterCurve6581);
-                    if (m_filter.filterCurve8580)
-                        rs->filter8580Curve((double)m_filter.filterCurve8580);
-*/
-                }
-            }
-            break;
-#else
-        case XS_BLD_RESID:
-            {
-                engine->config.sidEmulation = ReSIDBuilderCreate("ReSID builder");
-                SidLazyIPtr<IReSIDBuilder> rs(engine->config.sidEmulation);
-                if (rs)
-                {
-                    engine->config.sidEmulation = rs->iaggregate();
-                    rs->create((engine->emu.info()).maxsids);
-                    if (!*rs) return FALSE;
+                    rs->filter6581Curve(0.0);
+                    rs->filter8580Curve(0.0);
                 }
             }
             break;
 #endif
-#endif
 
 #ifdef HAVE_HARDSID_BUILDER
         case XS_BLD_HARDSID:
-#ifdef HAVE_SIDPLAY2_FP
             {
                 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)");
                 engine->config.sidEmulation = (sidbuilder *) hs;
                 if (hs)
                 {
-#else
-                engine->config.sidEmulation = HardSIDBuilderCreate("HardSID builder");
-                SidLazyIPtr<IHardSIDBuilder> hs(engine->config.sidEmulation);
-                if (hs)
-                {
-                    engine->config.sidEmulation = hs->iaggregate();
-#endif
-                    /* Builder object created, initialize it */
                     hs->create((engine->emu.info()).maxsids);
                     if (!*hs)
                     {
@@ -349,6 +330,7 @@
         return FALSE;
     }
 
+#ifdef HAVE_SIDPLAY2_FP
     // Setup filter
     engine->config.sidEmulation->filter(xs_cfg.emulateFilters);
     if (!*(engine->config.sidEmulation))
@@ -356,11 +338,9 @@
         xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters);
         return FALSE;
     }
+#endif
 
-#ifdef HAVE_SIDPLAY2_FP
-    engine->config.sidEmulation = engine->config.sidEmulation;
     XSDEBUG("%s\n", engine->config.sidEmulation->credits());
-#endif
 
     /* Clockspeed settings */
     switch (xs_cfg.clockSpeed)
@@ -405,13 +385,6 @@
     engine->config.sidModel   = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT;
     engine->config.sidSamples = TRUE;
 
-    /* Now set the emulator configuration */
-    if (engine->emu.config(engine->config) < 0)
-    {
-        xs_error("[SIDPlay2] Emulator engine configuration failed!\n");
-        return FALSE;
-    }
-
     return TRUE;
 }
 
@@ -426,16 +399,6 @@
 
     if (engine)
     {
-#ifdef HAVE_SIDPLAY2_FP
-        if (engine->config.sidEmulation)
-        {
-            sidbuilder *builder = engine->config.sidEmulation;
-            engine->config.sidEmulation = NULL;
-            engine->emu.config(engine->config);
-            delete builder;
-        }
-#endif
-
         delete engine;
         engine = NULL;
     }
@@ -459,12 +422,19 @@
         return FALSE;
     }
 
+    if (engine->emu.config(engine->config) < 0)
+    {
+        xs_error("[SIDPlay2] Emulator engine configuration failed!\n");
+        return FALSE;
+    }
+
+    engine->tuneLoaded = TRUE;    
     if (engine->emu.load(engine->tune) < 0)
     {
         xs_error("[SIDPlay2] emu.load() failed\n");
         return FALSE;
     }
-    
+
     return TRUE;
 }
 
@@ -478,9 +448,18 @@
     if (!engine)
         return 0;
 
-    int len = audioBufSize / sizeof(short);
-    if (len > 512) len = 512;
-    return engine->emu.play((short *) audioBuffer, len) * sizeof(short);
+#if 1
+#ifdef HAVE_SIDPLAY2_FP
+    int nsamples = audioBufSize / sizeof(short);
+    return engine->emu.play((short *) audioBuffer, nsamples) * sizeof(short);
+#else
+    return engine->emu.play(audioBuffer, audioBufSize);
+#endif
+#else
+    int nsamples = audioBufSize / sizeof(short);
+    fprintf(stderr, "%p, %d -> %d\n", audioBuffer, audioBufSize, nsamples);
+    return 0;
+#endif
 }
 
 
@@ -492,9 +471,11 @@
 
     if (!engine)
         return FALSE;
-
+    
     if (!(engine->tune = new SidTune(filename)))
         return FALSE;
+    
+    engine->tuneLoaded = FALSE;
 
     return TRUE;
 }
@@ -508,11 +489,14 @@
 
     if (engine)
     {
-        if (engine->tune)
+        if (engine->tuneLoaded)
         {
-            delete engine->tune;
-            engine->tune = NULL;
+            engine->emu.load(0);
         }
+
+        delete engine->tune;
+        engine->tune = NULL;
+        engine->tuneLoaded = FALSE;
     }
 }