FOLLOWGATE

simple envelope follower, controlling an amplitude gate (in package insts.jg)

FOLLOWGATE extracts the amplitude of an audio input signal and uses it to control an audio signal gate applied to a separate signal. See the FOLLOWER instrument for the more general amplitude-envelope follower.

p-fields:

/* FOLLOWGATE - envelope follower controlling a gate

   FOLLOWGATE uses the amplitude envelope of the modulator to control the
   action of a gate applied to the carrier.  The gate opens when the power
   of the modulator rises above a threshold and closes when the power falls
   below the threshold.  The bottom of the gate can be adjusted (via the
    parameter) so that it sits flush against the "floor" or rides
   above the floor, letting some signal through even when the gate is closed.
   The carrier is supplied as the "left" channel, the modulator as the
   "right" channel.  (See below.)

   p0  = output start time
   p1  = input start time (must be 0 for aux bus -- see below)
   p2  = duration
   p3  = carrier amplitude multiplier
   p4  = modulator amplitude multiplier
   p5  = power gauge window length (in samples; try 100)
   p6  = smoothness -- how much to smooth the power gauge output (0-1; try .8)
   p7  = attack time -- how long it takes the gate to fully open once the
            modulator power rises above the threshold
   p8  = release time -- how long it takes the gate to fully close once the
            modulator power falls below the threshold
   p9  = percent to left channel [optional, default is .5]

   Function table 1 is the overall amplitude envelope.
   Function table 2 is the power threshold (try gen 18).
   Function table 3 is the range (try gen 18).

   NOTES:

     -  The "left" input channel comes from the bus with the lower number;
        the "right" input channel from the bus with the higher number.

     -  Currently in RTcmix it's not possible for an instrument to take
        input from both an "in" bus and an "aux in" bus at the same time.
        So, for example, if you want the modulator to come from a microphone,
        which must enter via an "in" bus, and the carrier to come from a
        WAVETABLE instrument via an "aux" bus, then you must route the
        mic into the MIX instrument as a way to convert it from "in" to
        "aux in".  If you want the carrier to come from a file, then it
        must first go through MIX (or some other instrument) to send it
        into an aux bus.  Since the instrument is usually taking input
        from an aux bus, the input start time for this instrument must be
        zero.  The only exception would be if you're taking the carrier
        and modulator signals from the left and right channels of the same
        sound file.

     -  The envelope follower consists of a power gauge that measures the
        average power of the modulator signal.  The window length (p5) is
        the number of samples to average.  Large values (> 1000) track only
        gross amplitude changes; small values (< 10) track very minute
        changes.  If the power level changes abruptly, as it does especially
        with long windows, you'll hear zipper noise.  Reduce this by
        increasing the smoothness (p6).  This applies a low-pass filter
        to the power gauge signal, smoothing any abrupt changes.
*/
Sample scorefile:
rtsetparams(44100, 2)
load("WAVETABLE")
load("FOLLOWGATE")

source_listen = 0  /* set to 1 to hear carrier and modulator separately */

dur = 20

/* play carrier to bus 0 */
bus_config("WAVETABLE", "aux 0 out")
makegen(2, 10, 1000, 1, .5, .2)
amp = 15000
WAVETABLE(0, dur, amp, freq = 440)
WAVETABLE(0, dur, amp, freq * 1.02)

/* play modulator to bus 1 */
bus_config("WAVETABLE", "aux 1 out")
setline(0,0, 1,1, 19,1, 20,0)
reset(20000)
incr = base_incr = 0.15
notedur = base_incr * 0.3
freq = 1000
for (st = 0; st < dur; st = st + incr) {
   amp = irand(5000, 30000)
   WAVETABLE(st, notedur, amp, freq)
   incr = base_incr * irand(0.5, 2)
}
reset(1000)

/* apply modulator's amp envelope to carrier */
bus_config("FOLLOWGATE", "aux 0-1 in", "out 0-1")
setline(0,0, 1,1, 10,1, 20,0)
caramp = 2.0
modamp = 5.0
winlen = 100      /* number of samples for power gauge to average */
smooth = 0.0      /* how much to smooth the power gauge curve */
attack = 0.002
release = 0.02
pctleft = 0.5
thresh = 0.5
range = 0.005
makegen(2, 18, 100, 0,thresh, 1,thresh)
makegen(3, 18, 1000, 0,range, 1,range)
if (source_listen) {
   bus_config("MIX", "aux 0-1 in", "out 0-1")
   MIX(0, 0, dur, 1, 0, 1)
}
else
   FOLLOWGATE(0, inskip = 0, dur, caramp, modamp, winlen, smooth, attack,
                                                         release, pctleft)