< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import java.io.IOException;
  29 

  30 import java.util.Vector;
  31 
  32 import javax.sound.sampled.AudioFormat;
  33 import javax.sound.sampled.AudioSystem;
  34 import javax.sound.sampled.AudioInputStream;
  35 
  36 
  37 /**
  38  * U-law encodes linear data, and decodes u-law data to linear data.
  39  *
  40  * @author Kara Kytle
  41  */
  42 public final class UlawCodec extends SunCodec {
  43 
  44     /* Tables used for U-law decoding */
  45 
  46     private final static byte[] ULAW_TABH = new byte[256];
  47     private final static byte[] ULAW_TABL = new byte[256];
  48 
  49     private static final AudioFormat.Encoding[] ulawEncodings = {AudioFormat.Encoding.ULAW,


  89             } else {
  90                 return new AudioFormat.Encoding[0];
  91             }
  92         } else if (AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding())) {
  93             if (sourceFormat.getSampleSizeInBits() == 8) {
  94                 AudioFormat.Encoding enc[] = new AudioFormat.Encoding[1];
  95                 enc[0] = AudioFormat.Encoding.PCM_SIGNED;
  96                 return enc;
  97             } else {
  98                 return new AudioFormat.Encoding[0];
  99             }
 100         } else {
 101             return new AudioFormat.Encoding[0];
 102         }
 103     }
 104 
 105 
 106     /**
 107      */
 108     public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){


 109         if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding)
 110              && AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding()))
 111             ||
 112             (AudioFormat.Encoding.ULAW.equals(targetEncoding)
 113              && AudioFormat.Encoding.PCM_SIGNED.equals(sourceFormat.getEncoding()))) {
 114                 return getOutputFormats(sourceFormat);
 115             } else {
 116                 return new AudioFormat[0];
 117             }
 118     }
 119 
 120     /**
 121      */
 122     public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream){
 123         AudioFormat sourceFormat = sourceStream.getFormat();
 124         AudioFormat.Encoding sourceEncoding = sourceFormat.getEncoding();
 125 
 126         if (sourceEncoding.equals(targetEncoding)) {
 127             return sourceStream;
 128         } else {


   1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import java.io.IOException;
  29 
  30 import java.util.Objects;
  31 import java.util.Vector;
  32 
  33 import javax.sound.sampled.AudioFormat;
  34 import javax.sound.sampled.AudioSystem;
  35 import javax.sound.sampled.AudioInputStream;
  36 
  37 
  38 /**
  39  * U-law encodes linear data, and decodes u-law data to linear data.
  40  *
  41  * @author Kara Kytle
  42  */
  43 public final class UlawCodec extends SunCodec {
  44 
  45     /* Tables used for U-law decoding */
  46 
  47     private final static byte[] ULAW_TABH = new byte[256];
  48     private final static byte[] ULAW_TABL = new byte[256];
  49 
  50     private static final AudioFormat.Encoding[] ulawEncodings = {AudioFormat.Encoding.ULAW,


  90             } else {
  91                 return new AudioFormat.Encoding[0];
  92             }
  93         } else if (AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding())) {
  94             if (sourceFormat.getSampleSizeInBits() == 8) {
  95                 AudioFormat.Encoding enc[] = new AudioFormat.Encoding[1];
  96                 enc[0] = AudioFormat.Encoding.PCM_SIGNED;
  97                 return enc;
  98             } else {
  99                 return new AudioFormat.Encoding[0];
 100             }
 101         } else {
 102             return new AudioFormat.Encoding[0];
 103         }
 104     }
 105 
 106 
 107     /**
 108      */
 109     public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
 110         Objects.requireNonNull(targetEncoding);
 111         Objects.requireNonNull(sourceFormat);
 112         if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding)
 113              && AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding()))
 114             ||
 115             (AudioFormat.Encoding.ULAW.equals(targetEncoding)
 116              && AudioFormat.Encoding.PCM_SIGNED.equals(sourceFormat.getEncoding()))) {
 117                 return getOutputFormats(sourceFormat);
 118             } else {
 119                 return new AudioFormat[0];
 120             }
 121     }
 122 
 123     /**
 124      */
 125     public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream){
 126         AudioFormat sourceFormat = sourceStream.getFormat();
 127         AudioFormat.Encoding sourceEncoding = sourceFormat.getEncoding();
 128 
 129         if (sourceEncoding.equals(targetEncoding)) {
 130             return sourceStream;
 131         } else {


< prev index next >