Using SynthDef as a \filter for Ndef?

Hello everybody.
I’m tinkering again with Ndefs and it is still difficult.
I want to use a SynthDef as a \filter for the the Ndef. Is this possible?
I documented this very well in the following code, i hope it becomes clear what i want. I am also using a SynthDef as the initial Ndef, now i just want another SynthDef for the effect chaining. This can be theoretically done with \filter → {…}, but I dont know how to apply this for my problem.

Here is the Example Code:

//making a SynthDef
(
//simple Synth
SynthDef(\sins, {
	|freq=440, out = 0, amp=1|
	Out.ar(out,amp*SinOsc.ar(freq!2)*((Saw.kr(1).range(0,1))**10))
}).add;
//simple Reverb
SynthDef(\rev, {
	|amp=0.2, in=0 ,out=0|
	var sig;
	//instead of the In.ar, the in argument of the filter 
	//could also be used? somehow? i dont know...
	sig = In.ar(in,2);
	sig = FreeVerb.ar(sig,0.6);
	Out.ar(out,sig)
}).add;
)
//This is on one way of making it work with synths
a=Synth(\rev,[\in: 10]);
b=Synth(\sins,[\out: 10]);
a.free;b.free;
//now i want this with ndefs
Ndef(\sinn).add(\sins);
Ndef(\sinn).play;
//the next commented line is one way of making it work
//Ndef(\sinn).put(100,\filter -> {arg in; FreeVerb.ar(in,0.6)})

//however I want to make it work with the \rev SynthDef
//it doesn't work yet, but i hope the point gets accross...
Ndef(\sinn).put(100,\filter -> /*something \rev SynthDef*/)

//clear the Ndef
Ndef(\sinn).clear

Thank you very much

Oh well, I think i kind of bypassed this issue by declaring functions instead of synth defs. Like this:

//making a SynthDef
(
//simple Synth
SynthDef(\sins, {
	|freq=440, out = 0, amp=2|
	Out.ar(out,amp*SinOsc.ar(freq!2)*((Saw.kr(1).range(0,1))**10))
}).add;
//simple Reverb
~rev = {|in| FreeVerb.ar(in,0.6);}
)
Ndef(\sinn).add(\sins);
Ndef(\sinn).play;
Ndef(\sinn).put(100,\filter -> ~rev)
//clear the Ndef
Ndef(\sinn).clear
> //simple Reverb
> SynthDef(\rev, {
> 	>amp=0.2, in=0 ,out=0|
> 

if you rewrite your effect definition to use ReplaceOut and only use the ‘out’ bus, you can do…

(
SynthDef(\sins, {
	>freq=440, out = 0, amp=1|
	Out.ar(out,amp*SinOsc.ar(freq!2)*((Saw.kr(1).range(0,1))**10))
}).add;
SynthDef(\rev, {
	>amp=0.2, out=0|
	var sig;
	sig = In.ar(out,2);
	sig = FreeVerb.ar(sig,0.6);
	ReplaceOut.ar(out, sig)
}).add;
)
Ndef(\sinn).add(\sins);
Ndef(\sinn).play;
Ndef(\sinn)[10] = \rev
Ndef(\sinn)[10]= nil
Ndef(\sinn).clear

but yea, → filter + function is a more elegant and practical solution.
_f

#|
fredrikolofsson.com musicalfieldsforever.com

2 Likes