;  #############################################################
;  soundfile ex3-4   :  F.M. Glissando Instrument : Csound Tutorial
;  #############################################################

instr 1
    k1 linen p5,p6,p3,p7   ; amplitude envelope

    ; Glissando control signal :
    i1 = cpspch(p4)        ; 1st pitch
    i2 = cpspch(p10)       ; 2nd pitch
    i3 = p8*i1             ; ratio of mod. freq. to carrier freq.
    p12 = (p12 < .0001 ? .0001 : p12)  ; for notes with no gliss
                                         ; p12 cannot be 0 in expseg below
    kgliss expseg i1,p11,i1,p12,i2,p3-(p11+p12),i2 ; gliss. envelope
    display kgliss,p3            ; let's see how it looks

    ; Scale fm index : the lower the pitch, the higher the index
    k3 = octcps(kgliss)  ; convert cps to oct for scalar
    kscale = (18-k3)*.1  ; index scalar ; c4 = 1., c3=1.1, c5 = .9 etc
    kscale = kscale*kscale ; now c4 =1., c3 = 1.21, c5 = .81 etc
;   display kscale,p3

    ; F.M.
    amod  oscili p9*p8*kgliss, p8*kgliss, 100     ; modulating oscillator
    amod = kscale*amod  ; now scale the fm index
    acar  oscili k1, kgliss+amod, 100   ; carrier oscillator
    out acar
endin

