Skip to content

Commit

Permalink
Merge pull request #5761 from dyfer/topic/libsndfile-fix-2
Browse files Browse the repository at this point in the history
libsndfile: use a macro instead of redefining the struct
  • Loading branch information
dyfer committed Apr 25, 2022
2 parents 0f1466a + e93a0c8 commit 5c8e944
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions include/plugin_interface/SC_SndBuf.h
Expand Up @@ -22,7 +22,7 @@

#include <stdint.h>

typedef struct SNDFILE_tag SNDFILE;
#define GETSNDFILE(x) ((SNDFILE*)x->sndfile)

#ifdef SUPERNOVA

Expand Down Expand Up @@ -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;
Expand Down
29 changes: 15 additions & 14 deletions server/plugins/DiskIO_UGens.cpp
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions server/scsynth/SC_HiddenWorld.h
Expand Up @@ -37,6 +37,10 @@

#include "../../common/server_shm.hpp"

#ifndef NO_LIBSNDFILE
# include <SC_SndFileHelpers.hpp> // includes sndfile.h with appropriate configuration
#endif

extern HashTable<struct UnitDef, Malloc>* gUnitDefLib;


Expand Down
10 changes: 5 additions & 5 deletions server/scsynth/SC_SequencedCommand.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -600,7 +600,7 @@ bool BufReadCmd::Stage2() {
}

if (buf->sndfile)
sf_close(buf->sndfile);
sf_close(GETSNDFILE(buf));

if (mLeaveFileOpen) {
buf->sndfile = sf;
Expand Down Expand Up @@ -903,7 +903,7 @@ bool BufReadChannelCmd::Stage2() {

leave:
if (buf->sndfile)
sf_close(buf->sndfile);
sf_close(GETSNDFILE(buf));

if (mLeaveFileOpen) {
buf->sndfile = sf;
Expand Down Expand Up @@ -1014,7 +1014,7 @@ bool BufWriteCmd::Stage2() {
}

if (buf->sndfile)
sf_close(buf->sndfile);
sf_close(GETSNDFILE(buf));

if (mLeaveFileOpen) {
buf->sndfile = sf;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions server/scsynth/SC_World.cpp
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions server/supernova/sc/sc_plugin_interface.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5c8e944

Please sign in to comment.