javax.sound.sampled.AudioFormat#isBigEndian ( )源码实例Demo

下面列出了javax.sound.sampled.AudioFormat#isBigEndian ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: PCMtoPCMCodec.java
/**
 */
public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) {

    if( isConversionSupported(targetEncoding, sourceStream.getFormat()) ) {

        AudioFormat sourceFormat = sourceStream.getFormat();
        AudioFormat targetFormat = new AudioFormat( targetEncoding,
                                                    sourceFormat.getSampleRate(),
                                                    sourceFormat.getSampleSizeInBits(),
                                                    sourceFormat.getChannels(),
                                                    sourceFormat.getFrameSize(),
                                                    sourceFormat.getFrameRate(),
                                                    sourceFormat.isBigEndian() );

        return getAudioInputStream( targetFormat, sourceStream );

    } else {
        throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString() );
    }

}
 
源代码2 项目: Bytecoder   文件: AudioFloatFormatConverter.java
@Override
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
                                            AudioInputStream sourceStream) {
    if (!isConversionSupported(targetEncoding, sourceStream.getFormat())) {
        throw new IllegalArgumentException(
                "Unsupported conversion: " + sourceStream.getFormat()
                        .toString() + " to " + targetEncoding.toString());
    }
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
 
源代码3 项目: openjdk-jdk8u   文件: AudioFloatFormatConverter.java
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
 
源代码4 项目: tuxguitar   文件: AudioFloatFormatConverter.java
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
 
源代码5 项目: Bytecoder   文件: PCMtoPCMCodec.java
@Override
public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) {

    if( isConversionSupported(targetEncoding, sourceStream.getFormat()) ) {

        AudioFormat sourceFormat = sourceStream.getFormat();
        AudioFormat targetFormat = new AudioFormat( targetEncoding,
                                                    sourceFormat.getSampleRate(),
                                                    sourceFormat.getSampleSizeInBits(),
                                                    sourceFormat.getChannels(),
                                                    sourceFormat.getFrameSize(),
                                                    sourceFormat.getFrameRate(),
                                                    sourceFormat.isBigEndian() );

        return getConvertedStream(targetFormat, sourceStream);

    } else {
        throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString() );
    }

}
 
源代码6 项目: openjdk-8-source   文件: AudioFloatConverter.java
AudioFloatLSBFilter(AudioFloatConverter converter, AudioFormat format) {
    int bits = format.getSampleSizeInBits();
    boolean bigEndian = format.isBigEndian();
    this.converter = converter;
    stepsize = (bits + 7) / 8;
    offset = bigEndian ? (stepsize - 1) : 0;
    int lsb_bits = bits % 8;
    if (lsb_bits == 0)
        mask = (byte) 0x00;
    else if (lsb_bits == 1)
        mask = (byte) 0x80;
    else if (lsb_bits == 2)
        mask = (byte) 0xC0;
    else if (lsb_bits == 3)
        mask = (byte) 0xE0;
    else if (lsb_bits == 4)
        mask = (byte) 0xF0;
    else if (lsb_bits == 5)
        mask = (byte) 0xF8;
    else if (lsb_bits == 6)
        mask = (byte) 0xFC;
    else if (lsb_bits == 7)
        mask = (byte) 0xFE;
    else
        mask = (byte) 0xFF;
}
 
源代码7 项目: jdk8u-dev-jdk   文件: SoftMixingDataLine.java
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;
}
 
源代码8 项目: openjdk-8   文件: SoftMixingDataLine.java
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;
}
 
源代码9 项目: jdk8u-jdk   文件: SoftMixingDataLine.java
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;
}
 
源代码10 项目: dragonwell8_jdk   文件: SoftMixingDataLine.java
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;
}
 
源代码11 项目: hottub   文件: SoftMixingDataLine.java
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;
}
 
源代码12 项目: jdk8u-jdk   文件: AudioFloatFormatConverter.java
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());
}
 
