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

Posted: 7/12/2019 6:30:53 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

My Kingdom For 538 Bytes

Got past the evil scary bug, which was just a mismatch between the assembler boot reserved memory (1024 bytes) and the assembly code package boot code starting address definition (512 bytes) - it was nothing at all to fix once I tracked it down.  So I've got a whopping 538 extra bytes to play with!  Which is actually a fair amount of assembly...  

While I was in there I added a "ver" HCL command which displays the CRC of the SW load in EEPROM.  Always handy to know what the hell is currently running.

Back in business! 

Posted: 7/17/2019 6:02:38 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

SPDIF x2

A while back Roger requested a second SPDIF output for pitch preview, and now that the inharmonic resonator supports pseudo-stereo there is more of a pressing need for this feature.  With a single SPDIF the right audio output gets co-opted for pitch preview (when the pitch preview volume is greater than zero), but the introduction of a second SPDIF output allows for a better division of labor, where the original SPDIF output may be used as the line level PA output (and never passing the pitch preview signal), and the second SPDIF as headphone or personal monitor output.  With proper switching, this would cover the scenarios where a player:

1. Practices alone and monitors the stereo output via stereo headphones (this is me most of the time).
2. Performs with accompaniment and monitors pitch preview in one ear via a single headphone (this is many players I've watched perform).
3. Performs with accompaniment and monitors pitch preview in one ear and mono in the other ear via stereo headphones (does anyone do this?).

With all of the above also supporting mono or stereo going to the PA.

SPDIF only takes one output pin of the FPGA, and Roger's experiments have found that an electrical connection works as well as an optical connection (I thought optical was necessary to keep digital noise out of the output audio).  We want the analog outputs to be in phase with each other, and SPDIF TX is a timing master, so the most natural solution in the FPGA logic is to replicate the data shift registers.  I did this with an SV "generate" statement around the shift block, but intentionally excluded the master counter / state machine and flags decode from replication.  This ensures output phase alignment, that internal data for both components is taken at the same time, and saves a bit of logic here and there.  There were two convenient Hive register locations left unoccupied, so I used these for the HW / SW interface to the new SPDIF component, one for the left channel and one for the right (24 bits each).  FPGA usage has gone from 88% to 91% with no obvious dramatic increase in difficulty in meeting timing closure during the FPGA build.  I'm kind of amazed that the FPGA is this full of logic running at ~200MHz and it isn't too hard to build, nor does it seem to have a thermal problem.

I added a new "Mntr" knob to the SYSTEM UI page to switch between the old single SPDIF arrangement and the new dual SPDIF arrangement.  Regardless of knob settings, both SPDIF channels are always driven by the software.

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

Another request of Roger's was reduced sensitivity for the axis auto calibration knob.   This is a dual use knob on the main page which, when turned performs a instant auto calibration of both axes, and when pressed writes to the preset slot.  A slip when pressing the knob can accidentally turn it, thus erasing one's current edits, as well as performing an undesired auto calibration.  My prototype has small diameter knobs that are actually kind of hard to slip and turn when pressing, but the possibility is always on my mind when storing a preset (which actually requires two presses, for double the chance of slippage).  My solution here was to have the software examine the knob rotation delta, with anything over 1 detent in either direction during the sample interval triggering an auto calibration, and anything less ignored, so the knob rotation must have some deliberate minimal velocity to register as an event.  This was a much easier edit than I imagined it would be, and I want to again thank Roger for coming up with these excellent suggestions for improving the prototype.

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

I also added a bass tone control to the pitch preview, so that it now has bass and treble knobs.  And I FINALLY fixed a command line stack fault bug that's been a minor nuisance for what seems like forever (and this after thinking I fixed it several times in the past).

Posted: 7/19/2019 7:55:38 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Constant Time Gated Noise

Playing around with gated noise again.  Tried gating at twice the oscillator rate, as some research papers claim this is consistent with lower pitched human vocals, but it sounded less realistic to me.  Then I tried giving the pulses a constant on time, rather than having this be a percentage of the oscillator duty cycle, and I think it may be an improvement.  One thing I didn't foresee was highly variable harmonic content when the pulse on time is made quite small.  It makes sense in retrospect though, the gated on portion could have anything going on in there, and lacks the long-term average of ungated noise.  I need to mess with it some more to see where it might end up, but here is a sample: [MP3].  It starts out with the (muted) oscillator high enough in frequency that the cycle time is shorter than the gate interval, so the noise is constant.  Then I lower the oscillator frequency to a few Hz, and turn the gate time down to a small value, where you can clearly hear the harmonic content vary from pulse to pulse.  This is then used to "ring" the inharmonic resonator.

===========

Trumpet, Trombone, Tuba

This one took me a while to develop, though I don't know why as there isn't all that much to it.  It uses a single variable harmonic oscillator that gets brighter with increased volume (all harmonics).  Some velocity and knee are used to give it that horn "blip" at the beginning of the envelope, along with a touch of decay time.  Following the oscillator is a low Q 2nd order bandpass filter set to ~880Hz, with minor volume axis (+2) and pitch axis (+5) modulation.  It seems to work fairly well over a fairly wide range, imitating the trombone and tuba better than the trumpet IMO.  Here is a sample: [MP3].  I can't see wanting to play this 24/7 as my main go-to voice, but it might work well in a mix or as accompaniment.  And it's always educational to experiment with one's playing style, with an ear towards making the voice sound as realistic as possible.

Posted: 7/19/2019 9:56:01 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

That's growing into an interesting palette of sounds you're compiling there for a theremin player, and probably playable in a much more responsive way that if one were to MIDI-fy things and just connect it to some sampler, even if it had more options.

The wind instrument sound realistic enough to know what they represent without sounding silly, yet there is still, to my ear (can't really explain it) some "theremin" character retained, i.e. it's believable for this to come out of a theremin, and hence perhaps not so outlandish seeming for a theremin player of many years. Hah. Maybe it's just the playing with the vibrato and volume hand, but I'm not sure.

I wasn't familiar with a "inharmonic resonator", or i forgot about it, very faintly remember hearing about physics of bell sounds, but not the contents.
I found one explanation putting it as a delay line with frequency-dependent delay time. I wonder how that aspect maps out onto a physical ringing cowbell or something like that.

Edit: I wonder how and why this editor keeps randomly spitting random font control codes into text without me doing anything with the funny buttons at the top...

Posted: 7/19/2019 11:20:16 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"That's growing into an interesting palette of sounds you're compiling there for a theremin player, and probably playable in a much more responsive way that if one were to MIDI-fy things and just connect it to some sampler, even if it had more options."  - tinkeringdude

Thanks!  I think it's important to have a certain amount of internal synth control tied directly to the axes (much like they do for keyboard synths).

"The wind instrument sound realistic enough to know what they represent without sounding silly, yet there is still, to my ear (can't really explain it) some "theremin" character retained, i.e. it's believable for this to come out of a theremin, and hence perhaps not so outlandish seeming for a theremin player of many years. Hah. Maybe it's just the playing with the vibrato and volume hand, but I'm not sure."

I think it's mostly me trying to play a discretely pitched instrument like the trumpet on a continuous controller.  And the synth isn't up to doing this kind of thing with 100% fidelity.  And I'm kinda new to synth programming.  After listening to (and playing along with) some trumpet players on YouTube, I think I've got a better trumpet preset.  Nothing like listening to the real thing when dialing in a patch.

"I wasn't familiar with a "inharmonic resonator", or i forgot about it, very faintly remember hearing about physics of bell sounds, but not the contents.

I found one explanation putting it as a delay line with frequency-dependent delay time. I wonder how that aspect maps out onto a physical ringing cowbell or something like that."

That's a good description!  It's a delay line with feedback, where one of the delay elements is an all-pass reverberator and the other is a simple delay.  It can be seen as an extremely rudimentary reverb arrangement.  The all-pass makes the resonance locations non-harmonic, and thus more complex sounding.  With a lot of feedback you get things like bells and gongs, with less you get drums and hollow tubes, with even less you can simulate the violin family body upper resonances OK.  It's somewhat equivalent to a bank of bandpass filters, though obviously with considerably less freedom in terms of setting individual resonance frequencies and Q's.

"Edit: I wonder how and why this editor keeps randomly spitting random font control codes into text without me doing anything with the funny buttons at the top..."

I've found it can depend on what browser I'm using.  When editing my post in Pale Moon I sometimes get a bunch of blank lines inserted out of nowhere.  But in all browsers I have to toggle "View source" (Ctrl+Shft+s, the right-most button) before pasting text, otherwise I get a bunch of unwanted font, color, size, etc. tags.

[EDIT] Here's a better sounding trumpet IMO: [MP3].  It needs to be able to go from fairly mellow to "blarry" sounding.  Among other things the treble control was my friend here.  Fun fact: trumpet was my first instrument (grade school band for a couple of years, though I never got anywhere near mastering it - the one I had was more or less unmasterable, which may have had something to do with it).

Posted: 7/20/2019 1:20:41 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

SPDIF Box (Cirrus Logic 8416) Strangeness

During my pulsed noise experiments yesterday I ran across some odd behavior that I don't believe was directly caused by my assembly code.  When the SPDIF output from the noise generator was set to long periods (large fraction of a second) of zero data, I saw what seemed like random short-term muting of the analog output.  The zero period time had a definite threshold below which there was no muting, and above which there was mostly (partial) muting.  I was able to side-step this by reducing the noise amplitude by 96dB (signed right shift of 16) rather than stomping it to zero.

I believe the Cirrus Logic 8416 interface chip in the SPDIF box (see above) is somehow interpreting a long string of zeros (or perhaps just static DC? - I didn't test for this) as some kind of special mode.  From the 8416 manual, it's clear that the chip snoops on the digital data to switch modes, but it doesn't mention anything like this.  Evidently, a highly attenuated (-96dB) signal gives the chip something to "chew on" and keep it from switching modes or whatever undocumented behavior it's doing.  That this quite obvious weirdness happened during a valid output of the prototype is disturbing to me.

Lord knows I'm not god's gift, but it's this sort of thing that drove me away from working with other random engineers on anything I cared about at all.  I mean, I can screw things up on my own just fine, thank you very much! #NotAllEngineers (and present company excepted!)  I design my logic to be as stupid as possible for good reasons.

[EDIT] I suppose I should include the ES7144LV DAC in the lineup of suspects, though it seems to be a much simpler part than the 8416.  Who knows...

Posted: 7/20/2019 10:24:43 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Muted Trumpet

Found one presentation on trumpet mutes [LINK] that lists the resonances of some mutes.  Here [LINK] are some photos of mutes and a bit of discussion.  I suppose the sound I'm looking for is the Harmon mute without the stem, that blaring tinny metallic resonant sound from 60's movie jazz sound tracks.  I got the trumpet sounding OK to me, then tried a few formants on it to see if I could get that crazy mute sound.  Here are 2092Hz (level 41), 2709Hz (level 63), and 4185Hz (level 63) with the resonances all set to 27: [MP3] (I'm just learning this song, please be gentle with your criticism of my rendition!).  At the end is an inharmonic resonator sound that I found interesting.

Tried noodling with the trumpet sound to some tracks, the unmuted trumpet sounds really nice along with Poe's song "Spanish Doll" off of her CD "Haunted" from 2000.  Adds a kind of a flamenco spaghetti western vibe.

Ha, I played the real thing for long enough and it never dawned on me that the first valve is a full step, the second a 1/2 step, and the third 3/2 steps.  Lordy, I was oblivious to all kinds of basic stuff back then.

Posted: 7/22/2019 12:38:23 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Constant Time Gated Noise w/ VMOD

In my never ending quest for creaky voice (it's either a complicated thing, or I just haven't yet hit on the simple formula), I tried modulating the gated noise off level attenuation factor with the volume axis number - which unfortunately was a dud so I backed it out.  Worked on the gate time knob scaling, finally settled on [0:127] 72dB exponential, right shifted to give minimum changes of >1, <2, and offset to give a minimum of 2 (which gives a minimum pulse width of one 48kHz sample).  I swear, ~90% of implementing anything digital with knobs is knob scaling, and you need a diverse bag of tricks to do it justice IMO.

As there were a few knob spots left on the noise UI screen (the other ~10% comes down to real estate), I decided to swap the grey filter knob for separate bass and treble controls.  The noise source already has it's own state variable filter, but it seems that there is no such thing as too many filtering options.

Posted: 7/22/2019 3:59:48 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

The Outer Limits

There are times when I'm trying to use formant frequencies from research papers that exceed the maximum limit of 4.186kHz that I've set for the D-Lev. Since I've also set the dynamic range of the pitch numbers to 48dB, this gives a lower limit of 16.35Hz.  I would rather both be a bit higher - what are the hard limits here?

On the low end, the displayed frequency sometimes doesn't increment when spinning the knob because the decimal portion isn't shown on the LCD.  This produces two detents for the displayed values of 16, 17, 18, 19, 21, 23, 26 (all in Hz) which is kind of annoying.

On the high end, the state variable filters can go into oscillation when the damping is set to a low value and the frequency is set to a high value.  This is due to feedback gain through the state variable structure going above 1.  Currently, the minimum value the damping can be set to is 1, so the maximum frequency is:

  w = 2 * sin( pi * f / fs )  

where w = 1, fs = 48kHz, and solving for f:

  f = fs * sin^-1( 1/2 ) / pi = 8kHz

In my filtering spreadsheet I'm seeing anything significantly above ~4kHz not behaving all that "scientific".  High Q peaking gets really droopy, and the center frequency of the peak is significantly in error.  For example, setting it for 7kHz and infinite Q (damping = 0) I see a ~6kHz peak of only a couple of dB.  So if we made the top frequency 8kHz the entire top octave would have increasing error as the setting approaches the top.

Pushing the top frequency higher might also have aliasing implications for the oscillators.  If I were to go ahead and increase the top frequency I might try for A8, which is an even 7040Hz, and 8 octaves below this gives 27.5Hz, which is just outside the double detent range.  Will mull it over.

Posted: 7/22/2019 6:06:46 PM
ILYA

From: Theremin Motherland

Joined: 11/13/2005

dewster, dont worry, we are all the men in years, with an upper bound of 10-12 kHz

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