[sdiy] Stupid Lookup Table Tricks - BLEPs when you can't divide (and can barely multiply)
Andrew Simper
andy at cytomic.com
Mon Jul 2 06:39:26 CEST 2018
To expand on what Olivier has said:
1/x can be approximated on the range 0.5 to 1.0, and then you can scale the
input value to get it in the right range, and also scale the approximation
output by the same amount to get the correct answer.
For example, if you use the approximation:
f(x) = 17/3 - (106/9)*x + (32/3)*x^2 - (32/9)*x^3
then if your x is 0.3 then you can double the 0.3 to get it into the range
0.5 to 1.0, then also double the result of f(x):
s * f (s*x)
for s = 2 and x = 0.3 gives:
2 * f(2*0.3) = 2 * f(0.6) = 2*1.672 = 1.344
which is close to the actual value 1.3333...
In fixed point you can use CLZ (count leading zeros) if available to make
the algorithm O(1), for example if using 8 bits to represent the range 0 to
1 then:
255*0.3 = 76 = 01001100
so there is one leading zero, and then you bit shift by this amount to
scale the value into the range 0.5 to 1.0
s = 1<<CLZ(76) = 2
Another option if you've not got a multiply is to use the cordic algorithm
to do the division directly, which is O(B) where B is the number of bits.
Here is a great dr dobs article on the subject:
http://www.drdobbs.com/microcontrollers-cordic-methods/184404244
Cheers,
Andy
On Thu, 28 Jun 2018 at 20:17, O Gillet <ol.gillet at gmail.com> wrote:
> There is an alternate firmware for Shruthi / Ambika that uses
> PolyBlep. The reciprocal computation code has a better resolution,
> using the identity 1 / 0.5x = 2x. Code here:
> https://github.com/bjoeri/ambika/blob/master/voicecard/oscillator.cc#L56
>
> The original Shruthi / Ambika code uses band-limited wavetables, as
> described by Richie ; with some crossfading from one octave to the
> other.
> On Thu, Jun 28, 2018 at 1:05 PM <rburnett at richieburnett.co.uk> wrote:
> >
> > Neat! The quality is not bad but there is still quite a bit of audible
> > aliasing even with the corrections enabled.
> >
> > I think the problem is that your LUT of reciprocal values really needs a
> > lot more resolution. It returns the same value for large ranges of
> > input index. This heavily quantizes the positioning of the polyBLEP
> > corrections and ultimately limits their effectiveness for the
> > anti-aliasing.
> >
> > You're only seeing about 20dB reduction in aliasing, and should be able
> > to do much better than this in practice. But I think the implementation
> > is being limited by the resolution of the reciprocal lookup.
> >
> > The neat thing about polyBLEP is that the correction curves are simple
> > functions, so you would ideally calculate these on a more capable
> > platform, instead of using a pre-calculated lookup table. Then you are
> > only limited to the numerical precision of the calculations and not the
> > number of entries in a LUT. But I understand your motivations for doing
> > it this way to see if it can be made to work :-)
> >
> > FWIW, if you just want to generate anti-aliased sawtooths and pulse
> > waveforms on a low-end 8-bit platform without oscillator-sync, then the
> > best option is probably just to use wavetables. You store a whole load
> > of sawtooth renderings generated by additive synthesis with
> > progressively less harmonics in a lookup table. Every time you go up by
> > one octave in pitch you switch to the next waveform from the table.
> > Square an pulse can be generated by taking the difference of two
> > phase-shifted sawtooths.
> >
> > -Richie,
> >
> >
> > On 2018-06-28 01:14, Gordonjcp wrote:
> > > Why would you pick an avr8 to do bandlimited oscillators?
> > >
> > > Because folk say it won't work, that's why!
> > >
> > > https://github.com/ErroneousBosh/slttblep
> > _______________________________________________
> > Synth-diy mailing list
> > Synth-diy at synth-diy.org
> > http://synth-diy.org/mailman/listinfo/synth-diy
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at synth-diy.org
> http://synth-diy.org/mailman/listinfo/synth-diy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20180702/0f9805e4/attachment.htm>
More information about the Synth-diy
mailing list