/usr/share/snd/big-gens.scm is in snd 18.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | (provide 'snd-big-gens.scm)
(require snd-generators.scm)
;;; -------- conversions --------
(define (big-hz->radians hz)
(/ (* hz 2 pi) *clm-srate*))
(define (big-radians->hz rad)
(/ (* rad *clm-srate*) 2 pi))
(define (big-db->linear x)
(expt 10.0 (/ x 20.0)))
(define (big-linear->db x)
(if (> x 0.0) (* 20.0 (log x 10)) -100.0))
(define (big-degrees->radians deg)
(* (/ pi 180) deg))
(define (big-radians->degrees rad)
(/ (* rad 180) pi))
(define (big-seconds->samples secs)
(round (* secs *clm-srate*)))
(define (big-samples->seconds samps)
(/ samps *clm-srate*))
(define (big-rectangular->polar rl im)
(do ((len (length rl))
(i 0 (+ i 1)))
((= i len))
(let ((rl1 (rl i))
(im1 (im i)))
(set! (rl i) (sqrt (+ (* rl1 rl1) (* im1 im1))))
(set! (im i) (- (atan im1 rl1))))))
(define (big-polar->rectangular mag ang)
(do ((len (length mag))
(i 0 (+ i 1)))
((= i len))
(let ((mag1 (mag i))
(ang1 (- (ang i))))
(set! (mag i) (* mag1 (cos ang1)))
(set! (ang i) (* mag1 (sin ang1))))))
;;; -------- arrays (vectors in this context) --------
(define (big-array-clear v)
(fill! v 0.0))
(define (big-array-normalize v)
(let ((len (length v))
(pk 0.0))
(do ((i 0 (+ i 1)))
((= i len))
(set! pk (max pk (abs (v i)))))
(if (not (member pk '(0.0 1.0) =))
(do ((i 0 (+ i 1)))
((= i len))
(set! (v i) (/ (v i) pk))))
v))
(define (big-array-interp wave x n)
(let* ((xx (modulo x n))
(ipart (floor xx))
(fpart (- xx ipart)))
(if (zero? fpart)
(wave ipart)
(+ (wave ipart)
(* fpart (- (wave (modulo (+ ipart 1) n))
(wave ipart)))))))
;;; -------- polynomial --------
(define (big-polynomial coeffs x)
(let* ((top (- (length coeffs) 1))
(sum (coeffs top)))
(do ((i (- top 1) (- i 1)))
((< i 0) sum)
(set! sum (+ (* x sum)
(coeffs i))))))
;;; -------- dot-product --------
(define (big-dot-product v1 v2)
(do ((len (min (length v1) (length v2)))
(sum 0.0)
(i 0 (+ i 1)))
((= i len) sum)
(set! sum (+ sum (* (v1 i) (v2 i))))))
;;; -------- ring-modulate --------
(define big-ring-modulate *)
;;; -------- amplitude-modulate --------
(define (big-amplitude-modulate carrier in1 in2)
(* in1 (+ carrier in2)))
;;; -------- contrast-enhancement --------
(define* (big-contrast-enhancement in1 (index 1.0))
(sin (+ (* in1 (/ pi 2))
(* index (sin (* 2 pi in1))))))
;;; -------- oscil --------
(defgenerator (big-oscil
:make-wrapper
(lambda (g) (set! (g 'frequency) (big-hz->radians (g 'frequency))) g))
(frequency 0.0)
(angle 0.0))
(define* (big-oscil gen (fm 0.0) (pm 0.0))
(let ((x (gen 'angle)))
(set! (gen 'angle) (+ fm x (gen 'frequency)))
(sin (+ x pm))))
#|
(with-sound (:statistics #t :clipped #f)
(let ((g (make-big-oscil 440.0)))
(do ((i 0 (+ i 1)))
((= i 22050))
(outa i (* .5 (big-oscil g))))))
|#
;;; -------- ncos --------
(defgenerator (big-ncos
:make-wrapper
(lambda (g)
(if (<= (g 'n) 0)
(set! (g 'n) 1))
(set! (g 'r) (/ (g 'n)))
(set! (g 'frequency) (big-hz->radians (g 'frequency)))
g))
(frequency 0.0)
(n 1)
(angle 0.0)
(r 1.0))
(define* (big-ncos gen (fm 0.0))
(let* ((n (gen 'n))
(x (gen 'angle))
(scl (gen 'r))
(den (* 2 (sin (/ x 2)))))
(set! (gen 'angle) (+ fm x (gen 'frequency)))
(if (= den 0.0)
1.0
(min 1.0 (* scl (- (/ (sin (* (+ n 1/2) x)) den) 1/2))))))
#|
(with-sound (:statistics #t :clipped #f)
(let ((g (make-big-ncos 100.0 10)))
(do ((i 0 (+ i 1)))
((= i 22050))
(outa i (* .5 (big-ncos g))))))
|#
;;; -------- nsin --------
(defgenerator (big-nsin
:make-wrapper (letrec ((ns (lambda (x n)
(let* ((a2 (/ x 2))
(den (sin a2)))
(if (= den 0.0)
0.0
(/ (* (sin (* n a2))
(sin (* (+ n 1) a2)))
den)))))
(find-scaler (lambda (n lo hi)
(let ((mid (/ (+ lo hi) 2))
(ylo (ns lo n))
(yhi (ns hi n)))
(if (< (abs (- yhi ylo)) 1e-12)
(ns mid n)
(find-scaler n (if (> ylo yhi)
(values lo mid)
(values mid hi))))))))
(lambda (g)
(if (<= (g 'n) 0)
(set! (g 'n) 1))
(set! (g 'r) (/ 1.0 (find-scaler (g 'n) 0.0 (/ pi (+ (g 'n) 1/2)))))
(set! (g 'frequency) (big-hz->radians (g 'frequency)))
g)))
(frequency 0.0)
(n 1)
(angle 0.0)
(r 1.0))
(define* (big-nsin gen (fm 0.0))
(let* ((n (gen 'n))
(x (gen 'angle))
(a2 (/ x 2))
(scl (gen 'r))
(den (sin a2)))
(set! (gen 'angle) (+ fm x (gen 'frequency)))
(if (= den 0.0)
0.0
(/ (* scl (sin (* n a2)) (sin (* (+ n 1) a2))) den))))
#|
(with-sound (:statistics #t :clipped #f)
(let ((g (make-big-nsin 100.0 10)))
(do ((i 0 (+ i 1)))
((= i 22050))
(outa i (* .5 (big-nsin g))))))
|#
;;; -------- table-lookup --------
(defgenerator (big-table-lookup
:make-wrapper
(lambda (g)
(if (g 'wave)
(set! (g 'size) (length (g 'wave)))
(set! (g 'wave) (make-vector (g 'size) 0.0)))
(set! (g 'frequency) (/ (* (g 'frequency) (g 'size)) *clm-srate*))
(set! (g 'angle) (/ (* (g 'angle) (g 'size)) (* 2 pi)))
g))
(frequency 0.0)
(angle 0.0)
(wave #f)
(size *clm-table-size*))
(define* (big-table-lookup gen (fm 0.0))
(let ((x (gen 'angle))
(w (gen 'wave))
(n (gen 'size)))
(set! (gen 'angle) (+ x (gen 'frequency) (/ (* fm n) 2 pi)))
(big-array-interp w x n)))
#|
(with-sound (:statistics #t :clipped #f)
(let ((g (make-big-table-lookup 100.0 0.0 (let ((w (make-vector 32)))
(do ((i 0 (+ i 1)))
((= i 32) w)
(set! (w i) (sin (/ (* i pi) 16))))))))
(do ((i 0 (+ i 1)))
((= i 22050))
(outa i (* .5 (big-table-lookup g))))))
|#
;;; -------- one-zero --------
(defgenerator big-one-zero (a0 1.0) (a1 0.0) (x1 0.0))
(define* (big-one-zero gen x)
(let ((val (+ (* x (gen 'a0))
(* (gen 'x1) (gen 'a1)))))
(set! (gen 'x1) x)
val))
;;; -------- one-pole --------
(defgenerator big-one-pole (a0 1.0) (b1 0.0) (y1 0.0))
(define* (big-one-pole gen x)
(let ((val (- (* x (gen 'a0))
(* (gen 'y1) (gen 'b1)))))
(set! (gen 'y1) val)))
|