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

Thread: trouble with granular audio block

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    3

    trouble with granular audio block

    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.

    [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("% / ");
    }

  2. #2
    Hey! So did you look into the example of the granular object? I would just start with the example and then when that works modify it from there.

  3. #3
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    When I import your Audio connections into the Audio System Design Tool, I see that mixer channnel 0 is used and the other inputs are not.
    So you may want to adjust your code to:
    Code:
    mixer1.gain(0, 0.5); // granular1 (wet) gain
    mixer1.gain(1, 0); // unused
    mixer1.gain(2, 0); // unused
    mixer1.gain(3, 0); // unused
    Hope this helps,
    Paul
    Last edited by PaulS; 09-28-2021 at 11:51 AM.

  4. #4
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    By the way: sgtl5000_1.volume(5); is not recommended, perhaps you meant sgtl5000_1.volume(0.5); ?
    From the Audio System Design Tool info tab:
    volume(level);
    Set the headphone volume level. Range is 0 to 1.0, but 0.8 corresponds to the maximum undistorted output for a full scale signal. Usually 0.5 is a comfortable listening level. The line level outputs are not changed by this function.


    Paul

  5. #5
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    204
    Hi

    Something else to look at is that the loop() function will be executing at a very high rate (millions of times a second).

    You'll be continuously re-starting the effect (.begin) and continually re-adjusting the freeze point. Also the serial.print will quickly overfill the buffers.

    You also need to think about how you initiate the freeze - have a look at the example which uses a button to set the freeze point

    cheers Paul

Tags for this Thread

Posting Permissions

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