/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A-law encodes linear data, and decodes a-law data to linear data.
*
* @author Kara Kytle
*/
/* Tables used for A-law decoding */
private static final AudioFormat.Encoding[] alawEncodings = { AudioFormat.Encoding.ALAW, AudioFormat.Encoding.PCM_SIGNED };
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
/**
* Initializes the decode tables
*/
static {
for (int i=0;i<256;i++) {
int input = i ^ 0x55;
if(segment>=1)
value+=0x100;
if(segment>1)
}
}
/**
* Constructs a new ALAW codec object.
*/
public AlawCodec() {
super(alawEncodings, alawEncodings);
}
// NEW CODE
/**
*/
return enc;
} else {
}
return enc;
} else {
}
} else {
}
}
/**
*/
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
if( (targetEncoding.equals( AudioFormat.Encoding.PCM_SIGNED ) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.ALAW)) ||
(targetEncoding.equals( AudioFormat.Encoding.ALAW) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED)) ) {
return getOutputFormats( sourceFormat );
} else {
return new AudioFormat[0];
}
}
/**
*/
public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream){
return sourceStream;
} else {
throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString());
}
16,
8,
false);
} else {
throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString());
}
}
}
/**
* use old code...
*/
public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream 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) { */
} else {
}
return cs;
}
/**
* Obtains the set of output formats supported by the codec
* 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) { */
8,
false );
}
16,
false );
16,
true );
}
}
return formatArray;
}
// tempBuffer required only for encoding (when encode is true)
/**
* True to encode to a-law, false to decode to linear
*/
boolean encode = false;
// throw an IllegalArgumentException if not ok
throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString());
}
//$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness
boolean PCMIsBigEndian;
// determine whether we are encoding or decoding
encode = false;
} else {
encode = true;
tempBuffer = new byte[tempBufferSize];
}
if (PCMIsBigEndian) {
highByte = 0;
lowByte = 1;
} else {
highByte = 1;
lowByte = 0;
}
// set the AudioInputStream length in frames if we know it
if (stream instanceof AudioInputStream) {
}
// set framePos to zero
framePos = 0;
frameSize=1;
}
}
/*
* $$jb 2/23/99
* Used to determine segment number in aLaw encoding
*/
for(short i = 0; i < size; i++) {
}
return size;
}
/**
* Note that this won't actually read anything; must read in
* two-byte units.
*/
byte[] b = new byte[1];
}
}
// don't read fractional frames
}
if (encode) {
short QUANT_MASK = 0xF;
short SEG_SHIFT = 4;
short mask;
short seg;
int adj;
int i;
short sample;
byte enc;
int readCount = 0;
int currentPos = off;
/* Get the sample from the tempBuffer */
if(sample >= 0) {
mask = 0xD5;
} else {
mask = 0x55;
}
/* Convert the scaled magnitude to segment number. */
/*
* Combine the sign, segment, quantization bits
*/
} else {
if(seg < 2) {
} else {
}
}
/* Now put the encoded sample where it belongs */
b[currentPos] = enc;
currentPos++;
}
/* And update pointers and counters for next iteration */
}
return readCount;
}
} else {
int i;
readOffset++;
}
return readCount;
}
return (i - off);
}
}
} // end class AlawCodecStream
} // end class ALAW