~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to plug-ins/delay.ny

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;nyquist plug-in
2
 
;version 1
 
2
;version 3
3
3
;type process
4
4
;name "Delay..."
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
10
 
 
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.
14
 
 
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."
 
7
 
 
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
 
13
 
 
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.
 
24
 
 
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.
 
28
 
 
29
; initialize empty error message
 
30
(setf error-msg "")
 
31
 
 
32
 
 
33
; check function: returns 1 on error
 
34
(defun check (arg min max)
 
35
(if (and (>= arg min) (<= arg max))
 
36
0 1))
 
37
 
 
38
 
 
39
; checking for erroneous user-input values:
 
40
(setf error-msg (if (= (check decay -1 24) 0)
 
41
error-msg 
 
42
(strcat error-msg 
 
43
(format nil "Decay value '~a' outside valid range -1.0 to 24.0 dB. 
 
44
" decay))))
 
45
 
 
46
(setf error-msg (if (= (check delay 0 5) 0)
 
47
error-msg 
 
48
(strcat error-msg 
 
49
(format nil "Delay value '~a' outside valid range 0.0 to 5.0 seconds. 
 
50
" delay))))
 
51
 
 
52
(setf error-msg (if (= (check shift -2 2) 0)
 
53
error-msg 
 
54
(strcat error-msg 
 
55
(format nil "Pitch change value '~a' outside valid range -2.0 to 2.0 semitones. 
 
56
" shift))))
 
57
 
 
58
(setf error-msg (if (= (check count 1 30) 0)
 
59
error-msg 
 
60
(strcat error-msg 
 
61
(format nil "Number of echoes '~a' outside valid range 1 to 30 echoes. 
 
62
" count))))
 
63
; finished error-checking
 
64
 
 
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:
 
69
" error-msg)
 
70
error-msg))
 
71
 
 
72
(cond ; 1
 
73
((> (length error-msg) 0)
 
74
(format nil "~a" error-msg))
 
75
 
 
76
(t ; no input errors, perform delay
 
77
 
 
78
; convert shift value to a value the Nyquist code understands
 
79
(setf shift (expt 0.5 (/ shift 12.0)))
 
80
 
 
81
; for bouncing ball effects, set delay time to delay time/count
 
82
(setf delay (if (> delay-type 0)
 
83
(/ delay count) delay))
 
84
 
 
85
 
 
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)
 
89
(seq
 
90
(extract-abs start1 stop1 (cue sound))
 
91
(extract-abs start2 stop2 (cue sound))))
 
92
 
 
93
 
 
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*)
 
100
(* dur 0.5)))
 
101
;
 
102
(dual-extract-abs 0 time (- dur time) dur sound))
 
103
 
 
104
 
 
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))
 
113
 
 
114
 
 
115
; function to stretch audio 
 
116
(defun change (sound shift)
 
117
(if (arrayp sound)
 
118
(vector
 
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)))))
 
122
 
 
123
 
 
124
(cond ; 2
 
125
((= delay-type 0) ; regular delay
 
126
; delay function
 
127
(defun delays (s decay delay count shift)
16
128
  (if (= count 0) (cue s)
17
129
         (sim (cue s)
18
 
                        (loud decay (at delay (delays s decay delay (- count 1)))))))
19
 
(stretch-abs 1 (delays s (- 0 decay) delay count))
20
 
 
21
 
; arch-tag: 9dc830cf-962c-4429-a587-b7607b5040fa
22
 
 
 
130
                        (loud decay (at delay (delays (change s shift) 
 
131
decay delay (- count 1) shift))))))
 
132
 
 
133
(normalize (stretch-abs 1 (delays s (- 0 decay) delay count shift))))
 
134
 
 
135
 
 
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)
 
140
      (sim (cue s)
 
141
               (loud decay (at (mult delay count) 
 
142
(bounces (change s shift) decay delay 
 
143
(- count 1) shift)))))) 
 
144
 
 
145
(normalize (stretch-abs 1 (bounces s (- 0 decay) delay count shift))))
 
146
 
 
147
 
 
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)
 
152
      (sim (cue s)
 
153
               (loud decay (at (mult delay (- revcount count))
 
154
(revbounces (change s shift) decay delay 
 
155
(- count 1 ) revcount shift)))))) 
 
156
 
 
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
 
160
) ; end cond1 t
 
161
) ; end cond 1