Package wavFiles

Class ByteConverter

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

public abstract class ByteConverter extends 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 Details

    • ByteConverter

      public ByteConverter()
  • Method Details

    • createByteConverter

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

      WAV files are in little endian format AIFF files are in big endian format AU files are in big endian format. Java uses big endian irrespective of platform. Therefore wav files need to be byte swapped, AIFF and AU files don't.

      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(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