From jsyn at music.columbia.edu Wed May 16 12:33:26 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Wed May 16 12:12:54 2007 Subject: [jsyn] CPU usage with looping threads Message-ID: <260536EA-38CD-4E88-B709-692DFD87F03A@gmail.com> 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 From jsyn at music.columbia.edu Wed May 16 13:47:52 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Wed May 16 13:47:26 2007 Subject: [jsyn] CPU usage with looping threads In-Reply-To: <260536EA-38CD-4E88-B709-692DFD87F03A@gmail.com> References: <260536EA-38CD-4E88-B709-692DFD87F03A@gmail.com> Message-ID: <464B43C8.8030605@softsynth.com> Hello Antonio, > 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. On each iteration of the loop you are creating and starting new sine oscillators and and envelope players. They continue to run at the end of the loop. This means that they will slowly accumulate and eventually consume all of the CPU. It is better to create the units outside the loop and then just use same ones over and over. Also note that you can write() new values to an envelope instead of creating new envelopes. As an alternative to envelopes you can also use a LinearLag and simply write new target values to its input. The output will slowly change to the match the input. http://www.softsynth.com/jsyn/docs/autodocs/com/softsynth/jsyn/LinearLag.html Thank you, Phil Burk --------------------------------------- SoftSynth, Audio Research and Development http://www.softsynth.com/ 75 Pleasant Lane, San Rafael, CA, 94901 USA Phone/FAX: 1-415-453-4320 --------------------------------------- From jsyn at music.columbia.edu Sat May 19 19:50:46 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Sat May 19 19:30:03 2007 Subject: [jsyn] CPU usage with looping threads In-Reply-To: <464B43C8.8030605@softsynth.com> References: <260536EA-38CD-4E88-B709-692DFD87F03A@gmail.com> <464B43C8.8030605@softsynth.com> Message-ID: > > On each iteration of the loop you are creating and starting new > sine oscillators and and envelope players. They continue to run at > the end of the loop. This means that they will slowly accumulate > and eventually consume all of the CPU. > It is better to create the units outside the loop and then just use > same ones over and over. > Thank you Phil, definitely something wrong with my code.. :-/ I wonder if I have to create 8 sinOscillators since I want 8 simultaneous / independent tracks, or just make a single one and start it 8 times with passing new values each time. I worked around my java, but only got "cannot find symbol" or "NullPointerException" errors. Where should I create the units? Would you suggest me a brief brief structure scheme? that would be very helpful for me antonio From jsyn at music.columbia.edu Sat May 19 20:35:12 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Sat May 19 20:34:59 2007 Subject: [jsyn] CPU usage with looping threads In-Reply-To: References: <260536EA-38CD-4E88-B709-692DFD87F03A@gmail.com> <464B43C8.8030605@softsynth.com> Message-ID: <464F97C0.1020902@softsynth.com> > I wonder if I have to create 8 sinOscillators since I want 8 > simultaneous / independent tracks, or just make a single one and start Yes. Each oscillator object generate a tone at one frequency. For multiple frequencies you need multiple objects. Use arrays or Vectors to manage the multiple instances. Phil Burk From jsyn at music.columbia.edu Fri May 25 14:02:00 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Fri May 25 14:02:14 2007 Subject: [jsyn] JSyn under Linux Message-ID: <46572498.4090108@nefkom.net> I've successfully installed the JSyn-PlugIn via Firefox 1.5 under Linux (SUSE 10.0) and jre1.6.0_01. Test on Download-Site is successful too. But Running then a JSyn-Applet throws the message "com.softsynth.jsyn.SynthException: JSyn error: Host initialization failed. - , 0x0=0, 0x0=0". Can you help please? Wolfgang Fulda (Library installed at: /usr/share/jre1.6.0_01/lib/i386/client/libJSynV142.so JSynClasses.jar installed at: /usr/share/jre1.6.0_01/lib/ext/JSynClasses.jar) From jsyn at music.columbia.edu Fri May 25 14:09:53 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Fri May 25 14:09:50 2007 Subject: [jsyn] JSyn under Linux In-Reply-To: <46572498.4090108@nefkom.net> References: <46572498.4090108@nefkom.net> Message-ID: <46572671.4080103@softsynth.com> Hello, > I've successfully installed the JSyn-PlugIn via Firefox 1.5 under Linux > (SUSE 10.0) and jre1.6.0_01. Test on Download-Site is successful too. > But Running then a JSyn-Applet throws the message > "com.softsynth.jsyn.SynthException: JSyn error: Host initialization > failed. - , 0x0=0, 0x0=0". Can you help please? That seems like an audio initialization problem. Perhaps another application has ownership of audio. Please quit all other audio apps first. Do other audio apps work? If not then maybe you need to add your user to the "audio" group, or change the permissions of "/dev/dsp". Please consult your Linux distro docs for details. You can get more detail about the JSyn installation with this diagnostic Applet: http://www.softsynth.com/jsyn/support/diagnostic.html Thank you, Phil Burk --------------------------------------- SoftSynth, Audio Research and Development http://www.softsynth.com/ 75 Pleasant Lane, San Rafael, CA, 94901 USA Phone/FAX: 1-415-453-4320 --------------------------------------- From jsyn at music.columbia.edu Fri May 25 18:32:13 2007 From: jsyn at music.columbia.edu (jsyn@music.columbia.edu) Date: Fri May 25 18:32:21 2007 Subject: [jsyn] JSyn under Linux In-Reply-To: <46572671.4080103@softsynth.com> References: <46572498.4090108@nefkom.net> <46572671.4080103@softsynth.com> Message-ID: <465763ED.9040604@nefkom.net> jsyn@music.columbia.edu schrieb: > Hello, > > > I've successfully installed the JSyn-PlugIn via Firefox 1.5 under Linux > > (SUSE 10.0) and jre1.6.0_01. Test on Download-Site is successful too. > > But Running then a JSyn-Applet throws the message > > "com.softsynth.jsyn.SynthException: JSyn error: Host initialization > > failed. - , 0x0=0, 0x0=0". Can you help please? > > > That seems like an audio initialization problem. Perhaps another > application has ownership of audio. Please quit all other audio apps > first. > > Do other audio apps work? If not then maybe you need to add your user > to the "audio" group, or change the permissions of "/dev/dsp". Please > consult your Linux distro docs for details. > > You can get more detail about the JSyn installation with this > diagnostic Applet: > > http://www.softsynth.com/jsyn/support/diagnostic.html > > Thank you, > Phil Burk Thank you so much, Phil, for your immediate support - I think that should help ... Wolfgang