Sloppy fixes to adpcm

Stopped ignoring warnings in the makefile. Made warnings an error.
Sanity checked nsequences to prevent allocating gigantic tables.
This commit is contained in:
MysterD 2022-02-06 15:18:20 -08:00
parent 0cd3cbca3d
commit 55c1e94081
6 changed files with 24 additions and 18 deletions

View file

@ -1,6 +1,6 @@
CC := gcc CC := gcc
CXX := g++ CXX := g++
CFLAGS := -I../include -I. -Wall -Wextra -Wno-unused-parameter -Wno-error=implicit-function-declaration -pedantic -std=c99 -O2 -s CFLAGS := -I../include -I. -Wall -Wextra -Wno-unused-parameter -Wno-error=implicit-function-declaration -pedantic -std=c99 -O2
LDFLAGS := -lm LDFLAGS := -lm
PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv
@ -29,7 +29,7 @@ tabledesign_CFLAGS := -Iaudiofile -Wno-uninitialized
tabledesign_LDFLAGS := -Laudiofile -laudiofile -lstdc++ -lm tabledesign_LDFLAGS := -Laudiofile -laudiofile -lstdc++ -lm
vadpcm_enc_SOURCES := sdk-tools/adpcm/vadpcm_enc.c sdk-tools/adpcm/vpredictor.c sdk-tools/adpcm/quant.c sdk-tools/adpcm/util.c sdk-tools/adpcm/vencode.c vadpcm_enc_SOURCES := sdk-tools/adpcm/vadpcm_enc.c sdk-tools/adpcm/vpredictor.c sdk-tools/adpcm/quant.c sdk-tools/adpcm/util.c sdk-tools/adpcm/vencode.c
vadpcm_enc_CFLAGS := -Wno-unused-result -Wno-uninitialized -Wno-sign-compare -Wno-absolute-value vadpcm_enc_CFLAGS := -Werror -g
extract_data_for_mio_SOURCES := extract_data_for_mio.c extract_data_for_mio_SOURCES := extract_data_for_mio.c

View file

