jdk/test/javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest2.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:
4386
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4386
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
4386
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     4
 *
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
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.
4386
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     8
 *
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    13
 * accompanied this code).
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    14
 *
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4386
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4386
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4386
diff changeset
    21
 * questions.
4386
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    22
 */
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    23
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    24
/* @test
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    25
   @summary Test SoftChannel overflow test 2 */
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    26
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    27
import java.util.HashMap;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    28
import java.util.Map;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    29
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    30
import javax.sound.midi.MidiChannel;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    31
import javax.sound.midi.Patch;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    32
import javax.sound.midi.VoiceStatus;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    33
import javax.sound.sampled.AudioFormat;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    34
import javax.sound.sampled.AudioInputStream;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    35
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    36
import com.sun.media.sound.AudioSynthesizer;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    37
import com.sun.media.sound.SF2Instrument;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    38
import com.sun.media.sound.SF2InstrumentRegion;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    39
import com.sun.media.sound.SF2Layer;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    40
import com.sun.media.sound.SF2LayerRegion;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    41
import com.sun.media.sound.SF2Region;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    42
import com.sun.media.sound.SF2Sample;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    43
import com.sun.media.sound.SF2Soundbank;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    44
import com.sun.media.sound.SoftSynthesizer;
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    45
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    46
public class NoteOverFlowTest2 {
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    47
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    48
    public static void main(String[] args) throws Exception
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    49
    {
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    50
        // Create instance of the synthesizer with very low polyphony
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    51
        AudioSynthesizer synth = new SoftSynthesizer();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    52
        AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    53
        Map<String, Object> p = new HashMap<String, Object>();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    54
        p.put("max polyphony", new Integer(5));
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    55
        AudioInputStream stream = synth.openStream(format, p);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    56
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    57
        // Create instrument with too many regions (more than max polyphony)
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    58
        SF2Soundbank sf2 = new SF2Soundbank();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    59
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    60
        SF2Sample sample = new SF2Sample(sf2);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    61
        sample.setName("test sample");
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    62
        sample.setData(new byte[100]);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    63
        sample.setSampleRate(44100);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    64
        sample.setOriginalPitch(20);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    65
        sf2.addResource(sample);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    66
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    67
        SF2Layer layer = new SF2Layer(sf2);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    68
        layer.setName("test layer");
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    69
        sf2.addResource(layer);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    70
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    71
        for (int i = 0; i < 100; i++) {
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    72
            SF2LayerRegion region = new SF2LayerRegion();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    73
            region.setSample(sample);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    74
            layer.getRegions().add(region);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    75
        }
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    76
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    77
        SF2Instrument ins = new SF2Instrument(sf2);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    78
        ins.setPatch(new Patch(0,0));
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    79
        ins.setName("test instrument");
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    80
        sf2.addInstrument(ins);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    81
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    82
        SF2InstrumentRegion insregion = new SF2InstrumentRegion();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    83
        insregion.setLayer(layer);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    84
        ins.getRegions().add(insregion);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    85
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    86
        // Load the test soundbank into the synthesizer
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    87
        synth.unloadAllInstruments(synth.getDefaultSoundbank());
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    88
        synth.loadAllInstruments(sf2);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    89
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    90
        // Send out one midi on message
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    91
        MidiChannel ch1 = synth.getChannels()[0];
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    92
        ch1.programChange(0);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    93
        ch1.noteOn(64, 64);
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    94
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    95
        // Read 1 sec from stream
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    96
        stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 2)));
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    97
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    98
        // Close the synthesizer after use
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
    99
        synth.close();
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
   100
    }
3477770cfaac 6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff changeset
   101
}