Making advanced noise on ESP8266 using Heavy
May 13, 2018
Building tools and instruments to either better create or listen to music is by far the project I spend the most time thinking about.
Hearing about Heavy from Enzienaudio three years ago has slowly become a key element for my projects and experimenting new tools and instruments. From the start, embedding PureData patches as highly performant code on almost any kind of device (computer, microcontroller, smartphone) was an interesting perspective. For a long while I focused on “nanocomputers”, think Raspberry Pi here, in a similar way as what Bela is. Sadly, I didn’t find the time and motivation to work on it long enough to provide a working version.
Here comes another hero from the hacking community in our technological era: the ESP8266. This cheap device from a chinese manufacturer was first on the market to offer a powerful microcontroller combined with wifi connectivity in a single chip. Back in 2014 when it appeared, market leaders in the field of microcontrollers with built-in wifi were offering solutions in the range $25-65, while the most basic ESP8266 models cost between $2 and $3.
From that point, the ESP8266 competed in the market of microcontroller boards like Arduino, even though it provided much more processing power from the start, if compared to the most common Arduino boards.
Speaking of which, processing power is exactly what makes this project feasible.
There is no pre-recorded sound in this, it is all generated in realtime, meaning it will fit the dynamic and ever-evolving nature of making music, just as with an acoustic instrument, for example.
Surprisingly good performance of @Arduino on #esp8266 running a @HashtagPureData patch from @enzienaudio's Heavy compiler! Code is here: https://t.co/uPgJ8gpOcm Patch is here: https://t.co/9cMu0Pph1Z The DIY speaker and amp adds a nice analog (acoustic?) distortion! pic.twitter.com/JRNrW9SoEE— FergusL (@Fergus_L) May 19, 2018
- PCM5102 I2S DAC: A DAC converts sound represented as digital data from the microcontroller into analog voltage which you can feed into a headphone or a speaker.
- An amplifier and a loudspeaker : I’m also demoing here a nice DIY loudspeaker!
The rest of the magic is simply using the code produced by the Heavy compiler to generate sound directly on the microcontroller and sending it to the DAC.
The code is available on Framagit.
The hardest part of the code is figuring out the audio loop. As with every system that processes and outputs sound, you have to solve the problem of filling a bucket at regular intervals and at the same time supplying a constant flow with its content. There are several ways to do that, the README references the project I’ve based my work on.
As a bonus, Heavy also provides versions of Puredata patches to be shown directly on websites, which I can do here, toggle the “Off” button and listen to the same patch as the one running in the video:
And as a reference, here is the patch diagram of the synthesis, it is indeed very simple yet it features a noise source, a filter and a sine oscillator! I didn’t expect at first to go this far with Heavy on ESP8266.