5
5
;action "Performing Delay Effect..."
6
;info "Demo effect for Nyquist by Roger Dannenberg.\nThis effect creates a fixed number of echos."
7
;control decay "Decay amount" int "dB" 6 0 24
8
;control delay "Delay time" real "seconds" 0.5 0.0 5.0
9
;control count "Number of echos" int "times" 5 1 30
11
;; Note: this effect will use up memory proportional to
12
;; delay * count, since that many samples must be buffered
13
;; before the first block is freed.
15
(defun delays (s decay delay count)
6
;info "by Roger Dannenberg, modified by David R. Sky\nReleased under terms of the GNU General Public License Version 2 \nDelay type: 'bouncing ball' makes the echoes occur increasingly close\ntogether (faster); 'reverse bouncing ball' makes them occur increasingly far\napart (slower). In either bouncing ball effect, delay time is not time between\nechoes but the * maximum * delay time in bounces."
8
;control delay-type "Delay type" choice "regular,bouncing ball,reverse bouncing ball" 0
9
;control decay "Decay amount [dB; negative value increases volume]" real "" 6 -1 24
10
;control delay "Delay time [seconds]" real "" 0.5 0 5
11
;control shift "Pitch change per echo [semitones; negative value = lower, 0 is off]" real "" 0 -2 2
12
;control count "Number of echoes" int "" 5 1 30
14
; Delay by Roger B. Dannenberg
15
; modified by David R. Sky October 2007
16
; thanks Gale Andrews for polishing suggestions
17
; now includes normalization to avoid clipping
18
; [first and last maximum 500000 samples are checked
19
; to avoid computer crunching];
20
; added negative decay values, which gives delay effect
21
; increasing volume with each delay;
22
; added bouncing ball and reverse bouncing ball delay effects;
23
; and pitch [semitone] change with each echo.
25
; Note by Roger Dannenberg: this effect will use up memory proportional to
26
; delay * count, since that many samples must be buffered
27
; before the first block is freed.
29
; initialize empty error message
33
; check function: returns 1 on error
34
(defun check (arg min max)
35
(if (and (>= arg min) (<= arg max))
39
; checking for erroneous user-input values:
40
(setf error-msg (if (= (check decay -1 24) 0)
43
(format nil "Decay value '~a' outside valid range -1.0 to 24.0 dB.
46
(setf error-msg (if (= (check delay 0 5) 0)
49
(format nil "Delay value '~a' outside valid range 0.0 to 5.0 seconds.
52
(setf error-msg (if (= (check shift -2 2) 0)
55
(format nil "Pitch change value '~a' outside valid range -2.0 to 2.0 semitones.
58
(setf error-msg (if (= (check count 1 30) 0)
61
(format nil "Number of echoes '~a' outside valid range 1 to 30 echoes.
63
; finished error-checking
65
; if error-msg is longer than 0 characters,
66
; prepend opening message
67
(setf error-msg (if (> (length error-msg) 0)
68
(strcat "Error -\n\nYou have input at least one invalid value:
73
((> (length error-msg) 0)
74
(format nil "~a" error-msg))
76
(t ; no input errors, perform delay
78
; convert shift value to a value the Nyquist code understands
79
(setf shift (expt 0.5 (/ shift 12.0)))
81
; for bouncing ball effects, set delay time to delay time/count
82
(setf delay (if (> delay-type 0)
83
(/ delay count) delay))
86
; function to extract maximum first and last 500000 samples of duration
87
; from delay output for normalization
88
(defun dual-extract-abs (start1 stop1 start2 stop2 sound)
90
(extract-abs start1 stop1 (cue sound))
91
(extract-abs start2 stop2 (cue sound))))
94
; actual extract function embedded within normalize function
95
(defun perform-extract (sound)
96
; determine duration of delay output
97
(setf dur (/ (snd-length sound ny:all) *sound-srate*))
98
; set maximum duration of start and end of audio to extract
99
(setf time (min (/ 500000 *sound-srate*)
102
(dual-extract-abs 0 time (- dur time) dur sound))
105
; normalize function:
106
; checks peak level for maximum 1 million samples
107
(defun normalize (sound)
108
(setf x (if (arrayp sound)
109
(max (peak (perform-extract (aref sound 0)) 1000000)
110
(peak (perform-extract (aref sound 1)) 1000000))
111
(peak (perform-extract sound) 1000000)))
112
(scale (/ 0.95 x) sound))
115
; function to stretch audio
116
(defun change (sound shift)
119
(force-srate 44100 (stretch-abs shift (sound (aref sound 0))))
120
(force-srate 44100 (stretch-abs shift (sound (aref sound 1)))))
121
(force-srate 44100 (stretch-abs shift (sound sound)))))
125
((= delay-type 0) ; regular delay
127
(defun delays (s decay delay count shift)
16
128
(if (= count 0) (cue s)
18
(loud decay (at delay (delays s decay delay (- count 1)))))))
19
(stretch-abs 1 (delays s (- 0 decay) delay count))
21
; arch-tag: 9dc830cf-962c-4429-a587-b7607b5040fa
130
(loud decay (at delay (delays (change s shift)
131
decay delay (- count 1) shift))))))
133
(normalize (stretch-abs 1 (delays s (- 0 decay) delay count shift))))
136
((= delay-type 1) ; bouncing ball delay
137
; bouncing ball delay function
138
(defun bounces (s decay delay count shift)
139
(if (= count 0) (cue s)
141
(loud decay (at (mult delay count)
142
(bounces (change s shift) decay delay
143
(- count 1) shift))))))
145
(normalize (stretch-abs 1 (bounces s (- 0 decay) delay count shift))))
148
((= delay-type 2) ; reverse bouncing ball delay
149
; reverse bouncing ball delay function
150
(defun revbounces (s decay delay count revcount shift)
151
(if (= count 0) (cue s)
153
(loud decay (at (mult delay (- revcount count))
154
(revbounces (change s shift) decay delay
155
(- count 1 ) revcount shift))))))
157
(setf revcount (1+ count))
158
(normalize (stretch-abs 1 (revbounces s (- 0 decay) delay count revcount shift))))
159
) ; end cond2, different delay effect choices