animals.scm 481 KB
Newer Older
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
;;; animals.scm


;;; sources:
;;; "The Diversity of Animal Sounds", Cornell Lab of Ornithology
;;; Geoffrey Keller, "Bird Songs of California" (Cornell)
;;; Geoffrey Keller, "Bird Songs of Southeastern Arizona and Sonora, Mexico" (Cornell)
;;; Bret Whitney et al, "Voices of New World Parrots" (Cornell)
;;; Carlos Davidson, "Frog and Toad Calls of the Rocky Mountains" (Cornell)
;;; Geoffrey Keller, "Bird Songs of the Lower Rio Grande Valley" (Cornell)
;;; Vyn, Budney, "Voices of North American Owls" (Cornell)
;;; Roche and Chevereau, "Guide to the Sounds of the Birds of Europe"
;;; from Richard Mankin, Reference Library of Digitized Insect Sounds, http://www.ars.usda.gov/sp2UserFiles/person/3559/soundlibrary.html
;;; Lang Elliott, Donald and Lillian Stokes, "Stokes Field Guide to Bird Songs, Eastern Region"
;;; Lang Elliott "The Calls of Frogs and Toads"
;;; Lang Elliott and W Herschberger "The Songs of the Insects"
;;; Lang Elliott "Music of the Birds"
;;; Cocroft, Morales, McDiarmid "Frogs of Tambopata, Peru" (Cornell)
;;; Ross, Whitney, "Voices of Costa Rican Birds" (Cornell)
;;; Rebolledo, Ramirez, Cuervo, "A Guide to the Bird Sounds of the Colombian Andes" (Humboldt and Cornell)
;;; Emmons, Whitney, Ross, "Sounds of Neotropical Rainforest Mammals" (Cornell)
;;; Marantz, Zimmer, "Bird Voices of the Alta Floresta" (Cornell)
;;; "Voices of the Night" (Cornell)
;;; Keller, Vyn, "Bird Songs of the Pacific Northwest" (Cornell)


;;; -------- frogs and toads --------
;;; Oak toad
;;; Knudsen's frog
;;; Southern cricket frog
;;; Northern leopard frog (2)
;;; Spring peeper
;;; Crawfish frog
;;; River frog
;;; Green tree-frog
;;; Pinewoods tree frog
;;; Squirrel tree frog
;;; Ornate chorus frog
;;; Bullfrog
;;; Texas toad
;;; American toad
;;; Plains spadefoot
;;; Barking tree-frog
;;; Western toad
;;; Southwestern toad
;;; Great Plains Narrow-mouthed toad
;;; Pacific chorus frog
;;; Red-spotted toad
;;; Green toad
;;; Little grass frog
;;; Sonoran desert toad
;;; Amargosa toad

;;; -------- mammals --------
;;; Indri

;;; -------- insects --------
;;; mosquito
;;; Long-spurred meadow katydid
;;; Handsome trig
;;; Dog-day cicada
;;; Linnaeus' cicada
;;; Lyric cicada
;;; Southern mole cricket
;;; Confused ground cricket
;;; Tinkling ground cricket
;;; Striped ground cricket
;;; Sphagnum ground cricket
;;; Southeastern field cricket
;;; Snowy tree cricket
;;; Pine tree cricket
;;; Davis's tree cricket
;;; Broad-winged tree cricket
;;; Fast-calling tree cricket
;;; Black-horned tree cricket
;;; Narrow-winged tree cricket
;;; Four-spotted tree cricket
;;; Marsh meadow grasshopper
;;; Carolina grasshopper
;;; Slightly musical conehead

;;; -------- birds --------
;;; Fox sparrow
;;; White-throated sparrow
;;; Henslow's sparrow
;;; Field sparrow
;;; Savannah sparrow
;;; Chipping sparrow
;;; Bachman's sparrow
;;; Grasshopper sparrow
;;; Black-chinned sparrow
;;; Golden-crowned sparrow
;;; Cassin's sparrow
;;; Song sparrow
;;; Sage sparrow
;;; House sparrow
;;; Black-throated sparrow
;;; Dark-eyed junco
;;; Purple finch
;;; House finch
;;; Gray-crowned rosy-finch
;;; Eastern wood-pewee (2)
;;; Western wood-pewee (2)
;;; Greater pewee
;;; Tufted titmouse
;;; Oak titmouse
;;; Bushtit
;;; Wrentit
;;; California towhee
;;; Green-tailed towhee
;;; Carolina wren
;;; Warbling vireo
;;; Plumbeous vireo (2)
;;; Cassin's vireo
;;; Hutton's vireo
;;; Gray vireo (5)
;;; Yellow-green vireo
;;; Red-eyed vireo
;;; White-eyed vireo
;;; Philadelphia vireo
;;; Nashville warbler
;;; Orange-crowned warbler
;;; Yellow warbler
;;; Yellow-rumped warbler
;;; Lucy's warbler
;;; Macgillivray's warbler
;;; Wilson's warbler
;;; Magnolia warbler
;;; Chestnut-sided warbler
;;; Black-throated blue warbler
;;; Pine warbler
;;; Cape May warbler
;;; Kirtland's warbler
;;; Verdin
;;; Townsend's solitaire
;;; Cedar waxwing
;;; Western meadowlark
;;; Eastern meadowlark
;;; Ruby-crowned kinglet
;;; Least flycatcher
;;; Acadian flycatcher
;;; Vermillion flycatcher
;;; Ash-throated flycatcher
;;; Olive-sided flycatcher
;;; Willow flycatcher
;;; Hammond's flycatcher
;;; Pacific-slope flycatcher
;;; Dusky flycatcher
;;; Yellow-bellied flycatcher
;;; Great crested flycatcher
;;; Brown-crested flycatcher (2)
;;; Black phoebe
;;; Say's phoebe
;;; Northern beardless tyrannulet
;;; Great kiskadee
;;; Scrub euphonia
;;; Eastern bluebird
;;; Common yellowthroat
;;; Blue grosbeak
;;; Evening grosbeak
;;; Cardinal
;;; American robin
;;; Scott's oriole
;;; Swainson's thrush
;;; Varied thrush
;;; Hermit thrush
;;; Western tanager
;;; Summer tanager
;;; Chuck-will's-widow
;;; Whip-poor-will
;;; Lesser nighthawk
;;; Common pauraque
;;; Mourning dove
;;; Inca dove (2)
;;; White-tipped dove
;;; Bobwhite
;;; California quail
;;; Gambel's quail
;;; Scaled quail
;;; Montezuma quail
;;; Mountain quail
;;; Ruffed grouse
;;; Great-horned owl
;;; Barred owl
;;; Flammulated owl
;;; Burrowing owl
;;; Barn owl
;;; Long-eared owl
;;; Northern goshawk
;;; Red-shouldered hawk
;;; Zone-tailed hawk
;;; Bald eagle
;;; Crested caracara
;;; Pileated woodpecker
;;; White-headed woodpecker
;;; Acorn woodpecker
;;; Hairy woodpecker
;;; Red-breasted nuthatch
;;; White-breasted nuthatch
;;; Pygmy nuthatch
;;; Common loon (2)
;;; American crow
;;; Brown jay
;;; Steller's jay
;;; Pinyon jay
;;; Groove-billed ani
;;; Loggerhead shrike (2)
;;; Greater roadrunner
;;; Common Gull
;;; Willet
;;; Black-necked stilt
;;; Whooping crane
;;; Sandhill crane
;;; Trumpeter swan
;;; Canada goose
;;; Wood duck
;;; Black-crowned night heron
;;; Least bittern
;;; Black rail
;;; Virginia rail
;;; Sora
;;; Plain chacalaca
;;; Black-billed cuckoo
;;; Eared grebe
;;; Killdeer

