René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Shaping the envelope of an instrument

With a gen function

The following template shows how the shape the envelope of an instrument. The parameter p6 identifies the function table of the envelope shape; p7 is the function table of the tone to be shaped.
Good candidates to shape the envelope are f5 and f7.
sr = 44100
kr   = 441
ksmps =100
nchnls = 1


instr  1;
ilen     =  p3
iamp     =  p4
ifrq     =  cpspch(p5)
if1      =  p6 ; shape of envelope
if2      =  p7 ; waveform

   aenv   oscili  iamp, 1/ilen, if2
   asig   oscili  aenv, ifrq, if1
          out    asig
endin
f1 0  1024 10   1 2 3 5 8 13 1 2 3 5 8 13              ; fibonacci twice
f2 0  513   5  1 100 1024 100 1 112 1 100 1024 100 1        ; twin peaks

i1    0     2    8000  7.00   1   2     

e
See gong for an example that uses this technique.

With linseg and expon

expon makes it ideal to generate a simple envelope.
  asig = ....
  a_amp_1  linseg 0, 0.01, 1, 1, 1
  a_amp_2  expon 1, 0.3333, 0.5   ; Signal decreases 50% after 0.333 seconds
  a_sig_shaped  =  a_sig * a_amp_1 * a_amp_2