// stereo, the channels will be interleaved with each other in the
// double stream, as in the byte stream. offset is the offset (in
// samples) into audioData.
private void bytes2doubles(byte[] audioBytes, double[] audioData, int offset)
{
AudioFormat format = ais.getFormat();
if (format.getSampleSizeInBits() == 16)
{
if (format.isBigEndian())
{
for (int i = 0; i < audioData.length - offset; i++)
{
/* First byte is MSB (high order) */
int MSB = (int) audioBytes[2 * i];
/* Second byte is LSB (low order) */
int LSB = (int) audioBytes[2 * i + 1];
audioData[offset + i] = ((double) (MSB << 8 | (255 & LSB))) / 32768.0;
}
}
else
{
for (int i = 0; i < audioData.length - offset; i++)
{
/* First byte is LSB (low order) */
int LSB = (int) audioBytes[2 * i];
/* Second byte is MSB (high order) */
int MSB = (int) audioBytes[2 * i + 1];
audioData[offset + i] = ((double) (MSB << 8 | (255 & LSB))) / 32768.0;
}
}
}
else if (format.getSampleSizeInBits() == 8)
{
// int nlengthInSamples = audioBytes.length;
if (format.getEncoding().toString().startsWith("PCM_SIGN"))
{
for (int i = 0; i < audioBytes.length - offset; i++)
audioData[offset + i] = audioBytes[i] / 128.0;
}
else