Package samer.audio

Class StreamSource

  • java.lang.Object
    • samer.audio.StreamSource
  • All Implemented Interfaces:
    AudioSource


    public class StreamSource
    extends java.lang.Object
    implements AudioSource
    An AudioSource that read from an input stream. Can read any format for which the appropriate JavaSound plug-in is installed on your system, eg WAV, AU, MP3, OGG. The implementation of AudioSource.reader() returns a Task which gets samples from the audio files, going through the play list one by one. If the loop flag is true, then samples are returned indefinitely by looping through the playlist; otherwise, an EOFException is thrown if an attempt is made to read beyond the end of the last file. Properties read from current environment:
    current
    Current file (String)
    loop
    Loop playlist? (Boolean) [true]
    • Constructor Summary

      Constructors 
      Constructor and Description
      StreamSource(java.io.File file) 
      StreamSource(java.io.InputStream s) 
      StreamSource(java.net.URL url) 
      StreamSource(javax.sound.sampled.AudioInputStream s)
      Construct a StreamSource initialised with current file and loop initialised from the current Environment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int available()
      Returns number of bytes available in current file
      void close()
      Closes current input stream
      void dispose() 
      int getChannels() 
      javax.sound.sampled.AudioFormat getFormat() 
      float getRate() 
      boolean isOpen() 
      void open()
      Opens the playlist starting with the first file.
      Task reader(double[] dbuf, int off, int len)
      Returns a Task which copies samples as doubles into the given buffer between the given positions.
      Task reader(float[] dbuf, int off, int len)
      Returns a Task which copies samples as floats into the given buffer between the given positions.
      void setTargetFormat(javax.sound.sampled.AudioFormat f)
      Returns current file
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StreamSource

        public StreamSource(java.io.File file)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • StreamSource

        public StreamSource(java.io.InputStream s)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • StreamSource

        public StreamSource(java.net.URL url)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • StreamSource

        public StreamSource(javax.sound.sampled.AudioInputStream s)
                     throws java.lang.Exception
        Construct a StreamSource initialised with current file and loop initialised from the current Environment. No exception is thrown if the current file
        Throws:
        java.lang.Exception
    • Method Detail

      • setTargetFormat

        public void setTargetFormat(javax.sound.sampled.AudioFormat f)
        Returns current file
      • getFormat

        public javax.sound.sampled.AudioFormat getFormat()
      • close

        public void close()
        Closes current input stream
        Specified by:
        close in interface AudioSource
      • open

        public void open()
                  throws java.lang.Exception
        Opens the playlist starting with the first file.
        Specified by:
        open in interface AudioSource
        Throws:
        java.lang.Exception
      • available

        public int available()
                      throws java.lang.Exception
        Returns number of bytes available in current file
        Throws:
        java.lang.Exception
      • reader

        public Task reader(double[] dbuf,
                           int off,
                           int len)
        Returns a Task which copies samples as doubles into the given buffer between the given positions.
        Specified by:
        reader in interface AudioSource
      • reader

        public Task reader(float[] dbuf,
                           int off,
                           int len)
        Returns a Task which copies samples as floats into the given buffer between the given positions.
        Specified by:
        reader in interface AudioSource