Path: blob/master/test/jdk/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetAttenuation.java
41159 views
/*1* Copyright (c) 2007, 2015, 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 getAttenuation method25@modules java.desktop/com.sun.media.sound26*/2728import java.io.ByteArrayOutputStream;2930import javax.sound.sampled.*;3132import com.sun.media.sound.*;3334public class GetAttenuation {3536static float[] testarray;37static byte[] test_byte_array;38static byte[] test_byte_array_8ext;39static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);40static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);41static ModelByteBuffer buffer;42static ModelByteBuffer buffer_wave;43static ModelByteBuffer buffer8;44static ModelByteBuffer buffer16_8;45static ModelByteBuffer buffer24;4647static void setUp() throws Exception {48testarray = new float[1024];49for (int i = 0; i < 1024; i++) {50double ii = i / 1024.0;51ii = ii * ii;52testarray[i] = (float)Math.sin(10*ii*2*Math.PI);53testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);54testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);55testarray[i] *= 0.3;56}57test_byte_array = new byte[testarray.length*2];58AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);59buffer = new ModelByteBuffer(test_byte_array);6061byte[] test_byte_array2 = new byte[testarray.length*3];62buffer24 = new ModelByteBuffer(test_byte_array2);63test_byte_array_8ext = new byte[testarray.length];64byte[] test_byte_array_8_16 = new byte[testarray.length*2];65AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);66int ix = 0;67int x = 0;68for (int i = 0; i < test_byte_array_8ext.length; i++) {69test_byte_array_8ext[i] = test_byte_array2[ix++];70test_byte_array_8_16[x++] = test_byte_array2[ix++];71test_byte_array_8_16[x++] = test_byte_array2[ix++];72}73buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);74buffer8 = new ModelByteBuffer(test_byte_array_8ext);7576AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);77ByteArrayOutputStream baos = new ByteArrayOutputStream();78AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);79buffer_wave = new ModelByteBuffer(baos.toByteArray());80}8182public static void main(String[] args) throws Exception {8384setUp();8586ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);87wavetable.setAttenuation(10f);88if(wavetable.getAttenuation() != 10f)89throw new RuntimeException("wavetable.getAttenuation() not 10!");90wavetable.setAttenuation(20f);91if(wavetable.getAttenuation() != 20f)92throw new RuntimeException("wavetable.getAttenuation() not 20!");9394}9596}979899