net.sf.fmj.media.codec.audio.ulaw
Class MuLawEncoderUtil

java.lang.Object
  extended by net.sf.fmj.media.codec.audio.ulaw.MuLawEncoderUtil

public class MuLawEncoderUtil
extends java.lang.Object

Turns 16-bit linear PCM values into 8-bit mu-law bytes. Adapted from code by Marc Sweetgall at http://www.codeproject.com/csharp/g711audio.asp


Field Summary
static int BIAS
           
static int MAX
           
 
Constructor Summary
MuLawEncoderUtil()
           
 
Method Summary
 boolean getZeroTrap()
          Sets whether or not all-zero bytes are encoded as 2 instead.
static void muLawEncode(boolean bigEndian, byte[] data, int offset, int len, byte[] target)
           
static byte muLawEncode(int pcm)
          Encode a pcm value into a mu-law byte
static byte muLawEncode(short pcm)
          Encode a pcm value into a mu-law byte
static void muLawEncodeBigEndian(byte[] data, int offset, int len, byte[] target)
           
static void muLawEncodeLittleEndian(byte[] data, int offset, int len, byte[] target)
          Encode an array of pcm values into a pre-allocated target array
 void setZeroTrap(boolean value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIAS

public static final int BIAS
See Also:
Constant Field Values

MAX

public static final int MAX
See Also:
Constant Field Values
Constructor Detail

MuLawEncoderUtil

public MuLawEncoderUtil()
Method Detail

getZeroTrap

public boolean getZeroTrap()
Sets whether or not all-zero bytes are encoded as 2 instead. The pcm values this concerns are in the range [32768,33924] (unsigned).


setZeroTrap

public void setZeroTrap(boolean value)

muLawEncode

public static byte muLawEncode(int pcm)
Encode a pcm value into a mu-law byte

Parameters:
pcm - A 16-bit pcm value
Returns:
A mu-law encoded byte

muLawEncode

public static byte muLawEncode(short pcm)
Encode a pcm value into a mu-law byte

Parameters:
pcm - A 16-bit pcm value
Returns:
A mu-law encoded byte

muLawEncodeLittleEndian

public static void muLawEncodeLittleEndian(byte[] data,
                                           int offset,
                                           int len,
                                           byte[] target)
Encode an array of pcm values into a pre-allocated target array

Parameters:
data - An array of bytes in Little-Endian format
target - A pre-allocated array to receive the mu-law bytes. This array must be at least half the size of the source.

muLawEncodeBigEndian

public static void muLawEncodeBigEndian(byte[] data,
                                        int offset,
                                        int len,
                                        byte[] target)

muLawEncode

public static void muLawEncode(boolean bigEndian,
                               byte[] data,
                               int offset,
                               int len,
                               byte[] target)