mxmix.lsp Version 1.00 09 June 2005 Author Steven Jones The contents of this file are released under the terms of the GNU General Public License. See the file LICENSE.txt Provides functions for cross-mixing several source signals as function of control signal. See also xmix.lsp
function
(mxmix:make-table on off [:delta][:a0][:a1][:len]) Create table for use by shape function. ------------- / \ / \ ------ ------- | | | on off len on - Flonum. Time of transition from "off" to "on" as ratio of total length, 0 <= on < off off - Flonum. Time of transition from on to off as ratio of total length, on < off <= 1. :delta - Flonum. Slope of transition time as ratio of total length. 0 <= delta <= 1, default 0 :a0 - Flonum. Amplitude of "off" state, default 0 :a1 - Flonum. Amplitude of "on" state, default 1 :len - Flonum. Total duration of curve, default 2 seconds. return - Sound at control sample rate.
function
(mxmix3 sig1 sig2 sig3 ctrl [:xfade][:signed]) Cross mix between three source signals as function of control signal. sig1 - Sound. Source signal output for ctrl < 33% amplitude. sig2 - Sound. Source signal output for ctrl amplitude in interval 33%,67% sig3 - Sound. Source signal output for ctrl > 67% ctrl - Sound. The instantaneous amplitude of ctrl controls which source signal(s) contribute to the output. Depending on the value of the signed argument, the amplitude of ctrl should be in the interval [-1,+1] or [0,+1]. :xfade - Flonum. Controls transition between source signals. For xfade = 0 the transition is instantaneous. 0 <= xfade <=1, default 0.33 :signed - Boolean. Sets how the control signal, ctrl, is scaled. If ctrl is signed, such as the output of LFO, the scaled argument should be true. Conversely for un-signed control signals, such as from envelope generators, signed should be false. Default t return - Sound. The sample rate of the result is the maximum of sig1, sig2, and sig3.
function
(mxmix4 sig1 sig2 sig3 sig4 ctrl [:xfade][:signed]) Exactly like mxmix3 except selectes between 4 source signals.
;; mxmix.lsp ;; Version 1.00 09 June 2005 ;; Author Steven Jones ;; ;; The contents of this file are released under the terms of the GNU General ;; Public License. See the file LICENSE.txt ;; ;; Provides functions for cross-mixing several source signals as function of ;; control signal. ;; See also xmix.lsp ;; (provide 'mxmix) (current-file "mxmix") ;; @doc function mxmix:make-table ;; (mxmix:make-table on off [:delta][:a0][:a1][:len]) ;; Create table for use by shape function. ;; ;; ;; ------------- ;; / \ ;; / \ ;; ------ ------- ;; ;; | | | ;; on off len ;; ;; ;; on - Flonum. Time of transition from "off" to "on" as ratio of total ;; length, 0 <= on < off ;; off - Flonum. Time of transition from on to off as ratio of total ;; length, on < off <= 1. ;; :delta - Flonum. Slope of transition time as ratio of total length. ;; 0 <= delta <= 1, default 0 ;; :a0 - Flonum. Amplitude of "off" state, default 0 ;; :a1 - Flonum. Amplitude of "on" state, default 1 ;; :len - Flonum. Total duration of curve, default 2 seconds. ;; ;; return - Sound at control sample rate. ;; (defun mxmix:make-table (on off &key (delta 0)(a0 0)(a1 1)(len 2)) (assert (and (numberp on)(numberp off)(numberp delta) (<= 0 on)(< on off)(<= off 1)(<= 0 delta)(<= delta 1)) "Invalid argument to window:make-table") (let (t0 t1 t2 t3 t4 t5) (setf t0 0 t5 len t2 (* on len) t3 (* off len) t1 (- t2 (* delta len)) t4 (+ t3 (* delta len))) (pwl t0 a0 t1 a0 t2 a1 t3 a1 t4 a0 t5 a0 t5))) ;; @doc function mxmix3 ;; (mxmix3 sig1 sig2 sig3 ctrl [:xfade][:signed]) ;; Cross mix between three source signals as function of control signal. ;; ;; sig1 - Sound. Source signal output for ctrl < 33% amplitude. ;; sig2 - Sound. Source signal output for ctrl amplitude in interval 33%,67% ;; sig3 - Sound. Source signal output for ctrl > 67% ;; ctrl - Sound. The instantaneous amplitude of ctrl controls which source ;; signal(s) contribute to the output. Depending on the value of the ;; signed argument, the amplitude of ctrl should be in the interval ;; [-1,+1] or [0,+1]. ;; :xfade - Flonum. Controls transition between source signals. For xfade = 0 ;; the transition is instantaneous. 0 <= xfade <=1, default 0.33 ;; :signed - Boolean. Sets how the control signal, ctrl, is scaled. If ctrl is ;; signed, such as the output of LFO, the scaled argument should be ;; true. Conversely for un-signed control signals, such as from ;; envelope generators, signed should be false. Default t ;; return - Sound. The sample rate of the result is the maximum of sig1, sig2, ;; and sig3. ;; (defun mxmix3 (sig1 sig2 sig3 ctrl &key (xfade 0.33)(signed 't)) (let (tab1 tab2 tab3 origin) (if signed (setf origin 1 tab1 (mxmix:make-table 0.00 0.33 :delta xfade :len 2) tab2 (mxmix:make-table 0.33 0.67 :delta xfade :len 2) tab3 (mxmix:make-table 0.67 1.00 :delta xfade :len 2)) (setf origin 0 tab1 (mxmix:make-table 0.00 0.33 :delta xfade :len 1) tab2 (mxmix:make-table 0.33 0.67 :delta xfade :len 1) tab3 (mxmix:make-table 0.67 1.00 :delta xfade :len 1))) (sum (mult sig1 (shape ctrl tab1 origin)) (mult sig2 (shape ctrl tab2 origin)) (mult sig3 (shape ctrl tab3 origin))))) ;; @doc function mxmix4 ;; (mxmix4 sig1 sig2 sig3 sig4 ctrl [:xfade][:signed]) ;; Exactly like mxmix3 except selectes between 4 source signals. ;; (defun mxmix4 (sig1 sig2 sig3 sig4 ctrl &key (xfade 0.33)(signed 't)) (let (tab1 tab2 tab3 tab4 origin) (if signed (setf origin 1 tab1 (mxmix:make-table 0.00 0.25 :delta xfade :len 2) tab2 (mxmix:make-table 0.25 0.50 :delta xfade :len 2) tab3 (mxmix:make-table 0.50 0.75 :delta xfade :len 2) tab4 (mxmix:make-table 0.75 1.00 :delta xfade :len 2)) (setf origin 0 tab1 (mxmix:make-table 0.00 0.25 :delta xfade :len 1) tab2 (mxmix:make-table 0.25 0.50 :delta xfade :len 1) tab3 (mxmix:make-table 0.50 0.75 :delta xfade :len 1) tab4 (mxmix:make-table 0.75 1.00 :delta xfade :len 1))) (sum (mult sig1 (shape ctrl tab1 origin)) (mult sig2 (shape ctrl tab2 origin)) (mult sig3 (shape ctrl tab3 origin)) (mult sig4 (shape ctrl tab4 origin))))) ; ************************************** DEBUG ************************************* (setq qq (mxmix3 (osc 50 5)(osc 60 5)(osc 70 5) (ramp 5) :xfade 0.33 :signed 'nil ))