jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

RPi Synthesizer Project

Thu Dec 08, 2016 10:39 am

https://github.com/james7780/synth/

The aim of this project is to build a "self-contained" synthesizer workstation using a RPi 2, a touchscreen LCD display and a MIDI keyboard.

The github above holds the source code for the project, which is split into 2 modules:
"Synth Engine" - the process which runs in the background, manages the virtual waveform-based synthesizer, and generates the audio output.
"Synth GUI" - the GUI application "front-end" for editing the synth "patches", customised for the offical RPF 7" touchscreen display.

The Synth Engine and Synth GUI communicate using MIDI "control commands" sent via the "mqueue" messaging system. This means that the Synth GUI can be replaced by writing another app that conforms to this (simple) messaging protocol.

The waveform-based synthesizer is written from scratch. If features 2 oscillators per voice, adjustable waveforms, adjustable pulse-width ("phase distortion"), detune, DAPDSR envelopes for Volume/Pitch/Filter/PWM, LFO, Reverb. Needs more work on the filters.

The project not complete, but in a working state. Of course there will be some bugs.

Youtube video of the synth in action: https://www.youtube.com/watch?v=_NiGQofBNt4
Last edited by jum on Wed Dec 21, 2016 12:19 pm, edited 2 times in total.

IanS
Posts: 232
Joined: Wed Jun 20, 2012 2:51 pm
Location: Southampton, England

Re: RPi Synthesizer Project

Thu Dec 08, 2016 10:59 am

Good luck with this. I am working on something comparable and will be releasing documentation once it is closer to being finished, but I have only done 2/3 of the woodworking required so far.

What kind of latency do you get between pressing a note and the sound starting? Is there any noticeable delay?

I found that if the latency is around 100ms or more, it is enough to be noticed. There is the note up/down detection, the sound generation and then getting it through the audio buffers. One of the contributing factors is the slow serial rate of hardware MIDI at 31250bps. A ten note chord can take 8ms just to send down the wire, so I ripped the MIDI encoders out of the keyboards I am using and scan the hardware switches directly using MPC23017s off the GPIO port. I can now check the state of all 61 notes in about 3ms, and that is using Python. I could go faster by using C[++] if I needed to. My total latency is now about 60ms, which is fast enough that I don't notice it while playing, but I might try to get it a bit faster to allow room for adding additional features.

jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

Re: RPi Synthesizer Project

Thu Dec 08, 2016 12:07 pm

Hi Ian, thanks for you insight.

I have tried to minimise latency. The code is all C++, the audio buffer size is small as possible, and the synth engine has a thread which reads MIDI on/off directly from /dev/midi. Initially the latency was quite bad, until I adjusted the audio buffer size. Now I would say that its "acceptable". That said, I am sure there is room for improvement. I will have to add some test code to log the time when the MIDI note is received, and the audio buffer fill is complete.

I also considered maybe using an Arduino in the future to scan keys directly and send to RPi via SPI or something.

