ccs.audio
Class AudioController

java.lang.Object
  extended by ccs.audio.AudioController
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class AudioController
extends java.lang.Object
implements java.beans.PropertyChangeListener

The main audio back-end object. MT-UNSAFE. This classes methods must only be invoked from a single thread. In most applications, this will be the Swing dispatch thread.


Field Summary
static java.lang.String LOGNAME
          The name of the Logger the audio system uses to log lifecycle events.
static java.lang.String STATENAME
          The name of the state property.
 
Constructor Summary
AudioController(Playlist playlist, int fifoSize, float lineSeconds, Hurlable hurl, boolean isAbortOnUnderrun)
          Create an AudioController.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Changes in the controller's state are broadcast to interested listeners as changes in the "state" property.
 void changeTrack(TrackChange motion)
          Track change.
 void close()
          Closedown.
 int getFIFOPercent()
          Get the current FIFO fill in %
 javax.sound.sampled.AudioFormat getFormat()
           
 Hurlable getHurlable()
           
 TrackState getState()
           
 long microsecondPosition()
           
 void pause()
          If a track is currently running (playing), pauses it.
 void play()
          If a track is currently ready (paused), starts it.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Responds to property changes from package internals.
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
           
 void setAutoStart(boolean isAutostart)
          Set whether a track should automatically start playing when it's ready.
 void setMasterGain(float dB)
          Set the master gain.
 void setTrackMode(TrackMode mode)
          Set the track mode.
 void stop()
          Stop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATENAME

public static final java.lang.String STATENAME
The name of the state property. Changes to this property are broadcast to PropertyChangeListeners.

See Also:
Constant Field Values

LOGNAME

public static final java.lang.String LOGNAME
The name of the Logger the audio system uses to log lifecycle events. Use the logging API to manipulate it.

See Also:
Constant Field Values
Constructor Detail

AudioController

public AudioController(Playlist playlist,
                       int fifoSize,
                       float lineSeconds,
                       Hurlable hurl,
                       boolean isAbortOnUnderrun)
Create an AudioController.

Parameters:
playlist - The playlist to play tracks from.
fifoSize - The size of the FIFO buffer. This is used to smooth out transient data starves when playing over a network. Minimum 256 KiB; the minimum should be OK for lightly loaded connections. Increasing it improves robustness in the face of stressed network connections, but increases application footprint and latency before starting the first track. (So don't go too mad.)
lineSeconds - The duration of the line buffer. This contains decoded (PCM) samples and is accessible by the low-level audio system. Increasing it may avoid playback glitches on machines with poor multithreading performance or long thread time-slices. 1.0 seconds recommended for most cases. Line buffer costs 176KiB per second, so don't go too mad here either.
hurl - A hurlable for reporting errors from the system. This hurlable will only be called from the Swing dispatch thread. If null, errors will cause a FAULT status, but the details will be lost.
isAbortOnUnderrun - If the FIFO empties completely while playing a track, the AudioController can suspend playback until the FIFO buffer fills back up again. However, this doesn't always work; sometimes the audio decoder libraries can't recover from this situation, and don't come back online when the buffer has been refilled. Alternatively, the AudioController can simply report this as a fault, and not attempt to fix it. To have the AudioController attempt to recover from an underrun, set this false; allows playback to continue, *maybe*, in adverse conditions, but doesn't always work. To have it abort instead, set this true.
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Changes in the controller's state are broadcast to interested listeners as changes in the "state" property.


removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)

getHurlable

public Hurlable getHurlable()
Returns:
The hurlable which was supplied for reporting exceptions.

getState

public TrackState getState()
Returns:
The current state of the controller. Don't poll this - register as a property-change listener instead.

getFormat

public javax.sound.sampled.AudioFormat getFormat()
Returns:
The current audio format, if there is one. Else null.

microsecondPosition

public long microsecondPosition()
Returns:
The current position in the track, if there is one. Else -1L.

changeTrack

public void changeTrack(TrackChange motion)
Track change. The user has manually changed to a new track. Call this to start things off, typically with FIRST.


play

public void play()
If a track is currently ready (paused), starts it. Otherwise does nothing.


pause

public void pause()
If a track is currently running (playing), pauses it. Otherwise does nothing.


stop

public void stop()
Stop. Cancels all tracks and downloads.


close

public void close()
Closedown. Stops, and releases the audio system. For use during shutdown.


setTrackMode

public void setTrackMode(TrackMode mode)
Set the track mode.


setAutoStart

public void setAutoStart(boolean isAutostart)
Set whether a track should automatically start playing when it's ready.


setMasterGain

public void setMasterGain(float dB)
Set the master gain. Allowed values are in dB, -12 to +12.


getFIFOPercent

public int getFIFOPercent()
Get the current FIFO fill in %


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Responds to property changes from package internals. Undocumented.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener