home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 February / MAC_easy_02_2010.iso / Software / Multimedia / audacity-macosx-ub-1.3.11.dmg / plug-ins / delay.ny < prev    next >
Encoding:
Audacity Nyquits plug-in  |  2010-01-16  |  4.4 KB  |  133 lines

  1. ;nyquist plug-in
  2. ;version 3
  3. ;type process
  4. ;categories "http://lv2plug.in/ns/lv2core#DelayPlugin"
  5. ;name "Delay..."
  6. ;action "Performing Delay Effect..."
  7. ;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.\nApplying delay can cause clipping (distortion), especially when reducing the\ndecay value and using more echoes. It's normally best to use Effect > Amplify\nto set the peak amplitude to -6 dB before using delay.     
  8.  
  9. ;control delay-type "Delay type" choice "regular,bouncing ball,reverse bouncing ball" 0
  10. ;control decay "Decay amount [dB; negative value increases volume]" real "" 6 -1 24
  11. ;control delay "Delay time [seconds]" real "" 0.5 0 5
  12. ;control shift "Pitch change per echo [semitones; negative value = lower, 0 is off]" real "" 0 -2 2
  13. ;control count "Number of echoes" int "" 5 1 30
  14.  
  15. ; Delay by Roger B. Dannenberg
  16. ; modified by David R. Sky October 2007, 
  17. ; adding negative decay values, which gives delay effect
  18. ; increasing volume with each delay; and adding
  19. ; bouncing ball and reverse bouncing ball delay effects
  20. ; and pitch [semitone] change with each echo.
  21. ; modified by Richard Ash January 2008, removing all 
  22. ; normalization functions. 
  23.  
  24. ; Note by Roger Dannenberg: this effect will use up memory proportional to
  25. ; delay * count, since that many samples must be buffered
  26. ; before the first block is freed.
  27.  
  28. ; initialize empty error message
  29. (setf error-msg "")
  30.  
  31.  
  32. ; check function: returns 1 on error
  33. (defun check (arg min max)
  34. (if (and (>= arg min) (<= arg max))
  35. 0 1))
  36.  
  37.  
  38. ; checking for erroneous user-input values:
  39. (setf error-msg (if (= (check decay -1 24) 0)
  40. error-msg 
  41. (strcat error-msg 
  42. (format nil "Decay value '~a' outside valid range -1.0 to 24.0 dB. 
  43. " decay))))
  44.  
  45. (setf error-msg (if (= (check delay 0 5) 0)
  46. error-msg 
  47. (strcat error-msg 
  48. (format nil "Delay value '~a' outside valid range 0.0 to 5.0 seconds. 
  49. " delay))))
  50.  
  51. (setf error-msg (if (= (check shift -2 2) 0)
  52. error-msg 
  53. (strcat error-msg 
  54. (format nil "Pitch change value '~a' outside valid range -2.0 to 2.0 semitones. 
  55. " shift))))
  56.  
  57. (setf error-msg (if (= (check count 1 30) 0)
  58. error-msg 
  59. (strcat error-msg 
  60. (format nil "Number of echoes '~a' outside valid range 1 to 30 echoes. 
  61. " count))))
  62. ; finished error-checking
  63.  
  64. ; if error-msg is longer than 0 characters,
  65. ; prepend opening message
  66. (setf error-msg (if (> (length error-msg) 0)
  67. (strcat "Error -\n\nYou have input at least one invalid value:
  68. " error-msg)
  69. error-msg))
  70.  
  71. (cond ; 1
  72. ((> (length error-msg) 0)
  73. (format nil "~a" error-msg))
  74.  
  75. (t ; no input errors, perform delay
  76.  
  77. ; convert shift value to a value the Nyquist code understands
  78. (setf shift (expt 0.5 (/ shift 12.0)))
  79.  
  80. ; for bouncing ball effects, set delay time to delay time/count
  81. (setf delay (if (> delay-type 0)
  82. (/ delay count) delay))
  83.  
  84.  
  85.  
  86. ; function to stretch audio 
  87. (defun change (sound shift)
  88. (if (arrayp sound)
  89. (vector
  90. (force-srate 44100 (stretch-abs shift (sound (aref sound 0))))
  91. (force-srate 44100 (stretch-abs shift (sound (aref sound 1)))))
  92. (force-srate 44100 (stretch-abs shift (sound sound)))))
  93.  
  94.  
  95. (cond ; 2
  96. ((= delay-type 0) ; regular delay
  97. ; delay function
  98. (defun delays (s decay delay count shift)
  99.   (if (= count 0) (cue s)
  100.      (sim (cue s)
  101.             (loud decay (at delay (delays (change s shift) 
  102. decay delay (- count 1) shift))))))
  103.  
  104. (stretch-abs 1 (delays s (- 0 decay) delay count shift)))
  105.  
  106.  
  107. ((= delay-type 1) ; bouncing ball delay
  108. ; bouncing ball delay function
  109. (defun bounces (s decay delay count shift)
  110.   (if (= count 0) (cue s)
  111.       (sim (cue s)
  112.                (loud decay (at (mult delay count) 
  113. (bounces (change s shift) decay delay 
  114. (- count 1) shift)))))) 
  115.  
  116. (stretch-abs 1 (bounces s (- 0 decay) delay count shift)))
  117.  
  118.  
  119. ((= delay-type 2) ; reverse bouncing ball delay
  120. ; reverse bouncing ball delay function
  121. (defun revbounces (s decay delay count revcount shift)
  122.   (if (= count 0) (cue s)
  123.       (sim (cue s)
  124.                (loud decay (at (mult delay (- revcount count))
  125. (revbounces (change s shift) decay delay 
  126. (- count 1 ) revcount shift)))))) 
  127.  
  128. (setf revcount (1+ count))
  129. (stretch-abs 1 (revbounces s (- 0 decay) delay count revcount shift)))
  130. ) ; end cond2, different delay effect choices
  131. ) ; end cond1 t
  132. ) ; end cond 1
  133.