Hi,
Few weeks ago i come to idea to make sound alerts in my home automation system (based on 16 Arduino nano/mega boards). Long story short - after started playing with few simple tones i end on making full MIDI synth ![]()
There's a lot of challenges there, but main ones are:
- Place full set of 127 MIDI programs into about 200Kb (as i need some flash space for main application)
- Get highest possible polyphony on acceptable sample rate
- Get decent output without much additional hardware
I know there are much more suitable boards for such project, with more flash and more CPU power, but my primary goal was to keep cost as low as possible (and compatible with my current system, of course).
So until now, i success to cover most of MIDI instruments (some of them are duplicates of course, as we can't really use 4 different pianos, neither there's necessity for that). Picking right sample for an instrument is quite lot of work. It has to be smallest in size while still sounding quite good, so that's still in progress.
After all possible optimizations, and writing all critical parts in assembler it's possible to achieve up to 20 voices polyphony on 22050 sample rate, 28 on 16000, or 10 at 44100. All is heavily optimized for speed, so some of quality (precision) has to be sacrificed. But unless you are not playing it on Hi-Fi it still sound acceptable.
As audio output i used 16bit PWM timer (5) with 2 pins, one for MSB and another for LSB, so theoretically output is 16bit, but due to all issues with PWM, and with all filtering it's still far from real DAC. But again, pretty much decent considering the cost and simplicity of few resistors and capacitors.
Code is currently mess, and still in development (it took me much more time than i expected on beginning), but i hope i'll be able to put it on GitHub soon, so other can contribute if interested.
Whole point of making such project is to be able to play any of thousands of MIDI files available - in difference from MOD players which are limited to single song in flash memory.
Here's an example of current state of project. If you have some particular MIDI files which you would like me to try, feel free to send ![]()