Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinity found with unmap function of rsParameterMapper stuff #249

Open
elanhickler opened this issue Oct 4, 2018 · 4 comments
Open

Infinity found with unmap function of rsParameterMapper stuff #249

elanhickler opened this issue Oct 4, 2018 · 4 comments

Comments

@elanhickler
Copy link
Contributor

elanhickler commented Oct 4, 2018

p = new jura::ModulatableParameter("spike", -1, 1, 0, jura::Parameter::LINEAR);
addObservedParameter(p);
p->setValueChangeCallback([this](double v) { oscillator.setBendSymmetrical(v); });
p->setMapper(new jura::rsParameterMapperTanh(-1, 1, 5));

image
x becomes infinity if y is over 1

tanH code

  double map(double x) const override
  { 
    x = 2*x - 1;           // 0..1 to -1..+1
    return a * tanh(b*x);  // -max..max
      // maybe generalize to y = a * tanh(b*(x+c)) + d for unsymmetric ranges, etc. 
  } 

  double unmap(double y) const override
  { 
    y = atanh(y/a) / b;    // -1..+1
    return 0.5 * (y+1);    //  0..1
  }

if tanH shape is 5, and we set parameter value to 1 (with an input box value entry! not with mouse) we get infinities, something to do with the unmapped normalized value going over 1 (it was like 1.0000084 or something). Please fix, I was very much enjoying the fine control of having a shape of 5!

temporary fix
image

i dunno what this is but...
image

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Oct 4, 2018

hmm...actually, infinity is the proper value of atanh(1):

https://www.desmos.com/calculator/9jrf3hkipt

(and above 1, it's actually not even defined). so, maybe we need indeed to hack around with clipping or whatever. but the error doesn't seem to have to with infinity per se but with my root-finding algorithm not converging (which could be because the function is so flat in that area). i could try a more robust (but typically slower) root-finding algorithm such as bisection (instead of false position) ....or finally implement brent's method (i want to have that algorithm in the library at some point anyway). would be best, if i could try this in the debugger myself. what would i have to do?

@elanhickler
Copy link
Contributor Author

elanhickler commented Oct 4, 2018

RhythmAndPitchModule.cpp
image
set to 1 instead of .99999

double click on the widget in the UI and enter 1.

you will get an infinite hang because I calculate knob arc based on normalized value which will be infinite, so you'll have to put a breakpoint where I have circled or you can't debug.

@elanhickler
Copy link
Contributor Author

I'm not on your latest build so there will be lots of errors. Use build from September 27 2018" fixed mac build issues"

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Oct 5, 2018

ok, i can reproduce it now in my DebugAudioModule. hmmm....this is some numerical precision issue...i have to experiment with my convergence criterion in the root finder...maybe i'm dividing by a difference of numbers which gives zero....need to investigate...i think i will have to create a unit test for my root-finder and throw some "evil" functions at it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants