8152501: closed/javax/sound/sampled/FileWriter/WaveBigEndian.java failing
authorserb
Tue, 05 Apr 2016 17:30:23 +0300
changeset 37556 80409fc0c8ed
parent 37555 89696d7ce334
child 37557 00d5cb18c86b
8152501: closed/javax/sound/sampled/FileWriter/WaveBigEndian.java failing Reviewed-by: amenkov
jdk/src/java.desktop/share/classes/com/sun/media/sound/AudioFloatConverter.java
jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits16ToFromFloatArray.java
jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits24ToFromFloatArray.java
jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits32ToFromFloatArray.java
jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits64ToFromFloatArray.java
jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits8ToFromFloatArray.java
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AudioFloatConverter.java	Tue Apr 05 15:37:13 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AudioFloatConverter.java	Tue Apr 05 17:30:23 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,6 +22,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package com.sun.media.sound;
 
 import java.nio.ByteBuffer;
@@ -319,8 +320,10 @@
                 float[] out_buff, int out_offset, int out_len) {
             int ix = in_offset;
             int ox = out_offset;
-            for (int i = 0; i < out_len; i++)
-                out_buff[ox++] = in_buff[ix++] * (1.0f / 127.0f);
+            for (int i = 0; i < out_len; i++) {
+                byte x = in_buff[ix++];
+                out_buff[ox++] = x > 0 ? x / 127.0f : x / 128.0f;
+            }
             return out_buff;
         }
 
@@ -328,8 +331,10 @@
                 byte[] out_buff, int out_offset) {
             int ix = in_offset;
             int ox = out_offset;
-            for (int i = 0; i < in_len; i++)
-                out_buff[ox++] = (byte) (in_buff[ix++] * 127.0f);
+            for (int i = 0; i < in_len; i++) {
+                final float x = in_buff[ix++];
+                out_buff[ox++] = (byte) (x > 0 ? x * 127 : x * 128);
+            }
             return out_buff;
         }
     }
@@ -340,9 +345,10 @@
                 float[] out_buff, int out_offset, int out_len) {
             int ix = in_offset;
             int ox = out_offset;
-            for (int i = 0; i < out_len; i++)
-                out_buff[ox++] = ((in_buff[ix++] & 0xFF) - 127)
-                        * (1.0f / 127.0f);
+            for (int i = 0; i < out_len; i++) {
+                byte x = (byte) (in_buff[ix++] - 128);
+                out_buff[ox++] = x > 0 ? x / 127.0f : x / 128.0f;
+            }
             return out_buff;
         }
 
@@ -350,8 +356,10 @@
                 byte[] out_buff, int out_offset) {
             int ix = in_offset;
             int ox = out_offset;
-            for (int i = 0; i < in_len; i++)
-                out_buff[ox++] = (byte) (127 + in_buff[ix++] * 127.0f);
+            for (int i = 0; i < in_len; i++) {
+                float x = in_buff[ix++];
+                out_buff[ox++] = (byte) (128 + (x > 0 ? x * 127 : x * 128));
+            }
             return out_buff;
         }
     }
@@ -369,10 +377,9 @@
             int ix = in_offset;
             int len = out_offset + out_len;
             for (int ox = out_offset; ox < len; ox++) {
-                out_buff[ox] = ((short) ((in_buff[ix++] & 0xFF) |
-                           (in_buff[ix++] << 8))) * (1.0f / 32767.0f);
+                short x = (short) (in_buff[ix++] & 0xFF | (in_buff[ix++] << 8));
+                out_buff[ox] = x > 0 ? x / 32767.0f : x / 32768.0f;
             }
-
             return out_buff;
         }
 
@@ -381,7 +388,8 @@
             int ox = out_offset;
             int len = in_offset + in_len;
             for (int ix = in_offset; ix < len; ix++) {
-                int x = (int) (in_buff[ix] * 32767.0);
+                float f = in_buff[ix];
+                short x = (short) (f > 0 ? f * 32767 : f * 32768);
                 out_buff[ox++] = (byte) x;
                 out_buff[ox++] = (byte) (x >>> 8);
             }
