SubbufferLongLong.java revision 8729:0242fce0f717
1309124Sdim/* 2234285Sdim * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 3353358Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4353358Sdim * 5353358Sdim * This code is free software; you can redistribute it and/or modify it 6234285Sdim * under the terms of the GNU General Public License version 2 only, as 7234285Sdim * published by the Free Software Foundation. 8234285Sdim * 9234285Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 10234285Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11234285Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12234285Sdim * version 2 for more details (a copy is included in the LICENSE file that 13234285Sdim * accompanied this code). 14234285Sdim * 15234285Sdim * You should have received a copy of the GNU General Public License version 16234285Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17296417Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18296417Sdim * 19360784Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20239462Sdim * or visit www.oracle.com if you need additional information or have any 21360784Sdim * questions. 22239462Sdim */ 23314564Sdim 24296417Sdim/* @test 25360784Sdim @summary Test ModelByteBuffer subbuffer(long,long) method */ 26360784Sdim 27234285Sdimimport java.io.File; 28239462Sdimimport java.io.FileOutputStream; 29314564Sdim 30314564Sdimimport javax.sound.sampled.*; 31239462Sdim 32314564Sdimimport com.sun.media.sound.*; 33239462Sdim 34360784Sdimpublic class SubbufferLongLong { 35314564Sdim 36309124Sdim static float[] testarray; 37234285Sdim static byte[] test_byte_array; 38234285Sdim static File test_file; 39360784Sdim static AudioFormat format = new AudioFormat(44100, 16, 1, true, false); 40360784Sdim 41296417Sdim static void setUp() throws Exception { 42296417Sdim testarray = new float[1024]; 43360784Sdim for (int i = 0; i < 1024; i++) { 44314564Sdim double ii = i / 1024.0; 45360784Sdim ii = ii * ii; 46360784Sdim testarray[i] = (float)Math.sin(10*ii*2*Math.PI); 47360784Sdim testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI); 48296417Sdim testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI); 49360784Sdim testarray[i] *= 0.3; 50360784Sdim } 51314564Sdim test_byte_array = new byte[testarray.length*2]; 52360784Sdim AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); 53360784Sdim test_file = File.createTempFile("test", ".raw"); 54309124Sdim FileOutputStream fos = new FileOutputStream(test_file); 55360784Sdim fos.write(test_byte_array); 56360784Sdim } 57360784Sdim 58360784Sdim static void tearDown() throws Exception { 59360784Sdim if(!test_file.delete()) 60296417Sdim test_file.deleteOnExit(); 61360784Sdim } 62239462Sdim 63239462Sdim public static void main(String[] args) throws Exception { 64239462Sdim try 65239462Sdim { 66239462Sdim setUp(); 67360784Sdim 68360784Sdim for (int i = 0; i < 2; i++) { 69360784Sdim ModelByteBuffer buff; 70360784Sdim if(i == 0) 71360784Sdim buff = new ModelByteBuffer(test_file); 72239462Sdim else 73239462Sdim buff = new ModelByteBuffer(test_byte_array); 74239462Sdim 75360784Sdim ModelByteBuffer buff2 = buff.subbuffer(10,21); 76360784Sdim if(buff2.getFilePointer() != buff.getFilePointer()) 77360784Sdim throw new RuntimeException("buff2.getFilePointer() incorrect!"); 78296417Sdim if(buff2.arrayOffset() != 10) 79360784Sdim throw new RuntimeException("buff2.arrayOffset() not 10!"); 80360784Sdim if(buff2.capacity() != 11) 81360784Sdim throw new RuntimeException("buff2.capacity() not 11!"); 82296417Sdim } 83360784Sdim } 84360784Sdim finally 85296417Sdim { 86360784Sdim tearDown(); 87360784Sdim } 88360784Sdim } 89360784Sdim 90239462Sdim} 91239462Sdim