< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/UlawCodec.java

Print this page

        

@@ -31,11 +31,10 @@
 
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 
-
 /**
  * U-law encodes linear data, and decodes u-law data to linear data.
  *
  * @author Kara Kytle
  */

@@ -51,11 +50,11 @@
 
     private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
                                              0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
 
     /**
-     * Initializes the decode tables
+     * Initializes the decode tables.
      */
     static {
         for (int i=0;i<256;i++) {
             int ulaw = ~i;
             int t;

@@ -68,20 +67,18 @@
             ULAW_TABL[i] = (byte) (t&0xff);
             ULAW_TABH[i] = (byte) ((t>>8) & 0xff);
         }
     }
 
-
     /**
      * Constructs a new ULAW codec object.
      */
     public UlawCodec() {
         super(ulawEncodings, ulawEncodings);
     }
 
-    /**
-     */
+    @Override
     public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat){
         if( AudioFormat.Encoding.PCM_SIGNED.equals(sourceFormat.getEncoding()) ) {
             if( sourceFormat.getSampleSizeInBits() == 16 ) {
                 AudioFormat.Encoding enc[] = new AudioFormat.Encoding[1];
                 enc[0] = AudioFormat.Encoding.ULAW;

@@ -100,13 +97,11 @@
         } else {
             return new AudioFormat.Encoding[0];
         }
     }
 
-
-    /**
-     */
+    @Override
     public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
         Objects.requireNonNull(targetEncoding);
         Objects.requireNonNull(sourceFormat);
         if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding)
              && AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding()))

@@ -117,12 +112,11 @@
             } else {
                 return new AudioFormat[0];
             }
     }
 
-    /**
-     */
+    @Override
     public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream){
         AudioFormat sourceFormat = sourceStream.getFormat();
         AudioFormat.Encoding sourceEncoding = sourceFormat.getEncoding();
 
         if (!isConversionSupported(targetEncoding,sourceStream.getFormat())) {

@@ -155,42 +149,36 @@
         }
 
         return getConvertedStream(targetFormat, sourceStream);
     }
 
-    /**
-     * use old code...
-     */
+    @Override
     public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream){
         if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
             throw new IllegalArgumentException("Unsupported conversion: "
                                                + sourceStream.getFormat().toString() + " to "
                                                + targetFormat.toString());
         return getConvertedStream(targetFormat, sourceStream);
     }
 
-
-    // OLD CODE
-
     /**
      * Opens the codec with the specified parameters.
      * @param stream stream from which data to be processed should be read
      * @param outputFormat desired data format of the stream after processing
      * @return stream from which processed data may be read
      * @throws IllegalArgumentException if the format combination supplied is
      * not supported.
      */
-    /*  public AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) { */
     private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) {
         AudioInputStream cs = null;
 
         AudioFormat inputFormat = stream.getFormat();
 
         if( inputFormat.matches(outputFormat) ) {
             cs = stream;
         } else {
-            cs = (AudioInputStream) (new UlawCodecStream(stream, outputFormat));
+            cs = new UlawCodecStream(stream, outputFormat);
         }
         return cs;
     }
 
     /**

@@ -198,11 +186,10 @@
      * given a particular input format.
      * If no output formats are supported for this input format,
      * returns an array of length 0.
      * @return array of supported output formats.
      */
-    /*  public AudioFormat[] getOutputFormats(AudioFormat inputFormat) { */
     private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
 
         Vector<AudioFormat> formats = new Vector<>();
         AudioFormat format;
 

@@ -239,18 +226,17 @@
             formatArray[i] = formats.elementAt(i);
         }
         return formatArray;
     }
 
-
     private final class UlawCodecStream extends AudioInputStream {
 
         private static final int tempBufferSize = 64;
         private byte tempBuffer [] = null;
 
         /**
-         * True to encode to u-law, false to decode to linear
+         * True to encode to u-law, false to decode to linear.
          */
         boolean encode = false;
 
         AudioFormat encodeFormat;
         AudioFormat decodeFormat;

@@ -310,11 +296,10 @@
             if (frameSize == AudioSystem.NOT_SPECIFIED) {
                 frameSize = 1;
             }
         }
 
-
         /*
          * $$jb 2/23/99
          * Used to determine segment number in uLaw encoding
          */
         private short search(short val, short table[], short size) {

@@ -326,22 +311,25 @@
 
         /**
          * Note that this won't actually read anything; must read in
          * two-byte units.
          */
+        @Override
         public int read() throws IOException {
             byte[] b = new byte[1];
             if (read(b, 0, b.length) == 1) {
                 return b[1] & 0xFF;
             }
             return -1;
         }
 
+        @Override
         public int read(byte[] b) throws IOException {
             return read(b, 0, b.length);
         }
 
+        @Override
         public int read(byte[] b, int off, int len) throws IOException {
             // don't read fractional frames
             if( len%frameSize != 0 ) {
                 len -= (len%frameSize);
             }
< prev index next >