Finite Impulse Response Filter
This scripts needs to be run in a terminal because it requires you to interact with Bela using your computer's keyboard. Note that it cannot be run from within the IDE or the IDE's console.
See here how to use Bela with a terminal.
In this project an audio recording processesd through an FIR filter.
To control the playback of the audio sample, use your computer keyboard, by pressing:
'a' <enter> to start playing the sample
's' <enter> to stop
'q' <enter> or ctrl-C to quit
#include <cmath>
#include <libraries/Convolver/Convolver.h>
#include <libraries/AudioFile/AudioFile.h>
#include <string>
#include <vector>
#include "FIRfilter.h"
std::string fileName;
int gReadPtr;
std::vector<float> data;
bool initialise_trigger();
void trigger_samples(void*);
{
fileName = (const char *)userData;
if(0 == data.size()) {
fprintf(stderr, "Unable to load file\n");
return false;
}
gReadPtr = -1;
if(!initialise_trigger())
return false;
return true;
}
{
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
float in = 0;
if(gReadPtr != -1)
in += data[gReadPtr++];
if(gReadPtr >= int(data.size()))
gReadPtr = -1;
ins[n] = in;
}
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
}
}
bool initialise_trigger()
{
return false;
rt_printf("Press 'a' <enter> to start playing the sample\n"
" 's' <enter> to stop\n");
rt_printf(" 'q' <enter> or ctrl-C to quit\n");
return true;
}
void trigger_samples(void*)
{
char keyStroke = '.';
fd_set readfds;
struct timeval tv;
int fd_stdin;
fd_stdin = fileno(stdin);
FD_ZERO(&readfds);
FD_SET(fileno(stdin), &readfds);
tv.tv_sec = 0;
tv.tv_usec = 1000;
fflush(stdout);
int num_readable = select(fd_stdin + 1, &readfds, NULL, NULL, &tv);
if(num_readable > 0){
scanf("%c", &keyStroke);
if(keyStroke != '\n'){
switch (keyStroke)
{
case 'a':
gReadPtr = 0;
break;
case 's':
gReadPtr = -1;
break;
case 'q':
break;
default:
break;
}
}
}
usleep(1000);
}
}
{
}