Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-08-2008, 01:14 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
JAVA a cross-platform language? I have my doubts!
I have been working quit some time on a twenty-year-old Pascal program, translating it into java. The program manipulates a small Yamaha synthesizer called FBO-1. Al the program does is sending timed midi code numbers to the synthesizer and there is where the problem lays. The midi code transition is based on large timed-loops (a swing clock of 7 mili sec is set). The problem I am experiencing is that the timing of each soundtrack is very different on PC compared to MAC (interesting to know is that my 8-year-sold-slow G4 mac synchronizes perfect with my new macbook, so it is definitely not a CPU speed problem). Curiously my MAC is much faster compared to the PC. Is there anybody who can shine some light on my JAVA-darkness, because for the moment the thing simply does not go on PC and I do not know what to do!
(I include the first sound track code as an example, the other tracks work on the same principle)





Code:
//-------------------------------------------------------------------- //klankblokken 1-----12 public void Soundblock1() { int tel=0, teller=0, fractie=0, toon=0, tijd1=0, tijd2=0, tijd3=0, i1=0, i2=0, i3=0, i4=0, i5=0, stem=0, vel=0, waarde=0, x=0, y=0, toon1=0, toon2=0; cont.setpedFlag(false); System.out.println("entering in soundblock 1 " + (System.currentTimeMillis() - starttime)); cont.ed.midi_datadump(1,1,5); System.out.println("DATADUMP 1 DONE " + (System.currentTimeMillis() - starttime)); cont.setInfo(" DATADUMP 1 DONE \n\n",false); cont.ed.midi_datadump(2,6,8); System.out.println("DATADUMP 2 DONE " + (System.currentTimeMillis() - starttime)); cont.setInfo(" DATADUMP 2 DONE \n\n",true); cont.ed.midi_data(algemeen,"fdb",7,6,8); cont.ed.midi_stereo(1,1,links); cont.ed.midi_stereo(2,3,midde); cont.ed.midi_stereo(4,4,rechts); cont.ed.midi_stereo(5,6,links); cont.ed.midi_stereo(7,8,midde); cont.ed.midi_vel(1,4,67); cont.ed.midi_vel(5,8,97); System.out.println("WAITING FOR PEDAL 1 (time reset on start seq) " + (System.currentTimeMillis() - starttime)); cont.setInfo(" WAITING FOR PEDAL 1 \n\n",true); waitforPedal(); System.out.println(" 1 pedal done "); cont.setInfo(" PEDAL 1 DONE \n\n",true); cont.clkset(6,237); do { if (cont.getescFlag()) { exit=true; //exit the soundblock } if (cont.clkpls>=tel*7 && tel<=60) { tel=tel+1; cont.ed.midi_vel(1,4,67+tel); } if (cont.clkpls>=50*teller) { teller=teller+1; if (teller>10 && teller<=40) cont.ed.midi_vel(5,8,97+teller-10); } if (teller==8) cont.ed.midi_data(algemeen,"fdb",1,1,2); if (teller==12) cont.ed.midi_data(algemeen,"fdb",1,3,4); if (teller==14) cont.ed.midi_data(algemeen,"fdb",2,1,2); if (teller==19) cont.ed.midi_data(operator4,"lev",8,1,2); if (teller==23) cont.ed.midi_data(operator4,"lev",8,3,4); if (teller==25) cont.ed.midi_data(algemeen,"fdb",3,3,4); if (teller==29) cont.ed.midi_data(algemeen,"fdb",3,1,2); if (teller==31) cont.ed.midi_data(algemeen,"fdb",4,1,2); if (teller==34) cont.ed.midi_data(algemeen,"fdb",5,3,4); if (teller==38) cont.ed.midi_data(algemeen,"fdb",5,1,2); if (teller==40) cont.ed.midi_data(operator4,"lev",7,1,2); if (teller==43) cont.ed.midi_data(operator4,"lev",7,3,4); if (teller==45) cont.ed.midi_data(operator4,"lev",6,1,2); if (teller==49) cont.ed.midi_data(operator4,"lev",6,3,4); if (teller==52) cont.ed.midi_data(operator4,"lev",5,1,4); if (teller==53) cont.ed.midi_data(operator4,"lev",4,1,4); if (teller==55) cont.ed.midi_data(operator4,"lev",3,1,4); if (teller==56) cont.ed.midi_data(operator4,"lev",1,1,4); if (teller==57) { cont.ed.midi_data(operator4,"lev",0,1,4); cont.ed.midi_data(operator4,"d1r",6,1,4); cont.ed.midi_data(operator3,"lev",3,1,4); cont.ed.midi_data(algemeen,"fdb",7,1,4); } if (teller==12) waarde=134; if (teller==19) waarde=259; if (teller==23) waarde=378; if (teller==30) waarde=491; if (teller==37) waarde=598; if (teller==43) waarde=700; if (teller==52) waarde=798; if (teller==6) cont.ed.midi_vel(5,8,97); if (cont.clkpls>=tijd1) { tijd1=cont.ed.random(startgetal,80-teller,400-(6*teller))+tijd1; //? //System.out.println("tijd1 " + tijd1); if (teller<=58) { boo1=false; boo2=false; boo3=false; boo4=false; } x = cont.ed.random(startgetal,1,4); y = cont.ed.random(startgetal,1,2); // System.out.println("boo1-4 " + x); if (x==1) boo1=true; else if (x==2) boo2=true; if (y==1) boo3=true; else if (y==2) boo4=true; } if (cont.clkpls>=7*i1) { //3 i1=i1+1; if (boo1 || boo2) { toon=cont.ed.random(startgetal,1,waarde); fractie= toon % 127; toon= toon / 127; vel=cont.ed.random(startgetal,80,100); stem=cont.ed.random(startgetal,1,2); if (boo1=true) stem=2; if (boo2=true) stem=1; cont.ed.midi_toon(stem,50+toon,fractie,vel); } } if (cont.clkpls>=9*i2) { //4 i2=i2+1; if (boo3 || boo4) { toon=cont.ed.random(startgetal,1,waarde); fractie= toon % 127; toon= toon / 127; vel=cont.ed.random(startgetal,80,100); stem=cont.ed.random(startgetal,3,4); if (boo3=true) stem=4; if (boo4=true) stem=3; cont.ed.midi_toon(stem,50+toon,fractie,vel); } } if (cont.clkpls>=tijd3) { cont.ed.midi_toon(5,20,cont.ed.random(startgetal,0,127),cont.ed.random(startgetal,50,80)); tijd3 = cont.ed.random(startgetal,10,60)+tijd3; } if ((cont.clkpls>=400+tijd2) || (teller==56) || (teller==58)) { tijd2=cont.ed.random(startgetal,30,600)+tijd2; cont.ed.midi_data(algemeen,"fdb",cont.ed.random(startgetal,5,7),5,8); if (teller>=58) { cont.ed.midi_data(algemeen,"fdb",7,5,8); cont.ed.midi_data(operator4,"lev",0,5,8); } toon=cont.ed.random(startgetal,16,17); // System.out.println("ransdom 16-7 " + toon); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(5,toon,fractie,127); toon=cont.ed.random(startgetal,17,18); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(6,toon,fractie,127); toon=cont.ed.random(startgetal,18,19); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(7,toon,fractie,127); } } while (teller<61 && !exit); //midi datadump no 3 cont.ed.midi_datadump(1,6,7); System.out.println("DATADUMP 3 DONE"); cont.setInfo(" DATADUMP 3 DONE \n\n",false); cont.ed.midi_data(algemeen,"fdb",6,1,8); cont.ed.midi_data(operator4,"d1r",3,1,8); cont.ed.midi_data(operator4,"lev",4,1,8); cont.ed.midi_data(operator3,"lev",7,1,8); cont.clkset(6,237); cont.ed.midi_toon(1,50+b_toon1,b_fractie1,127); do {} while (cont.clkpls<=3); cont.ed.midi_toon(2,50+b_toon2,b_fractie2,127); cont.ed.midi_toon(3,50+b_toon3,b_fractie3,127); do {} while (cont.clkpls<=7); cont.ed.midi_toon(4,50+b_toon4,b_fractie4,127); do {} while (cont.clkpls<=5); cont.ed.midi_toon(5,50+b_toon5,b_fractie5,127); do {} while (cont.clkpls<=4); cont.ed.midi_toon(6,50+b_toon6,b_fractie6,127); cont.ed.midi_toon(7,50+b_toon7,b_fractie7,127); do { } while (cont.clkpls<700 && !exit ); cont.ed.midi_toon(3,50+b_toon3,b_fractie3,0); cont.ed.midi_toon(4,50+b_toon4,b_fractie4,0); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-08-2008, 01:30 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
So the hearth beat of this code is the var clkpls and all small counters called in Dutch "tellers" are synchronized on this var.