@@ -396,8 +404,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < out_len; i++) {
-                out_buff[ox++] = ((short) ((in_buff[ix++] << 8) |
-                        (in_buff[ix++] & 0xFF))) * (1.0f / 32767.0f);
+                short x = (short) ((in_buff[ix++] << 8) | (in_buff[ix++] & 0xFF));
+                out_buff[ox++] = x > 0 ? x / 32767.0f : x / 32768.0f;
             }
             return out_buff;
         }
@@ -407,7 +415,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * 32767.0);
+                float f = in_buff[ix++];
+                short x = (short) (f > 0 ? f * 32767.0f : f * 32768.0f);
                 out_buff[ox++] = (byte) (x >>> 8);
                 out_buff[ox++] = (byte) x;
             }
@@ -423,7 +432,8 @@
             int ox = out_offset;
             for (int i = 0; i < out_len; i++) {
                 int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8);
-                out_buff[ox++] = (x - 32767) * (1.0f / 32767.0f);
+                x -= 32768;
+                out_buff[ox++] = x > 0 ? x / 32767.0f : x / 32768.0f;
             }
             return out_buff;
         }
@@ -433,7 +443,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = 32767 + (int) (in_buff[ix++] * 32767.0);
+                float f = in_buff[ix++];
+                int x = 32768 + (int) (f > 0 ? f * 32767 : f * 32768);
                 out_buff[ox++] = (byte) x;
                 out_buff[ox++] = (byte) (x >>> 8);
             }
@@ -449,7 +460,8 @@
             int ox = out_offset;
             for (int i = 0; i < out_len; i++) {
                 int x = ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
-                out_buff[ox++] = (x - 32767) * (1.0f / 32767.0f);
+                x -= 32768;
+                out_buff[ox++] = x > 0 ? x / 32767.0f : x / 32768.0f;
             }
             return out_buff;
         }
@@ -459,7 +471,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = 32767 + (int) (in_buff[ix++] * 32767.0);
+                float f = in_buff[ix++];
+                int x = 32768 + (int) (f > 0 ? f * 32767 : f * 32768);
                 out_buff[ox++] = (byte) (x >>> 8);
                 out_buff[ox++] = (byte) x;
             }
@@ -484,7 +497,7 @@
                         | ((in_buff[ix++] & 0xFF) << 16);
                 if (x > 0x7FFFFF)
                     x -= 0x1000000;
-                out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
+                out_buff[ox++] = x > 0 ? x / 8388607.0f : x / 8388608.0f;
             }
             return out_buff;
         }
@@ -494,7 +507,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
+                float f = in_buff[ix++];
+                int x = (int) (f > 0 ? f * 8388607.0f : f * 8388608.0f);
                 if (x < 0)
                     x += 0x1000000;
                 out_buff[ox++] = (byte) x;
@@ -516,7 +530,7 @@
                         | ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
                 if (x > 0x7FFFFF)
                     x -= 0x1000000;
-                out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
+                out_buff[ox++] = x > 0 ? x / 8388607.0f : x / 8388608.0f;
             }
             return out_buff;
         }
@@ -526,7 +540,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
+                float f = in_buff[ix++];
+                int x = (int) (f > 0 ? f * 8388607.0f : f * 8388608.0f);
                 if (x < 0)
                     x += 0x1000000;
                 out_buff[ox++] = (byte) (x >>> 16);
@@ -546,8 +561,8 @@
             for (int i = 0; i < out_len; i++) {
                 int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
                         | ((in_buff[ix++] & 0xFF) << 16);
-                x -= 0x7FFFFF;
-                out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
+                x -= 0x800000;
+                out_buff[ox++] = x > 0 ? x / 8388607.0f : x / 8388608.0f;
             }
             return out_buff;
         }
@@ -557,8 +572,9 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
-                x += 0x7FFFFF;
+                float f = in_buff[ix++];
+                int x = (int) (f > 0 ? f * 8388607.0f : f * 8388608.0f);
+                x += 0x800000;
                 out_buff[ox++] = (byte) x;
                 out_buff[ox++] = (byte) (x >>> 8);
                 out_buff[ox++] = (byte) (x >>> 16);
