1170N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
1170N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1170N/A *
1170N/A * This code is free software; you can redistribute it and/or modify it
1170N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1170N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1170N/A *
1170N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1170N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1170N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1170N/A * version 2 for more details (a copy is included in the LICENSE file that
1170N/A * accompanied this code).
1170N/A *
1170N/A * You should have received a copy of the GNU General Public License version
1170N/A * 2 along with this work; if not, write to the Free Software Foundation,
1170N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1170N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1170N/A */
1170N/A
1170N/A/* @test
1170N/A @summary Test SoftChannel noteOn/noteOff overflow test */
1170N/A
1170N/Aimport javax.sound.midi.MidiChannel;
1170N/Aimport javax.sound.midi.VoiceStatus;
1170N/Aimport javax.sound.sampled.AudioFormat;
1170N/Aimport javax.sound.sampled.AudioInputStream;
1170N/A
1170N/Aimport com.sun.media.sound.AudioSynthesizer;
1170N/Aimport com.sun.media.sound.SoftSynthesizer;
1170N/A
1170N/Apublic class NoteOverFlowTest {
1170N/A
1170N/A public static void main(String[] args) throws Exception
1170N/A {
1170N/A AudioSynthesizer synth = new SoftSynthesizer();
1170N/A AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
1170N/A AudioInputStream stream = synth.openStream(format, null);
1170N/A
1170N/A // Make all voices busy, e.g.
1170N/A // send midi on and midi off on all available voices
1170N/A MidiChannel ch1 = synth.getChannels()[0];
1170N/A ch1.programChange(48); // Use contionus instrument like string ensemble
1170N/A for (int i = 0; i < synth.getMaxPolyphony(); i++) {
1170N/A ch1.noteOn(64, 64);
1170N/A ch1.noteOff(64);
1170N/A }
1170N/A
1170N/A // Now send single midi on, and midi off message
1170N/A ch1.noteOn(64, 64);
1170N/A ch1.noteOff(64);
1170N/A
1170N/A // Read 10 sec from stream, by this time all voices should be inactvie
1170N/A stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 20)));
1170N/A
1170N/A // If no voice are active, then this test will pass
1170N/A VoiceStatus[] v = synth.getVoiceStatus();
1170N/A for (int i = 0; i < v.length; i++) {
1170N/A if(v[i].active)
1170N/A {
1170N/A throw new RuntimeException("Not all voices are inactive!");
1170N/A }
1170N/A }
1170N/A
1170N/A // Close the synthesizer after use
1170N/A synth.close();
1170N/A }
1170N/A}