bytes To Short by Audio format - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

bytes To Short by Audio format

Demo Code


//package com.java2s;

import javax.sound.sampled.AudioFormat;

public class Main {
    public static short bytesToShort(AudioFormat format, byte b1, byte b2) {
        byte big;
        byte little;
        if (!format.isBigEndian()) {
            little = b1;//from ww w . java2s .c  o  m
            big = b2;
        } else {
            little = b2;
            big = b1;
        }
        int val = big;
        if (format.getEncoding() == AudioFormat.Encoding.PCM_UNSIGNED) {
            val &= 0xff;
        }
        return (short) ((val << 8) + (little & 0xff));
    }
}

Related Tutorials