[CM] snd-rt problem

Kjetil S. Matheussen k.s.matheussen at notam02.no
Wed Jun 4 11:23:39 PDT 2008

On Wed, 4 Jun 2008, border wrote:

> Hey (Kjetil)
> Dunno if I should post troubles with snd-rt here on the mailing-list or
> mail them directly to Kjetil, so in the meantime I'll post them here
> like I did before.
> If I run this code:
> ((lambda (hertz)
>   (do ((x 1 (+ x 1)))
>       ((> x (- (/ (/ (rte-samplerate) 2) hertz) 1)))
>     (begin
>       (print x)
>       (<rt-out> 0 (* 0.5
> 		      (/ 1 x)
> 		      (oscil* (* hertz x)))))))
> 200)
> everything works as expected, generating a saw-wave up to the nyquist
> frequency on channel 0.
> But if I want to run the same code on channel 1, the saw-wave from
> channel 0 gets distorted a lot, and newly generated one is as expected.
> Is there an explanatino for this kind of behaviour?
> I have tried all kinds of volume levels, saw-wave levels, reversed the
> channels still the result remains.
> Only if I keep the number of sines generated below 40-45 then I get
> acceptable results (but not acceptable saw-waves).
> I do need the control over the different frequencies badly, otherwise I
> would've use another saw-wave generator probably.
> Thanks for looking at it.

You are simply using too much cpu. Snd-rt doesn't tell you,
although it probaby should, when you use too much cpu. Instead
it won't run remaining queued instruments. And since instruments
are placed first in the scheduling queue, the instruments
you add first are the one not to be played. Instruments using
more cpu also gets a penalty, if I remember correctly, so
they will not be run at next block iteration, which explains
the distorted-like sound.

I think this is a good example where you should use coroutines. Coroutines
are only in CVS, and they are not very stable yet. But using coroutines
you could write something like this:

  ((lambda (hertz)
     (do ((x 1 (+ x 1)))
         ((> x (- (/ (/ (rte-samplerate) 2) hertz) 1)))
         (define phase 0.0)
         (declare (<double> phase))
         (debug "%d" x)
         (out 0 (* 0.05
                   (/ 1 x)
                   (sin phase)))
         (inc! phase (hz->radians (* hertz x))))))

(not tested)

But until I do a lot of debugging on that feature,
you should instead try to use only one instrument
playing all oscillators. I think the most efficient
way would be to allocate all oscillators in a vector
first before starting the instrument.

More information about the Cmdist mailing list