sensorium / Mozzi

sound synthesis library for Arduino
https://sensorium.github.io/Mozzi/
GNU Lesser General Public License v2.1
1.07k stars 186 forks source link

Arduino Uno R3 not enough memory #266

Closed ilmank closed 2 months ago

ilmank commented 2 months ago

Hi, I'm using an Arduino Uno R3 to run Mozzi, but I get errors regarding how much dynamic memory the global variables are using.

I tried compiling code from other people's tutorials to test if my code is the problem, but when I try to compile the same code that worked in the tutorials I also run out of memory,

I've put my code below and attached the "d_kit.h" in a zip file. Are there any issues in how I'm using the library which is causing memory problems?

#include <Mozzi.h>
#include <Sample.h> // Sample template
#include "d_kit.h"

//#define OUTPUTSCALING 9

int readV = A5;
int val = 0;
int lastVal = 0;

Sample <BD_NUM_CELLS, AUDIO_RATE> aBD(BD_DATA);
//Sample <SD_NUM_CELLS, AUDIO_RATE> aSD(SD_DATA);
//Sample <CH_NUM_CELLS, AUDIO_RATE> aCH(CH_DATA);
//Sample <OH_NUM_CELLS, AUDIO_RATE> aOH(OH_DATA);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  startMozzi();
  // Initialise all samples to play at the speed it was recorded
  aBD.setFreq((float) D_SAMPLERATE / (float) BD_NUM_CELLS);
  //aSD.setFreq((float) D_SAMPLERATE / (float) SD_NUM_CELLS);
  //aCH.setFreq((float) D_SAMPLERATE / (float) CH_NUM_CELLS);
  //aOH.setFreq((float) D_SAMPLERATE / (float) OH_NUM_CELLS);
}

void loop() {
  audioHook(); 
}

void updateControl() {

  val = analogRead(readV);
  Serial.println(val);

  if (val >= 50 && lastVal < 50) 
  {
    aBD.start();  
  }
  else
  {

  }

  lastVal = val;
}

AudioOutput_t updateAudio(){
  int16_t d_sample = aBD.next(); //+ aSD.next() + aCH.next() + aOH.next();
  return MonoOutput::fromNBit(10, d_sample);
}

[d_kit.zip](https://github.com/user-attachments/files/16172953/d_kit.zip)
sensorium commented 2 months ago

Hi ilmank, it compiled here after removing these lines from d_kit.h:

undef CONSTTABLE_STORAGE

#define CONSTTABLE_STORAGE(X) const X
ilmank commented 2 months ago

Awesome! Works perfect, thanks so much.