Page 1 of 1

Tap Tempo tremolo again

Posted: Mon Jul 31, 2017 4:38 pm
by Digital Larry
I referenced this older thread:

http://www.spinsemi.com/forum/viewtopic ... =tap+tempo

I have some tap tempo code that can measure up to 1 second. The resulting value is 32767 *256 or "really close to 1.0". This maps to LFO freq or 1.0 Hz, or Kf = 26, and at the low end I'm going down to 1/20th of a second (which is probably faster than you can tap) at which point the LFO is at 20 Hz, where Kf = 502.

Now one approach is to interpolate linearly between these endpoints, but this does not really give the desired result at anywhere other than the endpoints. The real equation I am trying to implement is Kf = (8 * pi)/x, where x is the delay time in seconds, or essentially the number of samples counted between taps at 32768 Hz.

I've read the 1/X section at the knowledge base more than a few times and it is breaking my brain as I have not used the log/exp functions much and they are a little tough to understand.

http://spinsemi.com/knowledge_base/pgm_ ... n_limiters

The input X will go from 0.05 to 1.0.

The output should go from 502 to 26 over this same range, of course that is scaled to the number representation used by the LFO.

Anyone want to help an old geezer out? Thanks! DL

Posted: Mon Jul 31, 2017 6:14 pm
by frank
So if the input X goes 0.05 to 1.0 and needs to give an output of 502 to 26 and it is linear then the equation:

527.05263 - X*501.05263

Should give a result between 502 and 26 for an input range of 0.05 to 1.0 for X

Posted: Mon Jul 31, 2017 6:46 pm
by Digital Larry
Hi Frank,

I don't want linear interpolation. I want the function (8 * pi)/x so that the tap interval maps as closely as possible to the LFO period.

I'll continue to attempt to muddle through with the LOG/EXP examples.

Thx,

DL

Posted: Mon Jul 31, 2017 7:22 pm
by frank
Then I would try solving for 1/Kf instead so solve r=x/(8*pi) then do the 1/r to get the result. Since 1/8*pi is a constant it becomes a multiply

Posted: Wed Aug 02, 2017 6:40 am
by Aaron
Log rules dictate that:

log(a/b) = log(a)-log(b)
and
log(a*b) = log(a)+log(b)


so for (8*pi)/x we can re-write this as:

exp ( log( 8 )+log( pi )-log( x ) )


in spin terms this would look like:

ldax x
;load x in acc

log -1,0.29
; ( logbase2(x) / 16 ) * -1 + ( logbase2(8*pi) / 16 )

exp 1,0
; 2^(acc*16)

Posted: Wed Aug 02, 2017 9:48 pm
by Digital Larry
Thanks a lot for the clarification. I very carefully went through the 1/X example at the knowledge base and mapped it to my situation. Just about to test it. Be still my heart!

Update - it seems like it worked. To be completely up front, the value I'm really trying to get to is (8 * pi)/(x * 512) or maybe 512 should be 511 because I'm scaling the value to write into the LFO rate register.

Re: Tap Tempo tremolo again

Posted: Thu Mar 05, 2020 8:04 am
by potul
Hi Larry

can you share your final code? I'm trying to achieve the same thing, I guess (adapting the infamous tap tempo delay to a sin LFO for a tremolo), and it would be helpful, because my head is spinning with so many number conversions....

Regards

Re: Tap Tempo tremolo again

Posted: Thu Mar 05, 2020 9:30 am
by Digital Larry
Sorry, I can't share the code as it was for a commercial customer.

DL

Re: Tap Tempo tremolo again

Posted: Thu Mar 05, 2020 12:41 pm
by potul
Ok, I understand

what I came up with is a variation of the code above, changing the parameter of the log instruction

Code: Select all

...
ldax taptempo
;load tempo in acc
log -1,-0.27178149
; ( logbase2(x) / 16 ) * -1 + ( logbase2(8*pi/ 512)/16 )
exp 1,0
; 2^(acc*16)
WRAX SIN0_RATE,0.00
...
But I didn't test it yet. Later today I will burn it and test if my calculations are right.

Re: Tap Tempo tremolo again

Posted: Thu Mar 05, 2020 3:51 pm
by potul
Quick update before going to bed.....

The formula works as expected, and everything fine. But it took me 2 hours of dumb troubleshooting because it was not working initially... and the failure was that I copy-pasted some code and did not check that the registers were duplicated (stupid me).

So, the code looks like this:
once you have your taptempo register calculated....

Code: Select all

...
ldax taptempo
; do the magic
;load tempo in acc
log -1,-0.27178149
; ( logbase2(x) / 16 ) * -1 + ( logbase2(8*pi/ 512/16 )
exp 1,0
; 2^(acc*16)
wrax sin0_rate,0
...
and if you want to control a ramp LFO....

Code: Select all

...
ldax taptempo
; do the magic
;load tempo in acc
log -1,-0.2499428
; ( logbase2(x) / 16 ) * -1 + ( logbase2(8*pi/ 512/16/0.7849 )
exp 1,0
; 2^(acc*16)
wrax   rmp1_rate,1 
...
I hope it gets useful for someone in the future.