Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest2.java
38860 views
/*1* Copyright (c) 2009, 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 SoftChannel overflow test 2 */2526import java.util.HashMap;27import java.util.Map;2829import javax.sound.midi.MidiChannel;30import javax.sound.midi.Patch;31import javax.sound.midi.VoiceStatus;32import javax.sound.sampled.AudioFormat;33import javax.sound.sampled.AudioInputStream;3435import com.sun.media.sound.AudioSynthesizer;36import com.sun.media.sound.SF2Instrument;37import com.sun.media.sound.SF2InstrumentRegion;38import com.sun.media.sound.SF2Layer;39import com.sun.media.sound.SF2LayerRegion;40import com.sun.media.sound.SF2Region;41import com.sun.media.sound.SF2Sample;42import com.sun.media.sound.SF2Soundbank;43import com.sun.media.sound.SoftSynthesizer;4445public class NoteOverFlowTest2 {4647public static void main(String[] args) throws Exception48{49// Create instance of the synthesizer with very low polyphony50AudioSynthesizer synth = new SoftSynthesizer();51AudioFormat format = new AudioFormat(44100, 16, 2, true, false);52Map<String, Object> p = new HashMap<String, Object>();53p.put("max polyphony", new Integer(5));54AudioInputStream stream = synth.openStream(format, p);5556// Create instrument with too many regions (more than max polyphony)57SF2Soundbank sf2 = new SF2Soundbank();5859SF2Sample sample = new SF2Sample(sf2);60sample.setName("test sample");61sample.setData(new byte[100]);62sample.setSampleRate(44100);63sample.setOriginalPitch(20);64sf2.addResource(sample);6566SF2Layer layer = new SF2Layer(sf2);67layer.setName("test layer");68sf2.addResource(layer);6970for (int i = 0; i < 100; i++) {71SF2LayerRegion region = new SF2LayerRegion();72region.setSample(sample);73layer.getRegions().add(region);74}7576SF2Instrument ins = new SF2Instrument(sf2);77ins.setPatch(new Patch(0,0));78ins.setName("test instrument");79sf2.addInstrument(ins);8081SF2InstrumentRegion insregion = new SF2InstrumentRegion();82insregion.setLayer(layer);83ins.getRegions().add(insregion);8485// Load the test soundbank into the synthesizer86synth.unloadAllInstruments(synth.getDefaultSoundbank());87synth.loadAllInstruments(sf2);8889// Send out one midi on message90MidiChannel ch1 = synth.getChannels()[0];91ch1.programChange(0);92ch1.noteOn(64, 64);9394// Read 1 sec from stream95stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 2)));9697// Close the synthesizer after use98synth.close();99}100}101102103