org.tritonus.share.sampled
Class TConversionTool

java.lang.Object
  extended byorg.tritonus.share.sampled.TConversionTool

public class TConversionTool
extends Object

Useful methods for converting audio data.

Author:
Florian Bomers, Matthias Pfisterer

Constructor Summary
TConversionTool()
           
 
Method Summary
static short alaw2linear(byte ulawbyte)
           
static void alaw2pcm16(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean bigEndian)
          Fills outBuffer with pcm signed 16 bit samples.
static void alaw2pcm8(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean signed)
          Fills outBuffer with alaw samples.
static void alaw2pcm8(byte[] buffer, int byteOffset, int sampleCount, boolean signed)
          Converts an alaw buffer to 8bit pcm samples The 8bit bytes overwrite the original alaw values.
static byte alaw2ulaw(byte sample)
           
static void alaw2ulaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
          Fills outBuffer with ulaw samples.
static void alaw2ulaw(byte[] buffer, int byteOffset, int sampleCount)
          Converts a buffer of aLaw samples to uLaw.
static int bytesToInt16(byte[] buffer, int byteOffset, boolean bigEndian)
          Converts 2 successive bytes starting at byteOffset in buffer to a signed integer sample with 16bit range.
static int bytesToInt16(byte highByte, byte lowByte)
          Converts 2 bytes to a signed integer sample with 16bit range.
static int bytesToInt24(byte[] buffer, int byteOffset, boolean bigEndian)
          Converts 3 successive bytes starting at byteOffset in buffer to a signed integer sample with 24bit range.
static int bytesToInt32(byte[] buffer, int byteOffset, boolean bigEndian)
          Converts a 4 successive bytes starting at byteOffset in buffer to a signed 32bit integer sample.
static short bytesToShort16(byte[] buffer, int byteOffset, boolean bigEndian)
          Converts 2 successive bytes starting at byteOffset in buffer to a signed sample of type short.
static short bytesToShort16(byte highByte, byte lowByte)
          Converts 2 bytes to a signed sample of type short.
static void changeOrderOrSign(byte[] inBuffer, int nInOffset, byte[] outBuffer, int nOutOffset, int nByteLength, int nBytesPerSample)
           
static void changeOrderOrSign(byte[] buffer, int nOffset, int nByteLength, int nBytesPerSample)
           
static void convertSign8(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
           
static void convertSign8(byte[] buffer, int byteOffset, int sampleCount)
           
static void intToBytes16(int sample, byte[] buffer, int byteOffset, boolean bigEndian)
          Converts a 16 bit sample of type int to 2 bytes in an array.
static void intToBytes24(int sample, byte[] buffer, int byteOffset, boolean bigEndian)
          Converts a 24 bit sample of type int to 3 bytes in an array.
static void intToBytes32(int sample, byte[] buffer, int byteOffset, boolean bigEndian)
          Converts a 32 bit sample of type int to 4 bytes in an array.
static byte linear2alaw(short pcm_val)
           
static byte linear2ulaw(int sample)
          Converts a linear signed 16bit sample to a uLaw byte.
static void pcm162alaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean bigEndian)
          Fills outBuffer with alaw samples.
static void pcm162alaw(byte[] buffer, int byteOffset, int sampleCount, boolean bigEndian)
          Converts a buffer of signed 16bit big endian samples to uLaw.
static void pcm162ulaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean bigEndian)
          Fills outBuffer with ulaw samples.
static void pcm162ulaw(byte[] buffer, int byteOffset, int sampleCount, boolean bigEndian)
          Converts a buffer of signed 16bit big endian samples to uLaw.
static void pcm82alaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean signed)
          Fills outBuffer with alaw samples.
static void pcm82alaw(byte[] buffer, int byteOffset, int sampleCount, boolean signed)
          Converts a buffer of 8bit samples to alaw.
static void pcm82ulaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean signed)
          Fills outBuffer with ulaw samples.
