Audio effect memory

Status
Not open for further replies.

chandrian

Member
Hello,

I have the Teensy 3.2 and I am adding audio effects that involve memory storage (like delay) and I was wondering if the memory used for that is RAM?
I am also wondering what the "AudioMemory" is for the audio projects. is that the amount of RAM you are setting aside for this storage?

I am trying to use the full extent of the Teensy capabilities

With the Teensy 3.2 I would have 64 kB of RAM so for the following code would the math look like this:
2 byte (16 bit) * 16384 (array size) = 32768 kbyte?


Code:
  AudioMemory(64);
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.volume(0.5);
  sgtl5000_1.lineInLevel(0);
  sgtl5000_1.lineOutLevel(13);
  queue2.begin();

}

void loop()
{  
uint16_t sampleQueue[16384];
uint16_t *queueP = sampleQueue; 

    for(x=0;x<16;x++)
    {
      if(queue2.available() >= 2)
        {
          memcpy(queueP + 256*x, queue2.readBuffer(), 256);
        }
      queue2.freeBuffer();  
    }

Thanks,
Aaron
 
AudioMemory() allocates some of the Teensy's RAM for use by the audio library. This memory is essential, since it's used as buffers for everything the audio library does, and for passing the audio between all the objects you put into your audio system. You'll see this usage reflected in the "memory used for global variables" info Arduino prints every time you compile.

Some effects use these buffers from AudioMemory. Others require you to create an array in your program and pass the array to a begin() function. Those arrays will also show up in the summary Arduino prints. Still others automatically allocate memory inside their objects, which also shows up in the global variables info.

If you look at that summary, you'll notice it mentions leaving the rest of the memory available for local variables. This is important. There's no way for the compiler to completely predict how much space all your local variables will use. Generally we try to not use much inside libraries, but some is always needed, so you can't use up all the memory for globals.

There is 1 special delay effect that uses an external memory chip to store the sound. If you need a longer delay, this can really help. But there is a lot of communication overhead to talk to that chip, so is saves memory but costs CPU time, plus an extra chip.

If you need a lot of memory-heavy effects, usually stepping up to Teensy 3.6 is the best solution.
 
I should also mention those queue objects use the memory you allocated with AudioMemory.

If your program always checks the queue and promptly processes each block, then the queue will use at most 1 of the blocks you allocated.

But if your code needs to go do other work, like drawing big LED art animations, or if you need to wait for something like a SD card write to complete before you can process more audio blocks, the queue will automatically queue up the audio blocks using the memory from AudioMemory. This is meant to relieve you from the burden of always having to process each block before the next arrives. You can occasionally go do big tasks that take more than 1 audio block time, as long as you later catch up. Of course the queue consumes memory if you use it this way. How much memory will depend on the timing of your code, or the timing of whatever other hardware (like a SD card) that it must service.
 
Status
Not open for further replies.
Back
Top