源代码13 项目: jipes   文件: Resample.java
private AudioFormat getProcessedAudioFormat(final AudioBuffer buffer) {
    final AudioFormat sourceAudioFormat = buffer.getAudioFormat();
    return new AudioFormat(sourceAudioFormat.getSampleRate() * resampler.getFactor(),
            sourceAudioFormat.getSampleSizeInBits(),
            sourceAudioFormat.getChannels(),
            AudioFormat.Encoding.PCM_SIGNED.equals(sourceAudioFormat.getEncoding()),
            sourceAudioFormat.isBigEndian());
}
 
源代码14 项目: jipes   文件: SelfSimilarity.java
private void deriveOutputFormat(final AudioFormat inputFormat) {
    final int frameDiff = secondFrame - firstFrame;
    final float sampleRate = inputFormat.getSampleRate() / frameDiff;
    audioFormat = new AudioFormat(
            inputFormat.getEncoding(), sampleRate, inputFormat.getSampleSizeInBits(),
            inputFormat.getChannels(), inputFormat.getFrameSize(), sampleRate,
            inputFormat.isBigEndian());
}
 
源代码15 项目: openjdk-8   文件: AudioFloatFormatConverter.java
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;
}
 
源代码16 项目: jdk8u_jdk   文件: UlawCodec.java
UlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) {
    super(stream, outputFormat, AudioSystem.NOT_SPECIFIED);

    AudioFormat inputFormat = stream.getFormat();

    // throw an IllegalArgumentException if not ok
    if (!(isConversionSupported(outputFormat, inputFormat))) {
        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
    if (AudioFormat.Encoding.ULAW.equals(inputFormat.getEncoding())) {
        encode = false;
        encodeFormat = inputFormat;
        decodeFormat = outputFormat;
        PCMIsBigEndian = outputFormat.isBigEndian();
    } else {
        encode = true;
        encodeFormat = outputFormat;
        decodeFormat = inputFormat;
        PCMIsBigEndian = inputFormat.isBigEndian();
        tempBuffer = new byte[tempBufferSize];
    }

    // setup tables according to byte order
    if (PCMIsBigEndian) {
        tabByte1 = ULAW_TABH;
        tabByte2 = ULAW_TABL;
        highByte = 0;
        lowByte  = 1;
    } else {
        tabByte1 = ULAW_TABL;
        tabByte2 = ULAW_TABH;
        highByte = 1;
        lowByte  = 0;
    }

    // set the AudioInputStream length in frames if we know it
    if (stream instanceof AudioInputStream) {
        frameLength = ((AudioInputStream)stream).getFrameLength();
    }
    // set framePos to zero
    framePos = 0;
    frameSize = inputFormat.getFrameSize();
    if (frameSize == AudioSystem.NOT_SPECIFIED) {
        frameSize = 1;
    }
}
 
源代码17 项目: dragonwell8_jdk   文件: AudioFloatConverter.java
public static AudioFloatConverter getConverter(AudioFormat format) {
    AudioFloatConverter conv = null;
    if (format.getFrameSize() == 0)
        return null;
    if (format.getFrameSize() !=
            ((format.getSampleSizeInBits() + 7) / 8) * format.getChannels()) {
        return null;
    }
    if (format.getEncoding().equals(Encoding.PCM_SIGNED)) {
        if (format.isBigEndian()) {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8S();
            } else if (format.getSampleSizeInBits() > 8 &&
                  format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16SB();
            } else if (format.getSampleSizeInBits() > 16 &&
                  format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24SB();
            } else if (format.getSampleSizeInBits() > 24 &&
                  format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32SB();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xSB(((format
                        .getSampleSizeInBits() + 7) / 8) - 4);
            }
        } else {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8S();
            } else if (format.getSampleSizeInBits() > 8 &&
                     format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16SL();
            } else if (format.getSampleSizeInBits() > 16 &&
                     format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24SL();
            } else if (format.getSampleSizeInBits() > 24 &&
                     format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32SL();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xSL(((format
                        .getSampleSizeInBits() + 7) / 8) - 4);
            }
        }
    } else if (format.getEncoding().equals(Encoding.PCM_UNSIGNED)) {
        if (format.isBigEndian()) {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8U();
            } else if (format.getSampleSizeInBits() > 8 &&
                    format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16UB();
            } else if (format.getSampleSizeInBits() > 16 &&
                    format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24UB();
            } else if (format.getSampleSizeInBits() > 24 &&
                    format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32UB();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xUB(((
                        format.getSampleSizeInBits() + 7) / 8) - 4);
            }
        } else {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8U();
            } else if (format.getSampleSizeInBits() > 8 &&
                    format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16UL();
            } else if (format.getSampleSizeInBits() > 16 &&
                    format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24UL();
            } else if (format.getSampleSizeInBits() > 24 &&
                    format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32UL();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xUL(((
                        format.getSampleSizeInBits() + 7) / 8) - 4);
            }
        }
    } else if (format.getEncoding().equals(Encoding.PCM_FLOAT)) {
        if (format.getSampleSizeInBits() == 32) {
            if (format.isBigEndian())
                conv = new AudioFloatConversion32B();
            else
                conv = new AudioFloatConversion32L();
        } else if (format.getSampleSizeInBits() == 64) {
            if (format.isBigEndian())
                conv = new AudioFloatConversion64B();
            else
                conv = new AudioFloatConversion64L();
        }

    }

    if ((format.getEncoding().equals(Encoding.PCM_SIGNED) ||
            format.getEncoding().equals(Encoding.PCM_UNSIGNED)) &&
            (format.getSampleSizeInBits() % 8 != 0)) {
        conv = new AudioFloatLSBFilter(conv, format);
    }

    if (conv != null)
        conv.format = format;
    return conv;
}
 
