|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object comirva.audio.util.AudioPreProcessor
public class AudioPreProcessor
AudioPreProcessor
Description:
This class simplifies the access to audio streams. It frees you from taking care of the encoding of the input stream. The samples of the audio stream get converted and are stored as double values. The sample rate of the output stream can be specified. The output stream has only one channel. If the input stream has more than one channel, it will get reduced. If the input stream is encoded the Java Sound API will be used for decoding the stream. Also some of the audio conversion operations use the API. So be sure to have correctly configured your Java Audio System.
Field Summary | |
---|---|
static float |
DEFAULT_SAMPLE_RATE
default sample rate of the output stream |
protected int |
frameSize
|
protected AudioInputStream |
in
|
protected boolean |
isBigEndian
|
protected float |
sampleRate
|
Constructor Summary | |
---|---|
AudioPreProcessor(AudioInputStream in)
An AudioPreProcessor encapsulates an AudioInputStream object permitting an easy access to the audio data. |
|
AudioPreProcessor(AudioInputStream in,
float sampleRate)
An AudioPreProcessor encapsulates an AudioInputStream object permitting an easy access to the audio data. |
Method Summary | |
---|---|
int |
append(double[] buffer,
int start,
int len)
Appends a specified number of samples to an array. |
static AudioInputStream |
convertBitsPerSample(AudioInputStream in,
int bitsPerSample)
Converts the number bits used to represent one sample within an AudioInputStream by returning a new a new stream using the given number of bits to represent one sample. |
static AudioInputStream |
convertByteOrder(AudioInputStream in,
boolean isBigEndian)
Converts the byte order of an AudioInputStream by returning a new a new stream using the given byte order (big/little Endian). |
static AudioInputStream |
convertChannels(AudioInputStream in,
int channels)
Converts the number of channels of an AudioInputStream by returning a new stream with the given number of channels. |
static AudioInputStream |
convertSampleRate(AudioInputStream in,
float sampleRate)
Converts the sample rate of an AudioInputStream by returning a new stream with the given sample rate. |
static AudioInputStream |
convertToPCM(AudioInputStream in)
Converts an AudioInputStream with arbitrary encoding into an AudioInputStream with signed pulse code modulation (PCM_SIGNED). |
protected void |
convertToSample(byte[] in,
int len,
double[] out,
int start)
This method is internally used to convert the bytes of the input byte stream to a steam of float pointing samples. |
int |
fastSkip(int len)
This method only skips on frame basis. |
protected void |
finalize()
|
double[] |
get(int len)
Returns a specified number of samples. |
static AudioPreProcessor |
getAudioPreProcessor(File input,
float sampleRate)
|
float |
getSampleRate()
Returns the sample rate of the output stream. |
int |
skip(int len)
Skips a specified number of samples. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final float DEFAULT_SAMPLE_RATE
protected AudioInputStream in
protected float sampleRate
protected int frameSize
protected boolean isBigEndian
Constructor Detail |
---|
public AudioPreProcessor(AudioInputStream in, float sampleRate) throws IllegalArgumentException
in
- AudioInputStream the audio input stream to encapsulate, must not
be a null valuesampleRate
- int the sampleRate of the output stream, must be greater
than zero and less or equal the sample rate of the
input stream, such that a conversion is possible;
none integer values are rounded
IllegalArgumentException
- raised if method contract is violatedpublic AudioPreProcessor(AudioInputStream in) throws IllegalArgumentException
in
- AudioInputStream the audio input stream to encapsulate, must not
be a null value
IllegalArgumentException
- raised if method contract is violatedMethod Detail |
---|
public float getSampleRate()
public int skip(int len) throws IllegalArgumentException, IOException
len
- number of samples to skip, must be a positive value
IllegalArgumentException
- raised if method contract is violated
IOException
- if there are any problems regarding the inputstreamfastSkip(int)
public int fastSkip(int len) throws IllegalArgumentException, IOException
len
- number of samples to skip, must be a positive value
IllegalArgumentException
- raised if method contract is violated
IOException
- if there are any problems regarding the inputstreampublic double[] get(int len) throws IllegalArgumentException, IOException
len
- a number of samples to return, must be a positive value
IllegalArgumentException
- raised if method contract is violated
IOException
- if there are any problems regarding the inputstreampublic int append(double[] buffer, int start, int len) throws IllegalArgumentException, IOException
buffer
- the buffer for the samples to be written in, must not be a
null value and sufficient large to hold the number of samples
specified by lenstart
- start index at which the new samples are filled into the
array, must be greater equal zero; starting form this index
there must be enough space to hold the number of samples
specified by lenlen
- number of samples to be written into the buffer, must be greater
than or equal to zero.
IllegalArgumentException
- raised if method contract is violated
IOException
- if there are any problems regarding the inputstreamprotected void convertToSample(byte[] in, int len, double[] out, int start)
in
- byte[] input date, bytes of the audio input streamlen
- int number of valid bytes in the input bufferout
- double[] output buffer for the db-SPL valuesstart
- int start index within the output bufferpublic static AudioInputStream convertToPCM(AudioInputStream in) throws IllegalArgumentException
in
- AudioInputStream the original audio stream, must not be a null
value
IllegalArgumentException
- raised if method contract is violated or
if the conversion is not supported by your
audio systempublic static AudioInputStream convertSampleRate(AudioInputStream in, float sampleRate) throws IllegalArgumentException
in
- AudioInputStream the original audio stream, must not be a null
valuesampleRate
- float the sample rate to convert, must be greater null
and less or equal the sample rate of the input
stream
IllegalArgumentException
- raised if method contract is violated or
if the conversion is not supported by your
audio systempublic static AudioInputStream convertChannels(AudioInputStream in, int channels) throws IllegalArgumentException
in
- AudioInputStream the original audio stream, must not be a null
valuechannels
- int the number of channels to convert to, must be greater
null
IllegalArgumentException
- raised if method contract is violated or
if the conversion is not supported by your
audio systempublic static AudioInputStream convertBitsPerSample(AudioInputStream in, int bitsPerSample) throws IllegalArgumentException
in
- AudioInputStream the original audio stream, must not be a null
valuebitsPerSample
- int the number of bits per samples to convert to, must
be either 8, 16, 24 or 32
IllegalArgumentException
- raised if method contract is violated or
if the conversion is not supported by your
audio systempublic static AudioInputStream convertByteOrder(AudioInputStream in, boolean isBigEndian) throws IllegalArgumentException
in
- AudioInputStream the original audio stream, must not be a null
valueisBigEndian
- boolean true if the byte order in the resulting stream
should be big-Endian, false otherwise
(little-Endian)
IllegalArgumentException
- raised if method contract is violated or
if the conversion is not supported by your
audio systempublic static AudioPreProcessor getAudioPreProcessor(File input, float sampleRate) throws UnsupportedAudioFileException, IOException
UnsupportedAudioFileException
IOException
protected void finalize() throws Throwable
finalize
in class Object
Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |