A Slew Of Open-Source Synthesizers

Hackaday reader [Jan Ostman] has been making microcontroller-based DIY synthesizers for quite a while now. Recently, he’s opened up the source for a lot of them so that you can play along at home. All of these virtual-analog synths and soundmakers can be realized on an Arduino or AVR ATmega328 if you happen to have one lying around.

Extra parts like a keyboard, some pushbuttons, or some potentiometer knobs to twiddle won’t hurt if you’d like to make something more permanent or more obviously playable, like [Jan] does. On the other hand, if you’d just like to get your feet wet, I’ve tweaked his code to be more immediately plug-and-play. The code is straightforward enough that it’s a good learning platform. So let’s take a quick tour through three drum machines and a string synth, each of which you can build on a breadboard in just a few minutes.

To install on an Arduino UNO, fetch the zip file from this GitHub repository, and move each subfolder to your Arduino sketch directory. You’re ready to play along.

Simple Drum Machines

[Jan] has two sample-playback~based drum machines that he’s published the code for: the dsp-D8 with straight-ahead drum samples and the dsp-L8 loaded with Latin percussion. They’re essentially the same code base, but with different samples, so we’ll treat them together.

Working through [Jan]’s code inspired me to write up a longer article on DDS playback, so if you want to brush up on the fundamentals, you can head over there. The short version is that you can change the pitch of playback of a sample by using a counter that’s much larger than the number of data points you’re going to play.

dds.sch[Jan]’s drum machines all use the AVR’s hardware pulse-width modulation (PWM) peripherals to play the samples back out. You could use something fancier, but this gets the job done with just an optional resistor and capacitor filter on the output, bringing the total parts count to three: Arduino, 1 KOhm resistor, and a decent-sized (0.1 uF?) capacitor. An interrupt service routine (ISR) periodically loads a new sample value into the PWM register, and the AVR’s peripheral hardware takes care of the rest.

One nice touch is the use of a circular buffer that holds the playback sample values until the ISR is ready for them. In the case of the drum machines, there’s not much math for the CPU to do — it just combines the samples from all of the different simultaneous voices — but in his more complicated modules this buffer allows the CPU to occasionally take more time to calculate a sample value than it would otherwise have between updates. It buys [Jan]’s code some breathing room and still allows it to make the sample-playback schedule without glitching.

dsp-l8-shot0001[Jan] adds individual pitch control for each sample, which is great for live playing or tweaking, and you can watch him use them in his two videos: one for the dsp-D8 and another for the dsp-L8. Wiring up so many knobs is a breadboard-salad, though, so I’ve gone through the code for you with a fine-toothed chainsaw, and hacked off [Jan]’s button-and-knob interface and replaced it with the Arduino’s built-in serial I/O.

To play my version of [Jan]’s drum machines, each sample is mapped to a key in the home row: “asdfjkl;”. If you’ve got a proper serial terminal program that transmits each keystroke in real-time, you’ll be tapping out rhythms at 9600 baud in no time. Note that the Arduino IDE’s built-in terminal only sends the keystroke after you hit “enter” — this makes playing in tempo very difficult. (I use screen /dev/ttyACM0 9600 or the terminal that’s built-in with Python’s pyserial library myself. What do Windows folks use for a real-time terminal?)

If you haven’t already, download this zip file, move each sub-folder to your Arduino sketch directory, and connect an amplified speaker either directly to your Arduino’s pin 11 and ground, or include an RC filter. It’ll only take a second before you’re playing. When you want the full version with all the knobs, head on over to [Jan]’s site.

O2 Minipops

[Jan]’s O2 Minipops machine mimics an old-school rhythm box: the Korg mini pops 7. Whether this primitive drum machine is horribly cheesy or divinely kitschy is in the ear of the beholder, but it’s a classic that has been used all over. [Jan]’s named his after an epic album Oxygene by Jean-Michel Jarre. You’ll hear them starting around 1:40 into the clip. Jarre famously used to press multiple buttons on the Minipops, making more complex drum patterns by playing more than one at a time.

The nice thing about having your own Minipops in minipops-shot0001firmware is that you can add the features you want to it. Instead of having to mash down multiple plastic buttons live on stage like poor Mr. Jarre, you can just tweak the firmware to suit. Need longer patterns? You’ve got the RAM. Emphasis? Swing? Tap tempo? It’s all just a matter of a few lines of code.

