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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 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

      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