public void unprepare( int X, int Y, final WaveFormat waveFormat, final ByteBuffer output, final Crc32 crc) { // decompress and convert from (x,y) -> (l,r) // sort of long and ugly.... sorry int channels = waveFormat.nChannels; int bitsPerSample = waveFormat.wBitsPerSample; if (channels == 2) { if (bitsPerSample == 16) { // get the right and left values short nR = (short) (X - (Y / 2)); short nL = (short) (nR + Y); output.append(nR, nL); crc.append(nR, nL); } else if (bitsPerSample == 8) { byte R = (byte) (X - (Y / 2) + 128); byte L = (byte) (R + Y); output.append(R, L); crc.append(R, L); } else if (bitsPerSample == 24) { int RV = X - (Y / 2); int LV = RV + Y; if (RV < 0) RV = (RV + 0x800000) | 0x800000; if (LV < 0) LV = (LV + 0x800000) | 0x800000; output.append24(RV, LV); crc.append24(RV, LV); } } else if (channels == 1) { if (bitsPerSample == 16) { output.append((short) X); crc.append((short) X); } else if (bitsPerSample == 8) { byte R = (byte) (X + 128); output.append(R); crc.append(R); } else if (bitsPerSample == 24) { if (X < 0) X = (X + 0x800000) | 0x800000; output.append24(X); crc.append24(X); } } }
public void unprepareOld( int[] pInputX, int[] pInputY, int nBlocks, WaveFormat pWaveFormatEx, ByteBuffer output, Crc32 crc, int nFileVersion) { // the CRC that will be figured during decompression crc.init(); // decompress and convert from (x,y) -> (l,r) // sort of int and ugly.... sorry int channels = pWaveFormatEx.nChannels; int bitsPerSample = pWaveFormatEx.wBitsPerSample; if (channels == 2) { // convert the x,y data to raw data if (bitsPerSample == 16) { short R; int pX = 0; int pY = 0; for (; pX < nBlocks; pX++, pY++) { R = (short) (pInputX[pX] - (pInputY[pY] / 2)); output.append(R); crc.append(R); R += pInputY[pY]; output.append(R); crc.append(R); } } else if (bitsPerSample == 8) { byte R; if (nFileVersion > 3830) { for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { R = (byte) (pInputX[SampleIndex] - (pInputY[SampleIndex] / 2) + 128); output.append(R); crc.append(R); R += pInputY[SampleIndex]; output.append(R); crc.append(R); } } else { for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { R = (byte) (pInputX[SampleIndex] - (pInputY[SampleIndex] / 2)); output.append(R); crc.append(R); R += pInputY[SampleIndex]; output.append(R); crc.append(R); } } } else if (bitsPerSample == 24) { int RV, LV; for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { RV = pInputX[SampleIndex] - (pInputY[SampleIndex] / 2); LV = RV + pInputY[SampleIndex]; int nTemp = 0; if (RV < 0) nTemp = (RV + 0x800000) | 0x800000; else nTemp = RV; output.append24(nTemp); crc.append24(nTemp); nTemp = 0; if (LV < 0) nTemp = (LV + 0x800000) | 0x800000; else nTemp = LV; output.append24(nTemp); crc.append24(nTemp); } } } else if (channels == 1) { // convert to raw data if (bitsPerSample == 8) { byte R; if (nFileVersion > 3830) { for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { R = (byte) (pInputX[SampleIndex] + 128); output.append(R); crc.append(R); } } else { for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { R = (byte) (pInputX[SampleIndex]); output.append(R); crc.append(R); } } } else if (bitsPerSample == 24) { int RV; for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { RV = pInputX[SampleIndex]; int nTemp = 0; if (RV < 0) nTemp = (RV + 0x800000) | 0x800000; else nTemp = RV; output.append24(nTemp); crc.append24(nTemp); } } else { short R; for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) { R = (short) (pInputX[SampleIndex]); output.append(R); crc.append(R); } } } crc.prefinalizeCrc(); }