1
0
Fork 0
forked from len0rd/rockbox

Eliminate references to "long" types for 64-bit compiles; return audio data

in Rockbox standard S3.28 format


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9272 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Bryant 2006-03-26 22:54:15 +00:00
parent d2327dd83d
commit 0ad19c7262
10 changed files with 191 additions and 192 deletions

View file

@ -24,7 +24,7 @@
static void bs_read (Bitstream *bs); static void bs_read (Bitstream *bs);
void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes) void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes)
{ {
CLEAR (*bs); CLEAR (*bs);
bs->buf = buffer_start; bs->buf = buffer_start;
@ -49,7 +49,7 @@ void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_s
static void bs_read (Bitstream *bs) static void bs_read (Bitstream *bs)
{ {
if (bs->file && bs->file_bytes) { if (bs->file && bs->file_bytes) {
ulong bytes_read, bytes_to_read = bs->end - bs->buf; uint32_t bytes_read, bytes_to_read = bs->end - bs->buf;
if (bytes_to_read > bs->file_bytes) if (bytes_to_read > bs->file_bytes)
bytes_to_read = bs->file_bytes; bytes_to_read = bs->file_bytes;
@ -100,12 +100,12 @@ static void bs_write (Bitstream *bs)
// This function forces a flushing write of the specified BitStream, and // This function forces a flushing write of the specified BitStream, and
// returns the total number of bytes written into the buffer. // returns the total number of bytes written into the buffer.
ulong bs_close_write (Bitstream *bs) uint32_t bs_close_write (Bitstream *bs)
{ {
ulong bytes_written; uint32_t bytes_written;
if (bs->error) if (bs->error)
return (ulong) -1; return (uint32_t) -1;
while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs); while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs);
bytes_written = bs->ptr - bs->buf; bytes_written = bs->ptr - bs->buf;
@ -118,13 +118,13 @@ ulong bs_close_write (Bitstream *bs)
void little_endian_to_native (void *data, char *format) void little_endian_to_native (void *data, char *format)
{ {
uchar *cp = (uchar *) data; uchar *cp = (uchar *) data;
long temp; int32_t temp;
while (*format) { while (*format) {
switch (*format) { switch (*format) {
case 'L': case 'L':
temp = cp [0] + ((long) cp [1] << 8) + ((long) cp [2] << 16) + ((long) cp [3] << 24); temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
* (long *) cp = temp; * (int32_t *) cp = temp;
cp += 4; cp += 4;
break; break;
@ -148,12 +148,12 @@ void little_endian_to_native (void *data, char *format)
void native_to_little_endian (void *data, char *format) void native_to_little_endian (void *data, char *format)
{ {
uchar *cp = (uchar *) data; uchar *cp = (uchar *) data;
long temp; int32_t temp;
while (*format) { while (*format) {
switch (*format) { switch (*format) {
case 'L': case 'L':
temp = * (long *) cp; temp = * (int32_t *) cp;
*cp++ = (uchar) temp; *cp++ = (uchar) temp;
*cp++ = (uchar) (temp >> 8); *cp++ = (uchar) (temp >> 8);
*cp++ = (uchar) (temp >> 16); *cp++ = (uchar) (temp >> 16);

View file

@ -25,7 +25,7 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
return TRUE; return TRUE;
} }
void float_values (WavpackStream *wps, long *values, long num_values) void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
{ {
while (num_values--) { while (num_values--) {
int shift_count = 0, exp = wps->float_max_exp; int shift_count = 0, exp = wps->float_max_exp;
@ -60,7 +60,7 @@ void float_values (WavpackStream *wps, long *values, long num_values)
} }
} }
void float_normalize (long *values, long num_values, int delta_exp) void float_normalize (int32_t *values, int32_t num_values, int delta_exp)
{ {
f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 }; f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 };
int exp; int exp;

View file

@ -29,12 +29,12 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
if (!wpc->infile (&tchar, 1)) if (!wpc->infile (&tchar, 1))
return FALSE; return FALSE;
wpmd->byte_length += (long) tchar << 9; wpmd->byte_length += (int32_t) tchar << 9;
if (!wpc->infile (&tchar, 1)) if (!wpc->infile (&tchar, 1))
return FALSE; return FALSE;
wpmd->byte_length += (long) tchar << 17; wpmd->byte_length += (int32_t) tchar << 17;
} }
if (wpmd->id & ID_ODD_SIZE) { if (wpmd->id & ID_ODD_SIZE) {
@ -42,10 +42,10 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
wpmd->byte_length--; wpmd->byte_length--;
} }
if (wpmd->byte_length && wpmd->byte_length <= (long)sizeof (wpc->read_buffer)) { if (wpmd->byte_length && wpmd->byte_length <= (int32_t)sizeof (wpc->read_buffer)) {
ulong bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1);
if (wpc->infile (wpc->read_buffer, bytes_to_read) != (long) bytes_to_read) { if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) {
wpmd->data = NULL; wpmd->data = NULL;
return FALSE; return FALSE;
} }
@ -108,7 +108,7 @@ int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end) int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end)
{ {
ulong mdsize = wpmd->byte_length + (wpmd->byte_length & 1); uint32_t mdsize = wpmd->byte_length + (wpmd->byte_length & 1);
WavpackHeader *wphdr = (WavpackHeader *) buffer_start; WavpackHeader *wphdr = (WavpackHeader *) buffer_start;
if (wpmd->byte_length & 1) if (wpmd->byte_length & 1)

View file

@ -39,7 +39,7 @@ static const signed char fast_terms [] = { 17,17,0 };
void pack_init (WavpackContext *wpc) void pack_init (WavpackContext *wpc)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong flags = wps->wphdr.flags; uint32_t flags = wps->wphdr.flags;
struct decorr_pass *dpp; struct decorr_pass *dpp;
const signed char *term_string; const signed char *term_string;
int ti; int ti;
@ -264,19 +264,19 @@ int pack_start_block (WavpackContext *wpc)
return TRUE; return TRUE;
} }
static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr, int m); static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr, int m);
static void decorr_stereo_pass_18 (struct decorr_pass *dpp, long *bptr, long *eptr); static void decorr_stereo_pass_18 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
static void decorr_stereo_pass_17 (struct decorr_pass *dpp, long *bptr, long *eptr); static void decorr_stereo_pass_17 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *eptr); static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count) int pack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong flags = wps->wphdr.flags; uint32_t flags = wps->wphdr.flags;
struct decorr_pass *dpp; struct decorr_pass *dpp;
long *bptr, *eptr; int32_t *bptr, *eptr;
int tcount, m; int tcount, m;
ulong crc; uint32_t crc;
if (!sample_count) if (!sample_count)
return TRUE; return TRUE;
@ -289,12 +289,12 @@ int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count)
if (!(flags & HYBRID_FLAG) && (flags & MONO_FLAG)) if (!(flags & HYBRID_FLAG) && (flags & MONO_FLAG))
for (bptr = buffer; bptr < eptr;) { for (bptr = buffer; bptr < eptr;) {
long code; int32_t code;
crc = crc * 3 + (code = *bptr); crc = crc * 3 + (code = *bptr);
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) { for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) {
long sam; int32_t sam;
if (dpp->term > MAX_TERM) { if (dpp->term > MAX_TERM) {
if (dpp->term & 1) if (dpp->term & 1)
@ -350,10 +350,10 @@ int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count)
return TRUE; return TRUE;
} }
static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr, int m) static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr, int m)
{ {
int k = (m + dpp->term) & (MAX_TERM - 1); int k = (m + dpp->term) & (MAX_TERM - 1);
long sam; int32_t sam;
while (bptr < eptr) { while (bptr < eptr) {
dpp->samples_A [k] = bptr [0]; dpp->samples_A [k] = bptr [0];
@ -369,9 +369,9 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr,
} }
} }
static void decorr_stereo_pass_18 (struct decorr_pass *dpp, long *bptr, long *eptr) static void decorr_stereo_pass_18 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
{ {
long sam; int32_t sam;
while (bptr < eptr) { while (bptr < eptr) {
sam = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1; sam = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1;
@ -389,9 +389,9 @@ static void decorr_stereo_pass_18 (struct decorr_pass *dpp, long *bptr, long *ep
} }
} }
static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *eptr) static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
{ {
long sam_A, sam_B; int32_t sam_A, sam_B;
for (; bptr < eptr; bptr += 2) { for (; bptr < eptr; bptr += 2) {
sam_A = bptr [1]; sam_A = bptr [1];
@ -404,9 +404,9 @@ static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *ep
} }
} }
static void decorr_stereo_pass_17 (struct decorr_pass *dpp, long *bptr, long *eptr) static void decorr_stereo_pass_17 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
{ {
long sam; int32_t sam;
while (bptr < eptr) { while (bptr < eptr) {
sam = 2 * dpp->samples_A [0] - dpp->samples_A [1]; sam = 2 * dpp->samples_A [0] - dpp->samples_A [1];
@ -428,7 +428,7 @@ int pack_finish_block (WavpackContext *wpc)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
struct decorr_pass *dpp; struct decorr_pass *dpp;
ulong data_count; uint32_t data_count;
int tcount, m; int tcount, m;
m = ((WavpackHeader *) wps->blockbuff)->block_samples & (MAX_TERM - 1); m = ((WavpackHeader *) wps->blockbuff)->block_samples & (MAX_TERM - 1);
@ -436,7 +436,7 @@ int pack_finish_block (WavpackContext *wpc)
if (m) if (m)
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++)
if (dpp->term > 0 && dpp->term <= MAX_TERM) { if (dpp->term > 0 && dpp->term <= MAX_TERM) {
long temp_A [MAX_TERM], temp_B [MAX_TERM]; int32_t temp_A [MAX_TERM], temp_B [MAX_TERM];
int k; int k;
memcpy (temp_A, dpp->samples_A, sizeof (dpp->samples_A)); memcpy (temp_A, dpp->samples_A, sizeof (dpp->samples_A));
@ -453,7 +453,7 @@ int pack_finish_block (WavpackContext *wpc)
data_count = bs_close_write (&wps->wvbits); data_count = bs_close_write (&wps->wvbits);
if (data_count) { if (data_count) {
if (data_count != (ulong) -1) { if (data_count != (uint32_t) -1) {
uchar *cptr = wps->blockbuff + ((WavpackHeader *) wps->blockbuff)->ckSize + 8; uchar *cptr = wps->blockbuff + ((WavpackHeader *) wps->blockbuff)->ckSize + 8;
*cptr++ = ID_WV_BITSTREAM | ID_LARGE; *cptr++ = ID_WV_BITSTREAM | ID_LARGE;

View file

@ -35,7 +35,7 @@ int unpack_init (WavpackContext *wpc)
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
WavpackMetadata wpmd; WavpackMetadata wpmd;
if (wps->wphdr.block_samples && wps->wphdr.block_index != (ulong) -1) if (wps->wphdr.block_samples && wps->wphdr.block_index != (uint32_t) -1)
wps->sample_index = wps->wphdr.block_index; wps->sample_index = wps->wphdr.block_index;
wps->mute_error = FALSE; wps->mute_error = FALSE;
@ -237,7 +237,7 @@ int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd)
{ {
int bytecnt = wpmd->byte_length, shift = 0; int bytecnt = wpmd->byte_length, shift = 0;
char *byteptr = wpmd->data; char *byteptr = wpmd->data;
ulong mask = 0; uint32_t mask = 0;
if (!bytecnt || bytecnt > 5) if (!bytecnt || bytecnt > 5)
return FALSE; return FALSE;
@ -245,7 +245,7 @@ int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd)
wpc->config.num_channels = *byteptr++; wpc->config.num_channels = *byteptr++;
while (--bytecnt) { while (--bytecnt) {
mask |= (ulong) *byteptr++ << shift; mask |= (uint32_t) *byteptr++ << shift;
shift += 8; shift += 8;
} }
@ -262,9 +262,9 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
if (bytecnt >= 3) { if (bytecnt >= 3) {
wpc->config.flags &= 0xff; wpc->config.flags &= 0xff;
wpc->config.flags |= (long) *byteptr++ << 8; wpc->config.flags |= (int32_t) *byteptr++ << 8;
wpc->config.flags |= (long) *byteptr++ << 16; wpc->config.flags |= (int32_t) *byteptr++ << 16;
wpc->config.flags |= (long) *byteptr << 24; wpc->config.flags |= (int32_t) *byteptr << 24;
} }
return TRUE; return TRUE;
@ -273,7 +273,7 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
// This monster actually unpacks the WavPack bitstream(s) into the specified // This monster actually unpacks the WavPack bitstream(s) into the specified
// buffer as 32-bit integers or floats (depending on orignal data). Lossy // buffer as 32-bit integers or floats (depending on orignal data). Lossy
// samples will be clipped to their original limits (i.e. 8-bit samples are // samples will be clipped to their original limits (i.e. 8-bit samples are
// clipped to -128/+127) but are still returned in longs. It is up to the // clipped to -128/+127) but are still returned in int32_ts. It is up to the
// caller to potentially reformat this for the final output including any // caller to potentially reformat this for the final output including any
// multichannel distribution, block alignment or endian compensation. The // multichannel distribution, block alignment or endian compensation. The
// function unpack_init() must have been called and the entire WavPack block // function unpack_init() must have been called and the entire WavPack block
@ -287,25 +287,25 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
// occurs or the end of the block is reached. // occurs or the end of the block is reached.
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) #if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, long *buffer, long sample_count); extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
#elif defined(CPU_ARM) && !defined(SIMULATOR) #elif defined(CPU_ARM) && !defined(SIMULATOR)
extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, long *buffer, long sample_count); extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, long *buffer, long sample_count); extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
#else #else
static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long sample_count); static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
#endif #endif
static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample_count); static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long sample_count); static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count); static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count);
long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count) int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong flags = wps->wphdr.flags, crc = wps->crc, i; uint32_t flags = wps->wphdr.flags, crc = wps->crc, i;
long mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2; int32_t mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2;
struct decorr_pass *dpp; struct decorr_pass *dpp;
long *bptr, *eptr; int32_t *bptr, *eptr;
int tcount; int tcount;
if (wps->sample_index + sample_count > wps->wphdr.block_index + wps->wphdr.block_samples) if (wps->sample_index + sample_count > wps->wphdr.block_index + wps->wphdr.block_samples)
@ -403,10 +403,10 @@ long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count)
return i; return i;
} }
static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long sample_count) static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
{ {
long delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
long *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; int32_t *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
int m, k; int m, k;
switch (dpp->term) { switch (dpp->term) {
@ -462,7 +462,7 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long samp
} }
if (m) { if (m) {
long temp_samples [MAX_TERM]; int32_t temp_samples [MAX_TERM];
memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
@ -520,10 +520,10 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long samp
#if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR) #if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR)
static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long sample_count) static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
{ {
long delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
long *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; int32_t *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
int k, i; int k, i;
switch (dpp->term) { switch (dpp->term) {
@ -619,10 +619,10 @@ static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long
#endif #endif
static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample_count) static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
{ {
long delta = dpp->delta, weight_A = dpp->weight_A; int32_t delta = dpp->delta, weight_A = dpp->weight_A;
long *bptr, *eptr = buffer + sample_count, sam_A; int32_t *bptr, *eptr = buffer + sample_count, sam_A;
int m, k; int m, k;
switch (dpp->term) { switch (dpp->term) {
@ -660,7 +660,7 @@ static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample
} }
if (m) { if (m) {
long temp_samples [MAX_TERM]; int32_t temp_samples [MAX_TERM];
memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
@ -687,12 +687,12 @@ static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample
// as 28-bits, and clipping (for lossy mode) has been eliminated because this // as 28-bits, and clipping (for lossy mode) has been eliminated because this
// now happens in the dsp module. // now happens in the dsp module.
static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count) static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count)
{ {
ulong flags = wps->wphdr.flags; uint32_t flags = wps->wphdr.flags;
int shift = (flags & SHIFT_MASK) >> SHIFT_LSB; int shift = (flags & SHIFT_MASK) >> SHIFT_LSB;
shift += 20 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit data shift += 21 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit (+sign)
if (flags & FLOAT_DATA) { if (flags & FLOAT_DATA) {
float_values (wps, buffer, (flags & MONO_FLAG) ? sample_count : sample_count * 2); float_values (wps, buffer, (flags & MONO_FLAG) ? sample_count : sample_count * 2);
@ -700,10 +700,10 @@ static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count)
} }
if (flags & INT32_DATA) { if (flags & INT32_DATA) {
ulong count = (flags & MONO_FLAG) ? sample_count : sample_count * 2; uint32_t count = (flags & MONO_FLAG) ? sample_count : sample_count * 2;
int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros; int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros;
int ones = wps->int32_ones, dups = wps->int32_dups; int ones = wps->int32_ones, dups = wps->int32_dups;
long *dptr = buffer; int32_t *dptr = buffer;
if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups)) if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups))
while (count--) { while (count--) {

View file

@ -16,7 +16,6 @@
typedef unsigned char uchar; typedef unsigned char uchar;
typedef unsigned short ushort; typedef unsigned short ushort;
typedef unsigned long ulong;
typedef unsigned int uint; typedef unsigned int uint;
// This structure is used to access the individual fields of 32-bit ieee // This structure is used to access the individual fields of 32-bit ieee
@ -43,10 +42,10 @@ typedef struct {
typedef struct { typedef struct {
char ckID [4]; char ckID [4];
ulong ckSize; uint32_t ckSize;
short version; short version;
uchar track_no, index_no; uchar track_no, index_no;
ulong total_samples, block_index, block_samples, flags, crc; uint32_t total_samples, block_index, block_samples, flags, crc;
} WavpackHeader; } WavpackHeader;
#define WavpackHeaderFormat "4LS2LLLLL" #define WavpackHeaderFormat "4LS2LLLLL"
@ -88,7 +87,7 @@ typedef struct {
typedef struct { typedef struct {
uchar temp_data [64]; uchar temp_data [64];
long byte_length; int32_t byte_length;
void *data; void *data;
uchar id; uchar id;
} WavpackMetadata; } WavpackMetadata;
@ -128,7 +127,7 @@ typedef struct {
typedef struct { typedef struct {
int bits_per_sample, bytes_per_sample; int bits_per_sample, bytes_per_sample;
int flags, num_channels, float_norm_exp; int flags, num_channels, float_norm_exp;
ulong sample_rate, channel_mask; uint32_t sample_rate, channel_mask;
} WavpackConfig; } WavpackConfig;
#define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample #define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample
@ -169,12 +168,12 @@ typedef struct {
// pointers to hold a complete allocated block of WavPack data, although it's // pointers to hold a complete allocated block of WavPack data, although it's
// possible to decode WavPack blocks without buffering an entire block. // possible to decode WavPack blocks without buffering an entire block.
typedef long (*read_stream)(void *, long); typedef int32_t (*read_stream)(void *, int32_t);
typedef struct bs { typedef struct bs {
uchar *buf, *end, *ptr; uchar *buf, *end, *ptr;
void (*wrap)(struct bs *bs); void (*wrap)(struct bs *bs);
ulong file_bytes, sr; uint32_t file_bytes, sr;
int error, bc; int error, bc;
read_stream file; read_stream file;
} Bitstream; } Bitstream;
@ -184,16 +183,16 @@ typedef struct bs {
struct decorr_pass { struct decorr_pass {
short term, delta, weight_A, weight_B; short term, delta, weight_A, weight_B;
long samples_A [MAX_TERM], samples_B [MAX_TERM]; int32_t samples_A [MAX_TERM], samples_B [MAX_TERM];
}; };
struct entropy_data { struct entropy_data {
ulong median [3], slow_level, error_limit; uint32_t median [3], slow_level, error_limit;
}; };
struct words_data { struct words_data {
ulong bitrate_delta [2], bitrate_acc [2]; uint32_t bitrate_delta [2], bitrate_acc [2];
ulong pend_data, holding_one, zeros_acc; uint32_t pend_data, holding_one, zeros_acc;
int holding_zero, pend_count; int holding_zero, pend_count;
struct entropy_data c [2]; struct entropy_data c [2];
}; };
@ -205,7 +204,7 @@ typedef struct {
struct words_data w; struct words_data w;
int num_terms, mute_error; int num_terms, mute_error;
ulong sample_index, crc; uint32_t sample_index, crc;
uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups; uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups;
uchar float_flags, float_shift, float_max_exp, float_norm_exp; uchar float_flags, float_shift, float_max_exp, float_norm_exp;
@ -241,7 +240,7 @@ typedef struct {
char error_message [80]; char error_message [80];
read_stream infile; read_stream infile;
ulong total_samples, crc_errors, first_flags; uint32_t total_samples, crc_errors, first_flags;
int open_flags, norm_offset, reduced_channels, lossy_blocks; int open_flags, norm_offset, reduced_channels, lossy_blocks;
} WavpackContext; } WavpackContext;
@ -252,9 +251,9 @@ typedef struct {
// bits.c // bits.c
void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes); void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes);
void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end); void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end);
ulong bs_close_write (Bitstream *bs); uint32_t bs_close_write (Bitstream *bs);
#define bs_is_open(bs) ((bs)->ptr != NULL) #define bs_is_open(bs) ((bs)->ptr != NULL)
@ -270,7 +269,7 @@ ulong bs_close_write (Bitstream *bs);
#define getbits(value, nbits, bs) { \ #define getbits(value, nbits, bs) { \
while ((nbits) > (bs)->bc) { \ while ((nbits) > (bs)->bc) { \
if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \
(bs)->sr |= (long)*((bs)->ptr) << (bs)->bc; \ (bs)->sr |= (int32_t)*((bs)->ptr) << (bs)->bc; \
(bs)->bc += 8; \ (bs)->bc += 8; \
} \ } \
*(value) = (bs)->sr; \ *(value) = (bs)->sr; \
@ -300,7 +299,7 @@ ulong bs_close_write (Bitstream *bs);
}} }}
#define putbits(value, nbits, bs) { \ #define putbits(value, nbits, bs) { \
(bs)->sr |= (long)(value) << (bs)->bc; \ (bs)->sr |= (int32_t)(value) << (bs)->bc; \
if (((bs)->bc += (nbits)) >= 8) \ if (((bs)->bc += (nbits)) >= 8) \
do { \ do { \
*((bs)->ptr) = (bs)->sr; \ *((bs)->ptr) = (bs)->sr; \
@ -354,14 +353,14 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd);
int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd); int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd);
int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd); int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd);
int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd); int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd);
long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
int check_crc_error (WavpackContext *wpc); int check_crc_error (WavpackContext *wpc);
// pack.c // pack.c
void pack_init (WavpackContext *wpc); void pack_init (WavpackContext *wpc);
int pack_start_block (WavpackContext *wpc); int pack_start_block (WavpackContext *wpc);
int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); int pack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
int pack_finish_block (WavpackContext *wpc); int pack_finish_block (WavpackContext *wpc);
// metadata.c stuff // metadata.c stuff
@ -377,15 +376,15 @@ void init_words (WavpackStream *wps);
int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd);
void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd);
int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd); int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd);
long get_words (long *buffer, int nsamples, ulong flags, int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags,
struct words_data *w, Bitstream *bs); struct words_data *w, Bitstream *bs);
void send_word_lossless (long value, int chan, void send_word_lossless (int32_t value, int chan,
struct words_data *w, Bitstream *bs); struct words_data *w, Bitstream *bs);
void send_words (long *buffer, int nsamples, ulong flags, void send_words (int32_t *buffer, int nsamples, uint32_t flags,
struct words_data *w, Bitstream *bs); struct words_data *w, Bitstream *bs);
void flush_word (struct words_data *w, Bitstream *bs); void flush_word (struct words_data *w, Bitstream *bs);
int log2s (long value); int log2s (int32_t value);
long exp2s (int log); int32_t exp2s (int log);
signed char store_weight (int weight); signed char store_weight (int weight);
int restore_weight (signed char weight); int restore_weight (signed char weight);
@ -394,8 +393,8 @@ int restore_weight (signed char weight);
// float.c // float.c
int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd); int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd);
void float_values (WavpackStream *wps, long *values, long num_values); void float_values (WavpackStream *wps, int32_t *values, int32_t num_values);
void float_normalize (long *values, long num_values, int delta_exp); void float_normalize (int32_t *values, int32_t num_values, int delta_exp);
// wputils.c // wputils.c
@ -411,21 +410,21 @@ int WavpackGetMode (WavpackContext *wpc);
#define MODE_HIGH 0x20 #define MODE_HIGH 0x20
#define MODE_FAST 0x40 #define MODE_FAST 0x40
ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples); uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples);
ulong WavpackGetNumSamples (WavpackContext *wpc); uint32_t WavpackGetNumSamples (WavpackContext *wpc);
ulong WavpackGetSampleIndex (WavpackContext *wpc); uint32_t WavpackGetSampleIndex (WavpackContext *wpc);
int WavpackGetNumErrors (WavpackContext *wpc); int WavpackGetNumErrors (WavpackContext *wpc);
int WavpackLossyBlocks (WavpackContext *wpc); int WavpackLossyBlocks (WavpackContext *wpc);
ulong WavpackGetSampleRate (WavpackContext *wpc); uint32_t WavpackGetSampleRate (WavpackContext *wpc);
int WavpackGetBitsPerSample (WavpackContext *wpc); int WavpackGetBitsPerSample (WavpackContext *wpc);
int WavpackGetBytesPerSample (WavpackContext *wpc); int WavpackGetBytesPerSample (WavpackContext *wpc);
int WavpackGetNumChannels (WavpackContext *wpc); int WavpackGetNumChannels (WavpackContext *wpc);
int WavpackGetReducedChannels (WavpackContext *wpc); int WavpackGetReducedChannels (WavpackContext *wpc);
WavpackContext *WavpackOpenFileOutput (void); WavpackContext *WavpackOpenFileOutput (void);
int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong total_samples); int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples);
void WavpackAddWrapper (WavpackContext *wpc, void *data, ulong bcount); void WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount);
int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end); int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end);
int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_count); int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count);
ulong WavpackFinishBlock (WavpackContext *wpc); uint32_t WavpackFinishBlock (WavpackContext *wpc);

