Re: Rate Conversion

From: John Lazzaro (lazzaro@CS.Berkeley.EDU)
Date: Fri Mar 31 2000 - 22:15:45 EST


> This would require that I change the rate of the envelope
> signal from the k-rate to an i-rate.

I'm assuming what you mean by this is that you want to use
one of these core opcodes:

kline, aline, kexpon, aexpon

to generate your envelope, and they all take i-rate arguments
for their x and dur values, correct?

If so, I'd suggest something like this:

ksig rflag, yactive, yout;

// if block handles release
// else block handles normal activity

if (released || rflag)
{
   if (!rflag)
    {
      rflag = 1;
      extend(1.25);
    }
   yout = yactive*kline(1, 1.25,0);
}
else
{
   yactive = 0.75 + kline(-0.75,2,0);
   yout = yactive;
}

output(yout*oscil(sintable,100));

               
What's going on here is this: while the note is active,
the "else" block runs each k-pass. The envelope yout
starts at 0, then rampls to 0.75 over 2 seconds, and
then stays there indefinitely.

Once the note is over, the released flag is set, and
the if statement executes for the first time. In its
first pass it extends the note, and sets rflag (to
make sure note only extends once, and not over and
over). Then, over the next 1.25 seconds, it computes
a release ramp, scaled by the last yactive value.

Finally, yout gets used on every a-pass as the envelope,
scaling an oscil() waveform that gets sent to output().

I didn't actually test this code, so there may be a typo,
but I'm pretty sure the logic is right. One subtle point,
note that when the kline/aline/kexpon/aexpon opcodes are
"over" they return 0 for subsequent calls -- this is why
the kline() in the else block goes from -0.75 to 0, so
that there isn't a discontinuity at the end of the
waveform.

                                                        --jl



This archive was generated by hypermail 2b29 : Mon Jan 28 2002 - 12:03:53 EST