Backport support for libsidplayfp-3 from 4.6beta1
https://github.com/audacious-media-player/audacious-plugins/commit/42c05763a136d6523d611473ff3701e2d9e30bec
https://github.com/audacious-media-player/audacious-plugins/commit/2aaf45bd3840858e23b75d5863129a510299abd6
From 42c05763a136d6523d611473ff3701e2d9e30bec Mon Sep 17 00:00:00 2001
From: Thomas Lange <thomas-lange2@gmx.de>
Date: Thu, 7 May 2026 20:25:10 +0200
Subject: [PATCH] sid: Use new sidplayfp API. Closes: #1706

The previous play() function is deprecated meanwhile.
--- a/src/sid/xs_sidplay2.cc
+++ b/src/sid/xs_sidplay2.cc
@@ -37,6 +37,14 @@
 #include <sidplayfp/SidTuneInfo.h>
 #include <sidplayfp/builders/residfp.h>
 
+#ifndef LIBSIDPLAYFP_CHECK_VERSION
+#define LIBSIDPLAYFP_CHECK_VERSION(major,minor,micro)                               \
+    (LIBSIDPLAYFP_VERSION_MAJ > (major) ||                                          \
+     (LIBSIDPLAYFP_VERSION_MAJ == (major) && LIBSIDPLAYFP_VERSION_MIN > (minor)) || \
+     (LIBSIDPLAYFP_VERSION_MAJ == (major) && LIBSIDPLAYFP_VERSION_MIN == (minor) && \
+      LIBSIDPLAYFP_VERSION_LEV >= (micro)))
+#endif
+
 #include <libaudcore/runtime.h>
 #include <libaudcore/vfs.h>
 
@@ -99,7 +107,7 @@ bool xs_sidplayfp_init()
         return false;
     }
 
-#if (LIBSIDPLAYFP_VERSION_MAJ << 8) + LIBSIDPLAYFP_VERSION_MIN < 0x020A
+#if !LIBSIDPLAYFP_CHECK_VERSION(2, 10, 0)
     state.currBuilder->filter(xs_cfg.emulateFilters);
     if (!state.currBuilder->getStatus()) {
         AUDERR("reSID->filter(%d) failed.\n", xs_cfg.emulateFilters);
@@ -141,7 +149,7 @@ bool xs_sidplayfp_init()
         return false;
     }
 
-#if (LIBSIDPLAYFP_VERSION_MAJ << 8) + LIBSIDPLAYFP_VERSION_MIN >= 0x020A
+#if LIBSIDPLAYFP_CHECK_VERSION(2, 10, 0)
     /* Call filter() after config() to have an effect */
     state.currEng->filter(0, xs_cfg.emulateFilters);
     state.currEng->filter(1, xs_cfg.emulateFilters);
@@ -212,6 +220,11 @@ bool xs_sidplayfp_initsong(int subtune)
         return false;
     }
 
+#if LIBSIDPLAYFP_CHECK_VERSION(2, 15, 0)
+    bool stereo = xs_cfg.audioChannels == XS_CHN_STEREO;
+    state.currEng->initMixer(stereo);
+#endif
+
     return true;
 }
 
@@ -220,7 +233,15 @@ bool xs_sidplayfp_initsong(int subtune)
  */
 unsigned xs_sidplayfp_fillbuffer(char * audioBuffer, unsigned audioBufSize)
 {
+#if LIBSIDPLAYFP_CHECK_VERSION(2, 15, 0)
+    int samples = state.currEng->play(audioBufSize / 2);
+    if (samples < 0)
+        return 0;
+
+    return state.currEng->mix((short *)audioBuffer, samples) * 2;
+#else
     return state.currEng->play((short *)audioBuffer, audioBufSize / 2) * 2;
+#endif
 }
 
 
From 2aaf45bd3840858e23b75d5863129a510299abd6 Mon Sep 17 00:00:00 2001
From: Thomas Lange <thomas-lange2@gmx.de>
Date: Thu, 7 May 2026 20:29:50 +0200
Subject: [PATCH] sid: Support version 3.0 of libsidplayfp version

libsidplayfp 3.0 contains the header <sidplayfp/builders/residfp.h>
only when built with ReSIDfp support, depending on the new library
libresidfp. Print a warning if this is not the case.

See also: https://github.com/libsidplayfp/libsidplayfp/releases/tag/v3.0.0
--- a/src/sid/meson.build
+++ b/src/sid/meson.build
@@ -1,6 +1,18 @@
 sidplayfp_dep = dependency('libsidplayfp', version: '>= 2.0', required: false)
-have_sid = sidplayfp_dep.found()
 
+# libsidplayfp 3.0 moved the ReSIDfp engine to an external library (libresidfp).
+# It is optional for libsidplayfp, but the SID plugin for Audacious requires it.
+if sidplayfp_dep.version().version_compare('>= 3.0')
+  residfp_dep = dependency('libresidfp', version: '>= 1.0', required: false)
+  if not residfp_dep.found()
+    warning('The SID plugin was disabled because your libsidplayfp installation ' +
+            'lacks ReSIDfp support. Make sure it was built with the optional ' +
+            'libresidfp dependency.')
+  endif
+  have_sid = sidplayfp_dep.found() and residfp_dep.found()
+else
+  have_sid = sidplayfp_dep.found()
+endif
 
 if have_sid
   sid_datadir = join_paths(get_option('prefix'), get_option('datadir'))
--- a/src/sid/xs_sidplay2.cc
+++ b/src/sid/xs_sidplay2.cc
@@ -82,6 +82,7 @@ bool xs_sidplayfp_init()
     /* Get current configuration */
     SidConfig config = state.currEng->config();
 
+#if !LIBSIDPLAYFP_CHECK_VERSION(3, 0, 0)
     /* Configure channels and stuff */
     switch (xs_cfg.audioChannels)
     {
@@ -93,6 +94,7 @@ bool xs_sidplayfp_init()
         config.playback = SidConfig::MONO;
         break;
     }
+#endif
 
     /* Audio parameters sanity checking and setup */
     config.frequency = xs_cfg.audioFrequency;
@@ -100,12 +102,14 @@ bool xs_sidplayfp_init()
     /* Initialize builder object */
     state.currBuilder = new ReSIDfpBuilder("ReSIDfp builder");
 
+#if !LIBSIDPLAYFP_CHECK_VERSION(3, 0, 0)
     /* Builder object created, initialize it */
     state.currBuilder->create(state.currEng->info().maxsids());
     if (!state.currBuilder->getStatus()) {
         AUDERR("reSID->create() failed.\n");
         return false;
     }
+#endif
 
 #if !LIBSIDPLAYFP_CHECK_VERSION(2, 10, 0)
     state.currBuilder->filter(xs_cfg.emulateFilters);
