be.hogent.tarsos.sampled
Class BlockingAudioPlayer

java.lang.Object
  extended by be.hogent.tarsos.sampled.BlockingAudioPlayer
All Implemented Interfaces:
AudioProcessor

public final class BlockingAudioPlayer
extends java.lang.Object
implements AudioProcessor

This AudioProcessor can be used to sync events with sound. It uses a pattern described in JavaFX Special Effects Taking Java RIA to the Extreme with Animation, Multimedia, and Game Element Chapter 9 page 185:

The variable line is the Java Sound object that actually makes the sound. The write method on line is interesting because it blocks until it is ready for more data.
If this AudioProcessor chained with other AudioProcessors the others should be able to operate in real time or process the signal on a separate thread.

Author:
Joren Six

Constructor Summary
BlockingAudioPlayer(javax.sound.sampled.AudioFormat format, int bufferSize, int overlap)
          Creates a new BlockingAudioPlayer.
 
Method Summary
 void processFull(float[] audioFloatBuffer, byte[] audioByteBuffer)
          Process the first (complete) buffer.
 void processingFinished()
          Notify the AudioProcessor that no more data is available and processing has finished.
 void processOverlapping(float[] audioBuffer, byte[] audioByteBuffer)
          Do the actual signal processing on an overlapping buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingAudioPlayer

public BlockingAudioPlayer(javax.sound.sampled.AudioFormat format,
                           int bufferSize,
                           int overlap)
                    throws javax.sound.sampled.LineUnavailableException
Creates a new BlockingAudioPlayer.

Parameters:
format - The AudioFormat of the buffer.
bufferSize - The size of each buffer in samples (not in bytes).
overlap - Defines how much consecutive buffers overlap in samples (not in bytes).
Throws:
javax.sound.sampled.LineUnavailableException - If no output line is available.
Method Detail

processFull

public void processFull(float[] audioFloatBuffer,
                        byte[] audioByteBuffer)
Description copied from interface: AudioProcessor
Process the first (complete) buffer. Once the first complete buffer is processed the remaining buffers are overlapping buffers and processed using the processOverlapping method (Even if overlap is zero).

Specified by:
processFull in interface AudioProcessor
Parameters:
audioFloatBuffer - The buffer to process using the float data type.
audioByteBuffer - The buffer to process using raw bytes.

processOverlapping

public void processOverlapping(float[] audioBuffer,
                               byte[] audioByteBuffer)
Description copied from interface: AudioProcessor
Do the actual signal processing on an overlapping buffer. Once the first complete buffer is processed the remaining buffers are overlapping buffers and are processed using the processOverlapping method. Even if overlap is zero.

Specified by:
processOverlapping in interface AudioProcessor
Parameters:
audioBuffer - The buffer to process using the float data type.
audioByteBuffer - The buffer to process using raw bytes.

processingFinished

public void processingFinished()
Description copied from interface: AudioProcessor
Notify the AudioProcessor that no more data is available and processing has finished. Can be used to deallocate resources or cleanup.

Specified by:
processingFinished in interface AudioProcessor