sound
Class AudioFormatUtils

java.lang.Object
  extended by sound.AudioFormatUtils

public class AudioFormatUtils
extends java.lang.Object


Constructor Summary
AudioFormatUtils()
           
 
Method Summary
static double[] bytesToSamples(byte[] byteArray, int offset, int length, int bytesPerSample, boolean signedData)
          Converts a byte array into an array of samples (a double).
static short[] get16BitAudioData(javax.sound.sampled.AudioFormat format, byte[] audioBytes)
           
static javax.sound.sampled.AudioFormat get44khzLinear16bitMonoSignedBigEndianFormat()
           
static javax.sound.sampled.AudioFormat get8000Linear16bitMonoSignedBigEndianFormat()
           
static javax.sound.sampled.AudioFormat get8khzMono8Format()
           
static javax.sound.sampled.AudioFileFormat.Type getAudioFileType()
           
static javax.sound.sampled.AudioFormat getCDLinearPcmFormat()
          Use 16 bit mono CD quality (44.1 khz sample rate with 16 bits per sample.
static javax.sound.sampled.AudioFormat getDefaultAudioFormat()
           
static double[] getDoubleData(javax.sound.sampled.AudioFormat format, byte[] audioBytes)
           
static javax.sound.sampled.AudioFileFormat.Type getSourceType()
           
static boolean isPcm(javax.sound.sampled.AudioFormat.Encoding encoding)
          Checks if the encoding is PCM.
static double[] littleEndianBytesToSamples(byte[] data, int offset, int length, int bytesPerSample, boolean signed)
          Converts a little-endian byte array into an array of samples (double).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioFormatUtils

public AudioFormatUtils()
Method Detail

getCDLinearPcmFormat

public static javax.sound.sampled.AudioFormat getCDLinearPcmFormat()
Use 16 bit mono CD quality (44.1 khz sample rate with 16 bits per sample.

Returns:
signed linear pcm coded data. Big Endian format

getDefaultAudioFormat

public static javax.sound.sampled.AudioFormat getDefaultAudioFormat()

get8khzMono8Format

public static javax.sound.sampled.AudioFormat get8khzMono8Format()
Returns:
little endian 8khz linear 8bit format. Unsigned.

get8000Linear16bitMonoSignedBigEndianFormat

public static javax.sound.sampled.AudioFormat get8000Linear16bitMonoSignedBigEndianFormat()

get44khzLinear16bitMonoSignedBigEndianFormat

public static javax.sound.sampled.AudioFormat get44khzLinear16bitMonoSignedBigEndianFormat()

get16BitAudioData

public static short[] get16BitAudioData(javax.sound.sampled.AudioFormat format,
                                        byte[] audioBytes)

getDoubleData

public static double[] getDoubleData(javax.sound.sampled.AudioFormat format,
                                     byte[] audioBytes)

bytesToSamples

public static double[] bytesToSamples(byte[] byteArray,
                                      int offset,
                                      int length,
                                      int bytesPerSample,
                                      boolean signedData)
                               throws java.lang.ArrayIndexOutOfBoundsException
Converts a byte array into an array of samples (a double). Each consecutive bytes in the byte array are converted into a double, and becomes the next element in the double array. The size of the returned array is (length/bytesPerDouble). Currently, only 1 byte (8-bit) or 2 bytes (16-bit) samples are supported.

Parameters:
byteArray - a byte array
offset - which byte to start from
length - how many bytes to convert
bytesPerSample - the number of bytes per sample
signedData - whether the data is signed
Returns:
a double array, or null if byteArray is of zero length
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown only if you go off the end of the array

littleEndianBytesToSamples

public static double[] littleEndianBytesToSamples(byte[] data,
                                                  int offset,
                                                  int length,
                                                  int bytesPerSample,
                                                  boolean signed)
                                           throws java.lang.ArrayIndexOutOfBoundsException
Converts a little-endian byte array into an array of samples (double). Each consecutive bytes of a float are converted into a double, and becomes the next element in the double array. The number of bytes in the double is specified as an argument. The size of the returned array is (data.length/bytesPerSample).

Parameters:
data - a byte array
offset - which byte to start from
length - how many bytes to convert
bytesPerSample - the number of bytes per sample
signed - whether the data is signed
Returns:
a double array, or null if byteArray is of zero length
Throws:
java.lang.ArrayIndexOutOfBoundsException - this should not happen

getAudioFileType

public static javax.sound.sampled.AudioFileFormat.Type getAudioFileType()

isPcm

public static boolean isPcm(javax.sound.sampled.AudioFormat.Encoding encoding)
Checks if the encoding is PCM.

Parameters:
encoding - query the audio format
Returns:
encoding true if PCM Signed or Unsigned

getSourceType

public static javax.sound.sampled.AudioFileFormat.Type getSourceType()