The vertical position of the touch is mapped to frequency, while the horizontal position maps to left/right panning. Touch size is used to control the overal amplitude of the oscillator.
Changes in frequency, amplitude and panning are smoothed using LP filters to avoid artifacts.
#include <cmath>
#include <libraries/Trill/Trill.h>
#include <libraries/OnePole/OnePole.h>
#include <libraries/Oscillator/Oscillator.h>
float gTouchPosition[2] = { 0.0 , 0.0 };
float gTouchSize = 0.0;
float gFreqRange[2] = { 200.0, 1500.0 };
OnePole freqFilt, panFilt, ampFilt;
float gAmpL = 1.0;
float gAmpR = 1.0;
unsigned int gTaskSleepTime = 12000;
void loop(void*)
{
{
touchSensor.readI2C();
gTouchSize = touchSensor.compoundTouchSize();
gTouchPosition[0] = touchSensor.compoundTouchHorizontalLocation();
gTouchPosition[1] = touchSensor.compoundTouchLocation();
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Square\n");
return false;
}
touchSensor.printDetails();
return true;
}
{
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
float frequency;
frequency =
map(gTouchPosition[1], 0, 1, gFreqRange[0], gFreqRange[1]);
frequency = freqFilt.process(frequency);
float panning = panFilt.process(gTouchPosition[0]);
gAmpL = 1 - panning;
gAmpR = panning;
float amplitude = ampFilt.process(gTouchSize);
float out = amplitude * osc.process(frequency);
if(channel == 0) {
} else if (channel == 1) {
}
}
}
}
{}
Definition Oscillator.h:3
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
Definition Trill.h:14
@ SQUARE
Trill Square
Definition Trill.h:35
AuxiliaryTask Bela_runAuxiliaryTask(void(*callback)(void *), int priority=0, void *arg=nullptr)
Create and start an AuxiliaryTask.
int Bela_stopRequested()
Check whether the program should stop.
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