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

Posted: 2/20/2018 8:07:28 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Grunt Work

As of yesterday I've laid most of the groundwork to implement presets.  As per my previous post re. them, I standardized on a byte for the ENCoder preset value, a byte for the preset TYPE (kind of an opcode), a 32 bit USE value, and a 4 byte LaBLe, all of which fit in a contiguous 10 byte space.  I stuck all 50-ish of these structures together in memory to form a contiguous block that can be accessed with a stride of 10.  ENC is the thing that gets manipulated by the associated encoder on a given page, USE is the value that gets used directly (or after something simple like a multiply, offset, or shift) by the code, LBL shows up on the LCD preceding the value, and TYPE helps the various parts of the code interpret what to do.  ENC is the only thing that ends up in EEPROM as a preset, and being 8 bits limits any single adjustment to this number of discrete values.

It took me a while to settle on the TYPE encoding in terms of ENC limits.  TYPE 0 is null, and displays a blank on the LCD.  The TYPE values 1-127 are just that, limits of 0 to the value.  The next 64 are +/- limits, the next 8 are 0 and 2^n - 1 limits, the next 8 are squared versions of those, and the next 8 are -2^n to 2^n - 1 limits.  This leaves 3 remaining TYPEs if we want to adhere to the LSb decoding, or 3 * 32 = 96 types if we don't (I obviously chose not to adhere).  I currently have two custom types, one for half note spacing of filter frequency and the like, and one with 2^12 dynamic range for volume attack and decay.  To arrive at this encoding I did a quick inventory of the limits in use (most are 0 to 2^n - 1). 

Having a TYPE means we can put anything we like on the LCD for the encoder value.  It's nice to finally see Hz for filter frequencies (I need to do something similar for Q or damping).  Handing the LCD string address directly to the display generator to stick the LBL and displayed value in there was the most straightforward way to do this.

And now all complex / time consuming conversion from ENC to USE values (LOG2, EXP2, INV, etc.) is out of the critical real-time path, and handled by a thread that gets interrupted at the LCD / encoder / refresh rate of 180Hz.  With the core running at 180MHz and 8 threads sharing this, that means we've got 1,000,000 / 8 = 125,000 cycles to do it in, which is a lifetime.

All of the USE values on the displayed page get updated at this rate, but none of the others.  So I've got a function that goes through and refreshes all USE values, and call it at start-up so I only have to put default values in one slot (ENC) and the rest auto-generate.  I'll be using this function when a new preset is loaded.  Limiting parameter loading from EEPROM to a subset, say past a certain point, can avoid changing system parameters that are placed lower than the limit.  I'm thinking of having system parameters store to EEPROM only when the associated knob is pressed, and recall only at power-up.  One system parameter will select 50/60Hz mains filtering, another will select the power-up preset to load, and there will be others for pitch and volume sensitivity, offset, linearity, etc.

A little more than 10% of RAM is left, which is probably OK though I wish there were more.  Most of the subroutines are defined and in memory, so calling them a bunch more shouldn't need all that much code.  It's kind of creepy making huge structural edits to the code at this point, as I need the prototype to remain in playable condition for practice and show-and-tell.  Some weird external RF thing was going on last night around midnight which made me think I'd subtly broke the pitch side, but by sticking older loads in there I finally realized that I hadn't.

Posted: 2/22/2018 2:26:24 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

DSP ~= Fractions

The vast majority of DSP math is fractional.  Filter coefficients are almost always less than one, gain terms tend to be defined in terms of 1 = max, the underlying polynomial coefficients in the various math library functions are less than one, floats themselves are fractions with separate signs and exponents, etc.  Fractions are everywhere because they're well-behaved (i.e. they don't blow up).  And if the fractions are unsigned (i.e. non-negative) then things are even more well-behaved.  Multiply an unsigned fraction by another unsigned fraction and you get an unsigned fraction.  Raise an unsigned fraction to an unsigned fractional power and you get an unsigned fraction, etc.

LOG2 is kind of mind bending in this regard.  My current UINT version of it gives a 5.27 unsigned decimal output which is fine, but the big issue with it is what to do with 0 input.  The input range [0:1) should give an output range of [-infinity:0) which is negative, and unsigned ints can't express the negative, so I punted here and return the smallest value I can, which is 0.  I'm wondering if I should instead define the input as an unsigned fraction, and return negative LOG2 which gives (+infinity:0].  

I'm trying to design a pipeline of LOG2 => fractional mult => EXP2 that gives fractional powers for any fractional input.  I think I already have the pieces to do it but need to convince myself whether that's true or not.  Sorry, kinda thinking out loud here.

[EDIT] Got it figured out.  

