< prev index next >

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

Print this page




  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 javax.sound.sampled.AudioFileFormat;
  29 import javax.sound.sampled.AudioFormat;
  30 
  31 /**
  32  * AU file format.
  33  *
  34  * @author Jan Borgersen
  35  */
  36 final class AuFileFormat extends AudioFileFormat {
  37 
  38     // magic numbers
  39     static final int AU_SUN_MAGIC = 0x2e736e64; // ".snd"
  40 
  41     // encodings
  42     static final int AU_ULAW_8       = 1;  /* 8-bit ISDN u-law */
  43     static final int AU_LINEAR_8     = 2;  /* 8-bit linear PCM */
  44     static final int AU_LINEAR_16    = 3;  /* 16-bit linear PCM */
  45     static final int AU_LINEAR_24    = 4;  /* 24-bit linear PCM */
  46     static final int AU_LINEAR_32    = 5;  /* 32-bit linear PCM */
  47     static final int AU_FLOAT        = 6;  /* 32-bit IEEE floating point */
  48 //  we don't support these ...
  49 //  static final int AU_DOUBLE       = 7;  /* 64-bit IEEE floating point */
  50 //  static final int AU_ADPCM_G721   = 23; /* 4-bit CCITT g.721 ADPCM */
  51 //  static final int AU_ADPCM_G722   = 24; /* CCITT g.722 ADPCM */
  52 //  static final int AU_ADPCM_G723_3 = 25; /* CCITT g.723 3-bit ADPCM */
  53 //  static final int AU_ADPCM_G723_5 = 26; /* CCITT g.723 5-bit ADPCM */
  54     static final int AU_ALAW_8       = 27; /* 8-bit ISDN A-law */
  55 
  56     static final int AU_HEADERSIZE       = 24;
  57 
  58     private int auType;





  59 
  60     AuFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) {
  61 
  62         super(type,lengthInBytes,format,lengthInFrames);


  63 
  64         AudioFormat.Encoding encoding = format.getEncoding();
  65 
  66         auType = -1;
  67 
  68         if (AudioFormat.Encoding.ALAW.equals(encoding)) {
  69             if (format.getSampleSizeInBits() == 8) {
  70                 auType = AU_ALAW_8;
  71             }
  72         } else if (AudioFormat.Encoding.ULAW.equals(encoding)) {
  73             if (format.getSampleSizeInBits() == 8) {
  74                 auType = AU_ULAW_8;
  75             }
  76         } else if (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) {
  77             if (format.getSampleSizeInBits() == 8) {
  78                 auType = AU_LINEAR_8;
  79             } else if (format.getSampleSizeInBits() == 16) {
  80                 auType = AU_LINEAR_16;
  81             } else if (format.getSampleSizeInBits() == 24) {
  82                 auType = AU_LINEAR_24;


  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 javax.sound.sampled.AudioFileFormat;
  29 import javax.sound.sampled.AudioFormat;
  30 
  31 /**
  32  * AU file format.
  33  *
  34  * @author Jan Borgersen
  35  */
  36 final class AuFileFormat extends StandardFileFormat {
  37 
  38     // magic numbers
  39     static final int AU_SUN_MAGIC = 0x2e736e64; // ".snd"
  40 
  41     // encodings
  42     static final int AU_ULAW_8       = 1;  /* 8-bit ISDN u-law */
  43     static final int AU_LINEAR_8     = 2;  /* 8-bit linear PCM */
  44     static final int AU_LINEAR_16    = 3;  /* 16-bit linear PCM */
  45     static final int AU_LINEAR_24    = 4;  /* 24-bit linear PCM */
  46     static final int AU_LINEAR_32    = 5;  /* 32-bit linear PCM */
  47     static final int AU_FLOAT        = 6;  /* 32-bit IEEE floating point */
  48 //  we don't support these ...
  49 //  static final int AU_DOUBLE       = 7;  /* 64-bit IEEE floating point */
  50 //  static final int AU_ADPCM_G721   = 23; /* 4-bit CCITT g.721 ADPCM */
  51 //  static final int AU_ADPCM_G722   = 24; /* CCITT g.722 ADPCM */
  52 //  static final int AU_ADPCM_G723_3 = 25; /* CCITT g.723 3-bit ADPCM */
  53 //  static final int AU_ADPCM_G723_5 = 26; /* CCITT g.723 5-bit ADPCM */
  54     static final int AU_ALAW_8       = 27; /* 8-bit ISDN A-law */
  55 
  56     static final int AU_HEADERSIZE       = 24;
  57 
  58     /**
  59      * According the specification of AU file format this is the value for
  60      * length field if length is not known. This is a maximum possible value for
  61      * the unsigned int.
  62      */
  63     static final long /*unsigned int */ UNKNOWN_SIZE = 0xffffffffL;
  64 
  65     private int auType;
  66 
  67     AuFileFormat(final AudioFileFormat.Type type, final long byteLength,
  68                  final AudioFormat format, final long frameLength) {
  69         super(type, byteLength, format, frameLength);
  70 
  71         AudioFormat.Encoding encoding = format.getEncoding();
  72 
  73         auType = -1;
  74 
  75         if (AudioFormat.Encoding.ALAW.equals(encoding)) {
  76             if (format.getSampleSizeInBits() == 8) {
  77                 auType = AU_ALAW_8;
  78             }
  79         } else if (AudioFormat.Encoding.ULAW.equals(encoding)) {
  80             if (format.getSampleSizeInBits() == 8) {
  81                 auType = AU_ULAW_8;
  82             }
  83         } else if (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) {
  84             if (format.getSampleSizeInBits() == 8) {
  85                 auType = AU_LINEAR_8;
  86             } else if (format.getSampleSizeInBits() == 16) {
  87                 auType = AU_LINEAR_16;
  88             } else if (format.getSampleSizeInBits() == 24) {
  89                 auType = AU_LINEAR_24;
< prev index next >