mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
(MioDecoder.DecodeSoundPCM16): use unsafe block to pack 16-bit samples into byte array.
This commit is contained in:
parent
4543d06841
commit
a44c9b15a5
@ -219,18 +219,21 @@ namespace GameRes.Formats.Entis
|
||||
uint nSampleCount = datahdr.SampleCount;
|
||||
uint nChannelCount = (uint)m_mioih.ChannelCount;
|
||||
uint nAllSampleCount = nSampleCount * nChannelCount;
|
||||
uint nBytes = nAllSampleCount * sizeof(short);
|
||||
|
||||
if (ptrWaveBuf.Length < wave_pos + (int)nBytes)
|
||||
return false;
|
||||
|
||||
if (nSampleCount > m_nBufLength)
|
||||
{
|
||||
m_ptrBuffer3 = new sbyte[nAllSampleCount * sizeof(short)];
|
||||
m_ptrBuffer4 = new byte[nAllSampleCount * sizeof(short)];
|
||||
m_ptrBuffer3 = new sbyte[nBytes];
|
||||
m_ptrBuffer4 = new byte[nBytes];
|
||||
m_nBufLength = nSampleCount;
|
||||
}
|
||||
if (0 != (datahdr.Flags & MIO_LEAD_BLOCK))
|
||||
{
|
||||
(context as HuffmanDecodeContext).PrepareToDecodeERINACode();
|
||||
}
|
||||
uint nBytes = nAllSampleCount * sizeof(short);
|
||||
if (context.DecodeBytes (m_ptrBuffer3, nBytes) < nBytes)
|
||||
{
|
||||
return false;
|
||||
@ -251,22 +254,29 @@ namespace GameRes.Formats.Entis
|
||||
m_ptrBuffer4[pbytDstBuf + j * sizeof(short) + 1] = (byte)(bytHigh ^ (bytLow >> 7));
|
||||
}
|
||||
}
|
||||
int ptrSrcBuf = 0; // (SWORD*) m_ptrBuffer4;
|
||||
int nStep = m_mioih.ChannelCount*sizeof(short);
|
||||
if (m_ptrBuffer4.Length < nBytes)
|
||||
return false;
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* rawBuffer4 = m_ptrBuffer4, rawWaveBuf = &ptrWaveBuf[wave_pos])
|
||||
{
|
||||
int nStep = m_mioih.ChannelCount;
|
||||
short* ptrSrcBuf = (short*)rawBuffer4;
|
||||
for (int i = 0; i < m_mioih.ChannelCount; i++)
|
||||
{
|
||||
int ptrDstBuf = wave_pos + i*sizeof(short); // (SWORD*) ptrWaveBuf;
|
||||
short* ptrDstBuf = (short*)rawWaveBuf + i; // (SWORD*) ptrWaveBuf;
|
||||
short wValue = 0;
|
||||
short wDelta = 0;
|
||||
for (uint j = 0; j < nSampleCount; j++)
|
||||
{
|
||||
wDelta += LittleEndian.ToInt16 (m_ptrBuffer4, ptrSrcBuf);
|
||||
wDelta += *ptrSrcBuf++;
|
||||
wValue += wDelta;
|
||||
LittleEndian.Pack (wValue, ptrWaveBuf, ptrDstBuf); // *ptrDstBuf = wValue;
|
||||
ptrSrcBuf += sizeof(short);
|
||||
*ptrDstBuf = wValue;
|
||||
ptrDstBuf += nStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user