The sound playback code is just like the simpler drum machines above, so we won’t have to cover that again. The only real addition is the sequencer, but that’s where the real magic lies. After all, what’s a drum machine without some beats? Because there are eight possible drum sounds, each beat is a byte and so four bars of 4/4 time is just sixteen bytes stored in memory. I broke the data out into its own header file O2_data.h, so have a look there for the pre-programmed rhythms, and feel free to modify them to suit your own needs.

In order to make the O2 Minipops immediately playable, I stripped out the potentiometer code again (sorry [Jan]!) and passed off control over the serial port. The “user interface” has five controls. Press j and k to switch between patterns and f and d to speed up or slow down. (They’re under your first two fingers in the home row.) The space bar starts and stops the drum machine.

Try switching between the patterns on the fly with j and k — it’s a surprisingly fun way to create your own, slightly less cheesy, patterns. You need to download this code and give it a try. Trust me.

The Solina

[Jan] has also built up a full-fledged string synthesizer keyboard out of just an Arduino Nano. It’s patterned on the Eminent Solina String Ensemble, and we’ve got to say that it gets the sound spot on.

Solina — the Original

[Jan]’s Solina is a “virtual analog” in the sense that it builds up sawtooth waveforms in the microcontroller’s RAM and then outputs the corresponding voltage through PWM. And that’s a good start for a string synthesizer, because a filtered sawtooth waveform is a good first stab at the sound put out by a violin, for example.

Solina — the clone

The secret to the sound of the string section of an orchestra (and to string synthesizers that mimic it) is that it’s a combination of many different bowed instruments all playing at once. No matter how precise the players, they’re each slightly differently tuned, and none of the strings are resonating exactly in phase. The Solina mimics this by detuning each oscillator, naturally, and by moving them in and out of phase with each other. If you want to dig into the details of how exactly [Jan]’s Solina works, he explains it well in this blog post.

Again, I’ve converted it for direct-serial control, and you can control the envelope, detune, LFO speed, and modulation depth over the serial port. Press the spacebar once to simulate a keypress, and again to let go. Try the Solina with detune and pitch modulation around twenty, and play with the LFO rate and other parameters. That’s a lot of useful noise for just some sawtooth waves.

Keyboards and What’s Next

swissonic49[Jan]’s builds are much more than what we’re demonstrating here, of course. His blog kicks off (in 2009!) with a project that essentially shoe-horns a PC into a keyboard enclosure, and the Solina and others get their own keys too. We’ve just presented the kernel of any such project — there’s a lot of labor-of-love left in wiring up all of the diodes necessary to do detection on a keyboard matrix, to say nothing of building enclosures, wiring up potentiometers, and making nice-looking front panels. But if you want to start down that path, you’ve at least got a good start.

[Jan]’s current project is the Minimo miniature monophonic synth that takes the Solina a step further and adds a lowpass filter with (digital) resonance to it. The resulting sounds are great, so we’re excited to see where [Jan] takes this one in the future.

Thanks again, [Jan], for opening the code up. And if any of you build something with this, be sure to post in the comments and let us all know. Since I started playing around with these, I’ve got the hankering to modularize the code up a bit and make it into something that’s even easier to adapt and modify. Maybe we’ll have to start up a Hackaday.io project — these little simple synths are just too much fun!