源代码18 项目: jdk8u-jdk   文件: AudioFloatConverter.java
public static AudioFloatConverter getConverter(AudioFormat format) {
    AudioFloatConverter conv = null;
    if (format.getFrameSize() == 0)
        return null;
    if (format.getFrameSize() !=
            ((format.getSampleSizeInBits() + 7) / 8) * format.getChannels()) {
        return null;
    }
    if (format.getEncoding().equals(Encoding.PCM_SIGNED)) {
        if (format.isBigEndian()) {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8S();
            } else if (format.getSampleSizeInBits() > 8 &&
                  format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16SB();
            } else if (format.getSampleSizeInBits() > 16 &&
                  format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24SB();
            } else if (format.getSampleSizeInBits() > 24 &&
                  format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32SB();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xSB(((format
                        .getSampleSizeInBits() + 7) / 8) - 4);
            }
        } else {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8S();
            } else if (format.getSampleSizeInBits() > 8 &&
                     format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16SL();
            } else if (format.getSampleSizeInBits() > 16 &&
                     format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24SL();
            } else if (format.getSampleSizeInBits() > 24 &&
                     format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32SL();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xSL(((format
                        .getSampleSizeInBits() + 7) / 8) - 4);
            }
        }
    } else if (format.getEncoding().equals(Encoding.PCM_UNSIGNED)) {
        if (format.isBigEndian()) {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8U();
            } else if (format.getSampleSizeInBits() > 8 &&
                    format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16UB();
            } else if (format.getSampleSizeInBits() > 16 &&
                    format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24UB();
            } else if (format.getSampleSizeInBits() > 24 &&
                    format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32UB();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xUB(((
                        format.getSampleSizeInBits() + 7) / 8) - 4);
            }
        } else {
            if (format.getSampleSizeInBits() <= 8) {
                conv = new AudioFloatConversion8U();
            } else if (format.getSampleSizeInBits() > 8 &&
                    format.getSampleSizeInBits() <= 16) {
                conv = new AudioFloatConversion16UL();
            } else if (format.getSampleSizeInBits() > 16 &&
                    format.getSampleSizeInBits() <= 24) {
                conv = new AudioFloatConversion24UL();
            } else if (format.getSampleSizeInBits() > 24 &&
                    format.getSampleSizeInBits() <= 32) {
                conv = new AudioFloatConversion32UL();
            } else if (format.getSampleSizeInBits() > 32) {
                conv = new AudioFloatConversion32xUL(((
                        format.getSampleSizeInBits() + 7) / 8) - 4);
            }
        }
    } else if (format.getEncoding().equals(Encoding.PCM_FLOAT)) {
        if (format.getSampleSizeInBits() == 32) {
            if (format.isBigEndian())
                conv = new AudioFloatConversion32B();
            else
                conv = new AudioFloatConversion32L();
        } else if (format.getSampleSizeInBits() == 64) {
            if (format.isBigEndian())
                conv = new AudioFloatConversion64B();
            else
                conv = new AudioFloatConversion64L();
        }

    }

    if ((format.getEncoding().equals(Encoding.PCM_SIGNED) ||
            format.getEncoding().equals(Encoding.PCM_UNSIGNED)) &&
            (format.getSampleSizeInBits() % 8 != 0)) {
        conv = new AudioFloatLSBFilter(conv, format);
    }

    if (conv != null)
        conv.format = format;
    return conv;
}
 
