< prev index next >
test/javax/sound/sampled/Clip/bug5070081.java
Print this page
rev 14028 : 6574989: TEST_BUG: javax/sound/sampled/Clip/bug5070081.java fails sometimes
Reviewed-by: prr
*** 1,7 ****
/*
! * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 19,28 ****
--- 19,30 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+ import java.util.concurrent.TimeUnit;
+
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
*** 54,75 ****
System.out.println(" frames: " + clip.getFrameLength());
System.out.println(" seconds: " + nLengthMS/1000.0);
clip.start(); // start playing
Thread.sleep(1000); // wait a sec
! long time1 = System.currentTimeMillis();
long pos1 = clip.getFramePosition(); // store the position
- System.out.println(" Position before stop: " + pos1);
clip.stop(); // and then stop
long pos2 = clip.getFramePosition(); // 2nd try
! long time2 = System.currentTimeMillis();
System.out.println(" Position after stop: " + pos2);
! System.out.println(" d(time): " + Math.abs(time2-time1) + " ms;"
! + "d(clip pos): " + Math.abs(pos2 - pos1) + " ms.");
! long nDerivation = Math.abs(pos2 - pos1) - Math.abs(time2-time1);
// add 50 ms for deviation (delay for stopping and errors due timer precision)
if (nDerivation > 50) {
System.out.println(" ERROR(1): The deviation is too much: " + nDerivation + " ms");
bSuccess = false;
}
--- 56,81 ----
System.out.println(" frames: " + clip.getFrameLength());
System.out.println(" seconds: " + nLengthMS/1000.0);
clip.start(); // start playing
Thread.sleep(1000); // wait a sec
! long time1 = currentTimeMillis();
long pos1 = clip.getFramePosition(); // store the position
clip.stop(); // and then stop
long pos2 = clip.getFramePosition(); // 2nd try
! long time2 = currentTimeMillis();
!
! System.out.println(" Position before stop: " + pos1);
System.out.println(" Position after stop: " + pos2);
! long timeDiff = Math.abs(time2 - time1);
! // sample rate is 22050 per second, so 22.05 per ms
! long posDiff = (long) (Math.abs(pos2 - pos1) / 22.05);
! System.out.println(" d(time): " + timeDiff + " ms;"
! + "d(clip pos time): " + posDiff + " ms.");
! long nDerivation = posDiff - timeDiff;
// add 50 ms for deviation (delay for stopping and errors due timer precision)
if (nDerivation > 50) {
System.out.println(" ERROR(1): The deviation is too much: " + nDerivation + " ms");
bSuccess = false;
}
*** 102,107 ****
--- 108,117 ----
}
}
System.out.println("Test passed sucessfully");
}
+
+ private static long currentTimeMillis() {
+ return TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
+ }
}
< prev index next >