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

Posted: 12/25/2018 8:03:57 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

CIC (huh, good god y'all)- what are they good for?  (absolutely nothing)

Well, CIC (cascade of integrators and combs) are pretty great for some things but I just tore all four of them out of D-Lev code.  I know I went on and on about them in the past, but I've got more DSP under my belt now and can see them for what they are.  

I was using a second order CIC, half in hardware (cleverly part of the NCO phase accumulator) and half in software, to change the sample rate of the LC DPLL frequency point from 196.666MHz to 48kHz.  As sample rate changers go they're not the best until you get to 3rd order or higher (I was using 2nd order) which means really wide accumulation, which is too slow to run at the SPDIF master clock rate of 196.666MHz.  I swapped them out with a cascade of three 1st order "fast" IIR low pass filters, which just barely meet timing (but do), and provide >80dB of anti-aliasing at PCM Nyquist of 24kHz with a cumulative -3dB point of 480Hz.  Here's a spreadsheet on the fast IIR: 

http://www.mediafire.com/file/18gj2oyw28f21ag/fast_iir_2012-12-20.xls/file


The above is the frequency response of the "fast" IIR cascade implemented in the D-Lev.

CICs also formed the mains hum filters for both axes, where they worked well but gave a 1st order roll-off around 30Hz, they gobbled up a ton of my precious RAM, and the notches were rather broader than I would have liked.  For a while I bookended them between two 150Hz 4th order low pass filters and ran the CIC hum filters at 1/16 the rate to save memory, but upon testing them in-depth yesterday I couldn't seem to reproduce the hum suppression results.  So this morning I looked into notch filters, and it turns out that you can make a really great notch filter from a Chamberlin state variable by summing the high and low pass outputs.  The resulting output is quite interesting in that the peaking associated with higher Q values disappears, as does the high pass amplitude deviation from 0dB, and we're left with a variable width notch that can go from fairly broad to surgically narrow.  Here's a spreadsheet on the Chamberlin notch:

http://www.mediafire.com/file/8qtd4dj7tvs60aj/notch_2018-12-25.xls/file

The notch algorithm is pretty efficient, with the subroutine consuming a mere 13 cycles.  So the hum filter is now a cascade of six notch filters with a 4th order low pass to smash the rest of the higher harmonics.  For 60Hz the notch frequencies are 60, 120, 180, 240, 300, and 360Hz; for 50Hz they start at 50Hz and increment by 50.  The 4th order low pass in both cases is set to 300Hz.  I'm using a table in software to select between the two sets of notch frequencies, and the damping I chose is a constant 0.5 for all.

Subjectively the axes perhaps seem a bit less noisy when operating in the far field, it's hard to tell.  Low frequency noise should be rather low anyway as it is small signal grounded through the tank coil and drive (I've never heard the prototype pick up any kind of hum whatsoever).  There is a definite massive reduction in the amplitude of the noise on the operating point numbers, though you would see that happening with almost any kind of filtering.  60Hz and its harmonics are clearly suppressed, and switching to 50Hz in my lab setting causes them all to jump up considerably, so I'm certain that it's working as designed.

Just when you think you've scienced the shit out of something, it ends up needing more.  Ah well, it's on a firmer theoretical footing now, and there should be more in the way of clean gestural bandwidth available.

I also implemented a rudimentary pitch preview system but it may need refinements.

This project is kind of like doing a crossword puzzle.  Very slow at first, then as things start falling into place it goes faster and faster until you hit the hell-for-leather final phase where it seems everything gets wrapped up at once.

Happy Holidays y'all!

Posted: 12/26/2018 6:10:48 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

New Mains Hum Filter Due-Diligence Day

To avoid the Journal of Irreproducible Results fiasco of the previous CIC-based mains hum filter, I thought it would be behoove me to put the new Chamberlin notch filter cascade mains hum filter to bed as it were.  So I first expanded the notch spreadsheet to graph the result of the six notch cascade, and immediately noticed that the damping setting of 0.5 was causing the higher frequency notch skirts to blend together and form a low pass response on top of the notching, which lowered the effective bandwidth rather severely.  So I reduced the damping 4x to 0.125 which gives a -3dB point of around 220Hz.  Reducing the damping requires proportionally more headroom inside the notch filter, so I added some gain down/up before/after the notch filtering to accommodate this.  Here's the updated spreadsheet:

http://www.mediafire.com/file/vv4hsqcqobefy56/notch_2018-12-25.xls


