com.cycling74.msp
Class AudioFileBuffer

java.lang.Object
  extended by com.cycling74.msp.AudioFileBuffer

public class AudioFileBuffer
extends java.lang.Object

A utility class for loading audio data off of disk and into memory. The data is translated from the native file format into the the floating point format used by msp.


Field Summary
 float[][] buf
          buf contains the audio samples loaded off of disk deinterleaved by channel into a 2 dimensional floating point array.
static int FINISHED_READING
          If an instance of MessageReceiver is passed into the constructor the FINISHED_READING message will be sent to it when the requested file is successfully loaded into memory.
 
Constructor Summary
AudioFileBuffer(java.lang.String filename)
          Constructor.
AudioFileBuffer(java.lang.String filename, MessageReceiver client)
          Constructor.
 
Method Summary
 int getChannels()
          Get the number of channels of the current audio file.
 long getFrameLength()
          Get the number of sample frames in the audio file.A frame consists of sample data for all channels at a particular instant in time.Thus a mono audio file which has 1000 samples will have a frame length of 1000 with each frame containing one sample.
 float getLengthMs()
          Get the length of the current audio file in milliseconds.
 float getSampleRate()
          Get the sample rate of the current audio file.
 int getSampleSizeInBits()
          Get the sample size in bits of the current audio file.
 boolean isBigEndian()
          Was the current audio file big endian format.
 void open(java.lang.String filename)
          Load a different audio file into memory using this instance of AudioFileBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FINISHED_READING

public static final int FINISHED_READING
If an instance of MessageReceiver is passed into the constructor the FINISHED_READING message will be sent to it when the requested file is successfully loaded into memory. File loading occurs asynchronously.

See Also:
Constant Field Values

buf

public float[][] buf
buf contains the audio samples loaded off of disk deinterleaved by channel into a 2 dimensional floating point array. The first dimension corresponds to the audio channel and the second dimension corresponds to the audio data itself. Thus a stereo audio file would have the samples for the left channel at buf[0][0...framelength - 1] and the right channel at buf[1][0...framelength - 1]

Constructor Detail

AudioFileBuffer

public AudioFileBuffer(java.lang.String filename)
                throws java.io.FileNotFoundException,
                       java.io.IOException,
                       javax.sound.sampled.UnsupportedAudioFileException
Constructor.

Parameters:
filename - Absolute native path of the audio file to be loaded into memory.
Throws:
java.io.FileNotFoundException
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

AudioFileBuffer

public AudioFileBuffer(java.lang.String filename,
                       MessageReceiver client)
                throws java.io.FileNotFoundException,
                       java.io.IOException,
                       javax.sound.sampled.UnsupportedAudioFileException
Constructor.

Parameters:
filename - Absolute native path of the audio file to be loaded into memory.
client - instance of MessageReceiver which will be notified when file is finished being loaded into memory. This information may or may not be relevant since the member buffer,buf[][], containing the audio data will be valid and zero filled when the constructor returns.
Throws:
java.io.FileNotFoundException
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException
Method Detail

open

public void open(java.lang.String filename)
          throws java.io.FileNotFoundException,
                 java.io.IOException,
                 javax.sound.sampled.UnsupportedAudioFileException
Load a different audio file into memory using this instance of AudioFileBuffer. Previous audio data is disgarded and buf[][] member variable reflects the number of channels and framesize of the new audio file..

Parameters:
filename - Absolute native path of the audio file to be loaded into memory.
Throws:
java.io.FileNotFoundException
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

getSampleRate

public float getSampleRate()
Get the sample rate of the current audio file. It is important to note that the current msp sampling rate is currently not considered when the audio file is being decoded from disk. This means that an audio file saved with a different sampling rate from the current msp sampling rate needs additional sample rate conversion done on its audio data after it is loaded to play back at the expected speed. This conversion is currently not done by default.


getSampleSizeInBits

public int getSampleSizeInBits()
Get the sample size in bits of the current audio file. For example, 8,16,24.


isBigEndian

public boolean isBigEndian()
Was the current audio file big endian format.


getFrameLength

public long getFrameLength()
Get the number of sample frames in the audio file.A frame consists of sample data for all channels at a particular instant in time.Thus a mono audio file which has 1000 samples will have a frame length of 1000 with each frame containing one sample. A stereo audio file with 2000 samples would have a frame length of 1000 with each frame containing 2 samples, one for each the left and right channels.


getChannels

public int getChannels()
Get the number of channels of the current audio file.


getLengthMs

public float getLengthMs()
Get the length of the current audio file in milliseconds. This is equivalent to:
 frame length / (sample rate / 1000)