Building an analog looping piano
This is the story of our new product, “Quaver: The Multiplayer Piano”. We turned an old piano into a song writing machine using magnetic pickups and a Raspberry Pi. For a less technical and more visual story, view the photo gallery on Imgur.
Sean and I christening the final product at Park City mall.
Walking around downtown Lancaster in the summer, it’s hard to miss the pianos sitting out on nearly every block. Known as the “street piano capital of the world”, Lancaster’s Keys for the City program has provided a fun way to rock out with strangers or just have a little fun on your stroll through the city.
As musicians, Sean and I often noodle around on a piano en route to work, and more often than not we find ourselves coming up with a riff or melody worth saving. Recording to your phone is one way to preserve the idea, but wouldn’t it be cool if you could record a song and upload it to the internet right from the piano itself? Maybe even record multiple layers to make a song with friends?
We thought so too, and soon found ourselves pitching the interactive “Multiplayer Piano” to Music for Everyone, the non-profit behind Keys for the City. We were prepared to go in depth on how this would increase donations, exposure, etc, but they immediately got it and loved the idea without much persuasion. I love this city!
We knew from the beginning that we didn’t want to rely on a display, so we tried to design around a minimal interface with only a few buttons and lights. At first we were convinced we could make it intuitive with no display at all.
However, after working through the user experience, we knew some kind of display would be required, and might even allow us to give Quaver a bit of personality. Still wanting to stay minimal, we ended up choosing the LDP-8008 from Embedded Adventures along with their Uber Display Driver PLT-2001.
Our final layout included:
- Current player indicator lights (Red for recording, green for finished)
- Record button
- Save & Upload (at any point after recording the first layer)
- Play Previous (to hear the last song made)
- Reset (to start over and reboot the machine)
I knew we wouldn’t have much space inside the piano, and I’ve been itching to play with the new Raspberry Pi 2, so it seemed like a good fit for this project. Plus with plenty of GPIO pins it left us many options for controlling our interface.
Pictured above is a basic proof-of-concept with a record and play/pause button, along with recording and playing indicator LEDs. At this point the pi is still running the default Raspian image, however I would later find that a 20 second boot time is unacceptable for our scenario…more on that later!
Capturing the Piano
Initially we thought we could just toss in a couple condenser microphones, some speakers and call it a day…but quickly realized our fallacy: speakers blasting right next to the microphones would surely cause a feedback loop after multiple layers, not to mention the street noise would still get picked up.
The next idea involved transposing to MIDI notes on-the-fly, however a few tests confirmed that this was much too inaccurate to rely on with an unknown or fluctuating tempo. With not much hope left, we stumbled upon our saving grace, the Helpinstill Piano Sensor:
It’s basically a pickup like you would find in an electric guitar, but built for the strings in a piano. The sound is amazing, there is no feedback, and we can feed the signal directly into our sound card. We both breathed a sigh of relief as we knew our idea was still possible. Helpinstill FTW!
All of this is captured through a C-Media chipset based USB audio interface, Amazon is littered with these little guys and we got ours for $8!
The signal out of the Helpinstill was pretty quiet. Amplifying at the audio interface caused a ton of noise, so we ended up using a direct box to fix some grounding issues and a clean boost pedal to get a hotter signal. I’m not convinced this is the best method, but it was the best we could do before launch.
Sean was kind enough to sacrifice some ancient Bose speakers from the 80’s, and we picked up a cheap Pyle 150W amp from Amazon to drive them.
For the software side of things, I initially considered writing a looper in ChucK. But when I realized that the open source SooperLooper can be compiled to run headless and controlled via OSC, I opted to give it a try before rolling my own.
- Jack takes care of all audio routing from the sound card to SooperLooper and back
- node-OSC sends commands to SooperLooper.
- onoff to control LEDs and listen for button presses.
- node-serialport was initially used to control the display, however when compiling a custom kernel (more on that later) I could not get it to compile correctly. I ended up just using echo to issue commands directly to /dev/ttyUSB0
- lame for encoding the SooperLooper’s wav output to mp3
- ffmpeg to concatenate copies of the mp3 loop into a longer “song”.
- Parse to handle file uploading and make it easy for us to produce a front-end on the web.
With a working prototype in hand it was time to get down and dirty. I began the process of designing the circuit board and electronics while Sean started designing, drilling and painting the piano.
How Not to Make a Circuit Board
After breadboarding a full working prototype with all buttons and LEDs, I decided to try my hand at soldering my own. In hindsight I would have definitely had it printed, but the tedious process of soldering this small was kinda fun once I got in the groove!
Terminal blocks would have been useful for the wires, but I forgot to order them and ended up soldering the wires directly to the board.
Mounting the Hardware
Drilling the first hole was the hardest! I had to give Sean moral support as defacing a perfectly good antique piano was not easy to do. But once he got started I’m pretty sure he was having a blast.
We then tested the fitment of all components, beside a few minor adjustments they all fit quite nicely! Here are the sources of the buttons and LEDs we ended up using:
- Player indicator LEDs: Adafruit Diffused RGB 10mm LED
- LED holders: Adafruit 10mm plastic LED Holder
- Display: Embedded Adventures LDP-8008
- Display driver: Embedded Adventures Uber PLT-2001
- Record button: Adafruit 100mm button
- Small buttons: Adafruit 30mm illuminated pushbutton
Having grown up in the 80’s, we’re huge fans of retro games. We host a retro video game tournament on First Fridays in Lancaster, and we’ve slowly started collecting arcade machines in the office. It only felt natural to extend this theme to highlight the communal aspect we hope this piano will offer. Sean came up with the name Quaver, which is actually the British term for eighth note.
Sean converted part of office into a paint booth, projected the artwork onto the piano and got to work. Judging by people’s reactions looking through the window, we’re pretty sure they thought Dexter was hard at work.
While I was busy soldering that circuit board, Sean absolutely killed the paint job, even hand painting all the little pixel-perfect fonts. I also need to give huge thanks and shout out to Sean’s
girlfriend wife for helping paint on some late nights. Thanks April!
Our first hurdle
Besides running low on time, things were going fairly smooth up to this point. It was the night before the piano was due, and we finally hooked it all up and started doing some final testing.
CPU Frequency Scaling issues
All was good until we started doing much longer songs - 30 to 40 seconds at a time. We noticed that a strange crackling would begin about 30 seconds in, but would go away sometimes after recording additional layers. Some further research concluded that this was due to the CPU ramping up to a higher frequency to meet the demands of longer audio. Apparently when the CPU changes frequency, it creates an audible noise when processing real-time audio.
I followed all the advice I could find on real-time, full duplex audio in Linux. Most resources advised setting the CPU governor to “performance” mode, but after some testing I found that this still didn’t totally stop the CPU from scaling at some point. The solution that finally worked was setting the governor to “userspace” and manually setting the frequency to 90,000 (900MHz).
Reducing Boot Time
The other issue we ran into is that resetting the machine took at least 20 to 30 seconds…totally unacceptable if people wanted to start a new song. I had never compiled my own Linux kernel before, but I knew it was the only way to achieve ultra-fast boot times.
If you’ve never heard of it, Buildroot is quite the amazing tool for compiling Linux for embedded devices. I started with rpi-buildroot as a base and started adding all of the audio packages I would need. It took about five days full of trial and error as I had to patch just about every package to get it to compile properly, but at the end of the day I had our Raspberry Pi 2 booting in 2.9 seconds! To me, the slow boot time was always the worst part about the pi and this has blown my mind. I’m excited to try and chip away at the boot time even more as I will definitely be using the pi 2 in more projects!
Putting it all together
The final version of Quaver’s guts. A bit bulkier than we anticipated, but we managed to find room for everything. We have many ideas on how to simplify and shrink version 2!
We also got word that the piano’s location would be at the local Park City shopping mall food court. It would be positioned in such a way that you could see it from the stores above. We decided to paint something for the shoppers looking down. It was the tamest message we could think of :)
After a few other final touches our piano was ready for the world. The movers showed up at 9pm and we had a proper send off.
We hope you have enjoyed reading about the making of Quaver! If you have any technical questions feel free to reach out to me at email@example.com. For more photos check out our photo gallery on Imgur, or check out Sean’s demo of the Quaver in action: