選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. ;;; strad.scm -- Translation CLM -> Snd
  2. ;; Bowed string physical model with stiffness. CLM version adapted
  3. ;; from the Matlab and C versions courtesy of JOS and Stefania Serafin
  4. ;; from code revised on 7/14/01
  5. ;; CLM version by Juan Reyes
  6. ;; SND version by Michael Scholz (based on strad.ins)
  7. ;; revised by Bill to suit the run macro
  8. (provide 'snd-strad.scm)
  9. (if (provided? 'snd)
  10. (require snd-ws.scm)
  11. (require sndlib-ws.scm))
  12. (define make-biquad
  13. (let ((documentation "(make-biquad a0 a1 a2 b1 b2) returns a biquad filter (use with the CLM filter gen)"))
  14. (lambda (a0 a1 a2 b1 b2)
  15. (make-filter 3
  16. (float-vector a0 a1 a2)
  17. (float-vector 0.0 b1 b2)))))
  18. (definstrument (bow beg dur frq amplitude
  19. (bufsize 2205)
  20. (fb 0.2) ;; bow force: between 0.0 and 1.0
  21. (vb 0.05) ;; bow velocity: between 0.0 and 0.8
  22. (bp 0.08) ;; bow position: 0.0=bridge; 0.5=middle of string; 1.0=Nut
  23. (inharm 0.1) ;; inharmonicity: 0.0 harmonic; 1.0 not harmonico
  24. (ampenv '(0 1 15 1 95 1 100 0))
  25. (degree 45) (dist 0.0025) (reverb 0))
  26. (let ((beg (seconds->samples beg))
  27. (len-1 (seconds->samples dur))
  28. (freq frq)
  29. (len (- (/ *clm-srate* frq ) 2))
  30. (twavespeedfactor 5.2)
  31. (stringImpedance 0.55)
  32. (stringImpedancet 1.8))
  33. (let ((lent (/ (- (/ *clm-srate* freq) 2) twavespeedfactor)))
  34. (let ((ampf (make-env :envelope ampenv :scaler amplitude :duration dur))
  35. (end (+ beg len-1))
  36. (loc (make-locsig degree dist reverb))
  37. (vinut (make-float-vector bufsize))
  38. (vinbridge (make-float-vector bufsize))
  39. (vinutt (make-float-vector bufsize))
  40. (vinbridget (make-float-vector bufsize))
  41. (vib 0.0) (vin 0.0) (vibt 0.0) (vint 0.0)
  42. (mus 0.8)
  43. (posl 0) (posr 0)
  44. (poslt 0) (posrt 0)
  45. (indexl 0) (indexr 0)
  46. (indexlt 0) (indexrt 0)
  47. (indexl_1 0) (indexr_1 0)
  48. (indexlt_1 0) (indexrt_1 0)
  49. (indexl_2 0) (indexr_2 0)
  50. (indexlt_2 0) (indexrt_2 0)
  51. (updl 0) (updr 0)
  52. (updlt 0) (updrt 0)
  53. (b0b 0.859210)
  54. (b1b -0.704922)
  55. (b2b 0.022502)
  56. (a1b -0.943639)
  57. (a2b 0.120665)
  58. (b0n 7.0580050e-001)
  59. (b1n -5.3168461e-001)
  60. (b2n 1.4579750e-002)
  61. (a1n -9.9142489e-001)
  62. (a2n 1.8012052e-001)
  63. (b0bt 9.9157155e-001)
  64. (b1bt -8.2342890e-001)
  65. (b2bt 8.8441749e-002)
  66. (a1bt -8.3628218e-001)
  67. (a2bt 9.2866585e-002)
  68. (b0nt 4.3721359e-001)
  69. (b1nt -2.7034968e-001)
  70. (b2nt -5.7147560e-002)
  71. (a1nt -1.2158343e+000)
  72. (a2nt 3.2555068e-001)
  73. (ynbt 0.0)
  74. (ynn 0.0) (ynnt 0.0)
  75. (y1nb 0.0)
  76. (vh 0.0)
  77. (aa 0.0) (bb1 0.0) (cc1 0.0) (delta1 0.0)
  78. (bb2 0.0) (cc2 0.0) (delta2 0.0)
  79. (v 0.0) (v1 0.0) (v2 0.0)
  80. (rhs #f) (lhs #f)
  81. (vtemp 0.0)
  82. (f 0.0)
  83. (stick 0)
  84. ;;(zslope (/ 1 (+ (/ 1 (* 2 stringImpedance)) (/ 1 (* 2 stringImpedancet)))))
  85. (zslope (/ (* 2 stringImpedance stringImpedancet) (+ stringImpedance stringImpedancet)))
  86. (xnn 0.0) (xnb 0.0)
  87. (xnnt 0.0) (xnbt 0.0)
  88. (alphar 0) (alphal 0)
  89. (alphart 0) (alphalt 0)
  90. (del_right (* len bp))
  91. (del_left (* len (- 1 bp)))
  92. (del_leftt (* lent (- 1 bp)))
  93. (del_rightt (* lent bp)))
  94. (let ((samp_rperiod (floor del_right))
  95. (samp_lperiod (floor del_left))
  96. (samp_lperiodt (floor del_leftt))
  97. (samp_rperiodt (floor del_rightt)))
  98. (define bowfilt
  99. (let ((g1 (make-biquad b0b b1b b2b a1b a2b))
  100. (g2 (make-biquad b0n b1n b2n a1n a2n))
  101. (g3 (make-biquad b0bt b1bt b2bt a1bt a2bt))
  102. (g4 (make-biquad b0nt b1nt b2nt a1nt a2nt))
  103. (ya1nb 0.0) (ynba1 0.0) (ynb 0.0))
  104. (lambda (inharmon)
  105. (set! ynb (filter g1 vib))
  106. (set! ynn (filter g2 vin))
  107. (set! ynbt (filter g3 vibt))
  108. (set! ynnt (filter g4 vint))
  109. (set! inharmon (min 0.9999 (max inharmon 0.00001)))
  110. (set! y1nb (- (+ ynba1 (* inharmon ya1nb)) (* inharmon ynb)))
  111. (set! ya1nb y1nb)
  112. (set! ynba1 ynb)
  113. (set! y1nb (- y1nb))
  114. (set! ynn (- ynn))
  115. (set! ynbt (- ynbt)))))
  116. (set! samp_rperiod (min (- bufsize 1) (max samp_rperiod 0)))
  117. (set! samp_lperiod (min (- bufsize 1) (max samp_lperiod 0)))
  118. (set! alphar (* 1.0 (- del_right samp_rperiod)))
  119. (set! alphal (* 1.0 (- del_left samp_lperiod)))
  120. (set! samp_rperiodt (min (- bufsize 1) (max samp_rperiodt 0)))
  121. (set! samp_lperiodt (min (- bufsize 1) (max samp_lperiodt 0)))
  122. (set! alphart (* 1.0 (- del_rightt samp_rperiodt)))
  123. (set! alphalt (* 1.0 (- del_leftt samp_lperiodt)))
  124. (set! posr (modulo (floor (+ end posr)) bufsize))
  125. (set! posl (modulo (floor (+ end posl)) bufsize))
  126. (set! posrt (modulo (floor (+ end posrt)) bufsize))
  127. (set! poslt (modulo (floor (+ end poslt)) bufsize))
  128. (set! indexl (modulo (floor (- (+ beg posl bufsize) samp_lperiod)) bufsize))
  129. (set! indexr (modulo (floor (- (+ beg posr bufsize) samp_rperiod)) bufsize))
  130. (set! indexlt (modulo (floor (- (+ beg poslt bufsize) samp_lperiodt)) bufsize))
  131. (set! indexrt (modulo (floor (- (+ beg posrt bufsize) samp_rperiodt)) bufsize))
  132. (set! indexl_1 (modulo (floor (- (+ beg posl bufsize) samp_lperiod 1)) bufsize))
  133. (set! indexr_1 (modulo (floor (- (+ beg posr bufsize) samp_rperiod 1)) bufsize))
  134. (set! indexlt_1 (modulo (floor (- (+ beg poslt bufsize) samp_lperiodt 1)) bufsize))
  135. (set! indexrt_1 (modulo (floor (- (+ beg posrt bufsize) samp_rperiodt 1)) bufsize))
  136. (set! indexl_2 (modulo (floor (- (+ beg posl bufsize) samp_lperiod 2)) bufsize))
  137. (set! indexr_2 (modulo (floor (- (+ beg posr bufsize) samp_rperiod 2)) bufsize))
  138. (set! indexlt_2 (modulo (floor (- (+ beg poslt bufsize) samp_lperiodt 2)) bufsize))
  139. (set! indexrt_2 (modulo (floor (- (+ beg posrt bufsize) samp_rperiodt 2)) bufsize))
  140. (set! updl (modulo (floor (+ beg posl bufsize)) bufsize))
  141. (set! updr (modulo (floor (+ beg posr bufsize)) bufsize))
  142. (set! updlt (modulo (floor (+ beg poslt bufsize)) bufsize))
  143. (set! updrt (modulo (floor (+ beg posrt bufsize)) bufsize))
  144. (do ((i beg (+ i 1)))
  145. ((= i end))
  146. (set! vib (- (/ (* (- alphal 1)
  147. (+ (* (vinbridge indexl_2) (- alphal 2))
  148. (* (vinbridge indexl) alphal)))
  149. 2)
  150. (* (vinbridge indexl_1) alphal (- alphal 2))))
  151. (set! vin (- (/ (* (- alphar 1)
  152. (+ (* (vinut indexr_2) (- alphar 2))
  153. (* (vinut indexr) alphar)))
  154. 2)
  155. (* (vinut indexr_1) alphar (- alphar 2))))
  156. (set! vibt (- (/ (* (- alphalt 1)
  157. (+ (* (vinbridget indexlt_2) (- alphalt 2))
  158. (* (vinbridget indexlt) alphalt)))
  159. 2)
  160. (* (vinbridget indexlt_1) alphalt (- alphalt 2))))
  161. (set! vint (- (/ (* (- alphart 1)
  162. (+ (* (vinutt indexrt_2) (- alphart 2))
  163. (* (vinutt indexrt) alphart)))
  164. 2)
  165. (* (vinutt indexrt_1) alphart (- alphart 2))))
  166. (bowfilt inharm)
  167. (set! vh (+ ynn y1nb ynnt ynbt))
  168. (set! aa zslope)
  169. (set! bb1 (- (+ (* 0.2 zslope) (* 0.3 fb)) (* zslope vb) (* zslope vh)))
  170. (set! cc1 (- (+ (* 0.06 fb) (* zslope vh vb)) (* 0.2 zslope vh) (* 0.3 vb fb)))
  171. (set! delta1 (- (* bb1 bb1) (* 4 aa cc1)))
  172. (set! bb2 (- (* -0.2 zslope) (* 0.3 fb) (* zslope vb) (* zslope vh)))
  173. (set! cc2 (+ (* 0.06 fb)
  174. (* zslope vh vb)
  175. (* 0.2 zslope vh)
  176. (* 0.3 vb fb)
  177. (* 0.1 fb)))
  178. (set! delta2 (- (* bb2 bb2) (* 4 aa cc2)))
  179. (if (or (= vb 0) (= fb 0))
  180. (set! v vh)
  181. (begin
  182. (if (= vh vb)
  183. (begin
  184. (set! v vb)
  185. (set! stick 1))
  186. (begin
  187. (if (> vh vb)
  188. (begin
  189. (set! lhs #f)
  190. (set! rhs #t))
  191. (begin
  192. (set! rhs #f)
  193. (set! lhs #t)))
  194. (if rhs
  195. (if (< delta1 0)
  196. (begin
  197. (set! v vb)
  198. (set! stick 1))
  199. (if (= stick 1)
  200. (begin
  201. (set! vtemp vb)
  202. (set! f (* 2 zslope (- vtemp vh)))
  203. (if (>= f (- (* mus fb)))
  204. (set! v vtemp)
  205. (begin
  206. (set! v1 (/ (- (sqrt delta1) bb1) (* 2 aa)))
  207. (set! v2 (/ (- (+ bb1 (sqrt delta1))) (* 2 aa)))
  208. (set! v (min v1 v2))
  209. (set! stick 0))))
  210. (begin
  211. (set! v1 (/ (- (sqrt delta1) bb1) (* 2 aa)))
  212. (set! v2 (/ (- (+ bb1 (sqrt delta1))) (* 2 aa)))
  213. (set! v (min v1 v2))
  214. (set! stick 0))))
  215. (when lhs
  216. (if (< delta2 0)
  217. (begin
  218. (set! v vb)
  219. (set! stick 1))
  220. (if (= stick 1)
  221. (begin
  222. (set! vtemp vb)
  223. (set! f (* zslope (- vtemp vh)))
  224. (if (and (<= f (* mus fb)) (> f 0))
  225. (set! v vtemp)
  226. (begin
  227. (set! v1 (/ (- (+ bb2 (sqrt delta2))) (* 2 aa)))
  228. (set! v2 (/ (- (sqrt delta2) bb2) (* 2 aa)))
  229. (set! vtemp (min v1 v2))
  230. (set! stick 0)
  231. (if (> vtemp vb)
  232. (begin
  233. (set! v vb)
  234. (set! stick 1))
  235. (begin
  236. (set! v vtemp)
  237. (set! f (* zslope (- v vh) )))))))
  238. (begin
  239. (set! v1 (/ (- (+ bb2 (sqrt delta2))) (* 2 aa)))
  240. (set! v2 (/ (- (sqrt delta2) bb2) (* 2 aa)))
  241. (set! v (min v1 v2))
  242. (set! stick 0))))
  243. (if (> v vb)
  244. (begin
  245. (set! v vb)
  246. (set! stick 1)))))))
  247. (set! f (* zslope (- v vh)))
  248. (set! xnn (+ y1nb (/ f (* 2 stringImpedance))))
  249. (set! xnb (+ ynn (/ f (* 2 stringImpedance))))))
  250. (set! f (* zslope (- v vh)))
  251. (set! xnnt (+ ynbt (/ f (* 2 stringImpedancet))))
  252. (set! xnbt (+ ynnt (/ f (* 2 stringImpedancet))))
  253. (set! (vinbridge updl) xnb)
  254. (set! (vinut updr) xnn)
  255. (set! (vinbridget updlt) xnbt)
  256. (set! (vinutt updrt) xnnt)
  257. (set! indexl (+ indexl 1)) (if (>= indexl bufsize) (set! indexl 0))
  258. (set! indexr (+ indexr 1)) (if (>= indexr bufsize) (set! indexr 0))
  259. (set! indexlt (+ indexlt 1)) (if (>= indexlt bufsize) (set! indexlt 0))
  260. (set! indexrt (+ indexrt 1)) (if (>= indexrt bufsize) (set! indexrt 0))
  261. (set! indexl_1 (+ indexl_1 1)) (if (>= indexl_1 bufsize) (set! indexl_1 0))
  262. (set! indexr_1 (+ indexr_1 1)) (if (>= indexr_1 bufsize) (set! indexr_1 0))
  263. (set! indexlt_1 (+ indexlt_1 1)) (if (>= indexlt_1 bufsize) (set! indexlt_1 0))
  264. (set! indexrt_1 (+ indexrt_1 1)) (if (>= indexrt_1 bufsize) (set! indexrt_1 0))
  265. (set! indexl_2 (+ indexl_2 1)) (if (>= indexl_2 bufsize) (set! indexl_2 0))
  266. (set! indexr_2 (+ indexr_2 1)) (if (>= indexr_2 bufsize) (set! indexr_2 0))
  267. (set! indexlt_2 (+ indexlt_2 1)) (if (>= indexlt_2 bufsize) (set! indexlt_2 0))
  268. (set! indexrt_2 (+ indexrt_2 1)) (if (>= indexrt_2 bufsize) (set! indexrt_2 0))
  269. (set! updl (+ updl 1)) (if (>= updl bufsize) (set! updl 0))
  270. (set! updr (+ updr 1)) (if (>= updr bufsize) (set! updr 0))
  271. (set! updlt (+ updlt 1)) (if (>= updlt bufsize) (set! updlt 0))
  272. (set! updrt (+ updrt 1)) (if (>= updrt bufsize) (set! updrt 0))
  273. (locsig loc i (* xnb (env ampf)))
  274. (set! lhs #f)
  275. (set! rhs #f)))))))
  276. ;(with-sound (:channels 2) (bow 0 3 400 0.5 :vb 0.15 :fb 0.1 :inharm 0.25))
  277. ;(with-sound (:channels 2) (bow 0 2 440 0.5 :fb 0.25))
  278. ;(with-sound (:channels 2) (bow 0 4 600 0.8))
  279. ;(with-sound (:channels 2) (bow 0 6 147 2 :fb 0.035 :vb 0.1))
  280. ;(with-sound (:channels 2) (bow 0 3 1100 0.5 :vb 0.45 :fb 0.9 :inharm 0.3))
  281. ;(with-sound (:channels 2) (bow 0 3 1500 0.5 :vb 0.25 :fb 0.9 :inharm 0.3))
  282. ;(with-sound (:channels 2) (bow 0 3 1525 0.5 :vb 0.25 :fb 0.9 :inharm 0.3))
  283. ;(with-sound (:channels 2 :reverb jc-reverb) (bow 0 1 400 0.5 :reverb 0.0051))
  284. ;
  285. ;(with-sound (:channels 2 :reverb jc-reverb)
  286. ; (bow 0 3 366 0.5 :degree 0)
  287. ; (bow 0 3 422 0.5 :degree 90)
  288. ; (bow 4 6 147 2 :fb 0.035 :vb 0.1 :reverb 0.051))
  289. ;; strad.scm ends here