View file

@ -141,7 +141,7 @@ void init_words (WavpackStream *wps)
CLEAR (wps->w); CLEAR (wps->w);
} }
static int mylog2 (unsigned long avalue); static int mylog2 (unsigned int32_t avalue);
// Read the median log2 values from the specifed metadata structure, convert // Read the median log2 values from the specifed metadata structure, convert
// them back to 32-bit unsigned values and store them. If length is not // them back to 32-bit unsigned values and store them. If length is not
@ -221,11 +221,11 @@ int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd)
} }
} }
wps->w.bitrate_acc [0] = (long)(byteptr [0] + (byteptr [1] << 8)) << 16; wps->w.bitrate_acc [0] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16;
byteptr += 2; byteptr += 2;
if (!(wps->wphdr.flags & MONO_FLAG)) { if (!(wps->wphdr.flags & MONO_FLAG)) {
wps->w.bitrate_acc [1] = (long)(byteptr [0] + (byteptr [1] << 8)) << 16; wps->w.bitrate_acc [1] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16;
byteptr += 2; byteptr += 2;
} }
@ -253,7 +253,7 @@ int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd)
// currently implemented) this is calculated from the slow_level values and the // currently implemented) this is calculated from the slow_level values and the
// bitrate accumulators. Note that the bitrate accumulators can be changing. // bitrate accumulators. Note that the bitrate accumulators can be changing.
void update_error_limit (struct words_data *w, ulong flags) void update_error_limit (struct words_data *w, uint32_t flags)
{ {
int bitrate_0 = (w->bitrate_acc [0] += w->bitrate_delta [0]) >> 16; int bitrate_0 = (w->bitrate_acc [0] += w->bitrate_delta [0]) >> 16;
@ -310,7 +310,7 @@ void update_error_limit (struct words_data *w, ulong flags)
} }
} }
static ulong read_code (Bitstream *bs, ulong maxcode); static uint32_t read_code (Bitstream *bs, uint32_t maxcode);
// Read the next word from the bitstream "wvbits" and return the value. This // Read the next word from the bitstream "wvbits" and return the value. This
// function can be used for hybrid or lossless streams, but since an // function can be used for hybrid or lossless streams, but since an
@ -320,7 +320,7 @@ static ulong read_code (Bitstream *bs, ulong maxcode);
// of WORD_EOF indicates that the end of the bitstream was reached (all 1s) or // of WORD_EOF indicates that the end of the bitstream was reached (all 1s) or
// some other error occurred. // some other error occurred.
long get_words (long *buffer, int nsamples, ulong flags, int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags,
struct words_data *w, Bitstream *bs) struct words_data *w, Bitstream *bs)
{ {
register struct entropy_data *c = w->c; register struct entropy_data *c = w->c;
@ -330,13 +330,13 @@ long get_words (long *buffer, int nsamples, ulong flags,
nsamples *= 2; nsamples *= 2;
for (csamples = 0; csamples < nsamples; ++csamples) { for (csamples = 0; csamples < nsamples; ++csamples) {
ulong ones_count, low, mid, high; uint32_t ones_count, low, mid, high;
if (!(flags & MONO_FLAG)) if (!(flags & MONO_FLAG))
c = w->c + (csamples & 1); c = w->c + (csamples & 1);
if (!(w->c [0].median [0] & ~1) && !w->holding_zero && !w->holding_one && !(w->c [1].median [0] & ~1)) { if (!(w->c [0].median [0] & ~1) && !w->holding_zero && !w->holding_one && !(w->c [1].median [0] & ~1)) {
ulong mask; uint32_t mask;
int cbits; int cbits;
if (w->zeros_acc) { if (w->zeros_acc) {
@ -397,7 +397,7 @@ long get_words (long *buffer, int nsamples, ulong flags,
break; break;
if (ones_count == LIMIT_ONES) { if (ones_count == LIMIT_ONES) {
ulong mask; uint32_t mask;
int cbits; int cbits;
for (cbits = 0; cbits < 33 && getbit (bs); ++cbits); for (cbits = 0; cbits < 33 && getbit (bs); ++cbits);
@ -493,10 +493,10 @@ long get_words (long *buffer, int nsamples, ulong flags,
// minimum number of bits and then determines whether another bit is needed // minimum number of bits and then determines whether another bit is needed
// to define the code. // to define the code.
static ulong read_code (Bitstream *bs, ulong maxcode) static uint32_t read_code (Bitstream *bs, uint32_t maxcode)
{ {
int bitcount = count_bits (maxcode); int bitcount = count_bits (maxcode);
ulong extras = (1L << bitcount) - maxcode - 1, code; uint32_t extras = (1L << bitcount) - maxcode - 1, code;
if (!bitcount) if (!bitcount)
return 0; return 0;
@ -514,7 +514,7 @@ static ulong read_code (Bitstream *bs, ulong maxcode)
return code; return code;
} }
void send_words (long *buffer, int nsamples, ulong flags, void send_words (int32_t *buffer, int nsamples, uint32_t flags,
struct words_data *w, Bitstream *bs) struct words_data *w, Bitstream *bs)
{ {
register struct entropy_data *c = w->c; register struct entropy_data *c = w->c;
@ -523,9 +523,9 @@ void send_words (long *buffer, int nsamples, ulong flags,
nsamples *= 2; nsamples *= 2;
while (nsamples--) { while (nsamples--) {
long value = *buffer++; int32_t value = *buffer++;
int sign = (value < 0) ? 1 : 0; int sign = (value < 0) ? 1 : 0;
ulong ones_count, low, high; uint32_t ones_count, low, high;
if (!(flags & MONO_FLAG)) if (!(flags & MONO_FLAG))
c = w->c + (~nsamples & 1); c = w->c + (~nsamples & 1);
@ -553,7 +553,7 @@ void send_words (long *buffer, int nsamples, ulong flags,
if (sign) if (sign)
value = ~value; value = ~value;
if ((unsigned long) value < GET_MED (0)) { if ((unsigned int32_t) value < GET_MED (0)) {
ones_count = low = 0; ones_count = low = 0;
high = GET_MED (0) - 1; high = GET_MED (0) - 1;
DEC_MED0 (); DEC_MED0 ();
@ -604,9 +604,9 @@ void send_words (long *buffer, int nsamples, ulong flags,
w->holding_one = ones_count * 2; w->holding_one = ones_count * 2;
if (high != low) { if (high != low) {
ulong maxcode = high - low, code = value - low; uint32_t maxcode = high - low, code = value - low;
int bitcount = count_bits (maxcode); int bitcount = count_bits (maxcode);
ulong extras = (1L << bitcount) - maxcode - 1; uint32_t extras = (1L << bitcount) - maxcode - 1;
if (code < extras) { if (code < extras) {
w->pend_data |= code << w->pend_count; w->pend_data |= code << w->pend_count;
@ -619,7 +619,7 @@ void send_words (long *buffer, int nsamples, ulong flags,
} }
} }
w->pend_data |= ((long) sign << w->pend_count++); w->pend_data |= ((int32_t) sign << w->pend_count++);
if (!w->holding_zero) if (!w->holding_zero)
flush_word (w, bs); flush_word (w, bs);
@ -709,7 +709,7 @@ void flush_word (struct words_data *w, Bitstream *bs)
// This function returns the log2 for the specified 32-bit unsigned value. // This function returns the log2 for the specified 32-bit unsigned value.
// The maximum value allowed is about 0xff800000 and returns 8447. // The maximum value allowed is about 0xff800000 and returns 8447.
static int mylog2 (unsigned long avalue) static int mylog2 (unsigned int32_t avalue)
{ {
int dbits; int dbits;
@ -733,7 +733,7 @@ static int mylog2 (unsigned long avalue)
// All input values are valid and the return values are in the range of // All input values are valid and the return values are in the range of
// +/- 8192. // +/- 8192.
int log2s (long value) int log2s (int32_t value)
{ {
return (value < 0) ? -mylog2 (-value) : mylog2 (value); return (value < 0) ? -mylog2 (-value) : mylog2 (value);
} }
@ -743,9 +743,9 @@ int log2s (long value)
// but since a full 32-bit value is returned this can be used for unsigned // but since a full 32-bit value is returned this can be used for unsigned
// conversions as well (i.e. the input range is -8192 to +8447). // conversions as well (i.e. the input range is -8192 to +8447).
long exp2s (int log) int32_t exp2s (int log)
{ {
ulong value; uint32_t value;
if (log < 0) if (log < 0)
return -exp2s (-log); return -exp2s (-log);

View file

@ -23,12 +23,12 @@ static void strcpy_loc (char *dst, char *src) { while ((*dst++ = *src++) != 0);
///////////////////////////// local table storage //////////////////////////// ///////////////////////////// local table storage ////////////////////////////
const ulong sample_rates [] = { 6000, 8000, 9600, 11025, 12000, 16000, 22050, const uint32_t sample_rates [] = { 6000, 8000, 9600, 11025, 12000, 16000, 22050,
24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 }; 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
///////////////////////////// executable code //////////////////////////////// ///////////////////////////// executable code ////////////////////////////////
static ulong read_next_header (read_stream infile, WavpackHeader *wphdr); static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr);
// This function reads data from the specified stream in search of a valid // This function reads data from the specified stream in search of a valid
// WavPack 4.0 audio block. If this fails in 1 megabyte (or an invalid or // WavPack 4.0 audio block. If this fails in 1 megabyte (or an invalid or
@ -50,11 +50,11 @@ static WavpackContext wpc IBSS_ATTR;
WavpackContext *WavpackOpenFileInput (read_stream infile, char *error) WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
{ {
WavpackStream *wps = &wpc.stream; WavpackStream *wps = &wpc.stream;
ulong bcount; uint32_t bcount;
CLEAR (wpc); CLEAR (wpc);
wpc.infile = infile; wpc.infile = infile;
wpc.total_samples = (ulong) -1; wpc.total_samples = (uint32_t) -1;
wpc.norm_offset = 0; wpc.norm_offset = 0;
wpc.open_flags = 0; wpc.open_flags = 0;
@ -64,7 +64,7 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
bcount = read_next_header (wpc.infile, &wps->wphdr); bcount = read_next_header (wpc.infile, &wps->wphdr);
if (bcount == (ulong) -1) { if (bcount == (uint32_t) -1) {
strcpy_loc (error, "invalid WavPack file!"); strcpy_loc (error, "invalid WavPack file!");
return NULL; return NULL;
} }
@ -74,7 +74,7 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
return NULL; return NULL;
} }
if (wps->wphdr.block_samples && wps->wphdr.total_samples != (ulong) -1) if (wps->wphdr.block_samples && wps->wphdr.total_samples != (uint32_t) -1)
wpc.total_samples = wps->wphdr.total_samples; wpc.total_samples = wps->wphdr.total_samples;
if (!unpack_init (&wpc)) { if (!unpack_init (&wpc)) {
@ -148,18 +148,18 @@ int WavpackGetMode (WavpackContext *wpc)
// Unpack the specified number of samples from the current file position. // Unpack the specified number of samples from the current file position.
// Note that "samples" here refers to "complete" samples, which would be // Note that "samples" here refers to "complete" samples, which would be
// 2 longs for stereo files. The audio data is returned right-justified in // 2 int32_t's for stereo files. The audio data is returned right-justified in
// 32-bit longs in the endian mode native to the executing processor. So, // 32-bit int32_t's in the endian mode native to the executing processor. So,
// if the original data was 16-bit, then the values returned would be // if the original data was 16-bit, then the values returned would be
// +/-32k. Floating point data can also be returned if the source was // +/-32k. Floating point data can also be returned if the source was
// floating point data (and this is normalized to +/-1.0). The actual number // floating point data (and this is normalized to +/-1.0). The actual number
// of samples unpacked is returned, which should be equal to the number // of samples unpacked is returned, which should be equal to the number
// requested unless the end of fle is encountered or an error occurs. // requested unless the end of fle is encountered or an error occurs.
ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples) uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong bcount, samples_unpacked = 0, samples_to_unpack; uint32_t bcount, samples_unpacked = 0, samples_to_unpack;
int num_channels = wpc->config.num_channels; int num_channels = wpc->config.num_channels;
while (samples) { while (samples) {
@ -167,7 +167,7 @@ ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples)
wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) { wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) {
bcount = read_next_header (wpc->infile, &wps->wphdr); bcount = read_next_header (wpc->infile, &wps->wphdr);
if (bcount == (ulong) -1) if (bcount == (uint32_t) -1)
break; break;
if (wps->wphdr.version < 0x402 || wps->wphdr.version > 0x40f) { if (wps->wphdr.version < 0x402 || wps->wphdr.version > 0x40f) {
@ -234,19 +234,19 @@ ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples)
// Get total number of samples contained in the WavPack file, or -1 if unknown // Get total number of samples contained in the WavPack file, or -1 if unknown
ulong WavpackGetNumSamples (WavpackContext *wpc) uint32_t WavpackGetNumSamples (WavpackContext *wpc)
{ {
return wpc ? wpc->total_samples : (ulong) -1; return wpc ? wpc->total_samples : (uint32_t) -1;
} }
// Get the current sample index position, or -1 if unknown // Get the current sample index position, or -1 if unknown
ulong WavpackGetSampleIndex (WavpackContext *wpc) uint32_t WavpackGetSampleIndex (WavpackContext *wpc)
{ {
if (wpc) if (wpc)
return wpc->stream.sample_index; return wpc->stream.sample_index;
return (ulong) -1; return (uint32_t) -1;
} }
// Get the number of errors encountered so far // Get the number of errors encountered so far
@ -265,7 +265,7 @@ int WavpackLossyBlocks (WavpackContext *wpc)
// Returns the sample rate of the specified WavPack file // Returns the sample rate of the specified WavPack file
ulong WavpackGetSampleRate (WavpackContext *wpc) uint32_t WavpackGetSampleRate (WavpackContext *wpc)
{ {
return wpc ? wpc->config.sample_rate : 44100; return wpc ? wpc->config.sample_rate : 44100;
} }
@ -284,7 +284,7 @@ int WavpackGetNumChannels (WavpackContext *wpc)
// always has 32 bits, integers may be from 1 to 32 bits each. When this // always has 32 bits, integers may be from 1 to 32 bits each. When this
// value is not a multiple of 8, then the "extra" bits are located in the // value is not a multiple of 8, then the "extra" bits are located in the
// LSBs of the results. That is, values are right justified when unpacked // LSBs of the results. That is, values are right justified when unpacked
// into longs, but are left justified in the number of bytes used by the // into int32_t's, but are left justified in the number of bytes used by the
// original data. // original data.
int WavpackGetBitsPerSample (WavpackContext *wpc) int WavpackGetBitsPerSample (WavpackContext *wpc)
@ -294,8 +294,8 @@ int WavpackGetBitsPerSample (WavpackContext *wpc)
// Returns the number of bytes used for each sample (1 to 4) in the original // Returns the number of bytes used for each sample (1 to 4) in the original
// file. This is required information for the user of this module because the // file. This is required information for the user of this module because the
// audio data is returned in the LOWER bytes of the long buffer and must be // audio data is returned in the LOWER bytes of the int32_t buffer and must be
// left-shifted 8, 16, or 24 bits if normalized longs are required. // left-shifted 8, 16, or 24 bits if normalized int32_t's are required.
int WavpackGetBytesPerSample (WavpackContext *wpc) int WavpackGetBytesPerSample (WavpackContext *wpc)
{ {
@ -321,10 +321,10 @@ int WavpackGetReducedChannels (WavpackContext *wpc)
// to indicate the error. No additional bytes are read past the header and it // to indicate the error. No additional bytes are read past the header and it
// is returned in the processor's native endian mode. Seeking is not required. // is returned in the processor's native endian mode. Seeking is not required.
static ulong read_next_header (read_stream infile, WavpackHeader *wphdr) static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr)
{ {
char buffer [sizeof (*wphdr)], *sp = buffer + sizeof (*wphdr), *ep = sp; char buffer [sizeof (*wphdr)], *sp = buffer + sizeof (*wphdr), *ep = sp;
ulong bytes_skipped = 0; uint32_t bytes_skipped = 0;
int bleft; int bleft;
while (1) { while (1) {
@ -335,7 +335,7 @@ static ulong read_next_header (read_stream infile, WavpackHeader *wphdr)
else else
bleft = 0; bleft = 0;
if (infile (buffer + bleft, sizeof (*wphdr) - bleft) != (long) sizeof (*wphdr) - bleft) if (infile (buffer + bleft, sizeof (*wphdr) - bleft) != (int32_t) sizeof (*wphdr) - bleft)
return -1; return -1;
sp = buffer; sp = buffer;
@ -407,10 +407,10 @@ WavpackContext *WavpackOpenFileOutput (void)
// WavPack file will not be directly unpackable to a valid wav file (although // WavPack file will not be directly unpackable to a valid wav file (although
// it will still be usable by itself). A return of FALSE indicates an error. // it will still be usable by itself). A return of FALSE indicates an error.
int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong total_samples) int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong flags = (config->bytes_per_sample - 1), shift = 0; uint32_t flags = (config->bytes_per_sample - 1), shift = 0;
int num_chans = config->num_channels; int num_chans = config->num_channels;
int i; int i;
@ -467,7 +467,7 @@ int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong t
// first block written and update the header directly. An example of this can // first block written and update the header directly. An example of this can
// be found in the Audition filter. // be found in the Audition filter.
void WavpackAddWrapper (WavpackContext *wpc, void *data, ulong bcount) void WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount)
{ {
wpc->wrapper_data = data; wpc->wrapper_data = data;
wpc->wrapper_bytes = bcount; wpc->wrapper_bytes = bcount;
@ -484,7 +484,7 @@ int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end)
return pack_start_block (wpc); return pack_start_block (wpc);
} }
// Pack the specified samples. Samples must be stored in longs in the native // Pack the specified samples. Samples must be stored in int32_ts in the native
// endian format of the executing processor. The number of samples specified // endian format of the executing processor. The number of samples specified
// indicates composite samples (sometimes called "frames"). So, the actual // indicates composite samples (sometimes called "frames"). So, the actual
// number of data points would be this "sample_count" times the number of // number of data points would be this "sample_count" times the number of
@ -493,7 +493,7 @@ int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end)
// many times as desired to build the final block (and performs the actual // many times as desired to build the final block (and performs the actual
// compression during the call). A return of FALSE indicates an error. // compression during the call). A return of FALSE indicates an error.
int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_count) int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count)
{ {
if (!sample_count || pack_samples (wpc, sample_buffer, sample_count)) if (!sample_count || pack_samples (wpc, sample_buffer, sample_count))
return TRUE; return TRUE;
@ -506,10 +506,10 @@ int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_c
// block in bytes. Note that the possible conversion of the WavPack header to // block in bytes. Note that the possible conversion of the WavPack header to
// little-endian takes place here. // little-endian takes place here.
ulong WavpackFinishBlock (WavpackContext *wpc) uint32_t WavpackFinishBlock (WavpackContext *wpc)
{ {
WavpackStream *wps = &wpc->stream; WavpackStream *wps = &wpc->stream;
ulong bcount; uint32_t bcount;
pack_finish_block (wpc); pack_finish_block (wpc);
bcount = ((WavpackHeader *) wps->blockbuff)->ckSize + 8; bcount = ((WavpackHeader *) wps->blockbuff)->ckSize + 8;

View file

@ -26,11 +26,11 @@ static struct codec_api *ci;
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
static long temp_buffer [BUFFER_SIZE] IBSS_ATTR; static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR;
static long read_callback (void *buffer, long bytes) static int32_t read_callback (void *buffer, int32_t bytes)
{ {
long retval = ci->read_filebuf (buffer, bytes); int32_t retval = ci->read_filebuf (buffer, bytes);
ci->id3->offset = ci->curpos; ci->id3->offset = ci->curpos;
return retval; return retval;
} }
@ -63,7 +63,7 @@ enum codec_status codec_start(struct codec_api* api)
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
ci->configure(DSP_DITHER, (bool *)false); ci->configure(DSP_DITHER, (bool *)false);
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(27)); // should be 28... ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(28));
next_track: next_track:
@ -97,7 +97,7 @@ enum codec_status codec_start(struct codec_api* api)
/* The main decoder loop */ /* The main decoder loop */
while (1) { while (1) {
long nsamples; int32_t nsamples;
if (ci->seek_time && ci->taginfo_ready && ci->id3->length) { if (ci->seek_time && ci->taginfo_ready && ci->id3->length) {
ci->seek_time--; ci->seek_time--;
@ -107,13 +107,13 @@ enum codec_status codec_start(struct codec_api* api)
if (ci->seek_time > curpos_ms) { if (ci->seek_time > curpos_ms) {
n = ci->seek_time - curpos_ms; n = ci->seek_time - curpos_ms;
d = ci->id3->length - curpos_ms; d = ci->id3->length - curpos_ms;
skip = (int)((long long)(ci->filesize - ci->curpos) * n / d); skip = (int)((int64_t)(ci->filesize - ci->curpos) * n / d);
ci->seek_buffer (ci->curpos + skip); ci->seek_buffer (ci->curpos + skip);
} }
else { else {
n = curpos_ms - ci->seek_time; n = curpos_ms - ci->seek_time;
d = curpos_ms; d = curpos_ms;
skip = (int)((long long) ci->curpos * n / d); skip = (int)((int64_t) ci->curpos * n / d);
ci->seek_buffer (ci->curpos - skip); ci->seek_buffer (ci->curpos - skip);
} }

View file

@ -42,42 +42,42 @@ static int audiobuflen;
static struct wav_header { static struct wav_header {
char ckID [4]; /* RIFF chuck header */ char ckID [4]; /* RIFF chuck header */
long ckSize; int32_t ckSize;
char formType [4]; char formType [4];
char fmt_ckID [4]; /* format chunk header */ char fmt_ckID [4]; /* format chunk header */
long fmt_ckSize; int32_t fmt_ckSize;
ushort FormatTag, NumChannels; ushort FormatTag, NumChannels;
ulong SampleRate, BytesPerSecond; uint32_t SampleRate, BytesPerSecond;
ushort BlockAlign, BitsPerSample; ushort BlockAlign, BitsPerSample;
char data_ckID [4]; /* data chunk header */ char data_ckID [4]; /* data chunk header */
long data_ckSize; int32_t data_ckSize;
} raw_header, native_header; } raw_header, native_header;
#define WAV_HEADER_FORMAT "4L44LSSLLSS4L" #define WAV_HEADER_FORMAT "4L44LSSLLSS4L"
static void wvupdate (long start_tick, static void wvupdate (int32_t start_tick,
long sample_rate, int32_t sample_rate,
ulong total_samples, uint32_t total_samples,
ulong samples_converted, uint32_t samples_converted,
ulong bytes_read, uint32_t bytes_read,
ulong bytes_written) uint32_t bytes_written)
{ {
long elapsed_ticks = *rb->current_tick - start_tick; int32_t elapsed_ticks = *rb->current_tick - start_tick;
int compression = 0, progress = 0, realtime = 0; int compression = 0, progress = 0, realtime = 0;
char buf[32]; char buf[32];
if (total_samples) if (total_samples)
progress = (int)(((long long) samples_converted * 100 + progress = (int)(((int64_t) samples_converted * 100 +
(total_samples/2)) / total_samples); (total_samples/2)) / total_samples);
if (elapsed_ticks) if (elapsed_ticks)
realtime = (int)(((long long) samples_converted * 100 * HZ / realtime = (int)(((int64_t) samples_converted * 100 * HZ /
sample_rate + (elapsed_ticks/2)) / elapsed_ticks); sample_rate + (elapsed_ticks/2)) / elapsed_ticks);
if (bytes_read) if (bytes_read)
compression = (int)(((long long)(bytes_read - bytes_written) * 100 + compression = (int)(((int64_t)(bytes_read - bytes_written) * 100 +
(bytes_read/2)) / bytes_read); (bytes_read/2)) / bytes_read);
rb->snprintf(buf, 32, "elapsed time: %d secs", (elapsed_ticks + (HZ/2)) / HZ); rb->snprintf(buf, 32, "elapsed time: %d secs", (elapsed_ticks + (HZ/2)) / HZ);
@ -99,19 +99,19 @@ static void wvupdate (long start_tick,
#define TEMP_SAMPLES 4096 #define TEMP_SAMPLES 4096
static long temp_buffer [TEMP_SAMPLES] IDATA_ATTR; static int32_t temp_buffer [TEMP_SAMPLES] IDATA_ATTR;
static int wav2wv (char *filename) static int wav2wv (char *filename)
{ {
int in_fd, out_fd, num_chans, error = false, last_buttons; int in_fd, out_fd, num_chans, error = false, last_buttons;
unsigned long total_bytes_read = 0, total_bytes_written = 0; unsigned int32_t total_bytes_read = 0, total_bytes_written = 0;
unsigned long total_samples, samples_remaining; unsigned int32_t total_samples, samples_remaining;
long *input_buffer = (long *) audiobuf; int32_t *input_buffer = (int32_t *) audiobuf;
unsigned char *output_buffer = (unsigned char *)(audiobuf + 0x100000); unsigned char *output_buffer = (unsigned char *)(audiobuf + 0x100000);
char *extension, save_a; char *extension, save_a;
WavpackConfig config; WavpackConfig config;
WavpackContext *wpc; WavpackContext *wpc;
long start_tick; int32_t start_tick;
rb->lcd_clear_display(); rb->lcd_clear_display();
rb->lcd_puts_scroll(0, 0, (unsigned char *)filename); rb->lcd_puts_scroll(0, 0, (unsigned char *)filename);
@ -188,9 +188,9 @@ static int wav2wv (char *filename)
wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0); wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0);
for (samples_remaining = total_samples; samples_remaining;) { for (samples_remaining = total_samples; samples_remaining;) {
unsigned long samples_count, samples_to_pack, bytes_count; unsigned int32_t samples_count, samples_to_pack, bytes_count;
int cnt, buttons; int cnt, buttons;
long value, *lp; int32_t value, *lp;
signed char *cp; signed char *cp;
samples_count = SAMPLES_PER_BLOCK; samples_count = SAMPLES_PER_BLOCK;
@ -200,7 +200,7 @@ static int wav2wv (char *filename)
bytes_count = samples_count * num_chans * 2; bytes_count = samples_count * num_chans * 2;
if (rb->read (in_fd, input_buffer, bytes_count) != (long) bytes_count) { if (rb->read (in_fd, input_buffer, bytes_count) != (int32_t) bytes_count) {
rb->splash(HZ*2, true, "could not read file!"); rb->splash(HZ*2, true, "could not read file!");
error = true; error = true;
break; break;
@ -212,7 +212,7 @@ static int wav2wv (char *filename)
cp = (signed char *) input_buffer; cp = (signed char *) input_buffer;
while (samples_to_pack) { while (samples_to_pack) {
unsigned long samples_this_pass = TEMP_SAMPLES / num_chans; unsigned int32_t samples_this_pass = TEMP_SAMPLES / num_chans;
if (samples_this_pass > samples_to_pack) if (samples_this_pass > samples_to_pack)
samples_this_pass = samples_to_pack; samples_this_pass = samples_to_pack;
@ -250,7 +250,7 @@ static int wav2wv (char *filename)
bytes_count = WavpackFinishBlock (wpc); bytes_count = WavpackFinishBlock (wpc);
if (rb->write (out_fd, output_buffer, bytes_count) != (long) bytes_count) { if (rb->write (out_fd, output_buffer, bytes_count) != (int32_t) bytes_count) {
rb->splash(HZ*2, true, "could not write file!"); rb->splash(HZ*2, true, "could not write file!");
error = true; error = true;
break; break;