public class FLACEncoder
extends java.lang.Object
1) Set StreamConfiguration to appropriate values. After a stream is opened, this must not be altered until the stream is closed.
2) Set FLACOutputStream, object to write results to.
3) Open FLAC Stream
4) Set EncodingConfiguration(if defaults are insufficient).
5) Add samples to encoder
6) Encode Samples
7) Close stream
(note: steps 4,5, and 6 may be done repeatedly, in any order, with the exception that step 4 must not be called while a concurrent step 6 is executing(as in threaded mode). See related method documentation for info on concurrent use) (note: steps 4,5, and 6 may be done repeatedly, in any order, with the exception that step 4 must not be called while a concurrent step 6 is executing(as in threaded mode). See related method documentation for info on concurrent use. For step 7, see the documentation for the encodeSamples(...) methods' "end" parameter)
Modifier and Type | Field and Description |
---|---|
java.util.concurrent.locks.ReentrantLock |
streamLock |
Constructor and Description |
---|
FLACEncoder()
Constructor which creates a new encoder object with the default settings.
|
Modifier and Type | Method and Description |
---|---|
void |
addSamples(int[] samples,
int count)
Add samples to the encoder, so they may then be encoded.
|
protected void |
blockFinished(BlockEncodeRequest ber)
Notify the encoder that a BlockEncodeRequest has finished, and is now
ready to be written to file.
|
void |
clear()
Clear all samples stored by this object, but not yet encoded.
|
int |
encodeSamples(int count,
boolean end)
Attempt to Encode a certain number of samples.
|
int |
fullBlockSamplesAvailableToEncode()
Get number of samples which are ready to encode.
|
int |
getThreadCount()
Get the number of threads this FLACEncoder is currently set to use.
|
void |
openFLACStream()
Begin a new FLAC stream.
|
int |
samplesAvailableToEncode()
Get number of samples that are available to encode.
|
boolean |
setEncodingConfiguration(EncodingConfiguration ec)
Set the encoding configuration to that specified.
|
void |
setOutputStream(FLACOutputStream fos)
Set the output stream to use.
|
boolean |
setStreamConfiguration(StreamConfiguration sc)
Set the stream configuration to that specified.
|
boolean |
setThreadCount(int count)
Tell encoder how many threads to use for encoding.
|
int |
t_encodeSamples(int inCount,
boolean end,
int blockingCount)
Attempt to Encode a certain number of samples(threaded version).
|
public FLACEncoder()
public boolean setThreadCount(int count)
count
- Number of encoding threads to use. Count > 0 means use that
many independent encoding threads, count == 0 means encode in main thread,
count < 0 is ignored.public int getThreadCount()
public boolean setEncodingConfiguration(EncodingConfiguration ec)
ec
- EncodingConfiguration to use.public boolean setStreamConfiguration(StreamConfiguration sc)
sc
- StreamConfiguration to use.public final void clear()
public void openFLACStream() throws java.io.IOException
java.io.IOException
- if there is an error writing the headers to output.public void addSamples(int[] samples, int count)
samples
- Array holding the samples to encode. For all multi-channel
audio, the samples must be interleaved in this array. For example, with
stereo: sample 0 will belong to the first channel, 1 the second, 2 the
first, 3 the second, etc. Samples are interpreted according to the
current configuration(for things such as channel and bits-per-sample).count
- Number of interchannel samples to add. For example, with
stero: if this is 4000, then "samples" must contain 4000 left samples and
4000 right samples, interleaved in the array.protected void blockFinished(BlockEncodeRequest ber)
ber
- BlockEncodeRequest that is ready to write to file.public int t_encodeSamples(int inCount, boolean end, int blockingCount) throws java.io.IOException
count
- number of samples to attempt to encode. Actual number
encoded may be greater or less if count does not end on a block boundary.
If "end" is false, we may set this value to something absurdly high, such
as Integer.MAX_VALUE to ensure all available, full blocks are encoded.end
- true to finalize stream after encode, false otherwise. If set
to true, and return value is greater than or equal to given count, no
more encoding must be attempted until a new stream is began.blockingCount
- value is used for flow-control into this encoder.
This method will block until fewer than the given number of blocks remain
queued for encoding.java.io.IOException
- if there was an error writing the results to output
stream.public int encodeSamples(int count, boolean end) throws java.io.IOException
count
- number of samples to attempt to encode. Actual number
encoded may be greater or less if count does not end on a block boundary.end
- true to finalize stream after encode, false otherwise. If set
to true, and return value is greater than or equal to given count, no
more encoding must be attempted until a new stream is began.java.io.IOException
- if there was an error writing the results to file.public int fullBlockSamplesAvailableToEncode()
public int samplesAvailableToEncode()
public void setOutputStream(FLACOutputStream fos)
fos
- output stream to use. This must not be null.