Java Code Examples for javax.sound.sampled.AudioFormat#Encoding
The following examples show how to use
javax.sound.sampled.AudioFormat#Encoding .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AiffFileWriter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) { AudioFileFormat.Type[] filetypes = new AudioFileFormat.Type[types.length]; System.arraycopy(types, 0, filetypes, 0, types.length); // make sure we can write this stream AudioFormat format = stream.getFormat(); AudioFormat.Encoding encoding = format.getEncoding(); if( (AudioFormat.Encoding.ALAW.equals(encoding)) || (AudioFormat.Encoding.ULAW.equals(encoding)) || (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) || (AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)) ) { return filetypes; } return new AudioFileFormat.Type[0]; }
Example 2
Source File: AuFileFormat.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
AuFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) { super(type,lengthInBytes,format,lengthInFrames); AudioFormat.Encoding encoding = format.getEncoding(); auType = -1; if( AudioFormat.Encoding.ALAW.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_ALAW_8; } } else if( AudioFormat.Encoding.ULAW.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_ULAW_8; } } else if( AudioFormat.Encoding.PCM_SIGNED.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_LINEAR_8; } else if( format.getSampleSizeInBits()==16 ) { auType = AU_LINEAR_16; } else if( format.getSampleSizeInBits()==24 ) { auType = AU_LINEAR_24; } else if( format.getSampleSizeInBits()==32 ) { auType = AU_LINEAR_32; } } }
Example 3
Source File: UlawCodec.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** */ public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding) && AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding())) || (AudioFormat.Encoding.ULAW.equals(targetEncoding) && AudioFormat.Encoding.PCM_SIGNED.equals(sourceFormat.getEncoding()))) { return getOutputFormats(sourceFormat); } else { return new AudioFormat[0]; } }
Example 4
Source File: AuFileFormat.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
AuFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) { super(type,lengthInBytes,format,lengthInFrames); AudioFormat.Encoding encoding = format.getEncoding(); auType = -1; if( AudioFormat.Encoding.ALAW.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_ALAW_8; } } else if( AudioFormat.Encoding.ULAW.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_ULAW_8; } } else if( AudioFormat.Encoding.PCM_SIGNED.equals(encoding) ) { if( format.getSampleSizeInBits()==8 ) { auType = AU_LINEAR_8; } else if( format.getSampleSizeInBits()==16 ) { auType = AU_LINEAR_16; } else if( format.getSampleSizeInBits()==24 ) { auType = AU_LINEAR_24; } else if( format.getSampleSizeInBits()==32 ) { auType = AU_LINEAR_32; } } }
Example 5
Source File: UlawCodec.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** */ public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding) && AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding())) || (AudioFormat.Encoding.ULAW.equals(targetEncoding) && AudioFormat.Encoding.PCM_SIGNED.equals(sourceFormat.getEncoding()))) { return getOutputFormats(sourceFormat); } else { return new AudioFormat[0]; } }
Example 6
Source File: FormatConversionProvider.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
/** * Indicates whether the format converter supports conversion to a particular encoding * from a particular format. * @param targetEncoding desired encoding of the outgoing data * @param sourceFormat format of the incoming data * @return <code>true</code> if the conversion is supported, otherwise <code>false</code> */ public boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ AudioFormat.Encoding targetEncodings[] = getTargetEncodings(sourceFormat); for(int i=0; i<targetEncodings.length; i++) { if( targetEncoding.equals( targetEncodings[i]) ) { return true; } } return false; }
Example 7
Source File: FormatConversionProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Indicates whether the format converter supports conversion to a particular encoding * from a particular format. * @param targetEncoding desired encoding of the outgoing data * @param sourceFormat format of the incoming data * @return <code>true</code> if the conversion is supported, otherwise <code>false</code> */ public boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){ AudioFormat.Encoding targetEncodings[] = getTargetEncodings(sourceFormat); for(int i=0; i<targetEncodings.length; i++) { if( targetEncoding.equals( targetEncodings[i]) ) { return true; } } return false; }
Example 8
Source File: AlawCodec.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public AudioFormat.Encoding[] getTargetEncodings() { return getSourceEncodings(); }
Example 9
Source File: PCMtoPCMCodec.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
PCMtoPCMCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); int sampleSizeInBits = 0; AudioFormat.Encoding inputEncoding = null; AudioFormat.Encoding outputEncoding = null; boolean inputIsBigEndian; boolean outputIsBigEndian; AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(inputFormat, outputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } inputEncoding = inputFormat.getEncoding(); outputEncoding = outputFormat.getEncoding(); inputIsBigEndian = inputFormat.isBigEndian(); outputIsBigEndian = outputFormat.isBigEndian(); sampleSizeInBits = inputFormat.getSampleSizeInBits(); sampleSizeInBytes = sampleSizeInBits/8; // determine conversion to perform if( sampleSizeInBits==8 ) { if( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) ) { conversionType = PCM_SWITCH_SIGNED_8BIT; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_SIGNED_8BIT"); } else if( AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) ) { conversionType = PCM_SWITCH_SIGNED_8BIT; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_SIGNED_8BIT"); } } else { if( inputEncoding.equals(outputEncoding) && (inputIsBigEndian != outputIsBigEndian) ) { conversionType = PCM_SWITCH_ENDIAN; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_ENDIAN"); } else if (AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && !inputIsBigEndian && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) && outputIsBigEndian) { conversionType = PCM_UNSIGNED_LE2SIGNED_BE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_UNSIGNED_LE2SIGNED_BE"); } else if (AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && !inputIsBigEndian && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) && outputIsBigEndian) { conversionType = PCM_SIGNED_LE2UNSIGNED_BE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SIGNED_LE2UNSIGNED_BE"); } else if (AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && inputIsBigEndian && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) && !outputIsBigEndian) { conversionType = PCM_UNSIGNED_BE2SIGNED_LE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_UNSIGNED_BE2SIGNED_LE"); } else if (AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && inputIsBigEndian && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) && !outputIsBigEndian) { conversionType = PCM_SIGNED_BE2UNSIGNED_LE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SIGNED_BE2UNSIGNED_LE"); } } // set the audio stream length in frames if we know it frameSize = inputFormat.getFrameSize(); if( frameSize == AudioSystem.NOT_SPECIFIED ) { frameSize=1; } if( stream instanceof AudioInputStream ) { frameLength = stream.getFrameLength(); } else { frameLength = AudioSystem.NOT_SPECIFIED; } // set framePos to zero framePos = 0; }
Example 10
Source File: PCMtoPCMCodec.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
PCMtoPCMCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); int sampleSizeInBits = 0; AudioFormat.Encoding inputEncoding = null; AudioFormat.Encoding outputEncoding = null; boolean inputIsBigEndian; boolean outputIsBigEndian; AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(inputFormat, outputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } inputEncoding = inputFormat.getEncoding(); outputEncoding = outputFormat.getEncoding(); inputIsBigEndian = inputFormat.isBigEndian(); outputIsBigEndian = outputFormat.isBigEndian(); sampleSizeInBits = inputFormat.getSampleSizeInBits(); sampleSizeInBytes = sampleSizeInBits/8; // determine conversion to perform if( sampleSizeInBits==8 ) { if( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) ) { conversionType = PCM_SWITCH_SIGNED_8BIT; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_SIGNED_8BIT"); } else if( AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) ) { conversionType = PCM_SWITCH_SIGNED_8BIT; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_SIGNED_8BIT"); } } else { if( inputEncoding.equals(outputEncoding) && (inputIsBigEndian != outputIsBigEndian) ) { conversionType = PCM_SWITCH_ENDIAN; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SWITCH_ENDIAN"); } else if (AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && !inputIsBigEndian && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) && outputIsBigEndian) { conversionType = PCM_UNSIGNED_LE2SIGNED_BE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_UNSIGNED_LE2SIGNED_BE"); } else if (AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && !inputIsBigEndian && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) && outputIsBigEndian) { conversionType = PCM_SIGNED_LE2UNSIGNED_BE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SIGNED_LE2UNSIGNED_BE"); } else if (AudioFormat.Encoding.PCM_UNSIGNED.equals(inputEncoding) && inputIsBigEndian && AudioFormat.Encoding.PCM_SIGNED.equals(outputEncoding) && !outputIsBigEndian) { conversionType = PCM_UNSIGNED_BE2SIGNED_LE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_UNSIGNED_BE2SIGNED_LE"); } else if (AudioFormat.Encoding.PCM_SIGNED.equals(inputEncoding) && inputIsBigEndian && AudioFormat.Encoding.PCM_UNSIGNED.equals(outputEncoding) && !outputIsBigEndian) { conversionType = PCM_SIGNED_BE2UNSIGNED_LE; if(Printer.debug) Printer.debug("PCMtoPCMCodecStream: conversionType = PCM_SIGNED_BE2UNSIGNED_LE"); } } // set the audio stream length in frames if we know it frameSize = inputFormat.getFrameSize(); if( frameSize == AudioSystem.NOT_SPECIFIED ) { frameSize=1; } if( stream instanceof AudioInputStream ) { frameLength = stream.getFrameLength(); } else { frameLength = AudioSystem.NOT_SPECIFIED; } // set framePos to zero framePos = 0; }
Example 11
Source File: FormatConversionProvider.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Obtains the set of target format encodings to which format * conversion services are provided by this provider. * @return array of target format encodings. If for some reason provider * does not provide any conversion services, an array of length 0 is * returned. */ public abstract AudioFormat.Encoding[] getTargetEncodings();
Example 12
Source File: FormatConversionProvider.java From jdk8u_jdk with GNU General Public License v2.0 | 2 votes |
/** * Obtains the set of target format encodings to which format * conversion services are provided by this provider. * @return array of target format encodings. If for some reason provider * does not provide any conversion services, an array of length 0 is * returned. */ public abstract AudioFormat.Encoding[] getTargetEncodings();
Example 13
Source File: FormatConversionProvider.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Obtains an audio input stream with the specified encoding from the given audio * input stream. * @param targetEncoding desired encoding of the stream after processing * @param sourceStream stream from which data to be processed should be read * @return stream from which processed data with the specified target encoding may be read * @throws IllegalArgumentException if the format combination supplied is * not supported. */ public abstract AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream);
Example 14
Source File: SunCodec.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** */ public abstract AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat);
Example 15
Source File: FormatConversionProvider.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * Obtains the set of target formats with the encoding specified * supported by the format converter * If no target formats with the specified encoding are supported * for this source format, an array of length 0 is returned. * @param targetEncoding desired encoding of the stream after processing * @param sourceFormat format of the incoming data * @return array of supported target formats. */ public abstract AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat);
Example 16
Source File: FormatConversionProvider.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
/** * Obtains an audio input stream with the specified encoding from the given audio * input stream. * @param targetEncoding desired encoding of the stream after processing * @param sourceStream stream from which data to be processed should be read * @return stream from which processed data with the specified target encoding may be read * @throws IllegalArgumentException if the format combination supplied is * not supported. */ public abstract AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream);
Example 17
Source File: FormatConversionProvider.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Obtains the set of target format encodings supported by the format converter * given a particular source format. * If no target format encodings are supported for this source format, * an array of length 0 is returned. * @param sourceFormat format of the incoming data * @return array of supported target format encodings. */ public abstract AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat);
Example 18
Source File: FormatConversionProvider.java From jdk1.8-source-analysis with Apache License 2.0 | 2 votes |
/** * Obtains the set of target formats with the encoding specified * supported by the format converter * If no target formats with the specified encoding are supported * for this source format, an array of length 0 is returned. * @param targetEncoding desired encoding of the stream after processing * @param sourceFormat format of the incoming data * @return array of supported target formats. */ public abstract AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat);
Example 19
Source File: FormatConversionProvider.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Obtains the set of source format encodings from which format * conversion services are provided by this provider. * @return array of source format encodings. If for some reason provider * does not provide any conversion services, an array of length 0 is * returned. */ public abstract AudioFormat.Encoding[] getSourceEncodings();
Example 20
Source File: FormatConversionProvider.java From JDKSourceCode1.8 with MIT License | 2 votes |
/** * Obtains the set of target formats with the encoding specified * supported by the format converter * If no target formats with the specified encoding are supported * for this source format, an array of length 0 is returned. * @param targetEncoding desired encoding of the stream after processing * @param sourceFormat format of the incoming data * @return array of supported target formats. */ public abstract AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat);