com.cloudgarden.audio
Class DefaultAudioSource

java.lang.Object
  |
  +--com.cloudgarden.audio.DefaultAudioObject
        |
        +--com.cloudgarden.audio.DefaultAudioSource
All Implemented Interfaces:
AudioObject, AudioSource
Direct Known Subclasses:
AudioClientSource, AudioFileSource, AudioLineSource, AudioMediaLineSource, AudioMediaURLSource, AudioStreamSource, DefaultAudioConnector

public abstract class DefaultAudioSource
extends DefaultAudioObject
implements AudioSource

The base class which implements all the functionality of a generic AudioSource except the read method.


Field Summary
protected  boolean sending
           
protected  java.lang.Thread sendThread
           
protected  AudioSink sink
           
 
Fields inherited from class com.cloudgarden.audio.DefaultAudioObject
contentType, exception, format, listeners, paused, pauseSync, running, waiting
 
Fields inherited from interface com.cloudgarden.audio.AudioObject
END_OF_DATA
 
Constructor Summary
DefaultAudioSource()
          Creates new AudioSource
 
Method Summary
 void drain()
          Blocks until END_OF_DATA is written to or read from this AudioObject.
 AudioSink getSink()
          Returns the AudioSink set using setSink
 boolean isSending()
          Returns true if the thread started by the startSending method is still writing data to the AudioSink.
 int read(byte[] data, int len)
          Convenience method - should call read(data, 0, len)
 void setAudioFormat(javax.sound.sampled.AudioFormat format)
          Sets the AudioFormat for this AudioObject.
 void setBufferSize(int size)
           
 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 setSink(AudioSink sink)
          Sets the sink for this source - this method should also call the setSource method on the sink object (making sure to avaoid an endless loop) to ensure that source and sink are connected to each other (and not to different sinks/sources).
 void startSending()
          This method should start a thread which repeatedly writes data to the AudioSink object which this object is connected to, until it writes data with length END_OF_DATA, or until the stopSending method is called.
 void stopSending()
           
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioObject
addTransferListener, blockWhilePaused, blockWhileWaiting, bytesTransferred, canSetAudioFormat, getAudioFormat, getContentType, getLastException, isPaused, isWaiting, removeTransferListener, setPaused
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.cloudgarden.audio.AudioSource
read
 
Methods inherited from interface com.cloudgarden.audio.AudioObject
addTransferListener, canSetAudioFormat, getAudioFormat, getContentType, isPaused, isWaiting, removeTransferListener, setPaused
 

Field Detail

sendThread

protected java.lang.Thread sendThread

sending

protected boolean sending

sink

protected AudioSink sink
Constructor Detail

DefaultAudioSource

public DefaultAudioSource()
Creates new AudioSource
Method Detail

isSending

public boolean isSending()
Description copied from interface: AudioSource
Returns true if the thread started by the startSending method is still writing data to the AudioSink.
Specified by:
isSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

setBufferSize

public void setBufferSize(int size)

read

public int read(byte[] data,
                int len)
         throws java.io.IOException
Description copied from interface: AudioSource
Convenience method - should call read(data, 0, len)
Specified by:
read in interface AudioSource

startSending

public void startSending()
                  throws java.io.IOException
Description copied from interface: AudioSource
This method should start a thread which repeatedly writes data to the AudioSink object which this object is connected to, until it writes data with length END_OF_DATA, or until the stopSending method is called. If an error occurs while the thread is sending data it could be detected by calling the drain method.
Specified by:
startSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
Throws:
an - IOException if the source is unable to start sending data - for example, if an audio file is unable to be opened to supply the data to be sent.
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink), AudioObject.drain()

stopSending

public void stopSending()
Specified by:
stopSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

setSink

public void setSink(AudioSink sink)
             throws java.io.IOException
Description copied from interface: AudioSource
Sets the sink for this source - this method should also call the setSource method on the sink object (making sure to avaoid an endless loop) to ensure that source and sink are connected to each other (and not to different sinks/sources). Also ensures continuity of the AudioFormat and ContentType (as described below).

If the sink's AudioFormat is null or the sink's format differs from this AudioSource's format, then the sink's format is set equal to that of this AudioSource.

If the sink's AudioFormat is not null and this AudioSource's format is null then this AudioSource's format is set equal to the sink's.

The same is done for the ContentType as described above for the AudioFormat.

Note: if the sink is an AudioConverter then the get/setIncomingAudioFormat method is called instead of get/setAudioFormat.

Specified by:
setSink in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.getSink()

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
Overrides:
setAudioFormat in class DefaultAudioObject
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()

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
Overrides:
setContentType in class DefaultAudioObject

getSink

public AudioSink getSink()
Description copied from interface: AudioSource
Returns the AudioSink set using setSink
Specified by:
getSink in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink)

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
Overrides:
drain in class DefaultAudioObject