@ -10,12 +10,12 @@ static u32 getshort(FILE *ifile)
u32 c1; u32 c1;
u32 c2; u32 c2;
if ((c1 = getc(ifile)) == -1) if ((c1 = (u32)getc(ifile)) == (u32)-1)
{ {
return 0; return 0;
} }
if ((c2 = getc(ifile)) == -1) if ((c2 = (u32)getc(ifile)) == (u32)-1)
{ {
return 0; return 0;
} }
@ -30,7 +30,7 @@ u32 readbits(u32 nbits, FILE *ifile)
u32 left; u32 left;
u32 mask; u32 mask;
if (nbits <= in_bit_pos + 1) if (nbits <= (u32)(in_bit_pos + 1))
{ {
mask = (1U << nbits) - 1; mask = (1U << nbits) - 1;
b = ((u32) input_word >> (in_bit_pos - nbits + 1)) & mask; b = ((u32) input_word >> (in_bit_pos - nbits + 1)) & mask;

View file

@ -21,7 +21,7 @@ typedef double f64;
#else #else
# define BSWAP16(x) x = __builtin_bswap16(x); # define BSWAP16(x) x = __builtin_bswap16(x);
# define BSWAP32(x) x = __builtin_bswap32(x); # define BSWAP32(x) x = __builtin_bswap32(x);
# define BSWAP16_MANY(x, n) { s32 _i; for (_i = 0; _i < n; _i++) BSWAP16((x)[_i]) } # define BSWAP16_MANY(x, n) { s32 _i; for (_i = 0; _i < (s32)n; _i++) BSWAP16((x)[_i]) }
#endif #endif
#ifdef __sgi #ifdef __sgi

View file

@ -11,30 +11,30 @@ int main(int argc, char **argv)
{ {
s32 c; s32 c;
char *progname = argv[0]; char *progname = argv[0];
s16 nloops = 0; u16 nloops = 0;
s16 numMarkers; s16 numMarkers;
s16 *inBuffer; s16 *inBuffer;
s16 ts; s16 ts;
s32 minLoopLength = 800; u32 minLoopLength = 800;
s32 ***coefTable = NULL; s32 ***coefTable = NULL;
s32 *state; s32 *state; // has to be signed
s32 order; s32 order;
s32 npredictors; s32 npredictors;
s32 done = 0; s32 done = 0;
s32 truncate = 0; s32 truncate = 0;
s32 num; s32 num;
s32 tableSize; s32 tableSize;
s32 nsam; u32 nsam;
s32 left; s32 left;
u32 newEnd; u32 newEnd;
s32 nRepeats; s32 nRepeats;
s32 i; s32 i;
s32 j; s32 j;
s32 k; s32 k;
s32 nFrames; u32 nFrames;
s32 offset; s32 offset;
s32 cChunkPos; s32 cChunkPos;
s32 currentPos; u32 currentPos = 0;
s32 soundPointer = 0; s32 soundPointer = 0;
s32 startPointer = 0; s32 startPointer = 0;
s32 startSoundPointer = 0; s32 startSoundPointer = 0;
@ -53,8 +53,8 @@ int main(int argc, char **argv)
SoundDataChunk SndDChunk; SoundDataChunk SndDChunk;
InstrumentChunk InstChunk; InstrumentChunk InstChunk;
Loop *loops = NULL; Loop *loops = NULL;
ALADPCMloop *aloops; ALADPCMloop *aloops = NULL;
Marker *markers; Marker *markers = NULL;
CodeChunk cChunk; CodeChunk cChunk;
char filename[1024]; char filename[1024];
FILE *fhandle; FILE *fhandle;
@ -92,7 +92,7 @@ int main(int argc, char **argv)
break; break;
case 'l': case 'l':
sscanf(optarg, "%d", &minLoopLength); sscanf(optarg, "%u", &minLoopLength);
break; break;
default: default:
@ -353,11 +353,11 @@ int main(int argc, char **argv)
startSoundPointer = ftell(ifile); startSoundPointer = ftell(ifile);
for (i = 0; i < nloops; i++) for (i = 0; i < nloops; i++)
{ {
if (lookupMarker(&aloops[i].start, loops[i].beginLoop, markers, numMarkers) != 0) if (aloops == NULL || markers == NULL || lookupMarker(&aloops[i].start, loops[i].beginLoop, markers, numMarkers) != 0)
{ {
fprintf(stderr, "%s: Start loop marker not found\n", progname); fprintf(stderr, "%s: Start loop marker not found\n", progname);
} }
else if (lookupMarker(&aloops[i].end, loops[i].endLoop, markers, numMarkers) != 0) else if (aloops == NULL || markers == NULL || lookupMarker(&aloops[i].end, loops[i].endLoop, markers, numMarkers) != 0)
{ {
fprintf(stderr, "%s: End loop marker not found\n", progname); fprintf(stderr, "%s: End loop marker not found\n", progname);
} }
@ -487,6 +487,7 @@ int main(int argc, char **argv)
BSWAP16(nloops) BSWAP16(nloops)
for (i = 0; i < nloops; i++) for (i = 0; i < nloops; i++)
{ {
if (aloops == NULL) { continue; }
BSWAP32(aloops[i].start) BSWAP32(aloops[i].start)
BSWAP32(aloops[i].end) BSWAP32(aloops[i].end)
BSWAP32(aloops[i].count) BSWAP32(aloops[i].count)

View file

@ -100,6 +100,7 @@ void vencodeframe(FILE *ofile, s16 *inBuffer, s32 *state, s32 ***coefTable, s32
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
if (coefTable == NULL || coefTable[optimalp] == NULL) { continue; }
prediction[i] = inner_product(order + i, coefTable[optimalp][i], inVector); prediction[i] = inner_product(order + i, coefTable[optimalp][i], inVector);
inVector[i + order] = inBuffer[i] - prediction[i]; inVector[i + order] = inBuffer[i] - prediction[i];
e[i] = (f32) inVector[i + order]; e[i] = (f32) inVector[i + order];
@ -126,7 +127,7 @@ void vencodeframe(FILE *ofile, s16 *inBuffer, s32 *state, s32 ***coefTable, s32
max = 0; max = 0;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
if (fabs(ie[i]) > fabs(max)) if (fabs((f64)ie[i]) > fabs((f64)max))
{ {
max = ie[i]; max = ie[i];
} }

View file

@ -11,6 +11,10 @@ s32 readcodebook(FILE *fhandle, s32 ****table, s32 *order, s32 *npredictors)
fscanf(fhandle, "%d", order); fscanf(fhandle, "%d", order);
fscanf(fhandle, "%d", npredictors); fscanf(fhandle, "%d", npredictors);
if (*npredictors > 500) {
fprintf(stderr, "Way too many predictors: %d\n", *npredictors);
return 1;
}
*table = malloc(*npredictors * sizeof(s32 **)); *table = malloc(*npredictors * sizeof(s32 **));
for (i = 0; i < *npredictors; i++) for (i = 0; i < *npredictors; i++)
{ {