fmpiano.lsp Version 1.00 16 May 2005 Author Steven Jones Contact jones57@swbell.net include the word "nyquist" in subject line The contents of this file are released under the terms of the GNU General Public License. See the file LICENSE.txt A vain attempt at piano like instrument using FM. [2]--->| [3]--->|--->[1]---> out [4]--->| The instrument uses three modulators and a carrier. Modulator [2] has a fixed frequency and provides in initial burst of non-harmonic partials. Modulator [3] uses a filtered square wave and provides the body of the tone. Modulator [4] provides the upper harmonics.
function
(fmpiano:voice step gate [:vel][:dt])
A piano like instrument using FM.
step - MIDI step number.
gate - Flonum. The "key down" time. The maximum tones duration is a
function of the step number. Higher notes have shorter decays.
The gate parameter is used to truncated the "natural" decay.
:vel - MIDI velocity. Default 64
:dt - Flonum. Detune ratio, default 1.00
return - Sound.
wrapper
(fmpiano plist gate [:vel][:pos][:arpeg][:comp][:dt])
An FM piano instrument.
plist - List | MIDI step. List of note(s) to be played.
gate - Flonum. The "key down" time. The maximum tones duration is a
function of the step number. Higher notes have shorter decays.
The gate parameter is used to truncated the "natural" decay.
:vel - MIDI velocity. Default 64
:pos - Flonum | sound. Pan position 0 <= pos <=1, default 0.5
:arpeg - Flonum. Arpeggio interval, default 0 seconds.
:comp - Flonum | Bool. Amplitude compensation. See definst.lsp
:dt - Flonum. Detune ratio, default 1.00
return - Sound vector.
;; fmpiano.lsp
;; Version 1.00 16 May 2005
;; Author Steven Jones
;;
;; Contact jones57@swbell.net include the word "nyquist" in subject line
;;
;; The contents of this file are released under the terms of the GNU General
;; Public License. See the file LICENSE.txt
;;
;; A vain attempt at piano like instrument using FM.
;;
;; [2]--->|
;; [3]--->|--->[1]---> out
;; [4]--->|
;;
;; The instrument uses three modulators and a carrier. Modulator [2] has a
;; fixed frequency and provides in initial burst of non-harmonic
;; partials. Modulator [3] uses a filtered square wave and provides the body
;; of the tone. Modulator [4] provides the upper harmonics.
;;
(require 'square-08)
(require 'map)
(require 'map-vel3)
(require 'map-vel6)
(require 'definst)
(provide 'fmpiano)
(current-file "fmpiano")
;; Map decay time as function of MIDI step number.
;;
(setf fmpiano:*map-decay-time*
(map:split :y0 20 :y1 10 :y2 0.01
:x0 00 :x1 64 :x2 128
:c1 1 :c2 .1))
;; @doc function fmpiano:voice
;; (fmpiano:voice step gate [:vel][:dt])
;; A piano like instrument using FM.
;;
;; step - MIDI step number.
;; gate - Flonum. The "key down" time. The maximum tones duration is a
;; function of the step number. Higher notes have shorter decays.
;; The gate parameter is used to truncated the "natural" decay.
;; :vel - MIDI velocity. Default 64
;; :dt - Flonum. Detune ratio, default 1.00
;; return - Sound.
;;
(defun fmpiano:voice (step gate &key vel (dt 1))
(let (
hz1 hz2 hz3 hz4 ;Frequencies
a1 a2 a3 a4 ;Amplitudes
ev1 ev2 ev3 ev4 decay pinch ;Envelopes
sig2 sig3 sig4 ;Intermediate signals
vhigh vlow ;velocity scale factors (linear)
)
(setf vel (or vel 64))
(setf vhigh (db-to-linear (send map:*vel6* :get vel)))
(setf vlow (db-to-linear (send map:*vel3* :get vel)))
(setf hz1 (* dt (step-to-hz step))
hz2 74.13 ;Fixed
hz3 (* hz1 0.995)
hz4 (* hz1 20.03)
)
(setf a1 vhigh
a2 (* 0.050 vhigh)
a3 (* 4.000 vhigh)
a4 (* 1.260 vlow)
)
(setf decay (send fmpiano:*map-decay-time* :get step))
(setf pinch 0.25)
(setf ev1 (mult (cond ((> step 64)
(mult (percussion decay)(percussion decay)))
(t (percussion decay)))
(asd 0 gate pinch)))
(setf ev2 (percussion 0.50))
(setf ev3 ev1)
(setf ev4 ev1)
(setf sig2
(mult (osc (hz-to-step hz2) decay) ev2))
(setf sig3
(lowpass2
(mult (osc (hz-to-step hz3) decay *square-08*) ev3)
1000))
(setf sig4
(lowpass2
(mult (osc (hz-to-step hz4) decay) ev4)
1000))
(mult (fmosc (hz-to-step hz1)
(sum (scale (* hz1 a2) sig2)
(scale (* hz1 a3) sig3)
(scale (* hz1 a4) sig4)
))
(scale a1 ev1))
))
;; @doc wrapper fmpiano
;; (fmpiano plist gate [:vel][:pos][:arpeg][:comp][:dt])
;; An FM piano instrument.
;;
;; plist - List | MIDI step. List of note(s) to be played.
;; gate - Flonum. The "key down" time. The maximum tones duration is a
;; function of the step number. Higher notes have shorter decays.
;; The gate parameter is used to truncated the "natural" decay.
;; :vel - MIDI velocity. Default 64
;; :pos - Flonum | sound. Pan position 0 <= pos <=1, default 0.5
;; :arpeg - Flonum. Arpeggio interval, default 0 seconds.
;; :comp - Flonum | Bool. Amplitude compensation. See definst.lsp
;; :dt - Flonum. Detune ratio, default 1.00
;; return - Sound vector.
;;
(defwrapper fmpiano #'fmpiano:voice)