Skip to content

Commit

Permalink
Improve classInit handling and documentation in faust2supercollider.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Nov 24, 2023
1 parent 215e72f commit f14658f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 33 deletions.
36 changes: 22 additions & 14 deletions architecture/supercollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ struct Faust : public Unit

// Global state

static size_t g_numControls; // Number of controls
static const char* g_unitName; // Unit name
static size_t g_numControls; // Number of controls
static const char* g_unitName; // Unit name
static int g_sampleRate = 48000; // Default SR

#ifdef SOUNDFILE
// Loaded soundfiles are shared between all UGen instances
Expand Down Expand Up @@ -380,15 +381,15 @@ inline static void Faust_updateControls(Faust* unit)

void Faust_next(Faust* unit, int inNumSamples)
{
// update controls
// Update controls
Faust_updateControls(unit);
// dsp computation
// DSP computation
unit->mDSP->compute(inNumSamples, unit->mInBuf, unit->mOutBuf);
}

void Faust_next_copy(Faust* unit, int inNumSamples)
{
// update controls
// Update controls
Faust_updateControls(unit);
// Copy buffers
for (int i = 0; i < unit->getNumAudioInputs(); ++i) {
Expand All @@ -403,7 +404,7 @@ void Faust_next_copy(Faust* unit, int inNumSamples)
unit->mInBufValue[i] = v1;
}
}
// dsp computation
// DSP computation
unit->mDSP->compute(inNumSamples, unit->mInBufCopy, unit->mOutBuf);
}

Expand All @@ -414,28 +415,34 @@ void Faust_next_clear(Faust* unit, int inNumSamples)

