Try changing the cutoff frequency of the smoothing filter which is applied to the Trill readings to change the response of this example. try filterCutoff = 50;
#include <libraries/Trill/Trill.h>
#include <libraries/Biquad/Biquad.h>
#include <libraries/Oscillator/Oscillator.h>
#include <vector>
#include <cstring>
#include <cmath>
#define NUM_CAP_CHANNELS 30
std::vector<Oscillator> gOscBank;
std::vector<Biquad> gFilters;
float gSensorReading[NUM_CAP_CHANNELS] = { 0.0 };
unsigned int gTaskSleepTime = 12000;
void loop(void*)
{
{
touchSensor.readI2C();
for(unsigned int i = 0; i < NUM_CAP_CHANNELS; i++)
gSensorReading[i] = touchSensor.rawData[i];
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Craft\n");
return false;
}
float filterCutoff = 10;
gFilters.resize(NUM_CAP_CHANNELS,
Biquad::Settings({.fs = context->
audioSampleRate, .type = Biquad::lowpass, .cutoff = filterCutoff, .q = 0.707, .peakGainDb = 0}));
gOscBank.resize(NUM_CAP_CHANNELS, {context->
audioSampleRate, Oscillator::sine});
float fundFreq = 50;
for(unsigned int n = 0; n < gOscBank.size(); n++) {
float freq = fundFreq * powf(1.0 + n, 1.002);
gOscBank[n].setFrequency(freq);
}
return true;
}
{
for(
unsigned int n = 0; n < context->
audioFrames; ++n){
float out = 0;
for(unsigned int o = 0; o < gOscBank.size(); ++o) {
float amplitude = gFilters[o].process(gSensorReading[o]);
out += gOscBank[o].process() * amplitude * amplitude / 6.f;
}
}
}
{
}
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
Definition Trill.h:14
void printDetails()
Definition Trill.cpp:492
@ CRAFT
Trill Craft
Definition Trill.h:36
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
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