A
download freeverb.rb
Language: Ruby
LOC: 152
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.rb -- CLM -> Snd/Ruby translation of freeverb.ins

# Translator/Author: Michael Scholz <scholz-micha@gmx.de>
# Last: Wed Mar 23 23:08:12 CET 2005

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

# Code:

require "examp"
require "ws"
with_silence(LoadError) do require "sndins" end

# Snd-Ruby's freeverb and fcomb (see sndins.so for a faster one).

unless provided? :sndins
  class Fcomb
    def initialize(scaler, size, a0, a1)
      @feedback = scaler.to_f
      @delay = make_delay(size.to_i)
      @filter = make_one_zero(a0, a1)
    end
    attr_accessor :feedback

    def fcomb(input = 0.0)
      delay(@delay, input + one_zero(@filter, tap(@delay)) * @feedback)
    end

    def inspect
      format("#<%s: %s, %s, feedback: %0.3f>",
             self.class, @delay.inspect, @filter.inspect, @feedback)
    end
  end
  
  def make_fcomb(scaler = 0.0, size = 1, a0 = 0.0, a1 = 0.0)
    Fcomb.new(scaler, size, a0, a1)
  end

  def fcomb(gen, input = 0.0)
    gen.fcomb(input)
  end

  def fcomb?(obj)
    obj.kind_of?(Fcomb)
  end
end

add_help(:freeverb_rb, "freeverb_rb(start, dur, *args)
        :room_decay,        0.5,
        :damping,           0.5,
        :global,            0.3,
        :predelay,          0.03,
        :output_gain,       1.0,
        :output_mixer,      nil,
        :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,
with_sound(:reverb, :freeverb_rb) do fm_violin_rb(0, 1, 440, 0.3) end
This is the Ruby version of freeverb.  For a faster one see sndins.so.")
def freeverb_rb(start = 0, dur = 1, *args)
  room_decay        = get_args(args, :room_decay, 0.5)
  damping           = get_args(args, :damping, 0.5)
  global            = get_args(args, :global, 0.3)
  predelay          = get_args(args, :predelay, 0.03)
  output_gain       = get_args(args, :output_gain, 1.0)
  output_mixer      = get_args(args, :output_mixer, nil)
  scale_room_decay  = get_args(args, :scale_room_decay, 0.28)
  offset_room_decay = get_args(args, :offset_room_decay, 0.7)
  combtuning        = get_args(args, :combtuning, [1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617])
  allpasstuning     = get_args(args, :allpasstuning, [556, 441, 341, 225])
  scale_damping     = get_args(args, :scale_damping, 0.4)
  stereo_spread     = get_args(args, :stereo_spread, 23)
  out_mix = (mixer?(output_mixer) ? output_mixer : make_mixer(@channels))
  out_buf = make_frame(@channels)
  out_gain = output_gain
  f_out = make_frame(@channels)
  predelays = make_array(@reverb_channels)
  local_gain = (1.0 - global) * (1.0 - 1.0 / @channels) + 1.0 / @channels
  global_gain = (@channels - local_gain * @channels) / [(@channels * @channels - @channels), 1].max
  srate_scale = @srate / 44100.0
  room_decay_val = room_decay * scale_room_decay + offset_room_decay
  numcombs = combtuning.length
  numallpasses = allpasstuning.length
  combs = make_array(@channels) do make_array(numcombs) end
  allpasses = make_array(@channels) do make_array(numallpasses) end
  if @reverb_channels > 1 and @reverb_channels != @channels
    error("input must be mono or input channels must equal output channels")
  end
  unless mixer?(output_mixer)
    if output_mixer.kind_of?(Array)
      @channels.times do |i|
        @channels.times do |j|
          mixer_set!(out_mix, i, j, output_mixer[i][j])
        end
      end
    else
      @channels.times do |i|
        @channels.times do |j|
          mixer_set!(out_mix, i, j, (out_gain * (i == j ? local_gain : global_gain)) / @channels)
        end
      end
    end
  end
  if predelay.kind_of?(Array)
    @reverb_channels.times do |c|
      predelays[c] = make_delay(:size, (@srate * predelay[c]).to_i)
    end
  else
    @reverb_channels.times do |c|
      predelays[c] = make_delay(:size, (@srate * predelay).to_i)
    end
  end
  if damping.kind_of?(Array)
    @channels.times do |c|
      combtuning.each_with_index do |tuning, i|
        l = (srate_scale * tuning).round
        dmp = scale_damping * damping[i]
        l += (srate_scale * stereo_spread).round if c.odd?
        combs[c][i] = make_fcomb(room_decay_val, l, 1.0 - dmp, dmp)
      end
    end
  else
    @channels.times do |c|
      combtuning.each_with_index do |tuning, i|
        l = (srate_scale * tuning).round
        dmp = scale_damping * damping
        l += (srate_scale * stereo_spread).round if c.odd?
        combs[c][i] = make_fcomb(room_decay_val, l, 1.0 - dmp, dmp)
      end
    end
  end
  @channels.times do |c|
    allpasstuning.each_with_index do |tuning, i|
      l = (srate_scale * tuning).round
      l += (srate_scale * stereo_spread).round if c.odd?
      allpasses[c][i] = make_all_pass(:size, l, :feedforward, -1, :feedback, 0.5)
    end
  end
  run_reverb(start, dur, :frames) do |f_in, i|
    if @reverb_channels > 1
      @channels.times do |c|
        frame_set!(f_in, c, delay(predelays[c], frame_ref(f_in, c)))
        frame_set!(f_out, c, 0.0)
        numcombs.times do |j|
          frame_set!(f_out, c, frame_ref(f_out, c) + fcomb(combs[c][j], frame_ref(f_in, c)))
        end
      end
    else
      frame_set!(f_in, 0, delay(predelays[0], frame_ref(f_in, 0)))
      @channels.times do |c|
        frame_set!(f_out, c, 0.0)
        numcombs.times do |j|
          frame_set!(f_out, c, frame_ref(f_out, c) + fcomb(combs[c][j], frame_ref(f_in, 0)))
        end
      end
    end
    @channels.times do |c|
      numallpasses.times do |j|
        frame_set!(f_out, c, all_pass(allpasses[c][j], frame_ref(f_out, c)))
      end
    end
    frame2frame(f_out, out_mix, out_buf)
  end
end

class Snd_Instrument
  alias freeverb freeverb_rb
end

=begin
with_sound(:reverb, :freeverb_rb,
           :reverb_data, [:room_decay, 0.9],
           :channels, 2,
           :reverb_channels, 1,
           :output, "fvrb-test.snd",
           :play, 1,
           :statistics, true) do
  fm_violin_rb(0, 1, 440, 0.5)
end
=end

# freeverb.rb ends here

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