SinOsc as control - basic help

Good morning!
I´m a little unsure of the arithmetic required for using SinOsc as a control wave. Let´s say I want a sine wave to oscillate between two specific values. How do I enter those values into the equation? Could anyone explain this for a math dummy?

In other words,
I have a LPF filter, and I want the cutoff frequency to oscillate every second between 400 and 4000 Hz. How do I do that?

LPF.ar(in, SinOsc.kr(1, …?

Hi @askevob,

The easiest way might be something like this:

LPF.ar(in,SinOsc.kr(1).linexp(-1,1,400,4000));

.linexp will map the output of the sine oscillator (which goes between -1 and 1) to 400 to 4000. You’ll notice that the first two arguments are the input range and the next two are the output range. I chose linexp because an exponential curve between frequencies might make more sense, but could also use linlin which is similar but outputs a linear mapping.

1 Like

You could also do

SinOsc.kr(1).range(400, 4000)
1 Like

I see that you’ve already got some answers. As a MD (math dummy) myself, it’s also worthwhile running/testing your code/solution via a plot method to check before blasting yourself.

{SinOsc.kr(1).range(400,4000)}.plot(1);
{SinOsc.kr(1).exprange(400,4000)}.plot(1);
{SinOsc.kr(1).linexp(-1, 1, 400,4000)}.plot(1);

I’d add exprange to your methods which I think will also give the same as linexp.

I often use a different approach:

{arg base=400, amount=0.5; base * (SinOsc.kr(1) * amount + 1) }.plot(1);

base is for example the cutoff frequency of LPF
when amount is 0.5 i know the range will go from base/2 to base*2
if amount is 0, no modulation will occurs
if amount is > 1 there will be negative cutoff frequency

1 Like