static void pcm82ulaw(byte[] buffer, int byteOffset, int sampleCount, boolean signed)
          Converts a buffer of 8bit samples to uLaw.
static void shortToBytes16(short sample, byte[] buffer, int byteOffset, boolean bigEndian)
          Converts a sample of type short to 2 bytes in an array.
static void swapOrder16(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
           
static void swapOrder16(byte[] buffer, int byteOffset, int sampleCount)
           
static void swapOrder24(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
           
static void swapOrder24(byte[] buffer, int byteOffset, int sampleCount)
           
static void swapOrder32(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
           
static void swapOrder32(byte[] buffer, int byteOffset, int sampleCount)
           
static byte ulaw2alaw(byte sample)
           
static void ulaw2alaw(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount)
          Fills outBuffer with alaw samples.
static void ulaw2alaw(byte[] buffer, int byteOffset, int sampleCount)
          Converts a buffer of uLaw samples to aLaw.
static short ulaw2linear(byte ulawbyte)
           
static void ulaw2pcm16(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean bigEndian)
          Fills outBuffer with pcm signed 16 bit samples.
static void ulaw2pcm8(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount, boolean signed)
          Fills outBuffer with ulaw samples.
static void ulaw2pcm8(byte[] buffer, int byteOffset, int sampleCount, boolean signed)
          Inplace-conversion of a ulaw buffer to 8bit samples.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TConversionTool

public TConversionTool()
Method Detail

convertSign8

public static void convertSign8(byte[] buffer,
                                int byteOffset,
                                int sampleCount)

swapOrder16

public static void swapOrder16(byte[] buffer,
                               int byteOffset,
                               int sampleCount)

swapOrder24

public static void swapOrder24(byte[] buffer,
                               int byteOffset,
                               int sampleCount)

swapOrder32

public static void swapOrder32(byte[] buffer,
                               int byteOffset,
                               int sampleCount)

convertSign8

public static void convertSign8(byte[] inBuffer,
                                int inByteOffset,
                                byte[] outBuffer,
                                int outByteOffset,
                                int sampleCount)

swapOrder16

public static void swapOrder16(byte[] inBuffer,
                               int inByteOffset,
                               byte[] outBuffer,
                               int outByteOffset,
                               int sampleCount)

swapOrder24

public static void swapOrder24(byte[] inBuffer,
                               int inByteOffset,
                               byte[] outBuffer,
                               int outByteOffset,
                               int sampleCount)

swapOrder32

public static void swapOrder32(byte[] inBuffer,
                               int inByteOffset,
                               byte[] outBuffer,
                               int outByteOffset,
                               int sampleCount)

bytesToShort16

public static short bytesToShort16(byte highByte,
                                   byte lowByte)
Converts 2 bytes to a signed sample of type short.

This is a reference function.


bytesToShort16

public static short bytesToShort16(byte[] buffer,
                                   int byteOffset,
                                   boolean bigEndian)
Converts 2 successive bytes starting at byteOffset in buffer to a signed sample of type short.

For little endian, buffer[byteOffset] is interpreted as low byte, whereas it is interpreted as high byte in big endian.

This is a reference function.


bytesToInt16

public static int bytesToInt16(byte highByte,
                               byte lowByte)
Converts 2 bytes to a signed integer sample with 16bit range.

This is a reference function.


bytesToInt16

public static int bytesToInt16(byte[] buffer,
                               int byteOffset,
                               boolean bigEndian)
Converts 2 successive bytes starting at byteOffset in buffer to a signed integer sample with 16bit range.

For little endian, buffer[byteOffset] is interpreted as low byte, whereas it is interpreted as high byte in big endian.

This is a reference function.


bytesToInt24

public static int bytesToInt24(byte[] buffer,
                               int byteOffset,
                               boolean bigEndian)
Converts 3 successive bytes starting at byteOffset in buffer to a signed integer sample with 24bit range.

For little endian, buffer[byteOffset] is interpreted as lowest byte, whereas it is interpreted as highest byte in big endian.

This is a reference function.


bytesToInt32

public static int bytesToInt32(byte[] buffer,
                               int byteOffset,
                               boolean bigEndian)
Converts a 4 successive bytes starting at byteOffset in buffer to a signed 32bit integer sample.

For little endian, buffer[byteOffset] is interpreted as lowest byte, whereas it is interpreted as highest byte in big endian.

This is a reference function.


shortToBytes16

public static void shortToBytes16(short sample,
                                  byte[] buffer,
                                  int byteOffset,
                                  boolean bigEndian)
Converts a sample of type short to 2 bytes in an array. sample is interpreted as signed (as Java does).

For little endian, buffer[byteOffset] is filled with low byte of sample, and buffer[byteOffset+1] is filled with high byte of sample.

For big endian, this is reversed.

This is a reference function.


intToBytes16

public static void intToBytes16(int sample,
                                byte[] buffer,
                                int byteOffset,
                                boolean bigEndian)
Converts a 16 bit sample of type int to 2 bytes in an array. sample is interpreted as signed (as Java does).

For little endian, buffer[byteOffset] is filled with low byte of sample, and buffer[byteOffset+1] is filled with high byte of sample + sign bit.

For big endian, this is reversed.

Before calling this function, it should be assured that sample is in the 16bit range - it will not be clipped.

This is a reference function.


intToBytes24

public static void intToBytes24(int sample,
                                byte[] buffer,
                                int byteOffset,
                                boolean bigEndian)
Converts a 24 bit sample of type int to 3 bytes in an array. sample is interpreted as signed (as Java does).

For little endian, buffer[byteOffset] is filled with low byte of sample, and buffer[byteOffset+2] is filled with the high byte of sample + sign bit.

For big endian, this is reversed.

Before calling this function, it should be assured that sample is in the 24bit range - it will not be clipped.

This is a reference function.


intToBytes32

public static void intToBytes32(int sample,
                                byte[] buffer,
                                int byteOffset,
                                boolean bigEndian)
Converts a 32 bit sample of type int to 4 bytes in an array. sample is interpreted as signed (as Java does).

For little endian, buffer[byteOffset] is filled with lowest byte of sample, and buffer[byteOffset+3] is filled with the high byte of sample + sign bit.

For big endian, this is reversed.

This is a reference function.


linear2ulaw

public static byte linear2ulaw(int sample)
Converts a linear signed 16bit sample to a uLaw byte. Ported to Java by fb.
Originally by:
Craig Reese: IDA/Supercomputing Research Center
Joe Campbell: Department of Defense
29 September 1989


ulaw2linear

public static short ulaw2linear(byte ulawbyte)

pcm162ulaw

public static void pcm162ulaw(byte[] buffer,
                              int byteOffset,
                              int sampleCount,
                              boolean bigEndian)
Converts a buffer of signed 16bit big endian samples to uLaw. The uLaw bytes overwrite the original 16 bit values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount/2 bytes.


pcm162ulaw

public static void pcm162ulaw(byte[] inBuffer,
                              int inByteOffset,
                              byte[] outBuffer,
                              int outByteOffset,
                              int sampleCount,
                              boolean bigEndian)
Fills outBuffer with ulaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount*2 bytes read from inBuffer; There will be sampleCount bytes written to outBuffer.


pcm82ulaw

public static void pcm82ulaw(byte[] buffer,
                             int byteOffset,
                             int sampleCount,
                             boolean signed)
Converts a buffer of 8bit samples to uLaw. The uLaw bytes overwrite the original 8 bit values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount bytes.


pcm82ulaw

public static void pcm82ulaw(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount,
                             boolean signed)
Fills outBuffer with ulaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes written to outBuffer.


ulaw2pcm16

public static void ulaw2pcm16(byte[] inBuffer,
                              int inByteOffset,
                              byte[] outBuffer,
                              int outByteOffset,
                              int sampleCount,
                              boolean bigEndian)
Fills outBuffer with pcm signed 16 bit samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes read from inBuffer; There will be sampleCount*2 bytes written to outBuffer.


ulaw2pcm8

public static void ulaw2pcm8(byte[] buffer,
                             int byteOffset,
                             int sampleCount,
                             boolean signed)
Inplace-conversion of a ulaw buffer to 8bit samples. The 8bit bytes overwrite the original ulaw values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount bytes.


ulaw2pcm8

public static void ulaw2pcm8(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount,
                             boolean signed)
Fills outBuffer with ulaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes written to outBuffer.


linear2alaw

public static byte linear2alaw(short pcm_val)

alaw2linear

public static short alaw2linear(byte ulawbyte)

pcm162alaw

public static void pcm162alaw(byte[] buffer,
                              int byteOffset,
                              int sampleCount,
                              boolean bigEndian)
Converts a buffer of signed 16bit big endian samples to uLaw. The uLaw bytes overwrite the original 16 bit values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount/2 bytes.


pcm162alaw

public static void pcm162alaw(byte[] inBuffer,
                              int inByteOffset,
                              byte[] outBuffer,
                              int outByteOffset,
                              int sampleCount,
                              boolean bigEndian)
Fills outBuffer with alaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount*2 bytes read from inBuffer; There will be sampleCount bytes written to outBuffer.


pcm82alaw

public static void pcm82alaw(byte[] buffer,
                             int byteOffset,
                             int sampleCount,
                             boolean signed)
Converts a buffer of 8bit samples to alaw. The alaw bytes overwrite the original 8 bit values. The first byte-offset of the aLaw bytes is byteOffset. It will be written sampleCount bytes.


pcm82alaw

public static void pcm82alaw(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount,
                             boolean signed)
Fills outBuffer with alaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes written to outBuffer.


alaw2pcm8

public static void alaw2pcm8(byte[] buffer,
                             int byteOffset,
                             int sampleCount,
                             boolean signed)
Converts an alaw buffer to 8bit pcm samples The 8bit bytes overwrite the original alaw values. The first byte-offset of the aLaw bytes is byteOffset. It will be written sampleCount bytes.


alaw2pcm8

public static void alaw2pcm8(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount,
                             boolean signed)
Fills outBuffer with alaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes written to outBuffer.


alaw2pcm16

public static void alaw2pcm16(byte[] inBuffer,
                              int inByteOffset,
                              byte[] outBuffer,
                              int outByteOffset,
                              int sampleCount,
                              boolean bigEndian)
Fills outBuffer with pcm signed 16 bit samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes read from inBuffer; There will be sampleCount*2 bytes written to outBuffer.


ulaw2alaw

public static byte ulaw2alaw(byte sample)

ulaw2alaw

public static void ulaw2alaw(byte[] buffer,
                             int byteOffset,
                             int sampleCount)
Converts a buffer of uLaw samples to aLaw.


ulaw2alaw

public static void ulaw2alaw(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount)
Fills outBuffer with alaw samples.


alaw2ulaw

public static byte alaw2ulaw(byte sample)

alaw2ulaw

public static void alaw2ulaw(byte[] buffer,
                             int byteOffset,
                             int sampleCount)
Converts a buffer of aLaw samples to uLaw. The uLaw bytes overwrite the original aLaw values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount bytes.


alaw2ulaw

public static void alaw2ulaw(byte[] inBuffer,
                             int inByteOffset,
                             byte[] outBuffer,
                             int outByteOffset,
                             int sampleCount)
Fills outBuffer with ulaw samples. reading starts from inBuffer[inByteOffset]. writing starts at outBuffer[outByteOffset]. There will be sampleCount bytes written to outBuffer.


changeOrderOrSign

public static void changeOrderOrSign(byte[] buffer,
                                     int nOffset,
                                     int nByteLength,
                                     int nBytesPerSample)

changeOrderOrSign

public static void changeOrderOrSign(byte[] inBuffer,
                                     int nInOffset,
                                     byte[] outBuffer,
                                     int nOutOffset,
                                     int nByteLength,
                                     int nBytesPerSample)