Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ;;; agn.scm -- Bill Schottstaedt's agn.cl
  2. ;;; (see clm-2/clm-example.clm and clm-2/bess5.cl)
  3. ;; Translator/Author: Michael Scholz <mi-scholz@users.sourceforge.net>
  4. ;; Created: Tue Jun 24 19:05:06 CEST 2003
  5. ;; Changed: Sat Jul 28 00:33:36 CEST 2012
  6. ;; Try (do-agn)
  7. (define *clm-c-version* #t)
  8. (if (not (provided? 'sndlib))
  9. (let ((hsndlib (dlopen "libsndlib.so")))
  10. (if (string? hsndlib)
  11. (snd-error (format #f "script needs the sndlib module: ~A" hsndlib))
  12. (dlinit hsndlib "Init_sndlib"))))
  13. (if *clm-c-version*
  14. (if (not (provided? 'sndins))
  15. (let ((hsndins (dlopen "libsndins.so")))
  16. (if (string? hsndins)
  17. (snd-error (format #f "script needs the sndins module: ~A" hsndins))
  18. (dlinit hsndins "Init_sndins"))))
  19. (load "v.scm"))
  20. (if (not (provided? 'snd-ws.scm)) (load "ws.scm"))
  21. (if (not (provided? 'snd-env.scm)) (load "env.scm"))
  22. (define *clm-play* #t)
  23. (define *clm-statistics* #t)
  24. (define *clm-verbose* #t)
  25. (define *clm-srate* 44100)
  26. (define *clm-channels* 2)
  27. (define *clm-reverb* jc-reverb)
  28. (define *clm-reverb-data* '(:volume 0.8))
  29. (define *clm-reverb-channels* 2)
  30. (define *clm-delete-reverb* #t)
  31. (define (snd-msg frm . args)
  32. (snd-print (apply format (append (list #f frm) args))))
  33. (define (main args)
  34. (do-agn (if (= 2 (length args)) (cadr args) "agn.clm")))
  35. (define* (do-agn (file "agn.clm"))
  36. (let ((sndfile (format #f "~A.snd" "agn")))
  37. (snd-msg ";; Writing ~S~%" file)
  38. (agn file)
  39. (with-sound (:output sndfile)
  40. (snd-msg ";; Loading ~S~%" file)
  41. (load file))))
  42. (define lim 256)
  43. (define time 60)
  44. (define mode (list->vector '(0 0 2 4 11 11 5 6 7 0 0 0 0)))
  45. (define rats (list->vector '(1.0 256/243 9/8 32/27 81/64 4/3 1024/729
  46. 3/2 128/81 27/16 16/9 243/128 2.0)))
  47. (define bell '(0 0 10 0.25 90 1.0 100 1.0))
  48. (define octs (make-vector (1+ lim)))
  49. (define pits (make-vector (1+ lim)))
  50. (define rhys (make-vector (1+ lim)))
  51. (define amps (make-vector (1+ lim)))
  52. (define (tune x)
  53. (let* ((pit (modulo x 12))
  54. (oct (inexact->exact (floor (/ x 12))))
  55. (base (vector-ref rats pit)))
  56. (* base (expt 2 oct))))
  57. (define (rbell x)
  58. (envelope-interp (* x 100) bell))
  59. (define* (glog r b)
  60. (if (<= r 0) (error "r must be > 0"))
  61. (if (and b (<= b 0)) (error "b must be > 0"))
  62. (if b (/ (log r) (log b)) (log r)))
  63. (define (agn file)
  64. (let ((wins (list->vector '((0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
  65. (0 0 60 0.1 80 0.2 90 0.4 95 1 100 0)
  66. (0 0 10 1 16 0 32 0.1 50 1 56 0 60 0 90 0.3 100 0)
  67. (0 0 30 1 56 0 60 0 90 0.3 100 0)
  68. (0 0 50 1 80 0.3 100 0)
  69. (0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
  70. (0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
  71. (0 0 10 1 32 0.1 50 1 90 0.3 100 0)
  72. (0 0 60 0.1 80 0.3 95 1 100 0)
  73. (0 0 80 0.1 90 1 100 0)))))
  74. (do ((i 0 (1+ i)))
  75. ((= i (+ lim 1)))
  76. (vector-set! octs i
  77. (inexact->exact (floor (+ 4 (* 2 (rbell (random 1.0)))))))
  78. (vector-set! pits i
  79. (vector-ref mode (inexact->exact (floor (* 12 (random 1.0))))))
  80. (vector-set! rhys i
  81. (inexact->exact (floor (+ 4 (* 6 (random 1.0))))))
  82. (vector-set! amps i
  83. (inexact->exact (floor (+ 1 (* 8 (rbell (random 1.0))))))))
  84. (call-with-output-file file
  85. (lambda (out-port)
  86. (format out-port
  87. ";; from agn.cl (see clm-2/clm-example.clm and clm-2/bess5.cl)~%")
  88. (do ((i 1 (1+ i)))
  89. ((> i 3))
  90. (let ((cellbeg 0)
  91. (cellsiz 4)
  92. (cellctr 0)
  93. (whichway 1)
  94. (base i)
  95. (mi (- i 1))
  96. (winnum 0)
  97. (mytempo 0.2)
  98. (nextbeg 0.0)
  99. (revamt 0.0)
  100. (ranamt 0.0)
  101. (beg 0.0)
  102. (dur 0.0)
  103. (freq 0.0)
  104. (ampl 0.0)
  105. (ind 0.0))
  106. (while (and (< beg time) (< cellctr lim))
  107. (set! beg (+ beg nextbeg))
  108. (set! nextbeg (max 0.25
  109. (* mytempo (+ 0.9 (* 0.2 (random 0.1)))
  110. (vector-ref rhys cellctr))))
  111. (set! freq (* (/ 16.352 (expt 2 mi))
  112. (tune (vector-ref pits cellctr))
  113. (expt 2 (vector-ref octs cellctr))))
  114. (set! dur nextbeg)
  115. (if (< freq 100) (set! dur (+ dur dur)))
  116. (set! ampl (max 0.003
  117. (* (vector-ref amps cellctr) (/ (* 60 base)))))
  118. (set! ind (* (random 1.0) 2 base))
  119. (set! cellctr (1+ cellctr))
  120. (set! revamt (* base 0.1))
  121. (set! winnum (inexact->exact
  122. (floor (* 10 (- beg (floor beg))))))
  123. (set! ranamt (* 0.00001 (expt (- (glog freq 2.0) 4) 4)))
  124. (format out-port
  125. "
  126. (fm-violin ~F ~F ~F ~F :fm-index ~F
  127. :amp-env '~S
  128. :reverb-amount ~F :noise-amount ~F)"
  129. beg dur freq ampl ind
  130. (vector-ref wins winnum) revamt ranamt)
  131. (set! cellctr (1+ cellctr))
  132. (if (> cellctr (+ cellsiz cellbeg))
  133. (begin
  134. (set! cellbeg (1+ cellbeg))
  135. (if (> (random 1.0) 0.5)
  136. (set! cellsiz (+ cellsiz whichway)))
  137. (if (and (> cellsiz 16) (> (random 1.0) 0.99))
  138. (begin
  139. (set! whichway -2)
  140. (if (and (> cellsiz 12) (> (random 1.0) 0.999))
  141. (begin
  142. (set! whichway -1)
  143. (if (< cellsiz 4)
  144. (set! whichway 1))))))
  145. (set! cellbeg (+ cellbeg 3))
  146. (set! cellctr cellbeg))))))
  147. (format out-port "~%~%;; ~A ends here~%" file))))
  148. file)
  149. ;; agn.scm ends here