# Why are all audio parameters \*float?

**URL:** <https://forum.juce.com/t/why-are-all-audio-parameters-float/32718>\
**Category:** General JUCE discussion\
**Created:** [April 6, 2019, 1:08pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718 "2019-04-06T13:08:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [April 6, 2019, 1:08pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/1 "2019-04-06T13:08:41Z")

</div>

I followed the [tutorial](https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html) for connecting controls to you AudioProcesssValueTreeState, but they always end up being a pointer to float?

Let’s say I wanna read a combobox and made the parameter an int:

`std::make_unique<AudioParameterInt>`

then

`AudioProcessorValueTreeState::getRawParameterValue()`

gives me the float pointer. Is this the intended way? I don’t feel well comparing float values, why I chose `int` in the first place (although they seem to turn out “exact” after all)

---

<div class="post-metadata">

**Author:** ![mikej](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mikej](https://forum.juce.com/u/mikej)\
**Post date:** [April 6, 2019, 6:47pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/2 "2019-04-06T18:47:30Z")

</div>

Yeah as far as i know that’s just a quirk. I feel like they should have made some more functions to get as different types but you can just cast from float to whatever type you want. It’s a bit silly because eg. It starts as a int, you get as a float, then you cast back to int. But it works. As far as I know there’s no other way currently.

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [April 6, 2019, 6:51pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/3 "2019-04-06T18:51:13Z")

</div>

Ok cool thanks! Just wanted to know if I’m far off the beaten path 🙂

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 6, 2019, 9:06pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/4 "2019-04-06T21:06:31Z")

</div>

Most hosts will store internally a normalised float, that’s why this is exposed here.  
But with the latest additions, you can use the [RangedAudioParameter](https://docs.juce.com/develop/classRangedAudioParameter.html) classes directly:

```auto
auto* selection = dynamic_cast<AudioParameterInt*> (apvts.getParameter ("foo"));
auto intValue = selection.get();

```

btw. best practice is to have the pointer looked up only once in the constructor and keep it as a member variable. That saves iterating through the parameters, and JUCE doesn’t allow adding and removing parameters after the constructor anyway. I am not sure, how slow the lookup is in practice, I seem to remember, that there is a map in place for fast lookup…

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [April 8, 2019, 6:57pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/5 "2019-04-08T18:57:33Z")

</div>

> [@daniel](#):
>
> normalised float

Following up on @daniel’s comment, but don’t quote me on this, using a float for all parameters means the API only has to deal with one data type, instead of having a more complex API that has different functions for each of the data types. And the beauty of using a value of 0.0-1.0 is that it’s super easy to convert to and from… `myValue = (floatValue * myValueRange) + myValueBase` and `floatValue = (myValue - myValueBase) / myValueRange`. I think I wrote those correctly… lol…

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 8, 2019, 7:07pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/6 "2019-04-08T19:07:45Z")

</div>

you did, but here’s the commercial block: [jmap](https://docs.juce.com/develop/group __juce__ core-maths.html#ga5b7171b191704c949f942076d4d2a82c) for the lazy:

```auto
myValue = jmap (value, minValue, maxValue);
// or
myValue = jmap (value, sourceMinValue, sourceMaxValue, targetMinValue, targetMaxValue);

```

🙂

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [April 8, 2019, 7:20pm UTC](https://forum.juce.com/t/why-are-all-audio-parameters-float/32718/7 "2019-04-08T19:20:00Z")

</div>

@daniel… doh! how do I keep forgetting that… _…heads off to edit a bunch of code…_