Code:
miditimer = new Timer(midiclockrate, listener); // sets the midi clock miditimer.setRepeats(true); class EventHandler implements ActionListener { public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == miditimer) { // clkpls reads out the pascal timer clkpls++; // augments the clock pulse counter } public void clkset(int x, int y) { // after pascal clkset(6,klok); para not used // miditimer.stop(); // I do not know if you should stop a timer miditimer.start(); // before starting miditimer.setRepeats(true); clkpls = 0; System.out.println(" midi clock started, rate in mili " + midiclockrate); } public void stopclk() { miditimer.stop(); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-08-2008, 10:54 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Java is platform independent. But talking to MIDI is not, it is, by definition, very hardware defendant.

I can't follow what your problem is, but you may need to clock out the MIDI bytes. This is not generally needed, but its hard to tell.

An obvious example where you need to clock it is if you send

1) note on, A440
2) note off,

You need to make sure that the note off comes only after the proper time, say a half note or quarter note in the current time signature.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-08-2008, 12:41 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
Do not worry about the timing of the midi code, I control the program by ear and all works perfect (this is really the amazing part of the story, because I have a recording of the work, of the old Pascal version, of the Dutch radio which sounds very similar to the new JAVA version). There is a design problem of the program (norm and nick have pointed that out already). The principle of the midi sound tracks is basically this:
Loop
If (timex1), go midi data
If (timex2), go midi data
If (timex3), go midi data
etc
while (timex4)

