well, Bela's API is minimal and no-frills, so your code will be maximally portable, in general.
That is to say : basically anything you write that doesn't use context
does not rely on the Bela API. A typical Bela processing loop which operates on an input to generate an output looks like this;
void render(BelaContext* context, void*) {
for(unsigned int n = 0; n < context->audioFrames; ++n) { // << replace `context->audioFrames` with your audio API's "frames"
for (unsigned int c = 0; c < context->audioInChannels; ++n) { // << replace `context->audioInChannels` with your audio API's "channels"
float in = audioRead(context, n, c);; // << replace with your audio API's "read" function
// here do all your DSP on `in` without using `context`
// ......
// and produce an output value
float out = ....; // whatever comes out of your DSP
audioWrite(context, n, c, out); // << replace with your audio API's "write" function
}
}
}
I am highlighting the lines that are Bela-specific. As you can see, the DSP code is not (at least in principle) Bela-specific. So, porting this to a different API should be straightforward. The way I tend to write maximally reusable code within a project involves having all the DSP separated out to a dedicated function or class. This then turns out in an almost empty render()
function, which simply reads data into an array, passes it to a processing function and takes the output array and audioWrite()
s it. If the DSP function or class do not include any Bela...
stuff, they are platform-independent. See for instance the Audio/convolver
example, where all the DSP is concentrated in the line
convolver.process(outBuf, inBuf, context->audioFrames);
and this comes from the Convolver
class from the Convolver
library, which is entirely Bela-independent (as denoted by the fact that none of the files in the library even includes Bela.h
).
JMC64 If not, which C++ DSP library can be build / used on Bela and on a Linux-elsewhere ( CSL6? , STK? ,...)?
You can use STK's or CSL6's DSP functions on Bela. Bela is an audio I/O API, not a DSP library (although it does provide some platform-independent DSP libraries, as shown above). The point is more: which audio I/O API can you use on the Pi? That is: what API gives you a memory buffer from which to read your inputs and where to write your outputs? Valid options are Raw ALSA , ALSA zita, Portaudio, RTAudio (RTAudio is also used by STK for their stand-alone programs) ...