animals.scm 482 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
(define-macro (define-animal args . body)
236 237 238 239 240 241 242 243 244
  (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))
245
           ()))))
246 247

#|
248
(define-macro (define-animal args . body)
249 250 251 252 253 254 255 256
  (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
257
	 (format () "~A: ~A~%" (- (get-internal-real-time) start) ,name)))
258 259
     ,@(if *definstrument-hook*
           (list (*definstrument-hook* name targs))
260
           ()))))
261 262
|#

263 264 265 266 267 268 269

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

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

(define (seldur) 
273
  (list (/ (selection-framples) 44100.0) 
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
	(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.

294 295
(if (null? (hook-functions start-playing-hook))
    (hook-push start-playing-hook
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
	       (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)))))
315 316 317 318 319 320


;;; precision window movements via arrow keys

(define (move-one-pixel s c right)
  (let* ((ax (axis-info s c time-graph))
321 322 323 324
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
325 326
	 (samps-per-pixel (max 1 (round (/ (- hi lo) (- hi-pix lo-pix)))))
	 (change (if right 
327
		     (- (min (+ hi samps-per-pixel) (framples s c)) hi)
328
		     (- (max 0 (- lo samps-per-pixel)) lo))))
329
    (set! (left-sample) (min (max 0 (+ lo change)) (framples s c)))
330 331 332 333 334 335 336
    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))
337 338 339 340
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
341 342
	 (samps-per-pixel (* 8 (max 1 (round (/ (- hi lo) (- hi-pix lo-pix))))))
	 (change (if right 
343
		     (- (min (+ hi samps-per-pixel) (framples s c)) hi)
344
		     (- (max 0 (- lo samps-per-pixel)) lo))))
345
    (set! (left-sample) (min (max 0 (+ lo change)) (framples s c)))
346 347 348 349 350 351 352
    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))
353 354 355 356
	 (lo (ax 0))
	 (hi (ax 1))
	 (lo-pix (ax 10))
	 (hi-pix (ax 12))
357
	 (samps-per-pixel (max 1 (round (/ (- hi lo) (- hi-pix lo-pix)))))
358
	 (len (framples s c)))
359 360 361 362
    (if in
	(if (> (- hi-pix lo-pix) samps-per-pixel)
	    (begin
	      (set! (left-sample) (+ lo samps-per-pixel))
363
	      (set! (x-zoom-slider) (* 1.0 (/ (max samps-per-pixel (- hi lo (* 2 samps-per-pixel))) len)))))
364 365
	(begin
	  (set! (left-sample) (max 0 (- lo samps-per-pixel)))
366
	  (set! (x-zoom-slider) (* 1.0 (/ (min len (+ (- hi lo) (* 2 samps-per-pixel))) len)))))
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    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)
388 389
				 (let ((snd (lst 0))
				       (name (lst 1)))
390 391 392 393
				   (if (and (sound? snd)
					    (string=? (file-name snd) name))
				       (for-each
					(lambda (chan-data)
394 395 396 397 398
					  (let ((chn (chan-data 0))
						(x0 (chan-data 3))
						(x1 (chan-data 5))
						(y0 (chan-data 4))
						(y1 (chan-data 6)))
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
					    (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)
415

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



;;; 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

432
(define-animal (a-frog beg dur freq amp amp-env gliss gliss-env pulse-dur pulse-env fm-index fm-freq)
433 434 435 436 437 438 439 440 441 442 443 444 445
  (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)))))))))
446 447 448 449 450 451 452 453 454 455

(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) 
456 457 458 459
  (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))
460 461

(with-sound (:play #t) 
462 463 464 465
  (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))
466 467 468

;;; frog-like
(with-sound (:play #t) 
469 470 471 472
  (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))
473 474
|#

475
(define-animal (a-cricket beg dur freq freq1 amp amp-env pulse-dur pulse-env)
476 477 478 479 480 481 482 483 484 485 486 487
  (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))))))))
488

489
;; (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)))
490 491 492 493 494 495 496 497



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

498
(define-animal (oak-toad beg amp)
499 500 501 502 503 504 505 506 507 508 509 510
  (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)))))))))
511 512
#|
(with-sound (:play #t)
513 514 515 516 517 518
  (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)))))
519 520
|#

521 522
;;; (with-sound (:play #t) (oak-toad 0 .25))

523 524 525 526 527

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

528
(define-animal (southern-cricket-frog beg amp)
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
  (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)))))))))))
547

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


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

555
(define-animal (northern-leopard-frog-1 beg amp)
556
  ;; this is slightly low-passed, and I don't quite have the vowel right at the end
557 558 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
  (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))))))))))))
608
	    (for-each mus-reset (vector pulsef1 pulsef2 gen1 gen2))
609 610
	    (set! (mus-location pulf) (- (+ i pulse-sep) start))
	    (set! pulse-sep (seconds->samples (env pulf)))))))))
611 612

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


615
(define-animal (northern-leopard-frog-2 beg amp)
616
  ;; rocky 57 2
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
  (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))
	  
640 641 642 643
	  (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))))
644 645 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
	  
	  (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))
689
	      (float-vector-set! rk k (rk!cos gen1 (env pulse-frqf))))
690 691 692 693 694 695 696 697 698 699 700 701 702
	    
	    (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)))))))
703

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



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

712
(define-animal (green-tree-frog beg amp)
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
  (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)))
729
	      (frq (env frqf)))
730 731 732 733 734 735
	  (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))))))))))
