|
1 /* |
|
2 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import javax.sound.sampled.AudioFormat; |
|
25 import javax.sound.sampled.AudioSystem; |
|
26 import javax.sound.sampled.DataLine; |
|
27 import javax.sound.sampled.Line; |
|
28 import javax.sound.sampled.Mixer; |
|
29 |
|
30 /** |
|
31 * @test |
|
32 * @bug 4469409 |
|
33 * @summary Check that the frame size in the formats returned by lines is |
|
34 * correct |
|
35 */ |
|
36 public class FrameSizeTest { |
|
37 public static void main(String[] args) throws Exception { |
|
38 boolean res=true; |
|
39 Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); |
|
40 for (int i = 0; i < mixerInfo.length; i++) { |
|
41 Mixer mixer = AudioSystem.getMixer(mixerInfo[i]); |
|
42 System.out.println(mixer); |
|
43 Line.Info[] lineinfo = mixer.getSourceLineInfo(); |
|
44 for (int j = 0; j < lineinfo.length; j++) { |
|
45 System.out.println(" " + lineinfo[j]); |
|
46 try { |
|
47 AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats(); |
|
48 for (int k = 0; k < formats.length; k++) { |
|
49 if ( (formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) |
|
50 || formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) |
|
51 && (formats[k].getFrameSize() != AudioSystem.NOT_SPECIFIED) |
|
52 && ((formats[k].getSampleSizeInBits() == 16) || (formats[k].getSampleSizeInBits() == 8)) |
|
53 && ((((formats[k].getSampleSizeInBits() + 7) / 8) * formats[k].getChannels()) != formats[k].getFrameSize())) { |
|
54 System.out.println(" # " + formats[k] + ", getFrameSize() wrongly returns"+ formats[k].getFrameSize()); |
|
55 res=false; |
|
56 } |
|
57 } |
|
58 } catch (ClassCastException e) { |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 if (res) { |
|
64 System.out.println("Test passed"); |
|
65 } else { |
|
66 System.out.println("Test failed"); |
|
67 throw new Exception("Test failed"); |
|
68 } |
|
69 } |
|
70 } |