A
download maraca.scm
Language: Scheme
LOC: 124
Project Info
Snd
Server: SourceForge
Type: cvs
SourceForge\s\snd\snd\cvs‑snd\
   _new_snd-test.rb
   _sndlib.h
   aclocal.m4
   analog-filter.scm
   audinfo.c
   audio.c
   autosave.scm
   bess.rb
   bess.scm
   bess1.rb
   bess1.scm
   bird.rb
   bird.scm
   clm-ins.rb
   clm-ins.scm
   clm-strings.h
   clm.c
   clm.h
   clm23.scm
   clm2xen.c
   clm2xen.h
   cmn-glyphs.lisp
   config.guess
   config.h.in
   config.rpath
   config.sub
   configure.ac
   debug.scm
   dlocsig.rb
   draw.rb
   draw.scm
   dsp.rb
   dsp.scm
   edit-menu.scm
   edit123.scm
   effects-utils.scm
   effects.rb
   env.rb
   env.scm
   enved.scm
   eval-c.scm
   event.scm
   examp.rb
   examp.scm
   extensions.rb
   extensions.scm
   fade.scm
   fft-menu.scm
   fix-optargs.scm
   fmv.scm
   freeverb.rb
   freeverb.scm
   gettext.h
   gl.c
   grani.scm
   gtk-effects.scm
   gtk-popup.scm
   gui.scm
   headers.c
   help-snd-fm.pd
   help-snd.pd
   HISTORY.Snd
   hooks.rb
   hooks.scm
   index.rb
   index.scm
   inf-snd.el
   io.c
   jcrev.scm
   ladspa-help.scm
   ladspa.scm
   makefile.in
   makefile.no-gettext
   maraca.rb
   maraca.scm
   marks-menu.scm
   marks.rb
   marks.scm
   maxf.rb
   maxf.scm
   midi.c
   misc.scm
   mix-menu.scm
   mix.rb
   mix.scm
   mixer.scm
   moog.scm
   musglyphs.rb
   musglyphs.scm
   nb.rb
   nb.scm
   new-backgrounds.scm
   new-buttons.scm
   new-effects.scm
   new-icons.scm
   noise.rb
   noise.scm
   old-mac-audio.c
   old-snd.spec
   oo.scm
   oscope.scm
   panic.scm
   pd-add.scm
   pd-any.scm
   pd-fm.scm
   pd-global.scm
   pd-inout.scm
   pd-local.scm
   pd-mozilla.scm
   pd-send_receive.scm
   peak-env.scm
   piano.rb
   piano.scm
   play.rb
   play.scm
   poly.rb
   poly.scm
   popup.rb
   popup.scm
   prc95.rb
   prc95.scm
   pvoc.rb
   pvoc.scm
   README.Snd
   rgb.rb
   rgb.scm
   rmsgain.scm
   rt-compiler.scm
   rt-engine.scm
   rt-examples.scm
   rt.tex
   rtio.rb
   rtio.scm
   rubber.rb
   rubber.scm
   saw.c
   singer.rb
   singer.scm
   snd-0.h
   snd-1.h
   snd-axis.c
   snd-chn.c
   snd-completion.c
   snd-dac.c
   snd-data.c
   snd-draw.c
   snd-edits.c
   snd-env.c
   snd-error.c
   snd-fft.c
   snd-file.c
   snd-file.h
   snd-find.c
   snd-g0.h
   snd-g1.h
   snd-gchn.c
   snd-gdraw.c
   snd-gdrop.c
   snd-genv.c
   snd-gfft.c
   snd-gfile.c
   snd-gfind.c
   snd-ghelp.c
   snd-gl.scm
   snd-glistener.c
   snd-gmain.c
   snd-gmenu.c
   snd-gmix.c
   snd-gprefs.c
   snd-gprint.c
   snd-grec.c
   snd-gregion.c
   snd-gsnd.c
   snd-gtk.scm
   snd-gutils.c
   snd-gxbitmaps.c
   snd-gxcolormaps.c
   snd-gxen.c
   snd-gxutils.c
   snd-help.c
   snd-hobbit.scm
   snd-io.c
   snd-kbd.c
   snd-ladspa.c
   snd-listener.c
   snd-main.c
   snd-marks.c
   snd-menu.c
   snd-menu.h
   snd-mix.c
   snd-motif.scm
   snd-nogui.c
   snd-nogui0.h
   snd-nogui1.h
   snd-prefs.c
   snd-print.c
   snd-rec.c
   snd-rec.h
   snd-region.c
   snd-run.c
   snd-select.c
   snd-sig.c
   snd-snd.c
   snd-strings.h
   snd-trans.c
   snd-utils.c
   snd-x0.h
   snd-x1.h
   snd-xchn.c
   snd-xdraw.c
   snd-xdrop.c
   snd-xen.c
   snd-xenv.c
   snd-xfft.c
   snd-xfile.c
   snd-xfind.c
   snd-xhelp.c
   snd-xlistener.c
   snd-xm.rb
   snd-xmain.c
   snd-xmenu.c
   snd-xmix.c
   snd-xprefs.c
   snd-xprint.c
   snd-xrec.c
   snd-xref.c
   snd-xregion.c
   snd-xsnd.c
   snd-xutils.c
   snd-xxen.c
   snd.1
   Snd.ad
   snd.c
   Snd.gtkrc
   snd.h
   snd.spec
   snd_conffile.scm
   snd_pd_external.c
   snd_pd_external.h
   snd4.scm
   snd5.scm
   snd6.scm
   snd7.scm
   sndctrl.c
   sndinfo.c
   sndlib-strings.h
   sndlib.h.in
   sndlib2xen.c
   sndlib2xen.h
   sndplay.c
   sndrecord.c
   sndwarp.scm
   sound.c
   special-menu.scm
   spectr.rb
   spectr.scm
   strad.rb
   strad.scm
   TODO.Snd
   track-colors.scm
   v.rb
   v.scm
   vct.c
   vct.h
   ws.rb
   ws.scm
   xen.c
   xen.h
   xg-x11.h
   xm-enved.rb
   xm-enved.scm
   zip.rb
   zip.scm

