[sdiy] Logs on a micro? Was: Reverse engineer an EPROM encoding?
Eric Brombaugh
ebrombaugh1 at cox.net
Wed Nov 13 01:24:11 CET 2013
In general it's not too hard to do a log2() approximation using simple
math operations without lookup tables - I do it all the time in
hardware. The trick is to implement it as a piecewise-linear function.
First you bring the input word in, then shift it upwards until there's a
'1' in the msb. Subtract the number of shifts required for this from the
number of bits in the input word - this is the integer portion of your
output and is the coarse log2() result.
For the piecewise linear portion, take the remaining bits below the '1'
in the MSB and concatenate them with the integer bits from the shift
operation.
There's a reasonable description of it here:
http://degiorgi.math.hr/~singer/aaa_sem/Div/97-105.pdf
and many other places - this is old tech.
Eric
On 11/12/2013 05:05 PM, Tom Wiltshire wrote:
> You're looking for an equation to get you from linear input data to values you have to stick in the EEPROM, right?
>
> So we're looking at something like:
>
> (log2( Linear Data )+5) * 128 = EEPROM Data
>
> If you want to do such a sum on a microcontroller (Is that what you meant?), you'd do best at the PICList:
>
> http://www.piclist.com/techref/microchip/math/power/index.htm
>
> As usual for this kind of craziness, Scott Dattalo is right up there. Still, his solution suggests that you'll be looking at some kind of approximate method - he uses a lookup with interp. I suppose the other approach would be interative methods. How much time have you got?
>
> HTH,
> Tom
>
> On 12 Nov 2013, at 23:19, MTG <grant at musictechnologiesgroup.com> wrote:
>
>> I have made some progress in figuring out this EPROM/ASIC/DAC combo that Kawai were using in the mid-80's, but I need some help with coding suggestions. You may recall some of the details by looking back in the archives. It's a drum machine that stores the sounds in some kind of log format. The ASIC then anti-logs the data before presenting it to the DAC. The ASIC does mixing and volume control.
>>
>> I made an EPROM containing a 12-bit ramp and inserted it in the drum machine. Then for every friggin single step of that ramp, I recorded the output from the ASIC to the DAC. Here is the transfer function:
>>
>> http://musictechnologiesgroup.com/blog/wp-content/uploads/2013/11/Kawai_R100_DGU.bmp
>>
>> So one obvious way of pre-encoding my own sound data would be to use a look-up table for the data I've recorded. BUT I'm looking for alternatives and since there has been talk about fixed point math and the like before... I thought people here might help. In a nutshell, it looks to me like for every 80h change in input data, the output data doubles. I wonder if there is a some binary math I can do here that do the same thing?? Here are some sample values:
>>
>> EPROM out DAC Input
>> (hex) (decimal)
>> --------- ---------
>> 000 0
>> 080 0 (1/16)
>> 100 0 (1/8)
>> 180 0 (1/4)
>> 200 0 (1/2)
>> 280 1
>> 300 2
>> 380 4
>> 400 8
>> 480 16
>> 500 32
>> 580 64
>> 600 128
>> 680 256
>> 700 512
>> 780 1024
>> 7FF 2048 (rail)
>>
>> I don't think it's piecewise linear either, but I've not had time to look at the in-between values.
>>
>> GB
>>
>> On 10/16/2013 12:40 PM, Scott Nordlund wrote:
>>> Several drum machines did use Mu-law encoding (Drumulator or something; I don't remember). And several others used floating point DACs (various Yamaha models since they were into that sort of thing). But you'd be able to tell this from the DAC circuits themselves. I do think it's likely that the waveforms are stored in logarithmic format, which is exponentiated before being sent to the DAC, but for a different reason. Two part question: (1) Is it possible to control the amplitudes of the individual drum sounds? (2) Is it a multiplying DAC configuration where the sounds are scaled by a time-multiplexed control voltage fed into the DAC's Vref pin? If (1) is yes and (2) is no, it's most likely that the wave data is stored in a logarithmic format for easier amplitude control. As in the DX7, amplitude is controlled by adding the amplitude value to the logarithmic format waveform data, then passing the result through an exponential table. y = exp(log(a)+log(b)) is equivalent to
> y
>> = a*b.
>> It's more efficient because it requires only a lookup table rather than a multiplier.
>>>
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at dropmix.xs4all.nl
>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>
More information about the Synth-diy
mailing list