be.hogent.tarsos.sampled
Class Player

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

public class Player
extends java.lang.Object
implements be.hogent.tarsos.dsp.AudioProcessor

Player plays audio. When the state of the audio player changes a property change is fired on the 'state' property. The player allows time stretching and volume change. Adding AudioProcessor objects before the time stretching step can implement any audio processing step.

Author:
Joren Six

Method Summary
 void addProcessorBeforeTimeStrechting(be.hogent.tarsos.dsp.AudioProcessor processor)
          Adds an audio processor to the chain before time stretching kicks in.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a change listener.
 void eject()
          Ejects the currently loaded file.
 double getCurrentTime()
           
 double getDurationInSeconds()
          If no file is loaded a illegal state exception is fired.
static Player getInstance()
           
 double getStartAt()
           
 PlayerState getState()
           
 double getStopAt()
          Returns the time at which the audio play back stops automatically.
 void increaseGain(double percent)
          Increase the gain by a defined percentage.
 void increaseTempo(double percent)
          Increase the tempo by a defined percentage.
 void load(java.io.File file)
          Loads a new audio file.
 void pauze()
          Stops the play back at current time.
 void pauze(double pauzeAt)
          Stops the play back.
 void play()
          Plays the currently loaded file.
 void play(double startTime)
           
 boolean process(be.hogent.tarsos.dsp.AudioEvent audioEvent)
           
 void processingFinished()
           
 boolean removeProcessorBeforeTimeStretching(be.hogent.tarsos.dsp.AudioProcessor processor)
          Removes an audio processor to the chain before time stretching kicks in.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes a change listener.
 void setGain(double newGain)
          Set the gain for the current stream.
 void setStopAt(double stopAt)
          At this point the sound that is played stops automatically.
 void setTempo(double newTempo)
          Set the tempo for the current stream.
 void stop()
          Stops the play back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setStopAt

public void setStopAt(double stopAt)
At this point the sound that is played stops automatically.

Parameters:
stopAt - The time at which the player stops (in seconds).

getStopAt

public double getStopAt()
Returns the time at which the audio play back stops automatically.

Returns:
The time at which the audio play back stops automatically.

load

public void load(java.io.File file)
Loads a new audio file. Throws an error if the audio format is not recognized.

Parameters:
file - The audio file to load.

eject

public void eject()
Ejects the currently loaded file.


play

public void play()
Plays the currently loaded file. Play back is started at the time of last If no file is loaded thow a illegal state exception.


play

public void play(double startTime)

pauze

public void pauze()
Stops the play back at current time.


pauze

public void pauze(double pauzeAt)
Stops the play back. When play is called, play back is resumed at the indicated time.

Parameters:
pauzeAt - The time at which to resume playing after calling play (in seconds).

stop

public void stop()
Stops the play back. When play is called, play back is resumed at 0. This is the same as pauze(0).


setGain

public void setGain(double newGain)
Set the gain for the current stream. 1 is no change, 0.8 is 80% of the volume and 2 double (watch out for clipping when using values > 1). If no stream is playing the next stream gets this gain.

Parameters:
newGain - The gain to apply to the current stream, 1 is no change, 0.8 is 80% of the volume and 2 double (watch out for clipping when using values > 1)

setTempo

public void setTempo(double newTempo)
Set the tempo for the current stream. 1 is no change, 2 is double tempo, 0.5 half. If no stream is playing the next stream gets this new tempo assigned.

Parameters:
newTempo - The new tempo for the current stream. 1 is no change, 2 is double tempo, 0.5 half.

getDurationInSeconds

public double getDurationInSeconds()
If no file is loaded a illegal state exception is fired.

Returns:
the duration in seconds of the loaded stream.

getState

public PlayerState getState()
Returns:
The current state of the player.

getStartAt

public double getStartAt()
Returns:
at which time the stream will start, in seconds, when play() is called, or at which time the current stream started.

getCurrentTime

public double getCurrentTime()
Returns:
The time in seconds of currently played buffer, or when the last stream stopped.

addProcessorBeforeTimeStrechting

public void addProcessorBeforeTimeStrechting(be.hogent.tarsos.dsp.AudioProcessor processor)
Adds an audio processor to the chain before time stretching kicks in.

Parameters:
processor - the processor to add.

removeProcessorBeforeTimeStretching

public boolean removeProcessorBeforeTimeStretching(be.hogent.tarsos.dsp.AudioProcessor processor)
Removes an audio processor to the chain before time stretching kicks in.

Parameters:
processor - the processor to remove.
Returns:
True if the specified processor is removed, false otherwise.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a change listener.

Parameters:
l - The listener to add.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a change listener.

Parameters:
l - The listener to remove.

process

public boolean process(be.hogent.tarsos.dsp.AudioEvent audioEvent)
Specified by:
process in interface be.hogent.tarsos.dsp.AudioProcessor

processingFinished

public void processingFinished()
Specified by:
processingFinished in interface be.hogent.tarsos.dsp.AudioProcessor

getInstance

public static Player getInstance()
Returns:
the player instance. Singleton design pattern.

increaseGain

public void increaseGain(double percent)
Increase the gain by a defined percentage. Negative percentages can be used.

Parameters:
percent - To increase the gain.

increaseTempo

public void increaseTempo(double percent)
Increase the tempo by a defined percentage. Negative percentages can be used.

Parameters:
percent - To increase the tempo.