jdk/test/javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2655 a69fc05ff63d
child 21596 0e3a39f29dbc
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     4
 *
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    10
 *
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    15
 * accompanied this code).
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    16
 *
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    23
 * questions.
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    24
 */
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    25
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    26
/* @test
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    27
   @summary Test SoftChannel noteOn/noteOff overflow test */
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    28
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    29
import javax.sound.midi.MidiChannel;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    30
import javax.sound.midi.VoiceStatus;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    31
import javax.sound.sampled.AudioFormat;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    32
import javax.sound.sampled.AudioInputStream;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    33
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    34
import com.sun.media.sound.AudioSynthesizer;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    35
import com.sun.media.sound.SoftSynthesizer;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    36
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    37
public class NoteOverFlowTest {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    38
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    40
    {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    41
        AudioSynthesizer synth = new SoftSynthesizer();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    42
        AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    43
        AudioInputStream stream = synth.openStream(format, null);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    44
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    45
        // Make all voices busy, e.g.
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    46
        // send midi on and midi off on all available voices
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    47
        MidiChannel ch1 = synth.getChannels()[0];
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    48
        ch1.programChange(48); // Use contionus instrument like string ensemble
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    49
        for (int i = 0; i < synth.getMaxPolyphony(); i++) {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    50
            ch1.noteOn(64, 64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    51
            ch1.noteOff(64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    52
        }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    53
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    54
        // Now send single midi on, and midi off message
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    55
        ch1.noteOn(64, 64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    56
        ch1.noteOff(64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    57
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    58
        // Read 10 sec from stream, by this time all voices should be inactvie
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    59
        stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 20)));
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    60
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    61
        // If no voice are active, then this test will pass
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    62
        VoiceStatus[] v = synth.getVoiceStatus();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    63
        for (int i = 0; i < v.length; i++) {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    64
            if(v[i].active)
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    65
            {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    66
                throw new RuntimeException("Not all voices are inactive!");
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    67
            }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    68
        }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    69
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    70
        // Close the synthesizer after use
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    71
        synth.close();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    72
    }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    73
}