-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
memory improvement of the tone.cpp lib #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Somewhat related, I just noticed that Tone.cpp defines a lot of variables that are not actually used. For each timer available, it defines Then, depending on the MCU used, the code below selects just one timer to use, and defines the The tone() function itself then again contains code again for modifying all supported timers, even the ones that are not being used. This leads to additional flash usage, but also a bit of memory overhead, since the compiler doesn't seem to always optimize away the unused variables (I noticed this happens when enabling lto). To fix this, both the declarations of variables as well as the code in I've got no time right now to prepare a PR, but still wanted to note this down somewhere in case someone else wants to pick up improving the tone function. |
related idea: On Mon, Jul 13, 2015 at 12:37 PM, Matthijs Kooijman <
|
Why don't try to replace tone()/notone() functions with similar ones obtained from (very) improved libraries like https://code.google.com/p/arduino-new-tone/ or even https://code.google.com/p/arduino-tone-ac/ ?? On the other hand, I didn't understand why official tone() was stripped from https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation ...the ability of using more than one timer or having the list of musical notes already preconfigured are very pleasant things which aren't present in official implementation. It's a pity |
here, for AVR timers, a function that selects prescaler to best match pwm frequency (not just tone) if it helps |
too old to be relevant anymore |
To find the optimal prescaler a formula is repeatedly calculated (9 times). By replacing this expensive formula (long divisions) partly by a precalculated value the size of a sample sketch, and thus the tone lib was reduced by 88 bytes.
Did not test the code but I assume it executes a tiny bit faster.
improved code snippet
and replace F_CPU / frequency / 2 in the rest of the function with ocrRaw.
See forum - http://arduino.cc/forum/index.php/topic,142370.msg1069191.html#msg1069191 -
The text was updated successfully, but these errors were encountered: