jdk/test/javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
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
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 5506
diff changeset
     7
 * published by the Free Software Foundation.
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     8
 *
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
     9
 * 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
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    12
 * 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
    13
 * accompanied this code).
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    14
 *
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2655
diff changeset
    21
 * questions.
2655
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    22
 */
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    23
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    24
/* @test
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    25
   @summary Test SoftChannel noteOn/noteOff overflow test */
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    26
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    27
import javax.sound.midi.MidiChannel;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    28
import javax.sound.midi.VoiceStatus;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    29
import javax.sound.sampled.AudioFormat;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    30
import javax.sound.sampled.AudioInputStream;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    31
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    32
import com.sun.media.sound.AudioSynthesizer;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    33
import com.sun.media.sound.SoftSynthesizer;
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    34
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    35
public class NoteOverFlowTest {
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 static void main(String[] args) throws Exception
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
        AudioSynthesizer synth = new SoftSynthesizer();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    40
        AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    41
        AudioInputStream stream = synth.openStream(format, null);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    42
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    43
        // Make all voices busy, e.g.
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    44
        // send midi on and midi off on all available voices
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    45
        MidiChannel ch1 = synth.getChannels()[0];
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    46
        ch1.programChange(48); // Use contionus instrument like string ensemble
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    47
        for (int i = 0; i < synth.getMaxPolyphony(); i++) {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    48
            ch1.noteOn(64, 64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    49
            ch1.noteOff(64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    50
        }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    51
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    52
        // Now send single midi on, and midi off message
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    53
        ch1.noteOn(64, 64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    54
        ch1.noteOff(64);
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    55
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    56
        // 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
    57
        stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 20)));
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    58
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    59
        // If no voice are active, then this test will pass
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    60
        VoiceStatus[] v = synth.getVoiceStatus();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    61
        for (int i = 0; i < v.length; i++) {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    62
            if(v[i].active)
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    63
            {
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    64
                throw new RuntimeException("Not all voices are inactive!");
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
        }
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
        // Close the synthesizer after use
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    69
        synth.close();
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    70
    }
a69fc05ff63d 6821030: Merge OpenJDK Gervill with upstream sources, Q1CY2009
kalli
parents:
diff changeset
    71
}