Skip to content

Commit

Permalink
Cleanup -os/-memX related code.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Jan 23, 2025
1 parent f15fa39 commit 4e56e5a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 33 deletions.
2 changes: 2 additions & 0 deletions compiler/generator/cmajor/cmajor_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using namespace std;
- sub-containers are compiled as 'struct' with associated functions
- classInit is a Processor method for now (waiting for the Cmajor external model to be ready)
- gExtControl is used, 'control' function is generated as well as 'main' function
- in gOneSampleIO mode, inputXX/outputXX are added in the DSP struct.
- 'faustpower' function fallbacks to regular 'pow' (see powprim.h)
- the 'fillXXX' function needs to generate the actual size of the table argument type. This is done
using the TableSizeVisitor class.
Expand Down
8 changes: 4 additions & 4 deletions compiler/generator/codebox/codebox_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace std;
- variable identifiers cannot end by a number, so add a "_cb" suffix
- all init code is done in 'dspsetup', called when audio start or in case of SR change
- gOneSampleControl mode is used, 'control' function is generated as well as 'update' function
- gExtControl is used, 'control' function is generated as well as 'update' function
which call 'control' only when needed (that is when as least one parameter changes)
- 'compute' returns the list of audio outputs (and possibly additional audio outputs for bargraph)
- MIDI support: https://rnbo.cycling74.com/learn/midi-in-rnbo, done in the architecture file, by
Expand All @@ -51,9 +51,9 @@ done in architecture file, creating the 'notein' and decoding MIDI messaged to u
freq/gain/gate parameters
- bargraph values cannot directly be send as control values. So additional audio outputs are
created for them, will be sampled (using 'snapshot~' and 'change') and be connected to 'param'
objects, like input controllers.
- in gOneSampleControl mode, inputXX/outputXX are added in the DSP struct. Here they are generated
as local variables at the begining of 'compute'.
objects, like input controllers
- in gOneSampleIO mode, inputXX/outputXX are added in the DSP struct. Here they are generated
as local variables at the begining of 'compute'
TODO:
- soundfile primitive support: https://rnbo.cycling74.com/learn/audio-files-in-rnbo
Expand Down
25 changes: 5 additions & 20 deletions compiler/generator/instructions_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void InstructionsCompiler::compileMultiSignal(Tree L)
"input", "inputs", fContainer->inputs(), ptr_type, false));
} else if (gGlobal->gOutputLang != "jax") {
// "input" and "inputs" used as a name convention
if (gGlobal->gOneSampleControl) {
if (gGlobal->gOneSampleIO) {
for (int index = 0; index < fContainer->inputs(); index++) {
string name = subst("input$0", T(index));
pushDeclare(IB::genDecStructVar(name, type));
Expand Down Expand Up @@ -556,7 +556,7 @@ void InstructionsCompiler::compileMultiSignal(Tree L)
"output", "outputs", fContainer->outputs(), ptr_type, true));
} else if (gGlobal->gOutputLang != "jax") {
// "output" and "outputs" used as a name convention
if (gGlobal->gOneSampleControl) {
if (gGlobal->gOneSampleIO) {
for (int index = 0; index < fContainer->outputs(); index++) {
string name = subst("output$0", T(index));
pushDeclare(IB::genDecStructVar(name, type));
Expand Down Expand Up @@ -606,7 +606,7 @@ void InstructionsCompiler::compileMultiSignal(Tree L)
return_string = return_string + sep + result_var;
sep = ",";
pushComputeDSPMethod(IB::genStoreStackVar(result_var, res));
} else if (gGlobal->gOneSampleControl) {
} else if (gGlobal->gOneSampleIO) {
name = subst("output$0", T(index));
if (gGlobal->gComputeMix) {
ValueInst* res1 = IB::genAdd(res, IB::genLoadStackVar(name));
Expand Down Expand Up @@ -909,8 +909,7 @@ ValueInst* InstructionsCompiler::generateFVar(Tree sig, Tree type, const string&
{
// Check access (handling 'fFullCount' as a special case)
if ((name != fFullCount && !gGlobal->gAllowForeignVar) ||
(name == fFullCount &&
(gGlobal->gOneSample || gGlobal->gOneSampleControl || gGlobal->gExtControl))) {
(name == fFullCount && (gGlobal->gOneSample || gGlobal->gExtControl))) {
stringstream error;
error << "ERROR : accessing foreign variable '" << name << "'"
<< " is not allowed in this compilation mode" << endl;
Expand Down Expand Up @@ -943,7 +942,7 @@ ValueInst* InstructionsCompiler::generateInput(Tree sig, int idx)
res = IB::genLoadStackVar(subst("*io$0", T(idx)));
} else if (gGlobal->gOutputLang == "jax") {
res = IB::genLoadArrayStackVar("inputs", IB::genInt32NumInst(idx));
} else if (gGlobal->gOneSampleControl) {
} else if (gGlobal->gOneSampleIO) {
res = IB::genLoadStructVar(subst("input$0", T(idx)));
} else if (gGlobal->gOneSample) {
res = IB::genLoadArrayStackVar("inputs", IB::genInt32NumInst(idx));
Expand Down Expand Up @@ -1726,20 +1725,6 @@ ValueInst* InstructionsCompiler::generateStaticTable(Tree sig, Tree tsize, Tree
args1.push_back(IB::genLoadFunArgsVar("sample_rate"));
pushStaticInitMethod(IB::genVoidFunCallInst("instanceInit" + tablename, args1, true));

if (gGlobal->gMemoryManager && (gGlobal->gOneSample == -1)) {
Values alloc_args;
alloc_args.push_back(IB::genLoadStaticStructVar("fManager"));
alloc_args.push_back(IB::genInt32NumInst(size * ctype->getSizeBytes()));
pushStaticInitMethod(IB::genStoreStaticStructVar(
vname, IB::genCastInst(IB::genFunCallInst("allocate", alloc_args, true),
IB::genArrayTyped(ctype, 0))));

Values destroy_args;
destroy_args.push_back(IB::genLoadStaticStructVar("fManager"));
destroy_args.push_back(IB::genLoadStaticStructVar(vname));
pushStaticDestroyMethod(IB::genVoidFunCallInst("destroy", destroy_args, true));
}

// Fill the table
Values args2;
args2.push_back(signame);
Expand Down
2 changes: 1 addition & 1 deletion compiler/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void global::reset()
gNeedManualPow = true;
gRemoveVarAddress = false;
gOneSample = false;
gOneSampleControl = false;
gOneSampleIO = false;
gExtControl = false;
gInlineTable = false;
gComputeMix = false;
Expand Down
7 changes: 3 additions & 4 deletions compiler/global.hh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct global {
bool gEnableFlag; // -es option (0/1: 0 by default)
bool gNoVirtual; // -nvi option, when compiled with the C++ backend, does not add the 'virtual'
// keyword
int gMemoryManager; // -mem option
int gMemoryManager; // -memX options
bool gRangeUI; // -rui option, whether to generate code to limit vslider/hslider/nentry values
// in [min..max] range
bool gFreezeUI; // -fui option, whether to freeze vslider/hslider/nentry to a given value (init
Expand Down Expand Up @@ -229,9 +229,8 @@ struct global {
bool gNeedManualPow; // If manual pow(x, y) generation when y is an integer is needed
bool gRemoveVarAddress; // If use of variable addresses (like &foo or &foo[n]) have to be
// removed
int gOneSample; // -osX options, generate one sample computation
bool gOneSampleControl; // -osX options, generate one sample computation control structure in
// DSP module
bool gOneSample; // -os option, generate one sample computation
bool gOneSampleIO; // generate one sample computation inputs/outputs access
int gExtControl; // separated 'control' and 'compute' functions
bool gInlineTable; // -it option, only in -cpp backend, to inline rdtable/rwtable code in the
// main class.
Expand Down
8 changes: 4 additions & 4 deletions compiler/libcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ static void compileCodebox(Tree signals, int numInputs, int numOutputs, ostream*
// FIR is generated with internal real instead of FAUSTFLOAT (see IB::genBasicTyped)
gGlobal->gFAUSTFLOAT2Internal = true;

// "one sample control" model by default;
gGlobal->gOneSampleControl = true;
// "one sample inputs/outputs" model by default
gGlobal->gOneSampleIO = true;
// Standard pow function will be used in pow(x,y) when y in an integer
gGlobal->gNeedManualPow = false;

Expand Down Expand Up @@ -729,8 +729,8 @@ static void compileCmajor(Tree signals, int numInputs, int numOutputs, ostream*
// FIR is generated with internal real instead of FAUSTFLOAT (see IB::genBasicTyped)
gGlobal->gFAUSTFLOAT2Internal = true;

// "one sample control" model by default;
gGlobal->gOneSampleControl = true;
// "one sample inputs/outputs" model by default
gGlobal->gOneSampleIO = true;
// Standard pow function will be used in pow(x,y) when y in an integer
gGlobal->gNeedManualPow = false;

Expand Down

0 comments on commit 4e56e5a

Please sign in to comment.