Skip to content

Commit

Permalink
BelaScope: create in SC_World, setup in SC_Bela
Browse files Browse the repository at this point in the history
  • Loading branch information
elgiano committed Oct 14, 2020
1 parent 1a424fd commit abecc8b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
10 changes: 5 additions & 5 deletions SCClassLibrary/Common/Audio/bela/BELAUGens.sc
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ DigitalIO : UGen {
* input 2: bus number
*/
BelaScopeUGen : UGen {
*ar { arg maxChannels, busnum;
^super.performList('new1', 'audio', maxChannels, In.ar(busnum, maxChannels));
}
numOutputs { ^0 }
writeOutputSpecs {}
*ar { arg maxChannels, busnum;
^super.performList('new1', 'audio', maxChannels, In.ar(busnum, maxChannels));
}
numOutputs { ^0 }
writeOutputSpecs {}
}
2 changes: 2 additions & 0 deletions include/plugin_interface/SC_World.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#ifdef BELA
#include "Bela.h"
#include "../libraries/Scope/Scope.h"
#endif

#include "SC_Types.h"
Expand Down Expand Up @@ -112,6 +113,7 @@ struct World

#ifdef BELA
BelaContext *mBelaContext;
Scope *mBelaScope;
// uint32 mBelaAnalogChannels;
uint32 mBelaAnalogInputChannels;
uint32 mBelaAnalogOutputChannels;
Expand Down
10 changes: 3 additions & 7 deletions server/plugins/BELAUGens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <atomic>

#include "Bela.h"
#include "libraries/Scope/Scope.h"
// These functions are provided by xenomai
int rt_printf(const char *format, ...);
int rt_fprintf(FILE *stream, const char *format, ...);
Expand Down Expand Up @@ -1360,7 +1359,7 @@ void BelaScopeUGen_next(BelaScopeUGen *unit, unsigned int numSamples)

LOOP1(numSamples,
for(unsigned int ch = 0; ch < numChannels; ++ch)
frameData[ch] = ZXP(inputPointers[ch]);//*(IN(1+ch)+n);
frameData[ch] = ZXP(inputPointers[ch]);
unit->belaScope->log(frameData);
)
}
Expand All @@ -1370,8 +1369,7 @@ void BelaScopeUGen_Ctor(BelaScopeUGen *unit)
BelaContext *context = unit->mWorld->mBelaContext;
unsigned int numChannels = static_cast<unsigned int>(IN0(0));
unit->frameData = (float*) RTAlloc(unit->mWorld, sizeof(float)*numChannels);
unit->belaScope = new Scope();
unit->belaScope->setup(numChannels, context->audioSampleRate);
unit->belaScope = unit->mWorld->mBelaScope;
unit->noScopeChannels = numChannels;
// initiate first sample
BelaScopeUGen_next( unit, 1);
Expand All @@ -1381,8 +1379,6 @@ void BelaScopeUGen_Ctor(BelaScopeUGen *unit)

void BelaScopeUGen_Dtor(BelaScopeUGen *unit)
{
unit->belaScope->cleanup();
delete unit->belaScope;
RTFree(unit->mWorld, unit->frameData);
}

Expand Down Expand Up @@ -1436,7 +1432,7 @@ PluginLoad(BELA)
DefineSimpleUnit(DigitalIn);
DefineSimpleUnit(DigitalOut);
DefineSimpleUnit(DigitalIO);
DefineDtorUnit(BelaScopeUGen);
DefineDtorUnit(BelaScopeUGen);
}


Expand Down
4 changes: 2 additions & 2 deletions server/scsynth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ elseif(AUDIOAPI STREQUAL portaudio)
target_link_libraries(libscsynth ${PORTAUDIO_LIBRARIES})
endif()
elseif(AUDIOAPI STREQUAL bela)
target_link_libraries(libscsynth ${XENOMAI_LIBRARIES} ${BELA_LIBRARIES})
target_link_libraries(libscsynth ${XENOMAI_LIBRARIES} ${BELA_LIBRARIES} belaextra)
elseif(AUDIOAPI STREQUAL coreaudio)
target_link_libraries(libscsynth "-framework CoreAudio")
endif()
Expand Down Expand Up @@ -238,7 +238,7 @@ add_executable(scsynth scsynth_main.cpp)
target_link_libraries(scsynth libscsynth)

if(AUDIOAPI STREQUAL bela)
target_link_libraries(scsynth ${XENOMAI_LIBRARIES} ${BELA_LIBRARIES})
target_link_libraries(scsynth ${XENOMAI_LIBRARIES} ${BELA_LIBRARIES} belaextra)
endif()

if (PTHREADS_FOUND)
Expand Down
6 changes: 5 additions & 1 deletion server/scsynth/SC_Bela.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class SC_BelaDriver : public SC_AudioDriver
static AuxiliaryTask mAudioSyncSignalTask;
static int countInstances;
static SC_SyncCondition* staticMAudioSync;

Scope* mBelaScope;
private:
uint32 mSCBufLength;
};
Expand Down Expand Up @@ -125,6 +127,7 @@ SC_BelaDriver::SC_BelaDriver(struct World *inWorld)
fprintf(stderr, "Error: there are %d instances of SC_BelaDriver running at the same time. Exiting\n", countInstances);
exit(1);
}
mBelaScope = inWorld->mBelaScope;
}

SC_BelaDriver::~SC_BelaDriver()
Expand All @@ -141,8 +144,9 @@ static float gBelaSampleRate;
bool sc_belaSetup(BelaContext* belaContext, void* userData)
{
// cast void pointer
//SC_BelaDriver *belaDriver = (SC_BelaDriver*) userData;
SC_BelaDriver *belaDriver = (SC_BelaDriver*) userData;
gBelaSampleRate = belaContext->audioSampleRate;
belaDriver->mBelaScope->setup(8, gBelaSampleRate);
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions server/scsynth/SC_World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ World* World_New(WorldOptions *inOptions)
world->mBelaADCLevel = inOptions->mBelaADCLevel;
world->mBelaNumMuxChannels = inOptions->mBelaNumMuxChannels;
world->mBelaPRU = inOptions->mBelaPRU;
world->mBelaScope = new Scope();
#endif

#ifdef __APPLE__
Expand Down Expand Up @@ -1099,6 +1100,9 @@ void World_Cleanup(World *world, bool unload_plugins)
free_alig(world->mControlBus);
free_alig(world->mAudioBus);
delete [] world->mRGen;
#ifdef BELA
delete world->mBelaScope;
#endif
if (hw) {

#ifndef NO_LIBSNDFILE
Expand Down

0 comments on commit abecc8b

Please sign in to comment.