2018-07-09 18:05:31 +00:00
|
|
|
#include "amuse/DSPCodec.hpp"
|
2016-05-11 04:48:08 +00:00
|
|
|
|
|
|
|
static const int32_t NibbleToInt[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
|
|
|
|
|
2016-05-13 01:46:41 +00:00
|
|
|
unsigned DSPDecompressFrame(int16_t* out, const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned lastSample)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
|
|
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
|
|
|
uint8_t exp = in[0] & 0xf;
|
|
|
|
unsigned ret = 0;
|
2016-12-11 01:52:42 +00:00
|
|
|
for (unsigned s=0 ; s<14 && s<lastSample ; ++s)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
|
|
|
int32_t sampleData = (s&1)?
|
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
2016-05-13 01:46:41 +00:00
|
|
|
out[s] = sampleData;
|
2016-05-11 04:48:08 +00:00
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:46:41 +00:00
|
|
|
unsigned DSPDecompressFrameStereoStride(int16_t* out, const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned lastSample)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-13 01:46:41 +00:00
|
|
|
uint32_t cIdx = (in[0]>>4) & 0xf;
|
2016-05-11 04:48:08 +00:00
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
2016-05-13 01:46:41 +00:00
|
|
|
uint32_t exp = in[0] & 0xf;
|
2016-05-11 04:48:08 +00:00
|
|
|
unsigned ret = 0;
|
2016-12-11 01:52:42 +00:00
|
|
|
for (unsigned s=0 ; s<14 && s<lastSample ; ++s)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
|
|
|
int32_t sampleData = (s&1)?
|
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
2016-05-13 01:46:41 +00:00
|
|
|
out[s*2] = sampleData;
|
2016-05-11 04:48:08 +00:00
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:46:41 +00:00
|
|
|
unsigned DSPDecompressFrameStereoDupe(int16_t* out, const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned lastSample)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-13 01:46:41 +00:00
|
|
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
2016-05-11 04:48:08 +00:00
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
2016-05-13 01:46:41 +00:00
|
|
|
uint8_t exp = in[0] & 0xf;
|
2016-05-11 04:48:08 +00:00
|
|
|
unsigned ret = 0;
|
2016-12-11 01:52:42 +00:00
|
|
|
for (unsigned s=0 ; s<14 && s<lastSample ; ++s)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-13 01:46:41 +00:00
|
|
|
int32_t sampleData = (s&1)?
|
2016-05-11 04:48:08 +00:00
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
|
|
|
out[s*2] = sampleData;
|
2016-05-13 01:46:41 +00:00
|
|
|
out[s*2+1] = sampleData;
|
2016-05-11 04:48:08 +00:00
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:46:41 +00:00
|
|
|
unsigned DSPDecompressFrameRanged(int16_t* out, const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned firstSample, unsigned lastSample)
|
|
|
|
{
|
|
|
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
|
|
|
uint8_t exp = in[0] & 0xf;
|
|
|
|
unsigned ret = 0;
|
2016-12-11 01:52:42 +00:00
|
|
|
for (unsigned s=firstSample ; s<14 && s<lastSample ; ++s)
|
2016-05-13 01:46:41 +00:00
|
|
|
{
|
|
|
|
int32_t sampleData = (s&1)?
|
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
|
|
|
*out++ = sampleData;
|
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned DSPDecompressFrameStateOnly(const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned lastSample)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
|
|
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
|
|
|
uint8_t exp = in[0] & 0xf;
|
|
|
|
unsigned ret = 0;
|
2016-12-11 01:52:42 +00:00
|
|
|
for (unsigned s=0 ; s<14 && s<lastSample ; ++s)
|
2016-05-11 04:48:08 +00:00
|
|
|
{
|
2016-05-13 01:46:41 +00:00
|
|
|
int32_t sampleData = (s&1)?
|
2016-05-11 04:48:08 +00:00
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2018-07-30 06:20:03 +00:00
|
|
|
|
|
|
|
unsigned DSPDecompressFrameRangedStateOnly(const uint8_t* in,
|
|
|
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
|
|
|
unsigned firstSample, unsigned lastSample)
|
|
|
|
{
|
|
|
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
|
|
|
int32_t factor1 = coefs[cIdx][0];
|
|
|
|
int32_t factor2 = coefs[cIdx][1];
|
|
|
|
uint8_t exp = in[0] & 0xf;
|
|
|
|
unsigned ret = 0;
|
|
|
|
for (unsigned s=firstSample ; s<14 && s<lastSample ; ++s)
|
|
|
|
{
|
|
|
|
int32_t sampleData = (s&1)?
|
|
|
|
NibbleToInt[(in[s/2+1])&0xf]:
|
|
|
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
|
|
|
sampleData <<= exp;
|
|
|
|
sampleData <<= 11;
|
|
|
|
sampleData += 1024;
|
|
|
|
sampleData +=
|
|
|
|
factor1 * ((int32_t)(*prev1)) +
|
|
|
|
factor2 * ((int32_t)(*prev2));
|
|
|
|
sampleData >>= 11;
|
|
|
|
sampleData = DSPSampClamp(sampleData);
|
|
|
|
*prev2 = *prev1;
|
|
|
|
*prev1 = sampleData;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|