Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
This project is a minimal example on how to send data buffers from p5js to Bela. Bela (render.cpp) receives a buffer of data from p5js (sketch.js) containing three floats: two corresponding to slider values and the third one correponding to a button. These values are then mapped as parameters of an oscillator object. The mapping is: slider1–>pitch slider2–>amplitude button–>play/stop
In order to receive a buffer from the GUI, the type of the buffer and maximum number of values that it will hold need to be specified in setup: ``` myGUi.setBuffer('f', 3); ``` In this case we are expecting to receive a buffer of floats with a maximum of 3 elements. This function will return the index of the buffer (which is given automatically based on the order they are set on). This buffer will have index = 0. The buffer can then be accessed using this index: ``` DataBuffer& buffer = myGui.getDataBuffer(0); `` Notice that the Gui::getDataBuffer() method returns a
DataBuffer& `(that is: a reference to a DataBuffer). You should in turn always be storing the return value in a DataBuffer&
variable to minimize copy overhead, and ensure that it can be used safely from within a real-time context.
And its contents retrieved in the desired format (floats in this case): float* data = buffer.getAsFloat();