736

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


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

744
(define-animal (pinewoods-tree-frog beg dur amp)
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
  (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)))
768
	    (set! (mus-frequency gen1) (* pitch (if (< pulse 3) 10 11)))
769 770 771 772 773 774 775
	    (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)))
776 777 778 779 780
			      (* .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)))
781 782
	
	(set! pulses (if (> (random 1.0) .6) 5 4))))))
783

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


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

791
(define-animal (squirrel-tree-frog beg dur amp)
792 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
  (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))))))))
826
	  (for-each mus-reset (vector frqf pulsef indf-1 indf)))))))
827 828 829

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

830 831 832 833 834 835


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

836
(define-animal (ornate-chorus-frog beg dur amp)
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
  (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)
854
	  (set! next-pulse (seconds->samples (if (> (random 1.0) .8) (+ .25 (random .3)) .4))))))))
855

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


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

863
(define-animal (spring-peeper beg amp)
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
  (let ((dur 0.17)
	(pause 0.23)
	(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
884 885
      (let ((start2 (+ stop (seconds->samples pause)))
	    (dur2 .13))	    
886 887 888 889 890 891 892 893 894 895 896 897
	(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))
898 899 900 901 902 903


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

904
(define-animal (crawfish-frog beg amp)
905 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
  (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))
932 933 934 935
			    (* (env intrp-1) (polywave poly2 frq))))))))
	(mus-reset pulsef)
	(mus-reset gen1)
	(mus-reset fmd)))))
936 937

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


;;; --------------------------------------------------------------------------------
;;;
;;; 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

947
(define-animal (river-frog beg amp)
948 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
  (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))
987 988 989 990 991 992


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

993
(define-animal (bullfrog beg amp)
994 995 996 997 998 999
  (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)))
	  
1000 1001
	  (f1 (make-rxyk!cos 200 1/2 0.6))
	  (f2 (make-rxyk!cos 230 10/23 1.2))
1002
	  
1003 1004
	  (f3 (make-rxyk!cos 600 1/6 8.0))
	  (f4 (make-rxyk!cos 630 10/63 8.0))
1005 1006 1007 1008 1009 1010 1011 1012
	  
	  (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))
	  
1013 1014 1015
	  (frm1f (* 14 (sin (hz->radians 400))))
	  (frm2f (* 28 (sin (hz->radians 1200))))
	  (frm3f (* 8 (sin (hz->radians 5000))))
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
	  
	  (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))
1036 1037 1038 1039 1040 1041 1042


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

(define (texas-toad beg1 dur1 amp1)
1043
  
1044
  (define-animal (texas-toad-1 beg dur amp)
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
    (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))))))
1065
  
1066
  (let ((last-dur 0.0)
1067
	(last-call (+ beg1 dur1 -0.4)))
1068 1069 1070 1071 1072
    (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))))

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


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

1080
(define-animal (american-toad beg dur amp)
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
  (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))
1095 1096 1097 1098 1099 1100 1101 1102
	(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)))))
1103 1104 1105 1106 1107 1108 1109 1110
	  (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))))))
1111

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


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

1119
(define-animal (plains-spadefoot beg amp)
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
  (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)))
1141 1142 1143 1144 1145 1146 1147 1148
	  (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)))))
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
	  (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))))))))))))
1159

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


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

1167
(define-animal (barking-tree-frog beg amp)
1168 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
  (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)))))))))
1197

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


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

1205
(define-animal (western-toad beg dur amp)
1206 1207 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
  (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)))))))
1240

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


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

1248
(define-animal (southwestern-toad beg dur amp)
1249 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
  (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))))))
1277

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


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

1285
(define-animal (great-plains-narrow-mouthed-toad beg dur1 amp)
1286
  ;; rocky 75 28
1287 1288 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
  (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) 
1348
				     (polywave gp (float-vector-ref saved-frq k)))
1349 1350 1351 1352 1353 1354 1355
				  (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)))))))))
1356

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


1360

1361 1362 1363 1364
;;; --------------------------------------------------------------------------------
;;;
;;; Pacific chorus frog

1365
(define-animal (pacific-chorus-frog beg amp)
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
  (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)))))))))
1391

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


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

1399
(define-animal (red-spotted-toad beg dur amp)
1400
  ;; rocky 23 1
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
  (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))
1415 1416 1417
	(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)))))
1418 1419 1420 1421 1422 1423 1424 1425
	  (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))))))
1426

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


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

1434
(define-animal (green-toad beg dur amp)
1435 1436
  ;; rocky 31 1
  ;;  (an experiment with wave-train in place of pulsed env)
1437 1438 1439 1440 1441 1442
  (let ((pulse (let ((wave-len 256))
		 (do ((v (make-float-vector wave-len))
		      (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))
		      (i 0 (+ i 1)))
		     ((= i wave-len) v)
		   (set! (v i) (env pulse-ampf))))))
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
    (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))))))))))
1461

1462
;; (with-sound (:play #t) (green-toad 0 1 .5))
1463 1464 1465 1466 1467 1468


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

1469
(define-animal (little-grass-frog beg amp)
1470
  ;; frogs 26 8.5
1471 1472 1473 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
  (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))))))))))
1506

1507
;; (with-sound (:play #t) (little-grass-frog 0 .5))
1508 1509 1510 1511 1512 1513


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

1514
(define-animal (sonoran-desert-toad beg dur amp)
1515
  ;; rocky 13 1
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
  (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)))
1543 1544 1545 1546
	      (set! pulse-ampf (make-env (case env-choice
					   ((0) env1)
					   ((1) env2)
					   (else env3))
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
					 :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))))))))))))
