dpharris
Well-known member
I got my Teensy and Audio shield up and running ... great stuff.
I tried out chorusing by adding code from the Chorus example to the WavFilePlayer example, see below. It works ok, but I am hearing glitches. I am using a Sandisk Ultra 16Gb scared. I may be doing something wrong ... like not allocating enough memory? Or perhaps pushing it too much with n_chorus = 5?
Thanks,
David
I tried out chorusing by adding code from the Chorus example to the WavFilePlayer example, see below. It works ok, but I am hearing glitches. I am using a Sandisk Ultra 16Gb scared. I may be doing something wrong ... like not allocating enough memory? Or perhaps pushing it too much with n_chorus = 5?
Thanks,
David
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// number of "voices" in the chorus which INCLUDES the original voice
int n_chorus = 5;
// Number of samples in each delay line
#define CHORUS_DELAY_LENGTH (16*AUDIO_BLOCK_SAMPLES)
// Allocate the delay lines for left and right channels
short l_delayline[CHORUS_DELAY_LENGTH];
short r_delayline[CHORUS_DELAY_LENGTH];
AudioEffectChorus l_myEffect;
AudioEffectChorus r_myEffect;
AudioPlaySdWav playWav1; //xy=154,78
AudioOutputI2S i2s1; //xy=334,89
AudioConnection c1(playWav1, 0, l_myEffect, 0);
AudioConnection c2(playWav1, 1, r_myEffect, 0);
//AudioConnection patchCord1(playWav1, 0, i2s1, 0);
//AudioConnection patchCord2(playWav1, 1, i2s1, 1);
AudioConnection c3(l_myEffect, 0, i2s1, 0);
AudioConnection c4(r_myEffect, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=240,153
void setup() {
Serial.begin(9600);
// Serial.begin(9600);
// while (!Serial) ;
// delay(3000);
// Serial.println("Chorus test");
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(5);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
// Initialize the effect - left channel
// address of delayline
// total number of samples in the delay line
// number of voices in the chorus INCLUDING the original voice
if(!l_myEffect.begin(l_delayline,CHORUS_DELAY_LENGTH,n_chorus)) {
Serial.println("AudioEffectChorus - left channel begin failed");
while(1);
}
// Initialize the effect - right channel
// address of delayline
// total number of samples in the delay line
// number of voices in the chorus INCLUDING the original voice
if(!r_myEffect.begin(r_delayline,CHORUS_DELAY_LENGTH,n_chorus)) {
Serial.println("AudioEffectChorus - left channel begin failed");
while(1);
}
l_myEffect.voices(n_chorus);
r_myEffect.voices(n_chorus);
}
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
// Start playing the file. This sketch continues to
// run while the file plays.
playWav1.play(filename);
// A brief delay for the library read WAV info
delay(5);
//delay(10000);
// Simply wait for the file to finish playing.
while (playWav1.isPlaying()) {
// uncomment these lines if you audio shield
// has the optional volume pot soldered
//float vol = analogRead(15);
//vol = vol / 1024;
// sgtl5000_1.volume(vol);
}
}
unsigned long last_time = millis();
void loop() {
playFile("SDTEST1.WAV");
if(1) {
if(millis() - last_time >= 5000) {
Serial.print("Proc = ");
Serial.print(AudioProcessorUsage());
Serial.print(" (");
Serial.print(AudioProcessorUsageMax());
Serial.print("), Mem = ");
Serial.print(AudioMemoryUsage());
Serial.print(" (");
Serial.print(AudioMemoryUsageMax());
Serial.println(")");
last_time = millis();
}
}
// delay(500);
// playFile("SDTEST2.WAV");
// delay(500);
// playFile("SDTEST3.WAV");
// delay(500);
// playFile("SDTEST4.WAV");
// delay(1500);
}