at.ofai.music.beatroot
Class AudioFile

java.lang.Object
  extended by at.ofai.music.beatroot.AudioFile

public class AudioFile
extends java.lang.Object

A simple class for reading audio data from files.


Field Summary
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)
private  at.ofai.music.util.RandomAccessInputStream underlyingStream
          The raw stream from which data is read
 
Constructor Summary
AudioFile(java.lang.String pathName)
          Constructor
 
Method Summary
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

path

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


underlyingStream

private at.ofai.music.util.RandomAccessInputStream underlyingStream
The raw stream from which data is read


audioIn

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


format

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


length

protected long length
The amount of audio data in bytes


frameSize

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


frameRate

protected float frameRate
The sampling rate


channels

protected int channels
The number of channels in the audio stream

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