Let's Design and Build a (mostly) Digital Theremin!

Posted: 9/20/2018 8:20:10 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Yes, the "viola" and "cello" sound fairly realistic to me too.  Some of it is what I'm doing, a quick +1 octave slide, which lets the harmonics "ring" a lot of the formant resonances.  Vibrato does this too, but not nearly as much.  The subtle movement might just be the band pass filters ramping up to full output?  I've got a little volume axis brightness modulation, but the basis is ~3/4 the way between sine and saw.  I think I've got the Q a bit higher than before, which gives a "woodier" sound.  If you play them at really low frequencies they sound like a creaky doors.  Something kind of "rubber bandy" in there, but I'm not doing anything special to cause it.  No velocity, no formant modulation, a mild volume knee as usual.

Read a couple of old papers on bow and breath noise: I'm wondering if multiplying the signal with uni-polar noise, rather than adding the noise, is the secret? With the exception of multiplying the noise by the unipolar wave or phase (and then adding it), everything I've done up to now has been additive, which just sounds like adding to me, not an inherent coarsening of the oscillator timbre.

Posted: 9/21/2018 10:55:14 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Resonator Damping

For my formant filters, the input is now scaled by d^2 (the panel knob scaling function) and the filter damping is scaled by the square of this, or d^4.  This is a nice scaling for musical use as the peak and skirt amplitudes scale equally about the 0dB point, which keeps the average somewhere near 0dB, so the perceived sound level is fairly constant, and overload with lower damping is somewhat tamed.  

