2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-21 09:39:11 +00:00

THP audio fix

This commit is contained in:
Jack Andersen
2016-03-09 10:03:35 -10:00
parent 5f7c6769e3
commit f53bdcc5bd
5 changed files with 36 additions and 36 deletions

View File

@@ -1,26 +1,26 @@
#include "dsp.h"
static const int NibbleToInt[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
static const int32_t NibbleToInt[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
void DSPDecompressFrame(int16_t* out, const uint8_t* in,
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
unsigned lastSample)
{
uint8_t cIdx = (in[0]>>4) & 0xf;
int16_t factor1 = coefs[cIdx][0];
int16_t factor2 = coefs[cIdx][1];
int32_t factor1 = coefs[cIdx][0];
int32_t factor2 = coefs[cIdx][1];
uint8_t exp = in[0] & 0xf;
for (int s=0 ; s<14 && s<lastSample ; ++s)
{
int sampleData = (s&1)?
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 * *prev1 +
factor2 * *prev2;
factor1 * ((int32_t)(*prev1)) +
factor2 * ((int32_t)(*prev2));
sampleData >>= 11;
sampleData = DSPSampClamp(sampleData);
out[s] = sampleData;
@@ -33,10 +33,10 @@ void DSPDecompressFrameStereoStride(int16_t* out, const uint8_t* in,
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
unsigned lastSample)
{
uint8_t cIdx = (in[0]>>4) & 0xf;
int16_t factor1 = coefs[cIdx][0];
int16_t factor2 = coefs[cIdx][1];
uint8_t exp = in[0] & 0xf;
uint32_t cIdx = (in[0]>>4) & 0xf;
int32_t factor1 = coefs[cIdx][0];
int32_t factor2 = coefs[cIdx][1];
uint32_t exp = in[0] & 0xf;
for (int s=0 ; s<14 && s<lastSample ; ++s)
{
int sampleData = (s&1)?
@@ -46,8 +46,8 @@ void DSPDecompressFrameStereoStride(int16_t* out, const uint8_t* in,
sampleData <<= 11;
sampleData += 1024;
sampleData +=
factor1 * *prev1 +
factor2 * *prev2;
factor1 * ((int32_t)(*prev1)) +
factor2 * ((int32_t)(*prev2));
sampleData >>= 11;
sampleData = DSPSampClamp(sampleData);
out[s*2] = sampleData;
@@ -61,8 +61,8 @@ void DSPDecompressFrameStereoDupe(int16_t* out, const uint8_t* in,
unsigned lastSample)
{
uint8_t cIdx = (in[0]>>4) & 0xf;
int16_t factor1 = coefs[cIdx][0];
int16_t factor2 = coefs[cIdx][1];
int32_t factor1 = coefs[cIdx][0];
int32_t factor2 = coefs[cIdx][1];
uint8_t exp = in[0] & 0xf;
for (int s=0 ; s<14 && s<lastSample ; ++s)
{
@@ -73,8 +73,8 @@ void DSPDecompressFrameStereoDupe(int16_t* out, const uint8_t* in,
sampleData <<= 11;
sampleData += 1024;
sampleData +=
factor1 * *prev1 +
factor2 * *prev2;
factor1 * ((int32_t)(*prev1)) +
factor2 * ((int32_t)(*prev2));
sampleData >>= 11;
sampleData = DSPSampClamp(sampleData);
out[s*2] = sampleData;