Each touch on the sensor controls the pitch and volume of an oscillator.
Position and size for each touch are then mapped to frequency and amplitude of their corresponding oscillator. Changes in frequency and amplitude are smoothed using low pass filters to avoid artifacts.
#include <cmath>
#include <libraries/Trill/Trill.h>
#include <libraries/OnePole/OnePole.h>
#include <libraries/Oscillator/Oscillator.h>
#define NUM_TOUCH 5 // Number of touches on Trill sensor
float gTouchLocation[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
float gTouchSize[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
int gNumActiveTouches = 0;
unsigned int gTaskSleepTime = 12000;
OnePole freqFilt[NUM_TOUCH], ampFilt[NUM_TOUCH];
float gCutOffFreq = 5, gCutOffAmp = 15;
float gFreqRange[2] = { 200.0, 1500.0 };
float gAmplitudeRange[2] = { 0.0, 1.0 } ;
void loop(void*)
{
{
for(unsigned int i = 0; i < gNumActiveTouches; i++) {
}
for(unsigned int i = gNumActiveTouches; i < NUM_TOUCH; i++) {
gTouchLocation[i] = 0.0;
gTouchSize[i] = 0.0;
}
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Bar\n");
return false;
}
for(unsigned int i = 0; i < NUM_TOUCH; i++) {
}
return true;
}
{
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
float out = 0.0;
for(unsigned int i = 0; i < NUM_TOUCH; i++) {
float frequency, amplitude;
frequency =
map(gTouchLocation[i], 0, 1, gFreqRange[0], gFreqRange[1]);
amplitude =
map(gTouchSize[i], 0, 1, gAmplitudeRange[0], gAmplitudeRange[1]);
amplitude = ampFilt[i].
process(amplitude);
out += (1.f/NUM_TOUCH) * amplitude * osc[i].process(frequency);
}
}
}
}
{}