javaFlacEncoder
Class RiceEncoder

java.lang.Object
  extended by javaFlacEncoder.RiceEncoder

public class RiceEncoder
extends java.lang.Object

The RiceEncoder class is used to create FLAC-compliant rice-encoded residuals.

Author:
Preston Lacey

Field Summary
static int DEBUG_LEV
          For debugging: Higher values equals greater output, generally in increments of 10
 
Constructor Summary
RiceEncoder()
          Constructor.
 
Method Summary
static int beginResidual(boolean useFiveBitParam, byte order, EncodedElement ele)
          Create the residual headers for a FLAC stream.
static int calculateEncodeSize(int[] values, int inputOffset, int inputStep, int inputCount, int bitParam)
          Calculate how large a given set of values will be once it has been rice-encoded.
 int encodeRicePartition(int[] values, int inputOffset, int inputStep, int inputCount, EncodedElement destEle, int bitParam, boolean fiveBitParam)
          Rice-encode a set of values, adding necessary headers for FLAC format.
static int encodeRicePartitionEscaped(int[] values, int inputOffset, int inputStep, int inputCount, EncodedElement destEle, int bitParam, boolean fiveBitParam)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_LEV

public static int DEBUG_LEV
For debugging: Higher values equals greater output, generally in increments of 10

Constructor Detail

RiceEncoder

public RiceEncoder()
Constructor. A RiceEncoder object is used(as opposed to potentially faster static methods), for memory considerations; some temporary, dynamically created arrays are kept between calls to the encode methods to prevent frequently allocating and freeing similarly sized arrays.

Method Detail

beginResidual

public static int beginResidual(boolean useFiveBitParam,
                                byte order,
                                EncodedElement ele)
Create the residual headers for a FLAC stream.

Parameters:
useFiveBitParam - Set TRUE if using a five-bit parameter size, FALSE for a four-bit parameter
order - Specify order of partitions to be used(actual number of partitions will be 2^order.
ele - EncodedElement to write header to.
Returns:
total written size of header.

encodeRicePartitionEscaped

public static int encodeRicePartitionEscaped(int[] values,
                                             int inputOffset,
                                             int inputStep,
                                             int inputCount,
                                             EncodedElement destEle,
                                             int bitParam,
                                             boolean fiveBitParam)

encodeRicePartition

public int encodeRicePartition(int[] values,
                               int inputOffset,
                               int inputStep,
                               int inputCount,
                               EncodedElement destEle,
                               int bitParam,
                               boolean fiveBitParam)
Rice-encode a set of values, adding necessary headers for FLAC format. This encodes a single rice-partition. In general, beginResidual(...) should be used before this method.

Parameters:
values - array of integer values to save
inputOffset - start index in input array
inputStep - number of values to skip between target values(for interleaved data.
inputCount - number of total values to encode
bitParam - rice-parameter to use. This value should be based upon the distribution of the input data(roughly speeking, each value will require at least bitParam+1 bits to save, so this value should reflect the average magnitude of input values.
destEle - EncodedElement to save result to.
fiveBitParam - Set true if this header should use a five-bit rice-parameter, false for a four bit parameter.
Returns:
total encoded size(including headers)

calculateEncodeSize

public static int calculateEncodeSize(int[] values,
                                      int inputOffset,
                                      int inputStep,
                                      int inputCount,
                                      int bitParam)
Calculate how large a given set of values will be once it has been rice-encoded. While this method duplicates much of the process of rice-encoding, it is faster than an actual encode since the data is not actually written to the flac bitstream format(a rather costly write).

Parameters:
values - array of integer values to save
inputOffset - start index in input array
inputStep - number of values to skip between target values(for interleaved data.
inputCount - number of total values to encode
bitParam - rice-parameter to use. This value should be based upon the distribution of the input data(roughly speeking, each value will require at least bitParam+1 bits to save, so this value should reflect the average magnitude of input values.
Returns:
total encoded-size with given data and rice-parameter.