Cannot reliably instantiate a SoundIn.ar synth controllable via Control bus w/ asMap set by MIDI

Hi Folks,

I am currently unable to instantiate a Synth where a parameter is reliably controlled by a Control Bus (set by a MIDIFunc and using asMap) without running the synth with some non-zero amplitude first and then running the asMap line. I am, frankly, stumped, as I used to do this all the time without issue. I am currently on Windows 11 and running SC 3.13. I have tried this on both Windows 11 and MacOS and two different MIDI controllers, I get the same symptoms no matter what.

More specifically: When I run what is below I cannot modulate the amplitude of the radio1 synth with the MIDI controller and it remains silent. However, if I make an instance of the synth first, and set the amplitude to 0.5, the synth will sound and I can then map amplitude to Control Bus and control with MIDI. I would prefer to instantiate the Synth with an amplitude of 0.0, map amplitude to Control Bus, and then control amplitude via MIDI. I used to be able to do this easily and am not sure why I am no longer able to do so. Anyone see any issues below?

// ServerOptions.devices; // all devices

o = Server.default.options;
o.outDevice_("MME : Speakers (Focusrite Usb Audio)");
Server.default.reboot;

/////////
// MIDI setup
MIDIClient.init;

~twistPort = MIDIIn.findPort( "Midi Fighter Twister", "Midi Fighter Twister" );
~twistPort.uid;

MIDIIn.connectAll;

~radio1Vol = Bus.control( s, 1 ).set( 0.0 );

(
SynthDef( \radio, { | amp = 0.0, in = 0, out = 0, trig = 0 |
	var env, signal;

	env = EnvGen.kr( Env.asr( 0.01, amp, 0.05 ), trig, doneAction: 0 );
	signal = SoundIn.ar( in, amp );
	Out.ar( out, Pan2.ar( signal * env ));
}).add;

)

(
// MIDI
a = MIDIFunc.cc({ arg ...msg;
	var value1, value2;
	switch( msg[1],
		0, {
			value1 = msg[0].linlin( 0, 127, 0.0, 1.0 );
			value1.postln;
			~radio1Vol.set(value1);
		}
	)
}, srcID: ~twistPort.uid );
)

~radio1 = Synth( \radio, [ \trig, 1, \in, 0, \out, 0, \amp, ~radio1Vol.asMap ]);

Ah… Missed this at first.

Envelope breakpoints update only at the beginning of the envelope segment. If you start with 0 here, you’d have to retrigger the EnvGen before it can change. Better practice is to have the Env always peak at 1, then multiply the env signal by the amp.

You’re already amp-scaling the SoundIn, so you don’t need to double-amp-scale by putting the amp in here too. (If you do want to scale by amp.squared, then do * amp.squared.)

hjh

Thanks for this, James, your explanation really helps me understand what was wrong about Env.asr sus setting. I made the change you suggested and am able to get the reliable behavior I was looking for. Thank you!