The above is an Excel graph of the 6 notch cascade set to 60Hz and with damping 0.125.  Note the -3dB point of ~225Hz in general trend due to skirt blending.

I also tied the 4th order low pass filter to the 5th harmonic frequency so the 50Hz case tracks.

Then I used a diagnostic SW load on the D-Lev to take the pre and post filtered axis numbers, 10Hz 4th order high pass filter them to remove DC, and spit the result out of the SPDIF audio port.  Here are the pitch axis results with the pitch plate ~1 foot from a desk lamp (volume side is very similar):



The raw pre-filtered pitch axis number is above, post-filtered below.  The 60Hz harmonic is suppressed ~24dB, 120Hz ~18dB, 180Hz ~15dB, and the rest ~13dB or more.  The overall bandwidth is perhaps 200Hz or so.

Here are the MP3s of the audio obtained during SPDIF testing, the three 10s phases are raw, filtered set to 60Hz, and filtered set to 50Hz:

http://www.mediafire.com/file/agylqcfg0qwzx1p/2018-24-26_pitch_axis_pre_post_50hz.mp3/file
http://www.mediafire.com/file/x2dvwt8oeq6gtoy/2018-24-26_volume_axis_pre_post_50hz.mp3/file

I should note that these files represent the noise contained in the lower 18 bits of a 30 bit axis number!  Though the analog gain is uncalibrated.

