Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions architecture/supercollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,17 @@ void Faust_next_clear(Faust* unit, int inNumSamples)

void Faust_Ctor(Faust* unit) // module constructor
{
// init such that those values can be freed if any alloc fails
unit->mDSP = nullptr;
unit->mInBufCopy = nullptr;
unit->mInBufValue = nullptr;
unit->mControlInputs = nullptr;
unit->mControlOutputs = nullptr;

// 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;
}
void* mem = RTAlloc(unit->mWorld, sizeof(FAUSTCLASS));
ClearUnitIfMemFailed(mem);
unit->mDSP = new(mem) FAUSTCLASS();
{
// Possibly call classInit again
if (SAMPLERATE != g_sampleRate) {
Expand All @@ -513,8 +518,6 @@ void Faust_Ctor(Faust* unit) // module constructor

ControlAllocator ca(unit->mControls);
unit->mDSP->buildUserInterface(&ca);
unit->mInBufCopy = nullptr;
unit->mInBufValue = nullptr;

#ifdef SOUNDFILE
// Access soundfiles
Expand All @@ -529,7 +532,9 @@ void Faust_Ctor(Faust* unit) // module constructor

// Build mControlInputs and mControlOutputs so that getInputControl/getOutputControl have O[1] cost
unit->mControlInputs = (Control**)RTAlloc(unit->mWorld, unit->mNumControlInput*sizeof(Control*));
ClearUnitIfMemFailed(unit->mControlInputs);
unit->mControlOutputs = (Control**)RTAlloc(unit->mWorld, unit->mNumControlOutput*sizeof(Control*));
ClearUnitIfMemFailed(unit->mControlOutputs);

for (int i = 0; i < unit->mNumControlInput; ++i) {
unit->mControlInputs[i] = unit->getInputControlAux(i);
Expand All @@ -550,24 +555,15 @@ void Faust_Ctor(Faust* unit) // module constructor
SETCALC(Faust_next);
} else {
unit->mInBufCopy = (float**)RTAlloc(unit->mWorld, unit->mDSP->getNumInputs()*sizeof(float*));
if (!unit->mInBufCopy) {
Print("Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n", g_unitName);
goto end;
}
ClearUnitIfMemFailed(unit->mInBufCopy);
// Allocate memory for input buffer copies (numInputs * bufLength)
// and linear interpolation state (numInputs)
// = numInputs * (bufLength + 1)
unit->mInBufValue = (float*)RTAlloc(unit->mWorld, unit->mDSP->getNumInputs()*sizeof(float));
if (!unit->mInBufValue) {
Print("Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n", g_unitName);
goto end;
}
ClearUnitIfMemFailed(unit->mInBufValue);
// Aquire memory for interpolator state.
float* mem = (float*)RTAlloc(unit->mWorld, unit->mDSP->getNumInputs()*BUFLENGTH*sizeof(float));
if (mem) {
Print("Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n", g_unitName);
goto end;
}
ClearUnitIfMemFailed(mem);
for (int i = 0; i < unit->mDSP->getNumInputs(); ++i) {
// Initialize interpolator.
unit->mInBufValue[i] = IN0(i);
Expand Down Expand Up @@ -597,7 +593,6 @@ void Faust_Ctor(Faust* unit) // module constructor
}
}

end:
// Fix for https://github.com/grame-cncm/faust/issues/13
ClearUnitOutputs(unit, 1);
}
Expand All @@ -615,7 +610,9 @@ void Faust_Dtor(Faust* unit) // Module destructor
}

// delete dsp
unit->mDSP->~FAUSTCLASS();
if (unit->mDSP != nullptr) {
unit->mDSP->~FAUSTCLASS();
}
RTFree(unit->mWorld, unit->mDSP);

RTFree(unit->mWorld, unit->mControlInputs);
Expand Down