Gecho Loopsynth - Little bit of background
Pocket-size subtractive, hackable DYI synth
Making of the Synth
I have been fascinated by synthesizers from very early age. My best friend's dad ran a wedding-playing band and he owned Roland JX-3P (just guessing the exact model now, from my memory of silver buttons with red LEDs inside). When he allowed us to touch it after lots of nagging, and we powered it on, my ears immediately noticed it was something out of this world. I was born in Czechoslovakia, a country run by communists, where we spent our days duplicating 10th copy of illegally imported tapes through cheap "International" branded double decks.
You can hardly imagine how I felt hearing the ultra clean, synthetic sound of a professional synth for the first time. It was like angels singing... no, forget this cliché :) It was, like if someone finally pulled invisible plugs from my ears and let the sound come in, the sound, I never thought could exist. I went home and soldered some 7400-driven two-tone beeper for starters.
Fast forward thirty years. My passion for electronics led me to various realms of the industry, doing things required by company, market, customers, swinging on waves of trends and following currents of innovation. Then I realized I'd love to do something just the way I want it to look, feel and behave. When I shown a very early prototype - which was already interactive - to people, one wanted it to be a large colorful ball, while other seen it as a wearable necklace. I decided to stay unaffected, followed my own imagination and added bit of vintage/retro look, as that always appealed to me greatly and was also very achievable. Rows of colorful LED lights, reminding of Roland's interface, had to be there too.
STANDING ON THE SHOULDERS OF GIANTS
While ago I bought the great STM32F4-Discovery board after realizing how much power it had, in compare to Arduino boards, and seeing amazing things other people did with it: FM Synths, Granular and Wavetable (just search YouTube for "STM32F4 synth"). It intrigued me why there was no subtractive synth built with the help of the true-random generator, which these MCUs have for cryptography purposes. Code for resonant low-pass filter in C++ which I found here on musicdsp.org was only few lines long. Cortex-M4 has fast floating-point instruction set, accelerated read from flash memory and other perks... so why not to try?
//set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);
//for each sample...
buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 + f * (buf0 - buf1);
out = buf1;
Turns out, there is long way to go from relatively simple looking code to something that really plays. Emulated filters tend to de-tune after a while, and there is thin line between pleasant resonance and runaway state, emitting deafening clipping, as mixing environmental sounds often adds too much energy to the filter and saturate it quickly. Besides, as I wanted to have more than just six of them running in parallel (three for each channel would be enough for basic chords), I added logic to automatically expand each chord. It stopped working when I tried to shift from one chord to another. After each update of cutout frequency, feedback needs to be recalculated based on resonance factor too, which involves some expensive multiplication and division. Codec expects to have next sample prepared right after it is finished with current one, and if it does not get it ASAP, squeeks nasty noise in revenge.
ROAD TO ZERO LATENCY
Using the output buffer would solve lot of problems easily. Most of demos you get with these boards come with DMA channels moving data over a buffer. But buffers mean latency. Assuming RTOS would be an overkill here, I implemented simple queuing system with two pipelines: one for filters-updating commands, and the other for I2C commands which also need to be parsed in real-time, as we want to change volume, treble or bass while playing. This way, between two samples only so much can be done, to not halt the codec. It required lot of experimentation with timing, but finally worked well.
Only later I realized this was the only way to go. Interactivity of the synth feels so magical exactly thanks to this: whatever you do, happens in real time. You sing, and immediately hear ambience added to your voice. While trying to explain the weird effect that happens to the listener after a while, I had to wander into realm of psychowalkmans and binaural beats, previously unbeknownst to me. What you hear actually gets mixed in your brain: signal which traveled through DSP resonates with frequencies, conducted by bones and tissues between your throat and ears.
While pondering the interactivity, I aimed to have this device operating on its own. Adding MIDI is perhaps usual way to go, but if it remained the only interface, the pocket synth would no longer make sense to carry around like that. The question is, how to control such a small thing effectively? Proximity sensors came into mind, they capture more than just a key press.
A sensor sounds simple in theory too: infra-red LED emits flash of light, it bounces off your finger into the phototransistor. It occurred to me that in order to mitigate influence of ambient light, it is better to first measure it while IR LED is off, then on, and compare both values. Larger problem appeared due to the fact that the particular sensor's IR LED was a current hog. Flashing all four of them at the same time created significant dent in power supply line. Solution was to run them alternatively, and put more logic into control function - add DMA transfer so main program does need to wait between measuring.
I spent a good while trying to control it all via one MCU signal, with the help of transistors, but there was no way turning all four detectors completely off. Two GPIOs had to be sacrificed, but it's not that bad as one is also driving "Signal" LED. Isolation in form of R/C filter was also added for the whole IR Sensors block power line, and the same way, for microphones/line-in pre-amp circuitry, so no interference leaks through. With all the colorful LEDs that shine on board, certain combinations may create spikes in current flow.
TIME TO EVOLVE
After all the circuitry thought out, my "Interactive synth shield for STM32F4-Discovery" sounded fine but was cumbersome. I wanted to pack the whole thing into the smallest area possible. Did not really want to go near 0402 size elements - at least not in first or second custom-PCB prototype, which I would need to solder by hand - but there was enough real estate on the "credit card" for all 0603 resistors and capacitors. I left the LEDs in 0805, as they looked better. Codec itself (which is a lead-less 40-pin QFN package) gave me enough trouble. Until I purchased stereo microscope from eBay, I've been spending whole afternoon putting it in place. The fact that it has the only GND soldering pad on the bottom does not help either.
While designing the first prototype PCB, wanting to save on costs, I packed it all on two layers only. Worst idea ever, almost impossible to route and lot of noise too! But it has done its job, revealing few unrelated design flaws which required attention. I improved reset circuit, so the button not only resets MCU but, via diode, the codec too. This way we avoid the same nasty clicks and noises from data-hungry codec between the time user presses the button and MCU re-initializes. Found viable way of sharing SWD connection and CH340G serial line with some LEDs (not doing it would mean throwing away four GPIOs. On official board, one capacitor is assembled against recommendation from Cirrus Logic's CS43L22 datasheet - 1uF instead of 10uF. Not sure how important is it, it sounded OK anyway, maybe would only give trouble at higher output powers.
ARCHITECTURE PROVEN TO WORK
The 3rd revision of the board, which I hope to get funded so it is viable for machine-assembly, has capability of routing signals from pretty much any input to sound processing function. It does not have to be microphones or line-in, ADC channels can be switched around so you can hear signal from infra-red phototransistors, magnetic sensor or any other thing you decide to solder in instead of it.
I am particularly happy about the fact that any of my boards, if assembled correctly, "just works". The surprises seem to have already been caught out. I received quote with exact components and amounts, showing that minimum of 200 boards need to be ordered, hence the campaign goal.
Apart from few things mentioned in the KS campaign (MIDI, gyros, touch sensors, or any module that communicates via serial or I2C), I am thinking of a TV remote control (you can put an interrupt routine over the ADC signal). Or simple gesture recognition, where proximity sensors work in pairs and detect direction of movement over them.
Microphone pre-amp had two channels left, so the line-in input came for free. In attempt to make it universal enough, there are two trimmers to adjust gain. One could possibly write a function to analyze incoming signal and replace it with something else: maybe play back drum samples from memory, changing their envelope by the sound of tapping. Thanks to ST's "ART accelerator" the board is capable to play audio directly from Flash memory, as if it was in SRAM, and because it is a 32-bit ARM, everything is in one address space.
The open-source framework I will be providing with the board has - apart from hardware abstraction - few things implemented that may come handy: Goertzel detectors for analyzing note on input (something like FFT but faster, less buckets). Auto-correlation algorithm to do the same, seem to work better with guitar sound. Simple, yet effective arpeggiator. Functions that translate from a string of simple chord notation - e.g. "a3c#4e4,c4f4a4,..." to frequencies, which you can pass to LPFs. Pseudo-random generator, saves power by having true-RNG shut down, while ears are not able to tell the difference here.
PROJECT THAT SLOWS DOWN ITS OWN PROGRESS
One of the major obstacles was to work on the code, instead of "testing" it :) I kept finding myself immersed in realm of sounds, realizing last hour has passed without me writing a line. People who seen the prototypes often said it was hard to take the headphones down. Demos which I recorded don't really capture it, the joy of interactivity is lost. Even taking photos or videos of LEDs with digital camera only gives false colors. If someone lives near Dublin, feel free to visit and check the real thing! :)
Otherwise, find more info in my Kickstarter Campagin