Several professional programmers said the loop is no good: it will cook up the CPU. Because all these go´s go "simultaneously", should each one start a new thread? This program has only one single purpose; it should be used on a concert or rehearsal of the work Cités, for voice and cello, after apollinaire (even when you would have the FBO1 synthesizer (it will not run on any other) it makes no sense to listen to the tracks without the cello and the voice). When running the program no other thing should and can be done on the computer anyway. It makes no sense to simply record the tracks because they run on random stuff and are interactive with the cello player through a midi pedal. From a standpoint of a prof programmer all this is crazy. But I am very much afraid that when redesigning the whole program another result would come out.

Sure the loop above runs different on each platform and comp. But the all if statements are timed. Why is the result is similar on every mac but different on pc (the sound take twice as long) I do not understand?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-08-2008, 09:09 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Threads are how you do things in Java. They have been built into the language from the very first.

A cruder approach would be to put a Thread.sleep(50)
in your loop. But the real Java way is to have a separate timer thread, and use
CyclicBarrier or Semaphore to communicate.

The timer thread approach is more robust, as it can keep time independently of the worker thread. This is good, because you don't know how long each task is going to take the worker to do.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-10-2008, 04:11 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
ok threads and timer/ worker apart, that makes sense.

But still I´d like to understand why this:
for macbook -> end of loop 21256 teller 61
for pc -> end of loop 55079 teller 61



