Ok, so I am overhauling the sound library.
What I am doing is I am making it faster & I have improved the resolution of the frequency counters to a whopping 32 bits. This means frequencies are mostly +/- 0.0001 accurate.
32-bit counter means the jitter and the fuzz is gone from the sound.
I am also adding a switch that allows you to decide what is the max sampling frequency you want to use in your game.
But heres this nights work, you can try it out yourself
syntest.bin (40.7 KB)
I’m by no means a sound expert. I have loaded this and compared it to a previous build of the synth test. From what I can tell the actual frequency seems more accurate compared to the old build. In the old one, certain notes would get washed out and almost muted. This seems to more accurately cover the spectrum.
Its a bit of a long story. The synth functions are a carryover from my 8-bit library for the AtMega328. Instead of calculating new frequency tables when launching the Pokitto, I just “multiplied” the tables by 4… I know, I know. Horrible.
Now I recalculated the frequency tables at 32 bits and verified the frequencies with an oscilloscope.
Tomorrow I will look at two other things that will further improve sound, namely:
- sound buffering (it is completely real time now which is kind of not good)
- transfering that buffer with DMA, thus unloading that from the cpu
Almost done with the DMA. Unfortunately it will not help as much as I thought.
But digging deep into the mbed internals I have found several things that are eating our MCU cycles in a devious way. One of these things is the Ticker class used to fire the sound interrupts at the moment.
The Ticker class allows you “to create any number of timer driven interrupts in a hardware abstracted way” … sounds too good? It is. A function loops compares timestamps and goes through a list of attached function pointers … on every cycle…
The moral of this story is (probably) that abstractions only help if they’re well designed/tested abstractions.
(Was that supposed to link to the mbed OS 2 page rather than the OS 5 page?)
Depends what you are designing. I applaud the fact that the same class works across 50 different boards but just like Arduino digitalWrite() all of it has to be replaced with pure register writes if you need speed. Which is exactly what I am doing.
I guess in this case it’s one of those ‘rapid development’ vs ‘longstanding tech’ things.
The components mbed offers are probably designed for the former, whereas the Pokitto is the latter.
Though I still have a feeling that a lot of mbed’s components would benefit from taking a template-oriented approach and using composition instead of using inheritance and virtual functions.
(I had a peek at the source. I’m not sure if this is the same version that was being used or not.)
Getting rid of Ticker class sped things up quite a bit, and there is still room for improvement.
Here is a new sound test at 22050Hz with new tables.
syntest.bin (41.7 KB)
Oops! Ignore the “Hello” and the random popping pixels on the screen in the beginning, thats actually parto of the DMA to screen test
Oh ! Oh !
I was able to up the output to a smooth 22kHz
… then I noticed …
I had compiler optimization flag -O0 (optimization completely off) …
Now setting -O3 (maximum optimization) …
this is going to be so smooth!
Holy moly this thing is fast now.
44.1 kHz sound (CD sound frequency) and screen is still updating very fast
syntest.bin (41.4 KB)
Finally we can get both the good gfx fps and the good quality audio in the game
Video or it didn’t happen
Pokitto improved core sound routines. In the demo two oscillators one octave apart are playing 1-3-5 arpeggios simultaneously.
There is no external amplification! This is directly recorded on a cell phone with sound coming from the internal speaker. The sound from the headphone jack is better (much higher dynamic range).
syntest.bin (41.4 KB)
Now we just need @NullMember to come back from retirement and start working on the tracker with me again!
And @trelemar should start looking for a musician / sfx for Doon
THIS IS AWESOME! I might know a guy or two. Is there a specific tracker you can confirm to eventually support?
I’m at Istanbul for a week. When I back to my home I can start working again
Is sound improvements synced with github repo? Github says last commit on sound related files 3 month ago
@NullMember: will be upped today/tomorrow
I just came back from a work trip in Sweden. I am working on still adding the tracker functionality (time of sounds). Once that is tested, its going up.
Yay! I have SDFileSystem running now! It is much faster, supports even things like mkdir and file deletion, directories, multiple open files, format SD card…
The idea is to improve the SD reading speed to allow better SD music streaming in games
Mbed has alot of ready-made good stuff. It just took a while to fit it to work with PokittoLib (there’s still a Ticker-conflict to solve)
Sound improvements pushed to github now, check the “SynthTest” project target
(SD lib improvements not yet, coming soon)
(Pushing to mbed online next)
Improvements now also in mbed online library
You will find sound kicks ass much more now in the games, especially the speaker output is louder