1565

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



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

(define (amargosa-toad beg1 amp1)
  ;; rocky 17 0
  
1577
  (define-animal (amargosa-toad-1 beg dur frqscl frqenv ampscl ampenv)
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
    (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))
1594
	(frqs (vector 14800 14020 14800/3 14800 7400))
1595
	 
1596 1597
	 (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 
1598
				  0.602 0.868 0.642 0.870 0.734 0.726 0.808 0.456 0.964 0.141 1.000 0.000)
1599
			  '(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 
1600 1601
				  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)
1602
			  '(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 
1603
				  0.209 0.168 0.234 0.410 0.639 0.278 0.823 0.373 1.000 0.000)
1604
			  '(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 
1605
				  0.739 0.434 1.000 0.000)))
1606 1607 1608
	 (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 
1609
				  0.669 0.233 0.751 0.225 0.852 0.215 1.000 0.227)
1610 1611
			  '(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 
1612
				  1.000 0.096))))
1613
    (do ((call 0 (+ call 1)))
1614
	((= call 5))
1615
      (amargosa-toad-1 
1616 1617 1618 1619 1620 1621
       (+ beg1 (begs call))
       (durs call)
       (frqs call)
       (frqenvs call)
       (* amp1 (amps call))
       (ampenvs call)))))
1622

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




1628 1629 1630 1631 1632 1633 1634 1635
;;; ================ 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?

1636
(define-animal (indri beg amp)
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
  (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))
1661 1662


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

1670
(define-animal (mosquito beg dur freq amp)
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
  (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))))))))))
1692

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

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

1700
(define-animal (southern-mole-cricket beg dur amp)
1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
  (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))
1721 1722 1723 1724 1725 1726


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

1727
(define-animal (broad-winged-tree-cricket beg dur amp)
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752
  (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)
1753 1754 1755 1756
			       (polywave gb buzz))))))))
	(mus-reset pulsef)
	(mus-reset frqf)
	(mus-reset indf)))))
1757

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



;;; --------------------------------------------------------------------------------
;;;
;;; 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...

1770
(define-animal (long-spurred-meadow-katydid beg amp)
1771 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
  (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))

#|
1799
(define-animal (long-spurred-meadow-katydid beg amp)
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
  (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)))))))))
|#

1837 1838 1839 1840 1841 1842


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

1843
(define-animal (handsome-trig beg dur amp)
1844 1845 1846 1847 1848 1849 1850 1851 1852
  (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)
1853
	  (obank (make-oscil-bank freqs (make-float-vector 7) amps #t)))
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
      (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)))))
	      (set! pulses 0))
	    (set! pulse-sep pulse-samps))
	(mus-reset pulsef)
	(mus-reset obank)))))

;; (with-sound (:play #t :statistics #t) (handsome-trig 0 2 .5))
1875 1876 1877 1878 1879 1880 1881 1882


;;; --------------------------------------------------------------------------------
;;;
;;; Fast calling tree cricket
;;;
;;; (use fm for noise to get the burble right, and pm for spectrum)

1883
(define-animal (fast-calling-tree-cricket beg dur amp)
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909
  (let ((pulse-dur .0167))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (pulsef (make-env '(0.0 0.0  0.05 0.07  0.08 0.4  0.2 0.7  0.37 0.93   0.52 1.0   0.6 0.4  0.67 0.2  0.84 0.16  0.88 0.06  0.96 0.03  1.0 0.0)
			    :scaler amp :duration pulse-dur))
	  (pulse-samps (seconds->samples (/ 1.0 55)))
	  (pulse-out (seconds->samples pulse-dur))
	  (gen1 (make-oscil 4100))
	  (md (make-oscil 4100))
	  (md1 (make-oscil 205))
	  (rnd (make-rand-interp 180 .01)))
	  ;; 1.0 .04 .007

      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef)
		       (oscil gen1 
			      (rand-interp rnd)
			      (+ (* .1 (oscil md))
				 (* .2 (oscil md1)))))))
	  (mus-reset pulsef))))))

