Main Page       Index


fhrn.lsp


 fhrn.lsp
 Version 1.00 	29 April 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

 An FM French Horn instrument.


function

fhrn:voice

 (fhrn:voice step gate [:vel][:vib][:vfrq][:vdelay][:vrnd][:vsync][:pb][:pbdecay][:dscale]
 An fm French Horn.
 
 step     - MIDI key number.
 gate     - Flonum. Tones duration in seconds.
 :vel     - MIDI velocity. Velocity controls attack time and brightness. 
            Default 64
 :vib     - MIDI CTRL. Vibrato depth, default 0
 :vfrq    - Flonum. Vibrato frequency, default ~7 HZ 
 :vdelay  - Flonum. Vibrato onset delay, default 0 seconds.
 :vrnd    - Bool. If true vibrato frequency is rnadomly altered slightly, 
            Default t
 :vsync   - Bool. If true vibrato phase is 0, otherwise its random. 
            Default nil
 :pb      - Flonum. Pitch bend depth, default 0.300.
 :pbdecay - Flonum. Pitch bend decay time, default 0.070 seconds.
 :dscale  - Flonum. Decay time scale, default 1.00
 return   - Sound.


wrapper

fhrn

 (fhrn plist gate [:vel][:pos][:arpeg][:comp][:vib][:vfrq][:vdelay][:vrnd][:vsync][:pb][:pbdecay][:dscale]
 A polyphonic fm French Horn
 
 plist    - List | MIDI key. The MIDI note(s) to be played.
 gate     - Flonum. Tones duration in seconds.
 :vel     - MIDI velocity. Velocity controls attack time and brightness. 
            Default 64
 :pos     - Sound | Flonum. Pan position, 0 <= pos <= 1, default 0.5
 :arpeg   - Flonum. Arpeggio time, default 0 seconds.
 :comp    - Flonum | Symbol. Amplitude compensation. 
            See definst.lsp
 :vib     - MIDI CTRL. Vibrato depth, default 0
 :vfrq    - Flonum. Vibrato frequency, default ~7 HZ 
 :vdelay  - Flonum. Vibrato onset delay, default 0 seconds.
 :vrnd    - Bool. If true vibrato frequency is rnadomly altered slightly, 
            Default t
 :vsync   - Bool. If true vibrato phase is 0, otherwise its random. 
            Default nil
 :pb      - Flonum. Pitch bend depth, default 0.300.
 :pbdecay - Flonum. Pitch bend decay time, default 0.070 seconds.
 :dscale  - Flonum. Decay time scale, default 1.00
 return   - Sound vector


View the Sourcecode :



;; fhrn.lsp
;; Version 1.00 	29 April 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
;;
;; An FM French Horn instrument.
;;

(require 'map)
(require 'map-vibrato)
(require 'dlfo)
(require 'saw-16)
(require 'xenvelope)
(require 'map)
(require 'definst)
(provide 'fhrn)
(current-file "fhrn")

(setf fhrn:*vel-mi-map* (map:linear 0.50 2.00))
(setf fhrn:*vel-attack-map* (map:linear-knee 4.000 1.0 0.90 0 32 128))


;; @doc function fhrn:voice
;; (fhrn:voice step gate [:vel][:vib][:vfrq][:vdelay][:vrnd][:vsync][:pb][:pbdecay][:dscale]
;; An fm French Horn.
;; 
;; step     - MIDI key number.
;; gate     - Flonum. Tones duration in seconds.
;; :vel     - MIDI velocity. Velocity controls attack time and brightness. 
;;            Default 64
;; :vib     - MIDI CTRL. Vibrato depth, default 0
;; :vfrq    - Flonum. Vibrato frequency, default ~7 HZ 
;; :vdelay  - Flonum. Vibrato onset delay, default 0 seconds.
;; :vrnd    - Bool. If true vibrato frequency is rnadomly altered slightly, 
;;            Default t
;; :vsync   - Bool. If true vibrato phase is 0, otherwise its random. 
;;            Default nil
;; :pb      - Flonum. Pitch bend depth, default 0.300.
;; :pbdecay - Flonum. Pitch bend decay time, default 0.070 seconds.
;; :dscale  - Flonum. Decay time scale, default 1.00
;; return   - Sound.
;;

(defun fhrn:voice (step gate &rest args)
  (let (
	vfrq vib vdelay vsync vrnd 	;vibrato variables
	vel mi attscale     		;Velocity
	hz1 hz2 hz3 hz4 hz5 hz6      	;Frequencies
	attscale dscale			;Envelope
	env1 env2 env3 env4 env5 env6
	op2 op3 op5 penv vibsig pb pbdecay
	modsig
	)
    (setf hz1 (step-to-hz step))
    (setf hz2 (* 1.00152 hz1))
    (setf hz3 (* 0.99848 hz1))
    (setf hz4 (* 3.21000 hz1))
    (setf hz5 (* 2.12000 hz1))
    (setf hz6 (* 7.42000 hz1))


    ;; Vibrato signal 
    (setf vrnd (get-keyword-value ':vrnd args 't))
    (setf vsync (if (get-keyword-value ':vsync args nil) 0 'random))
    (setf vfrq (if vrnd 
		   (about (get-keyword-value ':vfrq args 7) 0.01)
		 (get-keyword-value ':vfrq args 7)))
    (setf vib (send map:*vibrato* :get (get-keyword-value ':vib args 0)))
    (setf vdelay (get-keyword-value ':vdelay args 0))
    (setf vibsig (scale vib (dlfo vfrq gate
				  :delay (* 0.75 vdelay) 
				  :attack (* 0.25 vdelay)
				  :phase vsync)))

    ;; Pitch bend envelope
    (setf pb (get-keyword-value ':pb args 0.300))
    (setf pbdecay (get-keyword-value ':pbdecay args 0.070))
    (setf penv (scale pb (iramp pbdecay)))

    ;; Composite modulation signal
    (setf modsig (sum penv vibsig))

    
    ;; Velocity scales modulation indexes and attack times
    (setf vel (get-keyword-value ':vel args 64))
    (setf mi (send fhrn:*vel-mi-map* :get vel))
    (setf attscale (send fhrn:*vel-attack-map* :get vel))

    ;; User parameter: decay time scale
    (setf dscale (get-keyword-value ':dscale args 1.000))

    ;; Build envelopes
    (setf env1 
	  (xadsr (* attscale 0.160) 0.220 0.000 (* dscale 0.182) 0.86 gate))
    (setf env2 env1)
    (setf env3 env1)
    (setf env4 
	  (sum (s-rest gate)(xasd (* attscale 0.620) 0.124 (* dscale 0.340))))
    (setf env5 
	  (sum (s-rest gate)(xasd (* attscale 0.175) 0.400 (* dscale 0.400))))
    (setf env6 
	  (xadsr (* attscale 0.390) 0.600 0.00 (* dscale 0.50) 0.36 gate))
    
    ;; Render modulation stacks
    ;;
    (setf op2 (mult (lp (fmosc (hz-to-step hz2)
			       (scale hz2 modsig)
			       *saw-16*)
			(scale (* 2 hz2) env2))
		    env2))
			
    (setf op3 (highpass2
	       (mult (fmosc (hz-to-step hz3)
			    (sum 
			     (scale hz3 modsig)
			     (scale (* hz3 1.640)
				    (mult (fmosc (hz-to-step hz4)
						 (scale hz4 modsig))
					  env4))))
		     env3)
	       hz3))

    (setf op5 (highpass2
 	       (mult (fmosc (hz-to-step hz5)
			    (sum        
			     (scale hz5 modsig)
			     (scale (* hz5 3.901)
				    (mult (fmosc (hz-to-step hz6)
						 (scale hz6 modsig))
					  env6))))
		     env5)
	       hz5))

    ;; Final signal
    (mult (fmosc (hz-to-step hz1)
		 (scale hz1 (sum (scale (* mi 2.759) op2)
				 (scale (* 0.500) op3)
				 (scale (* mi 0.166) op5)
				 modsig)))
	  env1)
    ))


;; @doc wrapper fhrn
;; (fhrn plist gate [:vel][:pos][:arpeg][:comp][:vib][:vfrq][:vdelay][:vrnd][:vsync][:pb][:pbdecay][:dscale]
;; A polyphonic fm French Horn
;; 
;; plist    - List | MIDI key. The MIDI note(s) to be played.
;; gate     - Flonum. Tones duration in seconds.
;; :vel     - MIDI velocity. Velocity controls attack time and brightness. 
;;            Default 64
;; :pos     - Sound | Flonum. Pan position, 0 <= pos <= 1, default 0.5
;; :arpeg   - Flonum. Arpeggio time, default 0 seconds.
;; :comp    - Flonum | Symbol. Amplitude compensation. 
;;            See definst.lsp
;; :vib     - MIDI CTRL. Vibrato depth, default 0
;; :vfrq    - Flonum. Vibrato frequency, default ~7 HZ 
;; :vdelay  - Flonum. Vibrato onset delay, default 0 seconds.
;; :vrnd    - Bool. If true vibrato frequency is rnadomly altered slightly, 
;;            Default t
;; :vsync   - Bool. If true vibrato phase is 0, otherwise its random. 
;;            Default nil
;; :pb      - Flonum. Pitch bend depth, default 0.300.
;; :pbdecay - Flonum. Pitch bend decay time, default 0.070 seconds.
;; :dscale  - Flonum. Decay time scale, default 1.00
;; return   - Sound vector
;;		 

(defwrapper fhrn #'fhrn:voice)


Main Page       Index