Helloo,
For a project I am building a polyphonic karplus-strong instrument with audio input, as it is supposed to use audio input I cannot use the string option in the audio design tool. Aside from that I'm used to working with audio with a JUCE style callback, with an input and an output buffer.
Inspired by this post (https://forum.pjrc.com/index.php?threads/understanding-queue-and-buffers.59124/) I started out making my own audio callback with queue's and buffers. First I just made a passthrough callback and this seemed to work but as soon as I started implementing a simple FIR filter I noticed I made a mistake in my approach. As I'm just starting out with Teensy I'm not sure what went wrong, probably I'm thinking too simply about this.
This is my code now, through which I only hear the input audio without filtering:
Btw I have made a version with the delay lines and filters from the Teensy audio tool, but I couldn't get it in tune because of the delay caused from feedback.
This I read here: https://forum.pjrc.com/index.php?threads/precise-sample-delay-for-karplus-strong-algorithm.33287/
Hopefully I've made clear what I'm trying to achieve and it doesn't take too much of anyone's time.
Thanks!!!
For a project I am building a polyphonic karplus-strong instrument with audio input, as it is supposed to use audio input I cannot use the string option in the audio design tool. Aside from that I'm used to working with audio with a JUCE style callback, with an input and an output buffer.
Inspired by this post (https://forum.pjrc.com/index.php?threads/understanding-queue-and-buffers.59124/) I started out making my own audio callback with queue's and buffers. First I just made a passthrough callback and this seemed to work but as soon as I started implementing a simple FIR filter I noticed I made a mistake in my approach. As I'm just starting out with Teensy I'm not sure what went wrong, probably I'm thinking too simply about this.
This is my code now, through which I only hear the input audio without filtering:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputAnalog adc1; //xy=118,357
AudioRecordQueue record_queue; //xy=255,223
AudioPlayQueue play_queue; //xy=370,300
AudioOutputAnalog dac1; //xy=530,299
AudioConnection patchCord1(adc1, record_queue);
AudioConnection patchCord2(play_queue, dac1);
// GUItool: end automatically generated code
int16_t output_buffer[128];
void setup() {
AudioMemory(12);
record_queue.begin();
}
void loop() {
// make sure at least 1 block is available in the record queue
if (record_queue.available() > 0) {
// read the next block of input samples
int16_t* input_buffer = (int16_t*)record_queue.readBuffer();
// process input audio via callback
audio_callback(input_buffer, output_buffer);
// release the input buffer
record_queue.freeBuffer();
// play processed audio through play queue
if (play_queue.available() > 0) {
play_queue.play(output_buffer, 128);
}
}
}
void audio_callback(int16_t* input_buffer, int16_t* output_buffer) {
for (size_t i = 0; i < 128; ++i) {
output_buffer[i] = lpf(input_buffer[i]);
}
}
int16_t lpf(int16_t input) {
static int16_t prev_sample = 0;
int16_t output = (int16_t)((input + prev_sample) / 2);
prev_sample = input;
return output;
}
Btw I have made a version with the delay lines and filters from the Teensy audio tool, but I couldn't get it in tune because of the delay caused from feedback.
This I read here: https://forum.pjrc.com/index.php?threads/precise-sample-delay-for-karplus-strong-algorithm.33287/
Hopefully I've made clear what I'm trying to achieve and it doesn't take too much of anyone's time.
Thanks!!!