Mapping a Line to a Sine

Hi all -

I’d like to take something like Linen.kr - with values from 0 to 1 - and shape it into a sine wave, so that it faded it at the beginning and out at the ending.

I considered that I could apply the line to a sine function - something like Linen.kr.sin - but I was hoping to have a little more control over the curvature. I’m sure I’m forgetting something simple - but I bet someone here knows and I’d appreciate the help.

hey, you could for example create a triangle from a Phasor / Line and then run this trough a sin function with the additional tilt parameter to bend the tri / sine to the left and the right. You could then additionally use blend to mix between tri and sine.

(
var rampToTri = { |phase, tilt|
	phase.linlin(0, 1, tilt.neg, 1 - tilt).bilin(0, tilt.neg, 1 - tilt, 1, 0, 0);
};

{
	var phase, tri, sine;

	phase = Phasor.ar(0, 100 * SampleDur.ir);
	
	tri = rampToTri.(phase, \tilt.ar(0.5)) * 2 - 1;
	sine = sin(tri * 0.5pi);
	
	[tri, sine];
}.plot(0.021);
)

tilt = 0.5
grafik

tilt = 0.8
grafik

tilt = 0.2
grafik

1 Like

handy coversion methods:

bipolar = unipolar * 2 - 1;
unipolar = bipolar * 0.5 + 0.5;
2 Likes

This isn’t quite what I was thinking, thank you though… I’d like to map a single line - from 0 to 1 - so that it rises from 0 to 1, then back to 0 - a full cycle. This code seems to create a shaping function and apply it to a repeating waveform…

Just swap phasor for line and make the sine bipolar ?

you could use pow to adjust the shape:

{
    var pow = [0.5,1,1.5,2,3,4];
    var line = Line.kr(0,pi,1);

    line.sin**pow
}.plot(1)

Sam

2 Likes

Yet another way using Env:

(
{
	[2, 4, 7, 10].collect({arg curve, i;
		Env(
			[0, 0.5, 1],
			[0.5, 0.5],
			curve: [curve, curve.neg],
			).kr(gate: 1, timeScale: 0.5);
	});
}.plot(0.5, bounds: 200 @ 400);