Digital distortion (with lookup table)

Started by carrejans, March 26, 2009, 09:02:56 AM

Previous topic - Next topic

carrejans

Hi,

Does anyone have experience with making a digital distortion with a lookup table?
How does the algorithm works?
(maybe some interesting links, or pieces of code)

I'm using a Symphony Soundbite dsp development board from Freescale (Motorola). I'm programming in assembly.

Thanks...

zyxwyvu


carrejans

Quote from: zyxwyvu on March 26, 2009, 08:58:53 PM
Here's something similar that may help you:

http://www.diystompboxes.com/smfforum/index.php?topic=49860.msg379872#msg379872

I don't see why this can be helpfull, actually.

So no one here with dsp experience?

cctsim

I think the look up table refers to the transfer function of the clipper. Instead of computing the values directly you look up the output values based on a table. The clipping in a tubescreamer based overdrive for example can be approximated using the sinh( .) function, which maybe complex to compute in real time. Another way is to approximate the clipper with  a lower complexity nonlinearity such as

g(x)=x/(1+|x|^n)^n

flo

Quote from: carrejans on March 27, 2009, 04:21:24 AM
Quote from: zyxwyvu on March 26, 2009, 08:58:53 PM
http://www.diystompboxes.com/smfforum/index.php?topic=49860.msg379872#msg379872
I don't see why this can be helpfull, actually.
It's a hardware example for what you asked: "digital distortion with a lookup table".

The software part of it is filling the EPROM RAM with some (scaled) discrete values from a nice transfer function like:
Y = X*X
Y = sinh(X)

This goes for any DSP based solution where you have:
A/D -> "Software with a large LookUpTable filled with a clipping transfer function" -> D/A

Transmogrifox

The lookup table assumes the full scale input is finite (which it is for a DSP) and is a segment reserved in memory that stores an appropriate output for every possible input.  After this table is stored, you pass the lookup table function a number (audio sample).  The lookup table increments to the address associated with that particular number and spits the number from the table into the output.  Note that this is not valid for time-variant functions such as filters...well, it could be done with way more memory and programming time than what it's worth.

The advantage of a lookup table is that you could build analog circuits and record the exact clipping function instead of trying to mathematically model it.  If you build the clipping stage without filtering and size your DC blocking caps to have little or no effect on the signal fed through, then you can get a good measurement of the pure clipping curve.  You feed the analog circuit input with a good ramp or triangle wave signal at, say, 100Hz.  Adjust analog levels to be feeding the input right at full scale.  You would probably have to record many cycles before you just happened to hit every number in the range.    Alternately, a person could record the general curve and interpolate everything in between. 

{Some explanation:  I'm assuming 24-bit A/D conversion.  You're sending in a 100Hz signal that traverses the full 24-bit (16 million different numbers) range.  At a sampling frequency of 48kHz, you can get a maximum of 48,000 distinctly different numbers in a second, and that assumes the clock was synchronized with your signal so that it hit a different group on every cycle).  It would take a minimum of 6 minutes to have a chance at measuring a value for every single number in the range.  In reality it would probably take several hours before you had 16 million unique numbers stored in a lookup table.  I hope that makes sense. :)  If you were just to record a few cycles of the signal, then you would have a patchy set that represents the general curve throughout full-scale.  Then one could interpolate each number in between to obtain a reasonably accurate full-scale lookup-table}


For the table's operation,  whenever you get a signal on the input in the future, the DSP algorithm looks in column "A" for a match, then outputs the corresponding value from column "B", which is the recorded output of the clipper.

To do this simply, you don't really need to store two columns of data in EEPROM.  If processing 24 bits, you allocate 2^24 (16e6) addresses to represent every value within the full-scale range.  If the input sample at some arbitrary time is 2,014, then the DSP will recall the value stored in address {[buffer start address] + 2014} , and put that into the audio processing path instead of computing that number from a mathematical model.  You trade processing expense for memory.  Without a lookup table, the DSP does these same calculations over and over and over again and always comes up with the same result.  If you are needing to save some CPU clock cycles for other tasks (like filters), the lookup table is a must.

The lookup table philosophy says, "we'll only crunch the numbers once".  Unless the mathematical formula is really simple (like a+b), a read from memory can really save your CPU from unnecessary exercise.
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.

R O Tiree

#6
Interpolation shouldn't increase processor overhead too much? Not quite as simple as (a+b), but not much more crunching. In which case, have a look at what I posted a couple of weeks ago about a TubeScreamer's distortion curves...

As you can see, I only used 29 points for each line, covering the range +1mV to +3000mV and got pretty smooth curves. Negative numbers? Just reverse the sign, as a stock TS is symmetrical. For assymetric (LED one way, Si diode the other, for example) then you'd need to populate some more points. Suffice to say that +/- 3V should cover the expected range of input (another couple of points to take it up to 5V for completeness' sake?). A few more curves (say a total of 10?) to "fill in the gaps" and we're talking 290 samples covering the whole spectrum  for a stock TS, instead of 16 million to cover just one gain curve. It's a simple matter to convert/scale those input voltages on the graphs into numbers that you'd get spat out of the A-D converter.

Even if you decided to populate every millivolt from 1 to 5000 for 100 curves, you're still only talking 500,000 values in your look-up table and you've got it covered, 1,000,000 if you decide to go assymetric. So, you can get at least 16 and up to 32 different pedal-response models into the same 16-Meg EPROM, not just one curve from one pedal :) If you're prepared to accept only slightly-reduced fidelity, then we're talking hundreds if not thousands able to be shoe-horned into one EPROM. Anyone want to bet whether Boss/Roland, Korg, Vox, Line6 et al use look-up+interpolation or just look-up?
...you fritter and waste the hours in an off-hand way...