;;; Perry Cook's maraca from CMJ vol 21 no 3 (Fall 97) p 44
;;;   translated from CLM's maraca.ins

(provide 'snd-maraca.scm)
(if (not (provided? 'snd-ws.scm)) (load-from-path "ws.scm"))

(define two-pi (* 2 3.14159))

(definstrument (maraca beg dur #:optional (amp .1) 
		 (sound-decay 0.95) 
		 (system-decay 0.999) 
		 (probability .0625)
		 (shell-freq 3200.0)
		 (shell-reso 0.96))
  (let* ((st (inexact->exact (floor (* (mus-srate) beg))))
	 (nd (+ st (inexact->exact (floor (* (mus-srate) dur)))))
	 (temp 0.0)
	 (shake-energy 0.0)
	 (snd-level 0.0)
	 (input 0.0)
	 (output (make-vct 2))
	 (coeffs (make-vct 2))
	 (num-beans 64)
	 (j 0)
	 (sndamp (/ amp 16384.0))
	 (srate4 (inexact->exact (floor (/ (mus-srate) 4))))
	 (gain (/ (* (/ (log num-beans) (log 4.0)) 40) num-beans)))
    (ws-interrupt?)
    ;; gourd resonance filter
    (vct-set! coeffs 0 (* -2.0 shell-reso (cos (hz->radians shell-freq))))
    (vct-set! coeffs 1 (* shell-reso shell-reso))

    (run
     (lambda ()
       (do ((i st (1+ i)))
	   ((= i nd))
	 (if (< temp two-pi)
	     (begin
	       ;; shake over 50msec and add shake energy
	       (set! temp (+ temp (hz->radians 20)))
	       (set! shake-energy (+ shake-energy (- 1.0 (cos temp))))))
	 (if (= j srate4)		;shake 4 times/sec
	     (begin
	       (set! temp 0.0)
	       (set! j 0)))
	 (set! j (1+ j))
	 (set! shake-energy (* shake-energy system-decay))
	 ;; if collision, add energy
	 (if (< (random 1.0) probability)
	     (set! snd-level (+ snd-level (* gain shake-energy))))
	 ;; actual sound is random
	 (set! input (* snd-level (- (random 2.0) 1.0)))
	 ;; compute exponential sound decay
	 (set! snd-level (* snd-level sound-decay))
	 ;; gourd resonance filter calc
	 (set! input (- input 
			(* (vct-ref output 0) (vct-ref coeffs 0)) 
			(* (vct-ref output 1) (vct-ref coeffs 1))))
	 (vct-set! output 1 (vct-ref output 0))
	 (vct-set! output 0 input)
	 ;; extra zero for spectral shape, also fixup amp since Perry is assuming maxamp 16384
	 (outa i (* sndamp (- (vct-ref output 0) (vct-ref output 1))) *output*))))))

;;; maraca: (vct->channel (maraca 0 5 .5))
;;; cabasa: (vct->channel (maraca 0 5 .5 0.95 0.997 0.5 3000.0 0.7))

(definstrument (big-maraca beg dur #:optional (amp .1) 
		     (sound-decay 0.95) 
		     (system-decay 0.999) 
		     (probability .0625)
		     (shell-freqs '(3200.0))
		     (shell-resos '(0.96))
		     (randiff .01)
		     (with-filters #t))
  ;; like maraca, but takes a list of resonances and includes low-pass filter (or no filter)			   
  (let* ((st (inexact->exact (floor (* (mus-srate) beg))))
	 (nd (+ st (inexact->exact (floor (* (mus-srate) dur)))))
	 (temp 0.0)
	 (temp1 0.0)
	 (resn (length shell-freqs))
	 (shake-energy 0.0)
	 (snd-level 0.0)
	 (input 0.0)
	 (sum 0.0)
	 (last-sum 0.0)
	 (last-diff 0.0)
	 (diff 0.0)
	 (output (make-vct (* resn 2)))
	 (coeffs (make-vct (* resn 2)))
	 (basesf (make-vct resn))
	 (num-beans 64)
	 (j 0)
	 (sndamp (/ amp (* 16384.0 resn)))
	 (srate4 (floor (/ (mus-srate) 4)))
	 (gain (/ (* (/ (log num-beans) (log 4)) 40) num-beans)))
    ;; gourd resonance filters
    (ws-interrupt?)
    (do ((i 0 (1+ i)))
	((= i resn))
      (vct-set! coeffs (+ (* i 2) 0) (* -2.0 (list-ref shell-resos i) (cos (hz->radians (list-ref shell-freqs i)))))
      (vct-set! basesf i (vct-ref coeffs (+ (* i 2) 0)))
      (vct-set! coeffs (+ (* i 2) 1) (* (list-ref shell-resos i) (list-ref shell-resos i))))

    (run
     (lambda ()
       (do ((i st (1+ i)))
	   ((= i nd))
	 (if (< temp two-pi)
	     (begin
	       ;; shake over 50msec and add shake energy
	       (set! temp (+ temp (hz->radians 20.0)))
	       (set! shake-energy (+ shake-energy (- 1.0 (cos temp))))))
	 (if (= j srate4)		;shake 4 times/sec
	     (begin
	       (set! temp 0.0)
	       (set! j 0)))
	 (set! j (1+ j))
	 (set! shake-energy (* shake-energy system-decay))
	 ;; if collision, add energy
	 (if (< (random 1.0) probability)
	     (begin
	       (set! snd-level (+ snd-level (* gain shake-energy)))
	       ;; randomize res freqs a bit
	       (do ((i 0 (1+ i)))
		   ((= i resn))
		 (vct-set! coeffs (+ (* i 2) 0) (+ (vct-ref basesf i) (- (random (* 2.0 randiff)) randiff))))))
	 ;; actual sound is random
	 (set! input (* snd-level (- (random 2.0) 1.0)))
	 ;; compute exponential sound decay
	 (set! snd-level (* snd-level sound-decay))
	 ;; gourd resonance filter calcs
	 (set! temp1 input)
	 (set! last-sum sum)
	 (set! sum 0.0)
	 (do ((i 0 (1+ i)))
	     ((= i resn))
	   (set! input temp1)
	   (set! input (- input 
			  (* (vct-ref output (+ (* i 2) 0)) (vct-ref coeffs (+ (* i 2) 0)))
			  (* (vct-ref output (+ (* i 2) 1)) (vct-ref coeffs (+ (* i 2) 1)))))
	   (vct-set! output (+ (* i 2) 1) (vct-ref output (+ (* i 2) 0)))
	   (vct-set! output (+ (* i 2) 0) input)
	   (set! sum (+ sum input)))
	 (if with-filters
	     (begin
	       (set! last-diff diff)
	       (set! diff (- sum last-sum))
	       (set! temp1 (+ last-diff diff)))
	     (set! temp1 sum))
	 ;; extra zero for spectral shape, also fixup amp since Perry is assuming maxamp 16384
	 (outa i (* sndamp temp1) *output*))))))

;;; tambourine: (big-maraca 0 1 .25 0.95 0.9985 .03125 '(2300 5600 8100) '(0.96 0.995 0.995) .01)
;;; sleighbells: (big-maraca 0 2 .5 0.97 0.9994 0.03125 '(2500 5300 6500 8300 9800) '(0.999 0.999 0.999 0.999 0.999))
;;; sekere: (big-maraca 0 2 .5 0.96 0.999 .0625 '(5500) '(0.6))
;;; windchimes: (big-maraca 0 2 .5 0.99995 0.95 .001 '(2200 2800 3400) '(0.995 0.995 0.995) .01 #f)

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us