Main Page       Index


melodica.lsp


 melodica.lsp
 Version 1.00  24 December 2004
 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


function

melodica:voice

 (melodica:voice pitch dur [:vel][:n][:ndb][:attack][:decay][:env])
 A monophonic melodica voice

 pitch   - flonum. MIDI key number.
 dur     - flonum. Duration in seconds.
 vel     - flonum. MIDI velocity controls attack time, high frequency 
           components, number of noise bands. Default 64
 n       - integer. Number of noise bands. If specified, overrides 
           velocity control of noise band count. Noise bands are used
           to add some animation to the sound but are computationally
           hungry.
 ndb     - flonum. Relative mix of noise bands in db, default -3
 attack  - flonum. Attack time in seconds. Normally attack is a function 
           of velocity. Explicitly specified attack times override velocity
           derived attack times. 
 decay   - flonum Decay time in seconds, default 0.25
 env     - sound. If specified sets amplitude envelope directly, 
           attack and decay arguments are ignored. 
 
 return  - sound.


wrapper

melodica

 (melodica plist dur [:vel][:arpeg][:pos][:n][:ndb][:attack][:decay][:env][:lp][:tfrq][:ttab][:tdelay][:tphase][:trem])

 A polyphonic melodica instrument. The simulation consist of two components;
 a bright but static waveform and a "noisy" dynamic waveform.
 The composite sound is low passed filtered and subjected to optional tremolo.

 plist    - list or flonum. The midi note number(s) to be played.
 dur      - flonum. Duration in seconds.
 :vel     - flonum. MIDI velocity. The velocity controls attack time and 
            filter cutoff, default 64
 :arpeg   - flonum. Arpeggio rate, default 0 seconds.
 :pos     - flonum or sound. Sound pan position, default 0.5
 :n       - integer. Number of noise bands. Default 4
 :ndb     - flonum. Noise band amplitude in db, default -3
 :attack  - flonum. Attack time in seconds. If specified overrides velocity 
            derived attack.
 :decay   - flonum. Decay time
 :env     - sound. Optional amplitude envelope. If specified attack and 
            decay arguments are ignored 
 :lp      - flonum. Filter cutoff. If specified overrides velocity derived 
            cutoff
 :tfrq    - flonum. Tremolo frequency in hz, default 1
 :ttab    - table. Tremolo wave table, default *tri-table*
 :tdelay  - flonum. Tremolo delay time, default 0
 :tphase  - flonum. Tremolo phase. Default 0
 :trem    - flonum. Tremolo depth, scaled for MIDI controller range.

 return   - sound vector.


View the Sourcecode :



;; melodica.lsp
;; Version 1.00  24 December 2004
;; 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
;;

