xa.cpp: Cleanup that didn't help the crackling noise.

git-svn-id: https://svn.eduke32.com/eduke32@6762 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2018-03-13 23:29:31 +00:00
parent 1460dec6d8
commit 5f52049948

View file

@ -20,8 +20,8 @@
/* ADPCM */ /* ADPCM */
#define XA_DATA_START (0x44-48) #define XA_DATA_START (0x44-48)
#define FXD_FxdToPCM(dt) (max(min((short)((dt)>>16), 32767), -32768)) #define FXD_FxdToPCM(dt) (max(min((int16_t)((dt)>>16), 32767), -32768))
#define DblToPCM(dt) (short)(max(min((dt), 32767), -32768)) #define DblToPCM(dt) (int16_t)(max(min((dt), 32767), -32768))
#if USE_FXD #if USE_FXD
#define FXD_FxdToPcm16(dt) (max(min((dt)/2, 32767), -32768)) #define FXD_FxdToPcm16(dt) (max(min((dt)/2, 32767), -32768))
@ -41,16 +41,16 @@ typedef struct {
double t1_x, t2_x; double t1_x, t2_x;
#endif #endif
char *block; int8_t *block;
size_t blocksize; size_t blocksize;
VoiceNode *owner; VoiceNode *owner;
} xa_data; } xa_data;
typedef char SoundGroup[128]; typedef int8_t SoundGroup[128];
typedef struct XASector { typedef struct XASector {
char sectorFiller[48]; int8_t sectorFiller[48];
SoundGroup SoundGroups[18]; SoundGroup SoundGroups[18];
} XASector; } XASector;
@ -64,8 +64,8 @@ static int32_t K0[4] = {
static int32_t K1[4] = { static int32_t K1[4] = {
0x00000000, 0x00000000,
0x00000000, 0x00000000,
-53248, // 0xFFFF3000, (int32_t)0xFFFF3000u,
-56320, // 0xFFFF2400, (int32_t)0xFFFF2400u,
}; };
#else #else
static double K0[4] = { static double K0[4] = {
@ -109,10 +109,10 @@ static int32_t FXD_FixMul(int32_t a, int32_t b)
static int8_t getSoundData(char *buf, int32_t unit, int32_t sample) static int8_t getSoundData(int8_t *buf, int32_t unit, int32_t sample)
{ {
int8_t ret; int8_t ret;
char *p; int8_t *p;
int32_t offset, shift; int32_t offset, shift;
p = buf; p = buf;
@ -129,13 +129,13 @@ static int8_t getSoundData(char *buf, int32_t unit, int32_t sample)
return ret; return ret;
} }
static int8_t getFilter(char *buf, int32_t unit) static int8_t getFilter(int8_t *buf, int32_t unit)
{ {
return (*(buf + 4 + unit) >> 4) & 0x03; return (*(buf + 4 + unit) >> 4) & 0x03;
} }
static int8_t getRange(char *buf, int32_t unit) static int8_t getRange(int8_t *buf, int32_t unit)
{ {
return *(buf + 4 + unit) & 0x0F; return *(buf + 4 + unit) & 0x0F;
} }
@ -145,7 +145,7 @@ static void decodeSoundSectMono(XASector *ssct, xa_data * xad)
{ {
size_t count = 0; size_t count = 0;
int8_t snddat, filt, range; int8_t snddat, filt, range;
short decoded; int16_t decoded;
int32_t unit, sample; int32_t unit, sample;
int32_t sndgrp; int32_t sndgrp;
#if USE_FXD #if USE_FXD
@ -153,7 +153,7 @@ static void decodeSoundSectMono(XASector *ssct, xa_data * xad)
#else #else
double tmp2, tmp3, tmp4, tmp5; double tmp2, tmp3, tmp4, tmp5;
#endif #endif
char decodeBuf[kNumOfSGs*kNumOfSamples*2]; int8_t decodeBuf[kNumOfSGs*kNumOfSamples*2];
for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++) for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
{ {
@ -181,14 +181,14 @@ static void decodeSoundSectMono(XASector *ssct, xa_data * xad)
xad->t1 = tmp3 + tmp4 + tmp5; xad->t1 = tmp3 + tmp4 + tmp5;
decoded = DblToPCM(xad->t1); decoded = DblToPCM(xad->t1);
#endif #endif
decodeBuf[count++] = (char)(decoded & 0x0000ffff); decodeBuf[count++] = (int8_t) ((uint16_t)decoded & 0x00FF);
decodeBuf[count++] = (char)(decoded >> 8); decodeBuf[count++] = (int8_t)(((uint16_t)decoded & 0xFF00) >> 8);
} }
} }
} }
if (count > xad->blocksize) if (count > xad->blocksize)
xad->block = (char*)realloc(xad->block, count); xad->block = (int8_t *)realloc(xad->block, count);
memcpy(xad->block, decodeBuf, count); memcpy(xad->block, decodeBuf, count);
xad->blocksize = count; xad->blocksize = count;
@ -199,7 +199,7 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
size_t count = 0; size_t count = 0;
int8_t snddat, filt, range; int8_t snddat, filt, range;
int8_t filt1, range1; int8_t filt1, range1;
short decoded; int16_t decoded;
int32_t unit, sample; int32_t unit, sample;
int32_t sndgrp; int32_t sndgrp;
#if USE_FXD #if USE_FXD
@ -207,7 +207,7 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
#else #else
double tmp2, tmp3, tmp4, tmp5; double tmp2, tmp3, tmp4, tmp5;
#endif #endif
char decodeBuf[kNumOfSGs*kNumOfSamples*2]; int8_t decodeBuf[kNumOfSGs*kNumOfSamples*2];
for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++) for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
{ {
@ -239,8 +239,8 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
xad->t1 = tmp3 + tmp4 + tmp5; xad->t1 = tmp3 + tmp4 + tmp5;
decoded = DblToPCM(xad->t1); decoded = DblToPCM(xad->t1);
#endif #endif
decodeBuf[count++] = (char)(decoded & 0x0000ffff); decodeBuf[count++] = (int8_t) ((uint16_t)decoded & 0x00FF);
decodeBuf[count++] = (char)(decoded >> 8); decodeBuf[count++] = (int8_t)(((uint16_t)decoded & 0xFF00) >> 8);
// Channel 2 // Channel 2
snddat = getSoundData(ssct->SoundGroups[sndgrp], unit+1, sample); snddat = getSoundData(ssct->SoundGroups[sndgrp], unit+1, sample);
@ -261,14 +261,14 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
xad->t1_x = tmp3 + tmp4 + tmp5; xad->t1_x = tmp3 + tmp4 + tmp5;
decoded = DblToPCM(xad->t1_x); decoded = DblToPCM(xad->t1_x);
#endif #endif
decodeBuf[count++] = (char)(decoded & 0x0000ffff); decodeBuf[count++] = (int8_t) ((uint16_t)decoded & 0x00FF);
decodeBuf[count++] = (char)(decoded >> 8); decodeBuf[count++] = (int8_t)(((uint16_t)decoded & 0xFF00) >> 8);
} }
} }
} }
if (count > xad->blocksize) if (count > xad->blocksize)
xad->block = (char*)realloc(xad->block, count); xad->block = (int8_t *)realloc(xad->block, count);
memcpy(xad->block, decodeBuf, count); memcpy(xad->block, decodeBuf, count);
xad->blocksize = count; xad->blocksize = count;
@ -317,7 +317,7 @@ static playbackstatus MV_GetNextXABlock
if (sizeof(XASector) < bytes) if (sizeof(XASector) < bytes)
bytes = sizeof(XASector); bytes = sizeof(XASector);
memcpy(&ssct, (char*) xad->ptr + xad->pos, bytes); memcpy(&ssct, (int8_t *)xad->ptr + xad->pos, bytes);
xad->pos += bytes; xad->pos += bytes;
} }
#define SUBMODE_REAL_TIME_SECTOR (1 << 6) #define SUBMODE_REAL_TIME_SECTOR (1 << 6)
@ -340,7 +340,7 @@ static playbackstatus MV_GetNextXABlock
else else
decodeSoundSectMono(&ssct, xad); decodeSoundSectMono(&ssct, xad);
voice->sound = xad->block; voice->sound = (char *)xad->block;
voice->length = (((xad->blocksize * (voice->bits/8))/2)<<voice->bits) / 4; voice->length = (((xad->blocksize * (voice->bits/8))/2)<<voice->bits) / 4;
voice->position = 0; voice->position = 0;
voice->BlockLength = 0; voice->BlockLength = 0;
@ -474,7 +474,7 @@ int32_t MV_PlayXA
voice->wavetype = FMT_XA; voice->wavetype = FMT_XA;
voice->rawdataptr = (void*)xad; voice->rawdataptr = (void*)xad;
voice->GetSound = MV_GetNextXABlock; voice->GetSound = MV_GetNextXABlock;
voice->NextBlock = xad->block; voice->NextBlock = (char *)xad->block;
voice->LoopCount = 0; voice->LoopCount = 0;
voice->BlockLength = 0; voice->BlockLength = 0;
voice->PitchScale = PITCH_GetScale( pitchoffset ); voice->PitchScale = PITCH_GetScale( pitchoffset );
@ -485,8 +485,6 @@ int32_t MV_PlayXA
voice->bits = 16; voice->bits = 16;
voice->bits = 16;
voice->Playing = TRUE; voice->Playing = TRUE;
voice->Paused = FALSE; voice->Paused = FALSE;