trouble with granular audio block

Status
Not open for further replies.

WOH

New member
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("% / ");
}
 
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.
 
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 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
 
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
 
Status
Not open for further replies.
Back
Top