Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Granular beginFreeze doenst work on Teensy 3.6 / Trellis Adafruit

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    4

    Granular beginFreeze doenst work on Teensy 3.6 / Trellis Adafruit

    Hello,
    i am a professional bass player from Berlin and i m trying to upgrade my guitar by adding a teensy 3.6 and trellis (look here ). Everything works fine exept the the beginFreeze() . It work on 3.2 but i want to work with samples this is why i decided to use the 3.6 (more memory, faster). Any why nothing is happening when i am activating beginFreeze()? Do i need somthing like a debounce function for the trellis pad? if so do you know how to write that? here is the code. THX hottib


    Code:
    // Granular Effect Example - Pitch shift or freeze sgt input and samples
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include "Adafruit_Trellis.h"
    #include "AudioSampleLang.h"  
    #include "AudioSampleKurz.h"  
    #include "Bounce.h"  
    
    
    // GUItool: begin automatically generated code
    AudioPlayMemory          playMem1;       //xy=146.1666717529297,193.1666717529297
    //AudioSynthWavetable      wavetable1;     //xy=146.74998474121094,134.75
    AudioInputI2S            i2s2;           //xy=156.1666717529297,163.1666717529297
    AudioMixer4              mixer1;         //xy=413.16668701171875,141
    AudioEffectGranular      granular1;      //xy=563.1666870117188,117.00000762939453
    AudioOutputI2S           i2s1;           //xy=728.1666870117188,146
    AudioConnection          patchCord1(playMem1, 0, mixer1, 2);
    //AudioConnection          patchCord2(wavetable1, 0, mixer1, 0);
    AudioConnection          patchCord3(i2s2, 0, mixer1, 1);
    AudioConnection          patchCord4(mixer1, granular1);
    AudioConnection          patchCord5(granular1, 0, i2s1, 0);
    AudioConnection          patchCord6(granular1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=482.75,296.75
    // GUItool: end automatically generated code
    
    
    Adafruit_Trellis matrix0 = Adafruit_Trellis();
    Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0);
    #define NUMTRELLIS 1
    #define numKeys (NUMTRELLIS * 16)
    #define INTPIN A2
    
    
    
    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];
    
    
    const int myInput = AUDIO_INPUT_LINEIN;
    boolean compressorOn = false; // default this to off.
    
    
    
    
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(80);
    
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
    
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
     sgtl5000_1.inputSelect(myInput);
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.5);
     mixer1.gain(2, 0.5);
      mixer1.gain(3, 0.5);
    
    
    trellis.begin(0x70);
    for (uint8_t i=0; i<numKeys; i++) {
    trellis.setLED(i);
    trellis.writeDisplay();
    delay(50);
    }
    // then turn them off
    for (uint8_t i=0; i<numKeys; i++) {
    trellis.clrLED(i);
    trellis.writeDisplay();
    delay(50);
    analogRead(A1);
    analogRead(A2);
    analogRead(A0);
    }
      
      // the Granular effect requires memory to operate
      granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
    
    
    
    }
    
    
    
    
    
    
    void updateKnob() {
     
      // read pushbuttons
      button0.update();
      button1.update();
      button2.update();
      // read knobs, scale to 0-1.0 numbers
      float knobA0 = (float)analogRead(A0) / 1023.0;
      float knobA1 = (float)analogRead(A1) / 1023.0;
    
      // Button 0 starts Freeze effect
      if (button0.fallingEdge()) {
        float msec = 100.0 + (knobA1 * 190.0);
        granular1.beginFreeze(msec);
        Serial.print("Begin granular freeze using ");
        Serial.print(msec);
        Serial.println(" grains");
      }
      if (button0.risingEdge()) {
        granular1.stop();
      }
    
      // Button 1 starts Pitch Shift effect
      if (button1.fallingEdge()) {
        float msec = 25.0 + (knobA1 * 75.0);
        granular1.beginPitchShift(msec);
        Serial.print("Begin granular pitch phift using ");
        Serial.print(msec);
        Serial.println(" grains");
      }
      if (button1.risingEdge()) {
        granular1.stop();
    
     
      }
      if (button1.risingEdge()) {
        granular1.stop();} 
    
        
     // Button 2 starts sample
       if (button2.fallingEdge()) {
        playMem1.play(AudioSampleLang); 
    
        
      }
      // Continuously adjust the speed, based on the A1 pot
      #
      float ratio;
      //ratio = powf(2.0, knobA0 * 2.0 - 1.0); // 0.5 to 2.0
      
      
      ratio = powf(2.0, knobA0 * 6.0 - 3.0); // 0.125 to 8.0 -- uncomment for far too much range!
      granular1.setSpeed(ratio);
    }
    
    
    
    void updateTrellis() {
    
    
    trellis.readSwitches();
    
    
    if (trellis.justPressed(0))
    {
     playMem1.play(AudioSampleKurz); 
    }
    if (trellis.justPressed(1))
    {
     playMem1.play(AudioSampleLang); 
    }
    if (trellis.isKeyPressed(1)){
    
    }
    
    // 8-11 Freeze mit unterschidlichen Lšngen
    
    if (trellis.justPressed(4))
    {
     granular1.beginFreeze(250); 
    }
    if (trellis.justReleased(4))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(9))
    {
     granular1.beginFreeze(180); 
    }
    if (trellis.justReleased(9))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(10))
    {
     granular1.beginFreeze(110); 
    }
    if (trellis.justReleased(10))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(11))
    {
     granular1.beginFreeze(60); 
    }
    if (trellis.justReleased(11))
    {
     granular1.stop(); 
    }
    // 12-15 Pitchshift when pressed mit unterschidlichen Lšngen
    if (trellis.justPressed(12))
    {
     granular1.beginPitchShift(8); 
    }
    if (trellis.justReleased(12))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(13))
    {
     granular1.beginPitchShift(6); 
    }
    if (trellis.justReleased(13))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(14))
    {
     granular1.beginPitchShift(0.8); 
    }
    if (trellis.justReleased(14))
    {
     granular1.stop(); 
    }
    if (trellis.justPressed(15))
    {
     granular1.beginPitchShift(0.4); 
    }
    if (trellis.justReleased(15))
    {
     granular1.stop(); 
    }
    
    
    
    
    }
    
    /*void updateTrellisLED()
    {
    
    for (uint8_t i=0; i<numKeys; i++) {
    if (trellis.justPressed(i)){trellis.setLED(i);
    
    }
    for (uint8_t i=0; i<numKeys; i++) {
    if (trellis.justReleased(i)){trellis.clrLED(i);
    } 
    trellis.writeDisplay();
    }
    }
    }
    */
    
    void loop() 
    {
       // capture the latest value of millis()
                                 //   this is equivalent to noting the time from a clock
                                 //   use the same time for all LED flashes to keep them synchronized
    // call the functions that do the work
     updateTrellis();
     updateKnob();
    delay(10);
     // updateTrellisLED();
      }
    Last edited by defragster; 03-01-2019 at 07:12 AM. Reason: Added # Code hashtag

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,548
    Thanks for the Trellis link. I added the [C0DE] // code goes here - but with letter O not #0[/C0DE] to your OP.

    Looking there I see:
    Connect the wires:

    5V goes to the 5V power pin on the Arduino
    The T_3.6 has no tolerance for 5V - except Vin pin. Is everything touching the T_3.6 only presenting a 3.3V signal when high?

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Posts
    4
    THX for the reply and the C-zero-DE-help
    I think th power supply of the trellis is not the problem because all the other buttons work fine (see playMem and beginPitchShift). Futhermore works even without a power supply - but then the LEDs are very (very) weak. Vin works too. Either way the beginFreeze doesnt work

    OH WAIT! I added a delay of 10ms before calling the buttons. now it works!

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,548
    Nice, I figured there were other buttons in the code that worked - but seeing 5V seemed like the first question with a Higher Potential for bad results.

    The 'Reply' toolbar shows the ' # ' icon that will insert the CODE brackets for display - just like the 'quote' icon does.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •