going-digital / Talkie

Speech library for Arduino
314 stars 112 forks source link

Add memory management, remove static declarations and store/restore timer register values #14

Open idhanu opened 8 years ago

idhanu commented 8 years ago

I was working in a project which is tight on memory and the MCU has to switch between tasks. So, I improved memory management in the library to be local to the object. Please feel free to use/distribute my suggestions. I also added .begin() and .end() functions which respectively store and restore timer register values modified in the library. Now the library uses less than 10 bytes of statically allocated memory.

Following is a example usage in which the library is allocated in the call stack and released after the function call. The destructor calls .end() and clean up after use. void sayGreeting() { Talkie voice; voice.begin(); voice.say(spGOOD); voice.say(spMORNING); voice.say(spPAUSE1); voice.say(spTHE); voice.say(spTIME); voice.say(spIS); voice.say(spELEVEN); voice.say(spTHIRTY); voice.say(spFOURTY); voice.say(spFIFTY); voice.say(spEIGHTEEN); voice.say(spSIX); voice.say(spA_M_); voice.say(spPAUSE1); Serial.print("freeMemory()="); Serial.println(freeMemory()); }