Class AudioFile

  • java.lang.Object
    • at.ofai.music.beatroot.AudioFile


  • public class AudioFile
    extends java.lang.Object
    A simple class for reading audio data from files.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected javax.sound.sampled.AudioInputStream audioIn
      The stream from which audio is read (after conversion if necessary)
      protected int channels
      The number of channels in the audio stream
      protected javax.sound.sampled.AudioFormat format
      The format of the audio data
      protected float frameRate
      The sampling rate
      protected int frameSize
      The size of an audio frame (i.e.
      protected long length
      The amount of audio data in bytes
      protected java.lang.String path
      The path name of the audio file (relative or absolute)
    • Constructor Summary

      Constructors 
      Constructor and Description
      AudioFile(java.lang.String pathName)
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static void main(java.lang.String[] args)
      Unit test for reading audio from jar file
      int[] read()
      Reads a mono 16-bit audio file and returns the whole file as an int array
      int read(byte[] buffer)
      Reads some number of bytes from the audio input stream and stores them into the buffer array.
      double setPosition(double time)
      Moves the read pointer to the specified time in seconds.
      long setPosition(long position)
      Moves the read pointer to the specified byte position.
      java.lang.String toString()
      Returns a String representation of the audio file, consisting of path name, length and frame size.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • audioIn

        protected javax.sound.sampled.AudioInputStream audioIn
        The stream from which audio is read (after conversion if necessary)
      • channels

        protected int channels
        The number of channels in the audio stream
      • format

        protected javax.sound.sampled.AudioFormat format
        The format of the audio data
      • frameRate

        protected float frameRate
        The sampling rate
      • frameSize

        protected int frameSize
        The size of an audio frame (i.e. one sample for each channel)
      • length

        protected long length
        The amount of audio data in bytes
      • path

        protected java.lang.String path
        The path name of the audio file (relative or absolute)
    • Constructor Detail

      • AudioFile

        public AudioFile(java.lang.String pathName)
        Constructor
        Parameters:
        pathName - The relative or absolute path name of the audio file
    • Method Detail

      • toString

        public java.lang.String toString()
        Returns a String representation of the audio file, consisting of path name, length and frame size.
        Overrides:
        toString in class java.lang.Object
      • setPosition

        public double setPosition(double time)
                           throws java.io.IOException
        Moves the read pointer to the specified time in seconds.
        Throws:
        java.io.IOException
      • setPosition

        public long setPosition(long position)
                         throws java.io.IOException
        Moves the read pointer to the specified byte position.
        Throws:
        java.io.IOException
      • read

        public int read(byte[] buffer)
        Reads some number of bytes from the audio input stream and stores them into the buffer array.
        Parameters:
        buffer - The buffer for storing audio data
        Returns:
        The number of bytes read, or -1 if there is no more data (EOS)
      • read

        public int[] read()
        Reads a mono 16-bit audio file and returns the whole file as an int array
        Returns:
        The content of the audio file
      • main

        public static void main(java.lang.String[] args)
        Unit test for reading audio from jar file