be.hogent.tarsos.sampled
Class AudioDispatcher

java.lang.Object
  extended by be.hogent.tarsos.sampled.AudioDispatcher
All Implemented Interfaces:
java.lang.Runnable

public final class AudioDispatcher
extends java.lang.Object
implements java.lang.Runnable

Author:
Joren Six

Constructor Summary
AudioDispatcher(javax.sound.sampled.AudioInputStream stream, int audioBufferSize, int bufferOverlap)
          Create a new.
 
Method Summary
 void addAudioProcessor(AudioProcessor audioProcessor)
          Adds an AudioProcessor to the list of subscribers.
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 audioprocessor.
static AudioDispatcher fromFile(java.io.File audioFile, int size)
          Create a stream from a file and use that to create a new audioprocessor.
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioDispatcher

public AudioDispatcher(javax.sound.sampled.AudioInputStream stream,
                       int audioBufferSize,
                       int bufferOverlap)
                throws javax.sound.sampled.UnsupportedAudioFileException
Create a new.

Parameters:
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.
Throws:
javax.sound.sampled.UnsupportedAudioFileException - If an unsupported format is used.
Method Detail

addAudioProcessor

public void addAudioProcessor(AudioProcessor audioProcessor)
Adds an AudioProcessor to the list of subscribers.

Parameters:
audioProcessor - The AudioProcessor to add.

run

public void run()
Specified by:
run in interface java.lang.Runnable

fromFile

public static AudioDispatcher fromFile(java.io.File audioFile,
                                       int size)
                                throws javax.sound.sampled.UnsupportedAudioFileException,
                                       java.io.IOException
Create a stream from a file and use that to create a new audioprocessor.

Parameters:
audioFile - The file.
size - The number of samples used in the buffer.
Returns:
A new audioprocessor.
Throws:
javax.sound.sampled.UnsupportedAudioFileException - If the audio file is not supported.
java.io.IOException - When an error occurs reading the file.

fromByteArray

public static AudioDispatcher fromByteArray(byte[] byteArray,
                                            javax.sound.sampled.AudioFormat audioFormat,
                                            int audioBufferSize,
                                            int bufferOverlap)
                                     throws javax.sound.sampled.UnsupportedAudioFileException
Create a stream from an array of bytes and use that to create a new audioprocessor.

Parameters:
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.
Returns:
A new audioprocessor.
Throws:
javax.sound.sampled.UnsupportedAudioFileException - If the audio format is not supported.