1. Clearly, for UINT x and output, and UFRAC y (UINT ^ UFRAC = UINT) we can use the integer forms of LOG2 and EXP2, with an extended unsigned multiply in the middle.  Then force zero out for zero in.

2. For UFRAC x, y, and output (UFRAC ^ UFRAC = UFRAC):

  LOG2(in / (2^32)) = LOG2(in) - LOG2(2^32) = LOG2(in) - 32

So we can employ logical NOT to negate the LOG2 result, multiply (extended unsigned), then NOT again.  This performs UINT <=> UFRAC in the middle so we can again use the integer forms of LOG2 and EXP2 along with a zero force.  Max error about the same as the version of EXP2 employed.

Glad to finally put this to bed, it's been in the back (and front) of my mind for too long.

[EDIT2] And of course, after looking at it some more, it's not put to bed.  For waveform bending and quantization and such I really need UFRAC ^ UINT = UFRAC, which gives nice parabolas and such.  Not sure how to do the multiplication without it blowing up.

Posted: 2/27/2018 9:03:45 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Odd & All

I've been using integer powers of fractional ramp and triangle, generated by and subtracted from the NCO fractional ramp, to produce ramp-ish and square-ish waveforms.  Setting the knob to 0 gave a sine wave, increasing positive values gave increasing quantities of all harmonics (ramp), and increasing negative values gave increasing quantities of odd harmonics (square).  Not bad in the aliasing department, but the glottal fry struck me as lame.

Yesterday I switched to LOG2 | MUL | EXP2 to implement fractional powers of fractional I/O and used two variants of this to generate a sort of rounded step NCO phase, and fed this to the SIN2 function as phase modulation.  The panel knob works the same as before, but the underlying power is continuously variable, so I can use it as a harmonic control input.  Here's a sample of it: (link).

When set to higher levels of harmonics, it obviously aliases above C7 or so, but the glottal "pop" is much clearer, and human voices don't often go above C7 (though other things do).  I guess it's time to really start looking into anti-aliasing methods.

Posted: 2/27/2018 11:41:18 PM
Touchless

From: Tucson, AZ USA

Joined: 2/26/2011

You joined a year after me, why the insults? I have met who you speak of, an unselfish contributor who helps theremin enthusiasts build things that work.

Yes this sound is much better, trying not to be a cheap digital whistle... but after your "many" years of research would Clara like it or even Lev himself? Have you ever had a qualified Thereminst test your approach, is this a direction that improves the original design or is it simply Theremini-2 which you call the original a toy.

link

T

Posted: 2/28/2018 1:12:42 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

 "I have met who you speak of, an unselfish contributor who helps theremin enthusiasts build things that work."

You mean Christopher, who regularly shows up here to unselfishly contribute a ration of shit?

"Yes this sound is much better, trying not to be a cheap digital whistle... but after your "many" years of research would Clara like it or even Lev himself?"

Jesus, who can say?  Who cares?

I mean, I have respect for them, but if they were somehow reanimated and it turned out they disapproved (?) it wouldn't really change what I'm doing or where I'm trying to go with this project. 

Posted: 2/28/2018 10:46:18 AM
tinkeringdude

From: Germany

Joined: 8/30/2014

It seems to me some people here are not good at seeing potential in things and imagining a possible trajectory, extrapolating (not necessarily linearly!) from the past so far. That, paired with a lack of understanding of the effort involved in R&D for this new instrument to get every little detail exactly right - especially as a one man band. And as a third, a failure to discern the (I guess. I'm not dewster and haven't read the whole thread from start) the two different goals between, say, the "Theremini" and this new device here. The former was made to produce some cheap device for the masses to get some first idea of theremin. To try out some notoriously difficult to learn, let alone master instrument, spending 400 bucks or so for *a kit*, like the Etherwave, may seem a bit much, if you can get a beginners guitar or keyboard for less than 100.
Dewster's instrument, on the other hand, does apparently not have this target audience, although as I understood it, there are some aspects to make it more playable, as an option/setting anyway.

He is about to put all the details he has worked on together and you can already see and hear the baby scream, now please have the patience to let it mature into an adult who may be able to do great things!
To me it looks and sounds very promising. As soon as the playing responses are working satisfactorily, there are endless possibilities to enhance the sound / give different kind of flavors of typical and untypical theremin sounds, if that's on the agenda.


And on a side note - I do have *some* sympathy for the "analog sounds better" crowd - e.g. in certain areas of analog synthesizers, where even the better implementations maybe are 90% convincing. Some people like to tease skeptics with blind A/B comparisons, but they usually use patches which are flattering to the digital synths, not really kicking it hard. Esp. the fatter or nastier settings are, in the synths I've heard, not fully convincing. Although in recent years, researchers have apparently stepped it up a notch.

