author | yan |
Tue, 23 Jun 2015 11:59:27 +0300 | |
changeset 31448 | 1066345d2a8a |
parent 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
4386
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
1 |
/* |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
23010
diff
changeset
|
2 |
* Copyright (c) 2009, 2015, 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 | 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 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
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 |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
23010
diff
changeset
|
25 |
@summary Test SoftChannel overflow test 2 |
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
23010
diff
changeset
|
26 |
@modules java.desktop/com.sun.media.sound |
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
23010
diff
changeset
|
27 |
*/ |
4386
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
28 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
29 |
import java.util.HashMap; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
30 |
import java.util.Map; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
31 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
32 |
import javax.sound.midi.MidiChannel; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
33 |
import javax.sound.midi.Patch; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
34 |
import javax.sound.midi.VoiceStatus; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
35 |
import javax.sound.sampled.AudioFormat; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
36 |
import javax.sound.sampled.AudioInputStream; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
37 |
|
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.AudioSynthesizer; |
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.SF2Instrument; |
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.SF2InstrumentRegion; |
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.SF2Layer; |
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.SF2LayerRegion; |
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.SF2Region; |
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.SF2Sample; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
48 |
public class NoteOverFlowTest2 { |
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 |
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
|
51 |
{ |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
52 |
// 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
|
53 |
AudioSynthesizer synth = new SoftSynthesizer(); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
59 |
// 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
|
60 |
SF2Soundbank sf2 = new SF2Soundbank(); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
61 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
62 |
SF2Sample sample = new SF2Sample(sf2); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
63 |
sample.setName("test sample"); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
64 |
sample.setData(new byte[100]); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
65 |
sample.setSampleRate(44100); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
66 |
sample.setOriginalPitch(20); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
67 |
sf2.addResource(sample); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
68 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
69 |
SF2Layer layer = new SF2Layer(sf2); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
70 |
layer.setName("test layer"); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
71 |
sf2.addResource(layer); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
72 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
73 |
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
|
74 |
SF2LayerRegion region = new SF2LayerRegion(); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
75 |
region.setSample(sample); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
76 |
layer.getRegions().add(region); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
77 |
} |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
78 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
79 |
SF2Instrument ins = new SF2Instrument(sf2); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
80 |
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
|
81 |
ins.setName("test instrument"); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
82 |
sf2.addInstrument(ins); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
83 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
84 |
SF2InstrumentRegion insregion = new SF2InstrumentRegion(); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
85 |
insregion.setLayer(layer); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
86 |
ins.getRegions().add(insregion); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
87 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
88 |
// 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
|
89 |
synth.unloadAllInstruments(synth.getDefaultSoundbank()); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
90 |
synth.loadAllInstruments(sf2); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
91 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
92 |
// 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
|
93 |
MidiChannel ch1 = synth.getChannels()[0]; |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
94 |
ch1.programChange(0); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
95 |
ch1.noteOn(64, 64); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
96 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
97 |
// Read 1 sec from stream |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
98 |
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
|
99 |
|
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
100 |
// Close the synthesizer after use |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
101 |
synth.close(); |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
102 |
} |
3477770cfaac
6823449: Gervill: ArrayIndexOutOfBoundsException thrown when trying to play too may voices at same time
kalli
parents:
diff
changeset
|
103 |
} |