;  #############################################################
;  soundfile exapp2-1  : Double carrier F.M. instrument with formant
;  #############################################################
; phase (frequency) modulation  instrument with 2 carriers; STEREO OUT
;  NORMALLY THIS WOULD BE A MONO INSTRUMENT. THE TWO CARRIER OUTPUTS
; ARE SENT TO THE LEFT AND RIGHT CHANNELS IN THIS EXAMPLE ONLY SO THAT THE
; OUTPUT OF EACH CARRIER CAN BE HEARD INDIVIDUALLY. TO HEAR THE 2 CHANNELS
; (CARRIERS) INDIVIDUALLY, MOVE THE BALANCE POT BACK ON THE CS-115 BACK & 
; FORTH BETWEEN LEFT & RIGHT CHANNEL OUTPUTS
; p-fields :
; p3 Duration ;  p4 Pitch        ;p5 Amplitude   ;p6 Attack Time 
; p7 Decay time  ; p8 atss       ;p9 rise function
; Fm :
; p10  1st carrier freq. (*p4)  ; p11 = 1st mod. freq. (*p4)
; p12  2nd carrier freq. (*p4)  ; p13  2nd mod. freq. (*p4)
; Modulation index: p14 opening index; p15  index after p6; p16 index before p7
; Ampiltude % for 2nd carrier : p17 opening ; p18 after p6 ; p19 before p7
; p20 attack hardness (1. ord)

instr 1
i1 = cpspch(p4)
a1 envlpx p5,p6,p3,p7,p9,p8,.005

; Random frequency deviation ( for attack noise)
i2 = octcps(i1)
i2 = (18-i2) * .1     ; scalar : c4 = 1.,c5 =.9, c3 = 1.1, etc.
k1 expseg .5*p20,p20*p6,.003,p3,.002
k2 expseg 999,p20*p6,15
k1 randi  k1*i1,k2
k1 = i1+k1              ; pitch
; Fm index:
k2 expseg p14,p6,p15,p3-(p6+p7),p16,p7,.5*p7

a2 foscili a1,k1,p12,p13,k2,100      ; 2nd carrier (usually higher frequencies)
a1 foscili a1,k1,p10,p11,k2,100      ; 1st carrier
; envelope for % 2nd carrier
k1 expseg p17,p6,p18,p3-(p6+p7),p19,p7,.5*p19

     ; The next four lines are the normal output
     ; a1 = (k1*k2)+((1-k1)*a1)
     ; a2 reson a1,p21,p22,1           ; formant
     ; a1 balance .5*a2+.5*a1,a1
     ; out a1

  ; The following lines send the output of carrier 1 to the left channel and
  ; the output of carrier two to the right channel, so that they can be heard
  ; separately
a3 reson a1,p21,p22,1        ; formant for carrier 1
a4 reson a2,p21,p22,1        ; same formant for carrier 2
a1 balance .5*a1+.5*a3,a1
a2 balance .5*a2+.5*a4,a2
outs (1-k1)*a1,k1*a2
endin
