[Audio-engine-dev] Updating Gervill for OpenJDK 6 build 13

Joe Darcy Joe.Darcy at Sun.COM
Mon Sep 15 20:24:47 PDT 2008


Hello.

Since OpenJDK 6 took a snapshot of Gervill for b12, Gervill was been 
updated.  Also, Mark Wielaard has a patch which address some JCK failures:

http://mail.openjdk.java.net/pipermail/audio-engine-dev/2008-September/000059.html

For the next build of OpenJDK 6,  build 13, I'd like to include both 
sets of changes; below is patch of those changes compared to build 12.

Please review by September 19.

Thanks,

-Joe

--- old/src/share/classes/com/sun/media/sound/ModelByteBuffer.java	Sun Sep 14 23:15:37 2008
+++ new/src/share/classes/com/sun/media/sound/ModelByteBuffer.java	Sun Sep 14 23:15:37 2008
@@ -85,11 +85,12 @@
         }
 
         public long skip(long n) throws IOException {
+            if( n < 0)
+                return 0;
             if (n > left)
                 n = left;
-            n = super.skip(n);
-            if (n == -1)
-                return -1;
+            long p = raf.getFilePointer();
+            raf.seek(p + n);
             left -= n;
             return n;
         }
--- old/src/share/classes/com/sun/media/sound/SoftMainMixer.java	Sun Sep 14 23:15:38 2008
+++ new/src/share/classes/com/sun/media/sound/SoftMainMixer.java	Sun Sep 14 23:15:38 2008
@@ -69,7 +69,7 @@
     private int nrofchannels = 2;
     private SoftVoice[] voicestatus = null;
     private SoftAudioBuffer[] buffers;
-    private SoftAudioProcessor reverb;
+    private SoftReverb reverb;
     private SoftAudioProcessor chorus;
     private SoftAudioProcessor agc;
     private long msec_buffer_len = 0;
@@ -681,6 +681,8 @@
         chorus.init(samplerate, controlrate);
         agc.init(samplerate, controlrate);
 
+        reverb.setLightMode(synth.reverb_light);
+        
         reverb.setMixMode(true);
         chorus.setMixMode(true);
         agc.setMixMode(false);
