Mercurial > hg > openjdk > jdk8u > jdk
changeset 14099:fb9d9cfd0523 jdk8u272-b03
6574989: TEST_BUG: javax/sound/sampled/Clip/bug5070081.java fails sometimes
Reviewed-by: prr
author | serb |
---|---|
date | Thu, 23 Mar 2017 17:50:10 +0300 |
parents | 3e0c4e45bd5f |
children | 9a21ba120101 c19e5d127e6c |
files | test/javax/sound/sampled/Clip/bug5070081.java |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/test/javax/sound/sampled/Clip/bug5070081.java Thu Jun 28 09:40:46 2018 +0530 +++ b/test/javax/sound/sampled/Clip/bug5070081.java Thu Mar 23 17:50:10 2017 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -21,6 +21,8 @@ * questions. */ +import java.util.concurrent.TimeUnit; + import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; @@ -56,18 +58,22 @@ clip.start(); // start playing Thread.sleep(1000); // wait a sec - long time1 = System.currentTimeMillis(); + long time1 = 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(); + long time2 = currentTimeMillis(); + + System.out.println(" Position before stop: " + pos1); 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 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 = Math.abs(pos2 - pos1) - Math.abs(time2-time1); + 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"); @@ -104,4 +110,8 @@ System.out.println("Test passed sucessfully"); } + + private static long currentTimeMillis() { + return TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); + } }