I have designed a case (retro 70's style, inspired by Fairlight etc), have the wood, just need to get on with the woodworking :)

Good luck with your project, let me know when you have something to show.

IanS
Posts: 232
Joined: Wed Jun 20, 2012 2:51 pm
Location: Southampton, England

Re: RPi Synthesizer Project

Fri Dec 09, 2016 3:28 pm

Are you planning on housing the RPi in a Fairlight processor unit style (and size) box?

jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

Re: RPi Synthesizer Project

Fri Dec 09, 2016 8:13 pm

No. I'm making something a lot more portable.

The RPi is attached to the back of the 7" touchscreen, both will be housed in a wooden case roughly 220x130x45mm. This "screen box" will be mounted on a swivel pole which is fixed near the back of the main keyboard unit.

Keyboard unit will be wood for retro look, and will have a slightly tilted shelf behind the keybed, to rest an ASCII keyboard on, and to maybe house 2 4" speakers at either end.

See attached (rough) sketch.
Attachments
WP_20161209_22_08_26_Pro.jpg
Sketch of case
WP_20161209_22_08_26_Pro.jpg (62.08 KiB) Viewed 3800 times

IanS
Posts: 232
Joined: Wed Jun 20, 2012 2:51 pm
Location: Southampton, England

Re: RPi Synthesizer Project

Mon Dec 12, 2016 5:14 pm

Mine will not be especially portable. At least, not without some disassembly first.
ManualsAndStops.JPG
ManualsAndStops.JPG (62.51 KiB) Viewed 3680 times
I currently have the notes, stops, couplers and presets wired in and working for the pair of manuals. I still need to add a pedalboard and a case to hold it all together.
Each keyboard (both manuals and pedals) requires a RPi, and when the couplers are active they communicate across the internal LAN to trigger notes on each others sets of virtual pipes.
It also includes a cheap USB GPS module. Not so that I know where it is, but so that it can pick up a time signal when there is no network based NTP available.

User avatar
TonyD
Posts: 447
Joined: Thu Sep 08, 2011 10:58 am
Location: Newcastle, UK
Contact: Website

Re: RPi Synthesizer Project

Tue Dec 13, 2016 1:31 pm

@Jum & @IanS

Both synth projects look great.

Over the years I've built a number of different serial MIDI interfaces for the Rpi for using a MIDI keyboard so I'm really looking forward to seeing how both your projects develop

Here's my last attempt:

https://zuzebox.wordpress.com/2015/12/1 ... softsynth/

Keep us posted !
Tony

jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

Re: RPi Synthesizer Project

Wed Dec 14, 2016 8:03 am

@TonyD - Thanks for the link to the Rpi UART MIDI setup - very interesting. I assume you built some sort of MIDI IN to GPIO interface.

@IanS - Wow that looks super cool. Those panels must have taken a lot of work! How do they communicate with the RPi(s)? The wooden "bookends" on your keybed are very similar to what I've been glueing up the last few days. Will post a progress picture soon. Also keen to know how your softsynth is structured.

User avatar
TonyD
Posts: 447
Joined: Thu Sep 08, 2011 10:58 am
Location: Newcastle, UK
Contact: Website

Re: RPi Synthesizer Project

Wed Dec 14, 2016 1:23 pm

jum wrote:@TonyD - Thanks for the link to the Rpi UART MIDI setup - very interesting. I assume you built some sort of MIDI IN to GPIO interface.
Yeah. I've built a few for the RPi over the last few years.

This was my last one:

Image

https://zuzebox.wordpress.com/2015/12/1 ... out-board/
Tony

IanS
Posts: 232
Joined: Wed Jun 20, 2012 2:51 pm
Location: Southampton, England

Re: RPi Synthesizer Project

Thu Dec 15, 2016 5:00 pm

This is the back of the panels. Any hole that holds an LED was drilled twice: 5mm all the way through for the LED to stick out through, and 7mm part way through to allow the LED bevel to go through to the required depth. 123 holes drilled in this panel, and a few less in the other which has a 7" touchscreen panel instead of the status LEDs, shutdown bottons, and power switches. Making sure everything was in the correct place and nice and neat was definitely an exercise in 'Measure twice, cut (or drill in this case) once.' The zig-zag black wire is the ground lead going between LED cathodes, and it also serves to hold the ribbon cable in place.
StopsBack.jpg
StopsBack.jpg (58.74 KiB) Viewed 3456 times
Any single cable ends up going to either the power rails or to a GPIO pin. The ribbon cables go to a dual MPC23017 board (https://www.abelectronics.co.uk/p/54/IO-Pi-Plus) I have four already, and will probably end up with six of these in the end, stacked two on top of each of three RPIs. One monitors the notes and the other the stops and controls the stop indicator LEDs.

The code is purely in Python, which is just about fast enough at the moment. One program monitors the hardware and sends a UDP packet to the other on any status change (note up/down, stop or preset pressed). The second uses the python interface to fluidsynth to generate the sounds. For a single keyboard the two could have been combined, but splitting them allows the couplers to come in to play, where one keyboard generates notes based on the active stops of another. I would like to add some kind of save/replay functionality, but capturing the state across all the RPIs in a suitably synchronised fashion (and then retransmitting it for playback) presents a challenge, especially if I want to be able to play along on top of a recording as well.

I've seen mention of direct MIDI connections, quite possibly from some of TonyD's posts, or there is the possibility of using USB MIDI ports. Although I started by using the MIDI library which is part of PyGame, some upgrade or other stopped it working, so there is no longer any MIDI involved at all. And as I mentioned before, the low baud rate introduces too much latency with big chords. Coupling the keyboards together would have been a problem too, although there are ways of handling MIDI over a network.

yogi2016
Posts: 26
Joined: Thu Mar 17, 2016 4:49 pm

Re: RPi Synthesizer Project

Thu Dec 15, 2016 11:47 pm

Great projects! Love the cases, really love the Moog 'Wood and Steal' style for the studio.
I've been building Midibox.org projects for awhile and really want to do a combo RPi/Midibox build. The great thing with the MB universe is the modular nature, with a great RTOS running on the STM32F4 Discovery board. Want to use the MB core for the UI, styled like a Minimoog Voyager. Talking to the Pi via USB Midi for synth and seq hosting. The core will also support and route 4 full DIN interfaces and 4 Out only DIN interfaces for external synth boxes.
Looking forward to seeing these projects advance,
Yogi

jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

Re: RPi Synthesizer Project

Tue Dec 20, 2016 3:31 pm

Too much information! :) So many good ideas. Looking forward to seeing the finished synths.

Have spent some hours over the last few days trying to finish my prototype case. See attached photos. Will make a video of the thing in action if I get the chance over the next few weeks.

Edit: Here's the video: https://www.youtube.com/watch?v=_NiGQofBNt4
Attachments
WP_20161220_16_30_43_Pro.jpg
WP_20161220_16_30_43_Pro.jpg (63.75 KiB) Viewed 3288 times
WP_20161220_16_30_17_Pro.jpg
WP_20161220_16_30_17_Pro.jpg (63.14 KiB) Viewed 3288 times

Return to “Graphics, sound and multimedia”