com.cloudgarden.audio
Class AudioLineSource

java.lang.Object
  |
  +--com.cloudgarden.audio.DefaultAudioObject
        |
        +--com.cloudgarden.audio.DefaultAudioSource
              |
              +--com.cloudgarden.audio.AudioLineSource
All Implemented Interfaces:
AudioObject, AudioSource

public class AudioLineSource
extends DefaultAudioSource

AudioSource wrapper for a TargetDataLine.


Fields inherited from class com.cloudgarden.audio.DefaultAudioSource
sending, sendThread, 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
AudioLineSource(javax.sound.sampled.AudioFormat format)
          Creates a TargetDataLine with the given AudioFormat, opens and starts it.
AudioLineSource(AudioSink sink)
          Creates an AudioLineSource to push data to the given AudioSink, with the same AudioFormat as the AudioSink.
AudioLineSource(int rate, int bits, int chans, boolean signed, boolean bigEndian)
          Creates a TargetDataLine with the given AudioFormat parameters and opens it.
AudioLineSource(javax.sound.sampled.TargetDataLine line)
          Creates new AudioLineSource using the given line, opens and starts the line.
 
Method Summary
 boolean canSetAudioFormat()
          The AudioFormat is set when the AudioLineSource is created and cannot be changed, since the TargetDataLine cannot change its format once created.
 void close()
          Closes the line
 void drain()
          Calls DefaultAudioSource.drain, then drains and stops the line.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Returns the AudioFormat for this AudioObject.
 javax.sound.sampled.TargetDataLine getLine()
          Returns the TargetDataLine used by this AudioSource
 void open()
          Opens the line.
 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 setAudioFormat(javax.sound.sampled.AudioFormat format)
          Sets the AudioFormat for this AudioObject.
 void startSending()
          Opens the TargetDataLine, if not already open, starts it, and calls DefaultAudioSource's startSending method.
 void stopSending()
          Stops the line and calls DefaultAudioSource.stopSending();
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioSource
getSink, isSending, read, setBufferSize, setContentType, setSink
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioObject
addTransferListener, blockWhilePaused, blockWhileWaiting, bytesTransferred, 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.AudioObject
addTransferListener, getContentType, isPaused, isWaiting, removeTransferListener, setPaused
 

Constructor Detail

AudioLineSource

public AudioLineSource(javax.sound.sampled.TargetDataLine line)
                throws javax.sound.sampled.LineUnavailableException
Creates new AudioLineSource using the given line, opens and starts the line.

AudioLineSource

public AudioLineSource(int rate,
                       int bits,
                       int chans,
                       boolean signed,
                       boolean bigEndian)
                throws javax.sound.sampled.LineUnavailableException
Creates a TargetDataLine with the given AudioFormat parameters and opens it.

AudioLineSource

public AudioLineSource(javax.sound.sampled.AudioFormat format)
                throws javax.sound.sampled.LineUnavailableException
Creates a TargetDataLine with the given AudioFormat, opens and starts it.

AudioLineSource

public AudioLineSource(AudioSink sink)
                throws javax.sound.sampled.LineUnavailableException,
                       java.io.IOException
Creates an AudioLineSource to push data to the given AudioSink, with the same AudioFormat as the AudioSink.
Method Detail

getAudioFormat

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

getLine

public javax.sound.sampled.TargetDataLine getLine()
Returns the TargetDataLine used by this AudioSource

canSetAudioFormat

public boolean canSetAudioFormat()
The AudioFormat is set when the AudioLineSource is created and cannot be changed, since the TargetDataLine cannot change its format once created.
Overrides:
canSetAudioFormat in class DefaultAudioObject

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.

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

read

public int read(byte[] data,
                int offset,
                int len)
         throws java.io.IOException
Description copied from interface: AudioSource
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.
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink), AudioSink#startGetting, AudioObject.setPaused(boolean)

startSending

public void startSending()
                  throws java.io.IOException
Opens the TargetDataLine, if not already open, starts it, and calls DefaultAudioSource's startSending method.
Overrides:
startSending in class DefaultAudioSource
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()

drain

public void drain()
           throws java.io.IOException
Calls DefaultAudioSource.drain, then drains and stops the line.
Overrides:
drain in class DefaultAudioSource

stopSending

public void stopSending()
Stops the line and calls DefaultAudioSource.stopSending();
Overrides:
stopSending in class DefaultAudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

close

public void close()
Closes the line

open

public void open()
          throws javax.sound.sampled.LineUnavailableException
Opens the line.