Skip to content

Commit

Permalink
Move SincDelay line; upgrade Endia; tiny other (surge-synthesizer#6968)
Browse files Browse the repository at this point in the history
1. SSESincDelayLine moves to basic blocks
2. the vt_read_blah use the ::endian
3. FIx the README and OSC problems from the accidental push last night
  • Loading branch information
baconpaul authored Apr 21, 2023
1 parent 46050fd commit cee4631
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 282 deletions.
4 changes: 0 additions & 4 deletions src/cmake/lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ file(MAKE_DIRECTORY ${SURGE_PRODUCT_DIR})

add_custom_target(surge-xt-distribution)
add_custom_target(surge-staged-assets)
add_custom_command(TARGET surge-xt-distribution
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/resources/surge-xt/README.txt ${SURGE_PRODUCT_DIR}
)

function(surge_juce_package target product_name)
get_target_property(output_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
Expand Down
1 change: 0 additions & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ add_library(${PROJECT_NAME}
dsp/vembertech/portable_intrinsics.h
dsp/vembertech/shared.h
dsp/vembertech/vt_dsp.h
dsp/vembertech/vt_dsp_endian.h
globals.h
resource.h
version.cpp.in
Expand Down
11 changes: 7 additions & 4 deletions src/common/PatchDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include "SurgeStorage.h"
#include <sstream>
#include <iterator>
#include "vt_dsp_endian.h"
#include "DebugHelpers.h"
#include <chrono>

#include "sst/basic-blocks/mechanics/endian-ops.h"
namespace mech = sst::basic_blocks::mechanics;

#define TRACE_DB 0

namespace Surge
Expand Down Expand Up @@ -848,15 +850,16 @@ CREATE TABLE IF NOT EXISTS Favorites (

uint8_t *d = contents.data();
auto *fxp = (fxChunkSetCustom *)d;
if ((vt_read_int32BE(fxp->chunkMagic) != 'CcnK') ||
(vt_read_int32BE(fxp->fxMagic) != 'FPCh') || (vt_read_int32BE(fxp->fxID) != 'cjs3'))
if ((mech::endian_read_int32BE(fxp->chunkMagic) != 'CcnK') ||
(mech::endian_read_int32BE(fxp->fxMagic) != 'FPCh') ||
(mech::endian_read_int32BE(fxp->fxID) != 'cjs3'))
{
return;
}

auto phd = d + sizeof(fxChunkSetCustom);
auto *ph = (patch_header *)phd;
auto xmlSz = vt_read_int32LE(ph->xmlsize);
auto xmlSz = mech::endian_read_int32LE(ph->xmlsize);

if (!memcpy(ph->tag, "sub3", 4) || xmlSz < 0 || xmlSz > 1024 * 1024 * 1024)
{
Expand Down
22 changes: 12 additions & 10 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "SurgeParamConfig.h"
#include "Effect.h"
#include <list>
#include <vembertech/vt_dsp_endian.h>
#include "MSEGModulationHelper.h"
#include "FormulaModulationHelper.h"
#include "DebugHelpers.h"
Expand All @@ -30,6 +29,9 @@
#include <locale>
#include <fmt/format.h>

#include "sst/basic-blocks/mechanics/endian-ops.h"
namespace mech = sst::basic_blocks::mechanics;

using namespace std;
using namespace Surge::ParamConfig;

Expand Down Expand Up @@ -1099,7 +1101,7 @@ void SurgePatch::load_patch(const void *data, int datasize, bool preset)
assert(data);
void *end = (char *)data + datasize;
patch_header *ph = (patch_header *)data;
ph->xmlsize = vt_read_int32LE(ph->xmlsize);
ph->xmlsize = mech::endian_read_int32LE(ph->xmlsize);

if (!memcmp(ph->tag, "sub3", 4))
{
Expand All @@ -1111,7 +1113,7 @@ void SurgePatch::load_patch(const void *data, int datasize, bool preset)
{
for (int osc = 0; osc < n_oscs; osc++)
{
ph->wtsize[sc][osc] = vt_read_int32LE(ph->wtsize[sc][osc]);
ph->wtsize[sc][osc] = mech::endian_read_int32LE(ph->wtsize[sc][osc]);
if (ph->wtsize[sc][osc])
{
wt_header *wth = (wt_header *)dr;
Expand Down Expand Up @@ -1180,7 +1182,7 @@ unsigned int SurgePatch::save_patch(void **data)

memcpy(header.tag, "sub3", 4);
size_t xmlsize = save_xml(&xmldata);
header.xmlsize = vt_write_int32LE(xmlsize);
header.xmlsize = mech::endian_write_int32LE(xmlsize);
wt_header wth[n_scenes][n_oscs];
for (int sc = 0; sc < n_scenes; sc++)
{
Expand All @@ -1196,7 +1198,7 @@ unsigned int SurgePatch::save_patch(void **data)
unsigned int wtsize =
wth[sc][osc].n_samples * scene[sc].osc[osc].wt.n_tables * sizeof(short) +
sizeof(wt_header);
header.wtsize[sc][osc] = vt_write_int32LE(wtsize);
header.wtsize[sc][osc] = mech::endian_write_int32LE(wtsize);
psize += wtsize;
}
else
Expand All @@ -1221,21 +1223,21 @@ unsigned int SurgePatch::save_patch(void **data)
{
if (header.wtsize[sc][osc])
{
size_t wtsize = vt_read_int32LE(header.wtsize[sc][osc]);
size_t wtsize = mech::endian_read_int32LE(header.wtsize[sc][osc]);
int n_tables = wth[sc][osc].n_tables;
int n_samples = wth[sc][osc].n_samples;

// do all endian swapping for the wavetables in one place (for ppc)
wth[sc][osc].n_samples = vt_write_int32LE(wth[sc][osc].n_samples);
wth[sc][osc].n_tables = vt_write_int16LE(wth[sc][osc].n_tables);
wth[sc][osc].flags = vt_write_int16LE(wth[sc][osc].flags | wtf_int16);
wth[sc][osc].n_samples = mech::endian_write_int32LE(wth[sc][osc].n_samples);
wth[sc][osc].n_tables = mech::endian_write_int16LE(wth[sc][osc].n_tables);
wth[sc][osc].flags = mech::endian_write_int16LE(wth[sc][osc].flags | wtf_int16);

memcpy(dw, &wth[sc][osc], sizeof(wt_header));
short *fp = (short *)(char *)(dw + sizeof(wt_header));

for (int j = 0; j < n_tables; j++)
{
vt_copyblock_W_LE(
mech::endian_copyblock16LE(
&fp[j * n_samples],
&scene[sc].osc[osc].wt.TableI16WeakPointers[0][j][FIRoffsetI16], n_samples);
}
Expand Down
20 changes: 13 additions & 7 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <cctype>
#include <map>
#include <queue>
#include <vembertech/vt_dsp_endian.h>
#include "UserDefaults.h"
#if HAS_JUCE
#include "SurgeSharedBinary.h"
Expand Down Expand Up @@ -51,6 +50,9 @@
// FIXME
#include "FormulaModulationHelper.h"

#include "sst/basic-blocks/mechanics/endian-ops.h"
namespace mech = sst::basic_blocks::mechanics;

using namespace std;

std::string SurgeStorage::skipPatchLoadDataPathSentinel = "<SKIP-PATCH-SENTINEL>";
Expand Down Expand Up @@ -1187,13 +1189,15 @@ bool SurgeStorage::load_wt_wt(string filename, Wavetable *wt)

size_t ds;

if (vt_read_int16LE(wh.flags) & wtf_int16)
if (mech::endian_read_int16LE(wh.flags) & wtf_int16)
{
ds = sizeof(short) * vt_read_int16LE(wh.n_tables) * vt_read_int32LE(wh.n_samples);
ds = sizeof(short) * mech::endian_read_int16LE(wh.n_tables) *
mech::endian_read_int32LE(wh.n_samples);
}
else
{
ds = sizeof(float) * vt_read_int16LE(wh.n_tables) * vt_read_int32LE(wh.n_samples);
ds = sizeof(float) * mech::endian_read_int16LE(wh.n_tables) *
mech::endian_read_int32LE(wh.n_samples);
}

const std::unique_ptr<char[]> data{new char[ds]};
Expand Down Expand Up @@ -1251,10 +1255,12 @@ bool SurgeStorage::load_wt_wt_mem(const char *data, size_t dataSize, Wavetable *
}

size_t ds;
if (vt_read_int16LE(wh.flags) & wtf_int16)
ds = sizeof(short) * vt_read_int16LE(wh.n_tables) * vt_read_int32LE(wh.n_samples);
if (mech::endian_read_int16LE(wh.flags) & wtf_int16)
ds = sizeof(short) * mech::endian_read_int16LE(wh.n_tables) *
mech::endian_read_int32LE(wh.n_samples);
else
ds = sizeof(float) * vt_read_int16LE(wh.n_tables) * vt_read_int32LE(wh.n_samples);
ds = sizeof(float) * mech::endian_read_int16LE(wh.n_tables) *
mech::endian_read_int32LE(wh.n_samples);

if (dataSize < ds + sizeof(wt_header))
{
Expand Down
31 changes: 17 additions & 14 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "SurgeSynthesizer.h"
#include "DSPUtils.h"
#include <time.h>
#include <vembertech/vt_dsp_endian.h>

#include "filesystem/import.h"

Expand All @@ -25,6 +24,9 @@
#include <iterator>
#include "SurgeMemoryPools.h"

#include "sst/basic-blocks/mechanics/endian-ops.h"
namespace mech = sst::basic_blocks::mechanics;

using namespace std;

// seems to be missing from VST2.3, so it's copied from the VST list instead
Expand Down Expand Up @@ -225,13 +227,14 @@ bool SurgeSynthesizer::loadPatchByPath(const char *fxpPath, int categoryId, cons
fxChunkSetCustom fxp;
auto read = f.sgetn(reinterpret_cast<char *>(&fxp), sizeof(fxp));
// FIXME - error if read != chunk size
if ((vt_read_int32BE(fxp.chunkMagic) != 'CcnK') || (vt_read_int32BE(fxp.fxMagic) != 'FPCh') ||
(vt_read_int32BE(fxp.fxID) != 'cjs3'))
if ((mech::endian_read_int32BE(fxp.chunkMagic) != 'CcnK') ||
(mech::endian_read_int32BE(fxp.fxMagic) != 'FPCh') ||
(mech::endian_read_int32BE(fxp.fxID) != 'cjs3'))
{
f.close();
auto cm = vt_read_int32BE(fxp.chunkMagic);
auto fm = vt_read_int32BE(fxp.fxMagic);
auto id = vt_read_int32BE(fxp.fxID);
auto cm = mech::endian_read_int32BE(fxp.chunkMagic);
auto fm = mech::endian_read_int32BE(fxp.fxMagic);
auto id = mech::endian_read_int32BE(fxp.fxID);

std::ostringstream oss;
oss << "Unable to load " << patchName << ".fxp!";
Expand Down Expand Up @@ -259,7 +262,7 @@ bool SurgeSynthesizer::loadPatchByPath(const char *fxpPath, int categoryId, cons
return false;
}

int cs = vt_read_int32BE(fxp.chunkSize);
int cs = mech::endian_read_int32BE(fxp.chunkSize);
std::unique_ptr<char[]> data{new char[cs]};

if (f.sgetn(data.get(), cs) != cs)
Expand Down Expand Up @@ -609,18 +612,18 @@ void SurgeSynthesizer::savePatchToPath(fs::path filename, bool refreshPatchList)
}

fxChunkSetCustom fxp;
fxp.chunkMagic = vt_write_int32BE('CcnK');
fxp.fxMagic = vt_write_int32BE('FPCh');
fxp.fxID = vt_write_int32BE('cjs3');
fxp.numPrograms = vt_write_int32BE(1);
fxp.version = vt_write_int32BE(1);
fxp.fxVersion = vt_write_int32BE(1);
fxp.chunkMagic = mech::endian_write_int32BE('CcnK');
fxp.fxMagic = mech::endian_write_int32BE('FPCh');
fxp.fxID = mech::endian_write_int32BE('cjs3');
fxp.numPrograms = mech::endian_write_int32BE(1);
fxp.version = mech::endian_write_int32BE(1);
fxp.fxVersion = mech::endian_write_int32BE(1);
strncpy(fxp.prgName, storage.getPatch().name.c_str(), 28);

void *data;
unsigned int datasize = storage.getPatch().save_patch(&data);

fxp.chunkSize = vt_write_int32BE(datasize);
fxp.chunkSize = mech::endian_write_int32BE(datasize);
fxp.byteSize = 0;

f.write((char *)&fxp, sizeof(fxChunkSetCustom));
Expand Down
18 changes: 10 additions & 8 deletions src/common/dsp/Wavetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include <assert.h>
#include "DSPUtils.h"
#include <vembertech/basic_dsp.h>
#include <vembertech/vt_dsp_endian.h>
#include "SurgeStorage.h"

#include "sst/basic-blocks/mechanics/endian-ops.h"
namespace mech = sst::basic_blocks::mechanics;

#if WINDOWS
#include <intrin.h>
#endif
Expand Down Expand Up @@ -155,9 +157,9 @@ bool Wavetable::BuildWT(void *wdata, wt_header &wh, bool AppendSilence)
{
assert(wdata);

flags = vt_read_int16LE(wh.flags);
n_tables = vt_read_int16LE(wh.n_tables);
size = vt_read_int32LE(wh.n_samples);
flags = mech::endian_read_int16LE(wh.flags);
n_tables = mech::endian_read_int16LE(wh.n_tables);
size = mech::endian_read_int32LE(wh.n_samples);

size_t req_size = RequiredWTSize(size, n_tables);

Expand Down Expand Up @@ -220,8 +222,8 @@ bool Wavetable::BuildWT(void *wdata, wt_header &wh, bool AppendSilence)
{
for (int j = 0; j < wdata_tables; j++)
{
vt_copyblock_W_LE(&this->TableI16WeakPointers[0][j][FIRoffsetI16],
&((short *)wdata)[this->size * j], this->size);
mech::endian_copyblock16LE(&this->TableI16WeakPointers[0][j][FIRoffsetI16],
&((short *)wdata)[this->size * j], this->size);
if (this->flags & wtf_int16_is_16)
{
i16toi15_block(&this->TableI16WeakPointers[0][j][FIRoffsetI16],
Expand All @@ -235,8 +237,8 @@ bool Wavetable::BuildWT(void *wdata, wt_header &wh, bool AppendSilence)
{
for (int j = 0; j < wdata_tables; j++)
{
vt_copyblock_DW_LE((int *)this->TableF32WeakPointers[0][j],
&((int *)wdata)[this->size * j], this->size);
mech::endian_copyblock32LE((int32_t *)this->TableF32WeakPointers[0][j],
&((int32_t *)wdata)[this->size * j], this->size);
float2i15_block(this->TableF32WeakPointers[0][j],
&this->TableI16WeakPointers[0][j][FIRoffsetI16], this->size);
}
Expand Down
Loading

0 comments on commit cee4631

Please sign in to comment.