wavFiles
Class ByteConverter

java.lang.Object
  extended by wavFiles.ByteConverter
Direct Known Subclasses:
ByteConverterAifInt16, ByteConverterAifInt24, ByteConverterAifInt32, ByteConverterAifInt8, ByteConverterWavInt16, ByteConverterWavInt24, ByteConverterWavInt32, ByteConverterWavInt8

public abstract class ByteConverter
extends java.lang.Object

Classes to convert between various wav and aif stream formats and double data scaled from -1 to +1 for PAMGUARD.

The double data will often need to be packed into a nChan*nSamples 2D array, so provide functionality for this as well as packing single channels of data.

Wav files follow a Windows standard of little endienness and Aif files follow the Mac/Linux standard of bigendienness. Java is Bigendian.

Author:
Doug Gillespie

Constructor Summary
ByteConverter()
           
 
Method Summary
abstract  int bytesToDouble(byte[] byteData, double[][] doubleData, int numBytes)
          Converts a byte array into a double array.
static ByteConverter createByteConverter(javax.sound.sampled.AudioFormat audioFormat)
           
static ByteConverter createByteConverter(int bytesPerSample, boolean bigEndian, javax.sound.sampled.AudioFormat.Encoding encoding)
          Create a byte converter based on the number of bytes per sample and on the endienness of the byte data.
abstract  int doubleToBytes(double[][] doubleData, byte[] byteData, int numSamples)
          Converts a double array into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteConverter

public ByteConverter()
Method Detail

createByteConverter

public static ByteConverter createByteConverter(int bytesPerSample,
                                                boolean bigEndian,
                                                javax.sound.sampled.AudioFormat.Encoding encoding)
Create a byte converter based on the number of bytes per sample and on the endienness of the byte data.

Parameters:
bytesPerSample - number of bytes per sample (1,2,3 or 4)
bigEndian - true if it's big Endian data, false for small Endians.
Returns:
byte converter for that format.

createByteConverter

public static ByteConverter createByteConverter(javax.sound.sampled.AudioFormat audioFormat)

bytesToDouble

public abstract int bytesToDouble(byte[] byteData,
                                  double[][] doubleData,
                                  int numBytes)
Converts a byte array into a double array. The double array can be longer than required to hold the byte array in which case remaining doubles will be left untouched and not set to zero.

Parameters:
byteData - byte data
doubleData - double data
Returns:
number of doubles converted

doubleToBytes

public abstract int doubleToBytes(double[][] doubleData,
                                  byte[] byteData,
                                  int numSamples)
Converts a double array into a byte array. The byte array can be longer than required to hold the double data in which case remaining bytes will be left untouched and not set to zero.

Parameters:
doubleData - double data
byteData - byte data
Returns:
number of bytes converted