No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. (provide 'snd-fullmix.scm)
  2. (if (provided? 'snd)
  3. (require snd-ws.scm)
  4. (require sndlib-ws.scm))
  5. (definstrument (fullmix in-file beg outdur inbeg matrix srate reverb-amount)
  6. ;; "matrix" can be a simple amplitude or a list of lists
  7. ;; each inner list represents one input channel's amps into one output channel
  8. ;; each element of the list can be a number, a list (turned into an env) or an env
  9. ;;
  10. ;; "srate" can be a negative number (read in reverse), or an envelope.
  11. (let ((st (seconds->samples (or beg 0.0)))
  12. (dur (or outdur
  13. (/ (- (mus-sound-duration in-file) (or inbeg 0.0))
  14. (or (and (real? srate) (abs srate)) 1.0))))
  15. (in-chans (channels in-file))
  16. (out-chans (channels *output*))
  17. (reversed (or (and (real? srate) (negative? srate))
  18. (and (pair? srate) (pair? (cdr srate)) (negative? (cadr srate)))))
  19. (inloc (floor (* (or inbeg 0.0) (mus-sound-srate in-file)))))
  20. (let ((samps (seconds->samples dur))
  21. (mx (let ((ochans (max in-chans out-chans)))
  22. (if matrix
  23. (make-float-vector (list ochans ochans))
  24. (let ((v (make-float-vector (list ochans ochans))))
  25. (do ((i 0 (+ i 1)))
  26. ((= i ochans))
  27. (set! (v i i) 1.0))
  28. v))))
  29. (rev-mx (and *reverb* (real? reverb-amount) (> reverb-amount 0.0)
  30. (let ((rmx (make-float-vector (list in-chans in-chans))))
  31. (do ((i 0 (+ i 1)))
  32. ((= i in-chans))
  33. (set! (rmx i 0) reverb-amount)) ; 0->assume 1 chan reverb stream, I think
  34. rmx)))
  35. (file (if (memv srate '(#f 1 1.0))
  36. (make-file->frample in-file)
  37. (let ((vect (make-vector in-chans #f)))
  38. (do ((i 0 (+ i 1)))
  39. ((= i in-chans))
  40. (vector-set! vect i (make-readin in-file i inloc :direction (if reversed -1 1))))
  41. vect)))
  42. (envs #f)
  43. (srcenv (and (pair? srate)
  44. (make-env srate :duration dur :scaler (if reversed -1.0 1.0)))))
  45. (when matrix
  46. (if (pair? matrix) ; matrix is list of scalers, envelopes (lists), or env gens
  47. (do ((inp 0 (+ inp 1))
  48. (off 0 (+ off out-chans)))
  49. ((= inp in-chans))
  50. (let ((inlist (list-ref matrix inp)))
  51. (do ((outp 0 (+ outp 1)))
  52. ((= outp out-chans))
  53. (let ((outn (list-ref inlist outp)))
  54. (if outn
  55. (if (number? outn)
  56. (set! (mx inp outp) outn)
  57. (if (or (env? outn)
  58. (pair? outn))
  59. (begin
  60. (if (not envs)
  61. (set! envs (make-vector (* in-chans out-chans) #f)))
  62. (vector-set! envs (+ off outp)
  63. (if (env? outn)
  64. outn
  65. (make-env outn :duration dur))))
  66. (format () "unknown element in matrix: ~A" outn))))))))
  67. (do ((inp 0 (+ inp 1))) ; matrix is a number in this case (a global scaler)
  68. ((= inp in-chans))
  69. (if (< inp out-chans)
  70. (set! (mx inp inp) matrix)))))
  71. (if (memv srate '(#f 1 1.0))
  72. (let ((mxe (and envs
  73. (do ((v (make-vector in-chans))
  74. (i 0 (+ i 1))
  75. (off 0 (+ off out-chans)))
  76. ((= i in-chans) v)
  77. (let ((vo (make-vector out-chans #f)))
  78. (vector-set! v i vo)
  79. (do ((j 0 (+ j 1)))
  80. ((= j out-chans))
  81. (vector-set! vo j (vector-ref envs (+ off j)))))))))
  82. ;; -------- no src
  83. (mus-file-mix *output* file st samps inloc mx mxe)
  84. (if rev-mx
  85. (mus-file-mix *reverb* file st samps inloc rev-mx)))
  86. (let ((srcs (make-vector in-chans #f)))
  87. (do ((inp 0 (+ inp 1)))
  88. ((= inp in-chans))
  89. (vector-set! srcs inp (make-src :input (vector-ref file inp) :srate (if (real? srate) (abs srate) 0.0))))
  90. (mus-file-mix-with-envs file st samps mx rev-mx envs srcs srcenv *output* *reverb*)
  91. )))))
  92. #|
  93. (with-sound (:channels 2 :statistics #t)
  94. (fullmix "pistol.snd")
  95. (fullmix "2.snd" .5 1)
  96. (fullmix "2.snd" 1.5 1 0 #f 2.0)
  97. (fullmix "oboe.snd" 1 2 0 (list (list .1 (make-env '(0 0 1 1) :duration 2 :scaler .5))))
  98. (fullmix "pistol.snd" 2 1 0 #f .5)
  99. (fullmix "2.snd" 0 2 0 (list (list .1 .2) (list .3 .4)) 2.0)
  100. (fullmix "oboe.snd" 3 2 0 (list (list .1 (make-env '(0 0 1 1) :duration 2 :scaler .5))) .25)
  101. (let ((e0->0 (make-env '(0 0 1 1) :duration 2))
  102. (e0->1 (make-env '(0 1 1 0) :duration 2))
  103. (e1->0 (make-env '(0 1 1 0) :duration 2))
  104. (e1->1 (make-env '(0 0 1 1) :duration 2)))
  105. (fullmix "2.snd" 4 2 0 (list (list e0->0 e0->1) (list e1->0 e1->1))))
  106. (let ((e0->0 (make-env '(0 0 1 1) :duration 2))
  107. (e0->1 (make-env '(0 1 1 0) :duration 2))
  108. (e1->0 (make-env '(0 1 1 0) :duration 2))
  109. (e1->1 (make-env '(0 0 1 1) :duration 2)))
  110. (fullmix "2.snd" 6 2 0 (list (list e0->0 e0->1) (list e1->0 e1->1)) 2.0)))
  111. (with-sound (:channels 2 :statistics #t)
  112. (fullmix "2.snd" 0 2 0 (list (list .1 .2) (list .3 .4)) 2.0))
  113. (with-sound () (fullmix "pistol.snd" 0 2 2 #f -1.0))
  114. (with-sound (:channels 2)
  115. (let ((e0->0 (make-env '(0 0 1 1) :duration 2))
  116. (e0->1 (make-env '(0 1 1 0) :duration 2))
  117. (e1->0 (make-env '(0 1 1 0) :duration 2))
  118. (e1->1 (make-env '(0 0 1 1) :duration 2)))
  119. (fullmix "2.snd" 6 2 0 (list (list e0->0 e0->1) (list e1->0 e1->1))) 2.0))
  120. (with-sound () (fullmix "pistol.snd"))
  121. (with-sound () (fullmix "pistol.snd" 1))
  122. (with-sound () (fullmix "pistol.snd" 1 1))
  123. (with-sound () (fullmix "pistol.snd" 0 1 1))
  124. (with-sound (:statistics #t) (fullmix "pistol.snd" 0 1 0 2.0))
  125. (with-sound (:statistics #t :channels 2) (fullmix "pistol.snd" 0 1 0 2.0))
  126. (with-sound (:statistics #t :channels 2) (fullmix "pistol.snd" 0 1 0 (list (list 0.1 0.7))))
  127. (with-sound (:statistics #t :channels 2) (fullmix "pistol.snd" 0 1 0 (list (list 0.1 (list 0 0 1 1)))))
  128. (with-sound (:channels 2 :output "one-2.snd") (do ((i 0 (+ i 1))) ((= i 10000)) (outa i 0.5) (outb i -0.5)))
  129. (with-sound (:channels 4 :output "one-4.snd") (do ((i 0 (+ i 1))) ((= i 10000)) (outa i 0.5) (outb i -0.5) (outc i 0.1) (outd i -0.1)))
  130. (with-sound (:statistics #t :channels 2) (fullmix "one-2.snd" 0 .2 0 '((1.0 0.5) (0.5 1.0))))
  131. (with-sound (:statistics #t :channels 2) (fullmix "one-2.snd" 0 .2 0 (list (list 0.1 (list 0 0 1 1)) (list (list 0 1 1 0) .5))))
  132. (with-sound (:statistics #t :channels 2)
  133. (let ((e0->0 (make-env '(0 0 1 1) :end 10000))
  134. (e0->1 (make-env '(0 1 1 0) :end 10000))
  135. (e1->0 (make-env '(0 1 1 0) :end 10000))
  136. (e1->1 (make-env '(0 0 1 1) :end 10000)))
  137. (fullmix "one-2.snd" 0 .2 0 (list (list e0->0 e0->1) (list e1->0 e1->1)))))
  138. (with-sound (:statistics #t :channels 2 :reverb jc-reverb)
  139. (let ((e0->0 (make-env '(0 0 1 1) :end 10000))
  140. (e0->1 (make-env '(0 1 1 0) :end 10000))
  141. (e1->0 (make-env '(0 1 1 0) :end 10000))
  142. (e1->1 (make-env '(0 0 1 1) :end 10000)))
  143. (fullmix "one-2.snd" 0 .2 0 (list (list e0->0 e0->1) (list e1->0 e1->1)) #f .1)))
  144. (with-sound () (fullmix "oboe.snd" 0 2 0 #f '(0 0.5 1 1 2 .1)))
  145. |#