[LAD] Prototyping algorithms and ideas

Kjetil S. Matheussen k.s.matheussen at notam02.no
Tue Jan 29 19:17:37 UTC 2008


Fons Adriaensen:
>
> On Fri, Jan 25, 2008 at 12:57:19PM -0500, Stephen Sinclair wrote:
>
>>>> Also, nice in the fact that you can do per-sample computations easily,
>>>
>>> How ? I seem to have missed something...
>>
>> Because you can wait in a 1-sample loop?
>>
>> Yes, it will use your whole CPU for a loop like that, but this thread
>> is about prototyping.  Obviously you'd rewrite in C for a real
>> application.
>> I never claimed chuck is perfect, but I've been liking it a lot
>> lately.  Sure, it can have performance issues depending on how you use
>> it, but the nice thing is having the option to abuse it that way when
>> necessary.
>
> This is one of the things I wanted to create a 'rapid prototype'
> for recently. I needed a jack client implementing:
>
> - a delay line,
> - allowing high-quality fractional-sample delays,
> - at least 12 outputs, for each two controls: delay, gain,
> - smooth 'crossfading' between two control sets, both delay
>  and gain, controlled by a GUI or by OSC.
>
> It should not take more than 20% CPU on a 2G P4
> (other things have to run at the same time).
> If you know how to get this faster than by actually
> writing it in C++, please let me know !
>

Quick version for snd-rt below. It use about 10% on my
xp2800, but its easy to optimize so that it use a lot less
by making the dsp function call "out" and "in" only one
time. (that optimization requires two more lines of code,
but the version below is the straight forward one)

I'm not quite sure what you mean by "smooth 'crossfading'" though,
but at least the gain values are interpolated to avoid clicks
when changing values. I'm not sure if that was what you ment.

Guess its time to learn scheme now Fons? ;-)
Oh well, hopefully someone will find this interesting.
To run it, just paste the text below into the terminal snd-ls
was started from.


(define-rt-vector-struct das-delay
   :delay (make-delay 20000)
   :gain (make-glide-var 0 0.001))

(definstrument (mdelay num-delays)
   (letrec* ((das-delays (map make-das-delay (iota num-delays)))
 	    (instrument (<rt-play>
 			 (lambda ()
 			   (for-each (lambda (das-delay)
 				       (out (* (read-glide-var (=> das-delay :gain))
 					       (delay (=> das-delay :delay) (in)))))
 				     das-delays))))
 	    (exit (lambda ()
 		    (-> instrument stop)
 		    (-> d hide)))
 	    (d (<dialog> "multi delay"  exit
 			 "Close" exit
 			 "Stop" (<- instrument stop)
 			 "Start" (<- instrument play))))
     (for-each (lambda (n das-delay)
 		(set! (mus-length (=> das-delay :delay)) 1)
 		(<slider> d (<-> "gain  " n) 0 0 2
 			  (lambda (val)
 			    (write-glide-var (=> das-delay :gain) val))
 			  100)
 		(<slider> d (<-> "delay " n) 1 1 20000
 			  (lambda (val)
 			    (set! (mus-length (=> das-delay :delay)) val))
 			  1))
 	      (map number->string (iota num-delays))
 	      das-delays)
     (-> d show)))

(define mdel (mdelay))




More information about the Linux-audio-dev mailing list