Java Code Examples for javax.sound.sampled.AudioFormat#getEncoding()

The following examples show how to use javax.sound.sampled.AudioFormat#getEncoding() . 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: WaveFileFormat.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
WaveFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) {

        super(type,lengthInBytes,format,lengthInFrames);

        AudioFormat.Encoding encoding = format.getEncoding();

        if( encoding.equals(AudioFormat.Encoding.ALAW) ) {
            waveType = WAVE_FORMAT_ALAW;
        } else if( encoding.equals(AudioFormat.Encoding.ULAW) ) {
            waveType = WAVE_FORMAT_MULAW;
        } else if( encoding.equals(AudioFormat.Encoding.PCM_SIGNED) ||
                   encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED) ) {
            waveType = WAVE_FORMAT_PCM;
        } else {
            waveType = WAVE_FORMAT_UNKNOWN;
        }
    }
 
Example 2
Source File: AuFileWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: DirectAudioDevice.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected static AudioFormat getSignOrEndianChangedFormat(AudioFormat format) {
    boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
    boolean isUnsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
    if (format.getSampleSizeInBits() > 8 && isSigned) {
        // if this is PCM_SIGNED and 16-bit or higher, then try with endian-ness magic
        return new AudioFormat(format.getEncoding(),
                               format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
                               format.getFrameSize(), format.getFrameRate(), !format.isBigEndian());
    }
    else if (format.getSampleSizeInBits() == 8 && (isSigned || isUnsigned)) {
        // if this is PCM and 8-bit, then try with signed-ness magic
        return new AudioFormat(isSigned?AudioFormat.Encoding.PCM_UNSIGNED:AudioFormat.Encoding.PCM_SIGNED,
                               format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
                               format.getFrameSize(), format.getFrameRate(), format.isBigEndian());
    }
    return null;
}
 
Example 4
Source File: WaveFileWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: WaveFileWriter.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: WaveFileWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
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 7
Source File: WaveFileWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 8
Source File: AudioFloatFormatConverter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
        int targetChannels) {
    this.sourceChannels = ais.getFormat().getChannels();
    this.targetChannels = targetChannels;
    this.ais = ais;
    AudioFormat format = ais.getFormat();
    targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(),
            targetChannels, (format.getFrameSize() / sourceChannels)
                    * targetChannels, format.getFrameRate(), format
                    .isBigEndian());
}
 
Example 9
Source File: AudioFloatFormatConverter.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
        int targetChannels) {
    this.sourceChannels = ais.getFormat().getChannels();
    this.targetChannels = targetChannels;
    this.ais = ais;
    AudioFormat format = ais.getFormat();
    targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(),
            targetChannels, (format.getFrameSize() / sourceChannels)
                    * targetChannels, format.getFrameRate(), format
                    .isBigEndian());
}
 
Example 10
Source File: AuFileFormat.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: AudioFloatFormatConverter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
        int targetChannels) {
    this.sourceChannels = ais.getFormat().getChannels();
    this.targetChannels = targetChannels;
    this.ais = ais;
    AudioFormat format = ais.getFormat();
    targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(),
            targetChannels, (format.getFrameSize() / sourceChannels)
                    * targetChannels, format.getFrameRate(), format
                    .isBigEndian());
}
 
