Fill in predict_nr's above 5, fix clamping.

We weren't processing vag properly when it hit the edges.

The coefficients were found with testing about 384 samples.
This commit is contained in:
Unknown W. Brackets 2014-02-19 01:01:56 -08:00
parent 11df9dabf9
commit a36f7bf267

View File

@ -27,25 +27,25 @@
// #define AUDIO_TO_FILE
static const s8 f[16][2] = {
{ 0, 0 },
{ 60, 0 },
{ 115, -52 },
{ 98, -55 },
{ 122, -60 },
// Padding to prevent overflow.
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
static const u8 f[16][2] = {
{ 0, 0 },
{ 60, 0 },
{ 115, 52 },
{ 98, 55 },
{ 122, 60 },
// TODO: The below values could use more testing, but match initial tests.
// Not sure if they are used by games, found by tests.
{ 0, 0 },
{ 0, 0 },
{ 52, 0 },
{ 55, 2 },
{ 60, 125 },
{ 0, 0 },
{ 0, 91 },
{ 0, 0 },
{ 2, 216 },
{ 125, 6 },
{ 0, 151 },
};
void VagDecoder::Start(u32 data, u32 vagSize, bool loopEnabled) {
@ -87,14 +87,14 @@ void VagDecoder::DecodeBlock(u8 *&read_pointer) {
int s2 = s_2;
int coef1 = f[predict_nr][0];
int coef2 = f[predict_nr][1];
int coef2 = -f[predict_nr][1];
for (int i = 0; i < 28; i += 2) {
u8 d = *readp++;
int sample1 = (short)((d & 0xf) << 12) >> shift_factor;
int sample2 = (short)((d & 0xf0) << 8) >> shift_factor;
s2 = (int)(sample1 + ((s1 * coef1 + s2 * coef2) >> 6));
s1 = (int)(sample2 + ((s2 * coef1 + s1 * coef2) >> 6));
s2 = clamp_s16(sample1 + ((s1 * coef1 + s2 * coef2) >> 6));
s1 = clamp_s16(sample2 + ((s2 * coef1 + s1 * coef2) >> 6));
samples[i] = s2;
samples[i + 1] = s1;
}