com.icdif.audio.io
Class WavDecoder

java.lang.Object
  extended by com.icdif.audio.io.WavDecoder
All Implemented Interfaces:
AudioDecoder

public class WavDecoder
extends java.lang.Object
implements AudioDecoder

This class implements the AudioDecoder Interface and is responsible for decoding the audio data from a wave file, i.e. transforming the bytes in pcm format to arrays of float that we can easily analyze and plot.

Author:
wanderer

Constructor Summary
WavDecoder(java.io.InputStream stream)
          Constructor that initializes the stream from where we read the pcm data.
 
Method Summary
 float getSampleRate()
          Gets the sample rate of the audio to be decoded
 int readSamples(float[] samples)
          Reads in samples from the decoder and fills the array passed as parameter with the values read (It tries to read as many samples from the stream as there are elements in the array passed in).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WavDecoder

public WavDecoder(java.io.InputStream stream)
           throws java.lang.Exception
Constructor that initializes the stream from where we read the pcm data. It also reads the header of this stream and checks if it really is valid.

Parameters:
stream - The Wave file as a stream
Throws:
java.lang.Exception - When it's not possible to read from the file
Method Detail

readSamples

public int readSamples(float[] samples)
Description copied from interface: AudioDecoder
Reads in samples from the decoder and fills the array passed as parameter with the values read (It tries to read as many samples from the stream as there are elements in the array passed in). Returns the actual number read in. If this number is smaller than samples.length then the end of stream has been reached. Note: In the present version, it averages from all the channels into a single channel.

Specified by:
readSamples in interface AudioDecoder
Parameters:
samples - The array to which it will write the samples read.
Returns:
The number of read samples.

getSampleRate

public float getSampleRate()
Description copied from interface: AudioDecoder
Gets the sample rate of the audio to be decoded

Specified by:
getSampleRate in interface AudioDecoder
Returns:
the sample rate