javaFlacEncoder
Class Subframe

java.lang.Object
  extended by javaFlacEncoder.Subframe
Direct Known Subclasses:
Subframe_Constant, Subframe_Fixed, Subframe_LPC, Subframe_Verbatim

public abstract class Subframe
extends java.lang.Object

Description: This abstract class declares the methods needed to retrieve encoded data in a standard format(across the different implemented Subframe types), as well as the generic methods needed to write the subframe header. It is assumed that objects of this type will be reused in future frames, rather than being destroyed and made anew. This is to avoid the overhead associated with creating and destroying objects in Java.

Author:
Preston Lacey

Field Summary
protected  EncodingConfiguration ec
          EncodingConfiguration used for encoding.
protected  int lastEncodedSize
          Store for size of last subframe encoded(in bits).
protected  StreamConfiguration sc
          StreamConfiguration used for encoding.
 
Constructor Summary
Subframe(StreamConfiguration sc)
          Constructor.
 
Method Summary
abstract  int encodeSamples(int[] samples, int count, int start, int skip, EncodedElement data, int offset, int bitsPerSample)
          Encodes samples into the appropriate compressed format, saving the result in the given “data” EncodedElement list.
 int getEncodedSize()
          Returns the total number of valid bits used in the last encoding(i.e, the number of compressed bits used).
 boolean registerConfiguration(EncodingConfiguration ec)
          This method is used to set the encoding configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sc

protected StreamConfiguration sc
StreamConfiguration used for encoding. The same StreamConfiguration MUST be used throughout an entire FLAC stream


ec

protected EncodingConfiguration ec
EncodingConfiguration used for encoding. This may be altered between frames, but must be the same for each subframe within that frame


lastEncodedSize

protected int lastEncodedSize
Store for size of last subframe encoded(in bits).

Constructor Detail

Subframe

public Subframe(StreamConfiguration sc)
Constructor. Sets StreamConfiguration to use. If the StreamConfiguration must later be changed, a new Subframe object must be created as well. A default EncodingConfiguration is created using EncodingConfiguration's default Constructor. This configuration should create a decent encode, but may be altered if desired.

Parameters:
sc - StreamConfiguration to use for encoding.
Method Detail

registerConfiguration

public boolean registerConfiguration(EncodingConfiguration ec)
This method is used to set the encoding configuration.

Parameters:
ec - encoding configuration to use.
Returns:
true if configuration was changed, false otherwise

encodeSamples

public abstract int encodeSamples(int[] samples,
                                  int count,
                                  int start,
                                  int skip,
                                  EncodedElement data,
                                  int offset,
                                  int bitsPerSample)
Encodes samples into the appropriate compressed format, saving the result in the given “data” EncodedElement list. Encodes 'count' samples, from index 'start', to index 'start' times 'skip', where “skip” is the format that samples may be packed in an array. For example, 'samples' may include both left and right samples of a stereo stream, while this SubFrame is only encoding the 'right' channel(channel 2). Therefore, “skip” would equal 2, resulting in the valid indices being only those where “index mod 2 equals 1”.

Parameters:
samples - the audio samples to encode. This array may contain samples for multiple channels, interleaved; only one of these channels is encoded by a subframe.
count - the number of samples to encode.
start - the index to start at in the array.
skip - the number of indices to skip between successive samples (for use when channels are interleaved in the given array).
data - the EncodedElement to attach encoded data to. Data in EncodedElement given is not altered. New data is attached starting with “data.getNext()”. If “data” already has a “next” set, it will be lost!
offset -
bitsPerSample - Number of bits per single-channel sample. This may differ from the StreamConfiguration's sample size, depending on the subframe used(i.e, the "side-channel" of a FLAC stream uses one extra bit compared to the input channels).
Returns:
number of encoded samples, or negative value indicating an error has occurred.

getEncodedSize

public int getEncodedSize()
Returns the total number of valid bits used in the last encoding(i.e, the number of compressed bits used). This is here for convenience, as the calling object may also loop through the resulting EncodingElement from the encoding process and sum the valid bits.

Returns:
an integer with value of the number of bits used in last encoding.