Code:
cont.clkset(7,237); // starts the swingclock on 7 milli sec. starttime = System.currentTimeMillis(); do { if (cont.getescFlag()) { exit=true; //exit the soundblock } if (cont.clkpls>=tel*7 && tel<=60) { // clkpls augments with each 7 mili tel=tel+1; cont.ed.midi_vel(1,4,67+tel); } if (cont.clkpls>=50*teller) { teller=teller+1; System.out.println(" teller " + teller); if (teller>10 && teller<=40) cont.ed.midi_vel(5,8,97+teller-10); } if (teller==8) cont.ed.midi_data(algemeen,"fdb",1,1,2); if (teller==12) cont.ed.midi_data(algemeen,"fdb",1,3,4); if (teller==14) cont.ed.midi_data(algemeen,"fdb",2,1,2); if (teller==19) cont.ed.midi_data(operator4,"lev",8,1,2); if (teller==23) cont.ed.midi_data(operator4,"lev",8,3,4); if (teller==25) cont.ed.midi_data(algemeen,"fdb",3,3,4); if (teller==29) cont.ed.midi_data(algemeen,"fdb",3,1,2); if (teller==31) cont.ed.midi_data(algemeen,"fdb",4,1,2); if (teller==34) cont.ed.midi_data(algemeen,"fdb",5,3,4); if (teller==38) cont.ed.midi_data(algemeen,"fdb",5,1,2); if (teller==40) cont.ed.midi_data(operator4,"lev",7,1,2); if (teller==43) cont.ed.midi_data(operator4,"lev",7,3,4); if (teller==45) cont.ed.midi_data(operator4,"lev",6,1,2); if (teller==49) cont.ed.midi_data(operator4,"lev",6,3,4); if (teller==52) cont.ed.midi_data(operator4,"lev",5,1,4); if (teller==53) cont.ed.midi_data(operator4,"lev",4,1,4); if (teller==55) cont.ed.midi_data(operator4,"lev",3,1,4); if (teller==56) cont.ed.midi_data(operator4,"lev",1,1,4); if (teller==57) { cont.ed.midi_data(operator4,"lev",0,1,4); cont.ed.midi_data(operator4,"d1r",6,1,4); cont.ed.midi_data(operator3,"lev",3,1,4); cont.ed.midi_data(algemeen,"fdb",7,1,4); } if (teller==12) waarde=134; if (teller==19) waarde=259; if (teller==23) waarde=378; if (teller==30) waarde=491; if (teller==37) waarde=598; if (teller==43) waarde=700; if (teller==52) waarde=798; if (teller==6) cont.ed.midi_vel(5,8,97); if (cont.clkpls>=tijd1) { tijd1=cont.ed.random(startgetal,80-teller,400-(6*teller))+tijd1; //? //System.out.println("tijd1 " + tijd1); if (teller<=58) { boo1=false; boo2=false; boo3=false; boo4=false; } x = cont.ed.random(startgetal,1,4); y = cont.ed.random(startgetal,1,2); // System.out.println("boo1-4 " + x); if (x==1) boo1=true; else if (x==2) boo2=true; if (y==1) boo3=true; else if (y==2) boo4=true; } if (cont.clkpls>=7*i1) { //3 i1=i1+1; if (boo1 || boo2) { toon=cont.ed.random(startgetal,1,waarde); fractie= toon % 127; toon= toon / 127; vel=cont.ed.random(startgetal,80,100); stem=cont.ed.random(startgetal,1,2); if (boo1=true) stem=2; if (boo2=true) stem=1; cont.ed.midi_toon(stem,50+toon,fractie,vel); } } if (cont.clkpls>=9*i2) { //4 i2=i2+1; if (boo3 || boo4) { toon=cont.ed.random(startgetal,1,waarde); fractie= toon % 127; toon= toon / 127; vel=cont.ed.random(startgetal,80,100); stem=cont.ed.random(startgetal,3,4); if (boo3=true) stem=4; if (boo4=true) stem=3; cont.ed.midi_toon(stem,50+toon,fractie,vel); } } if (cont.clkpls>=tijd3) { cont.ed.midi_toon(5,20,cont.ed.random(startgetal,0,127),cont.ed.random(startgetal,50,80)); tijd3 = cont.ed.random(startgetal,10,60)+tijd3; } if ((cont.clkpls>=400+tijd2) || (teller==56) || (teller==58)) { tijd2=cont.ed.random(startgetal,30,600)+tijd2; cont.ed.midi_data(algemeen,"fdb",cont.ed.random(startgetal,5,7),5,8); if (teller>=58) { cont.ed.midi_data(algemeen,"fdb",7,5,8); cont.ed.midi_data(operator4,"lev",0,5,8); } toon=cont.ed.random(startgetal,16,17); // System.out.println("ransdom 16-7 " + toon); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(5,toon,fractie,127); toon=cont.ed.random(startgetal,17,18); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(6,toon,fractie,127); toon=cont.ed.random(startgetal,18,19); fractie=cont.ed.random(startgetal,0,127); cont.ed.midi_toon(7,toon,fractie,127); } } while (teller<61 && !exit); System.out.println(" end of loop " + (System.currentTimeMillis() - starttime) + " teller " + teller);
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-10-2008, 04:14 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
the origen of clkpls clkset you in the miditimer above
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 10-17-2008, 01:15 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
I am not sure, but I can not get the timer to run
below the 10 msec on PC (on mac no problem)
So there lies the problem of my delay for sure!
(I am trying to feed the timer with 7 msec
but it keeps on going on 10 on pc)
First I used a swing timer but changed it
into the java.util.Timer.....
but still makes no difference on PC (like I
said can not get any faster as 10 msec)
I can not get find documentation on that issue either!
Strange issue, or not?

