< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/AlawCodec.java
Print this page
@@ -31,11 +31,10 @@
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
-
/**
* A-law encodes linear data, and decodes a-law data to linear data.
*
* @author Kara Kytle
*/
@@ -50,11 +49,11 @@
private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
/**
- * Initializes the decode tables
+ * Initializes the decode tables.
*/
static {
for (int i=0;i<256;i++) {
int input = i ^ 0x55;
int mantissa = (input & 0xf ) << 4;
@@ -81,14 +80,11 @@
public AlawCodec() {
super(alawEncodings, alawEncodings);
}
- // NEW CODE
-
- /**
- */
+ @Override
public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat){
if( sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED )) {
if( sourceFormat.getSampleSizeInBits() == 16 ) {
@@ -115,24 +111,22 @@
} else {
return new AudioFormat.Encoding[0];
}
}
- /**
- */
+ @Override
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
Objects.requireNonNull(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];
}
}
- /**
- */
+ @Override
public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream){
AudioFormat sourceFormat = sourceStream.getFormat();
AudioFormat.Encoding sourceEncoding = sourceFormat.getEncoding();
if( !isConversionSupported(targetEncoding,sourceStream.getFormat()) ) {
@@ -167,43 +161,36 @@
throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString());
}
return getConvertedStream(targetFormat, sourceStream);
}
- /**
- * use old code...
- */
+ @Override
public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream){
if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
throw new IllegalArgumentException("Unsupported conversion: "
+ sourceStream.getFormat().toString() + " to "
+ targetFormat.toString());
return getConvertedStream( targetFormat, 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) { */
private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) {
AudioInputStream cs = null;
AudioFormat inputFormat = stream.getFormat();
if( inputFormat.matches(outputFormat) ) {
cs = stream;
} else {
- cs = (AudioInputStream) (new AlawCodecStream(stream, outputFormat));
+ cs = new AlawCodecStream(stream, outputFormat);
}
return cs;
}
@@ -212,11 +199,10 @@
* 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) { */
private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
Vector<AudioFormat> formats = new Vector<>();
AudioFormat format;
@@ -341,22 +327,24 @@
/**
* Note that this won't actually read anything; must read in
* two-byte units.
*/
+ @Override
public int read() throws IOException {
byte[] b = new byte[1];
return read(b, 0, b.length);
}
-
+ @Override
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
+ @Override
public int read(byte[] b, int off, int len) throws IOException {
// don't read fractional frames
if( len%frameSize != 0 ) {
len -= (len%frameSize);
< prev index next >