Example 12
Source File: AuFileFormat.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: SoftMixingDataLine.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
        AudioFormat format) {
    this.ais = ais;
    AudioFormat sourceFormat = ais.getFormat();
    targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
            .getSampleRate(), sourceFormat.getSampleSizeInBits(),
            sourceFormat.getChannels(), sourceFormat.getFrameSize(),
            format.getSampleRate(), sourceFormat.isBigEndian());
    nrofchannels = targetFormat.getChannels();
    Object interpolation = format.getProperty("interpolation");
    if (interpolation != null && (interpolation instanceof String)) {
        String resamplerType = (String) interpolation;
        if (resamplerType.equalsIgnoreCase("point"))
            this.resampler = new SoftPointResampler();
        if (resamplerType.equalsIgnoreCase("linear"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("linear1"))
            this.resampler = new SoftLinearResampler();
        if (resamplerType.equalsIgnoreCase("linear2"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("cubic"))
            this.resampler = new SoftCubicResampler();
        if (resamplerType.equalsIgnoreCase("lanczos"))
            this.resampler = new SoftLanczosResampler();
        if (resamplerType.equalsIgnoreCase("sinc"))
            this.resampler = new SoftSincResampler();
    }
    if (resampler == null)
        resampler = new SoftLinearResampler2(); // new
    // SoftLinearResampler2();
    pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
    pad = resampler.getPadding();
    pad2 = pad * 2;
    ibuffer = new float[nrofchannels][buffer_len + pad2];
    ibuffer2 = new float[nrofchannels * buffer_len];
    ibuffer_index = buffer_len + pad;
    ibuffer_len = buffer_len;
}
 
Example 14
Source File: WaveFloatFileWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private AudioInputStream toLittleEndian(AudioInputStream ais) {
    AudioFormat format = ais.getFormat();
    AudioFormat targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(), format
            .getChannels(), format.getFrameSize(), format.getFrameRate(),
            false);
    return AudioSystem.getAudioInputStream(targetFormat, ais);
}
 
Example 15
Source File: AudioFloatFormatConverter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
AudioFloatInputStreamResampler(AudioFloatInputStream ais,
        AudioFormat format) {
    this.ais = ais;
    AudioFormat sourceFormat = ais.getFormat();
    targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
            .getSampleRate(), sourceFormat.getSampleSizeInBits(),
            sourceFormat.getChannels(), sourceFormat.getFrameSize(),
            format.getSampleRate(), sourceFormat.isBigEndian());
    nrofchannels = targetFormat.getChannels();
    Object interpolation = format.getProperty("interpolation");
    if (interpolation != null && (interpolation instanceof String)) {
        String resamplerType = (String) interpolation;
        if (resamplerType.equalsIgnoreCase("point"))
            this.resampler = new SoftPointResampler();
        if (resamplerType.equalsIgnoreCase("linear"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("linear1"))
            this.resampler = new SoftLinearResampler();
        if (resamplerType.equalsIgnoreCase("linear2"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("cubic"))
            this.resampler = new SoftCubicResampler();
        if (resamplerType.equalsIgnoreCase("lanczos"))
            this.resampler = new SoftLanczosResampler();
        if (resamplerType.equalsIgnoreCase("sinc"))
            this.resampler = new SoftSincResampler();
    }
    if (resampler == null)
        resampler = new SoftLinearResampler2(); // new
                                                // SoftLinearResampler2();
    pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
    pad = resampler.getPadding();
    pad2 = pad * 2;
    ibuffer = new float[nrofchannels][buffer_len + pad2];
    ibuffer2 = new float[nrofchannels * buffer_len];
    ibuffer_index = buffer_len + pad;
    ibuffer_len = buffer_len;
}
 
Example 16
Source File: AuFileFormat.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 17
Source File: AuFileFormat.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 18
Source File: AudioFloatFormatConverter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
        int targetChannels) {
    this.sourceChannels = ais.getFormat().getChannels();
    this.targetChannels = targetChannels;
    this.ais = ais;
    AudioFormat format = ais.getFormat();
    targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(),
            targetChannels, (format.getFrameSize() / sourceChannels)
                    * targetChannels, format.getFrameRate(), format
                    .isBigEndian());
}
 
Example 19
Source File: PCMtoPCMCodec.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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 20
Source File: TGSynthSettingsDialog.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isSameEncoding( AudioFormat f1, AudioFormat f2 ){
	if( f1 == null || f2 == null || f1.getEncoding() == null || f2.getEncoding() == null ){
		return false;
	}
	return ( f1.getEncoding().toString().equals( f2.getEncoding().toString() ) );
}