# [PlanetCCRMA] Re: Re: sine waves in real time

**Kjetil S. Matheussen
**
kjetil.matheussen at notam02.no

*Tue Oct 16 13:00:01 2007*

Fernando Lopez-Lezcano:
>* On Mon, 2007-10-15 at 15:22 -0700, Bill Schottstaedt wrote:
*>>>* On a very recent Intel laptop running a Core Duo at 2.4GHz (I think
*>>>* that's the speed), SuperCollider would do 500 interpolated sine
*>>>* oscillators with a (roughly) 50% cpu load (in one of the cores).
*>>*
*>>* In the Scheme version of Snd, at 44100 KHz, I get about 180 such
*>>* sines (actually, I'm calling the sin function, not interpolating some
*>>* table):
*>>*
*>>* (with-sound (:statistics #t)
*>>* (let ((gens (make-vector 180)))
*>>* (do ((i 0 (1+ i)))
*>>* ((= i 180))
*>>* (vector-set! gens i (make-oscil (* 10 (1+ i)) (random (* 2 pi)))))
*>>* (run
*>>* (lambda ()
*>>* (do ((i 0 (1+ i)))
*>>* ((= i 44100))
*>>* (let ((sum 0.0))
*>>* (do ((k 0 (1+ k)))
*>>* ((= k 180))
*>>* (set! sum (+ sum (oscil (vector-ref gens k)))))
*>>* (outa i (* .01 sum) *output*)))))))
*>>*
*>>* ;test.snd:
*>>* maxamp: 0.2935
*>>* compute time: 1.020
*>*
*>* Wow, that's impressive. 180 directly from scheme...
*>* I never tried Kjetil's realtime snd, that would (presumable) be faster?
*>*
*
Just tried. And yes, its about twice as fast:
(let* ((num 130)
(gens (make-vector num)))
(do ((i 0 (1+ i)))
((= i num))
(vector-set! gens i (make-oscil (* 10 (1+ i)) (random (* 2 pi)))))
(set! (rt-safety) 0)
(<rt-play> 0 10
(lambda ()
(let ((sum 0.0))
(do ((k 0 (1+ k)))
((= k num))
(set! sum (+ sum (oscil (vector-ref gens k)))))
(out (* .01 sum))))))
Here's the generated c-code for the inner loop:
static void rt_gen1__3(struct RT_Globals *rt_globals)
{
while (!((rt_globals->k__2 == rt_globals->num__4))) {
(rt_globals->sum__1 =
(rt_globals->sum__1 +
mus_oscil(XEN_TO_MUS_ANY
(SCM_VECTOR_REF
(rt_globals->gens__5, ((int) rt_globals->k__2))), 0,
0)), rt_globals->k__2 = (1 + rt_globals->k__2)
);
};
}
Its not quite optimal, but still I'm pretty
sure most of the time is spent in mus_oscil.
So I'm also pretty sure the oscillator generator in supercollider is super
fast.