Arduino Mega General MIDI Synth

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 :slight_smile:

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 :slight_smile:

After getting decent sound output from atmega, i realised that it would be a shame to not use those cheap ESP32 boards which offers hundreds of times processing power of Mega so i continue project on it. After some weeks of coding i success to got really nice output in combination with cheap i2s DAC. Unfortunately, i still have not enough time to clean the code and make it in library form, simple to add to existing projects. Sample set is still below 500kb so there are plenty of room for samples quality improvements.

Some of upgrades:

  • Stereo 16bit output
  • 60 channels maximum polyphony (automatic drop down if cpu is too busy)
  • Reverb, Chorus, Flanger and Distortion/Overdrive effects
  • Pitch bend and Modulation support
  • Parabolic interpolation, which dramatically improves sound quality, even with 8bit samples
  • Use of both cpu cores for maximum efficiency (one for samples processing, another for effects)

Here's some samples of midi files played via ESP32 soft synth: