javaFlacEncoder
Class StreamConfiguration

java.lang.Object
  extended by javaFlacEncoder.StreamConfiguration
All Implemented Interfaces:
java.lang.Cloneable

public class StreamConfiguration
extends java.lang.Object
implements java.lang.Cloneable

This class defines the configuration options that may not change throughout a FLAC stream. In general, these setting must be set to match the input audio used(sample rate, sample size, channels, etc). After a stream has started, these settings must not change.

Author:
Preston Lacey

Field Summary
static int DEFAULT_BITS_PER_SAMPLE
          Default sample size
static int DEFAULT_CHANNEL_COUNT
          Default channel count
static int DEFAULT_MAX_BLOCK_SIZE
          Default maximum block size
static int DEFAULT_MIN_BLOCK_SIZE
          Default minimum block size
static int DEFAULT_SAMPLE_RATE
          Default sample rate
static int MAX_BITS_PER_SAMPLE
          Maximum bits per sample allowed(FLAC spec allows 32, limited to 24 here due to limits in code)
static int MAX_BLOCK_SIZE
          Maximum Block size allowed(defined by flac spec)
static int MAX_CHANNEL_COUNT
          Maximum channel count allowed(defined by flac spec)
static int MAX_SAMPLE_RATE
          Maximum sample rate allowed(defined by flac spec)
static int MIN_BITS_PER_SAMPLE
          Minimum bits per sample allowed(defined by flac spec)
static int MIN_BLOCK_SIZE
          Minimum block size allowed(defined by flac spec)
static int MIN_SAMPLE_RATE
          Minimum sample rate allowed(defined by flac spec)
 
Constructor Summary
StreamConfiguration()
          Constructor, sets defaults for most values.
StreamConfiguration(int channelCount, int minBlock, int maxBlock, int sampleRate, int bitsPerSample)
          Constructor, allows setting of all options.
StreamConfiguration(StreamConfiguration sc)
          Copy Constructor.
 
Method Summary
 int getBitsPerSample()
          Get the number of bits per sample
 int getChannelCount()
          Get the currently set channel count
 int getMaxBlockSize()
          Get the currently set maximum block size
 int getMinBlockSize()
          Get the currently set minimum block size
 int getSampleRate()
          Get the currently set sample rate
 boolean isEncodingSubsetCompliant(EncodingConfiguration ec)
          Test if this StreamConfiguration and a paired EncodingConfiguration define a Subset compliant stream.
 boolean isStreamSubsetCompliant()
          Test if stream is Subset compliant.
 boolean isValid()
          Test if the current configuration is valid.
 boolean setBitsPerSample(int bitsPerSample)
          Set the bits per sample.
 boolean setChannelCount(int count)
          Set number of channels in stream.
 int setMaxBlockSize(int size)
          Set the maximum block size to use.
 int setMinBlockSize(int size)
          Set the minimum block size to use.
 boolean setSampleRate(int rate)
          Set the sample rate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_BLOCK_SIZE

public static final int MAX_BLOCK_SIZE
Maximum Block size allowed(defined by flac spec)

See Also:
Constant Field Values

MIN_BLOCK_SIZE

public static final int MIN_BLOCK_SIZE
Minimum block size allowed(defined by flac spec)

See Also:
Constant Field Values

MAX_CHANNEL_COUNT

public static final int MAX_CHANNEL_COUNT
Maximum channel count allowed(defined by flac spec)

See Also:
Constant Field Values

MIN_SAMPLE_RATE

public static final int MIN_SAMPLE_RATE
Minimum sample rate allowed(defined by flac spec)

See Also:
Constant Field Values

MAX_SAMPLE_RATE

public static final int MAX_SAMPLE_RATE
Maximum sample rate allowed(defined by flac spec)

See Also:
Constant Field Values

MIN_BITS_PER_SAMPLE

public static final int MIN_BITS_PER_SAMPLE
Minimum bits per sample allowed(defined by flac spec)

See Also:
Constant Field Values

MAX_BITS_PER_SAMPLE

public static final int MAX_BITS_PER_SAMPLE
Maximum bits per sample allowed(FLAC spec allows 32, limited to 24 here due to limits in code)

See Also:
Constant Field Values

DEFAULT_CHANNEL_COUNT

public static final int DEFAULT_CHANNEL_COUNT
Default channel count

See Also:
Constant Field Values

DEFAULT_MAX_BLOCK_SIZE

public static final int DEFAULT_MAX_BLOCK_SIZE
Default maximum block size

See Also:
Constant Field Values

DEFAULT_MIN_BLOCK_SIZE

public static final int DEFAULT_MIN_BLOCK_SIZE
Default minimum block size

See Also:
Constant Field Values

DEFAULT_SAMPLE_RATE

public static final int DEFAULT_SAMPLE_RATE
Default sample rate

See Also:
Constant Field Values

DEFAULT_BITS_PER_SAMPLE

public static final int DEFAULT_BITS_PER_SAMPLE
Default sample size

See Also:
Constant Field Values
Constructor Detail

StreamConfiguration

public StreamConfiguration()
Constructor, sets defaults for most values. Some default values must be changed to match the audio characteristics(channel count, sample rate, sample size).


StreamConfiguration

public StreamConfiguration(StreamConfiguration sc)
Copy Constructor. No values are altered or verified for sanity

Parameters:
sc - StreamConfiguration object to copy

StreamConfiguration

public StreamConfiguration(int channelCount,
                           int minBlock,
                           int maxBlock,
                           int sampleRate,
                           int bitsPerSample)
Constructor, allows setting of all options. In general, parameters given must match the input audio characteristics. minBlock and maxBlock may be set as desired, though minBlock is expected to be less than or equal to maxBlock. If minBlock or maxBlock is out of a valid range, it will be automatically adjusted to the closest valid value.

Parameters:
channelCount - number of channels in source audio stream
minBlock - minimum block to use in FLAC stream.
maxBlock - maximum block size to use in FLAC stream
sampleRate - sample rate in Hz of audio stream
bitsPerSample - sample size of audio stream
Method Detail

isValid

public boolean isValid()
Test if the current configuration is valid. While most set methods will ensure the values are in a valid range before setting them, some settings(such as number of channels), cannot be guessed. This method may alter current values to make them valid if possible.

Returns:
true if configuration defines a valid FLAC stream, false othwerise.

setChannelCount

public boolean setChannelCount(int count)
Set number of channels in stream. Because this is not a value that may be guessed and corrected, the value will be set to that given even if it is not valid.

Parameters:
count - Number of channels
Returns:
true if the channel count is within the valid range, false otherwise.

getChannelCount

public int getChannelCount()
Get the currently set channel count

Returns:
channel count

getMaxBlockSize

public int getMaxBlockSize()
Get the currently set maximum block size

Returns:
maximum block size

getMinBlockSize

public int getMinBlockSize()
Get the currently set minimum block size

Returns:
minimum block size

getSampleRate

public int getSampleRate()
Get the currently set sample rate

Returns:
sample rate(in Hz)

setSampleRate

public boolean setSampleRate(int rate)
Set the sample rate. Because this is not a value that may be guessed and corrected, the value will be set to that given even if it is not valid.

Parameters:
rate - sample rate(in Hz)
Returns:
true if given rate was within the valid range, false otherwise.

getBitsPerSample

public int getBitsPerSample()
Get the number of bits per sample

Returns:
bits per sample

setBitsPerSample

public boolean setBitsPerSample(int bitsPerSample)
Set the bits per sample. Because this is not a value that may be guessed and corrected, the value will be set to that given even if it is not valid.

Parameters:
bitsPerSample - number of bits per sample
Returns:
true if value given is within the valid range, false otherwise.

setMaxBlockSize

public int setMaxBlockSize(int size)
Set the maximum block size to use. If this value is out of a valid range, it will be set to the closest valid value. User must ensure that this value is set above or equal to the minimum block size.

Parameters:
size - maximum block size to use.
Returns:
actual size set

setMinBlockSize

public int setMinBlockSize(int size)
Set the minimum block size to use. If this value is out of a valid range, it will be set to the closest valid value. User must ensure that this value is set below or equal to the maximum block size.

Parameters:
size - minimum block size to use.
Returns:
actual size set

isStreamSubsetCompliant

public boolean isStreamSubsetCompliant()
Test if stream is Subset compliant. FLAC defines a subset of options to ensure resulting FLAC streams are streamable. Not all options in that subset are defined by the StreamConfiguration class, however, but exist in the EncodingConfiguration class. Therefore, the alternative method isEncodingSubsetCompliant should be checked as well to ensure the combined Stream/Encoding configurations are BOTH valid.

Returns:
true if this configuration is Subset compliant, false otherwise.

isEncodingSubsetCompliant

public boolean isEncodingSubsetCompliant(EncodingConfiguration ec)
Test if this StreamConfiguration and a paired EncodingConfiguration define a Subset compliant stream. FLAC defines a subset of options to ensure resulting FLAC streams are streamable.

Parameters:
ec - EncodingConfiguration object to check against
Returns:
true if these configurations are Subset compliant, false otherwise.