< prev index next >

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

Print this page

        

*** 38,48 **** * * @author Jan Borgersen */ public final class PCMtoPCMCodec extends SunCodec { - private static final AudioFormat.Encoding[] inputEncodings = { AudioFormat.Encoding.PCM_SIGNED, AudioFormat.Encoding.PCM_UNSIGNED, }; --- 38,47 ----
*** 57,68 **** public PCMtoPCMCodec() { super( inputEncodings, outputEncodings); } ! // NEW CODE ! public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) { final int sampleSize = sourceFormat.getSampleSizeInBits(); AudioFormat.Encoding encoding = sourceFormat.getEncoding(); if (sampleSize == 8) { --- 56,66 ---- public PCMtoPCMCodec() { super( inputEncodings, outputEncodings); } ! @Override public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) { final int sampleSize = sourceFormat.getSampleSizeInBits(); AudioFormat.Encoding encoding = sourceFormat.getEncoding(); if (sampleSize == 8) {
*** 86,98 **** } } return new AudioFormat.Encoding[0]; } ! ! /** ! */ public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ Objects.requireNonNull(targetEncoding); // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method --- 84,94 ---- } } return new AudioFormat.Encoding[0]; } ! @Override public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ Objects.requireNonNull(targetEncoding); // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
*** 111,123 **** } return formatArray; } ! ! /** ! */ public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { if( isConversionSupported(targetEncoding, sourceStream.getFormat()) ) { AudioFormat sourceFormat = sourceStream.getFormat(); --- 107,117 ---- } return formatArray; } ! @Override public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { if( isConversionSupported(targetEncoding, sourceStream.getFormat()) ) { AudioFormat sourceFormat = sourceStream.getFormat();
*** 134,168 **** } else { throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString() ); } } ! /** ! * use old code ! */ 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(); --- 128,155 ---- } else { throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString() ); } } ! ! @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 ); } /** * 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. */ private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) { AudioInputStream cs = null; AudioFormat inputFormat = stream.getFormat();
*** 170,194 **** if( inputFormat.matches(outputFormat) ) { cs = stream; } else { ! cs = (AudioInputStream) (new PCMtoPCMCodecStream(stream, outputFormat)); } 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) { */ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) { Vector<AudioFormat> formats = new Vector<>(); AudioFormat format; --- 157,178 ---- if( inputFormat.matches(outputFormat) ) { cs = stream; } else { ! cs = new PCMtoPCMCodecStream(stream, outputFormat); } 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. */ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) { Vector<AudioFormat> formats = new Vector<>(); AudioFormat format;
*** 348,358 **** } return formatArray; } - class PCMtoPCMCodecStream extends AudioInputStream { private final int PCM_SWITCH_SIGNED_8BIT = 1; private final int PCM_SWITCH_ENDIAN = 2; private final int PCM_SWITCH_SIGNED_LE = 3; --- 332,341 ----
*** 458,468 **** /** * Note that this only works for sign conversions. * Other conversions require a read of at least 2 bytes. */ ! public int read() throws IOException { // $$jb: do we want to implement this function? int temp; --- 441,451 ---- /** * Note that this only works for sign conversions. * Other conversions require a read of at least 2 bytes. */ ! @Override public int read() throws IOException { // $$jb: do we want to implement this function? int temp;
*** 487,502 **** } else { throw new IOException("cannot read a single byte if frame size > 1"); } } ! public int read(byte[] b) throws IOException { return read(b, 0, b.length); } public int read(byte[] b, int off, int len) throws IOException { int i; --- 470,486 ---- } else { throw new IOException("cannot read a single byte if frame size > 1"); } } ! @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 { int i;
*** 587,597 **** b[i] = b[i+1]; b[i+1] = temp; } } } - - - } // end class PCMtoPCMCodecStream - } // end class PCMtoPCMCodec --- 571,577 ----
< prev index next >