jdk/src/share/classes/com/sun/media/sound/AuFileFormat.java
author amenkov
Mon, 28 Feb 2011 18:36:33 +0300
changeset 8525 08f98f5a11df
parent 5506 202f599c92aa
child 18215 b2afd66ce6db
permissions -rw-r--r--
7013521: AudioSystem.write for AIFF files closes source audio stream Reviewed-by: dav
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.media.sound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.sound.sampled.AudioFileFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.sound.sampled.AudioFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * AU file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Jan Borgersen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class AuFileFormat extends AudioFileFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    // magic numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static final int AU_SUN_MAGIC =     0x2e736e64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static final int AU_SUN_INV_MAGIC = 0x646e732e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final int AU_DEC_MAGIC =         0x2e736400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final int AU_DEC_INV_MAGIC = 0x0064732e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // encodings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final int AU_ULAW_8       = 1;  /* 8-bit ISDN u-law */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int AU_LINEAR_8     = 2;  /* 8-bit linear PCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final int AU_LINEAR_16    = 3;  /* 16-bit linear PCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final int AU_LINEAR_24    = 4;  /* 24-bit linear PCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final int AU_LINEAR_32    = 5;  /* 32-bit linear PCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int AU_FLOAT        = 6;  /* 32-bit IEEE floating point */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final int AU_DOUBLE       = 7;  /* 64-bit IEEE floating point */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static final int AU_ADPCM_G721   = 23; /* 4-bit CCITT g.721 ADPCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static final int AU_ADPCM_G722   = 24; /* CCITT g.722 ADPCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final int AU_ADPCM_G723_3 = 25; /* CCITT g.723 3-bit ADPCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static final int AU_ADPCM_G723_5 = 26; /* CCITT g.723 5-bit ADPCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static final int AU_ALAW_8       = 27; /* 8-bit ISDN A-law */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final int AU_HEADERSIZE       = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int auType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    AuFileFormat( AudioFileFormat aff ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this( aff.getType(), aff.getByteLength(), aff.getFormat(), aff.getFrameLength() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    AuFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(type,lengthInBytes,format,lengthInFrames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        AudioFormat.Encoding encoding = format.getEncoding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        auType = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if( AudioFormat.Encoding.ALAW.equals(encoding) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if( format.getSampleSizeInBits()==8 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                auType = AU_ALAW_8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } else if( AudioFormat.Encoding.ULAW.equals(encoding) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if( format.getSampleSizeInBits()==8 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                auType = AU_ULAW_8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } else if( AudioFormat.Encoding.PCM_SIGNED.equals(encoding) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            if( format.getSampleSizeInBits()==8 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                auType = AU_LINEAR_8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            } else if( format.getSampleSizeInBits()==16 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                auType = AU_LINEAR_16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            } else if( format.getSampleSizeInBits()==24 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                auType = AU_LINEAR_24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            } else if( format.getSampleSizeInBits()==32 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                auType = AU_LINEAR_32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public int getAuType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return auType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}