com.cloudgarden.audio
Interface AudioSource

All Superinterfaces:
AudioObject
All Known Subinterfaces:
AudioConnector, AudioConverter
All Known Implementing Classes:
AudioServerSource, AudioSplitter, CGAudioManager, DefaultAudioSource

public interface AudioSource
extends AudioObject

An interface representing a class which generates audio data, and which can be connected to an AudioSink.


Fields inherited from interface com.cloudgarden.audio.AudioObject
END_OF_DATA
 
Method Summary
 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)
 int read(byte[] data, int offset, int len)
          Used to read data from this source - called by the AudioSink which this source is connected to (if its startGetting method is used) so need not be called explicitly by an application.
 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 interface com.cloudgarden.audio.AudioObject
addTransferListener, canSetAudioFormat, drain, getAudioFormat, getContentType, isPaused, isWaiting, removeTransferListener, setAudioFormat, setContentType, setPaused
 

Method Detail

read

public int read(byte[] data,
                int offset,
                int len)
         throws java.io.IOException
Used to read data from this source - called by the AudioSink which this source is connected to (if its startGetting method is used) so need not be called explicitly by an application. Blocks if this source is paused. Returns the number of bytes read, or END_OF_DATA if all the available data has been read - eg if the end of a file has been reached, or if the stopSending() method has been called.
See Also:
setSink(com.cloudgarden.audio.AudioSink), AudioSink#startGetting, AudioObject.setPaused(boolean)

read

public int read(byte[] data,
                int len)
         throws java.io.IOException
Convenience method - should call read(data, 0, len)

startSending

public void startSending()
                  throws java.io.IOException
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.
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:
setSink(com.cloudgarden.audio.AudioSink), AudioObject.drain()

stopSending

public void stopSending()
See Also:
startSending()

isSending

public boolean isSending()
Returns true if the thread started by the startSending method is still writing data to the AudioSink.
See Also:
startSending()

setSink

public void setSink(AudioSink sink)
             throws java.io.IOException
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.

See Also:
getSink()

getSink

public AudioSink getSink()
Returns the AudioSink set using setSink
See Also:
setSink(com.cloudgarden.audio.AudioSink)