View Single Post
Old 01-21-2019, 07:08 AM   #54
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,021
Default

That anti-alias tanh is interesting... Here is another version of it I came up while playing around with it:

Code:
function tanh_aa(x)
  instance(y)
  local(old_x, old_y, dx)
(
  old_x = this.x;
  old_y = y;

  abs(x) > log(2^511) ? (
    x = sign(x);
    this.x = x * log(2^511);
    y = log(2^511) - log(2);

    x;
  ) : (
    this.x = x;
    y = x - log(2 / (exp(x * -2) + 1));

    dx = x - old_x;
    abs(dx) > 0.0000000001 ? (y - old_y) / dx : 2 / (exp(-(x + old_x)) + 1) - 1;
  );
);
It should be a bit faster than sai'ke's original version (although you will likely not notice, unless you use it many times per sample), and it has ErBird's abs(x)>354 inside the function.

BTW, it seems that this tanh doesn't like sudden large changes in gain, I guess because then the difference between the current and the previous sample becomes too large. A smoother could probably fix this though.

Last edited by Tale; 01-22-2019 at 04:01 AM. Reason: Nitpicked/optimized duplicate sign(x)
Tale is offline   Reply With Quote