[PATCH] libsndfile: use a macro instead of redefining the struct
authorMarcin Pączkowski <dyfeer@gmail.com>
Mon, 18 Apr 2022 20:51:53 +0000 (13:51 -0700)
committerGeorges Khaznadar <georgesk@debian.org>
Wed, 2 Nov 2022 17:36:06 +0000 (17:36 +0000)
Co-Authored-By: Christof Ressi <info@christofressi.com>
Gbp-Pq: Name use_macro_instead_of_redefining_struct.patch

include/plugin_interface/SC_SndBuf.h
server/plugins/DiskIO_UGens.cpp
server/scsynth/SC_HiddenWorld.h
server/scsynth/SC_SequencedCommand.cpp
server/scsynth/SC_World.cpp
server/supernova/sc/sc_plugin_interface.cpp

index daccfef84382e4d9fadfb274b25cf4ca6bb95a21..2cc129edbf94064a0993be73eab324b8e20cc715 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <stdint.h>
 
-typedef struct SNDFILE_tag SNDFILE;
+#define GETSNDFILE(x) ((SNDFILE*)x->sndfile)
 
 #ifdef SUPERNOVA
 
@@ -145,7 +145,7 @@ struct SndBuf {
     int mask; // for delay lines
     int mask1; // for interpolating oscillators.
     int coord; // used by fft ugens
-    SNDFILE* sndfile; // used by disk i/o
+    void* sndfile; // used by disk i/o
     // SF_INFO fileinfo; // used by disk i/o
 #ifdef SUPERNOVA
     bool isLocal;
index 825d2d52ab3b0f866425f3109581a0485d3068b0..3ace3ca8ffe95b5317ef1c1527d58837ac280815 100644 (file)
@@ -111,7 +111,7 @@ void DiskIOMsg::Perform() {
     sf_count_t count;
     switch (mCommand) {
     case kDiskCmd_Read:
-        count = buf->sndfile ? sf_readf_float(buf->sndfile, buf->data + mPos * buf->channels, mFrames) : 0;
+        count = buf->sndfile ? sf_readf_float(GETSNDFILE(buf), buf->data + mPos * buf->channels, mFrames) : 0;
         if (count < mFrames) {
             memset(buf->data + (mPos + count) * buf->channels, 0, (mFrames - count) * buf->channels * sizeof(float));
             World_GetBuf(mWorld, mBufNum)->mask = mPos + count;
@@ -126,17 +126,17 @@ void DiskIOMsg::Perform() {
             memset(buf->data + mPos * buf->channels, 0, mFrames * buf->channels * sizeof(float));
             goto leave;
         }
-        count = sf_readf_float(buf->sndfile, buf->data + mPos * buf->channels, mFrames);
+        count = sf_readf_float(GETSNDFILE(buf), buf->data + mPos * buf->channels, mFrames);
         while (mFrames -= count) {
-            sf_seek(buf->sndfile, 0, SEEK_SET);
-            count = sf_readf_float(buf->sndfile, buf->data + (mPos + count) * buf->channels, mFrames);
+            sf_seek(GETSNDFILE(buf), 0, SEEK_SET);
+            count = sf_readf_float(GETSNDFILE(buf), buf->data + (mPos + count) * buf->channels, mFrames);
         }
         break;
     case kDiskCmd_Write:
         // printf("kDiskCmd_Write %d %p\n", mBufNum, buf->sndfile);
         if (!buf->sndfile)
             goto leave;
-        count = sf_writef_float(buf->sndfile, buf->data + mPos * buf->channels, mFrames);
+        count = sf_writef_float(GETSNDFILE(buf), buf->data + mPos * buf->channels, mFrames);
         break;
     }
 
@@ -287,14 +287,14 @@ void DiskIn_next(DiskIn* unit, int inNumSamples) {
             if ((int)ZIN0(1)) { // loop
                 if (!bufr->sndfile)
                     memset(bufr->data + mPos * bufr->channels, 0, bufFrames2 * bufr->channels * sizeof(float));
-                count = sf_readf_float(bufr->sndfile, bufr->data + mPos * bufr->channels, bufFrames2);
+                count = sf_readf_float(GETSNDFILE(bufr), bufr->data + mPos * bufr->channels, bufFrames2);
                 while (bufFrames2 -= count) {
-                    sf_seek(bufr->sndfile, 0, SEEK_SET);
-                    count = sf_readf_float(bufr->sndfile, bufr->data + (mPos + count) * bufr->channels, bufFrames2);
+                    sf_seek(GETSNDFILE(bufr), 0, SEEK_SET);
+                    count = sf_readf_float(GETSNDFILE(bufr), bufr->data + (mPos + count) * bufr->channels, bufFrames2);
                 }
             } else { // non-loop
-                count =
-                    bufr->sndfile ? sf_readf_float(bufr->sndfile, bufr->data + mPos * bufr->channels, bufFrames2) : 0;
+                count = bufr->sndfile ? sf_readf_float(GETSNDFILE(bufr), bufr->data + mPos * bufr->channels, bufFrames2)
+                                      : 0;
                 if (count < bufFrames2) {
                     memset(bufr->data + (mPos + count) * bufr->channels, 0,
                            (bufFrames2 - count) * bufr->channels * sizeof(float));
@@ -469,13 +469,14 @@ static void VDiskIn_request_buffer(VDiskIn* unit, float fbufnum, uint32 bufFrame
         if ((int)ZIN0(2)) { // loop
             if (!bufr->sndfile)
                 memset(bufr->data + mPos * bufr->channels, 0, bufFrames2 * bufr->channels * sizeof(float));
-            count = sf_readf_float(bufr->sndfile, bufr->data + mPos * bufr->channels, bufFrames2);
+            count = sf_readf_float(GETSNDFILE(bufr), bufr->data + mPos * bufr->channels, bufFrames2);
             while (bufFrames2 -= count) {
-                sf_seek(bufr->sndfile, 0, SEEK_SET);
-                count = sf_readf_float(bufr->sndfile, bufr->data + (mPos + count) * bufr->channels, bufFrames2);
+                sf_seek(GETSNDFILE(bufr), 0, SEEK_SET);
+                count = sf_readf_float(GETSNDFILE(bufr), bufr->data + (mPos + count) * bufr->channels, bufFrames2);
             }
         } else { // non-loop
-            count = bufr->sndfile ? sf_readf_float(bufr->sndfile, bufr->data + mPos * bufr->channels, bufFrames2) : 0;
+            count =
+                bufr->sndfile ? sf_readf_float(GETSNDFILE(bufr), bufr->data + mPos * bufr->channels, bufFrames2) : 0;
             if (count < bufFrames2) {
                 memset(bufr->data + (mPos + count) * bufr->channels, 0,
                        (bufFrames2 - count) * bufr->channels * sizeof(float));
index 1782ae8e5c41a06db10337203995be59a9607ead..1f1d924e83dc729795174d489cbaaeaa0d6c81c9 100644 (file)
 
 #include "../../common/server_shm.hpp"
 
+#ifndef NO_LIBSNDFILE
+#    include <sndfile.h>
+#endif
+
 extern HashTable<struct UnitDef, Malloc>* gUnitDefLib;
 
 
index 4227355f3e94fe51762d9c78428da22c7d61f17a..6f54e87a5e4cecc50b2f86b2f325cc949a0cb7be 100644 (file)
@@ -375,7 +375,7 @@ bool BufFreeCmd::Stage2() {
     mFreeData = buf->data;
 #ifndef NO_LIBSNDFILE
     if (buf->sndfile)
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
 #endif
     SndBuf_Init(buf);
     return true;
@@ -600,7 +600,7 @@ bool BufReadCmd::Stage2() {
     }
 
     if (buf->sndfile)
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
 
     if (mLeaveFileOpen) {
         buf->sndfile = sf;
@@ -903,7 +903,7 @@ bool BufReadChannelCmd::Stage2() {
 
 leave:
     if (buf->sndfile)
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
 
     if (mLeaveFileOpen) {
         buf->sndfile = sf;
@@ -1014,7 +1014,7 @@ bool BufWriteCmd::Stage2() {
     }
 
     if (buf->sndfile)
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
 
     if (mLeaveFileOpen) {
         buf->sndfile = sf;
@@ -1057,7 +1057,7 @@ bool BufCloseCmd::Stage2() {
 #else
     SndBuf* buf = World_GetNRTBuf(mWorld, mBufIndex);
     if (buf->sndfile) {
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
         buf->sndfile = nullptr;
     }
     return true;
index e6ee49023b2ec8375836c4f82f01e3a7c7e7c6e9..e3de39e4ce2adf343a2116fc1d4ed04b27227cb0 100644 (file)
@@ -968,9 +968,9 @@ void World_Cleanup(World* world, bool unload_plugins) {
 
 #ifndef NO_LIBSNDFILE
         if (nrtbuf->sndfile)
-            sf_close(nrtbuf->sndfile);
+            sf_close(GETSNDFILE(nrtbuf));
         if (rtbuf->sndfile && rtbuf->sndfile != nrtbuf->sndfile)
-            sf_close(rtbuf->sndfile);
+            sf_close(GETSNDFILE(rtbuf));
 #endif
     }
 
index 4cfd13f083ff662fbf202200a981c1f319cd8eb4..1e9432903168280a77052a01c79116522a91a232 100644 (file)
@@ -1041,7 +1041,7 @@ void sc_plugin_interface::buffer_close(uint32_t index) {
 
     if (buf->sndfile == nullptr)
         return;
-    sf_close(buf->sndfile);
+    sf_close(GETSNDFILE(buf));
     buf->sndfile = nullptr;
 }
 
@@ -1070,7 +1070,7 @@ void sc_plugin_interface::buffer_sync(uint32_t index) noexcept {
 void sc_plugin_interface::free_buffer(uint32_t index) {
     SndBuf* buf = world.mSndBufsNonRealTimeMirror + index;
     if (buf->sndfile)
-        sf_close(buf->sndfile);
+        sf_close(GETSNDFILE(buf));
 
     sndbuf_init(buf);
 }