author | serb |
Tue, 12 Nov 2013 20:24:25 +0400 | |
changeset 21596 | 0e3a39f29dbc |
parent 5506 | 202f599c92aa |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
1846
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. |
1846
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
4 |
* |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
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. |
1846
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
8 |
* |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
14 |
* |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
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. |
|
1846
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
22 |
*/ |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
23 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
24 |
/* @test |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
25 |
@summary Test ModelByteBuffer unload method */ |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
26 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
27 |
import java.io.File; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
28 |
import java.io.FileOutputStream; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
29 |
import java.io.IOException; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
30 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
31 |
import javax.sound.sampled.*; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
32 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
33 |
import com.sun.media.sound.*; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
34 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
35 |
public class Unload { |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
36 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
37 |
static float[] testarray; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
38 |
static byte[] test_byte_array; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
39 |
static File test_file; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
40 |
static AudioFormat format = new AudioFormat(44100, 16, 1, true, false); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
41 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
42 |
static void setUp() throws Exception { |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
43 |
testarray = new float[1024]; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
44 |
for (int i = 0; i < 1024; i++) { |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
45 |
double ii = i / 1024.0; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
46 |
ii = ii * ii; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
47 |
testarray[i] = (float)Math.sin(10*ii*2*Math.PI); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
48 |
testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
49 |
testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
50 |
testarray[i] *= 0.3; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
51 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
52 |
test_byte_array = new byte[testarray.length*2]; |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
53 |
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
54 |
test_file = File.createTempFile("test", ".raw"); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
55 |
FileOutputStream fos = new FileOutputStream(test_file); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
56 |
fos.write(test_byte_array); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
57 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
58 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
59 |
static void tearDown() throws Exception { |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
60 |
if(!test_file.delete()) |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
61 |
test_file.deleteOnExit(); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
62 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
63 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
64 |
public static void main(String[] args) throws Exception { |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
65 |
try |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
66 |
{ |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
67 |
setUp(); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
68 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
69 |
ModelByteBuffer buff = new ModelByteBuffer(test_file); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
70 |
buff.load(); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
71 |
buff.unload(); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
72 |
if(buff.array() != null) |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
73 |
throw new RuntimeException("buff.array() not null!"); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
74 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
75 |
finally |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
76 |
{ |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
77 |
tearDown(); |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
78 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
79 |
} |
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
80 |
|
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff
changeset
|
81 |
} |