Main Page       Index


pgtr.lsp


 pgtr.lsp
 Version 1.00  31 October 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

 A plucked string instrument with clipping and portamento


function

pgtr

 (pgtr  bplst [:dur][:vel][:bright][:detune][:pos][:vib][:vfrq][:vtab][:vdelay][:vattack])

 Clipped plucked string sound with portamento. The sound is composed of two
 basic components; An additive sound with percussive decay and an FM
 generated sound.

 pgtr     - list. Portamento break points of the form
            ((L0 D0 [T0])(L1 D1 [T1])...(Ln Dn [Tn]))   
            See port.lsp

 :dur     - flonum. Maximum duration of tone. By default the duration is
            determined by the sum D0+D1+...+Dn break point durations. 
            The dur argument may be used to set a shorter (but not lengthen) 
            duration. Default: NIL

 :bright  - flonum. The bright argument is used to scale the modulation
            indexes of the FM component. 0 <= bright 127. Default 0

 :detune  - flonum. Set the relative frequency between the FM and additive
            components. Default: 1.00

 :pos     - flonum. The pan position of the result. May either be a
            fixed value or a control signal. Default: 0.5

 :vib     - flonum. Vibrato depth. This is not a true vibrato since the LFO
            signal is only applied to one of the 2 FM modulators.
            0<=vib<=127, Default 8

 :vfrq    - flonum. Vibrato frequency. Default: 7 Hertz

 :vtab    - table. Vibrato wave table. Default: *sine-table*

 :vdelay  - flonum. Vibrato delay time. Default: 0.50 seconds

 :vattack - flonum. Vibrato attack time. Default 0.50 seconds

 return   - sound.


View the Sourcecode :



;; pgtr.lsp
;; Version 1.00  31 October 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
;;
;; A plucked string instrument with clipping and portamento
;; 

(require 'wtab)
(require 'port)
(require 'linfn)
(require 'map)
(require 'map-vel6)
(require 'map-vibrato)

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


(deflin2 pgtr:*bright-map* 0 1 128 16)
(setq pgtr:*vmap* map:*vel6*)


(setq pgtr:*wav1* (wtab:make '(( 1 1.0000)( 3 0.5000)( 5 0.2500)))
      pgtr:*wav2* (wtab:make '(( 2 1.0000)( 4 0.5000)( 6 0.2500)))
      pgtr:*wav3* (wtab:make '(( 7 0.1429)( 8 0.1250)( 9 0.1111)
			       (10 0.1000)(11 0.0909)(12 0.8333)
			       (13 0.0770)(14 0.0714)(15 0.0667)
			       (16 0.0625)(17 0.5882)(18 0.0556)
			       (19 0.0526)(20 0.0500)))
      )


(defun pgtr:clipper (snd dur)
  (highpass2
   (let ((epsilon 0.1))
     (mult 
      (s-max snd (mult (percussion dur)(soft-gate dur)))
      (asd 0 (- dur epsilon) epsilon)))
   50))


(defun pgtr:pluck (penv dur)
   (sim (scale 1.0000 (port:fm-cop penv dur :am (percussion dur) :tab pgtr:*wav1*))
	(scale 0.2500 (port:fm-cop penv dur :am (percussion (/ dur 2.0)) :tab pgtr:*wav2*))
	(scale 0.0125 (port:fm-cop penv dur :am (percussion (/ dur 3.0)) :tab pgtr:*wav3*))
      ))


(defun pgtr:fm  (penv dur &key detune bright vfrq vib vdelay vattack vtab sl)
  (let (att dec hold rel		;Carrier
	r1 i1 a1 dec1               	;Modulator 1
	r2 i2 a2 att2 hold2 dec2	;Modulator 2
	vibamp)				;Vibrato
	
    ;; Vibrato
    (setf vfrq    (or vfrq 7.00)
	  ;vibamp  (or vib  0.01)
	  vibamp (map:vibrato 1 (or vib 8))
	  vdelay  (or vdelay 0.50)
	  vattack (or vattack 0.50))

    ;; Carrier
    (setf detune (or detune 1.00)
	  bright-scale (pgtr:*bright-map* (or bright 0))
	  att     0.00
	  dec     0.50
	  rel     0.50
	  sl      (or sl 0.75)		;ADSR sustain level
	  hold    (max 0 (- dur att dec rel)))

    ;; Modulator 1
    (setf r1    (* detune 1.00)
	  i1    (* bright-scale 3.00)
	  dec1  dur)
    
    ;; Modulator 2
    (setf r2    (* detune 3.003)
	  i2    (* bright-scale 8.0)
	  att2  2.00
	  dec2  0.10
	  hold2 (- dur att2 dec2))
    
    (port:fm-cop penv dur 
		 :am (adsr att dec hold rel sl dur )
		 :fm (sum 
		      (port:fm-mop penv dur r1 i1 :am (percussion dec1))
		      (port:fm-mop penv dur r2 i2 
				   :am (asd att2 hold2 dec2)
				   :fm (port:lfo vfrq penv dur 
						 :mi vibamp 
						 :delay vdelay 
						 :attack vattack 
						 :tab vtab))
		      )
		      
		 )))


;; @doc function  pgtr
;; (pgtr  bplst [:dur][:vel][:bright][:detune][:pos][:vib][:vfrq][:vtab][:vdelay][:vattack])
;;
;; Clipped plucked string sound with portamento. The sound is composed of two
;; basic components; An additive sound with percussive decay and an FM
;; generated sound.
;;
;; pgtr     - list. Portamento break points of the form
;;            ((L0 D0 [T0])(L1 D1 [T1])...(Ln Dn [Tn]))   
;;            See port.lsp
;;
;; :dur     - flonum. Maximum duration of tone. By default the duration is
;;            determined by the sum D0+D1+...+Dn break point durations. 
;;            The dur argument may be used to set a shorter (but not lengthen) 
;;            duration. Default: NIL
;;
;; :bright  - flonum. The bright argument is used to scale the modulation
;;            indexes of the FM component. 0 <= bright 127. Default 0
;;
;; :detune  - flonum. Set the relative frequency between the FM and additive
;;            components. Default: 1.00
;;
;; :pos     - flonum. The pan position of the result. May either be a
;;            fixed value or a control signal. Default: 0.5
;;
;; :vib     - flonum. Vibrato depth. This is not a true vibrato since the LFO
;;            signal is only applied to one of the 2 FM modulators.
;;            0<=vib<=127, Default 8
;;
;; :vfrq    - flonum. Vibrato frequency. Default: 7 Hertz
;;
;; :vtab    - table. Vibrato wave table. Default: *sine-table*
;;
;; :vdelay  - flonum. Vibrato delay time. Default: 0.50 seconds
;;
;; :vattack - flonum. Vibrato attack time. Default 0.50 seconds
;;
;; return   - sound.
;;

(defun pgtr (bplst &key dur vel bright detune pos vib vfrq vtab vdelay vattack)
  (let ((pos (or pos 0.5))
	(dur (or dur (port:get-bplist-duration bplst)))
	(penv (port bplst)))
    (scale-db (send pgtr:*vmap* :get (or vel 64))
	      (pan (pgtr:clipper
		    (sum (pgtr:pluck penv dur)
			 (pgtr:fm penv dur :detune detune :bright bright 
				  :vib vib :vfrq vfrq :vtab vtab 
				  :vdelay vdelay :vattack vattack ))
		    dur ) 
		   pos ))))


Main Page       Index