Reducing the volume depending on played frequeny in a Pbind

I guess that’s a quite easy question.

What is the best way to reduce the volume of the frequencies 220 -1760 Hz. Maybe even exponentially? There’s Pif. Is this the way to go?

(
SynthDef('kick', {

    arg freq = 40, dec = 0.1, amp = 0.5;
	var osc, env, sig, clickosc,clickenv ;

	clickosc = {LPF.ar(WhiteNoise.ar(1),1500)};
    clickenv = {Line.ar(1, 0, 0.001)};

	osc = {SinOsc.ar(freq)};
    env = EnvGen.ar(Env.perc(0.001, dec, 1, -4), doneAction:2);

	sig = (osc * env + (clickosc * clickenv)) * amp;
	sig = sig;

    Out.ar(0,
        Pan2.ar(sig, 0)
    )

}).add;
)

Pdef(\bass,
	Pbind(
		\instrument, \kick,
		\dur, Prand([0.25, 1, Prand([0.5, Rest(0.5)]), 1, 1], inf),
		\freq,
		Pwrand(
			[55, 220, 440, 880, 1760],
			[2, 0.3, 0.1, 0.1, 0.1].normalizeSum, inf),
		\amp, 0.4,
		\dec, Pwhite(0.3, 0.5),
	)
);

See Pkey to calculate one value in an event pattern based on a value already stored under a different key.

hjh

1 Like

Thanks, this is working. When using 220 exactly it did not work, most likely because the frequency is 219.9999 or so.

Pdef(\bass,
	Pbind(
		\instrument, \kick,
		\dur, Prand([0.25, 1, Prand([0.5, Rest(0.5)]), 1, 1], inf),
		\freq,
		Pwrand(
			[55, 220, 440, 880, 1760, 3520],
			[2, 0.3, 0.1, 0.1, 0.1].normalizeSum, inf),
		//\amp, 0.4,
		\amp, Pif(Pkey(\freq).round > 110, 0.3, 0.5),
		\pan, Pif(Pkey(\freq).round < 441, 0, Pwhite(-0.6,0.6)),
		\dec, Pwhite(0.3, 0.5),
	)
);