Troubleshooting RAM overflow while using faust dsp

Status
Not open for further replies.

faemagedon

New member
Hi I've been trying to run a library made with the faust IDE and keep getting this error on Teensy 3.5:

Arduino: 1.8.13 (Mac OS X), TD: 1.53, Board: "Teensy 3.5, Serial, 120 MHz, Faster, US English"

/Applications/Teensyduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: /var/folders/xw/4_chkj0n4w58bfhrx_pb57pm0000gn/T/arduino_build_415137/sketch_may06a.ino.elf section `.bss' will not fit in region `RAM'
/Applications/Teensyduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: region `RAM' overflowed by 41148 bytes
collect2: error: ld returned 1 exit status
Multiple libraries were found for "SD.h"
Used: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
Not used: /Applications/Teensyduino.app/Contents/Java/libraries/SD
Error compiling for board Teensy 3.5.


The code is as follows:

Code:
#include <Audio.h>


#include "AMSmallSynth.h"
// GUItool: begin automatically generated code
AMSmallSynth      waveform1;      //xy=345,257
AudioOutputAnalogStereo  dacs1;          //xy=577,253
AudioConnection          patchCord1(waveform1, 0, dacs1, 0);
AudioConnection          patchCord2(waveform1, 0, dacs1, 1);
AudioControlSGTL5000     audioShield;     //xy=383,373
// GUItool: end automatically generated code




int buttonPinsOrange[] = {24, 25 ,26, 27};
int buttonPinsBlue[] = {28, 29, 30, 31};
byte currentPressOrange = 0;
byte currentPressBlue = 0;

int ledPinsBlue[] = {36, 37, 38, 39};
int ledPinsOrange[] = {32, 33, 34, 35};

float activeFrequency;
float octaveMultiplier = 1;

//float fundementals[] = {220, 220, 233.08, 246.94, 261.6, 277.18, 293.67, 311.13, 329.63, 349.23, 369.99, 392, 415.3, 440, 220, 220};


void setup() {
  // put your setup code here, to run once:
  for(int i = 0; i < 4; i++){
    pinMode(buttonPinsOrange[i],OUTPUT);
    pinMode(buttonPinsBlue[i],OUTPUT);
    pinMode(ledPinsBlue[i], OUTPUT);
    pinMode(ledPinsOrange[i], OUTPUT);
  }
  AudioMemory(127);
  audioShield.enable();
  audioShield.volume(0.1);
  waveform1.setParamValue("gain",0.9);
//  verb1.roomsize(0.2);
//  verb1.damping(0.7);
  //waveform1.setParamValue("duration",0.250);
}

void loop() {
  // put your main code here, to run repeatedly:
 currentPressOrange = readButtonPins(buttonPinsOrange);
 currentPressBlue = readButtonPins(buttonPinsBlue);
 writeLeds(currentPressBlue, currentPressOrange);
 if (currentPressOrange == 0) {
  activeFrequency = 0;
  waveform1.setParamValue("trigger",0);
 } else {
  activeFrequency = octaveMultiplier * (fundementals[currentPressBlue]*pow(2,((currentPressOrange)-1)/12.));
  waveform1.setParamValue("trigger",1);
 }
 waveform1.setParamValue("car_freq",activeFrequency);
 while (currentPressOrange == 14) {
      octaveMultiplier *= 2;
      activeFrequency = 0;
      delay(500);
      break;
    }
  while (currentPressOrange == 15){
    octaveMultiplier *= 0.5;
    activeFrequency = 0;
    delay(500); 
    break;
  }
  
  delay(50);
}

byte readButtonPins(int buttonPinsArr[]) {
  byte r_press = 0;
  for(int i = 0; i < 4; i++){
    if (digitalRead(buttonPinsArr[i]) == HIGH){
      bitWrite(r_press,i,1);
    } else {
      bitWrite(r_press,i,0);
    }
  }
  return r_press;
}

void writeLeds(byte blue_press, byte orange_press){
  for(int i = 0; i < 4; i++){
    digitalWrite(ledPinsBlue[i],bitRead(blue_press,i));
    digitalWrite(ledPinsOrange[i],bitRead(orange_press,i));
  }
}

Any suggestions as to what I could do to remedy this error?
 
Any suggestions as to what I could do to remedy this error?

On the latest version of my TeensyMIDIPolySynth project, simply selecting "Smallest Code" optimization (initially selected because code was exceeding available space) also reduced the RAM usage on my T4.1 . . . you might try the same & see if that works for you.

Good luck & have fun !!

Mark J Culross
KD5RXT
 
Thanks Mark. 6464 bytes to get rid of.


/Applications/Teensyduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: /var/folders/xw/4_chkj0n4w58bfhrx_pb57pm0000gn/T/arduino_build_415137/sketch_may06a.ino.elf section `.bss' will not fit in region `RAM'
/Applications/Teensyduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: region `RAM' overflowed by 6464 bytes
collect2: error: ld returned 1 exit status


If you know faust would you have any suggestions for optimizing this code:

Code:
import("stdfaust.lib");
duration = 0.25;
trigger = nentry("trigger",0,0,1,1);
car_freq = nentry("car_freq",220,0,20000,0.1) : si.smoo;
mod_freq = car_freq*0.5 : si.smoo;
env_length = 1/duration;
mod_index_env = en.ar(1/duration/2,env_length/2, trigger);
modulator = ((os.osc(mod_freq)*mod_index_env) * 0.5) + 0.5;
amp_env = en.adsr(env_length/4,env_length/4,0.5,env_length/4,mod_index_env) * 0.5;
mod_amp_sum = modulator + amp_env;
carrier = os.osc(car_freq) * mod_amp_sum;
process = carrier;
 
Looks like the issue was mostly with the faust code. I replaced os.osc with os.oscb and managed to reduce the the amount of space the code was taking up, THX!
 
For what it's worth, this webpage https://faustdoc.grame.fr/tutorials/teensy/ has a suggestion for reducing the amount of memory allocated to a Faust oscillator. I'm not much of a programmer so I couldn't figure this out.

I did managed to get the Faust flute physical model to run on a Teensy 4.0 using the on-line complier at https://faustide.grame.fr/. My code is at https://github.com/museelectronicinstruments/zen_flute and you can hear the result at https://museelectronicinstruments.com/?page_id=312 (the little music player widget).
 
Status
Not open for further replies.
Back
Top