|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectbe.hogent.tarsos.dsp.AudioDispatcher
public final class AudioDispatcher
This class plays a file and sends float arrays to registered AudioProcessor implementors. This class can be used to feed FFT's, pitch detectors, audio players, ... Using a (blocking) audio player it is even possible to synchronize execution of AudioProcessors and sound. This behavior can be used for visualization.
| Constructor Summary | |
|---|---|
AudioDispatcher(javax.sound.sampled.AudioInputStream stream,
int audioBufferSize,
int bufferOverlap)
Create a new dispatcher from a stream. |
|
| Method Summary | |
|---|---|
void |
addAudioProcessor(AudioProcessor audioProcessor)
Adds an AudioProcessor to the chain of processors. |
double |
durationInSeconds()
Returns the duration of the stream in seconds. |
static AudioDispatcher |
fromByteArray(byte[] byteArray,
javax.sound.sampled.AudioFormat audioFormat,
int audioBufferSize,
int bufferOverlap)
Create a stream from an array of bytes and use that to create a new AudioDispatcher. |
static AudioDispatcher |
fromFile(java.io.File audioFile,
int size,
int overlap)
Create a stream from a file and use that to create a new AudioDispatcher |
static AudioDispatcher |
fromFloatArray(float[] floatArray,
int sampleRate,
int audioBufferSize,
int bufferOverlap)
Create a stream from an array of floats and use that to create a new AudioDispatcher. |
javax.sound.sampled.AudioFormat |
getFormat()
|
void |
removeAudioProcessor(AudioProcessor audioProcessor)
Removes an AudioProcessor to the chain of processors and calls processingFinished. |
void |
run()
|
void |
setStepSizeAndOverlap(int audioBufferSize,
int bufferOverlap)
Set a new step size and overlap size. |
void |
skip(double seconds)
Skip a number of seconds before processing the stream. |
void |
stop()
Stops dispatching audio data. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AudioDispatcher(javax.sound.sampled.AudioInputStream stream,
int audioBufferSize,
int bufferOverlap)
throws javax.sound.sampled.UnsupportedAudioFileException
stream - The stream to read data from.audioBufferSize - The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap - How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common (512, 1024) for an FFT.
javax.sound.sampled.UnsupportedAudioFileException - If an unsupported format is used.| Method Detail |
|---|
public double durationInSeconds()
public void skip(double seconds)
seconds -
public void setStepSizeAndOverlap(int audioBufferSize,
int bufferOverlap)
audioBufferSize - The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap - How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common (512, 1024) for an FFT.public void addAudioProcessor(AudioProcessor audioProcessor)
audioProcessor - The AudioProcessor to add.public void removeAudioProcessor(AudioProcessor audioProcessor)
audioProcessor - The AudioProcessor to add.public void run()
run in interface java.lang.Runnablepublic void stop()
public javax.sound.sampled.AudioFormat getFormat()
public static AudioDispatcher fromFile(java.io.File audioFile,
int size,
int overlap)
throws javax.sound.sampled.UnsupportedAudioFileException,
java.io.IOException
audioFile - The file.size - The number of samples used in the buffer.overlap -
javax.sound.sampled.UnsupportedAudioFileException - If the audio file is not supported.
java.io.IOException - When an error occurs reading the file.
public static AudioDispatcher fromByteArray(byte[] byteArray,
javax.sound.sampled.AudioFormat audioFormat,
int audioBufferSize,
int bufferOverlap)
throws javax.sound.sampled.UnsupportedAudioFileException
byteArray - An array of bytes, containing audio information.audioFormat - The format of the audio represented using the bytes.audioBufferSize - The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap - How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.
javax.sound.sampled.UnsupportedAudioFileException - If the audio format is not supported.
public static AudioDispatcher fromFloatArray(float[] floatArray,
int sampleRate,
int audioBufferSize,
int bufferOverlap)
throws javax.sound.sampled.UnsupportedAudioFileException
floatArray - An array of floats, containing audio information.sampleRate - The sample rate of the audio information contained in the buffer.audioBufferSize - The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap - How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.
javax.sound.sampled.UnsupportedAudioFileException - If the audio format is not supported.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||