Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. ;;; maxf.scm -- CLM -> Snd/Scheme translation of maxf.ins
  2. ;; Translator/Author: Michael Scholz <scholz-micha@gmx.de>
  3. ;; Last: Tue Mar 25 04:32:23 CET 2003
  4. ;; Version: $Revision: 1.2 $
  5. ;; array -> vector functions added by Bill S, 18-Apr-11
  6. ;; defgenerator changes (Bill 25-Jul-12)
  7. ;; It follows the original header by Juan Reyes.
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;;
  10. ;; maxf.ins
  11. ;; This is Max Mathews (mvm) new filter (2002)
  12. ;; High-Q, 2-Integrator, filter with
  13. ;; Two Poles, and one Zero at the Origin
  14. ;;
  15. ;; It synthesizes equal-tempered frequencies
  16. ;; integer & just scales out of a wide-band input
  17. ;; signal.
  18. ;; Based on Max's code (filter.cpp)
  19. ;;
  20. ;; This heuristic might be called Modal Synthesis.
  21. ;; But as well it can also be additive synthesis in
  22. ;; which a resonator is initialized to generate the
  23. ;; exponentially decaying sinusoids at the desired
  24. ;; phase.
  25. ;;
  26. ;; This implementation written by Juan Reyes with dsp
  27. ;; assistance from JOS.
  28. ;; This version Oct-30, 2002
  29. ;;
  30. ;; Change gain(att) of input file if clipping
  31. ;;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. (provide 'snd-maxf.scm)
  34. (if (provided? 'snd)
  35. (require snd-ws.scm)
  36. (require sndlib-ws.scm))
  37. (define *locsig-type* mus-interp-sinusoidal)
  38. (define (snd-msg frm . args)
  39. ((if (not (string=? "" (getenv "EMACS"))) display snd-print)
  40. (apply format #f frm args)))
  41. (defgenerator mvm sample pp1 pp2 pp3 yy1 yy2 zz1 zz2 out)
  42. (define (mvmfilt b sample0)
  43. (let-set! b 'sample sample0)
  44. (with-let b
  45. (set! yy2 (- (+ (* pp1 yy1)
  46. (* pp2 zz1))
  47. (* pp3 sample)))
  48. (set! zz2 (- zz1 (* pp2 yy2)))
  49. (set! zz1 zz2)
  50. (set! yy1 yy2)
  51. (set! out yy1)))
  52. (define pi2s (/ (* 2.0 pi) *clm-srate*))
  53. (define i2s (/ 2.0 *clm-srate*))
  54. (define tper (/ 1.0 *clm-srate*))
  55. (define (set-coeffs b famp ffreq fdecay)
  56. (let ((centerfreq (* ffreq pi2s)))
  57. (let ((maxdecay (/ (* 2.0 tper) (* centerfreq centerfreq)))
  58. (mindecay (/ tper centerfreq)))
  59. ;; Conditions for JOS constraints
  60. ;; maxdecay: Filter may be unstable
  61. ;; mindecay: Filter may not oscillate
  62. (set! fdecay (max mindecay (min fdecay maxdecay))))
  63. (set! (b 'pp1) (- 1.0 (/ i2s fdecay)))
  64. (set! (b 'pp2) centerfreq)
  65. (set! (b 'pp3) (* (b 'pp2) famp))))
  66. (define (make-array dim1) ; I'm guessing ...
  67. (make-vector (list dim1 3) 0.0))
  68. (define (array-set! arr val i1 i2)
  69. (set! (arr i1 i2) val))
  70. (define array-ref vector-ref)
  71. (define maxfilter
  72. (let ((documentation "(maxfilter file beg (att 1.0) (numf 1) (freqfactor 1.0)
  73. (amplitude 1.0) (amp-env '(0 1 100 1))
  74. (degree (random 90.0)) (distance 1.0) (reverb-amount 0.2))
  75. This is Max Mathews (mvm) new filter (2002) High-Q, 2-Integrator,
  76. filter with Two Poles, and one Zero at the Origin
  77. It synthesizes equal-tempered frequencies integer & just scales
  78. out of a wide-band input signal.
  79. Based on Max's code (filter.cpp)
  80. This heuristic might be called Modal Synthesis. But as well it
  81. can also be additive synthesis in which a resonator is
  82. initialized to generate the exponentially decaying sinusoids at
  83. the desired phase.
  84. (att 1) in-file attenuation
  85. (numf 1) 1 filter
  86. (numf 4) 4 filters
  87. (numf 9) 9 filters
  88. (numf 12) 12 filters
  89. (numf 13) 13 filters"))
  90. (lambda* (file beg
  91. (att 1.0)
  92. (numf 1)
  93. (freqfactor 1.0)
  94. (amplitude 1.0)
  95. (amp-env '(0 1 100 1))
  96. (degree (random 90.0))
  97. (distance 1.0)
  98. (reverb-amount 0.2))
  99. (let ((beg (floor (* beg *clm-srate*)))
  100. (dur (mus-sound-framples file)))
  101. (let ((formfil (make-mvm))
  102. (end (+ beg dur))
  103. (rdA (make-readin :file file :channel 0))
  104. (ampf (make-env :envelope amp-env :scaler amplitude :length dur))
  105. (state-0 (make-array 1))
  106. (state-1 (make-array 12))
  107. (state-2 (make-array 9))
  108. (state-3 (make-array 13))
  109. (state-4 (make-array 4))
  110. (state-5 (make-array 2))
  111. (loc (make-locsig :degree degree
  112. :distance distance
  113. :reverb reverb-amount
  114. :type *locsig-type*)))
  115. (case numf
  116. ((1)
  117. (snd-msg ";;;; State 0 (default): One filter~%")
  118. (array-set! state-0 7.54e-002 0 0)
  119. (array-set! state-0 (* 2000 freqfactor) 0 1)
  120. (array-set! state-0 2.0 0 2))
  121. ;;
  122. ((2)
  123. (snd-msg ";;;; State 5: Two filters~%")
  124. (array-set! state-5 7.54e-003 0 0)
  125. (array-set! state-5 (* 200.0 freqfactor) 0 1)
  126. (array-set! state-5 4.0 0 2)
  127. ;;
  128. (array-set! state-5 7.54e-004 1 0)
  129. (array-set! state-5 (* 800.0 freqfactor) 1 1)
  130. (array-set! state-5 1.0 1 2))
  131. ;;
  132. ((4)
  133. (snd-msg ";;;; State 4: Four filters~%")
  134. (array-set! state-4 7.54e-002 0 0)
  135. (array-set! state-4 (* 1000.0 freqfactor) 0 1)
  136. (array-set! state-4 0.5 0 2)
  137. ;;
  138. (array-set! state-4 3.225e-002 1 0)
  139. (array-set! state-4 (* 400.0 freqfactor) 1 1)
  140. (array-set! state-4 3.0 1 2)
  141. ;;
  142. (array-set! state-4 1.14e-002 2 0)
  143. (array-set! state-4 (* 800.0 freqfactor) 2 1)
  144. (array-set! state-4 2.8 2 2)
  145. ;;
  146. (array-set! state-4 7.54e-002 3 0)
  147. (array-set! state-4 (* 1600.0 freqfactor) 3 1)
  148. (array-set! state-4 1.0 3 2))
  149. ;;
  150. ((9)
  151. (snd-msg ";;;; State 2: Streached overtone string 9 filters~%")
  152. (array-set! state-2 1.07e-002 0 0)
  153. (array-set! state-2 100.0 0 1)
  154. (array-set! state-2 2.5 0 2)
  155. ;;
  156. (array-set! state-2 1.07e-002 1 0)
  157. (array-set! state-2 202.0 1 1)
  158. (array-set! state-2 0.75 1 2)
  159. ;;
  160. (array-set! state-2 1.07e-002 2 0)
  161. (array-set! state-2 305.0 2 1)
  162. (array-set! state-2 0.5 2 2)
  163. ;;
  164. (array-set! state-2 7.077e-003 3 0)
  165. (array-set! state-2 408.0 3 1)
  166. (array-set! state-2 0.4 3 2)
  167. ;;
  168. (array-set! state-2 1.07e-002 4 0)
  169. (array-set! state-2 501.0 4 1)
  170. (array-set! state-2 0.3 4 2)
  171. ;;
  172. (array-set! state-2 1.07e-002 5 0)
  173. (array-set! state-2 612.0 5 1)
  174. (array-set! state-2 0.25 5 2)
  175. ;;
  176. (array-set! state-2 1.07e-003 6 0)
  177. (array-set! state-2 715.0 6 1)
  178. (array-set! state-2 0.25 6 2)
  179. ;;
  180. (array-set! state-2 1.07e-002 7 0)
  181. (array-set! state-2 817.0 7 1)
  182. (array-set! state-2 0.2 7 2)
  183. ;;
  184. (array-set! state-2 1.07e-002 8 0)
  185. (array-set! state-2 920.0 8 1)
  186. (array-set! state-2 0.18 8 2))
  187. ;;
  188. ((12)
  189. (snd-msg ";;;; State 1: Risset bell long 12 filters~%")
  190. (array-set! state-1 5.025e-002 0 0)
  191. (array-set! state-1 224.0 0 1)
  192. (array-set! state-1 3.7 0 2)
  193. ;;
  194. (array-set! state-1 5.025e-002 1 0)
  195. (array-set! state-1 225.0 1 1)
  196. (array-set! state-1 3.3 1 2)
  197. ;;
  198. (array-set! state-1 5.025e-002 2 0)
  199. (array-set! state-1 368.0 2 1)
  200. (array-set! state-1 2.8 2 2)
  201. ;;
  202. (array-set! state-1 5.025e-002 3 0)
  203. (array-set! state-1 369.0 3 1)
  204. (array-set! state-1 2.4 3 2)
  205. ;;
  206. (array-set! state-1 1.047e-002 4 0)
  207. (array-set! state-1 476.0 4 1)
  208. (array-set! state-1 1.9 4 2)
  209. ;;
  210. (array-set! state-1 5.025e-002 5 0)
  211. (array-set! state-1 680.0 5 1)
  212. (array-set! state-1 1.7 5 2)
  213. ;;
  214. (array-set! state-1 5.025e-002 6 0)
  215. (array-set! state-1 800.0 6 1)
  216. (array-set! state-1 1.5 6 2)
  217. ;;
  218. (array-set! state-1 4.05e-002 7 0)
  219. (array-set! state-1 1096.0 7 1)
  220. (array-set! state-1 1.1 7 2)
  221. ;;
  222. (array-set! state-1 4.05e-002 8 0)
  223. (array-set! state-1 1099.0 8 1)
  224. (array-set! state-1 0.9 8 2)
  225. ;;
  226. (array-set! state-1 4.05e-002 9 0)
  227. (array-set! state-1 1200.0 9 1)
  228. (array-set! state-1 0.6 9 2)
  229. ;;
  230. (array-set! state-1 3.78e-002 10 0)
  231. (array-set! state-1 1504.0 10 1)
  232. (array-set! state-1 0.4 10 2)
  233. ;;
  234. (array-set! state-1 4.05e-002 11 0)
  235. (array-set! state-1 1628.0 11 1)
  236. (array-set! state-1 0.3 11 2))
  237. ;;
  238. ((13)
  239. (snd-msg ";;;; State 3: Open major chord with repeated octave 12 filters~%")
  240. (array-set! state-3 5.025e-002 0 0)
  241. (array-set! state-3 100.0 0 1)
  242. (array-set! state-3 2.0 0 2)
  243. ;;
  244. (array-set! state-3 5.025e-002 1 0)
  245. (array-set! state-3 251.0 1 1)
  246. (array-set! state-3 2.0 1 2)
  247. ;;
  248. (array-set! state-3 5.025e-002 2 0)
  249. (array-set! state-3 299.0 2 1)
  250. (array-set! state-3 2.0 2 2)
  251. ;;
  252. (array-set! state-3 5.025e-002 3 0)
  253. (array-set! state-3 401.0 3 1)
  254. (array-set! state-3 2.0 3 2)
  255. ;;
  256. (array-set! state-3 5.025e-002 4 0)
  257. (array-set! state-3 199.0 4 1)
  258. (array-set! state-3 2.0 4 2)
  259. ;;
  260. (array-set! state-3 5.025e-002 5 0)
  261. (array-set! state-3 501.0 5 1)
  262. (array-set! state-3 2.0 5 2)
  263. ;;
  264. (array-set! state-3 5.025e-002 6 0)
  265. (array-set! state-3 599.0 6 1)
  266. (array-set! state-3 2.0 6 2)
  267. ;;
  268. (array-set! state-3 5.025e-002 7 0)
  269. (array-set! state-3 801.0 7 1)
  270. (array-set! state-3 2.0 7 2)
  271. ;;
  272. (array-set! state-3 5.025e-002 8 0)
  273. (array-set! state-3 201.0 8 1)
  274. (array-set! state-3 2.0 8 2)
  275. ;;
  276. (array-set! state-3 5.025e-002 9 0)
  277. (array-set! state-3 749.0 9 1)
  278. (array-set! state-3 2.0 9 2)
  279. ;;
  280. (array-set! state-3 5.025e-002 10 0)
  281. (array-set! state-3 900.0 10 1)
  282. (array-set! state-3 2.0 10 2)
  283. ;;
  284. (array-set! state-3 5.025e-004 11 0)
  285. (array-set! state-3 1205.0 11 1)
  286. (array-set! state-3 2.0 11 2)
  287. ;;
  288. (array-set! state-3 5.025e-004 12 0)
  289. (array-set! state-3 1205.0 12 1)
  290. (array-set! state-3 2.0 12 2))
  291. (else
  292. (snd-msg "Please leave default or enter [1] [2] [4] [9] [12] [13]~%")
  293. (set! numf 1)))
  294. (do ((run-state (case numf
  295. ((1) state-0)
  296. ((2) state-5)
  297. ((4) state-4)
  298. ((9) state-2)
  299. ((12) state-1)
  300. ((13) state-3)))
  301. (i beg (+ 1 i)))
  302. ((= i end))
  303. (let ((outvalA (* att (readin rdA)))
  304. (add-fl 0.0))
  305. (do ((j 0 (+ 1 j)))
  306. ((= j numf))
  307. (set-coeffs formfil (array-ref run-state j 0) (array-ref run-state j 1) (array-ref run-state j 2))
  308. (set! add-fl (+ add-fl (mvmfilt formfil outvalA))))
  309. (locsig loc i (* (env ampf) add-fl)))))))))
  310. ;; (let* ((ifile "dog.snd")
  311. ;; (ofile "gmax_dog.snd")
  312. ;; (snd (find-sound ofile))
  313. ;; (number-ary '(1 2 4 9 12 13)))
  314. ;; (if snd
  315. ;; (close-sound snd))
  316. ;; (with-sound (:play 1 :statistics #t :channels 4 :output ofile :reverb jc-reverb
  317. ;; :comment
  318. ;; (format #f "maxfilter test, filters ~S, source ~A" number-ary ifile))
  319. ;; (do ((i 0 (+ 1 i))
  320. ;; (nary number-ary (cdr nary)))
  321. ;; ((null? nary))
  322. ;; (maxfilter ifile i :numf (car nary) :degree (random 3454)))))
  323. ;; (with-sound () (maxfilter "dog.snd" 0))
  324. ;; (with-sound (:srate 44100) (maxfilter "dog.snd" 0 :numf 12))
  325. ;; (with-sound (:srate 44100) (maxfilter "dog.snd" 0 :numf 13 :att 0.75))
  326. ;; (with-sound (:srate 44100) (maxfilter "dog.snd" 0 :numf 2 :att 0.25 :freqfactor 0.5))
  327. ;; maxf.scm ends here