(bind-func my_simple_fm_inst
(lambda ()
(let ((freq 440.0) (newfreq 440.0) ;; frequency
(amp 1.0) (newamp 1.0) ;; amplitude
(a 10.0) (b 0.1) ;; fm params (midi cc 21 & 22)
(attack 100.0) (decay 200.0) (sustain 0.75) (release 200.0)
(gate 0.0) ;; gate (as per analogue synth)
(pitch:i32 0) ;; to help with note off
(glide 0.001:f) ;; frequency glide amount (midi cc 23)
(wet 0.35) ;; amount of delay (midi cc 24)
(adsr (adsr_c)) ;; adsr all in ms (midi cc 25,26,27,28)
(osc1 (osc_mc_c 0.0))
(lfo1 (osc_mc_c 0.0))
(dly (delay_st_c (/ SR 6) (/ SR 4))))
(lambda (chan:i64)
(if (< (fabs (- newfreq freq)) 5.0) ;; portamento
(set! freq newfreq)
(set! freq (+ freq (* glide (- newfreq freq)))))
(if (< (fabs (- newamp amp)) 0.05)
(set! amp newamp)
(set! amp (+ amp (* 0.0001:f (- newamp amp)))))
(dly chan
(* (adsr chan gate attack decay sustain release)
(osc1 chan (* 0.25 amp)
(+ freq
(lfo1 chan
(* a b freq)
(* a freq)))))
wet 0.75)))))