1 /* 2 * Copyright (c) 2003, 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 java.io.ByteArrayInputStream; 25 import java.io.InputStream; 26 27 import javax.sound.sampled.AudioFileFormat; 28 import javax.sound.sampled.AudioSystem; 29 30 /** 31 * @test 32 * @bug 4895934 33 * @summary AudioInputStream.getFrameLength returns wrong value for 12-bit AIFF 34 * file 35 */ 36 public class Aiff12bit { 37 38 public static void test(byte[] file) throws Exception { 39 InputStream inputStream = new ByteArrayInputStream(file); 40 AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream); 41 42 if (aff.getFormat().getSampleSizeInBits() != 12) { 43 throw new Exception("Wrong sample size. test FAILED"); 44 } 45 if (aff.getFormat().getFrameSize() != 2) { 46 throw new Exception("Wrong frame size. test FAILED"); 47 } 48 if (aff.getFrameLength() != 100) { 49 throw new Exception("Wrong file length. test FAILED"); 50 } 51 } 52 53 public static void main(String[] args) throws Exception { 54 test(AIFF_12BIT); 55 56 System.out.println("Test passed."); 57 } 58 59 public static byte[] AIFF_12BIT = { 60 70, 79, 82, 77, 0, 0, 0, -10, 65, 73, 70, 70, 67, 79, 77, 77, 61 0, 0, 0, 18, 0, 1, 0, 0, 0, 100, 0, 12, 64, 8, -6, 0, 62 0, 0, 0, 0, 0, 0, 83, 83, 78, 68, 0, 0, 0, -48, 0, 0, 63 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 32, 0, 48, 0, 64, 64 0, 80, 0, 96, 0, 112, 0, -128, 0, -112, 0, -96, 0, -80, 0, -64, 65 0, -48, 0, -32, 0, -16, 1, 0, 1, 16, 1, 32, 1, 48, 1, 64, 66 1, 80, 1, 96, 1, 112, 1, -128, 1, -112, 1, -96, 1, -80, 1, -64, 67 1, -48, 1, -32, 1, -16, 2, 0, 2, 16, 2, 32, 2, 48, 2, 64, 68 2, 80, 2, 96, 2, 112, 2, -128, 2, -112, 2, -96, 2, -80, 2, -64, 69 2, -48, 2, -32, 2, -16, 3, 0, 3, 16, 3, 32, 3, 48, 3, 64, 70 3, 80, 3, 96, 3, 112, 3, -128, 3, -112, 3, -96, 3, -80, 3, -64, 71 3, -48, 3, -32, 3, -16, 4, 0, 4, 16, 4, 32, 4, 48, 4, 64, 72 4, 80, 4, 96, 4, 112, 4, -128, 4, -112, 4, -96, 4, -80, 4, -64, 73 4, -48, 4, -32, 4, -16, 5, 0, 5, 16, 5, 32, 5, 48, 5, 64, 74 5, 80, 5, 96, 5, 112, 5, -128, 5, -112, 5, -96, 5, -80, 5, -64, 75 5, -48, 5, -32, 5, -16, 6, 0, 6, 16, 6, 32, 6, 48, 76 }; 77 78 }