be.hogent.tarsos.dsp
Class AudioPlayer

java.lang.Object
  extended by be.hogent.tarsos.dsp.AudioPlayer
All Implemented Interfaces:
AudioProcessor

public final class AudioPlayer
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
AudioPlayer(javax.sound.sampled.AudioFormat format)
          Creates a new audio player.
 
Method Summary
 boolean process(AudioEvent audioEvent)
          Process the audio event.
 void processingFinished()
          Notify the AudioProcessor that no more data is available and processing has finished.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioPlayer

public AudioPlayer(javax.sound.sampled.AudioFormat format)
            throws javax.sound.sampled.LineUnavailableException
Creates a new audio player.

Parameters:
format - The AudioFormat of the buffer.
Throws:
javax.sound.sampled.LineUnavailableException - If no output line is available.
Method Detail

process

public boolean process(AudioEvent audioEvent)
Description copied from interface: AudioProcessor
Process the audio event. Do the actual signal processing on an (optionally) overlapping buffer.

Specified by:
process in interface AudioProcessor
Parameters:
audioEvent - The audio event that contains audio data.
Returns:
False if the chain needs to stop here, true otherwise. This can be used to implement e.g. a silence detector.

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