@@ -576,8 +592,8 @@
             for (int i = 0; i < out_len; i++) {
                 int x = ((in_buff[ix++] & 0xFF) << 16)
                         | ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
-                x -= 0x7FFFFF;
-                out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
+                x -= 0x800000;
+                out_buff[ox++] = x > 0 ? x / 8388607.0f : x / 8388608.0f;
             }
             return out_buff;
         }
@@ -587,8 +603,9 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
-                x += 0x7FFFFF;
+                float f = in_buff[ix++];
+                int x = (int) (f > 0 ? f * 8388607.0f : f * 8388608.0f);
+                x += 8388608;
                 out_buff[ox++] = (byte) (x >>> 16);
                 out_buff[ox++] = (byte) (x >>> 8);
                 out_buff[ox++] = (byte) x;
@@ -673,7 +690,7 @@
                 int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8) |
                         ((in_buff[ix++] & 0xFF) << 16) |
                         ((in_buff[ix++] & 0xFF) << 24);
-                x -= 0x7FFFFFFF;
+                x -= 0x80000000;
                 out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
             }
             return out_buff;
@@ -685,7 +702,7 @@
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
                 int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
-                x += 0x7FFFFFFF;
+                x += 0x80000000;
                 out_buff[ox++] = (byte) x;
                 out_buff[ox++] = (byte) (x >>> 8);
                 out_buff[ox++] = (byte) (x >>> 16);
@@ -706,7 +723,7 @@
                 int x = ((in_buff[ix++] & 0xFF) << 24) |
                         ((in_buff[ix++] & 0xFF) << 16) |
                         ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
-                x -= 0x7FFFFFFF;
+                x -= 0x80000000;
                 out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
             }
             return out_buff;
@@ -718,7 +735,7 @@
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
                 int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
-                x += 0x7FFFFFFF;
+                x += 0x80000000;
                 out_buff[ox++] = (byte) (x >>> 24);
                 out_buff[ox++] = (byte) (x >>> 16);
                 out_buff[ox++] = (byte) (x >>> 8);
