com.cloudgarden.audio
Class DefaultAudioObject

java.lang.Object
  |
  +--com.cloudgarden.audio.DefaultAudioObject
All Implemented Interfaces:
AudioObject
Direct Known Subclasses:
DefaultAudioClient, DefaultAudioSink, DefaultAudioSource

public abstract class DefaultAudioObject
extends java.lang.Object
implements AudioObject

The base class which implements the functionality of a generic AudioObject.


Field Summary
protected  java.lang.String contentType
           
protected  java.io.IOException exception
           
protected  javax.sound.sampled.AudioFormat format
           
protected  java.util.Vector listeners
           
protected  boolean paused
           
protected  java.lang.Object pauseSync
           
protected  boolean running
           
protected  boolean waiting
           
 
Fields inherited from interface com.cloudgarden.audio.AudioObject
END_OF_DATA
 
Constructor Summary
DefaultAudioObject()
           
 
Method Summary
 void addTransferListener(TransferListener listener)
          Adds a TransferListener to receive notification when data is passed to or from this AudioObject
protected  void blockWhilePaused()
          Blocks while paused is true - should be used by classes extending this class to block in the write method.
 void blockWhileWaiting()
          Blocks while isWaiting returns false
protected  void bytesTransferred(byte[] data, int offset, int numBytes, int direction)
          Notifies any TransferListeners that bytes are about to be transferred (either read or written).
 boolean canSetAudioFormat()
          Returns false if the AudioFormat cannot be set - eg some Recognizers may not be able to change their input format, so the CGAudioManager (which is an AudioSink) for that Recognizer will return false here.
 void drain()
          Blocks until END_OF_DATA is written to or read from this AudioObject.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Returns the AudioFormat for this AudioObject.
 java.lang.String getContentType()
           
 java.lang.Exception getLastException()
           
 boolean isPaused()
           
 boolean isWaiting()
          Returns true if no data has yet been written or read from this AudioObject
 void removeTransferListener(TransferListener listener)
           
 void setAudioFormat(javax.sound.sampled.AudioFormat format)
          Sets the AudioFormat for this AudioObject.
 void setContentType(java.lang.String contentType)
          Sets the content type for this AudioObject - contentType must be one of the FileTypeDescriptor String fields, eg MPEG_AUDIO.
 void setPaused(boolean paused)
          If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

running

protected boolean running

waiting

protected boolean waiting

paused

protected boolean paused

format

protected javax.sound.sampled.AudioFormat format

exception

protected java.io.IOException exception

contentType

protected java.lang.String contentType

pauseSync

protected java.lang.Object pauseSync

listeners

protected java.util.Vector listeners
Constructor Detail

DefaultAudioObject

public DefaultAudioObject()
Method Detail

drain

public void drain()
           throws java.io.IOException
Description copied from interface: AudioObject
Blocks until END_OF_DATA is written to or read from this AudioObject. For sinks such as an AudioLineSink, or sources such as AudioLineSource should also drain the line.
Specified by:
drain in interface AudioObject

setAudioFormat

public void setAudioFormat(javax.sound.sampled.AudioFormat format)
                    throws java.io.IOException
Description copied from interface: AudioObject
Sets the AudioFormat for this AudioObject. If this object is connected to an AudioSource or an AudioSink, then the source/sink's AudioFormat is set equal to that of this AudioObject. Note: if the sink is an AudioConverter then the setIncomingAudioFormat method is called instead of setAudioFormat.

This ensures that the AudioFormat is uniform along a set of connected AudioObjects until the format is changed by an AudioConverter.

Specified by:
setAudioFormat in interface AudioObject
Following copied from interface: com.cloudgarden.audio.AudioObject
Throws:
java.io.IOException - if unable to set the AudioFormat for any reason (eg. if canSetAudioFormat returns false and setAudioFormat is used to try to change the AudioFormat).
See Also:
AudioObject.getAudioFormat()

canSetAudioFormat

public boolean canSetAudioFormat()
Description copied from interface: AudioObject
Returns false if the AudioFormat cannot be set - eg some Recognizers may not be able to change their input format, so the CGAudioManager (which is an AudioSink) for that Recognizer will return false here.
Specified by:
canSetAudioFormat in interface AudioObject

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Description copied from interface: AudioObject
Returns the AudioFormat for this AudioObject.
Specified by:
getAudioFormat in interface AudioObject
Following copied from interface: com.cloudgarden.audio.AudioObject
See Also:
AudioObject.setAudioFormat(javax.sound.sampled.AudioFormat)

isWaiting

public boolean isWaiting()
Returns true if no data has yet been written or read from this AudioObject
Specified by:
isWaiting in interface AudioObject

blockWhileWaiting

public void blockWhileWaiting()
Blocks while isWaiting returns false

blockWhilePaused

protected void blockWhilePaused()
Blocks while paused is true - should be used by classes extending this class to block in the write method.
See Also:
AudioSink.write(byte[], int, int), AudioObject.setPaused(boolean)

setPaused

public void setPaused(boolean paused)
Description copied from interface: AudioObject
If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called.
Specified by:
setPaused in interface AudioObject

isPaused

public boolean isPaused()
Specified by:
isPaused in interface AudioObject

getLastException

public java.lang.Exception getLastException()

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface AudioObject
Following copied from interface: com.cloudgarden.audio.AudioObject
See Also:
setContentType

setContentType

public void setContentType(java.lang.String contentType)
                    throws java.io.IOException
Description copied from interface: AudioObject
Sets the content type for this AudioObject - contentType must be one of the FileTypeDescriptor String fields, eg MPEG_AUDIO.
Specified by:
setContentType in interface AudioObject

addTransferListener

public void addTransferListener(TransferListener listener)
Description copied from interface: AudioObject
Adds a TransferListener to receive notification when data is passed to or from this AudioObject
Specified by:
addTransferListener in interface AudioObject

removeTransferListener

public void removeTransferListener(TransferListener listener)
Specified by:
removeTransferListener in interface AudioObject
Following copied from interface: com.cloudgarden.audio.AudioObject
See Also:
addTransferListener

bytesTransferred

protected void bytesTransferred(byte[] data,
                                int offset,
                                int numBytes,
                                int direction)
Notifies any TransferListeners that bytes are about to be transferred (either read or written). The actual data is passed in this method call, so this allows the data to be analysed or processed before it is written to this AudioObject or read from it. The direction parameter is either TransferListener.WRITE or TransferListener.READ