--- old/src/share/classes/com/sun/media/sound/SoftReverb.java	Sun Sep 14 23:15:39 2008
+++ new/src/share/classes/com/sun/media/sound/SoftReverb.java	Sun Sep 14 23:15:39 2008
@@ -35,7 +35,7 @@
  */
 public class SoftReverb implements SoftAudioProcessor {
 
-    private static class Delay {
+    private final static class Delay {
 
         private float[] delaybuffer;
         private int rovepos = 0;
@@ -52,31 +52,28 @@
             rovepos = 0;
         }
 
-        public void processReplace(float[] in, float[] out) {
-            float[] delaybuffer = this.delaybuffer;
+        public void processReplace(float[] inout) {
             if (delaybuffer == null)
                 return;
-            int len = in.length;
+            int len = inout.length;
             int rnlen = delaybuffer.length;
             int rovepos = this.rovepos;
 
             for (int i = 0; i < len; i++) {
-                float x = in[i];
-                out[i] = delaybuffer[rovepos];
+                float x = inout[i];
+                inout[i] = delaybuffer[rovepos];
                 delaybuffer[rovepos] = x;
-                rovepos = rovepos + 1;
-                if (rovepos == rnlen)
+                if (++rovepos == rnlen)
                     rovepos = 0;
-                //rovepos = (rovepos + 1) % rnlen;
             }
             this.rovepos = rovepos;
         }
     }
 
-    private static class AllPass {
+    private final static class AllPass {
 
-        private float[] delaybuffer;
-        private int delaybuffersize;
+        private final float[] delaybuffer;
+        private final int delaybuffersize;
         private int rovepos = 0;
         private float feedback;
 
@@ -88,47 +85,42 @@
         public void setFeedBack(float feedback) {
             this.feedback = feedback;
         }
-        int ucount = 0;
 
+        public void processReplace(float inout[]) {
+            int len = inout.length;
+            int delaybuffersize = this.delaybuffersize;
+            int rovepos = this.rovepos;            
+            for (int i = 0; i < len; i++) {
+                float delayout = delaybuffer[rovepos];
+                float input = inout[i];
+                inout[i] = delayout - input;
+                delaybuffer[rovepos] = input + delayout * feedback;
+                if (++rovepos == delaybuffersize)
+                    rovepos = 0;
+            }
+            this.rovepos = rovepos;                        
+        }
+        
         public void processReplace(float in[], float out[]) {
             int len = in.length;
+            int delaybuffersize = this.delaybuffersize;
+            int rovepos = this.rovepos;            
             for (int i = 0; i < len; i++) {
-
                 float delayout = delaybuffer[rovepos];
-
-                // undenormalise(delayout)
-                /*
-                if (((delayout > 0.0) && (delayout < 1.0E-10))
-                        || ((delayout < 0.0) && (delayout > -1.0E-10)))
-                    delayout = 0;
-                */
-
                 float input = in[i];
-                out[i] = -input + delayout;
+                out[i] = delayout - input;
                 delaybuffer[rovepos] = input + delayout * feedback;
                 if (++rovepos == delaybuffersize)
                     rovepos = 0;
             }
-
-            ucount++;
-            if (ucount == 10) {
-                ucount = 0;
-                for (int i = 0; i < delaybuffer.length; i++) {
-                    double v = delaybuffer[i];
-                    if (((v > 0.0) && (v < 1.0E-10))
-                            || ((v < 0.0) && (v > -1.0E-10))) {
-                        delaybuffer[i] = 0;
-                    }
-                }
-            }
-
-        }
+            this.rovepos = rovepos;                        
+        }        
     }
 
-    private static class Comb {
+    private final static class Comb {
 
-        private float[] delaybuffer;
-        private int delaybuffersize;
+        private final float[] delaybuffer;
+        private final int delaybuffersize;
         private int rovepos = 0;
         private float feedback;
         private float filtertemp = 0;
@@ -142,56 +134,54 @@
 
         public void setFeedBack(float feedback) {
             this.feedback = feedback;
+            filtercoeff2 = (1 - filtercoeff1)* feedback;
         }
-        int ucount = 0;
 
         public void processMix(float in[], float out[]) {
-            int len = in.length;
-
-            float filtercoeff2 = this.filtercoeff2 * feedback;
-
+            int len = in.length;            
+            int delaybuffersize = this.delaybuffersize;
+            int rovepos = this.rovepos;
+            float filtertemp = this.filtertemp;
+            float filtercoeff1 = this.filtercoeff1;
+            float filtercoeff2 = this.filtercoeff2;
             for (int i = 0; i < len; i++) {
                 float delayout = delaybuffer[rovepos];
-
                 // One Pole Lowpass Filter
                 filtertemp = (delayout * filtercoeff2)
                         + (filtertemp * filtercoeff1);
-
-                // undenormalise(filtertemp)
-                /*
-                if (((filtertemp > 0.0) && (filtertemp < 1.0E-10))
-                        || ((filtertemp < 0.0) && (filtertemp > -1.0E-10)))
-                    filtertemp = 0;
-                */
                 out[i] += delayout;
-                delaybuffer[rovepos] = in[i] + (filtertemp);// * feedback);
-
+                delaybuffer[rovepos] = in[i] + filtertemp;
                 if (++rovepos == delaybuffersize)
                     rovepos = 0;
+            }            
+            this.filtertemp  = filtertemp;
+            this.rovepos = rovepos;
+        }
 
-            }
-            ucount++;
-            if (ucount == 10) {
-                ucount = 0;
-                if (((filtertemp > 0.0) && (filtertemp < 1.0E-10))
-                        || ((filtertemp < 0.0) && (filtertemp > -1.0E-10))) {
-                    filtertemp = 0;
-                }
-                for (int i = 0; i < delaybuffer.length; i++) {
-                    double v = delaybuffer[i];
-                    if (((v > 0.0) && (v < 1.0E-10))
-                            || ((v < 0.0) && (v > -1.0E-10))) {
-                        delaybuffer[i] = 0;
-                    }
-                }
-            }
-
-
+        public void processReplace(float in[], float out[]) {
+            int len = in.length;            
+            int delaybuffersize = this.delaybuffersize;
+            int rovepos = this.rovepos;
+            float filtertemp = this.filtertemp;
+            float filtercoeff1 = this.filtercoeff1;
+            float filtercoeff2 = this.filtercoeff2;
+            for (int i = 0; i < len; i++) {
+                float delayout = delaybuffer[rovepos];
+                // One Pole Lowpass Filter
+                filtertemp = (delayout * filtercoeff2)
+                        + (filtertemp * filtercoeff1);
+                out[i] = delayout;
+                delaybuffer[rovepos] = in[i] + filtertemp;
+                if (++rovepos == delaybuffersize)
+                    rovepos = 0;
+            }            
+            this.filtertemp  = filtertemp;
+            this.rovepos = rovepos;
         }
 
         public void setDamp(float val) {
             filtercoeff1 = val;
-            filtercoeff2 = 1 - filtercoeff1;
+            filtercoeff2 = (1 - filtercoeff1)* feedback;
         }
     }
     private float roomsize;
@@ -203,8 +193,11 @@
     private AllPass[] allpassL;
     private AllPass[] allpassR;
     private float[] input;
-    private float[] outR;
-    private float[] outL;
+    private float[] out;
+    private float[] pre1;
+    private float[] pre2;
+    private float[] pre3;
+    private boolean denormal_flip = false;
     private boolean mix = true;
     private SoftAudioBuffer inputA;
     private SoftAudioBuffer left;
@@ -214,7 +207,8 @@
     private float dirty_damp;
     private float dirty_predelay;
     private float dirty_gain;
-    private float samplerate;
+    private float samplerate;    
+    private boolean light = true;
 
     public void init(float samplerate, float controlrate) {
         this.samplerate = samplerate;
@@ -237,7 +231,7 @@
         combL[3] = new Comb((int) (freqscale * (1356)));
         combR[3] = new Comb((int) (freqscale * (1356 + stereospread)));
         combL[4] = new Comb((int) (freqscale * (1422)));
-        combR[4] = new Comb((int) (freqscale * (1422 + stereospread)));
+        combR[4] = new Comb((int) (freqscale * (1422 + stereospread)));        
         combL[5] = new Comb((int) (freqscale * (1491)));
         combR[5] = new Comb((int) (freqscale * (1491 + stereospread)));
         combL[6] = new Comb((int) (freqscale * (1557)));
@@ -306,58 +300,100 @@
             input = new float[numsamples];
 
         float again = gain * 0.018f / 2;
+        
+        denormal_flip = !denormal_flip;
+        if(denormal_flip)
+            for (int i = 0; i < numsamples; i++) 
+                input[i] = inputA[i] * again + 1E-20f;
+        else
+            for (int i = 0; i < numsamples; i++) 
+                input[i] = inputA[i] * again - 1E-20f;
 
-        for (int i = 0; i < numsamples; i++)
-            input[i] = inputA[i] * again;
-
-        delay.processReplace(input, input);
-
-
-        if (right != null) {
-            if (outR == null || outR.length < numsamples)
-                outR = new float[numsamples];
-            Arrays.fill(outR, 0);
-            for (int i = 0; i < combR.length; i++)
-                combR[i].processMix(input, outR);
+        delay.processReplace(input);
+                      
+        if(light && (right != null))
+        {
+            if (pre1 == null || pre1.length < numsamples)
+            {
+                pre1 = new float[numsamples];
+                pre2 = new float[numsamples];
+                pre3 = new float[numsamples];
+            }
+            
             for (int i = 0; i < allpassL.length; i++)
-                allpassR[i].processReplace(outR, outR);
+                allpassL[i].processReplace(input);
 
-            if (mix) {
-                for (int i = 0; i < numsamples; i++)
-                    right[i] += outR[i];
-            } else {
-                for (int i = 0; i < numsamples; i++)
-                    right[i] = outR[i];
+            combL[0].processReplace(input, pre3);
+            combL[1].processReplace(input, pre3);
+
+            combL[2].processReplace(input, pre1);
+            for (int i = 4; i < combL.length-2; i+=2)
+                combL[i].processMix(input, pre1); 
+            
+            combL[3].processReplace(input, pre2);;
+            for (int i = 5; i < combL.length-2; i+=2)            
+                combL[i].processMix(input, pre2);
+                                        
+            if (!mix)
+            {
+                Arrays.fill(right, 0);            
+                Arrays.fill(left, 0);
             }
+            for (int i = combR.length-2; i < combR.length; i++)
+                combR[i].processMix(input, right);            
+            for (int i = combL.length-2; i < combL.length; i++)
+                combL[i].processMix(input, left);
+            
+            for (int i = 0; i < numsamples; i++) 
+            {
+                float p = pre1[i] - pre2[i];
+                float m = pre3[i];
+                left[i] += m + p;
+                right[i] += m - p;
+            }
         }
+        else
+        {
+            if (out == null || out.length < numsamples)
+                out = new float[numsamples];
+            
+            if (right != null) {
+                if (!mix)            
+                    Arrays.fill(right, 0);                        
+                allpassR[0].processReplace(input, out);
+                for (int i = 1; i < allpassR.length; i++)
+                    allpassR[i].processReplace(out);
+                for (int i = 0; i < combR.length; i++)
+                    combR[i].processMix(out, right);
+            }
 
-
-        if (outL == null || outL.length < numsamples)
-            outL = new float[numsamples];
-        Arrays.fill(outL, 0);
-        for (int i = 0; i < combL.length; i++)
-            combL[i].processMix(input, outL);
-        for (int i = 0; i < allpassL.length; i++)
-            allpassL[i].processReplace(outL, outL);
-        
-        if (mix) {
-            for (int i = 0; i < numsamples; i++)
-                left[i] += outL[i];
-        } else {
-            for (int i = 0; i < numsamples; i++)
-                left[i] = outL[i];
+            if (!mix)            
+                Arrays.fill(left, 0);                    
+            allpassL[0].processReplace(input, out);
+            for (int i = 1; i < allpassL.length; i++)
+                allpassL[i].processReplace(out);
+            for (int i = 0; i < combL.length; i++)
+                combL[i].processMix(out, left);            
         }
+        
+        
+        
+        
+        
 
         if (silent_input) {
-            float avgpower = 0; 
+            silent = true;
             for (int i = 0; i < numsamples; i++)
-                avgpower += outL[i]*outL[i];
-            avgpower /= numsamples;
-            avgpower = (float)Math.sqrt(avgpower);
-            if(avgpower < 0.00001)
-                silent = true;
-        } 
-
+            {
+                float v = left[i];
+                if(v > 1E-10 || v < -1E-10)
+                {
+                    silent = false;
+                    break;
+                }
+            }
+        }
+        
     }
 
     public void globalParameterControlChange(int[] slothpath, long param,
@@ -440,7 +476,7 @@
     public void setRoomSize(float value) {
         roomsize = 1 - (0.17f / value);
 
-        for (int i = 0; i < 8; i++) {
+        for (int i = 0; i < combL.length; i++) {
             combL[i].feedback = roomsize;
             combR[i].feedback = roomsize;
         }
@@ -464,10 +500,16 @@
             damp = 0;
 
         // damp = value * 0.4f;
-        for (int i = 0; i < 8; i++) {
+        for (int i = 0; i < combL.length; i++) {
             combL[i].setDamp(damp);
             combR[i].setDamp(damp);
         }
 
     }
+    
+    public void setLightMode(boolean light)
+    {
+        this.light = light;
+    }
 }
+
--- old/src/share/classes/com/sun/media/sound/DLSSoundbankReader.java	Sun Sep 14 23:15:40 2008
+++ new/src/share/classes/com/sun/media/sound/DLSSoundbankReader.java	Sun Sep 14 23:15:40 2008
@@ -47,6 +47,8 @@
             return new DLSSoundbank(url);
         } catch (RIFFInvalidFormatException e) {
             return null;
+        } catch(IOException ioe) {
+            return null;
         }
     }
 
--- old/src/share/classes/com/sun/media/sound/SF2SoundbankReader.java	Sun Sep 14 23:15:40 2008
+++ new/src/share/classes/com/sun/media/sound/SF2SoundbankReader.java	Sun Sep 14 23:15:40 2008
@@ -46,6 +46,8 @@
             return new SF2Soundbank(url);
         } catch (RIFFInvalidFormatException e) {
             return null;
+        } catch(IOException ioe) {
+            return null;
         }
     }
 
--- old/src/share/classes/com/sun/media/sound/SoftChannel.java	Sun Sep 14 23:15:41 2008
+++ new/src/share/classes/com/sun/media/sound/SoftChannel.java	Sun Sep 14 23:15:41 2008
@@ -1215,7 +1215,9 @@
 
     public int getController(int controller) {
         synchronized (control_mutex) {
-            return this.controller[controller];
+            // Should only return lower 7 bits,
+            // even when controller is "boosted" higher.
+            return this.controller[controller] & 127;
         }
     }
 
--- old/src/share/classes/com/sun/media/sound/SoftSynthesizer.java	Sun Sep 14 23:15:42 2008
+++ new/src/share/classes/com/sun/media/sound/SoftSynthesizer.java	Sun Sep 14 23:15:42 2008
@@ -177,6 +177,7 @@
     // 1: DLS Voice Allocation
     protected int voice_allocation_mode = 0;
 
+    protected boolean reverb_light = true;
     protected boolean reverb_on = true;
     protected boolean chorus_on = true;
     protected boolean agc_on = true;
@@ -334,6 +335,7 @@
         largemode = (Boolean)items[9].value;
         number_of_midi_channels = (Integer)items[10].value;
         jitter_correction = (Boolean)items[11].value;
+        reverb_light = (Boolean)items[12].value;
     }
 
     private String patchToString(Patch patch) {
@@ -742,6 +744,9 @@
     }
 
     public void unloadAllInstruments(Soundbank soundbank) {
+        if (soundbank == null || !isSoundbankSupported(soundbank))
+            throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
+
         if (!isOpen())
             return;
 
@@ -766,6 +771,9 @@
     }
 
     public void unloadInstruments(Soundbank soundbank, Patch[] patchList) {
+        if (soundbank == null || !isSoundbankSupported(soundbank))
+            throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
+
         if (!isOpen())
             return;
 
@@ -844,6 +852,10 @@
         item.description = "Turn jitter correction on or off.";
         list.add(item);
 
+        item = new AudioSynthesizerPropertyInfo("light reverb", o?reverb_light:true);
+        item.description = "Turn light reverb mode on or off";
+        list.add(item);
+        
         AudioSynthesizerPropertyInfo[] items;
         items = list.toArray(new AudioSynthesizerPropertyInfo[list.size()]);
 
--- old/test/javax/sound/midi/Gervill/AudioFloatConverter/ToFloatArray.java	Sun Sep 14 23:15:43 2008
+++ new/test/javax/sound/midi/Gervill/AudioFloatConverter/ToFloatArray.java	Sun Sep 14 23:15:43 2008
@@ -43,11 +43,30 @@
 			testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
 			testarray[i] *= 0.3;
 		}		
+        
+        // Check conversion using PCM_FLOAT
+        for (int big = 0; big < 2; big+=1)
+        for (int bits = 32; bits <= 64; bits+=32) {
+            AudioFormat frm = new AudioFormat(
+                    AudioFloatConverter.PCM_FLOAT,
+                    44100, bits, 1, bits/8,
+                    44100, big==1);
+            byte[] buff = new byte[testarray.length * frm.getFrameSize()];
+            float[] testarray2 = new float[testarray.length];
+            AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
+            conv.toByteArray(testarray, buff);
+            conv.toFloatArray(buff, testarray2);
+            for (int i = 0; i < testarray2.length; i++) {
+                if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
+                    throw new RuntimeException("Conversion failed for " + frm  +" , arrays not equal enough!\n");
+            }               
+            
+        }
 		
 		// Check conversion from float2byte and byte2float.
 		for (int big = 0; big < 2; big+=1) 
 		for (int signed = 0; signed < 2; signed+=1) 
-		for (int bits = 8; bits <= 32; bits+=8) {					
+		for (int bits = 6; bits <= 40; bits+=2) {					
 			AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
 			byte[] buff = new byte[testarray.length * frm.getFrameSize()];
 			float[] testarray2 = new float[testarray.length];
@@ -63,7 +82,7 @@
 		// Check big/little
 		for (int big = 0; big < 2; big+=1) 
 		for (int signed = 0; signed < 2; signed+=1)
-		for (int bits = 8; bits <= 32; bits+=8) {					
+		for (int bits = 6; bits <= 40; bits+=2) {					
 			AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
 			byte[] buff = new byte[testarray.length * frm.getFrameSize()];
 			AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
@@ -89,7 +108,7 @@
 		// Check signed/unsigned 
 		for (int big = 0; big < 2; big+=1) 
 		for (int signed = 0; signed < 2; signed+=1)
-		for (int bits = 8; bits <= 32; bits+=8) {					
+		for (int bits = 6; bits <= 40; bits+=2) {					
 			AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
 			byte[] b = new byte[testarray.length * frm.getFrameSize()];
 			AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
@@ -117,10 +136,10 @@
 		}
 		
 		// Check if conversion 32->24, 24->16, 16->8 result in same float data
-		AudioFormat frm = new AudioFormat(44100, 32, 1, true, true);
+		AudioFormat frm = new AudioFormat(44100, 40, 1, true, true);
 		byte[] b = new byte[testarray.length * frm.getFrameSize()];
 		AudioFloatConverter.getConverter(frm).toByteArray(testarray, b);
-		for (int bits = 8; bits <= 32; bits+=8) {
+		for (int bits = 6; bits <= 40; bits+=2) {
 			AudioFormat frm2 = new AudioFormat(44100, bits, 1, true, true);
 			byte[] b2 = new byte[testarray.length * frm2.getFrameSize()];
 			int fs1 = frm.getFrameSize();
--- /dev/null	Sun Sep 14 23:15:44 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Available.java	Sun Sep 14 23:15:44 2008
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream available() method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class Available {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                                     
+                    int ret = is.available();
+                    if(ret != capacity)
+                        throw new RuntimeException("is.available() return unexpected value!");
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:44 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Close.java	Sun Sep 14 23:15:44 2008
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream close method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class Close {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                    
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:45 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkReset.java	Sun Sep 14 23:15:44 2008
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream mark and reset methods */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class MarkReset {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                
+                    is.mark(1000);
+                    int ret = is.available();
+                    int a = is.read();
+                    is.skip(75);                          
+                    is.reset();
+                    if(is.available() != ret)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret)+") !");
+                    int b = is.read();
+                    if(a != b)
+                        throw new RuntimeException(
+                                "is doesn't return same value after reset ("
+                                + a + "!="+b+") !");
+                    
+                    is.skip(15);        
+                    ret = is.available();
+                    is.mark(1000);
+                    is.reset();
+                    if(is.available() != ret)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret)+") !");
+                   
+                    
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:45 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkSupported.java	Sun Sep 14 23:15:45 2008
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream markSupported() method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class MarkSupported {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {               
+                    if(!is.markSupported())
+                        throw new RuntimeException("InputStream doesn't support mark/reset!");
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:45 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Read.java	Sun Sep 14 23:15:45 2008
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream read() method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class Read {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                 
+                    byte[] b = new byte[100];
+                    int ret = is.available();
+                    int n = is.read();
+                    if(n == -1)                    
+                        throw new RuntimeException("is.read shouldn't return -1!");
+                    if(is.available() != ret - 1)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - 1)+") !");
+                    is.skip(5000);
+                    if(is.read() != -1)
+                        throw new RuntimeException(
+                                "is.read() doesn't return -1!");
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:45 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByte.java	Sun Sep 14 23:15:45 2008
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream read(byte[]) method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class ReadByte {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                 
+                    byte[] b = new byte[100];
+                    int ret = is.available();
+                    int n = is.read(b);
+                    if(n == -1)                    
+                        throw new RuntimeException("is.read shouldn't return -1!");
+                    if(is.available() != ret - n)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - n)+") !");
+                    is.skip(5000);
+                    if(is.read(b) != -1)
+                        throw new RuntimeException(
+                                "is.read() doesn't return -1!");
+                    
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:45 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByteIntInt.java	Sun Sep 14 23:15:45 2008
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream read(byte[], int, int) method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class ReadByteIntInt {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                 
+                    byte[] b = new byte[100];
+                    int ret = is.available();
+                    int n = is.read(b, 7, 50);
+                    if(n == -1)                    
+                        throw new RuntimeException("is.read shouldn't return -1!");
+                    if(is.available() != ret - n)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - n)+") !");
+                    is.skip(5000);
+                    if(is.read(b, 7, 50) != -1)
+                        throw new RuntimeException(
+                                "is.read() doesn't return -1!");
+                    
+                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}
--- /dev/null	Sun Sep 14 23:15:46 2008
+++ new/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Skip.java	Sun Sep 14 23:15:46 2008
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @summary Test ModelByteBuffer.RandomFileInputStream skip(long) method */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.*;
+
+import com.sun.media.sound.*;
+
+public class Skip {
+
+    static float[] testarray;
+    static byte[] test_byte_array;  
+    static File test_file;
+    static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
+    
+    static void setUp() throws Exception {
+        testarray = new float[1024];
+        for (int i = 0; i < 1024; i++) {
+            double ii = i / 1024.0;
+            ii = ii * ii;
+            testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
+            testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
+            testarray[i] *= 0.3;
+        }       
+        test_byte_array = new byte[testarray.length*2];
+        AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
+        test_file = File.createTempFile("test", ".raw");
+        FileOutputStream fos = new FileOutputStream(test_file);
+        fos.write(test_byte_array);
+    }   
+    
+    static void tearDown() throws Exception {
+        if(!test_file.delete())
+            test_file.deleteOnExit();
+    }           
+    
+    public static void main(String[] args) throws Exception {
+        try
+        {
+            setUp();
+            
+            for (int i = 0; i < 8; i++) {
+                ModelByteBuffer buff;
+                if(i % 2 == 0)
+                    buff = new ModelByteBuffer(test_file);
+                else
+                    buff = new ModelByteBuffer(test_byte_array);
+                if((i / 2) == 1)
+                    buff.subbuffer(5);
+                if((i / 2) == 2)
+                    buff.subbuffer(5,500);
+                if((i / 2) == 3)
+                    buff.subbuffer(5,600,true);
+                
+                long capacity = buff.capacity();
+                InputStream is = buff.getInputStream();
+                try
+                {                 
+                    int ret = is.available();
+                    long n = is.skip(75);
+                    if(n == -1)                    
+                        throw new RuntimeException("is.read shouldn't return -1!");
+                    if(is.available() != ret - n)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - n)+") !");
+                    
+                    ret = is.available();
+                    n = is.skip(-100);
+                    if(n != 0)                    
+                        throw new RuntimeException("is.skip(-100) shouldn't skip values!");
+                    if(is.available() != ret - n)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - n)+") !");
+
+                    ret = is.available();
+                    n = is.skip(5000);
+                    if(is.available() != ret - n)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(ret - n)+") !");
+                    if(is.available() != 0)
+                        throw new RuntimeException(
+                                "is.available() returns incorrect value ("
+                                + is.available() + "!="+(0)+") !");                }
+                finally
+                {
+                    is.close();
+                }
+                if(buff.capacity() != capacity)
+                    throw new RuntimeException("Capacity variable should not change!");                
+            }           
+        }
+        finally
+        {
+            tearDown();
+        }       
+    }
+
+}





More information about the audio-engine-dev mailing list