源代码19 项目: TencentKona-8   文件: AlawCodec.java
AlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) {

            super(stream, outputFormat, -1);

            AudioFormat inputFormat = stream.getFormat();

            // throw an IllegalArgumentException if not ok
            if ( ! (isConversionSupported(outputFormat, inputFormat)) ) {

                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
            if (AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) {
                encode = false;
                encodeFormat = inputFormat;
                decodeFormat = outputFormat;
                PCMIsBigEndian = outputFormat.isBigEndian();
            } else {
                encode = true;
                encodeFormat = outputFormat;
                decodeFormat = inputFormat;
                PCMIsBigEndian = inputFormat.isBigEndian();
                tempBuffer = new byte[tempBufferSize];
            }

            if (PCMIsBigEndian) {
                tabByte1 = ALAW_TABH;
                tabByte2 = ALAW_TABL;
                highByte = 0;
                lowByte  = 1;
            } else {
                tabByte1 = ALAW_TABL;
                tabByte2 = ALAW_TABH;
                highByte = 1;
                lowByte  = 0;
            }

            // set the AudioInputStream length in frames if we know it
            if (stream instanceof AudioInputStream) {
                frameLength = ((AudioInputStream)stream).getFrameLength();
            }

            // set framePos to zero
            framePos = 0;
            frameSize = inputFormat.getFrameSize();
            if( frameSize==AudioSystem.NOT_SPECIFIED ) {
                frameSize=1;
            }
        }
 
源代码20 项目: jsyn   文件: JavaSoundSampleLoader.java
private float[] loadSignedPCM(AudioInputStream audioInputStream) throws IOException,
        UnsupportedAudioFileException {
    int totalSamplesRead = 0;
    AudioFormat format = audioInputStream.getFormat();
    int numFrames = (int) audioInputStream.getFrameLength();
    int numSamples = format.getChannels() * numFrames;
    float[] data = new float[numSamples];
    final int bytesPerFrame = format.getFrameSize();
    // Set an arbitrary buffer size of 1024 frames.
    int numBytes = 1024 * bytesPerFrame;
    byte[] audioBytes = new byte[numBytes];
    int numBytesRead = 0;
    int numFramesRead = 0;
    // Try to read numBytes bytes from the file.
    while ((numBytesRead = audioInputStream.read(audioBytes)) != -1) {
        int bytesRemainder = numBytesRead % bytesPerFrame;
        if (bytesRemainder != 0) {
            // TODO Read until you get enough data.
            throw new IOException("Read partial block of sample data!");
        }

        if (audioInputStream.getFormat().getSampleSizeInBits() == 16) {
            if (format.isBigEndian()) {
                SampleLoader.decodeBigI16ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            } else {
                SampleLoader.decodeLittleI16ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            }
        } else if (audioInputStream.getFormat().getSampleSizeInBits() == 24) {
            if (format.isBigEndian()) {
                SampleLoader.decodeBigI24ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            } else {
                SampleLoader.decodeLittleI24ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            }
        } else if (audioInputStream.getFormat().getSampleSizeInBits() == 32) {
            if (format.isBigEndian()) {
                SampleLoader.decodeBigI32ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            } else {
                SampleLoader.decodeLittleI32ToF32(audioBytes, 0, numBytesRead, data,
                        totalSamplesRead);
            }
        } else {
            throw new UnsupportedAudioFileException(
                    "Only 16, 24 or 32 bit PCM samples supported.");
        }

        // Calculate the number of frames actually read.
        numFramesRead = numBytesRead / bytesPerFrame;
        totalSamplesRead += numFramesRead * format.getChannels();
    }
    return data;
}