Amplutide scaling of a signal without knowing its range

Hi!

I would like to scale the amplitude of signals to guarantee that everything as nice as possible withing the [-1,+1] range. Is there a built-in method for this? More exactly, I would like handle properly the derivatives and integrations of a signal.

When I try to make this with .range it does not work…
{[SinOsc.ar(), Slope.ar(SinOsc.ar).range(-1.0,1), Integrator.ar(SinOsc.ar()).range(-1.0,1)]}.plot

There’s Normalizer but it introduces a delay, and it may change the scaling over time. But it does automatically measure the input range.

Scaling a signal does require knowledge of the incoming signal’s range. So the possible approaches would be a/ you determine the input range and calculate scaling factors manually, or b/ write your own incoming min/max measurement (RunningMin and …Max, IIRC), or c/ use a UGen like Normalizer that measures it for you (but you wouldn’t be able to override the scaling behavior this way).

The derivative will depend on the sinewave’s frequency – higher frequency at the same amplitude means the wave is moving faster = higher derivative. So a manual measurement may not be appropriate here.

Do you want to ensure the output signal is -1 to 1, or scale it according to the larger of min/max (which is Peak.ar, I think)? The former might add a DC component; the latter wouldn’t alter DC characteristics.

hjh

1 Like

You can take one of the many so-called sigmoid functions, in SC, e.g., tanh, softclip, or distort. When using them in combination with a pre-amp, e.g. tanh(k * sig), you have already something that’s suited for many use cases. Not quite a limiter, as no look-ahead, but practically feasible. You can also check the saturation I cited here:

2 Likes