Ayra
August 29, 2023, 6:40pm
1
Hi,
I notice that when I call
state.getParameter("gain")->setValueNotifyingHost(gain); //where gain is 0.892857
when I’m in parameterChanged the value of newValue is truncated in 0.89
void GainProcessor::parameterChanged (const String& parameterID, float newValue)
{
DBG("newValue " + String(newValue)); // this print 0.89
}
there’s something I’m missing? how to fix it ? I have a gain that goes from -100 to 48 db and in this way it has only stepped values (where for example I can set gain to 0.000 db but only to -0.320 db or to 0.800 db)
Maybe the truncation happens when converting from float to String?
Try
DBG("newValue " + String(newValue, 10)); // this print 0.89
Now you get 10 decimal points
1 Like
Ayra
August 29, 2023, 8:24pm
3
really thank you for the trick, I think the problem is that between setValueNotifyingHost and parameterChanged the number changed… Debugging:
state.getParameter("gainL")->setValueNotifyingHost(gain); // here value is 0.8928571343
After is called:
void parameterValueChanged (int, float) override
{
const auto newValue = denormalise (parameter.getValue()); // here it become 0.8899999857
[...]
}
Not every value can be represented as 32-bit float. The difference is small enough to be imperceptible.
1 Like
Ayra
August 29, 2023, 9:07pm
5
but in a range of “-100” - "48 " it becomes significant…
No, it will not be significant. It will be off by something like 0.00001. Doesn’t matter at all.
1 Like
The interval is defined in the parameter itself. How are you defining your parameter?
1 Like
Ayra
August 30, 2023, 3:01pm
8
I init it with this lines of code:
state( *this, nullptr, Identifier("GainProcessor"),
{ std::make_unique<AudioParameterFloat>(ParameterID { "gainL", 1 }, "gainL", 0.0f, 1.0f, 0.5f),
std::make_unique<AudioParameterFloat>(ParameterID { "gainR", 2 }, "gainR", 0.0f, 1.0f, 0.5f) } )
That constructor for AudioParameterFloat is using the default precision which is 0.01f;
Use the constructor that takes a NormalisableRange:
static NormalisableRange<float> getGainRange()
{
return { 0.f, 1.f, 0.0001f, 1.f};
}
std::make_unique<AudioParameterFloat>({ "gainL", 1 }, "gainL", getGainRange());
1 Like
Ayra
August 30, 2023, 3:22pm
10
… I’m an idiot sorry, I known about normalizable range, but I forgot it, sorry