Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/NewModelByteBufferWavetableModelByteBufferFloat.java
38859 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@summary Test ModelByteBufferWavetable(ModelByteBuffer, AudioFormat, float) method */2526import java.io.ByteArrayOutputStream;2728import javax.sound.sampled.*;2930import com.sun.media.sound.*;3132public class NewModelByteBufferWavetableModelByteBufferFloat {3334static float[] testarray;35static byte[] test_byte_array;36static byte[] test_byte_array_8ext;37static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);38static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);39static ModelByteBuffer buffer;40static ModelByteBuffer buffer_wave;41static ModelByteBuffer buffer8;42static ModelByteBuffer buffer16_8;43static ModelByteBuffer buffer24;4445static void setUp() throws Exception {46testarray = new float[1024];47for (int i = 0; i < 1024; i++) {48double ii = i / 1024.0;49ii = ii * ii;50testarray[i] = (float)Math.sin(10*ii*2*Math.PI);51testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);52testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);53testarray[i] *= 0.3;54}55test_byte_array = new byte[testarray.length*2];56AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);57buffer = new ModelByteBuffer(test_byte_array);5859byte[] test_byte_array2 = new byte[testarray.length*3];60buffer24 = new ModelByteBuffer(test_byte_array2);61test_byte_array_8ext = new byte[testarray.length];62byte[] test_byte_array_8_16 = new byte[testarray.length*2];63AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);64int ix = 0;65int x = 0;66for (int i = 0; i < test_byte_array_8ext.length; i++) {67test_byte_array_8ext[i] = test_byte_array2[ix++];68test_byte_array_8_16[x++] = test_byte_array2[ix++];69test_byte_array_8_16[x++] = test_byte_array2[ix++];70}71buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);72buffer8 = new ModelByteBuffer(test_byte_array_8ext);7374AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);75ByteArrayOutputStream baos = new ByteArrayOutputStream();76AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);77buffer_wave = new ModelByteBuffer(baos.toByteArray());78}7980public static void main(String[] args) throws Exception {8182setUp();8384ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format,10f);85if(wavetable.getBuffer() != buffer)86throw new RuntimeException("wavetable.getBuffer() incorrect!");87if(!wavetable.getFormat().matches(format))88throw new RuntimeException("wavetable.getFormat() incorrect!");89if(wavetable.getPitchcorrection() != 10f)90throw new RuntimeException("wavetable.getPitchcorrection() not 10!");91}9293}949596