BUT - when it comes to an instrument as utterly tame (sonically) as a theremin, I find the hostility towards digital sound production utterly ridiculous. From my limited knowledge, and hands-on experience, I would say there's not much going on that poses too much of a challenge *in general*, especially if you have lots of resources (memory, processing).
In dewster's case, he imposed some strict limits on those things (for BOM price point?), which is why a lot of optimization is going on and things are not as easy.

But there were already some nice sounds... I'm especially impressed by the percussion sounds and their seamless playability connected to fluid playing.
There are possibilities not known before in theremins.


I, for one, am looking forward to the product!

P.S. as for people like Clara not liking it - it depends. The old Clara, maybe not. But do note that the young Clara obviously was very open to playing a new strange instrument that hardly anyone plays to this day, and that was of a category that some musicians considered to be somehow evil, unnatural (spooky electronic, nobody understands!!!),or "not a real instrument" and such things.
I say, if there's anyone who would be delighted by this instrument, it's (young) Clara Rockmore.

Posted: 2/28/2018 3:26:18 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Captain's Log, Stardate 2018.02.28

My main goal was to develop a professional grade Theremin that's simple to set up and maintain, is linear and stable, with adjustable sensitivity and a pitch display.  I've met that goal.  

The prototype is much simpler to set up than the Theremini or EW, and requires no maintenance, tuning, or alignment.  It is likely is more linear and rejects hum better than any other Theremin in existence, and I've found the responsive pitch & volume display to be invaluable to my own (pitiful) playing ability and advancement.

As it sits, the prototype has maybe $75 in parts, which could likely be reduced, though cabinetry is always expensive.  I suppose one could stick it all in a plastic box and call it a day, and manufacture it for (wild guess) $150 or so, and sell it retail for 3x or 4x this. Still, not bad for a Theremin that could mop the floor with the EW-Pro.  Mass production (however unlikely) could get it below the cost of the Theremini.  It would be great if everyone could afford an excellent Theremin, and this, ultimately, is why I'm doing this work.

What I'm working on now is (in one sense literally) bells and cheap digital whistles.  I looked at pitch correction some more yesterday and have it stripped down to almost nothing (though I'm still a bit on the fence as to its usefulness for me personally).  Alias mitigation is now more urgent with the more harmonically rich oscillator, and presets are crying out to be implemented.  Outside of a single oscillator, a noise source, the formant filter bank, and the volume side envelope generator, almost nothing has been done in the way of signal generation.

The underlying soft processor core is both a limitation and an asset.  It's so simple that coding in assembly is quite tractable.  And 8 threads with 8 interrupts gives a lot of flexibility in terms of real-time bandwidth allocation.  But there isn't much main memory so things like reverb are pretty much out (I love reverb, though one could easily spend a man-year on it alone).  A smaller FPGA lashed to a cheap multi-core ARM or similar with gobs of memory seems like a prudent course, though I'm loathe to give up the fine grained control I have over Hive, and the ability to design custom peripherals for it.

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

"I do have *some* sympathy for the "analog sounds better" crowd - e.g. in certain areas of analog synthesizers, where even the better implementations maybe are 90% convincing. Some people like to tease skeptics with blind A/B comparisons, but they usually use patches which are flattering to the digital synths, not really kicking it hard. Esp. the fatter or nastier settings are, in the synths I've heard, not fully convincing."  - tinkeringdude

Agreed.  Familiarity with things like aliasing and truncation error, and reading reviews of digital guitar FX pedals, can help one appreciate at least a portion of the analog=better argument.  Some things, like distortion, which are trivial in the analog domain, are quite problematic (though not impossible) in the digital domain.  But digital has it all over analog when comes to stability, repeatability, noise, economics, UI, etc.  Digital is often disparaged as being too precise, which is kind of ironic.  And (big) if given the effort, digital can sound as - or more - nuanced than analog.  So my take is digital=better (except for the exceptions).  They look sexy, but few would want to own & operate one of those huge wall-covering analog synths.  They take forever to program (no presets) and just keeping the pots clean would be a part-time job.  The Caustic synth is $10 and runs on my crummy Fire7.

One can easily do all sorts of things really wrong, or audibly vaguely wrong, in digital, and draw legitimate criticism.  I stop listening when people challenge the fundamentals (e.g. sampling theory) with superstition and techo-fear.

Posted: 2/28/2018 5:05:31 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

As for reverb, could you just slap something like this onto your processor? (receives and sends digital).

http://www.coolaudio.com/docs/V1000_DATASHEET.pdf

Apparently, the BUgera V22 guitar amp has this (using reverb mode only). The board seems to have digital noise issues, to no fault of the chip I assume.

Prices per piece in USD:
10 pcs: 11.50
100-999 pcs: 2.90
> 1000 pcs: 2.40

