com.cloudgarden.audio
Class DefaultAudioSink

java.lang.Object
  |
  +--com.cloudgarden.audio.DefaultAudioObject
        |
        +--com.cloudgarden.audio.DefaultAudioSink
All Implemented Interfaces:
AudioObject, AudioSink
Direct Known Subclasses:
AudioClientSink, AudioFileSink, AudioLineSink, AudioMediaLineSink, AudioMediaURLSink, AudioSplitter

public abstract class DefaultAudioSink
extends DefaultAudioObject
implements AudioSink

The base class which implements all the functionality of a generic AudioSink except the write method.


Field Summary
protected  java.lang.Thread getThread
           
protected  boolean getting
           
protected  AudioSource source
           
 
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
DefaultAudioSink()
          Creates new AudioSink
DefaultAudioSink(AudioSource src)
          Creates a DefaultAudioSink and calls setSource(src).
 
Method Summary
 AudioSource getSource()
          Returns the AudioSource set by setSource
 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 setSource(AudioSource source)
          Sets the source for this sink - this method also calls the setSink method on the source object (while avoiding an endless loop) to ensure that sink and source are connected to each other (and not to different sinks/sources).
 int write(byte[] data, int len)
          Convenience method - should call write(data, 0, len)
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioObject
addTransferListener, blockWhilePaused, blockWhileWaiting, bytesTransferred, canSetAudioFormat, drain, 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.AudioSink
write
 
Methods inherited from interface com.cloudgarden.audio.AudioObject
addTransferListener, canSetAudioFormat, drain, getAudioFormat, getContentType, isPaused, isWaiting, removeTransferListener, setPaused
 

Field Detail

getThread

protected java.lang.Thread getThread

getting

protected boolean getting

source

protected AudioSource source
Constructor Detail

DefaultAudioSink

public DefaultAudioSink()
Creates new AudioSink

DefaultAudioSink

public DefaultAudioSink(AudioSource src)
                 throws java.io.IOException
Creates a DefaultAudioSink and calls setSource(src).
Method Detail

write

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

setSource

public void setSource(AudioSource source)
               throws java.io.IOException
Sets the source for this sink - this method also calls the setSink method on the source object (while avoiding an endless loop) to ensure that sink and source are connected to each other (and not to different sinks/sources). Also ensures continuity of the AudioFormat and ContentType (as described below).

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

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

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

Specified by:
setSource in interface AudioSink
See Also:
getSource()

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

getSource

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