;; (with-sound (:play #t) (fast-calling-tree-cricket 0 2 .25))
1910 1911 1912 1913 1914 1915


;;; --------------------------------------------------------------------------------
;;;
;;; Dog-day cicada

1916
(define-animal (dog-day-cicada beg dur amp) ; dur ca 10 ..15 secs
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(ampf (make-env '(0.0 0.0    0.1 0.03   0.2 0.2   0.3 0.6   0.34 0.8  0.44 1.0 
			      0.5 0.83   0.55 0.92  0.6 0.86  0.66 1.0  0.7 0.7   0.88 0.25  
			      0.91 0.24  0.93 0.02  1.0 0.0)
			:duration dur :scaler (* 0.5 amp)))
	(gen1 (make-oscil 7500))
	(gen2 (make-polywave 200 '(1 .15)))
	(rnd (make-rand-interp 200))
	(rndf (make-env '(0 .3  .7 .3  .8 1  1 0) :duration dur :scaler (hz->radians 120)))
	(frqf (make-env '(0 -.5  .2 0  .85 0  1 -1) :scaler (hz->radians 400) :duration dur))
1928
	(rx (make-rxyk!cos 4000 3/20 8.0)))
1929 1930 1931 1932 1933 1934 1935 1936 1937
    (do ((i start (+ i 1)))
	((= i stop))
      (outa i (* (env ampf)
		 (+ (oscil gen1 (+ (env frqf)
				   (* (env rndf) (rand-interp rnd))
				   (polywave gen2)))
		    (rxyk!cos rx)))))))

;; (with-sound (:play #t) (dog-day-cicada 0 2 .5))
1938 1939 1940 1941 1942 1943


;;; --------------------------------------------------------------------------------
;;;
;;; Linnaeus' Cicada

1944
(define-animal (linnaeus-cicada beg dur amp)
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(ampf (make-env '(0 0 1 .8 10 1 11 0) :duration dur :scaler amp))
	(frqf (make-env '(0 0  3 .02 6 0 8 .03 9.8 0  10.6 -1 11 -1) :scaler (hz->radians 450) :duration dur :base 32))
	(gp1 (make-polywave 1280 '(1 .8 2 .02 3 .02)))
	(gp2 (make-polywave 1100 '(1 .15)))
	(gp3 (make-polywave 1460 '(1 .07)))
	(rnd (make-rand-interp 1280 .014))
	(saw (make-sawtooth-wave 180 .5)))
    (do ((i start (+ i 1)))
	((= i stop))
      (let ((sw (sawtooth-wave saw))
	    (md (+ (env frqf) (rand-interp rnd))))
	(outa i (* (env ampf)
		   (+ .75 (* sw sw))
		   (+ (polywave gp1 md)
		      (polywave gp2 (* 0.8593 md))          ;(/ 1100 1280)
		      (polywave gp3 (* 1.1406 md)))))))))  ;(/ 1460 1280)

;; (with-sound (:statistics #t) (linnaeus-cicada 0 2 .5))
1965 1966 1967 1968 1969 1970


;;; --------------------------------------------------------------------------------
;;;
;;; Lyric cicada

1971
(define-animal (lyric-cicada beg dur amp)
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
  (let ((p0 400))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (pulsef (make-pulsed-env '(0.0 0.0  0.038 0.16  0.044 0.6  0.07 0.6   0.08 0.26  
				  0.1 0.09 0.12  0.43  0.14  0.19   0.18 0.07  0.22 0.048 
				  0.23 0.65 0.25 0.65  0.26  0.23 0.28 0.044 
				  0.3  0.55 0.31 0.31  0.35  0.05 0.38 0.01 0.39 1.0
				  0.41 0.36 0.42 0.16  0.44  0.02 0.46 0.7  0.48 0.23
				  0.5  0.1  0.55 0.01   0.56  0.97  
				  0.6  0.12 0.612 0.02 0.63  0.61 0.65 0.18 0.69 0.07 
				  0.7  0.61 0.72 0.16  0.76  0.05 0.78 0.37 0.790 0.13
				  0.82 0.02 0.83 0.4   0.85  0.12 
				  0.9  0.01 0.92 0.29  0.95  0.2 0.96 0.08
				  1.0 0)
			    .02 50.0))
	  (gen1 (make-oscil (* p0 16)))
	  (gen2 (make-polywave p0 '(1 .15)))
	  (rnd (make-rand-interp p0 (hz->radians 800)))
	  (ampf (make-env '(0 0 1 1 10 1 11 0) :duration dur :scaler amp))) 
      (do ((i start (+ i 1)))
	  ((= i stop))
	(outa i (* (env ampf)
		   (pulsed-env pulsef)
		   (oscil gen1 (+ (polywave gen2)
				  (rand-interp rnd)))))))))

;; (with-sound (:play #t) (lyric-cicada 0 2 .5))
1999 2000 2001 2002 2003 2004 2005



;;; --------------------------------------------------------------------------------
;;;
;;; Confused ground cricket

2006
(define-animal (confused-ground-cricket beg dur amp)
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(gen1 (make-oscil 5700))
	(gen2 (make-polywave 5700 '(1 .01)))
	(rnd (make-rand-interp 600 (hz->radians 166)))
	(songf (make-env '(0.0 0.0  0.02 0.5  0.18 0.5  0.24 0.28  0.28 0.27  0.45 0.8  0.65 1.0 0.93 0.94  1.0 0.0) :duration .4))
	(pulsef #f)
	(pulse-samps (seconds->samples .01))
	(song-samps (seconds->samples .4)))
    (do ((i start (+ i (seconds->samples (+ .5 (random .2))))))
	((>= i stop))
      (let ((song-stop (min stop (+ i song-samps))))
	(do ((k i (+ k (seconds->samples (+ .01 (random .006))))))
	    ((>= k song-stop))
	  (set! (mus-location songf) (- k i))
	  (let ((pstop (+ k pulse-samps))
		(pulse-amp (env songf)))
	    (set! pulsef (make-env '(0.0 0.0  0.16 0.0  0.23 0.57  0.36  0.57  0.42 0.83  0.56 1.0  0.64 0.81  0.75 0.2  0.86 0.02 1.0 0.0) 
				   :scaler (* pulse-amp amp) :duration .01))
	    (do ((j k (+ j 1)))
		((= j pstop))
	      (outa j (* (env pulsef)
			 (oscil gen1 (+ (polywave gen2)
					(rand-interp rnd))))))))
	(mus-reset songf)))))
2032 2033

;; (with-sound (:play #t) (confused-ground-cricket 0 3 .3))
2034 2035


2036

2037 2038 2039 2040 2041 2042
;;; ------------------------------------------------------------------------------------------
;;;
;;; Tinkling ground cricket
;;;
;;;  There's a secondary (slower) peep -- is this part of our cricket's song, or another cricket in the background?

2043
(define-animal (tinkling-ground-cricket beg dur amp)
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(gen1 (make-oscil 7200))
	(gp (make-polywave 80 '(1 .01)))
	(pulser (make-env '(0.0 0.0  0.07 0.5  0.28 0.86  0.42 0.97  0.55 1.0  0.63 0.88  0.71 0.6  0.85 0.14  0.9 0.1 0.94 0.02 1.0 0.0) 
			  :scaler amp :duration .03))
	(pulse-samps (seconds->samples .15))
	(pulse-out (seconds->samples .03)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulser)
		       (oscil gen1 (polywave gp)))))
	  (mus-reset pulser)))))
2060

2061
;; (with-sound (:play #t) (tinkling-ground-cricket 0 3 .3))
2062 2063 2064 2065 2066 2067 2068 2069


;;; --------------------------------------------------------------------------------
;;;
;;; Marsh meadow grasshopper
;;;
;;; this is just a random number generator with an elaborate amplitude envelope

2070
(define-animal (marsh-meadow-grasshopper beg amp)
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
  (let ((dur 4.8))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0  .2 .6  .65 1.0  .87 .87 1.0 0) :duration dur :scaler amp))
	  (pulsef (make-env '(0.000  0.000   0.070  0.086   0.176  0.083   0.311  0.170   0.432  0.173  
				     0.470  0.321   0.487  0.021   0.503  0.021   0.504  0.304   0.540  0.298  
				     0.553  0.435   0.600  0.193   0.614  0.458   0.652  0.315   0.665  0.024  
				     0.689  0.018   0.699  0.638   0.725  0.582   0.727  0.027   0.790  0.009 
				     0.799  0.819   0.824  0.635   0.833  0.036   0.926  0.015   0.941  0.866
				     0.949  0.053   0.968  0.570   1.000  0.000)
				   :duration .19))
	  (pulse-samps (seconds->samples (+ .19 .02)))
	  (pulse-out (seconds->samples .19))
	  (r (make-rand 20000.0 1.0))
	  (oz (make-one-zero -1.0 1.0)))
      (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-scaler r) pulse-amp)
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (one-zero oz (* (env pulsef) (rand r)))))
	  (mus-reset pulsef))))))

;; (with-sound (:play #t :statistics #t) (marsh-meadow-grasshopper 0 .3))
2098 2099 2100 2101 2102 2103 2104 2105 2106 2107



;;; --------------------------------------------------------------------------------
;;;
;;; Carolina grasshopper
;;;
;;; tricky!  spikes are at 48 Hz, but the sound they make requires 24 Hz pulse -- I presume
;;;   I'm seeing the 2 or 4 wings alternating?

2108
(define-animal (carolina-grasshopper beg dur amp)
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(ampf (make-env ;'(0.000 0.000 0.032 0.115 0.151 0.044 0.181 0.485 0.254 0.841 0.620 0.431 0.731 0.051 0.757 0.292 0.898 0.620 0.984 0.380 1.000 0.000)
	       '(0.000 0.000 0.031 0.122 0.076 0.054 0.148 0.010 0.177 0.512 0.199 0.366 0.246 0.868 0.291 0.336 0.320 0.644 0.386 0.244 0.450 0.553 
		       0.535 0.142 0.583 0.424 0.611 0.427 0.727 0.081 0.778 0.315 0.835 0.319 0.899 0.600 0.972 0.356 1.000 0.000)
	       :duration dur :scaler (* 3 amp)))
	(spikes1 (make-nsin 24 250))
	(spikes1a (make-nsin 24 250))
	(spikes2 (make-nsin 48 140))
	(spikes3 (make-nsin 48 120))
	(rnd (make-rand-interp 100 .0001)) ; perhaps this is too much -- it clobbers the comb filter 
	(frqf (make-env '(0 0 1 -.4 2 0 3 -.2 4 .3 6 -1.0) :scaler (hz->radians .4) :duration dur))
	(oz (make-one-zero 1.0 -1.0)))
2122 2123 2124
    (set! (mus-phase spikes1a) pi)
    (set! (mus-phase spikes2) .7)
    (set! (mus-phase spikes3) 1.4)
2125 2126 2127 2128 2129 2130 2131 2132 2133
    (do ((i start (+ i 1)))
	((= i stop))
      (let* ((noi (rand-interp rnd))
	     (frq (+ noi (env frqf))))
	(outa i (one-zero oz (* (env ampf)
				(+ (* .6 (nsin spikes1 noi))
				   (* .6 (nsin spikes1a noi))
				   (* .4 (nsin spikes2 frq))
				   (* .3 (nsin spikes3 frq))))))))))
2134

2135
;; (with-sound (:play #t) (carolina-grasshopper 0 1.5 1.0))
2136 2137 2138 2139 2140 2141


;;; --------------------------------------------------------------------------------
;;;
;;; Striped ground cricket

2142
(define-animal (striped-ground-cricket beg dur amp)
2143 2144
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
2145 2146
	(gen1 (make-oscil 13200)) ;(* 2 6600)))
	(gen2 (make-oscil 132 (* 0.5 (+ pi (hz->radians 132)))))
2147 2148 2149 2150 2151 2152 2153
	(gen3 (make-oscil 6600))
	(gen4 (make-oscil 66 (* 0.5 (+ pi (hz->radians 66)))))
	(pulsef (make-env '(0.000 0.000  0.041 0.466  0.144 0.775  0.359 1.0  0.484 0.858  1.000 0.000) :scaler amp :duration .012))
	(pulsef1 (make-env '(0.000 0.000  0.041 0.466  0.144 0.775  0.359 1.0  0.484 0.858  1.000 0.000) :scaler (* 0.5 amp) :duration .012))
	(pulse-samps (seconds->samples 0.012))
	(pulse-sep (seconds->samples 0.015))
	(long-pulse-samps (seconds->samples .54))
2154
	(rnd (make-rand-interp 198 .04))) ; (* 3 66)
2155 2156 2157

    (do ((i start (+ i long-pulse-samps)))
	((>= i stop))
2158
      ;; do the first 0.5 amp pulse
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181
      (let ((pstop (+ i pulse-samps))
	    (next-start i)
	    (pulses (+ 8 (random 3))))
	(do ((j i (+ j 1)))
	    ((= j pstop))
	  (outa j (* (env pulsef1)
		     (+ (* .2 (oscil gen1 (* .075 (oscil gen2))))
			(* .8 (oscil gen3 (+ (* .0125 (oscil gen4))
					     (rand-interp rnd))))))))
	(mus-reset pulsef1)

	;; now the remaining pulses
	(do ((k 1 (+ k 1)))
	    ((= k pulses))
	  (set! next-start (+ next-start pulse-sep))
	  (set! pstop (+ next-start pulse-samps))
	  (do ((j next-start (+ j 1)))
	      ((= j pstop))
	    (outa j (* (env pulsef)
		       (+ (* .2 (oscil gen1 (* .075 (oscil gen2))))
			  (* .8 (oscil gen3 (+ (* .0125 (oscil gen4))
					       (rand-interp rnd))))))))
	  (mus-reset pulsef))))))
2182

2183
;; (with-sound (:play #t) (striped-ground-cricket 0 3 .5))
2184 2185 2186 2187 2188 2189


;;; --------------------------------------------------------------------------------
;;;
;;; Sphagnum ground cricket

2190
(define-animal (sphagnum-ground-cricket beg dur amp)
2191 2192 2193
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(gen1 (make-oscil 8850))
2194
	(gen2 (make-oscil 17700)) ;(* 8850 2)))
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
	(rnd1 (make-rand-interp 885 .03))
	(rnd2 (make-rand-interp 885 .1))
	(ampf (make-env '(0 0 1 1 10 1 11 0) :duration dur :scaler amp))
	(pulsef (make-env '(0.000 0.000  0.041  0.5  0.250 0.7  0.4 1.0  0.5  0.9  0.8  0.3  1.000 0.000) :duration .013))
	(pulse-samps (seconds->samples .019))
	(pulse-out (seconds->samples .013)))
    (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)))
	(do ((k i (+ k 1)))
	    ((= k reset-stop))
	  (outa k (* pulse-amp
		     (env pulsef)
		     (+ (* .9 (oscil gen1 (rand-interp rnd1)))
			(* .1 (oscil gen2 (rand-interp rnd2)))))))
	(mus-reset pulsef)))))
2213

2214
;; (with-sound (:play #t) (sphagnum-ground-cricket 0 2 .3))
2215 2216 2217 2218 2219 2220


;;; --------------------------------------------------------------------------------
;;;
;;; Southeastern field cricket

2221
(define-animal (southeastern-field-cricket beg dur amp)
2222 2223 2224 2225
  (let ((pulse-dur 0.027)) ; occasionally a hicccup = .039, 30..100 pulses per song
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (gen1 (make-polywave 4730 '(1 .8 2 .1 3 .1)))
2226
	  (rnd (make-rand-interp 946 1)) ; (* 2 473)
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
	  (oz (make-one-zero 1.0 -1.0))
	  (ampf (make-env '(0 0 1 1 10 1 11 0) :duration dur :scaler amp))
	  (pulsef (make-env '(0.0 0.0  0.05  0.38  0.14 0.77  0.26  0.95  0.47  1.0  0.57  0.9  0.81 0.5  0.85  0.3  1.0 0.0) :duration .014))
	  (pulses (+ 30 (random 70)))
	  (pulse-samps (seconds->samples pulse-dur))
	  (current-pulse-samps (seconds->samples pulse-dur)))

      (do ((i start (+ i current-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))
	    (outa k (* pulse-amp
		       (env pulsef)
2244
		       (polywave gen1 (one-zero oz (rand-interp rnd)))))))
2245

2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
	(mus-reset pulsef)
	(set! pulses (- pulses 1))
	(if (<= pulses 0)
	    (begin
	      (set! current-pulse-samps (+ pulse-samps (seconds->samples (+ .2 (random .1)))))
	      (set! pulses (+ 30 (random 70))))
	    (begin
	      (set! pulse-samps (seconds->samples (if (> (random 1.0) .95)
						      (+ pulse-dur .005 (random .01)) 
						      pulse-dur)))
	      (set! current-pulse-samps pulse-samps)))))))
2257

2258
;; (with-sound (:play #t) (southeastern-field-cricket 0 5 .3))
2259 2260


2261

2262 2263 2264 2265
;;; --------------------------------------------------------------------------------
;;;
;;; Snowy tree cricket

2266
(define-animal (snowy-tree-cricket beg dur amp)
2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
  (let ((pitch 1690))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (gp (make-polywave pitch '(1 .9 2 .05 3 .05)))
	  (rnd (make-rand-interp 1000 .014))
	  (pulsef (make-env '(0.0 0.0    0.04 0.79  0.08 0.09  0.11 0.02  0.14 0.83  0.15 0.95  
				  0.21 0.05  0.26 0.02  0.29 0.79  0.31 0.89  0.35 0.07  0.38 0.04  
				  0.39 0.79  0.42 0.94  0.45 0.08  0.48 0.05  0.50 0.80  0.52 0.96  
				  0.59 0.02  0.64 0.01  0.66 0.78  0.68 0.95  0.72 0.06  0.75 0.04  
				  0.76 0.70  0.79 0.96  0.83 0.07  0.85 0.02  0.88 0.80  0.90 1.0
				  0.95 0.12  0.97 0.04  1.00 0.00)
			    :scaler amp :duration .352 :base .1))
	  (frqf (make-env '(0.0 0.0    0.04 1.0  0.08 0.0  0.11 0.0  0.14 1.0  0.15 0.0
				0.21 0.0  0.26 0.0  0.29 1.0  0.31 0.0  0.35 0.0  0.38 0.0  
				0.39 1.0  0.42 0.0  0.45 0.0  0.48 0.0  0.50 1.0  0.52 0.0
				0.59 0.0  0.64 0.0  0.66 1.0  0.68 0.0  0.72 0.0  0.75 0.0  
				0.76 1.0  0.79 0.0  0.83 0.0  0.85 0.0  0.88 1.0  0.90 0.0
				0.95 0.0  0.97 0.0  1.00 0.0)
			  :duration .352 :scaler (hz->radians 60)))
	  (reset-samps (seconds->samples .85))
	  (on-samps (seconds->samples .36))) ; else ampf is 0.0

      (do ((i start (+ i reset-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i on-samps))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef)
		       (polywave gp (+ (env frqf) (rand-interp rnd))))))
	  (mus-reset pulsef)
	  (mus-reset frqf))))))
2298

2299
;; (with-sound (:play #t) (snowy-tree-cricket 0 2 .3))
2300 2301 2302 2303 2304 2305 2306 2307


;;; --------------------------------------------------------------------------------
;;;
;;; Slightly musical conehead
;;;
;;; this could use some work

2308
(define-animal (slightly-musical-conehead beg dur amp)
2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(gen1 (make-oscil 11000))
	(gp (make-polywave 1100 '(1 .1 5 .05)))
	(rnd1 (make-rand-interp 1100 .05))
	(rnd2 (make-rand-interp 1100 .4))
	(pulse-samps (seconds->samples .36))
	(pulse-out (seconds->samples .146))
	(pulsef (make-env '(0.00 0.00  0.02 0.29  0.04 0.55  0.07 0.37  0.08 0.06  0.11 0.48  0.14 0.13  
				 0.15 0.69  0.18 0.31  0.20 0.07  0.22 0.77  0.23 0.52  0.25 0.77  0.26 0.21  
				 0.28 0.70  0.30 0.12  0.34 0.80  0.38 0.17  0.39 0.79  0.42 0.08  0.44 0.54 
				 0.48 0.53  0.50 0.85  0.53 0.11  0.55 0.51  0.58 0.79  0.60 0.22  0.62 0.84
				 0.65 0.09  0.67 0.56  0.70 0.91  0.74 0.81  0.77 0.10  0.79 0.70  0.83 0.51
				 0.85 0.90  0.88 0.03  0.90 0.55  0.93 0.60  0.95 0.11  0.97 0.97  1.0  0.00)
			  :scaler amp :duration .146)))
    (do ((i start (+ i pulse-samps)))
	((>= i stop))
      (let ((reset-stop (min stop (+ i pulse-out))))
	(do ((k i (+ k 1)))
	    ((= k reset-stop))
	  (outa k (* (env pulsef)
		     (+ .6 (rand-interp rnd2))
		     (oscil gen1 (polywave gp (rand-interp rnd1))))))
	(mus-reset pulsef)))))
2333

2334
;; (with-sound (:play #t) (slightly-musical-conehead 0 2 .4))
2335 2336


2337

2338 2339 2340 2341
;;; --------------------------------------------------------------------------------
;;;
;;; Pine tree cricket

2342
(define-animal (pine-tree-cricket beg dur amp)
2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
  (let ((pulse-dur .014))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (pulsef (make-env '(0.000 0.000 0.027 0.196 0.104 0.448 0.236 0.773 0.341 0.910 0.416 0.975 0.532 1.0
				    0.671 0.868 0.751 0.711 0.833 0.504 0.926 0.160 1.000 0.000)
			    :scaler amp :duration pulse-dur))
	  (gp (make-polywave 3580 '(1 .97 3 .03)))
	  (frqf (make-env '(0 1 1 0) :scaler (hz->radians 100) :duration pulse-dur))
	  (pulse-samps (seconds->samples .022))
	  (pulse-out (seconds->samples pulse-dur))
	  (rnd (make-rand-interp 100 .004)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef)
		       (polywave gp (+ (env frqf) (rand-interp rnd))))))
	  (mus-reset frqf)
	  (mus-reset pulsef))))))
2363

2364
;; (with-sound (:play #t) (pine-tree-cricket 0 2 .25))
2365 2366


2367

2368 2369 2370 2371
;;;--------------------------------------------------------------------------------
;;;
;;; Davis's tree cricket

2372
(define-animal (davis-tree-cricket beg dur amp)
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
  (let ((pulse-dur .013)
	(pitch 2420))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (pulse-samps (seconds->samples 0.014))
	  (pulse-out (seconds->samples pulse-dur))
	  (pulsef (make-env '(0.000 0.000 0.079 0.395 0.245 0.925 0.410 1.000 0.470 0.874 
				    0.554 0.549 0.614 0.312 0.728 0.170 1.000 0.000)
			    :scaler amp :duration pulse-dur))
	  (gp (make-polywave pitch '(1 .93 2 .07)))
	  (rnd (make-rand-interp 150 .004)))
      (do ((i start (+ i pulse-samps)))
	  ((>= i stop))
	(let ((reset-stop (min stop (+ i pulse-out))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulsef)
		       (polywave gp (rand-interp rnd)))))
	  (mus-reset pulsef))))))
2392

2393
;; (with-sound (:play #t) (davis-tree-cricket 0 2 .25))
2394 2395 2396 2397 2398 2399


;;; --------------------------------------------------------------------------------
;;;
;;; Black-horned tree cricket

2400
(define-animal (black-horned-tree-cricket beg dur amp)
2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
  (let ((pulse-dur 0.0173)
	(pulse-space 0.0219)
	(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 .05 1 .95 1 1 0) :duration dur :scaler amp))
	  (gen1 #f)
	  (rnd (make-rand-interp 1000 (hz->radians 50)))
	  (pulse-ampf (make-env '(0.000 0.000 0.076 0.443 0.277 0.866 0.454 0.925 0.603 0.771 0.690 0.573 0.726 0.304 1.000 0.000)
				:duration pulse-dur)))
      (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! gen1 (make-polywave 3680.0 (list 1 (* pulse-amp .94) 
						 2 (* pulse-amp .04) 
						 3 (* pulse-amp .01) 
						 4 (* pulse-amp .005)
						 5 (* pulse-amp .003))))
	  (do ((k i (+ k 1)))
	      ((= k reset-stop))
	    (outa k (* (env pulse-ampf)
		       (polywave gen1 (rand-interp rnd)))))
	  (mus-reset pulse-ampf))))))
2427

2428
;; (with-sound (:play #t) (black-horned-tree-cricket 0 2 .25))
2429 2430


2431

2432 2433 2434 2435
;;; --------------------------------------------------------------------------------
;;;
;;; Narrow-winged tree cricket

2436
(define-animal (narrow-winged-tree-cricket beg dur amp)
2437
  ;; insects 18 4
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
  (let ((start (seconds->samples beg))
	(stop (seconds->samples (+ beg dur)))
	(ampf (make-env '(0 0 .1 1 20 1 20.1 0) :duration dur :scaler amp))
	(pulser (make-wave-train-with-env 43.0 
					  '(0.000 0.000 0.144 0.332 0.269 0.715 0.361 0.838 0.459 0.866 0.609 0.727 
						  0.652 0.530 0.780 0.194 1.000 0.000)
					  (seconds->samples .0185)))
	(gen1 (make-polywave 1900 '(1 .8 2 .07 3 .13)))
	(rnd (make-rand-interp 150 (hz->radians 20))))
    (do ((i start (+ i 1)))
	((= i stop))
      (outa i (* (env ampf)
		 (wave-train pulser)
		 (polywave gen1 (rand-interp rnd)))))))
2452

2453
;; (with-sound (:play #t) (narrow-winged-tree-cricket 0 2 .25))
2454 2455 2456 2457 2458 2459


;;; --------------------------------------------------------------------------------
;;;
;;; Four-spotted tree cricket

2460
(define-animal (four-spotted-tree-cricket beg dur amp)
2461
  ;; insects 16 4
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
  (let ((index (hz->radians 400)))
    (let ((start (seconds->samples beg))
	  (stop (seconds->samples (+ beg dur)))
	  (ampf (make-env '(0 0 .3 1 20 1 20.3 0) :duration dur :scaler amp))
	  (amp-pulser (make-table-lookup-with-env 40.0 
						  '(0.000 0.000 0.071 0.518 0.174 0.783 0.315 0.885 0.492 0.727 0.579 0.466 
							  0.625 0.186 0.671 0.028 0.755 0.083 0.848 0.024 0.935 0.126 1.000 0.000 1.5 0)
						  (seconds->samples .025)))
	  (frq-pulser (make-table-lookup-with-env 40.0 (list 0 index 1 0 2 0) (seconds->samples .025)))
	  (gen1 (make-polywave 3220 '(1 .92  2 .07  3 .01)))
	  (gen2 (make-oscil 5000))
	  (gen3 (make-oscil 2200))
	  (rnd1 (make-rand-interp 8000 (hz->radians 2000)))
	  (rnd (make-rand-interp 200 (hz->radians 30))))
      (do ((i start (+ i 1)))
	  ((= i stop))
	(let ((noise (rand-interp rnd1)))
	  (outa i (* (env ampf)
		     (+ (* (table-lookup amp-pulser)
			   (polywave gen1 (+ (rand-interp rnd)
					     (table-lookup frq-pulser))))
			(* .05
			   (+ (oscil gen2 noise)
			      (* .2 (oscil gen3 (* .2 noise)))))))))))))
2486

2487
;; (with-sound (:play #t) (four-spotted-tree-cricket 0 1 .5))
2488 2489 2490 2491 2492 2493 2494 2495



;;; ================ Birds ================
;;;
;;;
;;; Fox sparrow

2496
(define-animal (fox-sparrow beg dur amp)
2497 2498 2499