57 thoughts on “A Slew Of Open-Source Synthesizers

  1. I’m currently waiting on a new sync cable for my TI83+ so I can put HoustonTracker on it (my old black serial version broke,) which iirc, you guys covered a couple of months ago. How’s that for an open source synth?

      1. No, you stubbornly refused to accept that your understanding of what aliasing is, why it happens, and how to alleviate it was incorrect. From the looks of it, it would have been a simple fix, but pride got in your way.

        I don’t care that you think it sounds good, I don’t care that you’ve made mad bank from your synths. I care about making my own, and I can’t do that with bad underpinnings. That’s why I warned people: so they don’t start trying to make something great based on it, only for them to be disheartened when they find their core algorithm is broken, and they can’t fix it without ruining the rest of their creation.

    1. I can almost certainly guess what you found in your google search, but the code is up there to hack and improve and am sure people using it as a basis of a device will do just that. :-)

    2. You mean the ramp waveform in Solina, right? Not band-limited. Meh.

      The drum machines are awesome, and the string synth gets pretty nice 4-voice chorused pads out of an AVR/Arduino. He could maybe get a DDS routine working, but my guess is that the cycles are kinda tight. Especially since Jan’s version runs MIDI at the same time.

      1. I already had synth code for AVR (that I had done on ATmega328), so it started out as a port of a synthesis engine I had built before. Then I used the extra power to do more. I squeezed 5-note polyphony @ 22KHz out of the 32MHz xmega. I’d do it on an ARM today, though.

  2. I actually started making VA-synth’s on ARM, namely the NXP LPC-810.
    That’s 60MIPS on a 48MHz 8-pin DIP with 4Kb of flash.

    Turned out pretty well, turned into the dsp-G1, sold by Adafruit.
    Yes, 5 voices of MIDI synth an extremely small package.

    So I thought why not AVR and 20MIPS?
    It can only be 3 times slower?

    Turned out it can do alot with clever code optimizing.

    After all it’s 20 times faster than the C64?

    1. The chipophone, and Linus, are amazing. I’m not sure that they _did_ get forgotten. The article wasn’t an overview of everything awesome in 8-bit synths, although it’s certainly turning into that in the comments — which isn’t a bad thing. :)

  3. And this is taking over my desk at the moment:

    I suspect my end goal (Mono/Paraphonic Hybrid synth) is a bit different than Janstoman’s, but his code has an efficient key scanning routine and there are some cool tricks in the sound code, particularly the delay / phaser. It’s worth the time to tinker with but that said if you want HiFi sound look at 12 or 16bit DACs and faster MCU’s.
    I was using the nebulaphone code earlier and suggest that is also worth looking at, though it has some basic issues (off by one errors and wave tables for square waves come to mind)
    Janstomans code fitted my immediate needs to connect the keyboard and test paraphony better.

    Janostman, would you please consider licensing your code? GPL or CC-NC-SA might suit if you don’t want commercial usage, otherwise MIT is a good permissive licence.

    Some quick things I have found tinkering with the code:
    At ~64kHz there is very little time to do anything else in the DCO, I implemented a simple 2/ sub oscillator and had issues.
    The current code uses a variable sample rate, this make it hard to modify the VCO as sometime things will work when 1-2keys are pressed, but more start glitching.

    I’ve tried backporting the code snippets from the monophonic synth post on his blog and could not get it to work, I did not expend much time (as I assume he will release the code soon, please:) ), but I’m not a novice programmer either.
    Each oscillator is less than 6bits, with 2 oscillators per voice, the remaining bits are used for phaser feedback.

    On the breadboard is a VCF / LPG (Low pass gate) based on the Korg Monotrons / MS-20’s VCF with a DIY Vactrol instead of transistors. If you want to put the current output through a LPG then you need to remove the VCA code and either use the gate output to control a Attack / Decay circuit, or output the envelope on a different PWM pin (I’m still working on the later)
    It is very easy to overdrive the VCF with paraphony, sounds like an electric guitar distortion!

    And yes, thats a CD4051 and a bunch of POTs in the background waiting to be wired up.

  4. I am not poor to need to have live alterable not intended by design “hacks” in a drum machine. I can’t program anything live or ahead of time anyway, nor do I want to. I was pretty young when on seeing one of the first gen drum machines in an organ I mashed down two buttons and heard a new beat. The store salesman said not to do that simply because it was not intended, and not musically correct! Later the Minotaur was the first all electronic hit. In it Kingsley mashed several buttons for a hypnotic beat to go with first gen Moog tracks.
    Sadly when organs went from diode matrices to serial ROM this great feature went away.

    I have a Roland CompuRhythm machine with multi rhythm button capability and separate hi hats or cymbals in 1/4, 1/8, or 1/16’s. You can drop the rhythm and keep that hi hat ticking, just like a good live drummer just by mashing a few buttons. The only thing programmed in the thing is the basic rhythms. Though they are chip based they are mash-up able.

    Lastly I will pay attention when one of these micros can run ZynAddSubFX, which shouldn’t be too long if not now. Some Romanian software ain’t bad.

  5. I’m thinking of making the CZ-VCO open source.

    Its based on the classic Casio PD algorithm, a Yamaha FM ripoff because at the time it was patented and could not be used.

    It runs at a 66.9KHz samplerate and can do resonant sweeps without a filter.

  6. Quick question: Is there a handy utility to convert audio files to byte arrays like those used in Ostman’s include files? I would like to use my own samples but don’t want to do hexadecimal math on my fingers and toes.

  7. …And one more thing. Although I do not know why Jan Ostman went offline, I can see he was relentlessly bullied by someone who never lost a chance to criticize his minimalist digital-to-analog style. It’s pretty darned strange. Here you have a very creative hacker outputting audio over PWM, and someone who thinks his lack of a high-resolution anti-aliased DAC makes him some kind of a crook. Here we are in 2020 and Teensy-based polyphonic synthesizers are selling.

    Ostman was an explorer who kicked open a door where there was no door before, and that is how others then come in with their calipers, oscilloscopes and ieee standards to exploit the possibilities.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.