@@ -737,7 +754,7 @@
     // PCM 32+ bit, signed, little-endian
     private static class AudioFloatConversion32xSL extends AudioFloatConverter {
 
-        final int xbytes;
+        private final int xbytes;
 
         AudioFloatConversion32xSL(int xbytes) {
             this.xbytes = xbytes;
@@ -778,7 +795,7 @@
     // PCM 32+ bit, signed, big-endian
     private static class AudioFloatConversion32xSB extends AudioFloatConverter {
 
-        final int xbytes;
+        private final int xbytes;
 
         AudioFloatConversion32xSB(int xbytes) {
             this.xbytes = xbytes;
@@ -820,7 +837,7 @@
     // PCM 32+ bit, unsigned, little-endian
     private static class AudioFloatConversion32xUL extends AudioFloatConverter {
 
-        final int xbytes;
+        private final int xbytes;
 
         AudioFloatConversion32xUL(int xbytes) {
             this.xbytes = xbytes;
@@ -835,7 +852,7 @@
                 int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
                         | ((in_buff[ix++] & 0xFF) << 16)
                         | ((in_buff[ix++] & 0xFF) << 24);
-                x -= 0x7FFFFFFF;
+                x -= 0x80000000;
                 out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
             }
             return out_buff;
@@ -847,7 +864,7 @@
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
                 int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
-                x += 0x7FFFFFFF;
+                x += 0x80000000;
                 for (int j = 0; j < xbytes; j++) {
                     out_buff[ox++] = 0;
                 }
@@ -863,7 +880,7 @@
     // PCM 32+ bit, unsigned, big-endian
     private static class AudioFloatConversion32xUB extends AudioFloatConverter {
 
-        final int xbytes;
+        private final int xbytes;
 
         AudioFloatConversion32xUB(int xbytes) {
             this.xbytes = xbytes;
@@ -878,7 +895,7 @@
                         ((in_buff[ix++] & 0xFF) << 16) |
                         ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
                 ix += xbytes;
-                x -= 2147483647;
+                x -= 0x80000000;
                 out_buff[ox++] = x * (1.0f / 2147483647.0f);
             }
             return out_buff;
@@ -889,8 +906,8 @@
             int ix = in_offset;
             int ox = out_offset;
             for (int i = 0; i < in_len; i++) {
-                int x = (int) (in_buff[ix++] * 2147483647.0);
-                x += 2147483647;
+                int x = (int) (in_buff[ix++] * 2147483647.0f);
+                x += 0x80000000;
                 out_buff[ox++] = (byte) (x >>> 24);
                 out_buff[ox++] = (byte) (x >>> 16);
                 out_buff[ox++] = (byte) (x >>> 8);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits16ToFromFloatArray.java	Tue Apr 05 17:30:23 2016 +0300
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+import com.sun.media.sound.AudioFloatConverter;
+
+import static javax.sound.sampled.AudioFormat.Encoding.*;
+
+/**
+ * @test
+ * @bug 8152501
+ * @modules java.desktop/com.sun.media.sound
+ */
+public final class Bits16ToFromFloatArray {
+
+    private static final int SIZE = 16;
+
+    private static final float[] FLOATS = {-1.0f, 0, 1.0f};
+
+    private static short MID_U = (short) (Short.MAX_VALUE + 1);
+    private static short MAX_U = -1;
+
+    // BIG ENDIAN
+    private static final byte[] SIGNED_BIG = {
+            (byte) (Short.MIN_VALUE >> 8), (byte) (Short.MIN_VALUE & 0xff), 0,
+            0, (byte) (Short.MAX_VALUE >> 8), (byte) (Short.MAX_VALUE & 0xff)
+    };
+
+    private static final byte[] UNSIGNED_BIG = {
+            0, 0, (byte) (MID_U >> 8), (byte) (MID_U & 0xff),
+            (byte) (MAX_U >> 8), (byte) (MAX_U >> 8)
+    };
+
+    // LITTLE ENDIAN
+    private static final byte[] SIGNED_LITTLE = {
+            (byte) (Short.MIN_VALUE & 0xff), (byte) (Short.MIN_VALUE >> 8), 0,
+            0, (byte) (Short.MAX_VALUE & 0xff), (byte) (Short.MAX_VALUE >> 8)
+    };
+
+    private static final byte[] UNSIGNED_LITTLE = {
+            0, 0, (byte) (MID_U & 0xff), (byte) (MID_U >> 8),
+            (byte) (MAX_U >> 8), (byte) (MAX_U >> 8)
+    };
+
+    public static void main(final String[] args) {
+        test(PCM_UNSIGNED, UNSIGNED_BIG, true);
+        test(PCM_UNSIGNED, UNSIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_BIG, true);
+    }
+
+    private static void test(final Encoding enc, final byte[] expected,
+                             boolean end) {
+        System.err.println("enc = " + enc);
+        AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
+                                         end);
+        byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
+        AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
+
+        conv.toByteArray(FLOATS, bytes);
+
+        if (!Arrays.equals(bytes, expected)) {
+            System.err.println("Actual: " + Arrays.toString(bytes));
+            System.err.println("Expected: " + Arrays.toString(expected));
+            throw new RuntimeException();
+        }
+
+        float[] floats = new float[bytes.length / af.getFrameSize()];
+        conv.toFloatArray(bytes, floats);
+
+        if (!Arrays.equals(floats, FLOATS)) {
+            System.err.println("Actual: " + Arrays.toString(floats));
+            System.err.println("Expected: " + Arrays.toString(FLOATS));
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits24ToFromFloatArray.java	Tue Apr 05 17:30:23 2016 +0300
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+import com.sun.media.sound.AudioFloatConverter;
+
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_UNSIGNED;
+
+/**
+ * @test
+ * @bug 8152501
+ * @modules java.desktop/com.sun.media.sound
+ */
+public final class Bits24ToFromFloatArray {
+
+    private static final int SIZE = 24;
+
+    private static final float[] FLOATS = {-1.0f, 0, 1.0f};
+
+    private static int MIN_S = -8_388_608;
+    private static int MAX_S = 8_388_607;
+
+    private static int MID_U = 0xFFFFFF / 2 + 1;
+    private static int MAX_U = 0xFFFFFF;
+
+    // BIG ENDIAN
+    private static final byte[] SIGNED_BIG = {
+            (byte) ((MIN_S >> 16) & 0xff),
+            (byte) ((MIN_S >> 8) & 0xff),
+            (byte) ((MIN_S >> 0) & 0xff),
+            0, 0, 0,
+            (byte) ((MAX_S >> 16) & 0xff),
+            (byte) ((MAX_S >> 8) & 0xff),
+            (byte) ((MAX_S >> 0) & 0xff),
+    };
+
+    private static final byte[] UNSIGNED_BIG = {
+            0, 0, 0,
+            (byte) ((MID_U >> 16) & 0xff),
+            (byte) ((MID_U >> 8) & 0xff),
+            (byte) ((MID_U >> 0) & 0xff),
+            (byte) ((MAX_U >> 16) & 0xff),
+            (byte) ((MAX_U >> 8) & 0xff),
+            (byte) ((MAX_U >> 0) & 0xff),
+
+    };
+
+    // LITTLE ENDIAN
+    private static final byte[] SIGNED_LITTLE = {
+            (byte) ((MIN_S >> 0) & 0xff),
+            (byte) ((MIN_S >> 8) & 0xff),
+            (byte) ((MIN_S >> 16) & 0xff),
+            0, 0, 0,
+            (byte) ((MAX_S >> 0) & 0xff),
+            (byte) ((MAX_S >> 8) & 0xff),
+            (byte) ((MAX_S >> 16) & 0xff),
+            };
+
+    private static final byte[] UNSIGNED_LITTLE = {
+            0, 0, 0,
+            (byte) ((MID_U >> 0) & 0xff),
+            (byte) ((MID_U >> 8) & 0xff),
+            (byte) ((MID_U >> 16) & 0xff),
+            (byte) ((MAX_U >> 0) & 0xff),
+            (byte) ((MAX_U >> 8) & 0xff),
+            (byte) ((MAX_U >> 16) & 0xff),
+            };
+
+    public static void main(final String[] args) {
+        test(PCM_UNSIGNED, UNSIGNED_BIG, true);
+        test(PCM_UNSIGNED, UNSIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_BIG, true);
+    }
+
+    private static void test(final Encoding enc, final byte[] expected,
+                             boolean end) {
+        System.err.println(enc);
+        AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
+                                         end);
+        byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
+        AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
+
+        conv.toByteArray(FLOATS, bytes);
+
+        if (!Arrays.equals(bytes, expected)) {
+            System.err.println("Actual: " + Arrays.toString(bytes));
+            System.err.println("Expected: " + Arrays.toString(expected));
+            throw new RuntimeException();
+        }
+
+        float[] floats = new float[bytes.length / af.getFrameSize()];
+        conv.toFloatArray(bytes, floats);
+
+        if (!Arrays.equals(floats, FLOATS)) {
+            System.err.println("Actual: " + Arrays.toString(floats));
+            System.err.println("Expected: " + Arrays.toString(FLOATS));
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits32ToFromFloatArray.java	Tue Apr 05 17:30:23 2016 +0300
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+import com.sun.media.sound.AudioFloatConverter;
+
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_UNSIGNED;
+
+/**
+ * @test
+ * @bug 8152501
+ * @modules java.desktop/com.sun.media.sound
+ */
+public final class Bits32ToFromFloatArray {
+
+    private static final int SIZE = 32;
+
+    private static final float[] FLOATS = {-1.0f, 0, 1.0f};
+
+    private static int MID_U = (int) (Integer.MAX_VALUE + 1);
+    private static int MAX_U = -1;
+
+    // BIG ENDIAN
+    private static final byte[] SIGNED_BIG = {
+            (byte) ((Integer.MIN_VALUE >> 24) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 16) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 8) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 0) & 0xff),
+            0, 0, 0, 0,
+            (byte) ((Integer.MAX_VALUE >> 24) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 16) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 8) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 0) & 0xff),
+    };
+
+    private static final byte[] UNSIGNED_BIG = {
+            0, 0, 0, 0,
+            (byte) ((MID_U >> 24) & 0xff),
+            (byte) ((MID_U >> 16) & 0xff),
+            (byte) ((MID_U >> 8) & 0xff),
+            (byte) ((MID_U >> 0) & 0xff),
+            (byte) ((MAX_U >> 24) & 0xff),
+            (byte) ((MAX_U >> 16) & 0xff),
+            (byte) ((MAX_U >> 8) & 0xff),
+            (byte) ((MAX_U >> 0) & 0xff),
+
+    };
+
+    // LITTLE ENDIAN
+    private static final byte[] SIGNED_LITTLE = {
+            (byte) ((Integer.MIN_VALUE >> 0) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 8) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 16) & 0xff),
+            (byte) ((Integer.MIN_VALUE >> 24) & 0xff),
+            0, 0, 0, 0,
+            (byte) ((Integer.MAX_VALUE >> 0) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 8) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 16) & 0xff),
+            (byte) ((Integer.MAX_VALUE >> 24) & 0xff),
+            };
+
+    private static final byte[] UNSIGNED_LITTLE = {
+            0, 0, 0, 0,
+            (byte) ((MID_U >> 0) & 0xff),
+            (byte) ((MID_U >> 8) & 0xff),
+            (byte) ((MID_U >> 16) & 0xff),
+            (byte) ((MID_U >> 24) & 0xff),
+            (byte) ((MAX_U >> 0) & 0xff),
+            (byte) ((MAX_U >> 8) & 0xff),
+            (byte) ((MAX_U >> 16) & 0xff),
+            (byte) ((MAX_U >> 24) & 0xff),
+            };
+
+    public static void main(final String[] args) {
+        test(PCM_UNSIGNED, UNSIGNED_BIG, true);
+        test(PCM_UNSIGNED, UNSIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_BIG, true);
+    }
+
+    private static void test(final Encoding enc, final byte[] expected,
+                             boolean end) {
+        AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
+                                         end);
+        byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
+        AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
+
+        conv.toByteArray(FLOATS, bytes);
+
+        if (!Arrays.equals(bytes, expected)) {
+            System.err.println("Actual: " + Arrays.toString(bytes));
+            System.err.println("Expected: " + Arrays.toString(expected));
+            throw new RuntimeException();
+        }
+
+        float[] floats = new float[bytes.length / af.getFrameSize()];
+        conv.toFloatArray(bytes, floats);
+
+        if (!Arrays.equals(floats, FLOATS)) {
+            System.err.println("Actual: " + Arrays.toString(floats));
+            System.err.println("Expected: " + Arrays.toString(FLOATS));
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits64ToFromFloatArray.java	Tue Apr 05 17:30:23 2016 +0300
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+import com.sun.media.sound.AudioFloatConverter;
+
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;
+import static javax.sound.sampled.AudioFormat.Encoding.PCM_UNSIGNED;
+
+/**
+ * @test
+ * @bug 8152501
+ * @modules java.desktop/com.sun.media.sound
+ */
+public final class Bits64ToFromFloatArray {
+
+    private static final int SIZE = 64;
+
+    private static final float[] FLOATS = {-1.0f, 0, 1.0f};
+
+    private static long MID_U = (long) (Long.MAX_VALUE + 1);
+    private static long MAX_U = -1;
+
+    // BIG ENDIAN
+    private static final byte[] SIGNED_BIG = {
+            (byte) ((Long.MIN_VALUE >> 56) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 48) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 40) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 32) & 0xff),
+            0, 0, 0, 0, // current javasound impl will ignore this
+            0, 0, 0, 0,
+            0, 0, 0, 0,
+            (byte) ((Long.MAX_VALUE >> 56) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 48) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 40) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 32) & 0xff),
+            0, 0, 0, 0, // current javasound impl will ignore this
+    };
+
+    private static final byte[] UNSIGNED_BIG = {
+            0, 0, 0, 0,
+            0, 0, 0, 0,
+            (byte) ((MID_U >> 56) & 0xff),
+            (byte) ((MID_U >> 48) & 0xff),
+            (byte) ((MID_U >> 40) & 0xff),
+            (byte) ((MID_U >> 32) & 0xff),
+            0, 0, 0, 0, // current javasound impl will ignore this
+            (byte) ((MAX_U >> 56) & 0xff),
+            (byte) ((MAX_U >> 48) & 0xff),
+            (byte) ((MAX_U >> 40) & 0xff),
+            (byte) ((MAX_U >> 32) & 0xff),
+            0, 0, 0, 0, // current javasound impl will ignore this
+    };
+
+    // LITTLE ENDIAN
+    private static final byte[] SIGNED_LITTLE = {
+            0, 0, 0, 0, // current javasound impl will ignore this
+            (byte) ((Long.MIN_VALUE >> 32) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 40) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 48) & 0xff),
+            (byte) ((Long.MIN_VALUE >> 56) & 0xff),
+            0, 0, 0, 0,
+            0, 0, 0, 0,
+            0, 0, 0, 0, // current javasound impl will ignore this
+            (byte) ((Long.MAX_VALUE >> 32) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 40) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 48) & 0xff),
+            (byte) ((Long.MAX_VALUE >> 56) & 0xff),
+            };
+
+    private static final byte[] UNSIGNED_LITTLE = {
+            0, 0, 0, 0,
+            0, 0, 0, 0,
+            0, 0, 0, 0, // current javasound impl will ignore this
+            (byte) ((MID_U >> 32) & 0xff),
+            (byte) ((MID_U >> 40) & 0xff),
+            (byte) ((MID_U >> 48) & 0xff),
+            (byte) ((MID_U >> 56) & 0xff),
+            0, 0, 0, 0, // current javasound impl will ignore this
+            (byte) ((MAX_U >> 32) & 0xff),
+            (byte) ((MAX_U >> 40) & 0xff),
+            (byte) ((MAX_U >> 48) & 0xff),
+            (byte) ((MAX_U >> 56) & 0xff),
+            };
+
+    public static void main(final String[] args) {
+        test(PCM_UNSIGNED, UNSIGNED_BIG, true);
+        test(PCM_UNSIGNED, UNSIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_LITTLE, false);
+        test(PCM_SIGNED, SIGNED_BIG, true);
+    }
+
+    private static void test(final Encoding enc, final byte[] expected,
+                             boolean end) {
+        System.err.println(enc);
+        AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
+                                         end);
+        byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
+        AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
+
+        conv.toByteArray(FLOATS, bytes);
+
+        if (!Arrays.equals(bytes, expected)) {
+            System.err.println("Actual:   " + Arrays.toString(bytes));
+            System.err.println("Expected: " + Arrays.toString(expected));
+            throw new RuntimeException();
+        }
+
+        float[] floats = new float[bytes.length / af.getFrameSize()];
+        conv.toFloatArray(bytes, floats);
+
+        if (!Arrays.equals(floats, FLOATS)) {
+            System.err.println("Actual: " + Arrays.toString(floats));
+            System.err.println("Expected: " + Arrays.toString(FLOATS));
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/Gervill/AudioFloatConverter/Bits8ToFromFloatArray.java	Tue Apr 05 17:30:23 2016 +0300
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+import com.sun.media.sound.AudioFloatConverter;
+
+import static javax.sound.sampled.AudioFormat.Encoding.*;
+
+/**
+ * @test
+ * @bug 8152501
+ * @modules java.desktop/com.sun.media.sound
+ */
+public final class Bits8ToFromFloatArray {
+
+    private static final int SIZE = 8;
+
+    private static final float[] FLOATS = {-1.0f, 0, 1.0f};
+
+    private static final byte[] SIGNED = {Byte.MIN_VALUE, 0, Byte.MAX_VALUE};
+
+    private static final byte[] UNSIGNED = {
+            0, (byte) (Byte.MAX_VALUE + 1), (byte) -1
+    };
+
+    public static void main(final String[] args) {
+        test(PCM_UNSIGNED, UNSIGNED);
+        test(PCM_SIGNED, SIGNED);
+    }
+
+    private static void test(final Encoding enc, final byte[] expected) {
+        AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
+                                         true);
+        byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
+        AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
+
+        conv.toByteArray(FLOATS, bytes);
+
+        if (!Arrays.equals(bytes, expected)) {
+            System.err.println("Actual: " + Arrays.toString(bytes));
+            System.err.println("Expected: " + Arrays.toString(expected));
+            throw new RuntimeException();
+        }
+
+        float[] floats = new float[bytes.length / af.getFrameSize()];
+        conv.toFloatArray(bytes, floats);
+
+        if (!Arrays.equals(floats, FLOATS)) {
+            System.err.println("Actual: " + Arrays.toString(floats));
+            System.err.println("Expected: " + Arrays.toString(FLOATS));
+            throw new RuntimeException();
+        }
+    }
+}