Hello, I’m having troubles writing a code with the granular audio block (actually also to use the example) I’m super new with coding same with teensy so please don’t be hard with me.
I’m trying to do a simple granular reverb audio effect but not sure it is working properly, basically I want to have two potentiometers, one controlling beginFreeze and the other one the speed, and the other two roomSize and damping of the freeverb, now the reveb knobs works fine, what I can’t get is a proper granular effect (I’m getting like a sort of a bitcrusher pretty distorted)
Here the code I’ve made so far, an help would be super appreciated.
I’m trying to do a simple granular reverb audio effect but not sure it is working properly, basically I want to have two potentiometers, one controlling beginFreeze and the other one the speed, and the other two roomSize and damping of the freeverb, now the reveb knobs works fine, what I can’t get is a proper granular effect (I’m getting like a sort of a bitcrusher pretty distorted)
Here the code I’ve made so far, an help would be super appreciated.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=440,372
AudioMixer4 mixer1; //xy=660,396
AudioEffectGranular granular1; //xy=901,444
AudioOutputI2S i2s2; //xy=1089,399
AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(mixer1, granular1);
AudioConnection patchCord3(granular1, 0, i2s2, 0);
AudioConnection patchCord4(granular1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=526,143
#define GRANULAR_MEMORY_SIZE 12800 // enough for 290 ms at 44.1 kHz
int16_t granularMemory[GRANULAR_MEMORY_SIZE];
// inputs
#define pot1 A1 // beginFreeze
#define pot2 A2 // setSpeed
void setup() {
Serial.begin(9600);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// I2S audio init
sgtl5000_1.enable();
sgtl5000_1.volume(5);
AudioInterrupts();
}
void loop() {
// read pot levels
float knob1 = (float)analogRead(pot1) / 1023.0; // beginFreeze
float knob2 = (float)analogRead(pot2) / 1023.0; // setSpeed
mixer1.gain(0, 5); // unused, gain 0
mixer1.gain(1, 0.5); // granular1 (wet) gain
mixer1.gain(3, 5); // unused, gain 0
// the Granular effect requires memory to operate
granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
granular1.beginFreeze(knob1);
granular1.beginPitchShift(knob2);
Serial.print("%, beginFreeze: ");
Serial.print(knob1 * 100.0);
Serial.print("%, setSpeed: ");
Serial.print(knob2 * 100.0);
Serial.print("%, Dry Level: ");
Serial.print("% / ");
}