who can make this problem less timeless?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 10-17-2008, 05:22 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Can you write a short program that demonstrates the problem so we can see/work on it.
The wait() method has a nanosecond arg.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 10-17-2008, 10:31 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
Does not make any sense,
It has something to do with the pc os,
the information I got says:
Thread.sleep(int msec) can go below 10 msec
Windows' multimedia timers run at 100 nanosecond resolution

So I quote from an external email I got yesterday:
"so it's just that Sun drilled into the wrong timer with their high-level stuff."

SO YOU CAN NOT GET ANYTHING FASTER?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 10-17-2008, 11:08 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Faster than what? 100 nanoseconds?
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 10-18-2008, 12:44 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
on mac I run the clock on 7 msec.
not possible on pc
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 10-18-2008, 02:04 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Sample timer program
Here's a test program that uses several techniques to time calls to a method.
It looks like there is no change in times for delays of 1 - 15 msecs. They were all the same (as you are finding). I added a spin while loop and was able to get much finer timings.
Code:
iimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.TimerTask; public class TimerTest { // Define control and work variables static long delay = 999999; //milliseconds 999999 max for wait in nanosecs final static int NbrTests = 5; final static String[] TestNames = {"Wait", "SpinLoop", "Swing Timer", "util.Timer"}; final static int Test_Wait = 0; final static int Test_SpinLoop = 1; final static int Test_SwingTimer = 2; final static int Test_utilTimer = 3; static int theTest = Test_Wait; //NB: CHANGE THIS FOR different Tests<<< final static long OneMil = 1000000; // Conversion constant static int cnt = 0; // control nbr times thru loop in task static long[] nanos = new long[NbrTests]; // save called times here //--------------------------------------------------------------------- // Common task to record when called static void doTask() { // System.out.println("hello at " + System.nanoTime()); nanos[cnt++] = System.nanoTime(); // save the times to report later if(cnt >= nanos.length) { // // at end - show times and exit for(int i=0; i < nanos.length; i++){ System.out.println(nanos[i] + " " + (i > 0 ? ((nanos[i] - nanos[i-1])/(1.0*OneMil)) : "")); } System.exit(0); // Exit pgm after report } } // Constructor ---------------------------------------------------- TimerTest(int what) { // Q&D test of wait() if(what == Test_Wait) { // Use wait() for timing -------------------------------------------------------- try{ synchronized(this) { while(true) { doTask(); wait(0, (int)delay); // 1 millisec = 1,000,000 nanosecs // 1000000 - nanosecond timeout value out of range } } }catch(Exception x) { x.printStackTrace(); } }else if(what == Test_SpinLoop) { // use Spin loop for timing ------------------------------------------------------ while(true) { doTask(); int cnt2 = 0; long start = System.nanoTime(); // System.out.println("start=" + start + ", delay*OneMil=" + (delay * OneMil)); while((System.nanoTime() - start) < (delay * OneMil)){ cnt2++; } // kill some time // System.out.println("cnt=" + cnt2); //nt=462 cnt=463 cnt=462 cnt=368 } // end while() }else { System.err.println("unknown arg " + what); return; } System.exit(0); } // end constructor //------------------------------------------------------------ public static void main(String[] args){ System.out.println("delay = " + delay + ", testing: " + TestNames[theTest]); new TimerTest(theTest); // won't return for some tests if(theTest == Test_SwingTimer) { // For swing.Timer ActionListener taskPerformer = new ActionListener() { // @Override // only in 1.6 public void actionPerformed(ActionEvent ae) { doTask(); } }; // Use one or the other type of Timer new javax.swing.Timer((int)delay, taskPerformer).start(); }else if(theTest == Test_utilTimer) { // Following tests with util.Timer java.util.Timer timer = new java.util.Timer(); // For util.Timer class TT extends TimerTask { public void run() { doTask(); } } // end class TT TT tt = new TT(); timer.schedule(tt, delay, delay); }else { System.err.println("unknown test " + theTest); } try{Thread.sleep(10000);}catch(Exception x){} // wait for timer to exit } // end main() }

Last edited by Norm : 10-18-2008 at 08:03 PM. Reason: Correct logic error
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 10-18-2008, 03:25 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
Ironically we are back to loops again
strange, it looks like a design problem on windows/ sun?
It is late now tomorrow, I´ll run your prog
on mac. (I noticed differences when feeding 1 to 10
msec on mac.)
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 10-18-2008, 07:45 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Consumer Operating Systems don't care about timer accuracy. For decades, Windows could do nothing finer than 18milliseconds.

You really should change the thead title, its not about Java being cross platform, its about how do you program real-time activities in Java.

And the answer is that real-time is hard in nearly all cases
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 10-18-2008, 02:40 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
okay, so I´ll start a new thread "real-time programming in java on PC/MAC" or can I change the name of this thread?
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 10-18-2008, 04:37 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
norm, on mac, does this make sense

delay = 1000 ==================== test1
1224332279817177000
1224332279818200000 1.023
1224332279819218000 1.018
1224332279820261000 1.043
1224332279821295000 1.034
1224332279822320000 1.025
1224332279823367000 1.047
1224332279824389000 1.022
1224332279825416000 1.027
1224332279826445000 1.029
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 1
1224332424581844000
1224332424582865000 1.021
1224332424583878000 1.013
1224332424584889000 1.011
1224332424585906000 1.017
1224332424586963000 1.057
1224332424588004000 1.041
1224332424589034000 1.03
1224332424590057000 1.023
1224332424591100000 1.043
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 8
1224332542755688000
1224332542756721000 1.033
1224332542757737000 1.016
1224332542758766000 1.029
1224332542759796000 1.03
1224332542760840000 1.044
1224332542761864000 1.024
1224332542762888000 1.024
1224332542763915000 1.027
1224332542764956000 1.041
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 12
1224332626998597000
1224332626999623000 1.026
1224332627000638000 1.015
1224332627001656000 1.018
1224332627002700000 1.044
1224332627003744000 1.044
1224332627004775000 1.031
1224332627005792000 1.017
1224332627006836000 1.044
1224332627007879000 1.043
BUILD SUCCESSFUL (total time: 1 second)

delay = 15
1224332671573032000
1224332671574059000 1.027
1224332671575092000 1.033
1224332671576108000 1.016
1224332671577152000 1.044
1224332671578172000 1.02
1224332671579205000 1.033
1224332671580231000 1.026
1224332671581283000 1.052
1224332671582323000 1.04
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 18
1224332702067592000
1224332702068616000 1.024
1224332702069629000 1.013
1224332702070648000 1.019
1224332702071662000 1.014
1224332702072704000 1.042
1224332702073753000 1.049
1224332702074779000 1.026
1224332702075824000 1.045
1224332702076848000 1.024
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 25
1224332786448414000
1224332786449447000 1.033
1224332786450467000 1.02
1224332786451510000 1.043
1224332786453532000 2.022
1224332786454588000 1.056
1224332786455633000 1.045
1224332786456665000 1.032
1224332786457707000 1.042
1224332786458761000 1.054
BUILD SUCCESSFUL (total time: 1 second)

========================== test2
delay = 1000
1224332981263898000
1224332981263900000 0.0020
1224332981263901000 0.0010
1224332981263902000 0.0010
1224332981263903000 0.0010
1224332981263903000 0.0
1224332981263904000 0.0010
1224332981263905000 0.0010
1224332981263906000 0.0010
1224332981263907000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 1
1224333094791445000
1224333094791447000 0.0020
1224333094791448000 0.0010
1224333094791449000 0.0010
1224333094791450000 0.0010
1224333094791450000 0.0
1224333094791451000 0.0010
1224333094791452000 0.0010
1224333094791453000 0.0010
1224333094791454000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 8
1224333130348805000
1224333130348807000 0.0020
1224333130348808000 0.0010
1224333130348809000 0.0010
1224333130348810000 0.0010
1224333130348810000 0.0
1224333130348811000 0.0010
1224333130348812000 0.0010
1224333130348813000 0.0010
1224333130348814000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 12
1224333195350939000
1224333195350941000 0.0020
1224333195350942000 0.0010
1224333195350943000 0.0010
1224333195350944000 0.0010
1224333195350944000 0.0
1224333195350945000 0.0010
1224333195350946000 0.0010
1224333195350947000 0.0010
1224333195350948000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)


