So I did try to use the NCO (Numerically Controlled Oscillator) to generate a variable time base for each vowel and it kind of worked. It actually turned out to be easier than expected.
The idea worked like this:
- I kept the PWM working on TMR2 with a fixed frequency of 32kHz.
- I modified the main loop to wait on the NCO interrupt instead of the TMR2 postscaler.
- I assigned an initial NCO "increment" (524) to obtain the standard 8kHz sample rate.
I run a test to verify that this way I would get the same output as before (when using the TMR2 interrupt). it did!
(NOTE: increment = Fout / (Fosc / 2^20) = 8000 / (16MHz/1MB) = 524)
- I removed the tables for the vowels 'e' and 'i' and replaced them in the scheduler with 'a'.
- I added for each 'part' in the schedule a setting for the NCO increment leaving the value to 524 ( the constant EIGHTK) for all non vowels.
- I scaled the value of INC proportionally to the length of each of the vowels tables. (E = 645, I = 870)
While debugging the new code I found out a bug in the "silence" table (the signature was supposed to be changed to 0xff, but I had forgotten to update it).
I created a new branch of the project on Github (NCO) and later went back and fixed the "silence bug" in the "master" too...