(require 'definst)
(require 'wtab)
(require 'map)
(require 'dlfo)
(require 'rmband)

(provide 'melodica)
(current-file "melodica")


(setq melodica:*vel-attack-map*  (map:quad 0.125 0.1))
;;(setq melodica:*vel-hifrq-map*   (map:quad  -32 -9))
(setq melodica:*vel-noise-n-map* (map:quad  3 6))
(setq melodica:*vel-filter-map*  (map:linear 1500 20000))


(setq melodica:*tab-1* (wtab:make   '((1 1.000)
				      (3 0.783)
				      (4 0.450)
				      (5 0.736)
				      (6 0.523)
				      (7 0.014)
				      (8 0.125)
				      (9 0.111)
				      (10 0.10)
				      (12 0.08)
				      )))

;;
;;(setq melodica:*tab-2* (wtab:make '((09 0.558)
;;				    (11 0.250)
;;				    (13 0.125)
;;				    (15 0.060)
;;				    (17 0.030)
;;				    (19 0.015)
;;				    (21 0.007)
;;				    (23 0.003)
;;				    (25 0.001))))
;;

;; Provide chorusing component to melodica.
;; n parallel sine oscillators ring-modulated by band-limited noise.
;;

(definst melodica:noise (n)
  (let ((n (or n 4))
	(bw 10)
	(hz (step-to-hz pitch)))
    (rmband:harmonic pitch dur
		     :n n
		     :bwfn #'(lambda (j) bw)
		     :rffn #'(lambda (j hz) (* (+ (* j 2) 1) hz))
		     :rafn #'(lambda (j) (/ 1.0 (max 1.0 j)))
		     )))


;; @doc function melodica:voice
;; (melodica:voice pitch dur [:vel][:n][:ndb][:attack][:decay][:env])
;; A monophonic melodica voice
;;
;; pitch   - flonum. MIDI key number.
;; dur     - flonum. Duration in seconds.
;; vel     - flonum. MIDI velocity controls attack time, high frequency 
;;           components, number of noise bands. Default 64
;; n       - integer. Number of noise bands. If specified, overrides 
;;           velocity control of noise band count. Noise bands are used
;;           to add some animation to the sound but are computationally
;;           hungry.
;; ndb     - flonum. Relative mix of noise bands in db, default -3
;; attack  - flonum. Attack time in seconds. Normally attack is a function 
;;           of velocity. Explicitly specified attack times override velocity
;;           derived attack times. 
;; decay   - flonum Decay time in seconds, default 0.25
;; env     - sound. If specified sets amplitude envelope directly, 
;;           attack and decay arguments are ignored. 
;; 
;; return  - sound.
;;

(definst melodica:voice (vel n ndb attack decay env)
  (let* ((vel (or vel 64))
	 (attack (or attack (send melodica:*vel-attack-map* :get vel)))
	 (release (or decay 0.25))
	 ;(high-db (send melodica:*vel-hifrq-map* :get vel))
	 (n (truncate (or n (send melodica:*vel-noise-n-map* :get vel))))
	 (ndb (or ndb -3))
	 )
    (mult (sum (osc pitch dur melodica:*tab-1*)
	       ;(scale-db high-db
		;	 (osc pitch dur melodica:*tab-2*))
	       (scale-db ndb (melodica:noise pitch dur :n n)))
	  (or env 
	      (asd attack (max 0 (- dur attack release)) release)))))

(defun melodica:filter (signal cutoff)
  (vector
   (lowpass4 (aref signal 0) cutoff)
   (lowpass4 (aref signal 1) cutoff)))


;; @doc wrapper melodica
;; (melodica plist dur [:vel][:arpeg][:pos][:n][:ndb][:attack][:decay][:env][:lp][:tfrq][:ttab][:tdelay][:tphase][:trem])
;;
;; A polyphonic melodica instrument. The simulation consist of two components;
;; a bright but static waveform and a "noisy" dynamic waveform.
;; The composite sound is low passed filtered and subjected to optional tremolo.
;;
;; plist    - list or flonum. The midi note number(s) to be played.
;; dur      - flonum. Duration in seconds.
;; :vel     - flonum. MIDI velocity. The velocity controls attack time and 
;;            filter cutoff, default 64
;; :arpeg   - flonum. Arpeggio rate, default 0 seconds.
;; :pos     - flonum or sound. Sound pan position, default 0.5
;; :n       - integer. Number of noise bands. Default 4
;; :ndb     - flonum. Noise band amplitude in db, default -3
;; :attack  - flonum. Attack time in seconds. If specified overrides velocity 
;;            derived attack.
;; :decay   - flonum. Decay time
;; :env     - sound. Optional amplitude envelope. If specified attack and 
;;            decay arguments are ignored 
;; :lp      - flonum. Filter cutoff. If specified overrides velocity derived 
;;            cutoff
;; :tfrq    - flonum. Tremolo frequency in hz, default 1
;; :ttab    - table. Tremolo wave table, default *tri-table*
;; :tdelay  - flonum. Tremolo delay time, default 0
;; :tphase  - flonum. Tremolo phase. Default 0
;; :trem    - flonum. Tremolo depth, scaled for MIDI controller range.
;;
;; return   - sound vector.
;;

(defwrapper melodica
  #'melodica:voice
  #'(lambda (signal args)
      (let* ((vel (get-keyword-value ':vel args 64))
	     (cutoff (or (get-keyword-value ':lp    args)
			 (send melodica:*vel-filter-map* :get vel)))
	    (tfrq   (get-keyword-value ':tfrq   args 1.00))
	    (ttab   (get-keyword-value ':ttab   args *tri-table*))
	    (tdelay (get-keyword-value ':tdelay args 0 ))
	    (tphase (get-keyword-value ':tphase args 0 ))
	    (trem   (min (max 0 (/ (get-keyword-value ':trem   args 0) 128.0)) 1))
	    (amp    (- 1 trem)))
	(mult (melodica:filter signal cutoff)
	      (sum 
	       amp
	       (scale trem 
		      (dlfo tfrq dur 
			    :tab ttab 
			    :rho tphase 
			    :delay  (* 0.75 tdelay)
			    :attack (* 0.25 tdelay))))))) )


Main Page       Index