Visualising a Low Frequency Oscillator
Is this project you can find a sketch.js file which is a p5.js file that is rendered in a browser tab. Click the GUI button (next to the Scope button) in the IDE to see the rendering of this file.
This example sends a buffer of data from the Bela render to the browser via a web socket every few milliseconds containing the value of a sinewave LFO: gui.sendBuffer(0, sineValue);
The p5.js file displays the position of the sinewave in two different ways.
 
#include <cmath>
#include <libraries/Gui/Gui.h>
 
 
float gFrequency = 0.1;
float gPhase;
float gInverseSampleRate;
 
float sineValue[] = {0.0};
 
float gTimePeriod = 0.04;
 
{
        gPhase = 0.0;
 
        return true;
}
 
{
        for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
 
                float out = sinf(gPhase);
 
                gPhase += 2.0f * (float)M_PI * gFrequency * gInverseSampleRate;
                if(gPhase > M_PI)
                        gPhase -= 2.0f * (float)M_PI;
 
                static unsigned int count = 0;
                
                {
                        count = 0;
                        
                        sineValue[0] = out;
                        
                        gui.sendBuffer(0, sineValue);
                }
                count++;
        }
}
 
 
{
 
}
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t audioFrames
The number of audio frames per block.
Definition Bela.h:322
char projectName[MAX_PROJECTNAME_LENGTH]
Name of running project.
Definition Bela.h:417
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328