Load8.java revision 9330:8b1f1c2a400f
1145516Sdarrenr/*
2145516Sdarrenr * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3145516Sdarrenr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4145516Sdarrenr *
5145516Sdarrenr * This code is free software; you can redistribute it and/or modify it
6145516Sdarrenr * under the terms of the GNU General Public License version 2 only, as
7145516Sdarrenr * published by the Free Software Foundation.
8145516Sdarrenr *
9145516Sdarrenr * This code is distributed in the hope that it will be useful, but WITHOUT
10172776Sdarrenr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11145516Sdarrenr * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12145516Sdarrenr * version 2 for more details (a copy is included in the LICENSE file that
13145516Sdarrenr * accompanied this code).
14145516Sdarrenr *
15145516Sdarrenr * You should have received a copy of the GNU General Public License version
16145516Sdarrenr * 2 along with this work; if not, write to the Free Software Foundation,
17145516Sdarrenr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18145516Sdarrenr *
19145516Sdarrenr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20145516Sdarrenr * or visit www.oracle.com if you need additional information or have any
21145516Sdarrenr * questions.
22145516Sdarrenr */
23145516Sdarrenr
24145516Sdarrenr/* @test
25145516Sdarrenr   @summary Test SoftTuning load method */
26145516Sdarrenr
27145516Sdarrenrimport javax.sound.midi.MidiUnavailableException;
28145516Sdarrenrimport javax.sound.midi.Patch;
29145516Sdarrenrimport javax.sound.sampled.*;
30145516Sdarrenr
31145516Sdarrenrimport com.sun.media.sound.*;
32145516Sdarrenr
33145516Sdarrenrpublic class Load8 {
34145516Sdarrenr
35145516Sdarrenr    private static void assertEquals(Object a, Object b) throws Exception
36145516Sdarrenr    {
37145516Sdarrenr        if(!a.equals(b))
38145516Sdarrenr            throw new RuntimeException("assertEquals fails!");
39145516Sdarrenr    }
40145516Sdarrenr
41145516Sdarrenr    private static void assertTrue(boolean value) throws Exception
42145516Sdarrenr    {
43145516Sdarrenr        if(!value)
44145516Sdarrenr            throw new RuntimeException("assertTrue fails!");
45145516Sdarrenr    }
46145516Sdarrenr
47145516Sdarrenr    public static void main(String[] args) throws Exception {
48145516Sdarrenr        // http://www.midi.org/about-midi/tuning-scale.shtml
49145516Sdarrenr        // 0x08 scale/octave tuning 1-byte form (Non Real-Time/REAL-TIME)
50145516Sdarrenr        SoftTuning tuning = new SoftTuning();
51145516Sdarrenr        int[] msg = {0xf0,0x7f,0x7f,0x08,0x08,0x03,0x7f,0x7f,
52145516Sdarrenr                5,10,15,20,25,30,35,40,45,50,51,52,
53145516Sdarrenr                0xf7};
54145516Sdarrenr        int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52};
55145516Sdarrenr        byte[] bmsg = new byte[msg.length];
56145516Sdarrenr        for (int i = 0; i < bmsg.length; i++)
57145516Sdarrenr            bmsg[i] = (byte)msg[i];
58145516Sdarrenr        tuning.load(bmsg);
59145516Sdarrenr        double[] tunings = tuning.getTuning();
60170268Sdarrenr        for (int i = 0; i < tunings.length; i++)
61170268Sdarrenr            assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001);
62170268Sdarrenr    }
63170268Sdarrenr}
64170268Sdarrenr