; ### Eastman Orchestra Library Instrument  d_r_u_m_s ###
define([NEWPAR],22)dnl
ifelse(NCHNLS,2,[define([STEREO_OUT],[ipan	 = p21
[a2 = a1*sqrt(1-ipan)  ; stereo orchestra : right channel output]
[a1 = a1*sqrt(ipan)  ; left channel output]
[outs a1, a2]
])])dnl


; Functions Needed: 100 (sine wave); linear functions (50-53); drumfuncs (31-33)
;    optional: exponential funcs(60-62), and/or functions 55 & 56, which
;     can be used in addition to or in place of the linear control functions

; p fields:
; Attack (p6-8)
; p6 attack time (c. .002-.007)		p7 attack hardness(default = 1. ;range .8-1.5)
; p8 % of attack noise (.33 ord; range c. .2-.45)

; f.m. (p9-11)                            
; p9 modulation index (normal range 1.-2.) p10 c:m ratio (1.4 ord,range 1.1-1.9)
; p11 function for modulating oscilators (32 ord; 100,31,33 also possible)

; p12 brightness (default = 1. ; range .7-1.4)
; p13 = function for "pan" between upper and lower frequencies (52 ord;)
; (51 also common;50 less common)(expfuncs 60-62 can also be used if included
; in the score)
; Tremolo
; p14 % tremolo (c. .08-.15 ord)	p15 tremolo rate(variable -e.g.1. 1. 7.)
; p16 function for tremolo rate change (52 ord)(other linfuncs, or expfuncs if
; included, can also be used)

; Pitch bend (p17-19)
; p17 depth of pitchbend(% of p4 frequency) ( <.08 barely audible,>.15 = gliss)
; p18 func. for pitch bend (any of the linfuncs or, if included, expfuncs)
; p19 time delay before beginning of pitch bend ( % of p3)
; p20 - detune p-field, used almost exclusively with chorusing
; p21 : stereo pan location {for stereo only}

instr drumsinst
;  set defaults:
	p7 = (p7 = 0 ? 1. : p7)      ; attack hardness
	p8 = (p8 = 0 ? .33 : p8)     ; % attack noise
	p9 = (p9 = 0 ? 1.2 : p9)     ; f m modulation index
	p10 = (p10 = 0 ? 1.41 : p10)  ; c : m ratio
	p12 = (p12 = 0 ? 1. : p12)
       p11 = (p11 = 0 ? 32 : p11)
       p12 = (p12 = 0 ? 1. : p12)
       p13 = (p13 = 0 ? 52 : p13)
       p14 = (p14 = 0 ? .001 : p14)
       p16 = (p16 = 0 ? 52 : p16)
       p18 = (p18 = 0 ? 52 : p18)
i1 = (p4>13.01?p4:cpspch(p4))
        ;  --- Detuning  module (mostly for use with "chorus" ) ---
  idetunepf = p20
if idetunepf = 0 goto detunedone ;skip all this if detuning set to 0 in score
       idtcount init 0  ; counter
       idtmult =  (idetunepf > 0 ? 1.05946 : .94387) ;1/2 step freqency ratios
  idetune init 1.  ; detuning multiplier for p4 pitch
        icheck = abs(idetunepf)
        icheck = int(icheck)

   dumbloop:
	      idtcount = idtcount + 1   ; increment counter
	      idtmult = (icheck = 0 ? 1 : idtmult)
	      idetune = idetune * idtmult 
   if idtcount < icheck igoto dumbloop
 ; microtonal detuning:
	idtmult = abs(idetunepf)
	idtmult = frac(idtmult)
	idtmult = idtmult * .05496
	idtmult = (idetunepf > 0 ? idtmult : - idtmult)
	idetune = idetune + idtmult
i1 = i1 * idetune 
detunedone:   ; ---end of detuning module -------
p5 = ((p10+2)/3*p5)
k1 linseg 0,p6,(p7+1)/2,.045-p6,p7*.4,.1*p3,.15,.15*p3,.1,.25*p3,.05,.5*p3-.045,0
k1 = k1*p5
; Tremolo
k2 = p14 * k1
k1 = k1 - k2
k3 oscil p15,1/p3,p16
k3 = k3+(.4*p15)
k2 oscili k2,k3,100
k1 = k1+k2

; Pitch bend
k2 oscil1i p19 * p3,p17*i1,1/p3,p18

; Frequency modulation : 2 modulating waves, one carrier
i2 = p10 * i1				; c:m
a1 oscili p9 * i2, i2+k2,p11		; higher sidebands
k3 expseg 1.,.7*p3,.1,.3*p3,.01
a1 = a1*k3*p12

i3 = .51 * i2				; lower sidebands
a2 oscili p9*i3,i3+k2,p11                               
a2 = a2 * k3 * p12

k3 oscil 1.,1/p3,p13			; "pan" btw lower & higher sidebands
a1 = a1* k3
a2 = (1.-k3)*a2

a1 oscili (1.-(p7*p8))*k1,i1+k2+a1+a2,100

; Attack Noise            
k2 expseg p7*7500,p7*.02,p7*i1,p7*.02,.1*i1,p3-(p7*.04),.01*i1
k2 randh k2,999
a2 oscili p7*p8*k1,i1+k2,100
a1 = a1+a2
