wavFiles
Class WavFile

java.lang.Object
  extended by wavFiles.WavFile

public class WavFile
extends java.lang.Object


Field Summary
private  java.io.File file
           
private  java.lang.String fileMode
           
private  java.lang.String fileName
           
private  byte[] tempByteArray
           
private  WavHeader wavHeader
           
private  WindowsFile windowsFile
           
 
Constructor Summary
WavFile(java.lang.String fileName, java.lang.String fileMode)
          Open a wav file for reading or writing.
 
Method Summary
 void close()
           
protected  void finalize()
           
 WavHeader getWavHeader()
           
private  boolean openForReading()
           
 boolean positionAtData()
           
private  int readData(byte[] byteArray)
          Read a number of bytes from the wav file.
 int readData(double[][] doubleArray)
          Read data into a preallocated double array.
 WavHeader readWavHeader()
           
private  boolean reportError(java.lang.String warningText)
           
private  void unpackInt16(double[][] doubleArray, byte[] tempByteArray, int samplesRead)
          Unpack an array of 16 bit integer data in little endian format.
private  void unpackInt24(double[][] doubleArray, byte[] tempByteArray, int samplesRead)
          Unpack a byte array of data in little endian format.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

private java.io.File file

fileName

private java.lang.String fileName

fileMode

private java.lang.String fileMode

windowsFile

private WindowsFile windowsFile

wavHeader

private WavHeader wavHeader

tempByteArray

private byte[] tempByteArray
Constructor Detail

WavFile

public WavFile(java.lang.String fileName,
               java.lang.String fileMode)
Open a wav file for reading or writing.

Currently only supports reading

Parameters:
fileName - file name with full path
fileMode - mode = "r" for read or "w" for write
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

openForReading

private boolean openForReading()

readWavHeader

public WavHeader readWavHeader()

getWavHeader

public WavHeader getWavHeader()
Returns:
the wavHeader

positionAtData

public boolean positionAtData()

reportError

private boolean reportError(java.lang.String warningText)

close

public void close()

readData

private int readData(byte[] byteArray)
Read a number of bytes from the wav file.

Parameters:
byteArray - byte array preallocated to desired length
Returns:
number of bytes actually read.

readData

public int readData(double[][] doubleArray)
Read data into a preallocated double array. The array should be 2 D, with the first dim being the number of channels, the second the number of samples to read.

Parameters:
doubleArray - double array to receive data
Returns:
number of samples read (should be doubleArray[0].length if no EOF)

unpackInt16

private void unpackInt16(double[][] doubleArray,
                         byte[] tempByteArray,
                         int samplesRead)
Unpack an array of 16 bit integer data in little endian format.

Parameters:
doubleArray -
tempByteArray -
samplesRead -

unpackInt24

private void unpackInt24(double[][] doubleArray,
                         byte[] tempByteArray,
                         int samplesRead)
Unpack a byte array of data in little endian format.

Parameters:
doubleArray -
tempByteArray -
samplesRead -