Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

181 lines
7.1KB

  1. (provide 'snd-v.scm)
  2. (if (provided? 'snd)
  3. (require snd-ws.scm)
  4. (require sndlib-ws.scm))
  5. (define default-index-env (float-vector 0 1 25 .4 75 .6 100 0))
  6. (define default-amp-env (float-vector 0 0 25 1 75 1 100 0))
  7. (define default-gliss-env (float-vector 0 0 100 0))
  8. (definstrument (fm-violin startime dur frequency amplitude
  9. (fm-index 1.0)
  10. amp-env
  11. (periodic-vibrato-rate 5.0)
  12. (random-vibrato-rate 16.0)
  13. (periodic-vibrato-amplitude 0.0025)
  14. (random-vibrato-amplitude 0.005)
  15. (noise-amount 0.0)
  16. (noise-freq 1000.0)
  17. (ind-noise-freq 10.0)
  18. (ind-noise-amount 0.0)
  19. (amp-noise-freq 20.0)
  20. (amp-noise-amount 0.0)
  21. (gliss-env default-gliss-env)
  22. (glissando-amount 0.0)
  23. fm1-env
  24. fm2-env
  25. fm3-env
  26. (fm1-rat 1.0)
  27. (fm2-rat 3.0)
  28. (fm3-rat 4.0)
  29. fm1-index
  30. fm2-index
  31. fm3-index
  32. degree
  33. (distance 1.0)
  34. (reverb-amount 0.01)
  35. (base 1.0))
  36. "(fm-violin startime dur frequency amplitude
  37. (fm-index 1.0) (amp-env '(0 0 25 1 75 1 100 0))
  38. (periodic-vibrato-rate 5.0) (random-vibrato-rate 16.0)
  39. (periodic-vibrato-amplitude 0.0025) (random-vibrato-amplitude 0.005)
  40. (noise-amount 0.0) (noise-freq 1000.0) (ind-noise-freq 10.0)
  41. (ind-noise-amount 0.0) (amp-noise-freq 20.0)
  42. (amp-noise-amount 0.0) (gliss-env '(0 0 100 0))
  43. (glissando-amount 0.0) (fm1-env '(0 1 25 .4 75 .6 100 0))
  44. (fm2-env '(0 1 25 .4 75 .6 100 0)) (fm3-rat 4.0)
  45. (fm3-env '(0 1 25 .4 75 .6 100 0)) (fm1-rat 1.0)
  46. (fm2-rat 3.0) (fm1-index #f) (fm2-index #f)
  47. (fm3-index #f) (degree #f) (distance 1.0)
  48. (reverb-amount 0.01) (base 1.0))
  49. (with-sound () (fm-violin 0 1 440 .1))"
  50. (let ((beg (seconds->samples startime))
  51. (end (seconds->samples (+ startime dur)))
  52. (frq-scl (hz->radians frequency))
  53. (logfreq (log frequency))
  54. (sqrtfreq (sqrt frequency))
  55. (maxdev (* (hz->radians frequency) fm-index)))
  56. (if (>= (* 2 fm1-rat frequency) *clm-srate*) (set! fm1-rat 1.0))
  57. (if (>= (* 2 fm2-rat frequency) *clm-srate*) (set! fm2-rat 1.0))
  58. (if (>= (* 2 fm3-rat frequency) *clm-srate*) (set! fm3-rat 1.0))
  59. (let ((index1 (or fm1-index (min pi (* maxdev (/ 5.0 logfreq)))))
  60. (index2 (or fm2-index (min pi (/ (* maxdev 3.0 (- 8.5 logfreq)) (+ 3.0 (* frequency 0.001))))))
  61. (index3 (or fm3-index (min pi (* maxdev (/ 4.0 sqrtfreq)))))
  62. (easy-case (and (zero? noise-amount)
  63. (equal? fm1-env fm2-env)
  64. (equal? fm1-env fm3-env)
  65. (= fm1-rat (floor fm1-rat))
  66. (= fm2-rat (floor fm2-rat))
  67. (= fm3-rat (floor fm3-rat))
  68. (integer? (rationalize (/ fm2-rat fm1-rat))) ; might be 2=2 but 1=3 or whatever
  69. (integer? (rationalize (/ fm3-rat fm1-rat))))))
  70. (let ((norm (if easy-case 1.0 index1)))
  71. (let ((fmosc1 (if easy-case
  72. (make-polywave (* fm1-rat frequency)
  73. (list (floor fm1-rat) index1
  74. (floor (/ fm2-rat fm1-rat)) index2
  75. (floor (/ fm3-rat fm1-rat)) index3)
  76. mus-chebyshev-second-kind)
  77. (make-oscil (* fm1-rat frequency))))
  78. (indf1 (make-env (or fm1-env default-index-env) norm :duration dur))
  79. (indf2 (or easy-case (make-env (or fm2-env default-index-env) index2 :duration dur)))
  80. (indf3 (or easy-case (make-env (or fm3-env default-index-env) index3 :duration dur)))
  81. (frqf (make-env gliss-env (* glissando-amount frq-scl) :duration dur))
  82. (pervib (make-triangle-wave periodic-vibrato-rate (* periodic-vibrato-amplitude frq-scl)))
  83. (ranvib (make-rand-interp random-vibrato-rate (* random-vibrato-amplitude frq-scl)))
  84. (fm-noi (and (not (zero? noise-amount))
  85. (make-rand noise-freq (* pi noise-amount))))
  86. (ind-noi (and (not (zero? ind-noise-amount))
  87. (not (zero? ind-noise-freq))
  88. (make-rand-interp ind-noise-freq ind-noise-amount)))
  89. (amp-noi (and (not (zero? amp-noise-amount))
  90. (not (zero? amp-noise-freq))
  91. (make-rand-interp amp-noise-freq amp-noise-amount)))
  92. (carrier (make-oscil frequency))
  93. (fmosc2 (if (not easy-case) (make-oscil (* fm2-rat frequency))))
  94. (fmosc3 (if (not easy-case) (make-oscil (* fm3-rat frequency))))
  95. (ampf (make-env (or amp-env default-amp-env) :scaler amplitude :base base :duration dur))
  96. (locs (make-locsig (or degree (random 90.0)) distance reverb-amount)))
  97. (if (or (not easy-case)
  98. ind-noi
  99. amp-noi
  100. fm-noi)
  101. (let ((fuzz 0.0)
  102. (vib 0.0)
  103. (anoi 1.0)
  104. (inoi 1.0))
  105. (if easy-case ; no fm-noi here
  106. (do ((i beg (+ i 1)))
  107. ((= i end))
  108. (if amp-noi
  109. (set! anoi (* (env ampf) (+ 1.0 (rand-interp amp-noi))))
  110. (set! anoi (env ampf)))
  111. (if ind-noi
  112. (set! inoi (+ 1.0 (rand-interp ind-noi))))
  113. (set! vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib)))
  114. (locsig locs i (* anoi (oscil carrier (+ vib (* inoi (env indf1) (polywave fmosc1 vib)))))))
  115. (if (or ind-noi amp-noi fm-noi)
  116. (if (not (or ind-noi amp-noi))
  117. (do ((i beg (+ i 1)))
  118. ((= i end))
  119. (let ((fuzz (rand fm-noi))
  120. (vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib))))
  121. (locsig locs i (* (env ampf)
  122. (oscil carrier
  123. (+ vib
  124. (+ (* (env indf1) (oscil fmosc1 (+ (* fm1-rat vib) fuzz)))
  125. (* (env indf2) (oscil fmosc2 (+ (* fm2-rat vib) fuzz)))
  126. (* (env indf3) (oscil fmosc3 (+ (* fm3-rat vib) fuzz))))))))))
  127. (do ((i beg (+ i 1)))
  128. ((= i end))
  129. (if fm-noi (set! fuzz (rand fm-noi)))
  130. (if amp-noi
  131. (set! anoi (* (env ampf) (+ 1.0 (rand-interp amp-noi))))
  132. (set! anoi (env ampf)))
  133. (if ind-noi (set! inoi (+ 1.0 (rand-interp ind-noi))))
  134. (set! vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib)))
  135. (locsig locs i (* anoi (oscil carrier
  136. (+ vib
  137. (* inoi
  138. (+ (* (env indf1) (oscil fmosc1 (+ (* fm1-rat vib) fuzz)))
  139. (* (env indf2) (oscil fmosc2 (+ (* fm2-rat vib) fuzz)))
  140. (* (env indf3) (oscil fmosc3 (+ (* fm3-rat vib) fuzz)))))))))))
  141. (do ((i beg (+ i 1)))
  142. ((= i end))
  143. (let ((vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib))))
  144. (locsig locs i (* (env ampf)
  145. (oscil carrier (+ vib
  146. (+ (* (env indf1) (oscil fmosc1 (* fm1-rat vib)))
  147. (* (env indf2) (oscil fmosc2 (* fm2-rat vib)))
  148. (* (env indf3) (oscil fmosc3 (* fm3-rat vib)))))))))))))
  149. (if (= (mus-scaler frqf) 0.0)
  150. (do ((i beg (+ i 1)))
  151. ((= i end))
  152. (let ((vib (+ (triangle-wave pervib) (rand-interp ranvib))))
  153. (locsig locs i (* (env ampf)
  154. (oscil carrier (+ vib (* (env indf1)
  155. (polywave fmosc1 vib))))))))
  156. (do ((i beg (+ i 1)))
  157. ((= i end))
  158. (let ((vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib))))
  159. (locsig locs i (* (env ampf)
  160. (oscil carrier (+ vib (* (env indf1)
  161. (polywave fmosc1 vib)))))))))))))))
  162. ;; (with-sound (:statistics #t) (fm-violin 0 10 440 .1 :fm-index 2.0))
  163. ;; (with-sound (:statistics #t) (fm-violin 0 10 440 .1 :noise-amount .01))
  164. ;; (with-sound (:statistics #t) (fm-violin 0 10 440 .1 :ind-noise-amount .01))
  165. ;; (with-sound (:statistics #t) (fm-violin 0 10 440 .1 :fm1-rat 1.002))