During testing of the volume axis I thought I was hearing voices here and there (uh oh, dewster's off his meds!).  Turns out when the axis was operating at 710kHz it was picking up WOR, a 50kW AM radio station out of NYC.  Here's an MP3 of good ol' US of A hate radio via the raw pre-filtered volume axis:

http://www.mediafire.com/file/0o199uta9un5jre/2018-24-26_volume_axis_wor_710kHz.mp3/file

For that I had to move the volume plate near a bunch of stuff on my workbench and "tune" it to 710kHz by carefully sliding my hand on the bench.

The desk lamp introduces a ton of hum in the raw pre-filtered axis value when the plate is very near it.  With a couple of feet between them the hum level drops a lot.  None of this is audible or otherwise noticeable to me in the final functioning of the D-Lev.

The far field seems dramatically less noisy now, in particular there doesn't seem to be nearly as much interaction with the LED tuner (which is intentionally running at the 120Hz notch frequency).  Creamy smooth!  I believe I could play a tune with my hand ~1m away!  For those with 50Hz mains I should probably adjust the LED rate to 100Hz or 150Hz when the D-Lev is set to the 50Hz mode so they get the benefit of notching here as well.  A while back, in an attempt to lower LED interference, I made the LED dither signal LFSR noise rather than a ramp, but that didn't seem to change anything.

[EDIT] Oops, my mistake, the LED rate is currently 48kHz / 255 = 188.24Hz.  Hmm.

[EDIT2] Just changed the PWM from LFSR8 to LFSR32 with no apparent difference, so mains hum was probably more at work than the tuner LEDs in terms of far field noise.  It seems that I don't have to do anything special to accommodate 50Hz WRT the tuner here.

Posted: 12/29/2018 2:47:46 PM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

Eric, since you aren't bragging up your latest pitch preview features, here, let me help.

I do have some questions on a different topic though.  I'm back here because I am losing track of email communications, plus you should only have to answer these questions in one place.

My problems are perhaps as much about Synthesis 101 as they are specific to the D-Lev.  One question centers around the SOURCE parameter mult[-63:63], which chooses the harmonic series to be used as a starting point for most pitched presets, along with harm[-63:63] which sets the harmonic amplitude roll off.  I agree that these would require too many words to describe, and they really should have at least some spectrum analyzer screen shots or preferably a video to describe. I hope to do this myself and post it once I get caught up, if that helps.  I found that spending a few hours playing with all of the D-Lev's settings while watching the waveforms and frequency content on the spectrum analyzer was enlightening, but I still have questions...

It seems that nearly all of the useful presets that you have sent me and that I have been able to make to this point are based on the mult=1 series of all harmonics (something close to a sawtooth waveform). I can find some use for the mult=2 odd harmonic series as well, although I don't know how to make it less raw.

For all of the other harmonic series that are available, I am having a hard time understanding how to use them other than possibly for some bell or otherworldly or chromatic percussive sounds. I would be interested in hearing what the logic is behind these choices and how they can be modified to be more useful.  It also seems that I am having difficulty synthesizing relatively simple but mildly-bright analog-ish theremin timbres that don't sound horny (trumpety, perhaps a better word choice) because I don't know how to control the harmonic content without invoking the tracking "harm" setting or the non-tracking fixed formants or oscillator filter.

Another example of a timbre gamut that I can't seem to reach is slightly woodwind-ish character that has some accentuated odd harmonic content but still has even harmonics too.  I don't know how to modify the odd-harmonic series to get something that isn't 100% hollow, and I don't know how to suppress the even harmonics in the all-harmonic series in a manner that is independent of pitch.

The fixed filters and formants, and the inharmonic resonator are amazing for vocals and instrumental sounds, and there are tons of options here.  I'm just trying to start off with some less realistic and a little more simplistic theremin tones that are traditionally accomplished by wave shaping, and I am coming up empty.  

Does what I'm saying make sense, and what do you suggest?

Posted: 12/29/2018 5:51:17 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Hi Roger,

The PP (pitch preview) is something I threw together in an afternoon (after discussing it with you and thinking about it for a while) from stuff that was already laying around in the assembly code packages.  I knew you really needed and wanted it, so I thought getting you anything quick would be the best route.  I just sent you another code update with increased PP volume modulation depth.  I'm currently investigating loudness contours and EQ controls like bass & treble, and hopefully some fruit from that will end up in the PP and/or elsewhere.

The oscillator phase modulates (PM) a primary sine wave to generate harmonics.  The most important feature of which is that the resulting harmonics have a drop-off above 10kHz, which really tames aliasing.  For the mult[-8:8] knob, setting 0 gives no phase mod, or a sine.  Settings 1 and -1 are the same, and give all harmonics - this can be done quite economically with a single SIN2 calculation, as the output of the oscillator is used as the phase modulation directly! Setting 2 uses a secondary SIN2 calculation as phase modulation running at 2x the rate in order to generate odd harmonics, and settings >2 are just running this secondary SIN2 at 3x, 4x, ..., 8x the rate.  Negative mult values instead set the secondary SIN2 rate to 1 and increase the primary SIN2 rate by integer multiples.

The above is not the limit to what is possible, nor is it the ultimate nor particularly desired!  It's just the last place I stopped developing it (many gophers to bop).  As you point out, some control over the odd/all mix might be more useful.  I never quite know what the final form much of this should be as there are many types of players out there, some who want to do more natural / organic timbres, some who want to do way-out stuff.  But I'm totally open to suggestion!  And a digital Theremin should at least be able to do traditional analog Theremin voices to one degree or another.

It may be possible to mix the primary and secondary PM and thus control odd content.  I'll look into it.  Thanks!

[EDIT] I just checked, and mult[-8:-1] sounds (not that I'm married to them or anything) can be effectively replicated via mult[1] and a pitch tracking bandpass filter.

Posted: 12/30/2018 2:39:35 AM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

I like the idea of allowing the weighted summing of sources, and if that was possible those oddball harmonic series' (or some variations) might be more useful.  Maybe it would pay to look at the waveform libraries in hardware or soft synths, but I would guess that you already have more experience in this area.  I can take a look at what I have.

What have you thought about putting in some waveshaping functionality?  It seems like that would be a relatively easy way to mess up some ideal waveforms and add more dimensions of spectral diversity without having to think too hard about synthesizing from scratch.  Even though waveshaping creates a lot of crap, it's sort of like tuning an old shortwave radio with the precise combinations of settings that sound good amidst the noise.  It could be a useful feature, especially with the ability to save the waveshaper's settings and later replicate interesting timbres which would be further processed in the subsequent D-Lev stages.

Or not.  It's easy for me to ask about things when someone else is has to consider the work involved. And I have no idea about what kind of processing power this would take.

I think even in digital world with a vast library of waveforms and filters at my disposal I still like to have my timbre knobs to twiddle...


MORNING EDIT:  I can't stop thinking about how nice it might be to have some waveform manipulation available for SOURCE options in addition to having weighted summing of a few pre-defined harmonic series', the latter of which it looks like you have already implemented in the latest update. 

Things like variable duty-cycle pulse trains, rectified sines or sawtooths with soft threshold clipping, or other common analog processing techniques all done digitally might provide more familiar pathways to generation of the complex harmonics needed for a wide range of pleasing synthetic sounds, including some of the more traditional theremin timbres.  Add to this the extremely effective pmod/vmod modulation and all of the formant filtering and this might be absolutely killer.

Don't get me wrong-the synthesis options currently in the D-Lev provide a tremendously wide range of sounds unreachable by any other theremin that I know of.  The vocal and stringed instrument possibilities alone are endless, and much more remains unexplored. I think you could stop at any point and call it good.  But Dr. McCoy was right about engineers, so I know you'll think about it.

   

Posted: 12/30/2018 8:09:09 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"What have you thought about putting in some waveshaping functionality?"  - pitts8rh

Other than harmonic generation via soft clipping (via TANH for reduced aliasing), and the various multipliers in the PM oscillator, I haven't put any thought into this.  I think it's fairly important to steer clear from anything that might alias as that's the mark of a designer not knowing what they're doing.  But there may be ways to do waveshaping that don't introduce significant aliasing.
  
"Things like variable duty-cycle pulse trains, rectified sines or sawtooths with soft threshold clipping, or other common analog processing techniques all done digitally might provide more familiar pathways to generation of the complex harmonics needed for a wide range of pleasing synthetic sounds, including some of the more traditional theremin timbres."

Separating the harmonic content from the amplitude and then vmod-ing it back in allows for more control than normal for things that behave like clipping.  I suppose my main goal has to emulate the beautiful solo timbres as closely as I can (vocals & strings) and anything else that falls out of that is then gravy.  I want to keep the UI as simple as possible too, which can be difficult when supporting the myriad options the base entities possess. 

============

I'm learning to "emote" or phrase more with my left hand when doing violin/viola, which seems more realistic.  Here's a tune I started on late last night: [MP3].  The waveform has a bit of odd harmonic emphasis, as per the latest "blending" oscillator, which makes it sound a little more hollow.  It seems that I'm drawn to tunes that have accidentals and emphasize them.

Posted: 12/31/2018 3:25:55 AM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

Eric, I do like the change that you made to allow continuous blend of even and odd harmonics.  I think this is much better than having several fixed harmonic series.

Can this feature be expanded symmetrically in the negative direction to allow you to go to from all harmonics at 0 to strictly even harmonics at -63?  I'm also starting to think it would be interesting to have the even/odd blend itself modifiable by "pmod" and "vmod".

It's really adding another almost continuous dimension of control.  Vocals show a substantial change with a little bit of accentuated odd harmonics, and in particular one of the female voices that I have is greatly improved.  I was able to immediately find some of the bright-but-not-brassy tones that I couldn't reach previously.  I do think control in both directions would be worthwhile. 

I'm still trying to acclimate to the new pitch preview.  I think I'm seeing some overlap adjustment, but I'm having to work back and forth between two settings to adjust it ("pprev" is one I think, and I don't remember the other) and keep the volume at a barely audible level.   I was going to say that it wasn't clear what the "loud" control was doing and then I checked your previous email to find that it is not assigned yet.

Please don't put any effort into the loudness contouring on my account.  In my opinion the "pmod" parameter is working just fine, and better than anything I've ever had for my Etherwave mods.  Personally I would rather see effort go into working on a single blend control for the PP crossover threshold if that is at all possible.

I'm trying hard to not suggest pointless features that add complexity without being musically useful.  But sometimes you have to try these things a while to know if they work out.  In my earlier analog experiments, I would spend a lot of hours building VCFs, VCAs, etc. and signal conditioning boards to do these experiments only to find out within minutes that the best thought-out ideas sounded like crap. "pmod" and "vmod" are such powerful modifiers that it's hard to not want them everywhere, but if I can't restrain myself, you'll have to for me.

Posted: 1/11/2019 9:16:43 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Can this feature be expanded symmetrically in the negative direction to allow you to go to from all harmonics at 0 to strictly even harmonics at -63?" - pitts8rh

I'm no PM (phase modulation) expert, but I don't know of a way to do this.

"I'm also starting to think it would be interesting to have the even/odd blend itself modifiable by "pmod" and "vmod"."

I'll try this soon.  For the past week or so I've been concentrating on making the PM generation cleaner and the assembly more modular.  Tried a bunch of things that didn't pan out, hence my lack of posting here lately.

"It's really adding another almost continuous dimension of control.  Vocals show a substantial change with a little bit of accentuated odd harmonics, and in particular one of the female voices that I have is greatly improved.  I was able to immediately find some of the bright-but-not-brassy tones that I couldn't reach previously.  I do think control in both directions would be worthwhile."

Yes, I'm hearing that too.  I wonder if things like vocals have a small inherent odd harmonic emphasis due to the vocal tract acting like a closed pipe during the interval when the vocal cords are closed?

"I'm trying hard to not suggest pointless features that add complexity without being musically useful.  But sometimes you have to try these things a while to know if they work out.  In my earlier analog experiments, I would spend a lot of hours building VCFs, VCAs, etc. and signal conditioning boards to do these experiments only to find out within minutes that the best thought-out ideas sounded like crap."

Oh, I've been to that same dry well!

[EDIT] For those who have never heard pitch preview in action (the set of which I'm a member!) here's a sample of me playing with female vocal on the left and pitch preview on the right: [MP3].  I had the preview set to approximately 50% harmonics and with a bit of -vmod "ducking" going on.  I think my own playing style has congealed to the point where I'll likely never find myself needing/using pitch preview, but others rely on it heavily so I'll do my best to support them. 

[EDIT2] Been using the latest pitch correction (what was described before, I haven't changed it lately) and I must say it does what it's supposed to do and doesn't get in my way.  Once set up I don't find myself having to adjust or otherwise micromanage it at all, unlike earlier versions.  The trick, it seems, is to come up with and integrate as many scenarios as you can where you don't want it doing anything at all, and let providence sort out the rest.

Posted: 1/14/2019 5:44:35 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Assorted Fine Tuning

I've been taking another look at the audio oscillator hoping to make it cleaner and the assembly code more modular.  Here is where I ended up this time:


Above is the basic PM (phase modulation) unit.  It takes the NCO phase accumulator and the NCO phase increment as inputs, multiplies them up by 1 or 2, and uses the accumulator value to drive a SIN2 function, which is comb filtered with a zero at Nyquist, attenuated via a polynomial version of the increment, delayed once (to make it causal), and fed back on itself through the "harm" attenuator to generate harmonics.  The polynomial input is now scaled by the multiplier, and the polynomial function itself is simpler and more aggressive on the low end of audio.  poly := 0.55 * ( ( ~( inc * 5 ) ) ^2 )

Below is the shell of the oscillator, which employs two PM units.  It takes the phase increment, attenuates it so C8 = full scale, modulo accumulates it, adds the crossfed PM signals through the "harm" attenuator, and drives a SIN2 function, the output of which is audio.

I found it necessary to offset the NCO accumulation value feeding the odd PM1 unit by 180 degrees to prevent an odd buzzing sound when the "odd" mix is set about midway, and to prevent a minor suppression of the fundamental when "odd" is set to fully odd.  There's a lot of nuance in scaling / mixing / attenuating / etc. here and the solutions / ameliorations of which have to be more or less stumbled upon.  It's likely I have only begun to stumble!

============

I also took another look at pre-filter attenuation.  I noticed that I couldn't get the formants to ring long-term anymore because the damping-based attenuation was too aggressive.  So I removed all damping based attenuation, and moved all filter attenuation knob control from the filter output to the filter input position (including the resonator).  Unlike analog filters, digital filters don't generate thermal noise (though they do generate truncation noise), so it doesn't really matter where the attenuator is placed, though placing it at the input allows us to control internal overload associated with low damping / high Q along with overall gain.

A special weird case is the 4th order filters following the oscillator and noise sources.  These require damping-based attenuation between the two second order sections so as not to overload too easily.  It's lucky that, for synthesis purposes anyway, these filters don't have to be "clinically" perfect in shape or response in order for them to be musically useful.

I also added a notch (HP + LP) filter response option to the 2nd and 4th order cases.  I had this before and removed it, but it might be necessary for better stringed instrument synthesis.  And it gives an interesting "flanging" effect with low resonance settings.

[EDIT] I just changed all filter "reso" (damping) scaling from [full scale, not, 4th power] to [full scale, not, 3rd power] - and I like this a lot better!  The upper end of resonance is better represented and isn't insanely infinite until hitting knob max.

Posted: 1/16/2019 5:28:21 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Loudness Compensation

A fantastic article on loudness compensation:

http://www.rfcafe.com/references/electronics-world/loudness-control-electronics-world-december-1963.htm

I thought both bass and treble needed boosting at lower volume levels, but that article clearly explains it's only the bass.  As implemented, it's more of a treble shelving cut than a bass boost, which conveniently lets it function as a level control once the main volume is set.  Here's the relevant graph from the article, which was obtained by taking the difference between the various Fletcher-Munson curves:

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