delay = 15
1224333163519041000
1224333163519043000 0.0020
1224333163519044000 0.0010
1224333163519044000 0.0
1224333163519045000 0.0010
1224333163519046000 0.0010
1224333163519047000 0.0010
1224333163519048000 0.0010
1224333163519049000 0.0010
1224333163519049000 0.0
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 18
1224333265547567000
1224333265547569000 0.0020
1224333265547570000 0.0010
1224333265547571000 0.0010
1224333265547572000 0.0010
1224333265547573000 0.0010
1224333265547573000 0.0
1224333265547574000 0.0010
1224333265547575000 0.0010
1224333265547576000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)

delay = 25
1224333334487368000
1224333334487370000 0.0020
1224333334487371000 0.0010
1224333334487372000 0.0010
1224333334487373000 0.0010
1224333334487374000 0.0010
1224333334487374000 0.0
1224333334487375000 0.0010
1224333334487376000 0.0010
1224333334487377000 0.0010
BUILD SUCCESSFUL (total time: 0 seconds)
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 10-18-2008, 04:40 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
fishtoprecords,
what should one do when going beyond the 18 msec timing
(I need a 7 msec timing)
"Windows could do nothing finer than 18milliseconds."
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 10-18-2008, 06:39 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
What you posted looks like you get the same results with delay = 1000 as delay = 1.
Must be something wrong with the model. I got the same results from 1 to 15 and then it changed from 16 on.

I corrected a logic error in the while() test in the code I posted above. All output for the spin loop tests was wrong.

Last edited by Norm : 10-18-2008 at 08:04 PM. Reason: correct logic error in code