White noise waveform is too loud

Hi! I have created this white noise waveform:

initialise ([] (float x) { return juce::jmap(rand(), -1, 1); });

However it’s way too loud.

Trying to lowering the amplitude like this:

initialise ([] (float x) { return juce::jmap(rand(), -0.5, 0.5); }); 

Gives me this error:

No matching function for call to 'jmap'

What am I doing wrong?

jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)

These three values must have the same type:

  • correct: jmap(1.0, 0.2, 0.3)
  • wrong: jmap(1, 0.2f, 0.3)

BTW, it seems that you may misunderstand the function jmap (what is the value generated by rand()? Is it an integer?). Maybe you should check the documentation again. You may also consider std::uniform_real_distribution.

Instead of rand() use juce::Random. The nextFloat() function returns a value between 0 and 1, so you’d do random.nextFloat() * 2.0f - 1.0f to get a value between -1 and 1.

Thanks for the help. Working now. Like this:

initialise ([] (float x) { return juce::Random::getSystemRandom().nextFloat() * 2 - 1; });