Reset.java revision 829:b06c29386f63
1275970Scy/* 2275970Scy * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 3275970Scy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4275970Scy * 5275970Scy * This code is free software; you can redistribute it and/or modify it 6275970Scy * under the terms of the GNU General Public License version 2 only, as 7275970Scy * published by the Free Software Foundation. Sun designates this 8275970Scy * particular file as subject to the "Classpath" exception as provided 9275970Scy * by Sun in the LICENSE file that accompanied this code. 10275970Scy * 11275970Scy * This code is distributed in the hope that it will be useful, but WITHOUT 12275970Scy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13275970Scy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14275970Scy * version 2 for more details (a copy is included in the LICENSE file that 15275970Scy * accompanied this code). 16275970Scy * 17275970Scy * You should have received a copy of the GNU General Public License version 18275970Scy * 2 along with this work; if not, write to the Free Software Foundation, 19275970Scy * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20275970Scy * 21275970Scy * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22275970Scy * CA 95054 USA or visit www.sun.com if you need additional information or 23275970Scy * have any questions. 24275970Scy */ 25275970Scy 26275970Scy/* @test 27275970Scy @summary Test AudioFloatInputStream reset method */ 28275970Scy 29275970Scyimport java.io.*; 30275970Scy 31275970Scyimport javax.sound.sampled.*; 32275970Scy 33275970Scyimport com.sun.media.sound.*; 34275970Scy 35275970Scypublic class Reset { 36275970Scy 37275970Scy static float[] test_float_array; 38275970Scy static byte[] test_byte_array; 39275970Scy static AudioFormat format = new AudioFormat(44100, 16, 1, true, false); 40275970Scy 41275970Scy static AudioFloatInputStream getStream1() 42275970Scy { 43275970Scy return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length); 44275970Scy } 45275970Scy 46275970Scy static AudioFloatInputStream getStream2() 47275970Scy { 48275970Scy AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024); 49275970Scy return AudioFloatInputStream.getInputStream(strm); 50275970Scy } 51275970Scy 52275970Scy static void setUp() throws Exception { 53275970Scy test_float_array = new float[1024]; 54275970Scy test_byte_array = new byte[1024*format.getFrameSize()]; 55275970Scy for (int i = 0; i < 1024; i++) { 56275970Scy double ii = i / 1024.0; 57275970Scy ii = ii * ii; 58275970Scy test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI); 59275970Scy test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI); 60275970Scy test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI); 61275970Scy test_float_array[i] *= 0.3; 62275970Scy } 63275970Scy AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array); 64275970Scy } 65275970Scy 66275970Scy public static void main(String[] args) throws Exception { 67275970Scy setUp(); 68275970Scy 69275970Scy for (int i = 0; i < 2; i++) { 70275970Scy AudioFloatInputStream stream = null; 71275970Scy if(i == 0) stream = getStream1(); 72275970Scy if(i == 1) stream = getStream2(); 73275970Scy float[] buff = new float[512]; 74275970Scy float[] buff2 = new float[512]; 75275970Scy stream.read(buff); 76275970Scy stream.mark(512); 77275970Scy stream.read(buff); 78275970Scy stream.reset(); 79275970Scy stream.read(buff2); 80275970Scy for (int j = 0; j < buff2.length; j++) 81275970Scy if(!(Math.abs(buff[j] - buff2[j]) < 0.0001)) 82275970Scy throw new RuntimeException("Incorrect data in buffer."); 83275970Scy 84275970Scy } 85275970Scy } 86275970Scy 87275970Scy} 88275970Scy