<info>
ESM Csound Library
orc: fmod   sco: fmod1
Allan Schindler  1/97
</info>
<tk_interface>


</tk_interface>
<mono>
; ### Eastman Orchestra Library Instrument  f_m_o_d ###
; ###  simple single carrier, single modulator frequency modulation instrument ###
; p3 Duration  ;p4 Pitch (cps or pch); p5 Amplitude    ;p6 Attack  time
; p7 Decay time ; p8 atss
; frequency modulation  : p9 freq. ratio of modulator to carrier
; f_m index envelope values : p10 beginning; p11 after p6; p12 before p7
; p13  attack hardness   ; p14 = p-fields for chorus detuning
instr 38
p13 = (p13 = 0 ? 1. : p13 )
p4 = (p4>0?p4:(abs(p4))/100)  ; for microtones; -800.050 = quarter tone above c
i1 = (p4<12.99? cpspch(p4):p4)
        ;  --- Detuning  module (mostly for use with "chorus" ) ---
  idetunepf = p14
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 -------
p8 = (p8>9.99? p8 : p8*p5)    ; p8 can be absolute value or * p5
a1 expseg 1,p6,p5,p3-(p6+p7),p8,p7,1  ; amplitude envelope
k1 expseg p10,p6,p11,p3-(p6+p7),p12,p7,.3*p12  ; fm index envelope
;   display a1,p3
;    display k1,p3
; Attack hardness : random frequency deviation
i2 = octcps(i1)
i2 = (18-i2) * .1     ; scalar : c4 = 1.,c5 =.9, c3 = 1.1, etc.
i2 = i2*p13
k2 expseg .5*i2,p13*.9*p6,p13*.003,p3,.002 ; envelope for random amp.
k3 expseg 999,p13*p6,15    ; envelope for random rate
k2 randi  k2*i1,k3      ; random pitch deviations
k2 = i1+k2              ; pitch control signal

a1 foscili a1,k2,1,p9,k1,100

;Standard out statement
out a1
endin
    
</mono>
<stereo>


</stereo>
<quad>


</quad>
<score>
f100 0 1024 10 1.
  i38 0.000 4.000 7.03 10000 0.050 3.800 0.500 1.005 7.000 2.000 0.800 1.500 0
  i38 4.000 4.000 7.03 1500 1.000 0.200 7.000 1.996 0.100 0.400 4.500 0.100 0
  i38 8.000 4.000 7.03 10000 0.080 3.400 0.600 1.400 0.500 1.600 0.500 1.400 0
  i38 12.000 4.000 7.03 10000 0.050 3.600 0.400 2.700 8.000 3.500 0.800 3.400 0
e

</score>

