Package samer.audio

Class FileSource

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


    public class FileSource
    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. 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. FileSource is a Viewable called "playlist", and an Agent with commands next, prev, reopen, view, select, loop. Properties read from current environment:
    current
    Current file (String)
    loop
    Loop playlist? (Boolean) [true]
    • Constructor Summary

      Constructors 
      Constructor and Description
      FileSource()
      Construct a FileSource 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() 
      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 getStreamFormat()
      The actual format of the stream in.
      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.
      void prev()
      Move to head of previous file in playlist
      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) 
      void reopen()
      Reopen current file, so that next read will be from head of file.
      void rewind()
      Go back to start of playlist.
      void setBuffering(boolean b) 
      void setDirectory(java.io.File dir, java.lang.String ext)
      Set playlist to all WAV files in given directory
      void setLoop(boolean f)
      If true then loop playlist, otherwise, an Exception will be thrown when the end of the playlist is reached.
      void setPlaylist(java.util.List<java.io.File> l) 
      void setTargetFormat(javax.sound.sampled.AudioFormat f) 
      • Methods inherited from class java.lang.Object

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

      • FileSource

        public FileSource()
        Construct a FileSource initialised with current file and loop initialised from the current Environment. No exception is thrown if the current file cannot be opened, however, you must be sure to set it to a valid file (or to set a playlist) before trying to read any samples.
    • Method Detail

      • getFile

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

        public void setBuffering(boolean b)
      • getStreamFormat

        public javax.sound.sampled.AudioFormat getStreamFormat()
        The actual format of the stream in. May not be same as target format.
      • getTargetFormat

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

        public void setTargetFormat(javax.sound.sampled.AudioFormat f)
      • setLoop

        public void setLoop(boolean f)
        If true then loop playlist, otherwise, an Exception will be thrown when the end of the playlist is reached. If there is no playlist, then looping applies to the current file only.
      • setDirectory

        public void setDirectory(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()
      • setPlaylist

        public void setPlaylist(java.util.List<java.io.File> l)
      • rewind

        public void rewind()
                    throws java.lang.Exception
        Go back to start of playlist. Next block of samples will be from head of first file in playlist. Will throw an exception if there is no playlist
        Throws:
        java.lang.Exception
      • next

        public void next()
                  throws java.lang.Exception
        Move to head of next file in playlist
        Throws:
        java.lang.Exception
      • prev

        public void prev()
                  throws java.lang.Exception
        Move to head of previous 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
      • reopen

        public void reopen()
                    throws java.lang.Exception
        Reopen current file, so that next read will be from head of 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()