Control knob squared scaling with knob value range [0:63] gives a nice expanded low end, with human formant damping around knob setting 40 (actual damping=0.15), violins and such around 30 (0.05), wood blocks around 20 (0.01), and bells and such around 10 (0.0006).  (You honestly can't spend too much time adjusting stepping, ranges, and responses of the controls.)

Maximum damping is 1, musically we're usually not all that interested in clinical issues such as critical damping (d=1.414), maximal flatness, and the like.

Today I simulated the inharmonic resonator in Excel, it's really crazy looking!  Hope it sounds just as crazy...

[EDIT] ... and just because it looks crazy doesn't mean it will sound crazy, or vice-versa.  Our senses are surprisingly good and bad at various disparate things.  I took the path of that paper and simulated first a comb, then a reverberator, and then finally both together.  I have a bit of experience with feed forward (FIR) combs from the CIC, but none with feedback (IIR) combs.  And no experience at all with all-pass / reverberators.  All of these forms are about as simple as these things get, but stick a couple of them together - particularly with some feedback - and the results get fairly unpredictable.

[EDIT2] One thing about coding filters with external feedback: you need the old filter output before you can calculate the new filter input, which is inconvenient if the old output can't be found just laying around in some register or memory location.

Posted: 9/23/2018 3:36:06 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Non-Harmonic Resonator

Implemented the filter from the paper I pointed to a couple of posts back, a comb with internal reverberator.  It's quite interesting.  Surprisingly, it can do OK human voices without any formant filtering whatsoever, and it can sort of add to the 6 format string patches (violin, etc.) to flesh out the upper end.  And, being a delay / filter, it can do other fairly "wild" stuff one expects delays to do.  I need to get the Q higher so that it can do bells better (decay is too short), and there is an issue now and then with high frequency ringing going on way too long, but it's fairly useful as-is:

The 'c' parameter is much like the Q control in a 2nd order filter.  The 'k' parameter controls non-harmonic blend, and I find that I'm not using the 'g' path at all, which is straight through.  As a formant filter it should be placed in parallel with the other formants, but as a delay effect it should be placed in series.  You make either make 'c' signed or 'k' signed to get odd / even comb feedback.

Here's a sample: [MP3].  The first three are resonances "struck" by a sine wave w/ attack, the third has maximum delays and some overloading.  After that are some human voices.  Following that is my usual 6 formant cello, first without the new filter, then with the new filter in parallel, then without (for comparison purposes).  The filter pumps up the bass with that cello setting, which somewhat confounds the comparison.

I wouldn't want to depend on it entirely for human voices (SVF formants sound better IMO) but, like a dog walking on it's hind legs, it's remarkable that it can do it at all.  Whatever the approach, female voices are always easier / more realistic sounding because the resonances are higher, and the harmonics start higher and so are more widely spaced - it's simply the case where there are fewer cues to tip off a phony.  This is why you run across many analog Theremins that can do a passable female vowel, but can't do a male vowel without external help like the EH Talking Machine.

After my experience with this type of delay-based filter doing formants, I'm now somewhat wary of physical modeling synthesis in general, as it is delay-based.  I wonder how many physical models have audible artifacts of the underlying delays?

Before I added the filter I did a quick inventory of processor real-time and memory left over.  Of the 7 real-time threads (thread 7 does non-real-time stuff: displays, encoders, serial port command line, etc.) I had around 46% real-time to spare, and also about half of the 16kB total.  The new filter consumes fairly little real-time and 2kB of memory.

Posted: 9/24/2018 2:58:24 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Violin: 6 Formants + Non-Harmonic Resonator

I haven't done any work to the non-harmonic resonator yet, still playing with it to see how it might be optimized for my uses.  For a better violin sound I snagged the first 6 Stradivarius format frequencies from a paper (277, 392, 466, 565, 720, 905 Hz) and mixed in the non-harmonic resonator set to g=0, c=-29, k=32, n=9, m=9.  See what you think: [MP3].  The beginning is just the 6 formants, then I mix in the non-harmonic resonator and play a bit.  Then I play another piece, first without reverb, then with.  For reference, each delay sample corresponds to the speed of sound divided by the sample rate: 

  (343 m/sec) / (48k sample/sec) = 0.0071 m/sample = 7.1 mm.

Total delay is (9 + 9) * 7.1mm = 128 mm, and we multiply this by 2 because of the inverted comb gain (c=-29) to get 256 mm, which is very roughly the "size" of a physical violin.  This doesn't get the lowest filter resonance anywhere near the lowest formant, this would require n+m to be around 64 + 64 = 128 samples.

I plan on normalizing the delays to make them ratios of the total, and perhaps each other, as well as q enhancements and scaling, and serial / parallel modes. It might also be useful to include a 4th order high-pass filter to better integrate the filter result with explicit SVF formants.  With a high-pass filter one could set the delays longer to make them more dense, then chop them off at the formant zone transition so as not to compete with / color the "real" SVF formants.

Posted: 9/27/2018 11:32:12 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

All About All-Pass Filters

Can't say I knew much about them until this exercise with the inharmonic resonator.  Basically the superposition of a feedback comb filter (poles or positive going lumps in the frequency response) with a feedforward comb filter (zeros or negative going sharp dips) in the frequency response, with the two forms sharing a common delay element (z^-n, or n sample delay).  The zeros and poles coincide and cancel to give a static gain of 1, but if the input isn't static the poles and zeros will influence the output in the short term time.  Put a sine wave into it and you'll get the same amplitude sine wave out, but with likely different phase.

One runs across many forms of the first order allpass:


The first dates back to the early Schroeder reverb papers (the feedback and feedforward gains are quite obvious and non-interacting), the second is the most common portrayal (but I find it hard to think about), the third more likely to be encountered in digital waveguide papers IIRC.  Surprisingly, if you trace them out and do the math (I did), they all have the same transfer function: y/x = [(z^-n) - g] / [1 - g*(z^-n)].  Not sure if there are any advantages / disadvantages to the various topologies when it comes implementing them in code.  Clearly, when g=0 you get a simple z^-n delay.  For reverb, g is generally set to be around 0.7.

A nested allpass is formed by taking a first order form above, adding a series delay (z^-m) either to the input or output, and using this as the (z^-n) element in the first order form.  The inharmonic resonator is a comb with an allpass nested inside instead of a simple delay.  

If you flip the sign of g you swap the zeros / poles locations.  If you take the second or third first order allpass forms above and make both gains positive or negative you get a jagged comb where the zeros and poles alternate.  

I tried adding a 4th order high pass to the inharmonic resonator.  Setting it somewhat above the highest SVF formant allows you to dial the delays longer to get denser upper resonances without them interfering with the SVF resonances.  I think my next experiment will be to try a nested allpass nested in a comb to see if that is any improvement.

Posted: 9/30/2018 3:02:52 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Vocals Correction

I noticed that the non-harmonic resonator vocals I posted previously accidentally had some SVF formants turned on.  Without them I can get a realistic sounding medium pitched male voice, and somewhat realistic sounding lower pitched male voice, but that's about it.  Here's a short song with the medium pitched male voice, no SVF formants, only the non-harmonic resonator supplying the formants: [MP3].

Did a lot of simulating of non-harmonic resonator variants in Excel yesterday.  The paper states: "Although we did experiment with additional levels of nested filters, the results we obtained did not seem to offer any significant musical advantage over the nested pair of filters described above, neither in terms of interesting sonic results, nor computational stability during quick parameter changes."

I don't notice a big visual difference between one all-pass filter nested within the comb vs. two all-pass filters in series nested within the comb, but an all-pass nested within an all-pass nested within the comb seems to give a more visually chaotic resonance spread.  Hope to code it up soon on the prototype to see how it sounds.

Better Violin?

It sounds better to me anyway: [MP3].  It's the first 6 Strad formants via SVF again, with a 4th order high-pass filter on the non-harmonic resonator set to a bit above 1kHz to avoid overlap of the two resonance generators.  Delays are 69 for the comb; 44 for the all-pass.  Gains are 0.5 for comb feedback / feedforward; 0.67 for the all-pass feeds.

Posted: 10/1/2018 8:51:03 AM
Buggins

From: Porto, Portugal

Joined: 3/16/2017

dewster,

Nice voice.
What excitation signal is used? Something like single pulse? Can't it sound better if excitation is changed?

Violin sounds really nice.

Posted: 10/1/2018 2:42:56 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Nice voice.  What excitation signal is used? Something like single pulse? Can't it sound better if excitation is changed?  Violin sounds really nice."  - Buggins

Thanks!  I've been using this fantastic oscillator exclusively (note the new polynomial coefficients in EDIT2):

http://www.thereminworld.com/forums/T/28554?post=213760#213760

For human vocals I use about 0.28 base harmonics with about +0.28 volume axis modulation, which makes it considerably brighter as it gets louder.  You want the harmonics to drop off somewhere around -12dB/octave, which is twice the rate of a sawtooth (-6dB/octave).

For the violin I'm using around 0.75 base / +0.125 volume axis mod, so it's almost a sawtooth. 

A single pulse would almost certainly sound too "buzzy" and would alias (unless you generate it via BLIT).   I haven't heard *any* aliasing since I started using this oscillator.

If you want I can point you to a couple of waveform generation papers that cover just about every approach known to humankind.  BLIT and BLEP get a lot of attention lately but they're not at all what I was looking for, and it took me a while to realize that.  Having a harmonic control input on the oscillator is an incredibly powerful thing.  

Posted: 10/1/2018 3:23:17 PM
Buggins

From: Porto, Portugal

Joined: 3/16/2017

Didn't you try additive synthesis?
Formant filter might be applied to harmonics directly (e.g. lookup table amp(f) -> interpolation).

Posted: 10/1/2018 6:50:46 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Didn't you try additive synthesis?  Formant filter might be applied to harmonics directly (e.g. lookup table amp(f) -> interpolation)."  - Buggins

I haven't tried additive synthesis.  Who knows, maybe I'll end up there as it is incredibly powerful and generic.  One could almost trivially generate hundreds of sine waves via the FPGA logic, and individually scale and sum them (MAC).  

I suppose I prefer modulated harmonic level + filtering at this point because it's very tractable with the 180 mips / 16kB mem resources I have available.  I'm also attracted to synthesis methods that have "knobs" which correspond to physical things, like resonance frequency, Q, etc. that the player can easily manipulate.

Say your lowest note is 16Hz and you want all harmonics up to 15kHz.  That's 15,000/16 = 937.5 or ~1k sine waves.  If they have arbitrary frequency and amplitude that's 2k worth of tables if everything is static.  The amplitude table could be implemented exponentially, but that's more real-time calculation to do. Things like formant skirt width (Q) would have to be baked into the table itself.  I guess I just don't see anyone wanting to fart around with that much arcane data to make a patch, though off-line tools could certainly assist this (though I have an aversion to off-line tools as well).

You must be logged in to post a reply. Please log in or register for a new account.