您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

99 行
3.5KB

  1. ;; CLM implementation of Xenakis' Dynamic Stochastic Synthesis as heard in
  2. ;; his GENDY3, S.709, Legende d'Eer, etc.
  3. ;; 12/17/03
  4. ;; revised 01/22/06
  5. ;; Bill Sack wsack@buffalo.edu
  6. ;; revised slightly to accommodate the run macro, Bill 13-Jun-06
  7. (if (provided? 'snd)
  8. (require snd-ws.scm)
  9. (require sndlib-ws.scm))
  10. (require snd-env.scm)
  11. (definstrument
  12. (stochastic start dur
  13. (amp .9) (bits 16) (xmin 1) (xmax 20) (xwig 0) (xstep 1) (ywig 0) (xfb 0)
  14. (init-array '((10 0) (10 1) (10 0) (10 -.7) (10 0) (10 .5)
  15. (10 0) (10 -.3) (10 0) (10 .2) (10 0) (10 -.1))))
  16. ;;some explanation of the parameters:
  17. ;;amp - scales overall amplitude
  18. ;;bits - the resolution of the wave's amplitude dimension
  19. ;;xmin - minimum number of samples between time breakpoints. must be equal to or greater than 1
  20. ;;xmax - maximum number of samples between time breakpoints.
  21. ;;xwig - amplitude applied to random walk function in time dimension
  22. ;;xstep - quantization of freedom in time dimension, in samples. minimum of 1
  23. ;;ywig - amplitude applied to random walk function in amplitude dimension, in
  24. ;; percent of overall possible amplitude
  25. ;;xfb - an attempt at an FIR low-pass filter - the old (n + (x * n-1)) trick,
  26. ;; not really that useful
  27. ;;init-array - initial x and y breakpoints for wave. x values must be
  28. ;; integers and 1 or greater, y values between -1.0 and 1.0
  29. (let* ((beg (seconds->samples start))
  30. (end (+ beg (seconds->samples dur))))
  31. (let ((d-click (make-env (list 0 1 (- end 100) 1 end 0) :duration dur))
  32. ;;make float-vector to hold x,y breakpoints
  33. (xy-array (make-float-vector (* (length init-array) 2)))
  34. (y 0.0)
  35. (dx 0)
  36. (prev-dx 0)
  37. (dy 0.0)
  38. (j 0.0)
  39. (m 0)
  40. (dt 0)
  41. (output 0.0)
  42. (oldy 0.0)
  43. (xdev 0)
  44. (ydev 0)
  45. (b (expt 2 (- bits 1)))
  46. (xy-array-l (* (length init-array) 2)))
  47. ;;fill xy-array with values from init-array
  48. (do ((iy 0 (+ iy 2));;index for reading values from init-array (a 2-dimensional list)
  49. (jy 0 (+ jy 1)));;index for writing to xy-array (a 1-dimensional float-vector)
  50. ((= iy xy-array-l))
  51. (set! (xy-array iy) ((init-array jy) 0))
  52. (set! (xy-array (+ iy 1))
  53. ;;convert signed float y values into signed integers
  54. (floor (* b
  55. ((init-array jy) 1)))))
  56. (do ((i beg (+ i 1)))
  57. ((= i end))
  58. (when (= dx dt);;when current sample is a breakpoint
  59. (set! dx (floor (xy-array (modulo m xy-array-l))))
  60. (set! y (xy-array (+ (modulo m xy-array-l) 1)))
  61. (set! prev-dx (floor (xy-array (modulo (- m 2) xy-array-l))))
  62. (set! dy (- y oldy))
  63. (set! oldy y)
  64. ;;straight uniform distribution for y
  65. (set! ydev (round (mus-random (* .01 b ywig))))
  66. ;;gaussian distribution for x
  67. (set! xdev
  68. (* xstep (round
  69. (* xwig
  70. (sqrt (* -2.0 (log (- 1 (random 1.0))))) ; ??
  71. (cos (random 6.283185307179586))))))
  72. (set! (xy-array (modulo m xy-array-l))
  73. ;;mirror stuff for x
  74. (if (>= (round xmax) (+ dx xdev) (round xmin))
  75. (round (+ (* xfb prev-dx)
  76. (* (- 1 xfb) (+ dx xdev))))
  77. (max (min (round (+ (* xfb prev-dx)
  78. (* (- 1 xfb) (- dx xdev))))
  79. (round xmax))
  80. (round xmin))))
  81. (set! (xy-array (+ (modulo m xy-array-l) 1))
  82. ;;mirror stuff for y
  83. (if (>= b (+ y ydev) (- b))
  84. (+ y ydev)
  85. (max (min (- y ydev) b) (- b))))
  86. (set! m (+ m 2))
  87. (set! dt 0))
  88. (set! dt (+ dt 1))
  89. (set! j (+ j (/ dy dx)));linear interpolation
  90. (set! output (/ j b));normalization -1 to 1
  91. (outa i (* amp output (env d-click)))))))
  92. ;(with-sound (:statistics #t)(stochastic 0 10 :xwig .25 :ywig 10.0))