< prev index next >

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

Print this page


   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 import java.util.Objects;
  30 import java.util.Vector;
  31 
  32 import javax.sound.sampled.AudioFormat;

  33 import javax.sound.sampled.AudioInputStream;
  34 import javax.sound.sampled.AudioSystem;

  35 
  36 /**
  37  * Converts among signed/unsigned and little/big endianness of sampled.
  38  *
  39  * @author Jan Borgersen
  40  */
  41 public final class PCMtoPCMCodec extends SunCodec {
  42 
  43     private static final AudioFormat.Encoding[] inputEncodings = {
  44         AudioFormat.Encoding.PCM_SIGNED,
  45         AudioFormat.Encoding.PCM_UNSIGNED,
  46     };
  47 
  48     private static final AudioFormat.Encoding[] outputEncodings = {
  49         AudioFormat.Encoding.PCM_SIGNED,
  50         AudioFormat.Encoding.PCM_UNSIGNED,
  51     };
  52 
  53     /**
  54      * Constructs a new PCMtoPCM codec object.
  55      */
  56     public PCMtoPCMCodec() {
  57 
  58         super( inputEncodings, outputEncodings);


  59     }
  60 
  61     @Override
  62     public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
  63 
  64         final int sampleSize = sourceFormat.getSampleSizeInBits();
  65         AudioFormat.Encoding encoding = sourceFormat.getEncoding();
  66         if (sampleSize == 8) {
  67             if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) {
  68                 return new AudioFormat.Encoding[]{
  69                         AudioFormat.Encoding.PCM_UNSIGNED
  70                 };
  71             }
  72             if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
  73                 return new AudioFormat.Encoding[]{
  74                         AudioFormat.Encoding.PCM_SIGNED
  75                 };
  76             }
  77         } else if (sampleSize == 16) {
  78             if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)


   1 /*
   2  * Copyright (c) 1999, 2016, 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 import java.util.Objects;
  30 import java.util.Vector;
  31 
  32 import javax.sound.sampled.AudioFormat;
  33 import javax.sound.sampled.AudioFormat.Encoding;
  34 import javax.sound.sampled.AudioInputStream;
  35 import javax.sound.sampled.AudioSystem;
  36 import javax.sound.sampled.spi.FormatConversionProvider;
  37 
  38 /**
  39  * Converts among signed/unsigned and little/big endianness of sampled.
  40  *
  41  * @author Jan Borgersen
  42  */
  43 public final class PCMtoPCMCodec extends FormatConversionProvider {
  44 
  45     @Override
  46     public AudioFormat.Encoding[] getSourceEncodings() {
  47         return new Encoding[]{Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED};
  48     }










  49 
  50     @Override
  51     public AudioFormat.Encoding[] getTargetEncodings() {
  52         return getSourceEncodings();
  53     }
  54 
  55     @Override
  56     public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
  57 
  58         final int sampleSize = sourceFormat.getSampleSizeInBits();
  59         AudioFormat.Encoding encoding = sourceFormat.getEncoding();
  60         if (sampleSize == 8) {
  61             if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) {
  62                 return new AudioFormat.Encoding[]{
  63                         AudioFormat.Encoding.PCM_UNSIGNED
  64                 };
  65             }
  66             if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
  67                 return new AudioFormat.Encoding[]{
  68                         AudioFormat.Encoding.PCM_SIGNED
  69                 };
  70             }
  71         } else if (sampleSize == 16) {
  72             if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)


< prev index next >