From c204aadac279647b93567dca59060f60e2cd8d3e Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 26 Aug 2012 21:49:25 +0200 Subject: DUMB: fixed IT reader to read 8bit samples correctly even when char is unsigned (android ndk) --- plugins/dumb/dumb-kode54/src/it/itread.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'plugins/dumb') diff --git a/plugins/dumb/dumb-kode54/src/it/itread.c b/plugins/dumb/dumb-kode54/src/it/itread.c index 7170a57f..e08368fb 100644 --- a/plugins/dumb/dumb-kode54/src/it/itread.c +++ b/plugins/dumb/dumb-kode54/src/it/itread.c @@ -23,8 +23,6 @@ #include "dumb.h" #include "internal/it.h" - - #define INVESTIGATE_OLD_INSTRUMENTS @@ -43,11 +41,9 @@ static int it_seek(DUMBFILE *f, long offset) return 0; } - - typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned long dword; +typedef uint16_t word; +typedef uint32_t dword; typedef struct readblock_crap readblock_crap; @@ -126,8 +122,8 @@ static int decompress8(DUMBFILE *f, signed char *data, int len, int cmwt) { int blocklen, blockpos; byte bitwidth; - word val; - char d1, d2; + long val; + signed char d1, d2; readblock_crap crap; memset(&crap, 0, sizeof(crap)); @@ -146,12 +142,12 @@ static int decompress8(DUMBFILE *f, signed char *data, int len, int cmwt) //Start the decompression: while (blockpos < blocklen) { //Read a value: - val = (word)readbits(bitwidth, &crap); + val = readbits(bitwidth, &crap); //Check for bit width change: if (bitwidth < 7) { //Method 1: if (val == (1 << (bitwidth - 1))) { - val = (word)readbits(3, &crap) + 1; + val = readbits(3, &crap) + 1; bitwidth = (val < bitwidth) ? val : val + 1; continue; } @@ -178,14 +174,14 @@ static int decompress8(DUMBFILE *f, signed char *data, int len, int cmwt) //Expand the value to signed byte: { - char v; //The sample value: + signed char v; //The sample value: if (bitwidth < 8) { byte shift = 8 - bitwidth; v = (val << shift); v >>= shift; } else - v = (char)val; + v = (signed char)val; //And integrate the sample value //(It always has to end with integration doesn't it ? ;-) @@ -670,7 +666,7 @@ static long it_read_sample_data(int cmwt, IT_SAMPLE *sample, unsigned char conve long datasize = sample->length; if (sample->flags & IT_SAMPLE_STEREO) datasize <<= 1; - sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1)); + sample->data = malloc(datasize * ((sample->flags & IT_SAMPLE_16BIT) ? 2 : 1)); if (!sample->data) return -1; @@ -692,8 +688,9 @@ static long it_read_sample_data(int cmwt, IT_SAMPLE *sample, unsigned char conve */ if (sample->flags & IT_SAMPLE_16BIT) decompress16(f, sample->data, datasize, ((cmwt >= 0x215) && (convert & 4))); - else + else { decompress8(f, sample->data, datasize, ((cmwt >= 0x215) && (convert & 4))); + } } else if (sample->flags & IT_SAMPLE_16BIT) { if (convert & 2) for (n = 0; n < datasize; n++) -- cgit v1.2.3