How can I save memory when switching between multiple audio effect options?

Status
Not open for further replies.
I'm working on a project that takes input from a microphone, applies audio effects, and outputs it to a speaker. I'd like to have several choices of audio effects that I can switch between. I'm running into a problem with not having enough RAM. Right now I'm running it on a teensy 3.2 and I know that an easy solution would be to upgrade to a 4.0. Ideally the project would have 8 audio effect options to choose from and I don't think upgrading hardware alone would make this possible.

I'm still pretty new to programming arduino, so my understanding of all this is a little bit shaky. When I have a couple effects programmed, I think that all of the effects are working all of the time and using up RAM in the background even if it isn't selected. So if I have two effects and I select Effect 1, Effect 2 is still eating up RAM.

Is there a way to set it up so that the effects that aren't selected are "turned off"? Are there any other methods I could use to reduce RAM usage?
 
You could dynamically build the effect configuration during runtime with new and delete, but this is not a task for the faint of heart.

Could you tell us how you know your'e out of memory, just so we can rule out a simpler solution?
 
Here is an idea of what I'm trying to do

Code:
// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=82,171
AudioEffectChorus        chorus1;        //xy=213,276
AudioEffectGranular      granular1;      //xy=284,157
AudioEffectDelay         delay1;         //xy=295,65
AudioEffectReverb        reverb1;        //xy=353,228
AudioEffectFreeverb      freeverb2;      //xy=368,283
AudioMixer4              mixer3;         //xy=451,111
AudioEffectDelay         delay2;         //xy=516,358
AudioEffectFreeverb      freeverb1;      //xy=585,77
AudioMixer4              mixer2;         //xy=671,473
AudioMixer4              mixer1;         //xy=692,290
AudioOutputI2S           i2s2;           //xy=887,322
AudioConnection          patchCord1(i2s1, 0, delay1, 0);
AudioConnection          patchCord2(i2s1, 0, granular1, 0);
AudioConnection          patchCord3(i2s1, 0, reverb1, 0);
AudioConnection          patchCord4(i2s1, 1, chorus1, 0);
AudioConnection          patchCord5(chorus1, freeverb2);
AudioConnection          patchCord6(granular1, 0, mixer3, 1);
AudioConnection          patchCord7(delay1, 0, mixer3, 0);
AudioConnection          patchCord8(reverb1, 0, mixer1, 2);
AudioConnection          patchCord9(freeverb2, delay2);
AudioConnection          patchCord10(mixer3, freeverb1);
AudioConnection          patchCord11(mixer3, 0, mixer1, 1);
AudioConnection          patchCord12(delay2, 0, mixer1, 3);
AudioConnection          patchCord13(freeverb1, 0, mixer1, 0);
AudioConnection          patchCord14(mixer2, 0, i2s2, 1);
AudioConnection          patchCord15(mixer1, 0, i2s2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=362,518
// GUItool: end automatically generated code

Basically I have a bunch of different audio effects that are plugged into mixer 1 inputs (and eventually mixer 2 inputs). The plan is to use a switch statement to turn the gain on inputs down to 0 when an audio effect isn't being used. This portion of the code alone gives the error
Code:
region `RAM' overflowed by 33448 bytes
.
 
Ah, well, each reverb takes 22k of RAM, and you've got two of them. Teensy 3.2 only has 64k to start with, minus whatever is needed for the USB stack, etc. I just noticed two delays as well... hmm. I don't know how much you value your time, but a T4 is only $20 and will easily do what you're wanting to do. If you want to sanity check it, just select T4 from the board manager and try to compile. You don't need the hardware sitting next to you to check compilation.
 
I tested it out with the Teensy 4.0 and it looks like it will fit on there with lots of room to spare.

Thanks for the advice!
 
No problem, just beware that if you're using the audio shield, there is a different version for T3 and T4. So you will need to either buy the latest revision for the T4, or hook up a bunch of jumper wires to make the old version work with the T4. I should have mentioned that earlier.
 
Status
Not open for further replies.
Back
Top