com.cloudgarden.audio
Class AudioFileSource

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

public class AudioFileSource
extends DefaultAudioSource

AudioSource wrapper for a File, enabling audio data to be read from a File.


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
AudioFileSource(java.io.File file)
          Creates new AudioFileSource
 
Method Summary
static javax.sound.sampled.AudioFormat convertToLittleEndian(javax.sound.sampled.AudioFormat fmt)
          Utility method which returns an AudioFormat which has the same sampleRate, sampleSize and channels as the original, but with littleEndian format.
static javax.sound.sampled.AudioInputStream convertToLittleEndian(javax.sound.sampled.AudioInputStream stream)
          Utility method which returns an AudioInputStream which has the same sampleRate, sampleSize and channels as the original, but with littleEndian format.
 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 reopen()
          Reopens the file so it can be read from the start again
 void startSending()
          Starts a thread which reads audio data from the file.
 void stopSending()
           
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioSource
drain, getSink, isSending, read, setAudioFormat, setBufferSize, setContentType, setSink
 
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.AudioObject
addTransferListener, canSetAudioFormat, getAudioFormat, getContentType, isPaused, isWaiting, removeTransferListener, setPaused
 

Constructor Detail

AudioFileSource

public AudioFileSource(java.io.File file)
                throws javax.sound.sampled.UnsupportedAudioFileException,
                       java.io.IOException
Creates new AudioFileSource
Method Detail

reopen

public void reopen()
            throws javax.sound.sampled.UnsupportedAudioFileException,
                   java.io.IOException
Reopens the file so it can be read from the start again

convertToLittleEndian

public static javax.sound.sampled.AudioFormat convertToLittleEndian(javax.sound.sampled.AudioFormat fmt)
Utility method which returns an AudioFormat which has the same sampleRate, sampleSize and channels as the original, but with littleEndian format.

convertToLittleEndian

public static javax.sound.sampled.AudioInputStream convertToLittleEndian(javax.sound.sampled.AudioInputStream stream)
Utility method which returns an AudioInputStream which has the same sampleRate, sampleSize and channels as the original, but with littleEndian format.

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
Starts a thread which reads audio data from the file.
Overrides:
startSending in class DefaultAudioSource
Throws:
an - IOException if the file cannot be opened for reading

stopSending

public void stopSending()
Overrides:
stopSending in class DefaultAudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()