Re: [LAD] Prototyping algorithms and ideas

From: Kjetil S. Matheussen <k.s.matheussen@email-addr-hidden>
Date: Wed Jan 30 2008 - 10:45:35 EET

Le 29 janv. 08 à 23:36, Yann Orlarey a écrit :

> Hi Fons,
>
> Here is a quick solution using Faust :
>
> import("filter.lib");
>
> line(i) = vgroup("line %i", *(g) : fdelay2(1024, d))
> with { g = vslider("gain (dB)", -60, -60, 4, 0.1) :
> db2linear :
> smooth(0.995);
> d = nentry("delay (samp)", 0, 0, 1000, 0.1) :
> smooth(0.995); };
>
> process = hgroup("", par(i, 10, line(i)) );
>
> The first line imports a library of filters (written in Faust by
> Julius
> Smith) that includes several fractional delays based on Lagrange
> interpolation.
>
> Then we define a 'line' that combines in sequence (':' operator) a
> gain
> and a fractional delay encapsulated in a vertical layout. Here we use
> fdelay2 a fractional delay with a second order Lagrange interpolation.
> It can be replaced by fdelay3 or fdelay4 if better interpolations are
> needed.
>
> The gain value g is defined by a vertical slider (in dB) which is
> converted in a linear value and then filtered to avoid clicks during
> rapid movements. The delay value d is defined by a numerical entry box
> also filtered to avoid clicks. The parameter m is the maximum size of
> the delay and should be a power of 2.
>

Wow, that is cool. I wonder about making some faust inspired macros
for snd-rt to make user interfaces more integrated.

I think the snd-rt program below should do the same
as the faust version now, although I'm not too sure about the
correctnes of the delay interpolation and filtering. They both
sounds the same though, I think:

(set! (rt-safety) 0)
(definstrument (line n dialog)
   (let ((del (make-delay 1 :type mus-interp-lagrange
                            :max-size 20000))
         (length (make-glide-var 0 100))
         (gain (make-glide-var 0 0.005)))
     (<slider> dialog (<-> "gain " n) 0 0 2
               (lambda (val)
                 (write-glide-var gain val))
               100)
     (<slider> dialog (<-> "delay " n) 1 1 20000
               (lambda (val)
                 (write-glide-var length val))
               1)
     (<rt-play>
      (lambda ()
        (set! (mus-length del) (read-glide-var length))
        (out 0 (* (read-glide-var gain)
                  (delay del (in 0))))))))

(letrec* ((exit (lambda ()
                   (rte-silence!)
                   (-> dialog hide)))
           (dialog (<dialog> "Delay line stuff" exit
                             " exit " exit
                             "Stop" rte-pause
                             "Start" rte-continue)))
   (for-each (lambda (n) (line n dialog))
             (map number->string (iota 10)))
   (-> dialog show))

The faust program uses 2.1% percent cpu on my xp2800, while
the snd-rt program now uses 3.8% percent cpu. The reason
for the speed increase for the snd-rt program is because
the scheme list traversals and vector accesses is
removed from the dsp code. Instead the scheduler just runs
10 realtime instances. To run the program, just paste the
code above into snd-ls' terminal.

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Wed Jan 30 12:15:02 2008

This archive was generated by hypermail 2.1.8 : Wed Jan 30 2008 - 12:15:03 EET