Example usage for javax.sound.sampled AudioFormat isBigEndian

List of usage examples for javax.sound.sampled AudioFormat isBigEndian

Introduction

In this page you can find the example usage for javax.sound.sampled AudioFormat isBigEndian.

Prototype

public boolean isBigEndian() 

Source Link

Document

Indicates whether the audio data is stored in big-endian or little-endian byte order.

Usage

From source file:iristk.speech.nuance9.BaseRecognizer.java

public static String getEncoding(AudioFormat format) throws IllegalArgumentException {
    if (format.getFrameRate() != 8000 && format.getFrameRate() != 16000)
        throw new IllegalArgumentException("Can only process 8khz or 16khz");
    if (format.isBigEndian())
        throw new IllegalArgumentException("Can only process little-endian");
    if (format.getChannels() != 1)
        throw new IllegalArgumentException("Can only process mono sound");
    if (format.getEncoding() == Encoding.ULAW)
        return "audio/basic;rate=8000";
    else if (format.getEncoding() == Encoding.PCM_SIGNED) {
        if (format.getFrameSize() != 2)
            throw new IllegalArgumentException("Can only process 16 bit PCM sound");
        return "audio/L16;rate=8000";
    } else/*from  w ww .ja  v a  2  s.c  om*/
        throw new IllegalArgumentException("Bad audio encoding: " + format.getEncoding());
}

From source file:com.andrewkroh.cicso.rtp.AudioFileStreamer.java

private static AudioFormat toAlawFormat(AudioFormat source) {
    Preconditions.checkNotNull(source, "Source AudioFormat cannot be null.");

    return new AudioFormat(AudioFormat.Encoding.ALAW, source.getSampleRate(), 8, // sample size in bits
            source.getChannels(), 1, // frame size in bytes
            source.getFrameRate(), source.isBigEndian());
}

From source file:com.andrewkroh.cicso.rtp.AudioFileStreamer.java

private static AudioFormat toUlawFormat(AudioFormat source) {
    Preconditions.checkNotNull(source, "Source AudioFormat cannot be null.");

    return new AudioFormat(AudioFormat.Encoding.ULAW, source.getSampleRate(), 8, // sample size in bits
            source.getChannels(), 1, // frame size in bytes
            source.getFrameRate(), source.isBigEndian());
}

From source file:com.andrewkroh.cicso.rtp.AudioFileStreamer.java

/**
 * Utility method to convert an {@link AudioFormat} object to a String.
 * {@code AudioFormat} does implement a toString method, but it's output
 * varies depending upon the contents. I find it more useful to always print
 * the value of all fields./*from   w  ww. j a  v a  2  s  . c om*/
 *
 * @param format
 *            {@code AudioFormat} to convert to a String
 * @return {@code AudioFormat} object as a String
 */
private static String audioFormatToString(AudioFormat format) {
    return new ToStringBuilder(format).append("encoding", format.getEncoding())
            .append("sampleRate", format.getSampleRate())
            .append("sampleSizeInBits", format.getSampleSizeInBits()).append("channels", format.getChannels())
            .append("frameSize", format.getFrameSize()).append("frameRate", format.getFrameRate())
            .append("isBigEndian", format.isBigEndian()).toString();
}

From source file:sx.blah.discord.api.internal.DiscordUtils.java

/**
 * Converts an {@link AudioInputStream} to 48000Hz 16 bit stereo signed Big Endian PCM format.
 *
 * @param stream The original stream./*from  ww  w  . ja  v a 2 s . c om*/
 * @return The PCM encoded stream.
 */
public static AudioInputStream getPCMStream(AudioInputStream stream) {
    AudioFormat baseFormat = stream.getFormat();

    //Converts first to PCM data. If the data is already PCM data, this will not change anything.
    AudioFormat toPCM = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(),
            //AudioConnection.OPUS_SAMPLE_RATE,
            baseFormat.getSampleSizeInBits() != -1 ? baseFormat.getSampleSizeInBits() : 16,
            baseFormat.getChannels(),
            //If we are given a frame size, use it. Otherwise, assume 16 bits (2 8bit shorts) per channel.
            baseFormat.getFrameSize() != -1 ? baseFormat.getFrameSize() : 2 * baseFormat.getChannels(),
            baseFormat.getFrameRate() != -1 ? baseFormat.getFrameRate() : baseFormat.getSampleRate(),
            baseFormat.isBigEndian());
    AudioInputStream pcmStream = AudioSystem.getAudioInputStream(toPCM, stream);

    //Then resamples to a sample rate of 48000hz and ensures that data is Big Endian.
    AudioFormat audioFormat = new AudioFormat(toPCM.getEncoding(), OpusUtil.OPUS_SAMPLE_RATE,
            toPCM.getSampleSizeInBits(), toPCM.getChannels(), toPCM.getFrameSize(), toPCM.getFrameRate(), true);

    return AudioSystem.getAudioInputStream(audioFormat, pcmStream);
}