Package be.tarsos.dsp.io.jvm
Class AudioPlayer
java.lang.Object
be.tarsos.dsp.io.jvm.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 LineWavelet is the Java Sound object that actually makes the sound. The write method on LineWavelet 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
Constructors Constructor Description AudioPlayer(TarsosDSPAudioFormat format)
AudioPlayer(TarsosDSPAudioFormat format, int bufferSize)
AudioPlayer(javax.sound.sampled.AudioFormat format)
Creates a new audio player.AudioPlayer(javax.sound.sampled.AudioFormat format, int bufferSize)
-
Method Summary
Modifier and Type Method Description long
getMicroSecondPosition()
boolean
process(AudioEvent audioEvent)
Process the audio event.void
processingFinished()
Notify the AudioProcessor that no more data is available and processing has finished.
-
Constructor Details
-
AudioPlayer
public AudioPlayer(javax.sound.sampled.AudioFormat format) throws javax.sound.sampled.LineUnavailableExceptionCreates a new audio player.- Parameters:
format
- The AudioFormat of the buffer.- Throws:
javax.sound.sampled.LineUnavailableException
- If no output LineWavelet is available.
-
AudioPlayer
public AudioPlayer(javax.sound.sampled.AudioFormat format, int bufferSize) throws javax.sound.sampled.LineUnavailableException- Throws:
javax.sound.sampled.LineUnavailableException
-
AudioPlayer
public AudioPlayer(TarsosDSPAudioFormat format, int bufferSize) throws javax.sound.sampled.LineUnavailableException- Throws:
javax.sound.sampled.LineUnavailableException
-
AudioPlayer
public AudioPlayer(TarsosDSPAudioFormat format) throws javax.sound.sampled.LineUnavailableException- Throws:
javax.sound.sampled.LineUnavailableException
-
-
Method Details
-
getMicroSecondPosition
public long getMicroSecondPosition() -
process
Description copied from interface:AudioProcessor
Process the audio event. Do the actual signal processing on an (optionally) overlapping buffer.- Specified by:
process
in interfaceAudioProcessor
- 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 interfaceAudioProcessor
-