[jsyn] CPU usage with looping threads
jsyn at music.columbia.edu
jsyn at music.columbia.edu
Wed May 16 12:33:26 EDT 2007
Hello JSyn list,
I have written this simple code to make a 8 tracks piece in a web
applet. every track has random values renewed at every queue.
It works quite fine, but as I can see from my CPU activity, it takes
a lot of usage. Maybe it's because of the way I structured the
thread. Can you please tell me if there's something very wrong with it?
public class FadesAppletPoly extends Applet implements Runnable
{
thread looper
PanUnit pan1
etc...
(...)
public void run()
{
while(go)
{
sinOsc1 = new SineOscillator();
envelope1 = new SynthEnvelope( envelope1Data );
Random r = new Random();
etc...
envelope1.setReleaseLoop( -1, -1 );
sinOsc1.frequency.set(440.0);
etc...
// Connect units and ports.
sinOsc1.output.connect( pan1.input);
etc...
sinOsc1.start();
pan1.start();
etc..
// reassign new random values and queue.
envelope1Data[0] = (r.nextFloat() * 30) + 0.02;
sinOsc1.frequency.set(newRandFreq);
int time = Synth.getTickCount();
envelope1 = new SynthEnvelope( envelope1Data );
time += (int) ( durataInSec) * rate;
envPlay1.envelopePort.clear();
envPlay1.envelopePort.queue(envelope1, 0, 4 );
Synth.sleepUntilTick( time );
envelope1.delete();
}
}
public boolean action(Event evt, Object what)
{
if( evt.target == hitme )
{
Synth.startEngine(0);
for (int j=1; j<8; j++) {
looper = new Thread(this);
looper.start();
}
}
public void stop()
{
go = false;
Synth.stopEngine();
removeAll();
}
}
(if needed you can test the online work-in-progress version here:
www.fades.net/Test/fades2.html)
Thank you in advance
Antonio
More information about the JSyn
mailing list