# Normalize output between 0 and 1

hey,

quick and easy question, could someone tell me which values to pick for the mapping to normalise the output in a range between 0 and 1?

``````(
{
var plotScale = 400;
SinOsc.ar(1 * plotScale).lincurve(-1, 1, 0.1, 3.0, 2) * SinOsc.ar(0.5 * plotScale, 1.5pi).linlin(-1, 1, 0.1, 1);
}.plot(0.01);
)
``````

a little tricky!

if the 3rd and 4th args for `lincurve` were 0 and 1 (instead of 0.1 and 0.3) then that first term will be normalized between 0 and 1… and the second term is also normalized between 0 and 1… but because they are correlated their product need not ever reach one (and doesn’t here)

the .lincurve makes the changing of values difficult. when the mapping would be linear then it would be much easier to adjust the values to get the same shape but scaled between 0 and 1 i guess.

It depends a bit what kind of answer you want – are you looking for an analytic solution or something quick and dirty? I would stick the signal into RunningMin/Max and hardcode those values in .linlin, i.e. `sig.linlin(min, max, 0, 1)` or pass the output of those ugens directly. You have to accept a brief amount of garbage at the start if you do this.

I don’t think there’s a closed-form expression for this global maximum, because this boils down to a root-finding problem involving a gnarly combination of exponentials (lincurve has an e^x in it) and trig functions. Although not unsolvable, it’s just a hassle, so I’d just bash it the way @VIRTUALDOG suggests.

``````(
s.waitForBoot {
var length, plotScale, signal, peak, sendPeak, osc, normalisingFatcor;
length = 0.01;
plotScale = 400;
signal = { SinOsc.ar(1 * plotScale).lincurve(-1, 1, 0.1, 3.0, 2)
* SinOsc.ar(0.5 * plotScale, 1.5pi).linlin(-1, 1, 0.1, 1)
};
peak = { Peak.ar(signal.()) };
sendPeak = { SendReply.kr(Impulse.kr(length.reciprocal), values: peak.()) }.play;

s.sync;

osc = OSCFunc({ |msg|
normalisingFatcor = 1 / msg[3];
osc.free;
sendPeak.free;
defer { { signal.() * normalisingFatcor }.plot(length) }