This project showcases an example of how to communicate with the Trill Hex sensor using the Trill library and sonifies the X-Y position and size of the touch via a pair of detuned oscillators.
The Trill sensor is scanned on an auxiliary task running parallel to the audio thread and the X-Y position and size stored on global variables.
The vertical position of the touch is mapped to frequency, while the size of the touch maps to amplitude. Horizontal position is used to control the detuning (difference in frequency) between the otherwise identic pair of oscillators. The centre of the horizontal axis is both oscillators in tune. Changes in frequency and amplitude are smoothed using LP filters to avoid artifacts.
#include <libraries/Trill/Trill.h>
#include <cmath>
#include <libraries/OnePole/OnePole.h>
#include <libraries/Oscillator/Oscillator.h>
float gTouchPosition[2] = { 0.0 , 0.0 };
float gTouchSize = 0.0;
float gFreqRange[2] = { 100.0, 400.0 };
float gAmplitudeRange[2] = { 0.0, 1.0 } ;
float gDetuneRange[2] = { -25.0, 25.0 };
unsigned int gTaskSleepTime = 12000;
void loop(void*)
{
{
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Hex\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 detuning;
detuning =
map(gTouchPosition[0], 0, 1, gDetuneRange[0], gDetuneRange[1]);
osc[0].
setFrequency(frequency);
osc[1].setFrequency(frequency+ detuning);
float amplitude;
amplitude =
map(gTouchSize, 0, 1, gAmplitudeRange[0], gAmplitudeRange[1]);
amplitude = ampFilt.process(amplitude);
float out = amplitude * 0.5 * (osc[0].
process() + osc[1].process());
}
}
}
{
}