AudioSheild Memory Question

Status
Not open for further replies.
Hey Paul :)
Im almost done with my SynthGuitar Project
but Im not sure how to use properly the AudioMemory() function, how do I calculate the numberBlocks? How do I guess the numberBlocks?

thanks ahead :)
 
Reasonably sure here, won't be long before I am corrected if this is bad advice or something :)

If you use the http://www.pjrc.com/teensy/gui/ to create your virtual audio pathway then, for most objects in the library, just count each connection made and then add memory blocks per the following rules;

Add one more memory block for each source object (AudioInput* AudioSynth* etc, no connections on left side in gui), counting connections again - as in, give it two for AudioInputI2S.

Add a block per 2.9mS of delay you set in any AudioEffectDelay object plus one (no harm bumping up to two) for safer margin.

If you use an object that may require extra memory blocks then try to find out maximum blocks it may acquire at any given time and add one more to this figure too.

Another extra block per terminating signal (object receiving doesn't have connections on right in gui) may be worth it but if you've obeyed the other rules then you can disobey this one imho.

Add one more just for good measure :p
 
Reasonably sure here, won't be long before I am corrected if this is bad advice or something :)

If you use the http://www.pjrc.com/teensy/gui/ to create your virtual audio pathway then, for most objects in the library, just count each connection made and then add memory blocks per the following rules;

Add one more memory block for each source object (AudioInput* AudioSynth* etc, no connections on left side in gui), counting connections again - as in, give it two for AudioInputI2S.

Add a block per 2.9mS of delay you set in any AudioEffectDelay object plus one (no harm bumping up to two) for safer margin.

If you use an object that may require extra memory blocks then try to find out maximum blocks it may acquire at any given time and add one more to this figure too.

Another extra block per terminating signal (object receiving doesn't have connections on right in gui) may be worth it but if you've obeyed the other rules then you can disobey this one imho.

Add one more just for good measure :p

1st) thanks for your reply :)
2nd) what's the max no' of blocks I can input in the function AudioMemory()?
Won't it be easier to just put the highest possible block number and run it once with the function AudioMemoryUsageMax() to know the recommended number of blocks ?
 
The maximum depends on how much of the appropriate pool of memory your sketch leaves after compilation.

Easier to rough guesstimate loosely based on a stripped down version of what I posted and then multiply that by anything you like and then run the sampling test to find maximum actually employed - make sure you make the library do everything it may do during that test run.
 
Yup, the number of memory blocks your audio sketch will use is hard to predict. The process is mostly a matter of guessing and then checking with AudioMemoryUsageMax.

If you have a project where audio isn't always generated, like synthesis objects feeding into delay objects for funny echo sounds, check AudioMemoryUsageMax() *after* you've used all the functionality. Almost everything in the library tries to conserve memory, so you might not see the max until you've generated many sounds. For simple projects where you're just processing live audio the same way all the time, or just playing a file without anything fancy, AudioMemoryUsageMax() should give you the true maximum very quickly. It's the synthesis and memory-hungry delay effect you need to keep an eye on.
 
Yup, the number of memory blocks your audio sketch will use is hard to predict. The process is mostly a matter of guessing and then checking with AudioMemoryUsageMax.

If you have a project where audio isn't always generated, like synthesis objects feeding into delay objects for funny echo sounds, check AudioMemoryUsageMax() *after* you've used all the functionality. Almost everything in the library tries to conserve memory, so you might not see the max until you've generated many sounds. For simple projects where you're just processing live audio the same way all the time, or just playing a file without anything fancy, AudioMemoryUsageMax() should give you the true maximum very quickly. It's the synthesis and memory-hungry delay effect you need to keep an eye on.

Thanks :)
But, I figured it out that way, My new question is - what's the maximum no' of blocks I can put in the function AudioMemory();?

And one more question, I want to built in the Synth a Midi In option, what's the name of the chip you've used for the MidiIn example in the MIDI.h library?
https://www.pjrc.com/teensy/td_libs_MIDI.html
 
Thanks :)
what's the maximum no' of blocks I can put in the function AudioMemory();?

Each block uses 260 bytes of RAM.

Every time you compile, Arduino prints a message like this:

Global variables use 2,184 bytes (26%) of dynamic memory, leaving 6,008 bytes for local variables. Maximum is 8,192 bytes.

(ok, that one is for Teensy-LC.... it was still on my screen from just answering the thread about float point speed.....)

As you increase the amount of memory you're giving to the audio library, you'll see the "global variables" number go up, which reduces the amount of memory left over for local variables.

If you never create arrays as local variables, and you're not using the special String variables, you can probably get by with very little memory left over for local variables, maybe as little as a few hundred bytes. Maybe? It all depends on your code, and the code in all other libraries you're using. They need some amount of memory for local variables, and they also contribute to increasing the global variables, so the number of blocks you can give to the library depends on the amount of extra memory. That message Arduino prints is your best guide!

I should point out there is absolutely no benefit to giving the audio library more memory than it needs. Nothing in the library will utilize the extra memory. The only reason to give extra memory is if you're doing complex synthesis with lots of voices, where it's very hard to get the worst case to happen, so you're not entirely sure if you've ever really seem the true maximum worst case with AudioMemoryUsageMax().

And one more question, I want to built in the Synth a Midi In option, what's the name of the chip you've used for the MidiIn example in the MIDI.h library?
https://www.pjrc.com/teensy/td_libs_MIDI.html

PC900. See the schematic, on the same page.

If you're transmitting, also pay attention to the footnote about resistor values for 3.3V signals.
 
Each block uses 260 bytes of RAM.

Every time you compile, Arduino prints a message like this:


The maximum no of voices is 6 voices obviesly haha (6strings) so I guess it's still possible
(ok, that one is for Teensy-LC.... it was still on my screen from just answering the thread about float point speed.....)

As you increase the amount of memory you're giving to the audio library, you'll see the "global variables" number go up, which reduces the amount of memory left over for local variables.

If you never create arrays as local variables, and you're not using the special String variables, you can probably get by with very little memory left over for local variables, maybe as little as a few hundred bytes. Maybe? It all depends on your code, and the code in all other libraries you're using. They need some amount of memory for local variables, and they also contribute to increasing the global variables, so the number of blocks you can give to the library depends on the amount of extra memory. That message Arduino prints is your best guide!

I should point out there is absolutely no benefit to giving the audio library more memory than it needs. Nothing in the library will utilize the extra memory. The only reason to give extra memory is if you're doing complex synthesis with lots of voices, where it's very hard to get the worst case to happen, so you're not entirely sure if you've ever really seem the true maximum worst case with AudioMemoryUsageMax().



PC900. See the schematic, on the same page.

If you're transmitting, also pay attention to the footnote about resistor values for 3.3V signals.

I can't seem to find that chip....
And really, thanks a lot :)
 
Status
Not open for further replies.
Back
Top