632N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
632N/A *
632N/A * This code is free software; you can redistribute it and/or modify it
632N/A * under the terms of the GNU General Public License version 2 only, as
632N/A * published by the Free Software Foundation. Oracle designates this
632N/A * particular file as subject to the "Classpath" exception as provided
632N/A * by Oracle in the LICENSE file that accompanied this code.
632N/A *
632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
632N/A * version 2 for more details (a copy is included in the LICENSE file that
632N/A * accompanied this code).
632N/A *
632N/A * You should have received a copy of the GNU General Public License version
632N/A * 2 along with this work; if not, write to the Free Software Foundation,
2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
632N/A * or visit www.oracle.com if you need additional information or have any
632N/A * questions.
632N/A */
632N/A
632N/A/* @test
632N/A @summary Test ModelByteBuffer(byte[]) constructor */
632N/A
632N/Aimport java.io.File;
632N/Aimport java.io.FileOutputStream;
632N/A
632N/Aimport javax.sound.sampled.*;
632N/A
632N/Aimport com.sun.media.sound.*;
632N/A
632N/Apublic class NewModelByteBufferByteArray {
632N/A
632N/A static float[] testarray;
632N/A static byte[] test_byte_array;
632N/A static File test_file;
632N/A static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
632N/A
632N/A static void setUp() throws Exception {
632N/A testarray = new float[1024];
632N/A for (int i = 0; i < 1024; i++) {
632N/A double ii = i / 1024.0;
632N/A ii = ii * ii;
632N/A testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
632N/A testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
632N/A testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
632N/A testarray[i] *= 0.3;
632N/A }
632N/A test_byte_array = new byte[testarray.length*2];
632N/A AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
632N/A test_file = File.createTempFile("test", ".raw");
632N/A FileOutputStream fos = new FileOutputStream(test_file);
632N/A fos.write(test_byte_array);
632N/A }
632N/A
static void tearDown() throws Exception {
if(!test_file.delete())
test_file.deleteOnExit();
}
public static void main(String[] args) throws Exception {
try
{
setUp();
ModelByteBuffer buff = new ModelByteBuffer(test_byte_array);
if(buff.array() != test_byte_array)
throw new RuntimeException("buff.bytearray incorrect!");
if(buff.capacity() != test_byte_array.length)
throw new RuntimeException("buff.capacity() incorrect!");
if(buff.arrayOffset() != 0)
throw new RuntimeException("buff.arrayOffset not 0!");
}
finally
{
tearDown();
}
}
}