«Compander coded with ugens» by olaf

on 06 Jan'16 14:58 in

I am not sure if anybody else is interested in such a thing but i think it is cool be able to look inside the working of compander inside of SuperCollider.

leftchannel=different UGens rightchannel=Compander.ar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(//compander -> amplitude
n=Ndef(\ct,{
	//var sig=SinOsc.ar*(1-LFSaw.ar(1,0,0.5,0.5));
	var sig=SinOsc.ar*(1-LFPulse.ar(1));
	var inputspecs=[
				Spec.add(\clampTime, [0.00001, 10,\exp,0,0.05]);
				Spec.add(\clampTime2, [0, 1,\lin,0,0.05]);
				Spec.add(\relaxTime, [0.00001, 60,\exp,0,1]);
				Spec.add(\compression, [0.01, 1,\lin,0,0.1]);
				Spec.add(\slopeBelow, [0.01, 10,\lin,0,0.1]);
				Spec.add(\slopeAbove, [0.0001, 1,\lin,0,0.25]);
			];
	var t=\thresh.kr(0.75);
	var ct=\clampTime.kr(0.05);
	var rt=\relaxTime.kr(1);
	var slopeBelow= \slopeBelow.kr(1);
	var slopeAbove= \slopeAbove.kr(0.9);

	var a=Amplitude.ar(sig,ct,rt);
	var prevmaxval=a.abs;
	var lg1=pow(prevmaxval / t, slopeBelow - 1);
	var absx = lg1.abs;
	var lg=if((absx < 1e-15),0,if((absx > 1e15),1,lg1));
	var ag=pow(prevmaxval / t, slopeAbove - 1);
	var next_gain=if (prevmaxval < t,lg,ag);
	
	var cp=Compander.ar(sig,sig,t,slopeBelow,slopeAbove,ct,rt);
	Out.ar(0,[sig * next_gain,cp]);
});
n.gui;

)

s.scope(bufsize:2**14)
raw 1035 chars (focus & ctrl+a+c to copy)
reception
comments
rumush user 06 Jan'16 20:41

It will come handy. Cheers :)