Package samer.audio

Class FileSource2

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


    public class FileSource2
    extends Viewable
    implements AudioSource
    An AudioSource that read from multiple audio files. 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. An EOFException is thrown if an attempt is made to read beyond the end of the last file. FileSource2 is a Viewable called "playlist", and an Agent with commands next, view.
    • Constructor Summary

      Constructors 
      Constructor and Description
      FileSource2(javax.sound.sampled.AudioFormat targetFormat, java.util.List<java.io.File> files)
      Construct a FileSource2.
    • Method Summary

      All Methods Static 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
      static java.util.List<java.io.File> directory(java.io.File dir, java.lang.String ext)
      Set playlist to all WAV files in given directory
      void dispose() 
      void execute(java.lang.String cmd, Environment env) 
      int getChannels() 
      void getCommands(Agent.Registry r) 
      java.io.File getFile()
      Returns current file
      java.util.List<java.io.File> getPlaylist() 
      float getRate() 
      javax.sound.sampled.AudioFormat getTargetFormat()
      The requested audio format.
      Viewer getViewer() 
      boolean isOpen() 
      void next()
      Move to head of next file in playlist
      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.
      int readInto(java.nio.ByteBuffer buf, int offset, int len) 
      • Methods inherited from class java.lang.Object

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

      • FileSource2

        public FileSource2(javax.sound.sampled.AudioFormat targetFormat,
                           java.util.List<java.io.File> files)
        Construct a FileSource2.
    • Method Detail

      • getFile

        public java.io.File getFile()
        Returns current file
      • getTargetFormat

        public javax.sound.sampled.AudioFormat getTargetFormat()
        The requested audio format.
      • directory

        public static java.util.List<java.io.File> directory(java.io.File dir,
                                                             java.lang.String ext)
        Set playlist to all WAV files in given directory
      • getPlaylist

        public java.util.List<java.io.File> getPlaylist()
      • next

        public void next()
                  throws java.lang.Exception
        Move to head of next file in playlist
        Throws:
        java.lang.Exception
      • 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
      • readInto

        public int readInto(java.nio.ByteBuffer buf,
                            int offset,
                            int len)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • 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
      • getCommands

        public void getCommands(Agent.Registry r)
      • execute

        public void execute(java.lang.String cmd,
                            Environment env)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getViewer

        public Viewer getViewer()