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);
)

grafik

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.

How about this?

(
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) }
	}, '/reply');
}
)

thanks for all the suggestions. I have revisited some old modulation approaches and wanted to generalise them, so instead of having a frequency of 440 hz modulated by a modulation source between 0.1 and about 3.0, I thought you could normalise the range between 0 and 1 and afterwards map the range from 0 and 1 to the desired range of modulation between 1 and something, so the lowest value would be 440 hz. It turns out that the musical gestures ive created by different kinds of modulation are very sensitive to different parameter mappings, so i thought there could be an easy analytic solution. But all your suggestions have been really helpful, thanks alot!