Helping routing between Ndefs

There’s something that eludes me about routing audio between Ndefs.

What I’m trying to do is to accept external input into one Ndef, then route this into another for effects.

The code I’m using is below:

(
Ndef(\mv_in, {
	SoundIn.ar(8) ! 2;
});
Ndef(\mv_reverb, {
	|in|
	var audio = In.ar(in,2);
	NHHall.ar(audio, 5) * 0.25 + audio;
});
Ndef(\mv_reverb) <<>.in Ndef(\mv_in);
)

(
Ndef(\mv_in).play;
Ndef(\mv_reverb).play ;
)

What I’m finding is that I hear the external synth, but without the reverb. So it seems like Ndef(\mv_in) is routing its audio directly to the soundcard, and not via Ndef(\mv_reverb). Can anyone give me a hand?

This statement routes mv_in to the soundcard. If you don’t want the dry signal from this ndef, then don’t .play it.

hjh

Thanks for your reply, but I don’t think that’s it.

If I don’t play Ndef(\mv_in), I don’t hear anything at all. What I want to happen is that its output is routed to Ndef(\mv_reverb), which outputs the sound to the soundcard.

I think my mental model of Ndefs is not right, because I don’t seem to be getting this at all.

Okay, so if I don’t play Ndef(\mv_in), I can still call .scope on it and that shows me it’s processing audio. So the problem is that it’s not routing that audio to Ndef(\mv_reverb) for some reason.

Can anyone else help with this question?

Try

Ndef(\mv_reverb, {
	var in = NamedControl.ar(\in, 0!2);
...

hjh

Thank you, I gave it a try but that did not help. [Later edit: I obviously did it wrong because it does work.] I have tried using Ndef.map() to do the mapping also:

(
Ndef(\mv_in, {
	SoundIn.ar([2,3]);
});
Ndef(\mv_reverb, {
	|moooo|
	var audio = In.ar(moooo,2);
	NHHall.ar(audio, 5) * 0.25 + audio;
});
)

(
Ndef(\mv_reverb).map(\moooo, Ndef(\mv_in));
Ndef(\mv_reverb).play;
)

I really can’t see an error in the code. As far as I can tell, mapping between Ndefs is broken.

It isn’t broken, at least not here:

(
Ndef(\src, {
	var trig = Impulse.kr(4);
	var eg = EnvGen.kr(Env.perc(0.01, 0.1), trig);
	var freq = TExpRand.kr(200, 800, trig);
	(LFTri.ar(freq) * 0.1).dup
});

Ndef(\rvb, {
	var in = NamedControl.ar(\in, 0!2);
	FreeVerb2.ar(in[0], in[1], 0.4, 0.95, 0.2)
}).play;

Ndef(\rvb).set(\in, Ndef(\src));
)

Using your code, both of these work:

(
Ndef(\mv_in, {
	SoundIn.ar([2,3]);
});
Ndef(\mv_reverb, {
	var audio = NamedControl.ar(\audio, 0!2);
	NHHall.ar(audio, 5) * 0.25 + audio;
});
)

(
Ndef(\mv_reverb).set(\audio, Ndef(\mv_in));
Ndef(\mv_reverb).play;
)


// OR:

(
Ndef(\mv_in, {
	SoundIn.ar([2,3]);
});
Ndef(\mv_reverb, { |busin|
	// note that In.ar should not be used with JITLib, use InFeedback instead
	var audio = InFeedback.ar(busin, 2);
	NHHall.ar(audio, 5) * 0.25 + audio;
});
)

(
// and, don't map to a bus-number input
// set it to the bus number directly
Ndef(\mv_reverb).set(\busin, Ndef(\mv_in).bus);
Ndef(\mv_reverb).play;
)

EDIT: Reverted to your SoundIn indices (I had needed to change them for my own testing.)

hjh

Thank you for your persistence in helping me; I’ve finally got this to work.

So reading the help file for InFeedback, I guess I had an order of execution problem?

Anyway, as you say, Ndef and the In UGen don’t mix.

In JITLib, you don’t have control over the order of execution, so InFeedback is certainly preferable over In.

But that wasn’t the only problem.

Your reverb synth declared a control-rate input, and used it in In(Feedback). This means that the input’s value should be a bus number (and it’s completely OK to pass the bus number at control rate, but use it to read an audio bus, no problem).

But your first try, Ndef(\mv_reverb) <<>.in Ndef(\mv_in);, means that in should be an audio-rate input that receives the actual signal, not a bus number.

  1. in was declared as control-rate, but you patched an audio bus to it.
  2. But then, in was used as a bus number, but its value will actually be -1.0 to +1.0 (as an audio signal).

The NamedControl suggestion addresses this by declaring the input at audio rate, and patching it to an audio bus – OK. IMO this is the better way, though it’s largely a matter of taste.

My InFeedback suggestion addresses it by explicitly setting the bus number (Ndef(\mv_in).bus) rather than the Ndef itself (which, in JITLib, always patches the signal).

hjh