download freeverb.scm
Language: Scheme
LOC: 141
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

;;; freeverb.scm -- CLM -> Snd/Guile translation of freeverb.ins

;; Translator/Author: Michael Scholz <scholz-micha@gmx.de>
;; Last: Thu Apr 24 01:32:15 CEST 2003
;; Version: $Revision: 1.9 $

;;; Original notes of Fernando Lopez-Lezcano

;; Freeverb - Free, studio-quality reverb SOURCE CODE in the public domain
;;
;; Written by Jezar at Dreampoint, June 2000
;; http://www.dreampoint.co.uk
;;
;; Translated into clm-2 by Fernando Lopez-Lezcano <nando@ccrma.stanford.edu>
;; Version 1.0 for clm-2 released in January 2001
;; http://ccrma.stanford.edu/~nando/clm/freeverb/
;;
;; Changes to the original code by Jezar (by Fernando Lopez-Lezcano):
;; - the clm version can now work with a mono input or an n-channel input
;;   stream (in the latter case the number of channels of the input and output
;;   streams must match.
;; - the "wet" parameter has been eliminated as it does not apply to the model
;;   that clm uses to generate reverberation
;; - the "width" parameter name has been changed to :global. It now controls the
;;   coefficients of an NxN matrix that specifies how the output of the reverbs
;;   is mixed into the output stream.
;; - predelays for the input channels have been added.
;; - damping can be controlled individually for each channel.

;; For more information see clm-2/freeverb/index.html [MS]

;;; Code:

(use-modules (ice-9 format) (ice-9 optargs))
(provide 'snd-freeverb.scm)
(if (not (provided? 'snd-ws.scm)) (load-from-path "ws.scm"))

(def-clm-struct fcomb
  delay
  filter
  (feedback 0.0 :type float))

(define-macro (fcomb comb input)
  `(delay (fcomb-delay ,comb)
	  (+ ,input (* (one-zero (fcomb-filter ,comb)
				 (tap (fcomb-delay ,comb)))
		       (fcomb-feedback ,comb)))))

(definstrument (freeverb #:optional
		   (startime 0)
		   (dur (+ 1.0 (mus-sound-duration (mus-file-name *reverb*))))
		   #:key
		   (room-decay 0.5)
		   (damping 0.5)
		   (global 0.3)
		   (predelay 0.03)
		   (output-gain 1.0)
		   (output-mixer #f)
		   (scale-room-decay 0.28)
		   (offset-room-decay 0.7)
		   (combtuning '(1116 1188 1277 1356 1422 1491 1557 1617))
		   (allpasstuning '(556 441 341 225))
		   (scale-damping 0.4)
		   (stereo-spread 23)
		   (verbose #t))
  (let* ((beg (seconds->samples startime))
	 (end (cadr (times->samples startime dur)))
	 (out-chans (mus-channels *output*))
	 (out-mix (if (mixer? output-mixer) output-mixer
		      (make-mixer out-chans 0.0)))
	 (out-buf (make-frame out-chans 0.0))
	 (out-gain output-gain)
	 (f-out (make-frame out-chans 0.0))
	 (in-chans (mus-channels *reverb*))
	 (f-in (make-frame in-chans 0.0))
	 (predelays (make-array #f in-chans))
	 (local-gain (+ (/ (- 1 global) (- 1 (/ out-chans)))
			(/ out-chans)))
	 (global-gain (/ (- out-chans (* local-gain out-chans))
			 (- (* out-chans out-chans) out-chans)))
	 (srate-scale (/ *clm-srate* 44100.0))
	 (room-decay-val (+ (* room-decay scale-room-decay)
			    offset-room-decay))
	 (numcombs (length combtuning))
	 (numallpasses (length allpasstuning))
	 (combs (make-array #f out-chans numcombs))
	 (allpasses (make-array #f out-chans numallpasses)))
    (if verbose
	(format #t ";;; freeverb: ~d input channels, ~d output channels~%" in-chans out-chans))
    (if (and (> in-chans 1)
	     (/= in-chans out-chans))
	(snd-error "input must be mono or input channels must equal output channels"))
    (if (not (mixer? output-mixer))
	(if (array? output-mixer)
	    (do ((i 0 (1+ i)))
		((= i out-chans))
	      (do ((j 0 (1+ j)))
		  ((= j out-chans))
		(set! (mixer-ref out-mix i j) (array-ref output-mixer i j))))
	    (do ((i 0 (1+ i)))
		((= i out-chans))
	      (do ((j 0 (1+ j)))
		  ((= j out-chans))
		(set! (mixer-ref out-mix i j)
		      (/ (* out-gain (if (= i j)
					 local-gain
					 global-gain))
			 out-chans))))))
    (do ((c 0 (1+ c)))
	((= c in-chans))
      (array-set! predelays (make-delay :size (* *clm-srate*
						 (if (array? predelay)
						     (array-ref predelay c)
						     (if (list? predelay)
							 (list-ref predelay c)
							 predelay))))
		  c))
    (do ((c 0 (1+ c)))
	((= c out-chans))
      (do ((i 0 (1+ i)))
	  ((= i (length combtuning)))
	(let* ((tuning (list-ref combtuning i))
	       (len (inexact->exact (floor (* srate-scale tuning))))
	       (dmp (* scale-damping
		       (if (array? damping)
			   (array-ref damping i)
			   (if (list? damping)
			       (list-ref damping i)
			       damping)))))
	  (if (odd? c)
	      (set! len (+ len (inexact->exact (floor (* srate-scale stereo-spread))))))
	  (array-set! combs
		      (make-fcomb :delay (make-delay len)
				  :feedback room-decay-val
				  :filter (make-one-zero :a0 (- 1.0 dmp) :a1 dmp))
		      c i))))
    (do ((c 0 (1+ c)))
	((= c out-chans))
      (do ((i 0 (1+ i)))
	  ((= i (length allpasstuning)))
	(let* ((tuning (list-ref allpasstuning i))
	       (len (inexact->exact (floor (* srate-scale tuning)))))
	  (if (odd? c)
	      (set! len (+ len (floor (inexact->exact (* srate-scale stereo-spread))))))
	  (array-set! allpasses
		      (make-all-pass :size len :feedforward -1 :feedback 0.5)
		      c i))))
    (ws-interrupt?)
    (run
     (lambda ()
       (do ((i beg (1+ i)))
	   ((= i end))
	 (file->frame *reverb* i f-in)
	 (if (> in-chans 1)
	     (do ((c 0 (1+ c)))
		 ((= c out-chans))
	       (frame-set! f-in c (delay (array-ref predelays c) (frame-ref f-in c)))
	       (frame-set! f-out c 0.0)
	       (do ((j 0 (1+ j)))
		   ((= j numcombs))
		 (frame-set! f-out c (+ (frame-ref f-out c) (fcomb (array-ref combs c j)
								   (frame-ref f-in c))))))
	     (begin
	       (frame-set! f-in 0 (delay (array-ref predelays 0) (frame-ref f-in 0)))
	       (do ((c 0 (1+ c)))
		   ((= c out-chans))
		 (frame-set! f-out c 0.0)
		 (do ((j 0 (1+ j)))
		     ((= j numcombs))
		   (frame-set! f-out c (+ (frame-ref f-out c) (fcomb (array-ref combs c j)
								     (frame-ref f-in 0))))))))
	 (do ((c 0 (1+ c)))
	     ((= c out-chans))
	   (do ((j 0 (1+ j)))
	       ((= j numallpasses))
	     (frame-set! f-out c (all-pass (array-ref allpasses c j) (frame-ref f-out c)))))
	 (frame->file *output* i (frame->frame f-out out-mix out-buf)))))))

;; freeverb.scm ends here

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