void Faust_Ctor(Faust* unit) // module constructor
{
// allocate dsp
// Allocate DSP
unit->mDSP = new(RTAlloc(unit->mWorld, sizeof(FAUSTCLASS))) FAUSTCLASS();
if (!unit->mDSP) {
Print("Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n", g_unitName);
goto end;
}
{
// init dsp
// Possibly call classInit again
if (SAMPLERATE != g_sampleRate) {
g_sampleRate = SAMPLERATE;
unit->mDSP->classInit(g_sampleRate);
}
// Init DSP
unit->mDSP->instanceInit((int)SAMPLERATE);

// allocate controls
// Allocate controls
unit->mNumControls = g_numControls;
ControlAllocator ca(unit->mControls);
unit->mDSP->buildUserInterface(&ca);
unit->mInBufCopy = 0;
unit->mInBufValue = 0;

#ifdef SOUNDFILE
// Access soundfiles
unit->mDSP->buildUserInterface(g_SoundInterface);
#endif

// check input/output channel configuration
// Check input/output channel configuration
const size_t numInputs = unit->mDSP->getNumInputs() + unit->mNumControls;
const size_t numOutputs = unit->mDSP->getNumOutputs();

Expand Down Expand Up @@ -505,7 +512,7 @@ void Faust_Ctor(Faust* unit) // module constructor
ClearUnitOutputs(unit, 1);
}

void Faust_Dtor(Faust* unit) // module destructor
void Faust_Dtor(Faust* unit) // Module destructor
{
if (unit->mInBufValue) {
RTFree(unit->mWorld, unit->mInBufValue);
Expand Down Expand Up @@ -542,7 +549,8 @@ FAUST_EXPORT void load(InterfaceTable* inTable)

#ifdef SOUNDFILE
Soundfile::Directories soundfile_dirs
= { defaultUserAppSupportDirectory(),
= {
defaultUserAppSupportDirectory(),
defaultSoundfilesDirectory(),
defaultSoundfilesDirectory1(),
SoundUI::getBinaryPath()
Expand Down Expand Up @@ -571,8 +579,8 @@ FAUST_EXPORT void load(InterfaceTable* inTable)

g_unitName = STRDUP(name.c_str());

// TODO: use correct sample rate
tmp_dsp->classInit(48000);
// Use the default SR
tmp_dsp->classInit(g_sampleRate);
ControlCounter cc;
tmp_dsp->buildUserInterface(&cc);
g_numControls = cc.getNumControls();
Expand Down
55 changes: 36 additions & 19 deletions tools/faust2appls/faust2supercollider
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

. faustpath
. faustoptflags
. usage.sh

CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
UNIVERSAL="0"
Expand Down Expand Up @@ -59,16 +60,9 @@ fi

INCLUDE="-I$SC/plugin_interface/ -I$SC/common/ -I$SC/server/ -I$FAUSTINC"

if [ $# = 0 ]; then
echo USAGE:
echo "$0 [-d[ebug]] [-dm] [-sd] [-ks] [-sn] [-noprefix] [-soundfile] [-universal] file1.dsp [file2.dsp ...]"
exit 1
fi

#-------------------------------------------------------------------
# Analyze command arguments :
# faust options -> OPTIONS
# if -omp : -openmp or -fopenmp -> OPENMP
# if -d or -debug -> F2SC_DEBUG
# if -dm -> F2SC_DEBUG_MES
# if -ks -> KEEP_SRC
Expand All @@ -86,18 +80,45 @@ F2SC_DEBUG_MES=0
SUPERNOVA_FLAG=0
KEEP_SRC=0
SYNTHDEF=""
NO_FAUST_PREFIX=0
SC_FAUST_PREFIX="Faust"

echoHelp()
{
usage faust2supercollider "[options] [Faust options] <file.dsp>"
require SuperCollider includes
echo "Compiles Faust programs to SuperCollider UGens. On macOS, soundfiles will be searched in 'xx/Library/Application Support/SuperCollider/Extensions/' and 'xx/Library/Application Support/SuperCollider/Extensions/FaustSounds'"
option
option "-d[ebug]" "to activate debug mode"
option "-dm" "to activate debug message mode"
option "-sd" "activate the --synthdef option in faust2sc"
option "-ks" "to keep the UGen source"
option "-sn" "to compile for SuperNova"
option "-noprefix" "to remove the standard 'Faust' prefix"
options -soundfile
option -universal "to generate a universal (arm/intel) UGens"
option "Faust options"
exit
}


if [ "$#" -eq 0 ]; then
echo 'Please, provide a Faust file to process !'
echo ''
echoHelp
fi

for p in $@; do

if [ "$p" = -debug ] || [ "$p" = -d ]; then
if [ $p = "-help" ] || [ $p = "-h" ]; then
echoHelp
elif [ "$p" = -debug ] || [ "$p" = -d ]; then
F2SC_DEBUG=1
elif [ "$p" = -dm ]; then
F2SC_DEBUG_MES=1
elif [ "$p" = -ks ]; then
KEEP_SRC=1
elif [ "$p" = -noprefix ]; then
NO_FAUST_PREFIX=1
SC_FAUST_PREFIX=""
elif [ "$p" = -sd ] || [ "$p" = -synthdef ]; then
SYNTHDEF="--synthdef"
elif [ "$p" = -sn ] || [ "$p" = -supernova ]; then
Expand Down Expand Up @@ -132,10 +153,11 @@ else
DNDEBUG="-DNDEBUG"
fi

if [ "$FILES" = "" ]; then
echo USAGE:
echo "$0 [-d[ebug]] [-dm] [-sd] [-ks] [-sn] [-noprefix] [-soundfile] [-universal] file1.dsp [file2.dsp ...]"
exit 1

if [ "$#" -eq 0 ]; then
echo 'Please, provide a Faust file to process !'
echo ''
echoHelp
fi

#-------------------------------------------------------------------
Expand Down Expand Up @@ -183,11 +205,6 @@ for p in $FILES; do

# compile c++ to binary; --prefix should be same as in ../../examples/Makefile.sccompile
(
SC_FAUST_PREFIX="Faust"
if [ $NO_FAUST_PREFIX = 1 ]; then
SC_FAUST_PREFIX=""
fi

cd "$TMP"
faust2sc --prefix="$SC_FAUST_PREFIX" $SYNTHDEF "$f.xml" > "${f%.dsp}.sc" 2>$OUTDEV
BUILDFLAGS="$FAUSTTOOLSFLAGS $SCFLAGS -I$CUR $INCLUDE $CXXFLAGS $OMP -DSC_FAUST_PREFIX=\"$SC_FAUST_PREFIX\""
Expand Down

0 comments on commit f14658f

Please sign in to comment.