Hello everyone,

Was playing around with the Teensy today trying out an idea to pitch shift delays using the audio library.

I've had success in capturing a small granular loop and pitch shifting today. I tried to extend the idea to using a delay in the signal path, and hooking up the output of graulator to the input stage of a mixer before it goes into the delay. The idea was to put the pitch shifting granulator inside the feedback loop for the delay, so each time audio goes round the loop it gets progressively pitched higher.

However I've not been able to pitch shift a delay trail successfully yet, which makes me think the two processes could be incompatible.

Can someone have a look and see if I'm doing anything hideously wrong? Should I be able to use these effects at the same time?

This is the code from the Audio design tool:

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           //xy=98,106
AudioEffectDelay         delay1;         //xy=266,325
AudioMixer4              mixer1;         //xy=293,109
AudioEffectGranular      granular1;      //xy=475,282
AudioOutputI2S           i2s1;           //xy=700,206
AudioConnection          patchCord1(i2s2, 0, mixer1, 0);
AudioConnection          patchCord2(i2s2, 1, mixer1, 1);
AudioConnection          patchCord3(delay1, 0, granular1, 0);
AudioConnection          patchCord4(mixer1, delay1);
AudioConnection          patchCord5(granular1, 0, i2s1, 0);
AudioConnection          patchCord6(granular1, 0, i2s1, 1);
AudioConnection          patchCord7(granular1, 0, mixer1, 3);
AudioControlSGTL5000     sgtl5000_1;     //xy=72,266
// GUItool: end automatically generated code
And here's the rest of the code except the audio tool export above:

Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);
//Bounce button2 = Bounce(2, 15);

#define GRANULAR_MEMORY_SIZE 12800  // enough for 290 ms at 44.1 kHz
int16_t granularMemory[GRANULAR_MEMORY_SIZE];

void setup() {

  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);


  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  delay1.delay(0, 400);

  // the Granular effect requires memory to operate
  granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);

void loop() {

  // read pushbuttons
  // read knobs, scale to 0-1.0 numbers
  float knobA2 = (float)analogRead(A6) / 1023.0;
  float knobA3 = (float)analogRead(A7) / 1023.0;

  // Button 0 starts Freeze effect
  if (button0.fallingEdge()) {
    float msec = 100.0 + (knobA2 * 190.0);
    Serial.print("Begin granular freeze using ");
    Serial.println(" grains");
  if (button0.risingEdge()) {

  // Button 1 starts Pitch Shift effect
  if (button1.fallingEdge()) {
    float msec = 25.0 + (knobA2 * 75.0);
    Serial.print("Begin granular pitch phift using ");
    Serial.println(" grains");
  if (button1.risingEdge()) {

  // Continuously adjust the speed, based on the A3 pot
  float ratio;
  //ratio = powf(2.0, knobA2 * 2.0 - 1.0); // 0.5 to 2.0
  ratio = powf(2.0, knobA3 * 6.0 - 3.0); // 0.125 to 8.0 -- uncomment for far too much range!

 float feedback = (float)knobA2 / 1050.0; // Feedback the signal
 mixer1.gain(3, feedback);

Any help is greatly appreciated!