Oscilloscope in-browser
This example demonstrates the scope feature of the IDE.
The scope is instantiated at the top of the file via Scope scope;
In setup() we define how many channels the scope should have and the sample rate that it should run at via scope.setup(3, context->audioSampleRate).
In render() we choose what the scope log via scope.log(out, out2, out3). In this example the scope is logging three sine waves with different phases. To see the output click on the Open Scope button.
An additional option is to set the trigger of the oscilloscope from within render(). In this example we are triggering the scope when oscillator 1 becomes less than oscillator 2 via scope.trigger(). Note that this functionality only takes effect when the triggering mode is set to custom in the scope UI.
#include <libraries/Scope/Scope.h>
#include <cmath>
float gFrequency = 110.0;
float gPhase;
float gInverseSampleRate;
{
gPhase = 0;
return true;
}
float lastOut = 0.0;
float lastOut2 = 0.0;
{
for (
unsigned int n = 0; n < context->
audioFrames; ++n)
{
float out = 0.8f * sinf(gPhase);
float out2 = 0.8f * sinf(gPhase - (float)M_PI/2.f);
float out3 = 0.8f * sinf(gPhase + (float)M_PI/2.f);
gPhase += 2.0f * (float)M_PI * gFrequency * gInverseSampleRate;
if(gPhase > M_PI)
gPhase -= 2.0f * (float)M_PI;
scope.log(out, out2, out3);
if (lastOut >= lastOut2 && out < out2){
scope.trigger();
}
lastOut = out;
lastOut2 = out2;
}
}
{
}
An oscilloscope which allows data to be visualised in a browser in real time.
Definition Scope.h:23
void setup(unsigned int numChannels, float sampleRate)
Initialise the scope, setting the number of channels and the sample rate.
Definition Scope.cpp:48
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
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328