Trill Square oscillator pad
This example shows how to communicate with the Trill Square sensor using the Trill library. It sonifies the X-Y position and size of the touch via the control of an oscillator.
In this file Trill sensor is scanned in an AuxiliaryTask running in parallel with the audio thread and the horizontal and vertical position and size are stored in global variables.
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*)
{
{
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Square\n");
return false;
}
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) {
}
}
}
}
{}