(provide 'snd-animals.scm)

229 230 231 232 233
(require snd-generators.scm)
;;     rk!cos blackman=polywave rcos rxycos
(if (provided? 'snd)
    (require snd-ws.scm)
    (require sndlib-ws.scm))
234 235 236

(set! *clm-default-frequency* 0.0)

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
(define-macro (defanimal args . body)
  (let ((name (car args))
	(targs (cdr args)))
  `(begin 
     (define (,name ,@targs)
       (if *clm-notehook*
	   (*clm-notehook* (symbol->string ',name) ,@targs))
       ,@body)
     ,@(if *definstrument-hook*
           (list (*definstrument-hook* name targs))
           (list)))))

#|
(define-macro (defanimal args . body)
  (let ((name (car args))
	(targs (cdr args)))
  `(begin
     (define (,name ,@targs)
       (if *clm-notehook*
	   (*clm-notehook* (symbol->string ',name) ,@targs))
       (let ((start (get-internal-real-time)))
	 ,@body
259
	 (format () "~A: ~A~%" (- (get-internal-real-time) start) ,name)))
260 261 262 263 264
     ,@(if *definstrument-hook*
           (list (*definstrument-hook* name targs))
           (list)))))
|#

265 266 267 268 269 270 271

#|
;;; ================================================================================
;;; useful settings and functions for this work (I have these in my init file):

(define (clean-string e)
  ;; make the envelope lists look prettier
272
  (format #f "(~{~,3F~^ ~})" e))
273 274

(define (seldur) 
275
  (list (/ (selection-framples) 44100.0) 
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	(selection-maxamp)))

(define (sp) 
  (* 22050 (spectrum-end 0 0)))


;;; save us some dialog setup
(set! (show-transform-peaks) #t)
(set! (transform-size) 512)
(set! (fft-window) blackman10-window)
(set! (colormap) 7) ; jet
(set! (speed-control-style) speed-control-as-ratio)
(set! (color-cutoff) .001)
(set! (enved-clip?) #t)


;;; if click play button and there's a selection, play the selection
;;;   otherwise if the file is long (like most bird recordings), play what's in the current window.
;;;   This is mainly to cut out the ubiquitous and useless announcer.

296 297
(if (null? (hook-functions start-playing-hook))
    (hook-push start-playing-hook
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
	       (lambda (hook)
		 (let ((snd (hook 'snd)))
		   (if (sound? snd)  ; meaning not 123456 = temp-sound-index from View:Files play button
		       (if (and (selection?)
				(selection-member? snd))
			   (begin
			     (play (selection))
			     #t)
			   (if (> (framples snd) (* 10 (srate snd)))
			       (let ((chn (or (selected-channel) 0)))
				 (with-temporary-selection 
				  (lambda () (play (selection)))
				  (left-sample snd chn) 
				  (- (right-sample snd chn) 
				     (left-sample snd chn)) 
				  snd chn)
				 #t)
			       #f))
		       #f)))))
317 318 319 320 321 322


;;; precision window movements via arrow keys

(define (move-one-pixel s c right)
  (let* ((ax (axis-info s c time-graph))
323 324 325 326
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
327 328
	 (samps-per-pixel (max 1 (round (/ (- hi lo) (- hi-pix lo-pix)))))
	 (change (if right 
329
		     (- (min (+ hi samps-per-pixel) (framples s c)) hi)
330
		     (- (max 0 (- lo samps-per-pixel)) lo))))
331
    (set! (left-sample) (min (max 0 (+ lo change)) (framples s c)))
332 333 334 335 336 337 338
    keyboard-no-action))

(bind-key "Left" 0 (lambda () "move one pixel backward" (move-one-pixel (selected-sound) (selected-channel) #f)))
(bind-key "Right" 0 (lambda () "move one pixel forward" (move-one-pixel (selected-sound) (selected-channel) #t)))

(define (move-more-pixels s c right)
  (let* ((ax (axis-info s c time-graph))
339 340 341 342
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
343 344
	 (samps-per-pixel (* 8 (max 1 (round (/ (- hi lo) (- hi-pix lo-pix))))))
	 (change (if right 
345
		     (- (min (+ hi samps-per-pixel) (framples s c)) hi)
346
		     (- (max 0 (- lo samps-per-pixel)) lo))))
347
    (set! (left-sample) (min (max 0 (+ lo change)) (framples s c)))
348 349 350 351 352 353 354
    keyboard-no-action))

(bind-key "Left" 4 (lambda () "move some pixels backward" (move-more-pixels (selected-sound) (selected-channel) #f)))
(bind-key "Right" 4 (lambda () "move some pixels forward" (move-more-pixels (selected-sound) (selected-channel) #t)))

(define (zoom-one-pixel s c in)
  (let* ((ax (axis-info s c time-graph))
355 356 357 358
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
359
	 (samps-per-pixel (max 1 (round (/ (- hi lo) (- hi-pix lo-pix)))))
360
	 (len (framples s c)))
361 362 363 364
    (if in
	(if (> (- hi-pix lo-pix) samps-per-pixel)
	    (begin
	      (set! (left-sample) (+ lo samps-per-pixel))
365
	      (set! (x-zoom-slider) (* 1.0 (/ (max samps-per-pixel (- hi lo (* 2 samps-per-pixel))) len)))))
366 367
	(begin
	  (set! (left-sample) (max 0 (- lo samps-per-pixel)))
368
	  (set! (x-zoom-slider) (* 1.0 (/ (min len (+ (- hi lo) (* 2 samps-per-pixel))) len)))))
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
    keyboard-no-action))

(bind-key "Up" 0 (lambda () "zoom out one pixel" (zoom-one-pixel (selected-sound) (selected-channel) #f))) ;up
(bind-key "Down" 0 (lambda () "zoom in one pixel" (zoom-one-pixel (selected-sound) (selected-channel) #t))) ;down


;;; save the current window so that PageUp returns to it

(bind-key "Page_Down" 0 
	  (lambda ()
	    (let ((last-page-state (map (lambda (snd) 
					  (let ((data (list snd (file-name snd))))
					    (do ((i 0 (+ i 1)))
						((= i (channels snd)) data)
					      (set! data (append data (list (cons i (axis-info snd i))))))))
					(sounds))))
	      (bind-key "Page_Up" 0
			(lambda ()
			  (if last-page-state
			      (for-each
			       (lambda (lst)
390 391
				 (let ((snd (lst 0))
				       (name (lst 1)))
392 393 394 395
				   (if (and (sound? snd)
					    (string=? (file-name snd) name))
				       (for-each
					(lambda (chan-data)
396 397 398 399 400
					  (let ((chn (chan-data 0))
						(x0 (chan-data 3))
						(x1 (chan-data 5))
						(y0 (chan-data 4))
						(y1 (chan-data 6)))
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
					    (set! (x-bounds snd chn) (list x0 x1))
					    (set! (y-bounds snd chn) (list y0 y1))))
					(cddr lst)))))
			       last-page-state)))))))

;;; "m" -> make enved amp display suitable for drawing the amp env
(bind-key #\m 0
	  (lambda ()
	    (set! (y-bounds (selected-sound) (selected-channel)) (list 0 (selection-maxamp))))
	  #t)

;;; "C-m" returns to normal after "m"
(bind-key #\m 4
	  (lambda ()
	    (set! (y-bounds (selected-sound) (selected-channel)) (list -1.0 1.0)))
	  #t)
417

418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
|#
;;; ================================================================================



;;; some of these need srate=44100 since various frequencies are (well) over 10KHz
;;;   also, I have bare indices scattered around -- ideally these would be wrapped in hz->radians
;;; these were done more or less in the order they occur within a section



;;; ================ Frogs and Toads ================
;;;
;;;
;;; Knudsen's frog

434 435 436 437 438 439 440 441 442 443 444 445 446 447
(defanimal (a-frog beg dur freq amp amp-env gliss gliss-env pulse-dur pulse-env fm-index fm-freq)
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(base (make-oscil freq))
	(modm (make-oscil fm-freq))
	(frqf (make-env (or gliss-env '(0 0 1 0)) :duration dur :base 32 :scaler (hz->radians gliss)))
	(pulse (make-pulsed-env pulse-env pulse-dur (/ 1.0 pulse-dur)))
	(ampf (make-env amp-env :duration dur :scaler amp))
	(index (hz->radians (* fm-freq fm-index))))
    (do ((i start (+ i 1)))
	((= i stop))
      (outa i (* (env ampf)
		 (pulsed-env pulse)
		 (oscil base (+ (env frqf) (* index (oscil modm)))))))))
448 449 450 451 452 453 454 455 456 457

(define (knudsens-frog beg amp)
  (a-frog beg .25 480 amp '(0 0 1 1 3 1 4 0) 
	  50 '(0 0 .5 .2 .8 1 1 1) 
	  (/ .25 7) '(0 .1  .5 .4  .6 .75  1 .9  1.5 1  2 .9 2.3 .1) 
	  1.75 40))  ; 0.01 here is about 1.75 as an fm index: (/ (radians->hz .01) 40)

#|
;;; cricket-like:
(with-sound (:play #t) 
458 459 460 461
  (a-frog 0 .25 2000 .5 '(0 0 1 1 3 1 4 0) ; or 3000 6000 etc
	  50 '(0 0 .5 .2 .8 1 1 1) 
	  (/ .25 5) '(0 0 1 0 5 1 8 0 20 0) 
	  0.01 40))
462 463

(with-sound (:play #t) 
464 465 466 467
  (a-frog 0 .25 4000 .5 '(0 0 1 1 3 1 4 0) 
	  0 #f
	  (/ .25 10) '(0 0 1 1 2 1 4 0 10 0) 
	  0.0 10))
468 469 470

;;; frog-like
(with-sound (:play #t) 
471 472 473 474
  (a-frog 0 .25 2000 .5 '(0 0 1 1 3 1 4 0) 
	  50 '(0 0 .5 .2 .8 1 1 1) 
	  (/ .25 10) '(0 0 1 1 2 1 3 0 4 0 5 1 7 1 8 0 20 0) 
	  0.0 10))
475 476
|#

477 478 479 480 481 482 483 484 485 486 487 488 489
(defanimal (a-cricket beg dur freq freq1 amp amp-env pulse-dur pulse-env)
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(base (make-oscil freq))
	(base1 (make-oscil freq1))
	(pulse (make-pulsed-env pulse-env pulse-dur (/ 1.0 pulse-dur)))
	(ampf (make-env amp-env :duration dur :scaler amp)))
    (do ((i start (+ i 1)))
	((= i stop))
      (outa i (* (env ampf)
		 (pulsed-env pulse)
		 (+ (* .8 (oscil base))
		    (* .2 (oscil base1))))))))
490

491
;; (with-sound (:play #t) (a-cricket 0 .12 4500 5400 .5 '(0 0 1 1 3 1 4 0) (/ .11 3) '(0 0 1 .8 5 1 6 0 15 0)))
492 493 494 495 496 497 498 499



;;; --------------------------------------------------------------------------------
;;;
;;; Oak Toad
;;;   might be slightly too much noise (the peep I worked on turned out to be a raspy one)

500 501 502 503 504 505 506 507 508 509 510 511 512
(defanimal (oak-toad beg amp)
  (let ((dur .15)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 10 1 15 0) :base .3 :duration dur :scaler amp))
	  (gen1 (make-polywave 2150 '(1 .01  2 1.0  3 .001 4 .005  6 .02)))
	  (frqf (make-env '(0 -.5 1 1 5 -1) :duration .15 :scaler (hz->radians (+ 50 (random 40)))))
	  (noise (make-rand-interp 1000 (+ .01 (random .005)))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (* (env ampf)
		   (polywave gen1 (+ (env frqf)
				     (rand-interp noise)))))))))
513 514
#|
(with-sound (:play #t)
515 516 517 518 519 520
  (let ((last-beg 0.0))
    (do ((k 0 (+ k 1)))
	((= k 12))
      (let ((beg (+ last-beg .37 (random .08))))
	(oak-toad beg (+ .25 (random .3)))
	(set! last-beg beg)))))
521 522
|#

523 524
;;; (with-sound (:play #t) (oak-toad 0 .25))

525 526 527 528 529

;;; --------------------------------------------------------------------------------
;;;
;;; Southern cricket frog

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
(defanimal (southern-cricket-frog beg amp)
  (let ((dur1 .03)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur1)))
	  (ampf (make-env '(0 0 .75 1 5 1 10 0) :scaler amp :duration dur1))
	  (gen1 (make-oscil 3500))
	  (gen2 (make-oscil 6400))
	  (pulse (make-pulsed-env '(0 .1 1 .6 2 .8 3 1 6 .1 8 .1) (/ dur1 8) (/ 8 dur1)))
	  (index (hz->radians 300))
	  (f1 (make-env '(0 .9 9 .9 10 0) :duration dur1))
	  (f2 (make-env '(0 .05  8 .1  10 .8  11 .1) :duration dur1))
	  (fm (make-oscil 150)))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((fm1 (* index (oscil fm))))
	  (outa i (* (env ampf)
		     (pulsed-env pulse)
		     (+ (* (env f1) (oscil gen1 fm1))
			(* (env f2) (oscil gen2 (* 2 fm1)))))))))))
549

550
;; (with-sound (:play #t) (southern-cricket-frog 0 0.5))
551 552 553 554 555 556


;;; --------------------------------------------------------------------------------
;;;
;;; Northern leopard frog (2)

557
(defanimal (northern-leopard-frog-1 beg amp)
558
  ;; this is slightly low-passed, and I don't quite have the vowel right at the end
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
  (let ((dur 4.2))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (gen1 (make-oscil 440))
	  (gen2 (make-oscil 1030)) ; there's also a 1500 formant that follows the 1000 case -- looks a lot like FM index 1 ca 600Hz
	  (gen3 (make-oscil 2600))
	  (pulsef1 (make-env '(0 0 .1 1 10 0) :duration .013 :base 32.0))
	  (pulsef2 (make-env '(0 0 4 1 10 0) :duration .013 :base 3.0))
	  (interpf (make-env '(0 0 6 1 8 1 10 .5) :duration dur))
	  (ampf (make-env '(0 0 3 1 9.5 1 10 0) :base .2 :duration dur :scaler amp))
	  (gen1f (make-env '(0 1 8 1 10 0) :duration dur :scaler .65 :base 3))
	  (gen2f (make-env '(0 0 8 0 10 1) :duration dur :scaler (hz->radians 90)))
	  (gen3f (make-env '(0 1 6 1 10 0) :duration dur :offset (hz->radians 2200) :scaler (hz->radians 400)))
	  (gen4f (make-env '(0 0 8 0 10 .02) :duration dur))
	  (gen5f (make-env '(0 0 5 0 10 -1) :duration dur :scaler (hz->radians 200)))
	  (pulf (make-env (list 0.0 (/ 1.0 14.0)  2.0 (/ 1.0 11.0)  10.0  (/ 1.0 11.0)) :duration dur))
	  (gen6 (make-polywave 170 '(1 .075)))
	  (pulse-samps (seconds->samples 0.013)))

      (let ((pulse-sep (seconds->samples (env pulf))))
	(do ((i start (+ i pulse-sep)))
	    ((>= i stop))
	  (let ((pstop (+ i pulse-samps)))
	    
	    (set! (mus-location interpf) (- i start))
	    (set! (mus-location ampf) (- i start))
	    (set! (mus-location gen1f) (- i start))
	    (set! (mus-location gen2f) (- i start))
	    (set! (mus-location gen3f) (- i start))
	    (set! (mus-location gen4f) (- i start))
	    (set! (mus-location gen5f) (- i start))
	    
	    (let ((intrp (env interpf))
		  (gen1trp (env gen1f))
		  (gen2trp (env gen2f))
		  (gen3trp (env gen3f))
		  (gen4trp (env gen4f))
		  (gen5trp (env gen5f))
		  (pulse-amp (env ampf)))
	      (let ((intrp-1 (- 1.0 intrp))
		    (gen1trp-1 (- 1.0 gen1trp))
		    (gen4trp-1 (- 1.0 gen4trp)))
		(do ((k i (+ k 1)))
		    ((= k pstop))
		  (outa k (* pulse-amp
			     (+ (* intrp (env pulsef1))
				(* intrp-1 (env pulsef2)))
			     (+ (* gen1trp (oscil gen2 gen5trp))
				(* gen1trp-1 (+ (* gen4trp-1 (oscil gen1 gen2trp))
						(* gen4trp (oscil gen3 (+ gen3trp
									  (polywave gen6))))))))))))
610
	    (for-each mus-reset (vector pulsef1 pulsef2 gen1 gen2))
611 612
	    (set! (mus-location pulf) (- (+ i pulse-sep) start))
	    (set! pulse-sep (seconds->samples (env pulf)))))))))
613 614

;; (with-sound (:statistics #t :play #t) (northern-leopard-frog-1 0 .5))
615 616


617
(defanimal (northern-leopard-frog-2 beg amp)
618
  ;; rocky 57 2
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
  (let ((start (seconds->samples beg))
	(dur 1.53)
	(pulse-dur .03))
    (let ((stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples .045))
	  (pulse-out (seconds->samples pulse-dur))
	  (ampf (make-env '(0.000 0.108 0.118 0.596 0.167 0.719 0.357 0.827 0.604 0.838 0.745 0.912 0.860 1.000 0.929 0.962 0.984 0.831 1.000 0.000)
			  :duration dur :scaler amp))
	  
	  (frqf2 (make-env '(0.000 0.198 0.021 0.209 0.110 0.239 0.178 0.239 0.294 0.247 0.343 0.260 0.463 0.255 
				   0.593 0.265 0.704 0.252 0.788 0.244 0.881 0.228 0.941 0.204 1.000 0.18)
			   :duration dur :scaler 6100.0))
	  (frqf1 (make-env '(0.000 0.086 0.462 0.110 1.000 0.118)
			   :duration dur :scaler 6100.0))
	  (frqf3 (make-env '(0.000 0.721 0.508 0.786 0.698 0.761 0.876 0.689 0.935 0.563 1.000 0.509)
			   :duration dur :scaler 6100.0))
	  (frqf4 (make-env '(0 7200 .5 7600 .9 7000 1 5400) :duration dur))
	  
	  (frm1 (make-formant 900 .995))
	  (frm2 (make-formant 1260 .99))
	  (frm3 (make-formant 4500 .99))
	  (frm4 (make-formant 7200 .9))
	  
642 643 644 645
	  (ampfr1 (make-env '(0 .5 1 3) :duration dur :scaler (* 10 (sin (hz->radians 900))) :base 3))
	  (ampfr2 (make-env '(0 .25 .5 .4 1 1) :duration dur :scaler (* 10 (sin (hz->radians 1260)))))
	  (ampfr4 (make-env '(0 0 .3 1 1 1) :duration dur :scaler (* 10 (sin (hz->radians 7200)))))
	  (ampfr3 (* 10 (sin (hz->radians 4500))))
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
	  
	  (gen1 (make-rk!cos 100 13.0))
	  (ampf1 (make-env '(0 1 1 0) :base 3 :duration dur))
	  
	  (pulsef (make-env '(0.000 0.000 0.01 1  0.15 0.936  0.2 0.100  0.792 0.000 0.906 0.107 1.000 0.000)
			    :duration pulse-dur))
	  (pulse-frqf (make-env '(0 0 1 .9 2 1 ) :base .1 :duration pulse-dur :scaler (hz->radians 100))))

      (let ((fb (vector frm1 frm2 frm3 frm4))
	    (fs (float-vector 0.0 0.0 ampfr3 0.0))
	    (rk (make-float-vector pulse-out)))
	(set! fb (make-formant-bank fb fs))

	(do ((i start (+ i pulse-samps)))
	    ((>= i stop))
	  
	  (set! (mus-location ampf) (- i start))
	  (set! (mus-location ampf1) (- i start))
	  (set! (mus-location ampfr1) (- i start))
	  (set! (mus-location ampfr2) (- i start))
	  (set! (mus-location ampfr4) (- i start))
	  
	  (set! (mus-location frqf1) (- i start))
	  (set! (mus-location frqf2) (- i start))
	  (set! (mus-location frqf3) (- i start))
	  (set! (mus-location frqf4) (- i start))
	  (set! (mus-location ampfr1) (- i start))
	  (set! (mus-location ampfr2) (- i start))
	  (set! (mus-location ampfr4) (- i start))
	  
	  (set! (mus-frequency frm1) (env frqf1))
	  (set! (mus-frequency frm2) (env frqf2))
	  (set! (mus-frequency frm3) (env frqf3))
	  (set! (mus-frequency frm4) (env frqf4))
	  
	  (let ((reset-stop (min stop (+ i pulse-out)))
		(pulse-amp (env ampf))
		(val-amp (env ampf1)))
	    
	    (set! (fs 0) (env ampfr1))
	    (set! (fs 1) (env ampfr2))
	    (set! (fs 3) (env ampfr4))
	    
	    (do ((k 0 (+ k 1)))
		((= k pulse-out))
	      (set! (rk k) (rk!cos gen1 (env pulse-frqf))))
	    
	    (do ((k i (+ k 1)))
		((= k reset-stop))
	      (let ((val (* pulse-amp
			    (env pulsef)
			    (rk (- k i)))))
			    ;(rk!cos gen1 (env pulse-frqf)))))
		(outa k (+ (* val val-amp)
			   (formant-bank fb val)))))
	    
	    (set! (mus-phase gen1) (* -0.1 pi))
	    (mus-reset pulse-frqf)
	    (mus-reset pulsef)))))))
705

706
;; (with-sound (:play #t :statistics #t) (northern-leopard-frog-2 0 .5))
707 708 709 710 711 712 713



;;; --------------------------------------------------------------------------------
;;;
;;; Green tree-frog

714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
(defanimal (green-tree-frog beg amp)
  (let ((dur 0.2)
	(pitch 277)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 1 1 8 1 12 0) :scaler (* .333 amp) :duration dur))
	  (gen2770 (make-oscil (* 10 pitch) (* 0.5 pi)))
	  (mod277 (make-oscil pitch (* 0.5 pi)))
	  (gen7479 (make-oscil (* pitch 27)))
	  (poly (make-polywave pitch (list 3 (* .78 .3)  8 (* .78 .2)  9 (* .78 .2)  10 (* .78 .9)  11 0.78  12 (* .78 .5))))
	  (poly2 (make-polywave 860 (list  1 (* .25 .4)  2 (* .25 .1)  3 (* .25 .03)  4 (* .25 .3)  5 (* .25 .03))))
	  (index (hz->radians 277))
	  (frqf (make-env '(0 -.3  1 .3  2 0  5 0  6 -1) :duration dur :scaler (hz->radians 70)))
	  (pulsef (make-pulsed-env '(0 .2 1 1 3 .7 5 .2) (/ 1.0 pitch) pitch)))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((md (* index (oscil mod277)))
731
	      (frq (env frqf)))
732 733 734 735 736 737
	  (outa i (* (env ampf)
		     (pulsed-env pulsef frq)
		     (+ (polywave poly frq)
			(* .2 (oscil gen2770 (* 10 (+ frq md))))
			(* .02 (oscil gen7479 (* 27 (+ frq md))))
			(polywave poly2 (* 3.0 frq))))))))))
738

739
;; (with-sound (:play #t) (green-tree-frog 0 .5))
740 741 742 743 744 745


;;; --------------------------------------------------------------------------------
;;;
;;; Pinewoods tree-frog

746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
(defanimal (pinewoods-tree-frog beg dur amp)
  (let ((pitch 205.0)
	(pulse-dur .009)
	(start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur))))
    (let ((pulsef (make-env '(0.000 0.000 0.065 0.5 0.117 0.85 0.179 1.0 0.236 0.9 0.503 0.4 0.606 0.2 1.000 0.000) :duration pulse-dur))
	  (pulses (if (> (random 1.0) .6) 5 4))
	  (pulse-amps (apply vector (map (lambda (x) (* amp x)) '(.7 .9 1.0 .9 .6))))
	  
	  (gen1 (make-oscil (* pitch 10) (* 0.5 pi)))
	  (gen3 (make-oscil (* pitch 18) (* 0.5 pi)))
	  (gen4 (make-oscil (* pitch 28) (* 0.5 pi)))

	  (pulse-samps (seconds->samples pulse-dur))
	  (pulse-sep (seconds->samples 0.078))
	  
	  (rnd (make-rand-interp (* 10 pitch) (hz->radians (* 3 pitch))))) ; not sure this actually helps
      (do ((i start (+ i pulse-sep)))
	  ((>= i stop))
	(do ((pulse 0 (+ pulse 1))
	     (pulse-start i (+ pulse-start pulse-samps)))
	    ((= pulse pulses))
	  (let ((pulse-amp (pulse-amps pulse))
		(pulse-stop (+ pulse-start pulse-samps)))
770
	    (set! (mus-frequency gen1) (* pitch (if (< pulse 3) 10 11)))
771 772 773 774 775 776 777
	    (do ((k pulse-start (+ k 1)))
		((= k pulse-stop))
	      (let ((noise (rand-interp rnd)))
		(outa k (* pulse-amp
			   (env pulsef)
			   (+ (* .9 (oscil gen1 (* .1 noise)))
			      (* .08 (oscil gen3 (* .18 noise)))
778 779 780 781 782
			      (* .02 (oscil gen4 (* .28 noise)))))))))
	  (mus-reset pulsef)
	  (set! (mus-phase gen1) (* 0.5 pi))
	  (set! (mus-phase gen3) (* 0.5 pi))
	  (set! (mus-phase gen4) (* 0.5 pi)))
783 784
	
	(set! pulses (if (> (random 1.0) .6) 5 4))))))
785

786
;; (with-sound (:play #t) (pinewoods-tree-frog 0 1 .5))
787 788 789 790 791 792


;;; --------------------------------------------------------------------------------
;;;
;;; Squirrel tree frog

793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
(defanimal (squirrel-tree-frog beg dur amp)
  (let ((pitch 120)
	(pulse-dur 0.24))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  
	  (gen1 (make-blackman pitch 4))
	  (gen2 (make-oscil (* 10 pitch)))
	  (gen3 (make-oscil (* 24 pitch)))
	  (gen4 (make-polywave pitch (list 1 (hz->radians .1))))
	  (gen5 (make-oscil (* 14 pitch)))
	  (gen6 (make-oscil (* 6 pitch)))
	  
	  (rnd (make-rand-interp 100 (hz->radians 5)))
	  (frqf (make-env '(0 0  .2 0 .4 .75  .8 1  1.0 .5) :duration pulse-dur :scaler (hz->radians 15)))
	  (pulsef (make-env '(0 0 .5 .7 2 1 3.5 .7 4 0) :duration pulse-dur :scaler amp))
	  (pulse-samps (seconds->samples 0.52))
	  (pulse-out (seconds->samples pulse-dur))
	  (indf (make-env '(0 .3 1 .5 2 .5 3 0) :duration pulse-dur))
	  (indf-1 (make-env '(0 .3 1 .5 2 .5 3 0) :offset 1.0 :scaler -1.0 :duration pulse-dur)))

      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (let ((ind (+ (env frqf)
			  (polywave gen4)
			  (rand-interp rnd))))
	      (outa k (* (env pulsef)
			 (blackman gen1)
			 (+ (* (env indf) (oscil gen2 (* 10.0 ind)))
			    (* (env indf-1) (oscil gen3 (* 24.0 ind)))
			    (* .1 (oscil gen5 (* 14.0 ind)))
			    (* .1 (oscil gen6 (* 6.0 ind))))))))
828
	  (for-each mus-reset (vector frqf pulsef indf-1 indf)))))))
829 830 831

;;; (with-sound (:play #t) (squirrel-tree-frog 0 1.0 .5))

832 833 834 835 836 837


;;; --------------------------------------------------------------------------------
;;;
;;; Ornate chorus frog

838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
(defanimal (ornate-chorus-frog beg dur amp)
  (let ((pulse-dur 0.024)
	(pitch 1210)
	(start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur))))
    (let ((pulsef (make-env '(0.000 0.000 0.057 0.445 0.124 0.797 0.220 0.977 0.337 1.000 0.477 0.987 0.634 0.907 0.760 0.791 0.828 0.475 0.913 0.206 1.000 0.000)
			    :scaler amp :duration pulse-dur))
	  (gen1 (make-polywave pitch '(1 .02  2 .95  3 .01  4 .02  5 .01 6 .04 7 .01 8 .02)))
	  (next-pulse (seconds->samples .4))
	  (pulse-samps (seconds->samples pulse-dur)))

      (do ((i start (+ i next-pulse)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-samps))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef) (polywave gen1))))
	  (mus-reset pulsef)
856
	  (set! next-pulse (seconds->samples (if (> (random 1.0) .8) (+ .25 (random .3)) .4))))))))
857

858
;; (with-sound (:play #t) (ornate-chorus-frog 0 4 .5))
859 860 861 862 863 864


;;; --------------------------------------------------------------------------------
;;;
;;; Spring peeper

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
(defanimal (spring-peeper beg amp)
  (let ((dur 0.17)
	(pause 0.23)
	(dur2 .13)
	(index (hz->radians (* 0.1 2900))))
    ;; first note
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 .25 .6 8 1 10 .8 10.5 0) :scaler amp :duration dur :base .03))
	  (gen1 (make-oscil 2400))
	  (gen2 (make-oscil 1200))
	  (gen2a (make-oscil 2400))
	  (frqf (make-env '(0 0 1 1) :scaler (hz->radians 600) :duration dur :base 30.0)))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((frq (env frqf)))
	  (outa i (* (env ampf)
		     (oscil gen1 (+ frq 
				    (* index
				       (+ (* 0.2 (oscil gen2 (* 0.5 frq))) 
					  (* 1.5 (oscil gen2a frq)))))))))) ; end is not quite right (original has a catch)
      ;; second note
      (let ((start2 (+ stop (seconds->samples pause))))
	(let ((stop2 (+ start2 (seconds->samples dur2)))
	      (ampf2 (make-env '(0 0 .125 .8 1 .9 2 .7 4 1 10 0) :base .1 :duration dur2 :scaler (* .4 amp)))
	      (frqf2 (make-env '(0 0 2 1 3 .75) :duration dur2 :base .03 :scaler (hz->radians 300)))
	      (gen3 (make-oscil 2900))
	      (gen4 (make-oscil 1450)))
	  (do ((i start2 (+ i 1)))
	      ((= i stop2))
	    (let ((frq (env frqf2)))
	      (outa i (* (env ampf2)
			 (oscil gen3 (+ frq (* index (oscil gen4 (* 0.5 frq))))))))))))))

;; (with-sound (:play #t) (spring-peeper 0 .5))
900 901 902 903 904 905


;;;--------------------------------------------------------------------------------
;;;
;;; Crawfish frog

906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
(defanimal (crawfish-frog beg amp)
  (let ((dur 0.6)
	(pitch 58))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 4 1 8 1 9 .7 10 0) :scaler amp :duration dur))
	  (pulse-samps (seconds->samples (/ 1.0 pitch)))
	  (pulsef (make-env '(0 0 1 1 10 0) :base 32.0 :duration (/ 1.0 pitch)))
	  (fmd (make-oscil pitch))
	  (gen1 (make-oscil (* pitch 15)))
	  (frqf (make-env '(0 .5  .2 0  1 1) :scaler (hz->radians pitch) :base 10.0 :duration dur))
	  (index (hz->radians pitch))
	  (poly1 (make-polywave (* pitch 6) '(1 .5  2 1  5 .5)))
	  (poly2 (make-polywave (* pitch 6) '(2 .5  3 1  7 .25)))
	  (intrp (make-env '(0 1 1 0) :duration dur :scaler .2 :base 4))
	  (intrp-1 (make-env '(0 0 1 1) :duration dur :scaler .2 :base .25)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
	(let ((reset-stop (min stop (+ i pulse-samps)))
	      (pulse-amp (env ampf)))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (let ((frq (env frqf)))
	      (outa k (* pulse-amp
			 (env pulsef)
			 (+ (* .5 (oscil gen1 (+ frq (* index (oscil fmd (* frq .067))))))
			    (* (env intrp) (polywave poly1 frq))
934 935 936 937
			    (* (env intrp-1) (polywave poly2 frq))))))))
	(mus-reset pulsef)
	(mus-reset gen1)
	(mus-reset fmd)))))
938 939

;; (with-sound (:play #t) (crawfish-frog 0 .5))
940 941 942 943 944 945 946 947 948


;;; --------------------------------------------------------------------------------
;;;
;;; River frog
;;;
;;; original formants were much sharper, but using rxyk!cos to sharpen ours didn't seem to help
;;; animal seems to group these in 3's

949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
(defanimal (river-frog beg amp)
  (let ((dur 1.85)
	(pulse-pitch 42)
	(mid-pitch 185)
	(mid-pitch-change 10))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 2 1  7 .9  10 0) :scaler amp :duration dur :base .1))
	  (pulsef #f)
	  (pulse-samps (seconds->samples (/ 1.0 pulse-pitch)))
	  (frqf (make-env '(0 .1 .2 -.02 .5 0 .65 0 1 1) :scaler (hz->radians mid-pitch-change) :duration dur))
	  (vib (make-rand-interp 100 (hz->radians 10.0)))
	  (fm (make-polywave pulse-pitch (list 1 (hz->radians pulse-pitch)) mus-chebyshev-second-kind))
	  ;; cheb2 is needed here to match the original code which used (* index (oscil fm))
	  ;; if cheb1, the main sideband is below rather than above, giving the frog a deeper call
	  ;; does this make any sense?!?
	  (poly1 (make-polywave mid-pitch (normalize-partials '(2 1.2  4 .1  7 0.75  8 .1       10 .5))))
	  (poly2 (make-polywave mid-pitch (normalize-partials '(2 1.0        7 .5         9 .7        12 .01))))
	  (interpf (make-env '(0 0 2 0 5 1 7 1) :duration dur))
	  (interpf-1 (make-env '(0 0 2 0 5 1 7 1) :duration dur :offset 1.0 :scaler -1.0)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
	(let ((reset-stop (min stop (+ i pulse-samps)))
	      (pulse-amp (env ampf)))
	  (set! pulsef (make-env '(0 .1 3 .1 3.1 1 4 1 6 .1 9 .1) :scaler pulse-amp :duration (/ 1.0 pulse-pitch)))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (let ((frq (+ (env frqf)
			  (rand-interp vib)
			  (polywave fm))))
	      (outa k (* (env pulsef)
			 (+ (* (env interpf-1) (polywave poly1 frq))
			    (* (env interpf) (polywave poly2 frq))))))))))))


;;; pulsed-env here was basically the same speed as using the nested do loop
;;;   pulsed-env doesn't buy us anything if there's no run-time modulation

;; (with-sound (:play #t :statistics #t) (river-frog 0 .5))
989 990 991 992 993 994


;;; --------------------------------------------------------------------------------
;;;
;;; Bullfrog

995 996 997 998 999 1000 1001
(defanimal (bullfrog beg amp)
  (let ((start (seconds->samples beg))
	(dur 0.81))
    (let ((stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 1 1 2 1 3 0) :duration dur :scaler amp :base 10))
	  (frqf (make-env '(0 0  1 6  2 0) :duration dur :scaler (hz->radians 1.0)))
	  
1002 1003
	  (f1 (make-rxyk!cos 200 1/2 0.6))
	  (f2 (make-rxyk!cos 230 10/23 1.2))
1004
	  
1005 1006
	  (f3 (make-rxyk!cos 600 1/6 8.0))
	  (f4 (make-rxyk!cos 630 10/63 8.0))
1007 1008 1009 1010 1011 1012 1013 1014
	  
	  (rnd (make-rand-interp 4000 .2))
	  (rnd1 (make-rand-interp 200 (hz->radians 2)))
	  
	  (frm1 (make-formant 400 .99))
	  (frm2 (make-formant 1200 .98))
	  (frm3 (make-formant 5000 .97))
	  
1015 1016 1017
	  (frm1f (* 14 (sin (hz->radians 400))))
	  (frm2f (* 28 (sin (hz->radians 1200))))
	  (frm3f (* 8 (sin (hz->radians 5000))))
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
	  
	  (intrpf (make-env '(0 1 .6 0 1 1) :offset 1000.0 :scaler 200.0 :duration dur)))

      (let ((fb (vector frm1 frm2 frm3))
	    (fs (float-vector frm1f frm2f frm3f)))
	(set! fb (make-formant-bank fb fs))

	(do ((i start (+ i 1)))
	    ((= i stop))
	  (let ((frq (+ (env frqf)
			(rand-interp rnd1))))
	    (mus-set-formant-frequency frm2 (env intrpf))
	    (outa i (formant-bank fb (* (env ampf)
					(+ .8 (rand-interp rnd))
					(+       (rxyk!cos f1 (* 2.0 frq))
					   (* .5 (rxyk!cos f2 (* 2.3 frq)))
					   (* .1 (rxyk!cos f3 (* 6.0 frq)))
					   (* .1 (rxyk!cos f4 (* 6.3 frq)))))))))))))

;; (with-sound (:statistics #t) (bullfrog 0 .5))
1038 1039 1040 1041 1042 1043 1044


;;; --------------------------------------------------------------------------------
;;;
;;; Texas toad

(define (texas-toad beg1 dur1 amp1)
1045
  
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
  (defanimal (texas-toad-1 beg dur amp)
    (let ((pulse-dur .0173))
      (let ((start (seconds->samples beg))
	    (stop (seconds->samples (+ beg dur)))
	    (gen (make-polywave 2460 '(1 .9  2 .01  3 .05  4 .005  5 .01)))
	    (pulsef (make-env '(0 0 1 1 3 1 4 0) :duration pulse-dur :scaler amp))
	    (pulse2 (make-blackman (/ 4.0 pulse-dur) 2))
	    (pulse-samps (seconds->samples .02666))
	    (pulse-out (seconds->samples pulse-dur))
	    (rnd (make-rand-interp 4000 (hz->radians 200))))
	(do ((i start (+ i pulse-samps)))
	    ((>= i stop))
	  (let ((reset-stop (+ i pulse-out)))
	    (if (<= reset-stop stop)
		(do ((k i (+ k 1)))
		    ((= k reset-stop))
		  (outa k (* (env pulsef)
			     (blackman pulse2)
			     (polywave gen (rand-interp rnd))))))
	    (mus-reset pulsef)
	    (mus-reset pulse2))))))
1067
  
1068
  (let ((last-dur 0.0)
1069
	(last-call (+ beg1 dur1 -0.4)))
1070 1071 1072 1073 1074
    (do ((call-beg beg1 (+ call-beg last-dur 0.3 (random 0.2))))
	((>= call-beg last-call))
      (set! last-dur (+ .6 (random .25)))
      (texas-toad-1 call-beg last-dur amp1))))

1075
;; (with-sound (:play #t) (texas-toad 0 2.0 0.5))
1076 1077 1078 1079 1080 1081


;;; --------------------------------------------------------------------------------
;;;
;;; American toad

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
(defanimal (american-toad beg dur amp)
  (let ((pulse-dur .024)
	(pulse-sep .045)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples pulse-sep))
	  (pulse-out (seconds->samples pulse-dur))
	  (ampf (make-env '(0 0.05 4 1 20 1 21 0) :duration dur :scaler amp))
	  (gen1 #f)
	  (frqf (make-env '(0 150 .1 250 .5 300 .9 200 1 0) :duration pulse-dur :scaler (hz->radians 1.0)))
	  (pulsef (make-env '(0.000 0.000 0.147 0.700 0.261 0.968 0.405 0.996 0.601 0.830 0.878 0.198 1.000 0.000) :duration pulse-dur))
	  (pulse-frqf (make-env (list 0 1100 .4 1300 dur (- 1300 (* dur 8))) :duration dur :scaler (hz->radians 1.0))))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
1097 1098 1099 1100 1101 1102 1103 1104
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (let ((pulse-amp (env ampf)))
	    (set! gen1 (make-polywave 0.0 (list 1 (* pulse-amp .94)  
						2 (* pulse-amp .03)  
						3 (* pulse-amp .01)  
						4 (* pulse-amp .003) 
						5 (* pulse-amp .005)  
						7 (* pulse-amp .002)))))
1105 1106 1107 1108 1109 1110 1111 1112
	  (set! (mus-location ampf) (- i start))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef)
		       (polywave gen1 (+ (env frqf)
					 (env pulse-frqf))))))
	  (mus-reset pulsef)
	  (mus-reset frqf))))))
1113

1114
;; (with-sound (:play #t) (american-toad 0 2 .25))
1115 1116 1117 1118 1119 1120


;;; --------------------------------------------------------------------------------
;;;
;;; Plains spadefoot

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
(defanimal (plains-spadefoot beg amp)
  (let ((dur 0.73)
	(pulse-dur .019)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples pulse-dur))
	  (ampf (make-env '(0.000 0.000 0.098 0.423 0.310 0.747 0.630 0.929 0.785 0.830 0.902 0.553 1.000 0.000) :scaler amp :duration dur))
	  (gen1 (make-oscil))
	  (gen2 #f)
	  (ampf2 (make-env '(0 0 .3 0 .8 1 1 1) :duration dur :scaler 0.4))
	  (frqf (make-env '(0 1520  .4 1650 1 1630) :duration dur :scaler (hz->radians 1.0)))
	  (pulsef #f) 
	  (rnd (make-rand-interp 100 (hz->radians 100))))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
	(set! (mus-location frqf) (- i start))
	(set! (mus-location ampf2) (- i start))
	(let ((reset-stop (min stop (+ i pulse-samps)))
	      (pulse-amp (env ampf))
	      (pulse-amp2 (env ampf2))
	      (pulse-frq (env frqf)))
1143 1144 1145 1146 1147 1148 1149 1150
	  (set! gen2 (make-polywave 0.0 
				    (if (= pulse-amp2 0.0)
					(list 1 0.0)
					(list 1 (* pulse-amp2 .01)
					      2 (* pulse-amp2 .01) 
					      6 (* pulse-amp2 .01)
					      8 (* pulse-amp2 .1)
					      10 (* pulse-amp2 .01)))))
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
	  (set! pulsef (make-env (list 0.000 0.000  0.03 pulse-amp 0.08 pulse-amp
				       0.160 (* pulse-amp 0.486) 0.304 (* pulse-amp 0.202)
				       0.508 (* pulse-amp 0.087) 1.000 0.000)
				 :duration pulse-dur))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (let ((frq (+ pulse-frq (rand-interp rnd))))
	      (outa k (* (env pulsef)
			 (+ (oscil gen1 frq)
			    (polywave gen2 (* 0.25 frq))))))))))))
1161

1162
;; (with-sound (:play #t) (plains-spadefoot 0 .5))
1163 1164 1165 1166 1167 1168


;;; --------------------------------------------------------------------------------
;;;
;;; Barking tree-frog

1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
(defanimal (barking-tree-frog beg amp)
  (let ((dur 0.165))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0.000 0.000 0.015 0.131 0.038 0.110 0.066 0.621 0.078 0.488 0.090 0.977 0.104 0.423 
				  0.108 0.013 0.113 0.504 0.122 0.005 0.129 0.979 0.138 0.337 0.142 0.470 0.152 0.008 
				  0.156 0.561 0.160 0.008 0.165 1.000 0.177 0.535 0.183 0.744 0.189 0.290 0.193 0.731 
				  0.200 0.381 0.209 0.977 0.217 0.499 0.237 0.846 0.247 0.896 0.260 0.898 0.464 0.846 
				  0.623 0.689 0.801 0.305 1.000 0.000)
			  :duration dur :scaler amp))
	  (frqf (make-env '(0 480  .3 430 1 425) :duration dur :scaler (hz->radians 1.0)))
	  (gen1 (make-polywave 0.0 (normalize-partials '(1 .9  2 .06  3 .25  4 .79  5 .18  6 .03  7 .02  8 .03  9 .01  10 .02  11 .005 12 .005))))
	  (rnd (make-rand-interp 1000 (hz->radians 10)))
	  
	  (gen2 (make-oscil))
	  (frqf2 (make-env '(0 4750 .2 4790  .5 4710  1 4300) :duration dur :scaler (hz->radians 1.0)))
	  (attack (make-rand-interp 4000 (hz->radians 400)))
	  (gen3 (make-oscil 1720))
	  (attackf (make-env '(0.000 0.000 0.068 0.000 0.093 0.614 0.098 0.000 0.114 0.000 0.120 0.969 0.131 0.000 
				     0.155 0.000 0.159 0.997 0.175 0.000 0.198 0.000 0.2 1.000 0.224 0.000 0.241 0.000 
				     0.243 0.984 0.260 0.000 1.000 0.000)
			     :duration dur :scaler amp)))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (+ (* (env ampf)
		      (+ (polywave gen1 (+ (env frqf)
					   (rand-interp rnd)))
			 (* .02 (oscil gen2 (env frqf2)))))
		   (* (env attackf)
		      (oscil gen3 (rand-interp attack)))))))))
1199

1200
;; (with-sound (:play #t) (barking-tree-frog 0 .5))
1201 1202 1203 1204 1205 1206


;;; --------------------------------------------------------------------------------
;;;
;;; Western toad

1207
(defanimal (western-toad beg dur amp)
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
  (do ((stop (seconds->samples (+ beg dur)))
       (gen (make-polywave 0.0 '(1 .95  2 .02  3 .03  4 .005)))
       (cur-start (seconds->samples beg))
       (cur-is-long #t))
      ((>= cur-start stop))
    (let ((pulse-samps (seconds->samples (if cur-is-long 
					     (+ 0.04 (random .04)) 
					     (+ .01 (random .02))))))
      (let ((pulse-ampf (make-env (vector 0 0 (if cur-is-long 
						  (values .1 .5 2 1 3 0)
						  (values 1 1 1.5 .3 2 0)))
				  :scaler (* amp (if cur-is-long (+ .6 (random .4)) (+ .1 (random .7))))
				  :length pulse-samps
				  :base (if cur-is-long 6.0 3.0)))
	    (pulse-frqf (make-env (if cur-is-long
				      '(0 -.5 .5 0 1 -.3)
				      '(0 -1 .1 0 1 0))
				  :length pulse-samps
				  :base .1
				  :offset (hz->radians (if cur-is-long (if (> (random 1.0) .6) 1340 1260) 1200))
				  :scaler (hz->radians (random 500.0))))
	    (cur-end (+ cur-start pulse-samps)))
	(do ((i cur-start (+ i 1)))
	    ((= i cur-end))
	  (outa i (* (env pulse-ampf)
		     (polywave gen (env pulse-frqf)))))
	
	(set! cur-start (+ cur-end 
			   (seconds->samples
			    (if cur-is-long
				(+ .015 (random (if (> (random 1.0) .8) .15 .04)))
				(+ .01 (random .01))))))
	
	(set! cur-is-long (or (not cur-is-long) (> (random 1.0) .3)))))))
1242

1243
;; (with-sound (:play #t) (western-toad  0 2 .5))
1244 1245 1246 1247 1248 1249


;;; --------------------------------------------------------------------------------
;;;
;;; Southwestern toad

1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
(defanimal (southwestern-toad beg dur amp)
  (let ((pulse-dur 0.0135)
	(pulse-space 0.0236)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples pulse-space))
	  (pulse-out (seconds->samples pulse-dur))
	  (ampf (make-env (list 0 0    1.3 1   dur 1   (* 1.01 dur) 0) :duration dur :scaler amp :base .3))
	  (frqf (make-env (list 0 940  1 1230  dur 1230) :base 3.0 :duration dur :scaler (hz->radians 1.0) :offset (hz->radians -300)))
	  (gen1 #f)
	  (rnd (make-rand-interp 4000 (hz->radians 80)))
	  (pulse-ampf (make-env '(0 0 1 1 1.5 1 2 .5 3 0) :base .3 :duration pulse-dur))
	  (pulse-frqf (make-env '(0 0  .3 .8  1.5 1  2.7 .8  3 .3) :duration pulse-dur :scaler (hz->radians 300))))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
	(let ((reset-stop (min stop (+ i pulse-out)))
	      (pulse-amp (env ampf)))
	  (set! (mus-location ampf) (- i start))
	  (set! (mus-location frqf) (- i start))
	  (set! gen1 (make-polywave 0.0 (list 1 (* pulse-amp .95)  2 (* pulse-amp .02)  3 (* pulse-amp .03))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulse-ampf)
		       (polywave gen1 (+ (env frqf)
					 (env pulse-frqf)
					 (rand-interp rnd))))))
	  (mus-reset pulse-ampf)
	  (mus-reset pulse-frqf))))))
1279

1280
;; (with-sound (:play #t) (southwestern-toad 0 2 .5))
1281 1282 1283 1284 1285 1286


;;; --------------------------------------------------------------------------------
;;;
;;; Great Plains Narrow-mouthed toad

1287
(defanimal (great-plains-narrow-mouthed-toad beg dur1 amp)
1288
  ;; rocky 75 28
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
  (let ((attack-dur 0.155))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg (max dur1 0.3))))
	  
	  ;; attack portion
	  (attack-stop (seconds->samples (+ beg attack-dur)))
	  (attack-ampf (make-env '(0.000 0.000 0.015 0.078 0.020 0.289 0.042 0.000 0.057 0.000 0.069 0.409 0.093 0.425 
					 0.101 0.520 0.113 0.588 0.141 0.218 0.159 0.537 0.182 0.695 0.221 0.140 0.223 0.640 
					 0.233 0.872 0.253 0.602 0.269 0.000 0.280 0.000 0.292 0.915 0.319 0.520 0.322 0.000 
					 0.333 0.000 0.347 0.912 0.359 0.777 0.371 0.509 0.381 0.000 0.391 0.000 0.399 0.611 
					 0.407 0.948 0.428 0.475 0.433 0.000 0.448 0.000 0.468 0.905 0.491 0.206 0.504 0.000 
					 0.513 0.000 0.528 0.909 0.537 0.583 0.543 0.125 0.554 0.000 0.572 0.911 0.578 0.957 
					 0.597 0.132 0.611 0.000 0.619 0.000 0.639 0.803 0.648 0.643 0.655 0.108 0.660 0.000 
					 0.677 0.000 0.683 0.629 0.693 0.902 0.706 0.186 0.716 0.000 0.731 0.000 0.736 0.568 
					 0.747 0.985 0.767 0.000 0.790 0.000 0.791 0.358 0.804 0.666 0.818 0.145 0.825 0.000 
					 0.842 0.000 0.848 0.408 0.857 0.768 0.878 0.000 0.898 0.000 0.904 0.511 0.915 0.883 
					 0.929 0.000 0.952 0.000 0.970 0.688 0.977 0.280 0.988 0.052 1.000 0.000)
				 :duration attack-dur :scaler amp))
	  (attack-frqf (make-env '(0.000 0.124 0.037 0.145 0.060 0.205 0.067 0.152 0.091 0.132 0.107 0.145 0.126 0.175 
					 0.147 0.150 0.166 0.173 0.190 0.173 0.206 0.137 0.219 0.179 0.232 0.192 0.245 0.177 
					 0.260 0.158 0.274 0.177 0.288 0.203 0.298 0.186 0.312 0.167 0.325 0.147 0.336 0.190 
					 0.347 0.207 0.362 0.184 0.377 0.158 0.393 0.190 0.403 0.220 0.421 0.190 0.434 0.158 
					 0.453 0.197 0.465 0.229 0.480 0.199 0.496 0.169 0.515 0.197 0.525 0.218 0.532 0.194 
					 0.544 0.171 0.558 0.197 0.573 0.222 0.584 0.197 0.606 0.177 0.623 0.201 0.633 0.222 
					 0.645 0.203 0.661 0.182 0.676 0.209 0.690 0.222 0.700 0.203 0.717 0.177 0.735 0.207 
					 0.749 0.207 0.771 0.179 0.791 0.205 0.805 0.203 0.814 0.179 0.846 0.209 0.862 0.212 
					 0.869 0.186 0.912 0.207 0.969 0.220 1.000 0.218)
				 :duration attack-dur :scaler (hz->radians 8900.0)))
	  (attack-gen1 (make-polywave 0.0 '(1 .92 2 .05  3 .02  4 .01))))
      (do ((i start (+ i 1)))
	  ((= i attack-stop))
	(outa i (* (env attack-ampf)
		   (polywave attack-gen1 (env attack-frqf)))))
      
      ;; main portion
      (let ((dur (- dur1 attack-dur)))
	(let ((ampf (make-env '(0 1 1 1 10 1 11 0) :duration dur :scaler amp))
	      (frqf (make-env '(0 2000  .9 2000 1 1700) :duration dur :scaler (hz->radians 1.0)))
	      (gen1 (make-polywave 0.0 '(1 .92 2 .05  3 .02  4 .01)))
	      (frqf2 (make-env '(0 0  .1 25  4 20) :duration dur :scaler (hz->radians 1.0)))
	      (gp (make-polywave 100 '(4 1 9 1)))
	      (low-ampf (make-env (list 0 0 .2 1 dur 1) :duration dur :scaler .15))
	      (pulser (make-pulse-train 100))
	      (pulse-ampf (make-env '(0.000 0.000 0.227 0.057 0.319 0.164 0.407 0.946 0.554 0.706 0.707 0.036 0.839 0.031 
					    0.930 0.097 1.000 0.000) :duration .008))
	      (rnd (make-rand-interp 20 (hz->radians 3)))
	      (pulse-amp amp)
	      (saved-frq (make-float-vector (floor (* .03 *clm-srate*)))) ; 100 hz in pulser, so this is 3 times bigger than expected
	      (last-stop attack-stop))
	  (pulse-train pulser 0.0) ; flush the startup pulse
	  (do ((i attack-stop (+ i 1))
	       (j 0 (+ j 1)))
	      ((= i stop))
	    (if (> (pulse-train pulser (float-vector-set! saved-frq j (+ (env frqf2) (rand-interp rnd)))) 0.1)
		(begin
		  (do ((k 0 (+ k 1))
		       (n last-stop (+ n 1)))
		      ((= k j))
		    (outa n (* pulse-amp
			       (env pulse-ampf)
			       (+ (* (env low-ampf) 
				     (polywave gp (ina k saved-frq)))
				  (polywave gen1 (env frqf))))))
		  (mus-reset pulse-ampf)
		  (set! (mus-location ampf) (- i attack-stop))
		  (set! pulse-amp (env ampf))
		  (set! (mus-phase gen1) (* pi .75))
		  (set! last-stop i)
		  (set! j 0)))))))))
1358

1359
;; (with-sound (:play #t) (great-plains-narrow-mouthed-toad 0 2 .25))
1360 1361


1362

1363 1364 1365 1366
;;; --------------------------------------------------------------------------------
;;;
;;; Pacific chorus frog

1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
(defanimal (pacific-chorus-frog beg amp)
  (let ((dur 0.25))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0.000 0.000 0.011 0.147 0.023 0.131 0.028 0.034 0.059 0.000 0.063 0.153 0.067 0.113 
				  0.072 0.391 0.081 0.095 0.088 0.052 0.102 0.025 0.124 0.000 0.131 0.452 0.139 0.327 
				  0.144 0.099 0.156 0.097 0.160 0.048 0.186 0.000 0.194 0.438 0.200 0.366 0.201 0.156 
				  0.211 0.063 0.247 0.000 0.256 0.628 0.268 0.154 0.274 0.190 0.285 0.027 0.296 0.059 
				  0.309 0.031 0.312 0.481 0.322 0.939 0.331 0.314 0.351 0.061 0.363 0.099 0.374 0.056 
				  0.377 0.438 0.389 0.858 0.394 0.467 0.403 0.241 0.414 0.197 0.415 0.127 0.425 0.075 
				  0.436 0.090 0.441 0.526 0.454 0.869 0.471 0.239 0.490 0.029 0.503 0.117 0.505 0.485
				  0.514 0.811 0.528 0.415 0.538 0.088 0.552 0.056 0.561 0.106 0.580 0.075 0.597 0.000 
				  0.776 0.000 0.777 0.573 0.786 0.145 0.801 0.054 0.826 0.000 0.827 0.632 0.844 1.000 
				  0.856 0.524 0.866 0.031 0.883 0.074 0.891 0.136 0.896 0.745 0.907 0.424 0.915 0.765 
				  0.934 0.059 0.951 0.048 0.962 0.079 0.970 0.436 0.986 0.266 1.000 0.000)
			  :duration dur :scaler amp))
	  (frqf (make-env '(0.000 0.220 0.074 0.249 0.133 0.249 0.194 0.240 0.258 0.252 0.324 0.264 0.389 0.267 
				  0.456 0.270 0.520 0.264 0.847 0.270 0.920 0.273 1.000 0.279)
			  :duration dur :scaler (hz->radians (* 0.5 0.205 22050.0))))
	  (gen1 (make-polywave 0.0 '(2 .35  3 .1 4 .8  5 .01 6 .03  8 .005)))
	  (rnd (make-rand-interp 600 (hz->radians 50))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (* (env ampf)
		   (polywave gen1 (+ (env frqf)
				     (rand-interp rnd)))))))))
1393

1394
;; (with-sound (:play #t) (pacific-chorus-frog 0 .5))
1395 1396 1397 1398 1399 1400


;;; --------------------------------------------------------------------------------
;;;
;;; Red-spotted toad

1401
(defanimal (red-spotted-toad beg dur amp)
1402
  ;; rocky 23 1
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
  (let ((pulse-dur 0.0138)
	(pulse-space 0.0234)
	(start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples pulse-space))
	  (pulse-out (seconds->samples pulse-dur))
	  (ampf (make-env '(0 0 .5 .8 .8 .8 .9 1 .98 1 1 0) :duration dur :scaler amp))
	  (frqf (make-env '(0 1900 .2 2200 .4 2250 .9 2200 1 2100) :duration dur :scaler (hz->radians 1.0)))
	  (rnd (make-rand-interp 1000 (hz->radians 40)))
	  (gen1 #f)
	  (pulse-ampf (make-env '(0 0 1 1 1.25 1 2 .5 3 0) :base .3 :duration pulse-dur)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
1417 1418 1419
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (let ((pulse-amp (env ampf)))
	    (set! gen1 (make-polywave 0.0 (list 1 (* pulse-amp .99)  3 (* pulse-amp .005)))))
1420 1421 1422 1423 1424 1425 1426 1427
	  (set! (mus-location ampf) (- i start))
	  (set! (mus-location frqf) (- i start))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulse-ampf)
		       (polywave gen1 (+ (env frqf)
					 (rand-interp rnd))))))
	  (mus-reset pulse-ampf))))))
1428

1429
;; (with-sound (:play #t) (red-spotted-toad 0 4 .5))
1430 1431 1432 1433 1434 1435


;;; --------------------------------------------------------------------------------
;;;
;;; Green toad

1436
(defanimal (green-toad beg dur amp)
1437 1438
  ;; rocky 31 1
  ;;  (an experiment with wave-train in place of pulsed env)
1439 1440
  (let ((pulse (let* ((wave-len 256)
		      (v (make-float-vector wave-len))
1441
		      (pulse-ampf (make-env '(0.000 0.000 0.063 0.312 0.277 0.937 0.405 1.000 0.617 0.696 0.929 0.146 2.000 0.000) :length wave-len)))
1442 1443 1444 1445
		 (do ((i 0 (+ i 1)))
		     ((= i wave-len))
		   (set! (v i) (env pulse-ampf)))
		 v)))
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env (list 0 0  .2 .9  .3 .7  .4 1  (max .5 (- dur .01)) 1  (max .51 dur) 0) :duration dur :scaler amp))
	  (frqf (make-env (list 0 2540  .2 3250  (max .5 dur) 3200) :base 10 :duration dur :scaler (hz->radians 1.0)))
	  
	  (pulse1 (make-wave-train 56.0 :wave pulse))
	  (pulse2 (make-delay (seconds->samples .0078))) ; pulses come in pairs
	  (gen1 (make-polywave 0.0 '(1 .95  2 .04  3 .01)))
	  (rnd (make-rand-interp 100 (hz->radians 2.0)))
	  (rnd1 (make-rand-interp 1000 (hz->radians 80))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((val (wave-train pulse1 (rand-interp rnd))))
	  (outa i (* (env ampf)
		     (+ val
			(delay pulse2 val))
		     (polywave gen1 (+ (env frqf)
				       (rand-interp rnd1))))))))))
1464

1465
;; (with-sound (:play #t) (green-toad 0 1 .5))
1466 1467 1468 1469 1470 1471


;;; --------------------------------------------------------------------------------
;;;
;;; Little grass frog

1472
(defanimal (little-grass-frog beg amp)
1473
  ;; frogs 26 8.5
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
  (let ((dur .032))
    ;; initial note
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0.000 0.000 0.061 0.739 0.124 0.998 0.358 0.902 0.630 0.419 0.727 
				  0.469 0.813 0.391 0.857 0.046 0.884 0.256 0.918 0.121 1.000 0.000)
			  :duration dur :scaler amp))
	  (frqf (make-env '(0.000 0.289 0.534 0.302 0.793 0.299 1.000 0.307)
			  :duration dur :scaler (hz->radians (* 0.5 21900.0))))
	  (gen1 (make-polywave 0.0 '(1 .005  2 .97  3 .02  4 .01))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (* (env ampf)
		   (polywave gen1 (env frqf))))))
    
    ;; 4 tinks
    (let ((begs (vector 0.085 0.118 0.141 0.162))
	  (amps (vector 1.0 1.0 .8 .6))
	  (frqs (vector 6840 6940 6890 6940)))
      (do ((call 0 (+ call 1)))
	  ((= call 4))
	
	(let ((start (seconds->samples (+ beg (begs call))))
	      (dur .01))
	  (let ((stop (+ start (seconds->samples dur)))
		(ampf (make-env '(0.000 0.000 0.082 0.967 0.149 1.000 0.183 0.977 0.299 0.529 
					0.334 0.595 0.451 0.312 0.520 0.176 0.639 0.155 0.753 0.077 1.000 0.000)
				:duration dur :scaler (* amp (amps call))))
		(frq (hz->radians (* 0.5 (frqs call))))
		(gen1 (make-polywave 0.0 '(1 .005  2 .97  3 .02  4 .01))))
	    
	    (do ((i start (+ i 1)))
		((= i stop))
	      (outa i (* (env ampf)
			 (polywave gen1 frq))))))))))
1509

1510
;; (with-sound (:play #t) (little-grass-frog 0 .5))
1511 1512 1513 1514 1515 1516


;;; --------------------------------------------------------------------------------
;;;
;;; Sonoran desert toad

1517
(defanimal (sonoran-desert-toad beg dur amp)
1518
  ;; rocky 13 1
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
  (let ((start (seconds->samples beg)))
    (let ((stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0.000 0.000 0.011 0.201 0.193 0.704 0.338 0.878 0.593 0.986 0.865 0.972 0.954 0.895 
				0.970 0.645 1.000 0.000)
			  :duration dur :scaler amp))
	  (frqf (make-env '(0.000 0.360 0.069 0.387 0.144 0.411 0.500 0.428 0.649 0.432 0.746 0.425 0.877 0.435 
				0.974 0.418 1.000 0.291)
			  :duration dur :scaler (hz->radians 2800.0)))
	  (gen1 (make-oscil))
	  (gen2 (make-oscil))
	  (ampf2 (make-env (list 0 .1 .05 1 .2 .1 .3 .01 (- dur .1) .1 dur 1) :duration dur :scaler .2))
	  (gen3 (make-polywave 0.0 '(3 .5  4 .2 5 .1  6 .08  7 .05  9 .03)))
	  (ampf3 (make-env (list 0 .2  .1 1 (- dur .2) 1  dur .5) :duration dur :scaler .1))
	  (rnd (make-rand-interp 4000 (hz->radians 200)))
	  
	  (env1 (vector 0 0  .6 1   1 0))
	  (env2 (vector 0 0  .3 .7  .5 1  .8 .9  1 0))
	  (env3 (vector 0 0  .2 .7 .3 .1 .5 1 .7 .8 1 0))
	  
	  (next-pulse start)
	  (pulse-samps 0)
	  (pulse-ampf #f))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(if (>= i next-pulse)
	    (let ((pulse-dur (+ .01 (random .003)))
		  (env-choice (random 3)))
	      (set! pulse-ampf (make-env (if (= env-choice 0) env1
					     (if (= env-choice 1) env2
						 env3))
					 :duration pulse-dur
					 :scaler (+ .7 (random .3))))
	      (set! pulse-samps (seconds->samples (+ pulse-dur (random 0.005))))
	      (set! next-pulse (+ next-pulse pulse-samps))))
	(set! (mus-location ampf) (- i start))
	(set! (mus-location frqf) (- i start))
	(let ((pulse-end (+ i pulse-samps))
	      (pulse-amp (env ampf))
	      (pulse-frq (env frqf)))
	  (do ((k i (+ k 1)))
	      ((= k pulse-end))
	    (let ((frq (+ pulse-frq
			  (rand-interp rnd))))
	      (outa k (* pulse-amp
			 (env pulse-ampf)
			 (+ (* .7 (oscil gen1 frq))
			    (* (env ampf2) (oscil gen2 (* 2.0 frq)))
			    (* (env ampf3) (polywave gen3 frq))))))))))))
1567

1568
;; (with-sound (:play #t) (sonoran-desert-toad 0 .8 .5))
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578



;;; --------------------------------------------------------------------------------
;;;
;;; Amargosa toad

(define (amargosa-toad beg1 amp1)
  ;; rocky 17 0
  
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
  (defanimal (amargosa-toad-1 beg dur frqscl frqenv ampscl ampenv)
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env ampenv :duration dur :scaler ampscl))
	  (frqf (make-env frqenv :duration dur :scaler (hz->radians frqscl)))
	  (gen1 (make-polywave 
		 :partials 
		 (normalize-partials 
		  '(1 1  2 .18  3 .19  4 .04  5 .03  6 .04  8 .01  9 .01 10 .005 11 .01 12 .005)))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (* (env ampf)
		   (polywave gen1 (env frqf)))))))
  
  (let ((begs (vector 0.0 0.15 0.325 0.47 0.61))
	(durs (vector 0.027 0.06 0.065 0.042 0.05))
	(amps (vector 0.9 1.0 1.0 0.4 0.1))
1596
	(frqs (vector 14800 14020 14800/3 14800 7400))
1597
	 
1598 1599
	 (ampenvs (vector '(0.000 0.000 0.085 0.906 0.117 1.000 0.328 0.909 0.715 0.464 0.892 0.118 1.000 0.000)
			  '(0.000 0.000 0.025 1.000 0.056 0.201 0.121 0.848 0.151 0.503 0.217 0.395 0.441 0.556 
1600
				  0.602 0.868 0.642 0.870 0.734 0.726 0.808 0.456 0.964 0.141 1.000 0.000)
1601
			  '(0.000 0.000 0.026 0.053 0.047 1.000 0.063 0.809 0.079 0.181 0.106 0.637 0.151 0.442 
1602 1603
				  0.180 0.604 0.346 0.507 0.463 0.511 0.582 0.694 0.641 0.663 0.697 0.519 0.744 0.331 
				  0.806 0.087 1.000 0.000)
1604
			  '(0.000 0.000 0.037 0.108 0.070 1.000 0.090 0.700 0.117 0.067 0.144 0.462 0.166 0.523 
1605
				  0.209 0.168 0.234 0.410 0.639 0.278 0.823 0.373 1.000 0.000)
1606
			  '(0.000 0.000 0.091 0.302 0.184 0.083 0.243 0.639 0.286 0.120 0.364 0.465 0.570 0.187 
1607
				  0.739 0.434 1.000 0.000)))
1608 1609 1610
	 (frqenvs (vector '(0.000 0.075 0.317 0.073 1.000 0.065)
			  '(0.000 0.076 0.031 0.106 0.064 0.085 0.098 0.073 0.158 0.079 0.821 0.076 1.000 0.067)
			  '(0.000 0.201 0.050 0.209 0.090 0.213 0.257 0.217 0.377 0.215 0.486 0.221 0.548 0.231 
1611
				  0.669 0.233 0.751 0.225 0.852 0.215 1.000 0.227)
1612 1613
			  '(0.000 0.071 0.063 0.081 0.097 0.083 0.155 0.073 0.195 0.069 0.832 0.069 1.000 0.053)
			  '(0.000 0.120 0.132 0.128 0.218 0.126 0.272 0.120 0.326 0.120 0.513 0.120 0.730 0.118 
1614
				  1.000 0.096))))
1615
    (do ((call 0 (+ call 1)))
1616
	((= call 5))
1617
      (amargosa-toad-1 
1618 1619 1620 1621 1622 1623
       (+ beg1 (begs call))
       (durs call)
       (frqs call)
       (frqenvs call)
       (* amp1 (amps call))
       (ampenvs call)))))
1624

1625
;; (with-sound (:play #t) (amargosa-toad 0 .5))
1626 1627 1628 1629




1630 1631 1632 1633 1634 1635 1636 1637
;;; ================ Mammals ================
;;;
;;;
;;; Indri
;;;
;;; close in spectrum, amp, freq, but the original has what sounds like a ton of reverb
;;;   if I add the reverb, it's close -- is this really what this animal sounds like?

1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
(defanimal (indri beg amp)
  (let ((pitch 900)
	(dur 1.5))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (gen1 (make-polywave (* 2 pitch) '(1 .9)))
	  (gen4 (make-polywave pitch '(1 .125)))
	  (gen2 (make-polywave (* 8 pitch) '(1 .1)))
	  (gen3 (make-polywave pitch '(1 .2)))
	  (ampf (make-env '(0.0 0.0  0.05 0.4  0.1 0.65  0.2 0.5  0.27 1.0  0.4 0.43  0.43 0.53 
				0.5 0.5  0.53 0.36  0.6 1.0  0.64 0.99  0.69 0.6  0.7 0.3  0.77 0.15 
				0.8 0.04  1.0 0.0) :duration dur :scaler amp))
	  (frqf (make-env '(0 1  2 0  6 0 7 3 9 3) :scaler (hz->radians 60) :duration dur))
	  (vib (make-polywave 2 (list 1 (hz->radians 10)))))

      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((frq (+ (env frqf) (polywave vib))))
	  (outa i (* (env ampf)
		     (+ (polywave gen1 (+ (* 2.0 frq)
					  (polywave gen4 frq)))
			(polywave gen2 (+ (* 8.0 frq) 
					  (polywave gen3 frq)))))))))))

;; (with-sound (:play #t) (indri 0 .5))
1663 1664


1665 1666 1667 1668 1669 1670 1671
;;; ================ Insects ================
;;;
;;;
;;; mosquito 
;;;
;;; need to make freq env flicks at call time (is there a comb-filter effect as it gets near?)

1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
(defanimal (mosquito beg dur freq amp)
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(carrier (make-oscil freq))
	(modulator1 (make-polywave (* freq 2) '(1 .6))) ; or 1 (but leave lower mult at 2??)
	(modulator3 (make-polywave (* freq 3) '(1 .3)))
	(modulator2 (make-polywave (* freq 8) '(1 .1))) ; or 9
	(ampf (make-env '(0 0 .2 .5 1 .5 2 .5 3 1 4 .5 5 .5 5.1 0) :scaler amp :duration dur :base 32))
	(frqf (make-env '(0 0  1 0  1.01 0.1  1.03 -0.1  1.05 0.0  3 0 3.02 .05 3.03 -0.1 3.1 0 5 0.0) :duration dur :scaler (hz->radians freq)))
	(vib (make-rand-interp 10.0 (hz->radians 10)))
	(indf (make-rand-interp 1 .5))
	(index2 (hz->radians (* freq 1.0)))
	(index3 (hz->radians (* freq 0.5)))
	(hfreq (hz->radians freq)))
    (do ((i start (+ i 1)))
	((= i stop))
      (let* ((frq (+ (env frqf) (rand-interp vib)))
	     (pitch (oscil carrier frq)))
	  (outa i (* (env ampf)
		     (+ (polywave modulator1 (+ (* 2.0 frq) (* hfreq pitch (+ 1.0 (rand-interp indf)))))
			(polywave modulator3 (+ (* 3.0 frq) (* index3 pitch)))
			(polywave modulator2 (+ (* 8.0 frq) (* index2 pitch))))))))))
1694

1695
;; (with-sound (:play #t) (mosquito 0 5 560 .2) (mosquito 1 3 880 .05))
1696
;; (with-sound () (mosquito 0 1 560 .1))
1697 1698 1699 1700 1701

;;; --------------------------------------------------------------------------------
;;;
;;; Southern mole cricket

1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
(defanimal (southern-mole-cricket beg dur amp)
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(gen1 (make-oscil 2700))
	(gen2 (make-oscil (* 2700 2.4)))
	(gen3 (make-oscil 60))
	(gen5 (make-polywave 360 '(0 .035 1 .015)))
	(gen4 (make-oscil (* 2700 3.2)))
	(gargle (make-rand-interp 360 (hz->radians (* .25 360)))))
    (do ((i start (+ i 1)))
	((= i stop))
      (let ((pval (oscil gen3))
	    (noise (rand-interp gargle)))
	(outa i (* amp (+ (* (polywave gen5)
			     (- 1.0 pval)
			     (oscil gen2 (* 2.4 noise)))
			  (* (max 0.0 pval)
			     (+ (* .95 (oscil gen1 noise))
				(* .05 (oscil gen4 noise)))))))))))

;; (with-sound (:play #t) (southern-mole-cricket 0 3 .5))
1723 1724 1725 1726 1727 1728


;;; --------------------------------------------------------------------------------
;;;
;;; Broad-winged Tree cricket

1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
(defanimal (broad-winged-tree-cricket beg dur amp)
  (let ((freq 1700))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (gp (make-polywave freq '(1 .7 2 .05 3 .04)))
	  (gb (make-polywave freq '(4 .02 5 .02)))
	  (ampmod (make-triangle-wave 155 :amplitude .07))
	  (ampf (make-env '(0 0 8 1 20 1 21 0) :duration dur :scaler amp))
	  (frqf (make-env '(0 1  1 -1  2 -1) :duration .06 :base 10.0 :scaler (hz->radians 40.0)))
	  (pulsef #f)
	  (pulse-samps (seconds->samples .06))
	  (indf (make-env '(0 0 10 0 18 1 23 1 26 0 30 0) :duration .06))
	  (noise (make-rand-interp 1000 .005)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(set! (mus-location ampf) (- i start))
	(let ((reset-stop (min stop (+ i pulse-samps)))
	      (pulse-amp (env ampf)))
	  (set! pulsef (make-env '(0 0 1 .1 6 .2 7 0 8 .3 10 1 18 .9 21 .1 23 .3 28 .1 30 0) :scaler pulse-amp :duration .06 :base .1))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (let ((buzz (+ (env frqf) (rand-interp noise))))
	      (outa k (* (env pulsef)
			 (+ .93 (triangle-wave ampmod))
			 (+ (polywave gp buzz)
			    (* (env indf)
1755 1756 1757 1758
			       (polywave gb buzz))))))))
	(mus-reset pulsef)
	(mus-reset frqf)
	(mus-reset indf)))))
1759

1760
;; (with-sound (:play #t) (broad-winged-tree-cricket 0 1.0 0.3))
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771



;;; --------------------------------------------------------------------------------
;;;
;;; Long-spurred meadow katydid
;;;
;;;    I can barely hear this at its true pitch, so the match was
;;;    done down one or two octaves -- I think the recording has cut off high info (above 20Khz) --
;;;    need much higher srate to see what this guy is really doing.  This is not very good...

1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
(defanimal (long-spurred-meadow-katydid beg amp)
  (let ((dur 10.1) ; overall duration
	(slow-start 2.2)) ; buzz at start
    (let ((soft-end (+ slow-start 4.0))) ; softer section, rest is full vol
      (let ((start (seconds->samples beg))
	    (stop (seconds->samples (+ beg dur)))
	    ;; looks like the same basic pulse throughout, almost same speed at start but every other one is squelched
	    ;; slow startup pulse starts much faster (.06 mid-pulse duration, .0013 base pulse)
	    (carrier (make-polywave 400 (list 33 .36 35 (* .36 .7) 37 (* .36 .49) 39 (* .36 .343) 41 (* .36 .242))))
	    (modulator (make-polywave 1500 '(1 .003))) ; cos^2 = 1/2(cos 2x + 1), but polywave has constant term via partial 0
	    (modulator1 (make-polywave 3000 '(0 .5 1 .5)))
	    (noise (make-rand-interp 5000 .003))
	    (peep (make-pulsed-env '(0 0 1 0 2 .2 3 0 5 .75 8 1 10 0 11 0) .06 (/ 1.0 .06)))
	    (ampf (make-env (list 0 0 .5 .5 slow-start .4 soft-end .4 (+ soft-end .5) 1 (- dur 1) 1 dur 0.0) :duration dur :scaler amp))
	    (pulsef (make-env (list 0 -1 slow-start -1 (+ slow-start .03) 0 dur 0) :duration dur :scaler (hz->radians 8)))
	    (pulsef1 (make-env (list 0 -1 slow-start -1 (+ slow-start .03) 0 dur 0) :duration dur :scaler (hz->radians (* 24.75 8)))))
	(do ((i start (+ i 1)))
	    ((= i stop))
	  (outa i (* (env ampf) 
		     (polywave modulator1) 
		     (pulsed-env peep (env pulsef))
		     (polywave carrier (+ (env pulsef1)
					  (rand-interp noise)
					  (polywave modulator))))))))))


;; (with-sound (:statistics #t) (long-spurred-meadow-katydid 0 .5))

#|
(defanimal (long-spurred-meadow-katydid beg amp)
  (let ((dur 10.1) ; overall duration
	(slow-start 2.2)) ; buzz at start
    (let ((soft-end (+ slow-start 4.0))) ; softer section, rest is full vol
      (let ((start (seconds->samples beg))
	    (stop (seconds->samples (+ beg dur)))
	    ;; looks like the same basic pulse throughout, almost same speed at start but every other one is squelched
	    ;; slow startup pulse starts much faster (.06 mid-pulse duration, .0013 base pulse)
	    (carrier (make-nrxysin 13200 (/ 800 13200) 4 .7)) 
	    (modulator (make-oscil 1500 (* 0.5 pi)))
	    (noise (make-rand-interp 5000 .1))
	    (nrx 0.0)
	    (peep (make-pulsed-env '(0 0 1 0 2 .2 3 0 5 .75 8 1 10 0 11 0) .06 (/ 1.0 .06)))
	    (ampf (make-env (list 0 0 .5 .5 slow-start .4 soft-end .4 (+ soft-end .5) 1 (- dur 1) 1 dur 0.0) :duration dur :scaler amp))
	    (pulsef (make-env (list 0 -1 slow-start -1 (+ slow-start .03) 0 dur 0) :duration dur :scaler (hz->radians 8))))
	(do ((i start (+ i 1)))
	    ((= i stop))
	  (let ((frq (env pulsef))
		(md (oscil modulator)))
	    (set! nrx (nrxysin carrier (+ (* 825.0 frq) ; (/ 13200 16))
					  (rand-interp noise)
					  (* .1 md))))
	    (set! md (* md md nrx (pulsed-env peep frq)))
	    (outa i (* md (env ampf)))))))))
|#
#|
;; this is slower!
	(do ((i start (+ i 1)))
	    ((= i stop))
	  (let ((frq (env pulsef))
		(md (oscil modulator)))
	    (outa i (* md md 
		       (nrxysin carrier (+ (* 825.0 frq) ; (/ 13200 16))
					   (rand-interp noise)
					   (* .1 md)))
		       (pulsed-env peep frq) (env ampf)))))))))
|#

1839 1840 1841 1842 1843 1844


;;; --------------------------------------------------------------------------------
;;;
;;; Handsome trig

1845 1846 1847 1848 1849 1850 1851 1852 1853 1854
(defanimal (handsome-trig beg dur amp)
  (let ((freqs (apply float-vector (map hz->radians '(6439 6585 6860 6940 7090 7266 7362))))
	(amps (float-vector 0.355 0.355 0.089 0.060 0.071 0.035 0.035))
	(pulse-dur .02))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (pulsef (make-env '(0.0 0.0  0.05 1.0  0.13 1.0  0.4 0.1  1.0 0.0) :scaler amp :duration pulse-dur))
	  (pulse-samps (seconds->samples pulse-dur))
	  (pulse-sep (seconds->samples pulse-dur))
	  (pulses 0)
1855
	  (obank (make-oscil-bank freqs (make-float-vector 7) amps #t)))
1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876
      (do ((i start (+ i pulse-sep)))
	  ((>= i stop))
	(let ((pulse-stop (+ i pulse-samps)))
	  (do ((k i (+ k 1)))
	      ((= k pulse-stop))
	    (outa k (* (env pulsef) (oscil-bank obank)))))
	(set! pulses (+ pulses 1))
	;; count pulses in current group -- at least 2, at most 4, if 2 or 3, possibly and if 4 definitely insert a space
	(if (or (= pulses 4)
		(and (= pulses 2)
		     (> (random 1.0) 0.6))
		(and (= pulses 3)
		     (> (random 1.0) 0.3)))
	    (begin
	      (set! pulse-sep (+ pulse-samps (seconds->samples (+ .015 (random .005