241 points · by cushychicken · 5y ago · 81 comments
It’s got some obvious shortcomings and wild browser inconsistencies, but lets you go through much of the same design process in making your own synth.
1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_A...
My college electronics prof was old-school enough who told us back in his day it was “standard practice” to use pp-amps to solve differential equations from their Calc class.
You can specify the sampling rate of the Teensy with a bit of fiddling, and the limits depend on what you're asking the audio library to do. The stock Chord Organ's set up to run at 44.1k, using a couple of submixes in the library to do things like set waveform levels independently.
You can also set an oscillator to drive the output pin directly, with just one waveform.
I've got a couple of 'em running at 2,822,400hz instead of 44,100hz. That's 2,822k for one oscillator (I can get four running at 768k), by telling the Teensy its sample rate is something hilariously high, just to run some square and 12-bit triangle and sawtooth waves.
I avoid aliasing pretty well :) and it's definitely a fully digital DAC output. It's just good at being free from aliasing because I'm not concerned about what the sampling rate 'means' in terms of 'usable notes'. The only thing I care about is getting my waves nicer. The Teensy also has a rectangular wave, which is PWM adjustable. That, at 2,822k or even 768k, is quite nice even when it's a really thin pulse…
And of course you could use the square to drive an integrator :)
The Cortex M4 in the Teensy runs at 200MHz. In the early 80s consumer-grade DSP didn't exist at all. There were some exotic studio processors with slow microprocessors supported by custom hardware multipliers, but 8MHz 16-bit microprocessors were considered fast, expensive, and exotic.
Roland had a stellar run with their hardware designs. The Junos may be one of the best synthesizers ever made hitting the bullseye for price, character, simple but flexible programmability, and a legendary sweet but powerful sound.
There's a finesse to this kind of audio design that IMO makes a lot of Eurorack seem clumsy and uninspired in comparison.
Also, Teensy is amazing! I got one recently to play with some audio stuff and it’s so much fun. Amazingly capable board really, love that it can do USB MIDI etc.
Also, aliasing as a concept doesn’t show up in purely digital systems.
There are a lot of solutions to this in the literature, such as wavetables that are band-limited, but for simple virtual analog synthesizers, there's a technique that is close to magic in its simplicity and quality: PolyBLEP. Check it out.
Digital AA is very hard to design, just the mathematics involved are extremely difficult to grasp, much harder than analog.
Aliasing shows up SPECIALLY in purely digital systems. Take a sample every half period of a periodic signal like a sinusoidal wave. Your signal output will be constant or zero.
Take a digital sample(calculate a frame) of a wheel in a 3D game (draw the wheel at a specific position), each 30th or 60th of a second. The wheel will go backwards at some speeds(stroboscopic effect, a form of alias).
And aliasing does happens in digital oscillators when you're using a fixed clock and sample rate: If you have flexible clock (per-voice) you can just increment the output value in equal steps (and then set it to zero at the end of the "sawtooth") and you won't get aliasing. But if you have a fixed clock, you have to use a (very simple) equation to calculate the position of the soundwave at a given sample number. So you get aliasing when you approach Nyquist frequency, and you need the anti-aliasing filter to fix it.
And since it was 1982 the sampling rate of the chip was probably not that high, so you would get aliasing much earlier than at ~22kHz.
Try drawing what would appear to be a perfect square wave in a digital wave. Up, flat, down, flat. Guess what: you've just introduced enormous amounts of aliasing.
"Lollypop" sampling vs. real DAC output: https://mk0soundguyshosprmrt.kinstacdn.com/wp-content/upload...
As you've observed, the output of a real digital circuit includes the flat parts, unlike the infinitely thin "lollypops" that you see in DSP textbooks.
But the jaggies themselves are not aliasing, they're actually the result of anti-aliasing. The sample-and-hold reconstruction filter that practically every DAC uses is an anti-aliasing filter, albeit a crude one, but if you've chosen your sampling frequency correctly, the harmonics from the jaggies exist entirely outside of your passband. A simple RC filter removes them almost perfectly.
This is aliasing: https://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Al...
Digitally sampling an analog input signal is usually where you need to actually put some design effort into the AA filter, because you don't necessarily know whether the analog signal at your input has a lot of energy just outside your passband. Such an input can cause you to see an alias that's comparable to or louder than your signal of interest, and there's no way to get around that with direct sampling except for arbitrarily sharp AA filters.
But with a DAC, you know exactly what you're putting into your AA filter (your sampled signal convolved with a box), and you can easily arrange things so that the AA filter both works perfectly (sampling > nyquist) and is easy to design (sampling >> nyquist).
Once you introduce a master clock, especially one clocking an ADC, then aliasing can and does indeed show up.
Going from simple dc arduino inputs to high precision analog is a bear, but super rewarding. Get ready to get your soldering skills right and start caring about resistor tolerances!
Another of my synth DIY mentors (with whom I worked on the Arturia MiniBrute) is Yves Usson: http://yusynth.net/index_en.php
Well thanks. There goes all my free time... But seriously, that website looks like an amazing resource
For those interested in an open source design embodying these techniques, I have an open source hardware design here: https://github.com/russellmcc/dco with a blog write-up here: https://www.russellmcc.com/posts/2013-12-01-DCO.html .
Also of relevance is an open source hardware design for the later roland alpha juno digital oscillator design: https://github.com/russellmcc/alphaosc https://www.russellmcc.com/posts/2019-06-14-Alpha-DCO.html
It is clearly modeled after the Juno, and adds a lot of nice features (2 DCOs per voice, 2 more-capable LFOs, an arpeggiator, full FX suite...) and you can get the 12-voice keyboard model for about half of what you’d pay for a Juno 106.
It’s got a big screen in the middle, but the front panel is designed so that you almost never have to use it, even when building patches. They have a great shortcut system for assigning modulation that’s easy to pick up and very fast to use. It’s just a great synth all around.
Instability ironically prized and cherished by synth enthusiasts who will claim it makes old synthesizers sound "better" than modern ones...
And as someone who makes digital synths for a living even 100% accurate fully digital oscillators are difficult to fully realize in practice. Aliasing concerns abound at every stage of a softsynth- there are well-known formulas for calculating alias-free waveforms at a fixed frequency, but these start to get expensive when you also are considering PWM and frequency modulation which are essential tools for achieving a variety of different sounds. And aliasing sounds a lot worse than analog imperfections.
But there's more to that analog sound. The opamps and the rest of the circuitry, including supposedly passive elements like resistors and capacitors, all add tiny amounts of distortion and other parasitic interaction with the rest of the synth which varies with frequency content, level, and dynamics.
Human ears are incredibly sensitive to these variations, and the circuits in 70s and 80s synths had a lot of components, all adding their own colour. Which is why if you A/B the hardware with the software, the software rarely wins.
In DSP terms there are differences between functional/abstract models, component-level models, and component-level models that include these complications and imperfections. There hasn't been a lot of work done on the latter, and if they were modelled accurately they would likely need an order of magnitude more DSP cycles than current VSTs.
The Commodore Amiga has the crudest possible anti-aliasing filter: a single fixed-frequency low-pass filter shared by all 4 channels. It does not work very well, so aliasing is a defining characteristic of the Amiga sound. Aliasing adds high frequency content that compensates for the low sample rates required by memory limitations, and extra harmonic complexity that compensates for the low channel count. I think Amiga modules sound worse if played by something with good anti-aliasing filters.
> Whatever you now find weird, ugly, uncomfortable and nasty about a new medium will surely become its signature. CD distortion, the jitteriness of digital video, the crap sound of 8-bit - all of these will be cherished and emulated as soon as they can be avoided.
Aliasing (a sampling artifact) is an issue in synthesizers which run at low/fixed sampling rates and sample waveforms to produce output (often using frequency registers). This includes modern software synthesis, and also hardware like DS (ZOH, samples, almost like Amiga), N163 (ZOH, short wavetables), Yamaha (FM on sine waves, IDK the details), and to a lesser extent SNES (Gaussian reconstruction, samples).
Reconstruction artifacts (extra frequencies at x * fundamental, may exceed sampling rate) are different from sampling/aliasing artifacts (frequencies are taken modulo the sampling rate). But they can combine (like on DS hardware).
For this kind of circuitry I would reduce temperature drift by enclosing it into a heated thermostat kept well above room temperature. This way after initial warm up period there is very little drift.
Personally I'm from the camp that likes super-clean audio, so I was overjoyed when software synths fixed all the problems that we used to have with hardware, but there's definitely a camp that really likes the "warmth" or unpredictability of the original machine's output. Sometimes I think people spend more time adding plugins to dirty up their sound than they did making the original patch in the first place.
Pre-COVID I had a semi-regular synth jam session with a dude 100% invested in software synths. First 30 minutes (no exaggeration) of every session was him fighting with Ableton or whatever, and rebooting his Mac, trying to get something trivial to work, like MIDI clock or input monitoring.
Meanwhile I just plugged my Minilogue into the power strip and mixer and did my own thing.
There's something to be said for a musical instrument not to be joined at the hip to a general-purpose networked computing device.
If I understand correctly, the output from the sawtooth has a voltage offset? Can that lead to DC passing through speakers? And would the pulse-width comparator input need an equivalent voltage offset?
It motivates me to try it back.
I have to find a little time to do something interesting now that I have the resources that I had not in the past(if only I had the time I had then).