#include <cmath>
#include <libraries/Scope/Scope.h>
 
 
int gAudioFramesPerAnalogFrame = 0;
float gInverseSampleRate;
float gPhase;
 
float gAmplitude;
float gFrequency;
 
float gIn1;
float gIn2;
 
 
{
 
        
 
        {
                fprintf(stderr, "Error: for this project the sampling rate of the analog inputs has to be <= the audio sample rate\n");
                return false;
        }
        {
                fprintf(stderr, "Error: for this project you need at least two analog inputs\n");
                return false;
        }
 
        gPhase = 0.0;
 
        return true;
}
 
{
 
        for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
 
                if(gAudioFramesPerAnalogFrame && !(n % gAudioFramesPerAnalogFrame)) {
                        
                        gIn1 = 
analogRead(context, n/gAudioFramesPerAnalogFrame, 0);
                        gIn2 = 
analogRead(context, n/gAudioFramesPerAnalogFrame, 1);
                        gAmplitude = gIn1 * 0.8f;
                        gFrequency = 
map(gIn2, 0, 1, 100, 1000);
                }
 
                
                float out = gAmplitude * sinf(gPhase);
                gPhase += 2.0f * (float)M_PI * gFrequency * gInverseSampleRate;
                if(gPhase > M_PI)
                        gPhase -= 2.0f * (float)M_PI;
 
                
                scope.log(out, gIn1, gIn2);
 
                
                }
        }
}
 
{
 
}
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
static float analogRead(BelaContext *context, int frame, int channel)
Read an analog input, specifying the frame number (when to read) and the channel.
Definition Bela.h:1480
static void audioWrite(BelaContext *context, int frame, int channel, float value)
Write an audio output, specifying the frame number (when to write) and the channel.
Definition Bela.h:1469
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
static float map(float x, float in_min, float in_max, float out_min, float out_max)
Linearly rescale a number from one range of values to another.
Definition Utilities.h:71
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t audioOutChannels
The number of audio output channels.
Definition Bela.h:326
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
const uint32_t analogFrames
The number of analog frames per block.
Definition Bela.h:341
const uint32_t analogInChannels
The number of analog input channels.
Definition Bela.h:346
const float analogSampleRate
Analog sample rate in Hz.
Definition Bela.h:362