private void DecompressStereo(byte[] InputBuffer)
{
//if (InputBuffer.Length != 0x1E) return; //todo, deal with this correctly. Right now stereo audio is kind of totally fucked!
byte bInput;
uint i;
int c1left, c2left, c1right, c2right, left, right;
byte dleft, dright;
bInput = InputBuffer[0];
c1left = (int)EATable[HINIBBLE(bInput)]; // predictor coeffs for left channel
c2left = (int)EATable[HINIBBLE(bInput) + 4];
dleft = (byte)(LONIBBLE(bInput) + 8); // shift value for left channel
bInput = InputBuffer[1];
c1right = (int)EATable[HINIBBLE(bInput)]; // predictor coeffs for right channel
c2right = (int)EATable[HINIBBLE(bInput) + 4];
dright = (byte)(LONIBBLE(bInput) + 8); // shift value for right channel
for (i = 2; i < InputBuffer.Length-1; i += 2)
{
left = HINIBBLE(InputBuffer[i]); // HIGHER nibble for left channel
left = (left << 0x1c) >> dleft;
left = (left + m_CurSampleLeft * c1left + m_PrevSampleLeft * c2left + 0x80) >> 8;
left = Clip16BitSample(left);
m_PrevSampleLeft = m_CurSampleLeft;
m_CurSampleLeft = left;
right = HINIBBLE(InputBuffer[i + 1]); // HIGHER nibble for right channel
right = (right << 0x1c) >> dright;
right = (right + m_CurSampleRight * c1right + m_PrevSampleRight * c2right + 0x80) >> 8;
right = Clip16BitSample(right);
m_PrevSampleRight = m_CurSampleRight;
m_CurSampleRight = right;
// Now we've got lCurSampleLeft and lCurSampleRight which form one stereo
// sample and all is set for the next step...
//Output((SHORT)lCurSampleLeft,(SHORT)lCurSampleRight); // send the sample to output
m_Writer.Write((short)m_CurSampleLeft);
m_Writer.Write((short)m_CurSampleRight);
// now do just the same for LOWER nibbles...
// note that nubbles for each channel are packed pairwise into one byte
left = LONIBBLE(InputBuffer[i]); // LOWER nibble for left channel
left = (left << 0x1c) >> dleft;
left = (left + m_CurSampleLeft * c1left + m_PrevSampleLeft * c2left + 0x80) >> 8;
left = Clip16BitSample(left);
m_PrevSampleLeft = m_CurSampleLeft;
m_CurSampleLeft = left;
right = LONIBBLE(InputBuffer[i + 1]); // LOWER nibble for right channel
right = (right << 0x1c) >> dright;
right = (right + m_CurSampleRight * c1right + m_PrevSampleRight * c2right + 0x80) >> 8;
right = Clip16BitSample(right);
m_PrevSampleRight = m_CurSampleRight;
m_CurSampleRight = right;
// Now we've got lCurSampleLeft and lCurSampleRight which form one stereo
// sample and all is set for the next step...
m_Writer.Write((short)m_CurSampleLeft);
m_Writer.Write((short)m_CurSampleRight);
}
}