at.ofai.music.beatroot

Class AudioFile

public class AudioFile extends Object

A simple class for reading audio data from files.
Field Summary
protected AudioInputStreamaudioIn
The stream from which audio is read (after conversion if necessary)
protected intchannels
The number of channels in the audio stream
protected AudioFormatformat
The format of the audio data
protected floatframeRate
The sampling rate
protected intframeSize
The size of an audio frame (i.e. one sample for each channel)
protected longlength
The amount of audio data in bytes
protected Stringpath
The path name of the audio file (relative or absolute)
RandomAccessInputStreamunderlyingStream
The raw stream from which data is read
Constructor Summary
AudioFile(String pathName)
Constructor
Method Summary
static voidmain(String[] args)
Unit test for reading audio from jar file
intread(byte[] buffer)
Reads some number of bytes from the audio input stream and stores them into the buffer array.
int[]read()
Reads a mono 16-bit audio file and returns the whole file as an int array
doublesetPosition(double time)
Moves the read pointer to the specified time in seconds.
longsetPosition(long position)
Moves the read pointer to the specified byte position.
StringtoString()
Returns a String representation of the audio file, consisting of path name, length and frame size.

Field Detail

audioIn

protected 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 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 String path
The path name of the audio file (relative or absolute)

underlyingStream

private RandomAccessInputStream underlyingStream
The raw stream from which data is read

Constructor Detail

AudioFile

public AudioFile(String pathName)
Constructor

Parameters: pathName The relative or absolute path name of the audio file

Method Detail

main

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

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

setPosition

public double setPosition(double time)
Moves the read pointer to the specified time in seconds.

setPosition

public long setPosition(long position)
Moves the read pointer to the specified byte position.

toString

public String toString()
Returns a String representation of the audio file, consisting of path name, length and frame size.