Thursday, 23 August 2012

First sighting of Raspberry Pi Synthesizer

Welcome to the Raspberry Pi Synthesizer blog where I'll be documenting progress on my virtual analog Raspberry Pi polysynth. Which desperately needs a cool name ...

In the meantime, here's a teaser - the first video of my synth running. I was at the inaugural Raspberry Jam in Bristol 3 days ago, and committed to a few people there that the synth, under development for a few weeks, would be up and running on a Raspberry Pi before the end of the week. And here we are.

The MIDI interface isn't in place yet (I couldn't find the right bits of ALSA last night so just injected a rising test sequence), it should be playable by the end of the week.

Features - she is currently 4 note polyphonic. The target after optimization (and possibly overclocking!) is 8 notes. She - she is definitely a she - has two oscillators, two LFOs, four Envelope Generators for each of VCA, VCF, Noise and Phase Distortion control. The EGs are not ADSR but ADSλR, where λ is the sustain half-life. The use of the Greek alphabet allows the decay of a held note independent of the D setting, and yields beautiful piano-style envelopes. Plus it makes me look quite clever. The two oscillators offer slightly different shapes of the fundamental waveforms - one saw is tighter and more spiky than the other, one square is rounder, one has an impure sin and one has a triangle - which makes adding and ring modulating more interesting. I forgot, she has a ring modulator, allowing an arbitrary blend of A+B and A*B. And a noise generator.

Beyond the harmonics of the oscillators themselves, additional harmonic richness is injected by Phase Distortion of the waveforms. Aliasing is managed by some deeply clever stuff, plus the final edge is taken off by running at 88.2kHz and downsampling to 44.1kHz. Each note has a 4th order resonant low-pass filter capable of self-oscillation.

The modulation system is rather bonkers, and features a bytecode interpreter with a stupidly small instruction set, but rich outputs. Any modulated output can be driven by a reasonably complex program - up to 32 bytecodes - with any modulation input as parameters to a set of multiply and add instructions. Modulation inputs being any of the EGs, the LFOs, magic keywords such as 'KEYFOLLOW' to guarantee a tuned filter response, constant such as 0.1, 3/4, 4/3, -1.0 - it's wild and crazy and great. And a bugger to program, hence the 'templated' approach, where 16 preselected algorithms have been set up as templates and illustrated as vector diagrams on the right hand side of the display, giving you the modulation matrix at a glance. Well, a glance, a frown and some following of pale blue lines with your fingers ...

And as you can see, there is a cool OpenGL ES accelerated user interface featuring a neat oscilloscope.



Much, much more to follow, watch this space. There will be a few more weeks of development before my baby is ready for primetime, so please keep checking back here, I will keep you informed of progress.

In the meantime, here's 30 seconds of video where very little happens ...



And all this - oscillators being alias-managed, bonkers modulation, Moogy rolloff filters, GPU interface with tons of oscilloscope vertices bouncing around in real time - all of this runs on a stock, unoverclocked, 700MHz Raspberry Pi.

It really does sound pretty great, and next week's videos will show that. Rather than being captured on an iPod under low-light conditions so looking horrible and sounding like a wasp trapped in a kettle. But forgive the video quality, it was 11.00 p.m. and I just wanted to celebrate a job well done and get some sleep. 


And for those of you reading with eyes blinded by sheer, undiluted 21st century cynicism - yes, there have been compromises to get here. It has fewer oscillators than a Moog. It will at best only ever be 8 note polyphonic. But at every single compromise point where a quality-vs-anything decision had to be made, audio quality was selected above anything else. And yes, it may need to be overclocked to hit 8 note polyphony, and yes, it may yet need to be cranked down to a mere 32kHz (downsampled from 64) to hit the 8 note target. But even if it does - flippin' eck boys and girls, it's a whole polysynth. And only your nerdiest friends will be able to detect that it's not really analog. Seriously folks - this is about £30 for the entire hardware component of a polysynth tone generator. 

Talk about Moog on a budget ... and lest ye forget, a Moog Slim Phatty - the benchmark of gorgeous, rich analog synth technology, and like the Raspberry Pi Synthesizer a keyboardless tone generator - is over £600, and it plays one note at a time. 

10 comments:

  1. This is beautiful! You've got some real features going on here -- impressive. For more polyphony, how about adding another Pi as a slave? They're cheap enough, and you could probably get away with the $25 model A. Are you planning MIDI via USB, or via GPIO? Lastly, are you using the Raspi's internal audio out, digital out via HDMI (are these driven simultaneously?), or something else via USB?

    I'm excited -- can't wait to see what else you do here!

    ReplyDelete
    Replies
    1. Hi Jeff, thanks for dropping by. First visitor!

      The Pi audio port is a thing of horror - it's 1 bit PWM from a 100MHz clock, so is equivalent to only some 11 bits of 44.1kHz audio, and 11 not very good bits, it gets crunchy and ugly at even modest frequencies. So audio output will have to be HDMI-only for now. USB remains flaky on the Pi - my keyboard (ASCII) repeats randomly so I have to always use SSH into it, and today's post describes the USB MIDI really hurting performance, so I'm going to have to bridge a UART via an optocoupler to drive proper old-fashioned MIDI. In many ways the simpler the better with this thing, but it's a shame you have to get the quality audio output from a TV.

      It should be playable tomorrow (Saturday 25th August 2012, for future historians dragging through this in 2016 ... )

      Delete
  2. Note to historians - it's Saturday 25th August 2012 and indeed it's all workign just fine. Yay!

    ReplyDelete
  3. Hi, I'm actually staring a pi-based synth project, maybe it's a little different from yours, but you might be able to help me:
    my goal is to have a midi-in/audio-out, both via the same USB pipe, with 48khz/16bit sampling. since I saw you had a visual interface, i guess it is some heavy work on the chip... so the question is, do you think that, without the screen, i can actually manage to do this kinda device without the processor being overloaded? It has 2osc, 1 WN osc, 2 LFOs, 2 Enveloppes, an effect chain, and a master filter... btw, nice project!

    ReplyDelete
    Replies
    1. Hi Alexis

      The GUI is not as heavy as people seem to imagine, it is only consuming some 8% or so of the CPU, it's a much smaller burden than the work done to implement the modulation matrix for example, which is the biggest load outside the synthesis. I'm synthesizing at 88.2kHz, downsampled to 44.1, 8 voices, each voice has 2 OSCs with very careful alias management, 4 EGs (Phase, Pitch, Amplitude and Filter) and 2 LFOs, so you should be fine.

      Delete
    2. well thanks you... you're probably right, since i'm going to do something monophonic... not because of the hardware restriction, but because of the software knowledge i dont have... another question tho, what is the point of sampling at 88.2kHz and then downsampling it?

      Delete
  4. It's one of the many ways I'm keeping the alias energy low. I'd like to say 'eliminating aliasing' but 'keeping the alias energy low' is more honest!

    ReplyDelete
  5. Rubus Synth.

    http://en.wikipedia.org/wiki/Rubus_idaeus

    ReplyDelete