# [PlanetCCRMA] Re: sine waves in real time

**Bill Schottstaedt
**
bil at ccrma.Stanford.EDU

*Mon Oct 15 15:23:02 2007*

>* 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
30% of the time is handling the loops and writing output, nearly all the rest
is in the oscils, so if I were writing direct to a DAC, I'd estimate 200.
More interesting to me is the same question with the fm-violin -- I
think I get 53:
(with-sound (:statistics #t)
(do ((k 0 (1+ k)))
((= k 53))
(fm-violin 0 1 440 .01)))
;test.snd:
maxamp: 0.4320
compute time: 1.000
In the Common Lisp (sbcl) clm, I get around 68:
(with-sound (:srate 44100 :statistics t) (do ((i 0 (1+ i))) ((= i 68)) (fm-violin 0 1 440 .01)))
test.snd:
Duration: 1.0000, Last begin time: 0.0000
Compute time: 0.997, Compute ratio: 1.00
OutA max amp: 0.559 (near 0.249 secs)
"test.snd"
and presumably the sine wave case would scale similarly.