Source:
http://coolaudio.com/prod-coolaudio-semi.php?page=1

 

Posted: 2/28/2018 5:37:41 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"As for reverb, could you just slap something like this onto your processor? (receives and sends digital)."  - tinkeringdude

Hmm.  With 128 cycles per PCM sample, I have a hard time believing the reverb could be anything but very rudimentary.  Could maybe replace a spring reverb in a guitar amp, but I'd want more.  The equivalent of 128 DSP cycles could probably be done with one Hive thread.  Hanging more memory off the FPGA and utilizing some of the remaining ~33% of the fabric would likely do better.  Maybe down the road...

Our Roland RD-700NX keyboard has surprisingly lame reverb, so lame I'd rather not hear it.  I can't remember the Theremini ambient effects very well, but I don't recall a real reverb being in there, just simple delay effects.  There are decent digital multi-effects pedals out there that could likely run circles around both (and provide another axis of control over them via pedal).

 

Posted: 2/28/2018 5:43:09 PM
Thierry

From: Colmar, France

Joined: 12/31/2007

"Captain's Log, Stardate 2018.02.28 My main goal was to develop a professional grade Theremin that's simple to set up and maintain, is linear and stable, with adjustable sensitivity and a pitch display.  I've met that goal.   The prototype is much simpler to set up than the Theremini or EW, and requires no maintenance, tuning, or alignment.  It is likely is more linear and rejects hum better than any other Theremin in existence, and I've found the responsive pitch & volume display to be invaluable to my own (pitiful) playing ability and advancement. As it sits, the prototype has maybe $75 in parts, which could likely be reduced, though cabinetry is always expensive.  I suppose one could stick it all in a plastic box and call it a day, and manufacture it for (wild guess) $150 or so, and sell it retail for 3x or 4x this. Still, not bad for a Theremin that could mop the floor with the EW-Pro.  Mass production (however unlikely) could get it below the cost of the Theremini.  It would be great if everyone could afford an excellent Theremin, and this, ultimately, is why I'm doing this work. What I'm working on now is (in one sense literally) bells and cheap digital whistles.  I looked at pitch correction some more yesterday and have it stripped down to almost nothing (though I'm still a bit on the fence as to its usefulness for me personally).  Alias mitigation is now more urgent with the more harmonically rich oscillator, and presets are crying out to be implemented.  Outside of a single oscillator, a noise source, the formant filter bank, and the volume side envelope generator, almost nothing has been done in the way of signal generation. The underlying soft processor core is both a limitation and an asset.  It's so simple that coding in assembly is quite tractable.  And 8 threads with 8 interrupts gives a lot of flexibility in terms of real-time bandwidth allocation.  But there isn't much main memory so things like reverb are pretty much out (I love reverb, though one could easily spend a man-year on it alone).  A smaller FPGA lashed to a cheap multi-core ARM or similar with gobs of memory seems like a prudent course, though I'm loathe to give up the fine grained control I have over Hive, and the ability to design custom peripherals for it. ============ "I do have *some* sympathy for the "analog sounds better" crowd - e.g. in certain areas of analog synthesizers, where even the better implementations maybe are 90% convincing. Some people like to tease skeptics with blind A/B comparisons, but they usually use patches which are flattering to the digital synths, not really kicking it hard. Esp. the fatter or nastier settings are, in the synths I've heard, not fully convincing."  - tinkeringdude Agreed.  Familiarity with things like aliasing and truncation error, and reading reviews of digital guitar FX pedals, can help one appreciate at least a portion of the analog=better argument.  Some things, like distortion, which are trivial in the analog domain, are quite problematic (though not impossible) in the digital domain.  But digital has it all over analog when comes to stability, repeatability, noise, economics, UI, etc.  Digital is often disparaged as being too precise, which is kind of ironic.  And (big) if given the effort, digital can sound as - or more - nuanced than analog.  So my take is digital=better (except for the exceptions).  They look sexy, but few would want to own & operate one of those huge wall-covering analog synths.  They take forever to program (no presets) and just keeping the pots clean would be a part-time job.  The Caustic synth is $10 and runs on my crummy Fire7. One can easily do all sorts of things really wrong, or audibly vaguely wrong, in digital, and draw legitimate criticism.  I stop listening when people challenge the fundamentals (e.g. sampling theory) with superstition and techo-fear."

Dewster, your self-adulation is ridiculous. You never made an attempt to get your design approved by at least one of the well known professional thereminists, like Carolina Eyck, Lydia Kavina, Thorwald Jorgensen, or Peter Pringle. AFAIK, none of them played your instrument in a public concert up to now. All your (arrogant sounding) statements like "could mop the floor with the EW-Pro" are only based on... your personal experience as a professional musician? Did I miss your last concert and CD recording with the New York Philharmonics? 

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