summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Bryant <bryant@rockbox.org>2006-03-26 22:54:15 +0000
committerDave Bryant <bryant@rockbox.org>2006-03-26 22:54:15 +0000
commit0ad19c7262f987691d04051648e71d6f30892d5f (patch)
tree5ed040adca51fe7f5fbffb7ae58a50e7f565c111
parentd2327dd83d9a88acbc936687a1b823c1b2f573d8 (diff)
downloadrockbox-0ad19c7262f987691d04051648e71d6f30892d5f.tar.gz
rockbox-0ad19c7262f987691d04051648e71d6f30892d5f.zip
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
-rw-r--r--apps/codecs/libwavpack/bits.c20
-rw-r--r--apps/codecs/libwavpack/float.c4
-rw-r--r--apps/codecs/libwavpack/metadata.c12
-rw-r--r--apps/codecs/libwavpack/pack.c48
-rw-r--r--apps/codecs/libwavpack/unpack.c68
-rw-r--r--apps/codecs/libwavpack/wavpack.h67
-rw-r--r--apps/codecs/libwavpack/words.c44
-rw-r--r--apps/codecs/libwavpack/wputils.c58
-rw-r--r--apps/codecs/wavpack.c14
-rw-r--r--apps/plugins/wav2wv.c48
10 files changed, 191 insertions, 192 deletions
diff --git a/apps/codecs/libwavpack/bits.c b/apps/codecs/libwavpack/bits.c
index bf056a9392..0a148e123f 100644
--- a/apps/codecs/libwavpack/bits.c
+++ b/apps/codecs/libwavpack/bits.c
@@ -24,7 +24,7 @@
24 24
25static void bs_read (Bitstream *bs); 25static void bs_read (Bitstream *bs);
26 26
27void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes) 27void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes)
28{ 28{
29 CLEAR (*bs); 29 CLEAR (*bs);
30 bs->buf = buffer_start; 30 bs->buf = buffer_start;
@@ -49,7 +49,7 @@ void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_s
49static void bs_read (Bitstream *bs) 49static void bs_read (Bitstream *bs)
50{ 50{
51 if (bs->file && bs->file_bytes) { 51 if (bs->file && bs->file_bytes) {
52 ulong bytes_read, bytes_to_read = bs->end - bs->buf; 52 uint32_t bytes_read, bytes_to_read = bs->end - bs->buf;
53 53
54 if (bytes_to_read > bs->file_bytes) 54 if (bytes_to_read > bs->file_bytes)
55 bytes_to_read = bs->file_bytes; 55 bytes_to_read = bs->file_bytes;
@@ -100,12 +100,12 @@ static void bs_write (Bitstream *bs)
100// This function forces a flushing write of the specified BitStream, and 100// This function forces a flushing write of the specified BitStream, and
101// returns the total number of bytes written into the buffer. 101// returns the total number of bytes written into the buffer.
102 102
103ulong bs_close_write (Bitstream *bs) 103uint32_t bs_close_write (Bitstream *bs)
104{ 104{
105 ulong bytes_written; 105 uint32_t bytes_written;
106 106
107 if (bs->error) 107 if (bs->error)
108 return (ulong) -1; 108 return (uint32_t) -1;
109 109
110 while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs); 110 while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs);
111 bytes_written = bs->ptr - bs->buf; 111 bytes_written = bs->ptr - bs->buf;
@@ -118,13 +118,13 @@ ulong bs_close_write (Bitstream *bs)
118void little_endian_to_native (void *data, char *format) 118void little_endian_to_native (void *data, char *format)
119{ 119{
120 uchar *cp = (uchar *) data; 120 uchar *cp = (uchar *) data;
121 long temp; 121 int32_t temp;
122 122
123 while (*format) { 123 while (*format) {
124 switch (*format) { 124 switch (*format) {
125 case 'L': 125 case 'L':
126 temp = cp [0] + ((long) cp [1] << 8) + ((long) cp [2] << 16) + ((long) cp [3] << 24); 126 temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
127 * (long *) cp = temp; 127 * (int32_t *) cp = temp;
128 cp += 4; 128 cp += 4;
129 break; 129 break;
130 130
@@ -148,12 +148,12 @@ void little_endian_to_native (void *data, char *format)
148void native_to_little_endian (void *data, char *format) 148void native_to_little_endian (void *data, char *format)
149{ 149{
150 uchar *cp = (uchar *) data; 150 uchar *cp = (uchar *) data;
151 long temp; 151 int32_t temp;
152 152
153 while (*format) { 153 while (*format) {
154 switch (*format) { 154 switch (*format) {
155 case 'L': 155 case 'L':
156 temp = * (long *) cp; 156 temp = * (int32_t *) cp;
157 *cp++ = (uchar) temp; 157 *cp++ = (uchar) temp;
158 *cp++ = (uchar) (temp >> 8); 158 *cp++ = (uchar) (temp >> 8);
159 *cp++ = (uchar) (temp >> 16); 159 *cp++ = (uchar) (temp >> 16);
diff --git a/apps/codecs/libwavpack/float.c b/apps/codecs/libwavpack/float.c
index 2208e616d8..9d3a82c001 100644
--- a/apps/codecs/libwavpack/float.c
+++ b/apps/codecs/libwavpack/float.c
@@ -25,7 +25,7 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
25 return TRUE; 25 return TRUE;
26} 26}
27 27
28void float_values (WavpackStream *wps, long *values, long num_values) 28void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
29{ 29{
30 while (num_values--) { 30 while (num_values--) {
31 int shift_count = 0, exp = wps->float_max_exp; 31 int shift_count = 0, exp = wps->float_max_exp;
@@ -60,7 +60,7 @@ void float_values (WavpackStream *wps, long *values, long num_values)
60 } 60 }
61} 61}
62 62
63void float_normalize (long *values, long num_values, int delta_exp) 63void float_normalize (int32_t *values, int32_t num_values, int delta_exp)
64{ 64{
65 f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 }; 65 f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 };
66 int exp; 66 int exp;
diff --git a/apps/codecs/libwavpack/metadata.c b/apps/codecs/libwavpack/metadata.c
index ebc7dcf99d..b7d1e950bf 100644
--- a/apps/codecs/libwavpack/metadata.c
+++ b/apps/codecs/libwavpack/metadata.c
@@ -29,12 +29,12 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
29 if (!wpc->infile (&tchar, 1)) 29 if (!wpc->infile (&tchar, 1))
30 return FALSE; 30 return FALSE;
31 31
32 wpmd->byte_length += (long) tchar << 9; 32 wpmd->byte_length += (int32_t) tchar << 9;
33 33
34 if (!wpc->infile (&tchar, 1)) 34 if (!wpc->infile (&tchar, 1))
35 return FALSE; 35 return FALSE;
36 36
37 wpmd->byte_length += (long) tchar << 17; 37 wpmd->byte_length += (int32_t) tchar << 17;
38 } 38 }
39 39
40 if (wpmd->id & ID_ODD_SIZE) { 40 if (wpmd->id & ID_ODD_SIZE) {
@@ -42,10 +42,10 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
42 wpmd->byte_length--; 42 wpmd->byte_length--;
43 } 43 }
44 44
45 if (wpmd->byte_length && wpmd->byte_length <= (long)sizeof (wpc->read_buffer)) { 45 if (wpmd->byte_length && wpmd->byte_length <= (int32_t)sizeof (wpc->read_buffer)) {
46 ulong bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); 46 uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1);
47 47
48 if (wpc->infile (wpc->read_buffer, bytes_to_read) != (long) bytes_to_read) { 48 if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) {
49 wpmd->data = NULL; 49 wpmd->data = NULL;
50 return FALSE; 50 return FALSE;
51 } 51 }
@@ -108,7 +108,7 @@ int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
108 108
109int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end) 109int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end)
110{ 110{
111 ulong mdsize = wpmd->byte_length + (wpmd->byte_length & 1); 111 uint32_t mdsize = wpmd->byte_length + (wpmd->byte_length & 1);
112 WavpackHeader *wphdr = (WavpackHeader *) buffer_start; 112 WavpackHeader *wphdr = (WavpackHeader *) buffer_start;
113 113
114 if (wpmd->byte_length & 1) 114 if (wpmd->byte_length & 1)
diff --git a/apps/codecs/libwavpack/pack.c b/apps/codecs/libwavpack/pack.c
index 588efccc6f..9ccfa07261 100644
--- a/apps/codecs/libwavpack/pack.c
+++ b/apps/codecs/libwavpack/pack.c
@@ -39,7 +39,7 @@ static const signed char fast_terms [] = { 17,17,0 };
39void pack_init (WavpackContext *wpc) 39void pack_init (WavpackContext *wpc)
40{ 40{
41 WavpackStream *wps = &wpc->stream; 41 WavpackStream *wps = &wpc->stream;
42 ulong flags = wps->wphdr.flags; 42 uint32_t flags = wps->wphdr.flags;
43 struct decorr_pass *dpp; 43 struct decorr_pass *dpp;
44 const signed char *term_string; 44 const signed char *term_string;
45 int ti; 45 int ti;
@@ -264,19 +264,19 @@ int pack_start_block (WavpackContext *wpc)
264 return TRUE; 264 return TRUE;
265} 265}
266 266
267static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr, int m); 267static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr, int m);
268static void decorr_stereo_pass_18 (struct decorr_pass *dpp, long *bptr, long *eptr); 268static void decorr_stereo_pass_18 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
269static void decorr_stereo_pass_17 (struct decorr_pass *dpp, long *bptr, long *eptr); 269static void decorr_stereo_pass_17 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
270static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *eptr); 270static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr);
271 271
272int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count) 272int pack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count)
273{ 273{
274 WavpackStream *wps = &wpc->stream; 274 WavpackStream *wps = &wpc->stream;
275 ulong flags = wps->wphdr.flags; 275 uint32_t flags = wps->wphdr.flags;
276 struct decorr_pass *dpp; 276 struct decorr_pass *dpp;
277 long *bptr, *eptr; 277 int32_t *bptr, *eptr;
278 int tcount, m; 278 int tcount, m;
279 ulong crc; 279 uint32_t crc;
280 280
281 if (!sample_count) 281 if (!sample_count)
282 return TRUE; 282 return TRUE;
@@ -289,12 +289,12 @@ int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count)
289 289
290 if (!(flags & HYBRID_FLAG) && (flags & MONO_FLAG)) 290 if (!(flags & HYBRID_FLAG) && (flags & MONO_FLAG))
291 for (bptr = buffer; bptr < eptr;) { 291 for (bptr = buffer; bptr < eptr;) {
292 long code; 292 int32_t code;
293 293
294 crc = crc * 3 + (code = *bptr); 294 crc = crc * 3 + (code = *bptr);
295 295
296 for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) { 296 for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) {
297 long sam; 297 int32_t sam;
298 298
299 if (dpp->term > MAX_TERM) { 299 if (dpp->term > MAX_TERM) {
300 if (dpp->term & 1) 300 if (dpp->term & 1)
@@ -350,10 +350,10 @@ int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count)
350 return TRUE; 350 return TRUE;
351} 351}
352 352
353static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr, int m) 353static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr, int m)
354{ 354{
355 int k = (m + dpp->term) & (MAX_TERM - 1); 355 int k = (m + dpp->term) & (MAX_TERM - 1);
356 long sam; 356 int32_t sam;
357 357
358 while (bptr < eptr) { 358 while (bptr < eptr) {
359 dpp->samples_A [k] = bptr [0]; 359 dpp->samples_A [k] = bptr [0];
@@ -369,9 +369,9 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *bptr, long *eptr,
369 } 369 }
370} 370}
371 371
372static void decorr_stereo_pass_18 (struct decorr_pass *dpp, long *bptr, long *eptr) 372static void decorr_stereo_pass_18 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
373{ 373{
374 long sam; 374 int32_t sam;
375 375
376 while (bptr < eptr) { 376 while (bptr < eptr) {
377 sam = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1; 377 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
389 } 389 }
390} 390}
391 391
392static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *eptr) 392static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
393{ 393{
394 long sam_A, sam_B; 394 int32_t sam_A, sam_B;
395 395
396 for (; bptr < eptr; bptr += 2) { 396 for (; bptr < eptr; bptr += 2) {
397 sam_A = bptr [1]; 397 sam_A = bptr [1];
@@ -404,18 +404,18 @@ static void decorr_stereo_pass_m2 (struct decorr_pass *dpp, long *bptr, long *ep
404 } 404 }
405} 405}
406 406
407static void decorr_stereo_pass_17 (struct decorr_pass *dpp, long *bptr, long *eptr) 407static void decorr_stereo_pass_17 (struct decorr_pass *dpp, int32_t *bptr, int32_t *eptr)
408{ 408{
409 long sam; 409 int32_t sam;
410 410
411 while (bptr < eptr) { 411 while (bptr < eptr) {
412 sam = 2 * dpp->samples_A [0] - dpp->samples_A [1]; 412 sam = 2 * dpp->samples_A [0] - dpp->samples_A [1];
413 dpp->samples_A [1] = dpp->samples_A [0]; 413 dpp->samples_A [1] = dpp->samples_A [0];
414 dpp->samples_A [0] = bptr [0]; 414 dpp->samples_A [0] = bptr [0];
415 bptr [0] -= apply_weight_i (dpp->weight_A, sam); 415 bptr [0] -= apply_weight_i (dpp->weight_A, sam);
416 update_weight (dpp->weight_A, 2, sam, bptr [0]); 416 update_weight (dpp->weight_A, 2, sam, bptr [0]);
417 bptr++; 417 bptr++;
418 sam = 2 * dpp->samples_B [0] - dpp->samples_B [1]; 418 sam = 2 * dpp->samples_B [0] - dpp->samples_B [1];
419 dpp->samples_B [1] = dpp->samples_B [0]; 419 dpp->samples_B [1] = dpp->samples_B [0];
420 dpp->samples_B [0] = bptr [0]; 420 dpp->samples_B [0] = bptr [0];
421 bptr [0] -= apply_weight_i (dpp->weight_B, sam); 421 bptr [0] -= apply_weight_i (dpp->weight_B, sam);
@@ -428,7 +428,7 @@ int pack_finish_block (WavpackContext *wpc)
428{ 428{
429 WavpackStream *wps = &wpc->stream; 429 WavpackStream *wps = &wpc->stream;
430 struct decorr_pass *dpp; 430 struct decorr_pass *dpp;
431 ulong data_count; 431 uint32_t data_count;
432 int tcount, m; 432 int tcount, m;
433 433
434 m = ((WavpackHeader *) wps->blockbuff)->block_samples & (MAX_TERM - 1); 434 m = ((WavpackHeader *) wps->blockbuff)->block_samples & (MAX_TERM - 1);
@@ -436,7 +436,7 @@ int pack_finish_block (WavpackContext *wpc)
436 if (m) 436 if (m)
437 for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) 437 for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++)
438 if (dpp->term > 0 && dpp->term <= MAX_TERM) { 438 if (dpp->term > 0 && dpp->term <= MAX_TERM) {
439 long temp_A [MAX_TERM], temp_B [MAX_TERM]; 439 int32_t temp_A [MAX_TERM], temp_B [MAX_TERM];
440 int k; 440 int k;
441 441
442 memcpy (temp_A, dpp->samples_A, sizeof (dpp->samples_A)); 442 memcpy (temp_A, dpp->samples_A, sizeof (dpp->samples_A));
@@ -453,7 +453,7 @@ int pack_finish_block (WavpackContext *wpc)
453 data_count = bs_close_write (&wps->wvbits); 453 data_count = bs_close_write (&wps->wvbits);
454 454
455 if (data_count) { 455 if (data_count) {
456 if (data_count != (ulong) -1) { 456 if (data_count != (uint32_t) -1) {
457 uchar *cptr = wps->blockbuff + ((WavpackHeader *) wps->blockbuff)->ckSize + 8; 457 uchar *cptr = wps->blockbuff + ((WavpackHeader *) wps->blockbuff)->ckSize + 8;
458 458
459 *cptr++ = ID_WV_BITSTREAM | ID_LARGE; 459 *cptr++ = ID_WV_BITSTREAM | ID_LARGE;
diff --git a/apps/codecs/libwavpack/unpack.c b/apps/codecs/libwavpack/unpack.c
index af5d71585e..dcc9bf5bf9 100644
--- a/apps/codecs/libwavpack/unpack.c
+++ b/apps/codecs/libwavpack/unpack.c
@@ -35,7 +35,7 @@ int unpack_init (WavpackContext *wpc)
35 WavpackStream *wps = &wpc->stream; 35 WavpackStream *wps = &wpc->stream;
36 WavpackMetadata wpmd; 36 WavpackMetadata wpmd;
37 37
38 if (wps->wphdr.block_samples && wps->wphdr.block_index != (ulong) -1) 38 if (wps->wphdr.block_samples && wps->wphdr.block_index != (uint32_t) -1)
39 wps->sample_index = wps->wphdr.block_index; 39 wps->sample_index = wps->wphdr.block_index;
40 40
41 wps->mute_error = FALSE; 41 wps->mute_error = FALSE;
@@ -237,7 +237,7 @@ int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd)
237{ 237{
238 int bytecnt = wpmd->byte_length, shift = 0; 238 int bytecnt = wpmd->byte_length, shift = 0;
239 char *byteptr = wpmd->data; 239 char *byteptr = wpmd->data;
240 ulong mask = 0; 240 uint32_t mask = 0;
241 241
242 if (!bytecnt || bytecnt > 5) 242 if (!bytecnt || bytecnt > 5)
243 return FALSE; 243 return FALSE;
@@ -245,7 +245,7 @@ int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd)
245 wpc->config.num_channels = *byteptr++; 245 wpc->config.num_channels = *byteptr++;
246 246
247 while (--bytecnt) { 247 while (--bytecnt) {
248 mask |= (ulong) *byteptr++ << shift; 248 mask |= (uint32_t) *byteptr++ << shift;
249 shift += 8; 249 shift += 8;
250 } 250 }
251 251
@@ -262,9 +262,9 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
262 262
263 if (bytecnt >= 3) { 263 if (bytecnt >= 3) {
264 wpc->config.flags &= 0xff; 264 wpc->config.flags &= 0xff;
265 wpc->config.flags |= (long) *byteptr++ << 8; 265 wpc->config.flags |= (int32_t) *byteptr++ << 8;
266 wpc->config.flags |= (long) *byteptr++ << 16; 266 wpc->config.flags |= (int32_t) *byteptr++ << 16;
267 wpc->config.flags |= (long) *byteptr << 24; 267 wpc->config.flags |= (int32_t) *byteptr << 24;
268 } 268 }
269 269
270 return TRUE; 270 return TRUE;
@@ -273,7 +273,7 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
273// This monster actually unpacks the WavPack bitstream(s) into the specified 273// This monster actually unpacks the WavPack bitstream(s) into the specified
274// buffer as 32-bit integers or floats (depending on orignal data). Lossy 274// buffer as 32-bit integers or floats (depending on orignal data). Lossy
275// samples will be clipped to their original limits (i.e. 8-bit samples are 275// samples will be clipped to their original limits (i.e. 8-bit samples are
276// clipped to -128/+127) but are still returned in longs. It is up to the 276// clipped to -128/+127) but are still returned in int32_ts. It is up to the
277// caller to potentially reformat this for the final output including any 277// caller to potentially reformat this for the final output including any
278// multichannel distribution, block alignment or endian compensation. The 278// multichannel distribution, block alignment or endian compensation. The
279// function unpack_init() must have been called and the entire WavPack block 279// function unpack_init() must have been called and the entire WavPack block
@@ -287,25 +287,25 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
287// occurs or the end of the block is reached. 287// occurs or the end of the block is reached.
288 288
289#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) 289#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
290extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, long *buffer, long sample_count); 290extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
291#elif defined(CPU_ARM) && !defined(SIMULATOR) 291#elif defined(CPU_ARM) && !defined(SIMULATOR)
292extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, long *buffer, long sample_count); 292extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
293extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, long *buffer, long sample_count); 293extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
294#else 294#else
295static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long sample_count); 295static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
296#endif 296#endif
297 297
298static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample_count); 298static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
299static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long sample_count); 299static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
300static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count); 300static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count);
301 301
302long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count) 302int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count)
303{ 303{
304 WavpackStream *wps = &wpc->stream; 304 WavpackStream *wps = &wpc->stream;
305 ulong flags = wps->wphdr.flags, crc = wps->crc, i; 305 uint32_t flags = wps->wphdr.flags, crc = wps->crc, i;
306 long mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2; 306 int32_t mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2;
307 struct decorr_pass *dpp; 307 struct decorr_pass *dpp;
308 long *bptr, *eptr; 308 int32_t *bptr, *eptr;
309 int tcount; 309 int tcount;
310 310
311 if (wps->sample_index + sample_count > wps->wphdr.block_index + wps->wphdr.block_samples) 311 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)
403 return i; 403 return i;
404} 404}
405 405
406static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long sample_count) 406static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
407{ 407{
408 long delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; 408 int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
409 long *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; 409 int32_t *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
410 int m, k; 410 int m, k;
411 411
412 switch (dpp->term) { 412 switch (dpp->term) {
@@ -462,7 +462,7 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long samp
462 } 462 }
463 463
464 if (m) { 464 if (m) {
465 long temp_samples [MAX_TERM]; 465 int32_t temp_samples [MAX_TERM];
466 466
467 memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); 467 memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
468 468
@@ -520,10 +520,10 @@ static void decorr_stereo_pass (struct decorr_pass *dpp, long *buffer, long samp
520 520
521#if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR) 521#if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR)
522 522
523static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long sample_count) 523static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
524{ 524{
525 long delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; 525 int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
526 long *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; 526 int32_t *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
527 int k, i; 527 int k, i;
528 528
529 switch (dpp->term) { 529 switch (dpp->term) {
@@ -619,10 +619,10 @@ static void decorr_stereo_pass_cont (struct decorr_pass *dpp, long *buffer, long
619 619
620#endif 620#endif
621 621
622static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample_count) 622static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
623{ 623{
624 long delta = dpp->delta, weight_A = dpp->weight_A; 624 int32_t delta = dpp->delta, weight_A = dpp->weight_A;
625 long *bptr, *eptr = buffer + sample_count, sam_A; 625 int32_t *bptr, *eptr = buffer + sample_count, sam_A;
626 int m, k; 626 int m, k;
627 627
628 switch (dpp->term) { 628 switch (dpp->term) {
@@ -660,7 +660,7 @@ static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample
660 } 660 }
661 661
662 if (m) { 662 if (m) {
663 long temp_samples [MAX_TERM]; 663 int32_t temp_samples [MAX_TERM];
664 664
665 memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); 665 memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
666 666
@@ -687,12 +687,12 @@ static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample
687// as 28-bits, and clipping (for lossy mode) has been eliminated because this 687// as 28-bits, and clipping (for lossy mode) has been eliminated because this
688// now happens in the dsp module. 688// now happens in the dsp module.
689 689
690static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count) 690static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count)
691{ 691{
692 ulong flags = wps->wphdr.flags; 692 uint32_t flags = wps->wphdr.flags;
693 int shift = (flags & SHIFT_MASK) >> SHIFT_LSB; 693 int shift = (flags & SHIFT_MASK) >> SHIFT_LSB;
694 694
695 shift += 20 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit data 695 shift += 21 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit (+sign)
696 696
697 if (flags & FLOAT_DATA) { 697 if (flags & FLOAT_DATA) {
698 float_values (wps, buffer, (flags & MONO_FLAG) ? sample_count : sample_count * 2); 698 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)
700 } 700 }
701 701
702 if (flags & INT32_DATA) { 702 if (flags & INT32_DATA) {
703 ulong count = (flags & MONO_FLAG) ? sample_count : sample_count * 2; 703 uint32_t count = (flags & MONO_FLAG) ? sample_count : sample_count * 2;
704 int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros; 704 int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros;
705 int ones = wps->int32_ones, dups = wps->int32_dups; 705 int ones = wps->int32_ones, dups = wps->int32_dups;
706 long *dptr = buffer; 706 int32_t *dptr = buffer;
707 707
708 if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups)) 708 if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups))
709 while (count--) { 709 while (count--) {
diff --git a/apps/codecs/libwavpack/wavpack.h b/apps/codecs/libwavpack/wavpack.h
index e26cac353a..593af7831d 100644
--- a/apps/codecs/libwavpack/wavpack.h
+++ b/apps/codecs/libwavpack/wavpack.h
@@ -16,7 +16,6 @@
16 16
17typedef unsigned char uchar; 17typedef unsigned char uchar;
18typedef unsigned short ushort; 18typedef unsigned short ushort;
19typedef unsigned long ulong;
20typedef unsigned int uint; 19typedef unsigned int uint;
21 20
22// This structure is used to access the individual fields of 32-bit ieee 21// This structure is used to access the individual fields of 32-bit ieee
@@ -43,10 +42,10 @@ typedef struct {
43 42
44typedef struct { 43typedef struct {
45 char ckID [4]; 44 char ckID [4];
46 ulong ckSize; 45 uint32_t ckSize;
47 short version; 46 short version;
48 uchar track_no, index_no; 47 uchar track_no, index_no;
49 ulong total_samples, block_index, block_samples, flags, crc; 48 uint32_t total_samples, block_index, block_samples, flags, crc;
50} WavpackHeader; 49} WavpackHeader;
51 50
52#define WavpackHeaderFormat "4LS2LLLLL" 51#define WavpackHeaderFormat "4LS2LLLLL"
@@ -88,7 +87,7 @@ typedef struct {
88 87
89typedef struct { 88typedef struct {
90 uchar temp_data [64]; 89 uchar temp_data [64];
91 long byte_length; 90 int32_t byte_length;
92 void *data; 91 void *data;
93 uchar id; 92 uchar id;
94} WavpackMetadata; 93} WavpackMetadata;
@@ -128,7 +127,7 @@ typedef struct {
128typedef struct { 127typedef struct {
129 int bits_per_sample, bytes_per_sample; 128 int bits_per_sample, bytes_per_sample;
130 int flags, num_channels, float_norm_exp; 129 int flags, num_channels, float_norm_exp;
131 ulong sample_rate, channel_mask; 130 uint32_t sample_rate, channel_mask;
132} WavpackConfig; 131} WavpackConfig;
133 132
134#define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample 133#define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample
@@ -169,12 +168,12 @@ typedef struct {
169// pointers to hold a complete allocated block of WavPack data, although it's 168// pointers to hold a complete allocated block of WavPack data, although it's
170// possible to decode WavPack blocks without buffering an entire block. 169// possible to decode WavPack blocks without buffering an entire block.
171 170
172typedef long (*read_stream)(void *, long); 171typedef int32_t (*read_stream)(void *, int32_t);
173 172
174typedef struct bs { 173typedef struct bs {
175 uchar *buf, *end, *ptr; 174 uchar *buf, *end, *ptr;
176 void (*wrap)(struct bs *bs); 175 void (*wrap)(struct bs *bs);
177 ulong file_bytes, sr; 176 uint32_t file_bytes, sr;
178 int error, bc; 177 int error, bc;
179 read_stream file; 178 read_stream file;
180} Bitstream; 179} Bitstream;
@@ -184,16 +183,16 @@ typedef struct bs {
184 183
185struct decorr_pass { 184struct decorr_pass {
186 short term, delta, weight_A, weight_B; 185 short term, delta, weight_A, weight_B;
187 long samples_A [MAX_TERM], samples_B [MAX_TERM]; 186 int32_t samples_A [MAX_TERM], samples_B [MAX_TERM];
188}; 187};
189 188
190struct entropy_data { 189struct entropy_data {
191 ulong median [3], slow_level, error_limit; 190 uint32_t median [3], slow_level, error_limit;
192}; 191};
193 192
194struct words_data { 193struct words_data {
195 ulong bitrate_delta [2], bitrate_acc [2]; 194 uint32_t bitrate_delta [2], bitrate_acc [2];
196 ulong pend_data, holding_one, zeros_acc; 195 uint32_t pend_data, holding_one, zeros_acc;
197 int holding_zero, pend_count; 196 int holding_zero, pend_count;
198 struct entropy_data c [2]; 197 struct entropy_data c [2];
199}; 198};
@@ -205,7 +204,7 @@ typedef struct {
205 struct words_data w; 204 struct words_data w;
206 205
207 int num_terms, mute_error; 206 int num_terms, mute_error;
208 ulong sample_index, crc; 207 uint32_t sample_index, crc;
209 208
210 uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups; 209 uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups;
211 uchar float_flags, float_shift, float_max_exp, float_norm_exp; 210 uchar float_flags, float_shift, float_max_exp, float_norm_exp;
@@ -241,7 +240,7 @@ typedef struct {
241 char error_message [80]; 240 char error_message [80];
242 241
243 read_stream infile; 242 read_stream infile;
244 ulong total_samples, crc_errors, first_flags; 243 uint32_t total_samples, crc_errors, first_flags;
245 int open_flags, norm_offset, reduced_channels, lossy_blocks; 244 int open_flags, norm_offset, reduced_channels, lossy_blocks;
246 245
247} WavpackContext; 246} WavpackContext;
@@ -252,9 +251,9 @@ typedef struct {
252 251
253// bits.c 252// bits.c
254 253
255void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes); 254void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes);
256void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end); 255void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end);
257ulong bs_close_write (Bitstream *bs); 256uint32_t bs_close_write (Bitstream *bs);
258 257
259#define bs_is_open(bs) ((bs)->ptr != NULL) 258#define bs_is_open(bs) ((bs)->ptr != NULL)
260 259
@@ -270,7 +269,7 @@ ulong bs_close_write (Bitstream *bs);
270#define getbits(value, nbits, bs) { \ 269#define getbits(value, nbits, bs) { \
271 while ((nbits) > (bs)->bc) { \ 270 while ((nbits) > (bs)->bc) { \
272 if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ 271 if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \
273 (bs)->sr |= (long)*((bs)->ptr) << (bs)->bc; \ 272 (bs)->sr |= (int32_t)*((bs)->ptr) << (bs)->bc; \
274 (bs)->bc += 8; \ 273 (bs)->bc += 8; \
275 } \ 274 } \
276 *(value) = (bs)->sr; \ 275 *(value) = (bs)->sr; \
@@ -300,7 +299,7 @@ ulong bs_close_write (Bitstream *bs);
300 }} 299 }}
301 300
302#define putbits(value, nbits, bs) { \ 301#define putbits(value, nbits, bs) { \
303 (bs)->sr |= (long)(value) << (bs)->bc; \ 302 (bs)->sr |= (int32_t)(value) << (bs)->bc; \
304 if (((bs)->bc += (nbits)) >= 8) \ 303 if (((bs)->bc += (nbits)) >= 8) \
305 do { \ 304 do { \
306 *((bs)->ptr) = (bs)->sr; \ 305 *((bs)->ptr) = (bs)->sr; \
@@ -354,14 +353,14 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd);
354int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd); 353int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd);
355int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd); 354int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd);
356int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd); 355int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd);
357long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); 356int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
358int check_crc_error (WavpackContext *wpc); 357int check_crc_error (WavpackContext *wpc);
359 358
360// pack.c 359// pack.c
361 360
362void pack_init (WavpackContext *wpc); 361void pack_init (WavpackContext *wpc);
363int pack_start_block (WavpackContext *wpc); 362int pack_start_block (WavpackContext *wpc);
364int pack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); 363int pack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
365int pack_finish_block (WavpackContext *wpc); 364int pack_finish_block (WavpackContext *wpc);
366 365
367// metadata.c stuff 366// metadata.c stuff
@@ -377,15 +376,15 @@ void init_words (WavpackStream *wps);
377int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); 376int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd);
378void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); 377void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd);
379int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd); 378int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd);
380long get_words (long *buffer, int nsamples, ulong flags, 379int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags,
381 struct words_data *w, Bitstream *bs); 380 struct words_data *w, Bitstream *bs);
382void send_word_lossless (long value, int chan, 381void send_word_lossless (int32_t value, int chan,
383 struct words_data *w, Bitstream *bs); 382 struct words_data *w, Bitstream *bs);
384void send_words (long *buffer, int nsamples, ulong flags, 383void send_words (int32_t *buffer, int nsamples, uint32_t flags,
385 struct words_data *w, Bitstream *bs); 384 struct words_data *w, Bitstream *bs);
386void flush_word (struct words_data *w, Bitstream *bs); 385void flush_word (struct words_data *w, Bitstream *bs);
387int log2s (long value); 386int log2s (int32_t value);
388long exp2s (int log); 387int32_t exp2s (int log);
389signed char store_weight (int weight); 388signed char store_weight (int weight);
390int restore_weight (signed char weight); 389int restore_weight (signed char weight);
391 390
@@ -394,8 +393,8 @@ int restore_weight (signed char weight);
394// float.c 393// float.c
395 394
396int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd); 395int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd);
397void float_values (WavpackStream *wps, long *values, long num_values); 396void float_values (WavpackStream *wps, int32_t *values, int32_t num_values);
398void float_normalize (long *values, long num_values, int delta_exp); 397void float_normalize (int32_t *values, int32_t num_values, int delta_exp);
399 398
400// wputils.c 399// wputils.c
401 400
@@ -411,21 +410,21 @@ int WavpackGetMode (WavpackContext *wpc);
411#define MODE_HIGH 0x20 410#define MODE_HIGH 0x20
412#define MODE_FAST 0x40 411#define MODE_FAST 0x40
413 412
414ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples); 413uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples);
415ulong WavpackGetNumSamples (WavpackContext *wpc); 414uint32_t WavpackGetNumSamples (WavpackContext *wpc);
416ulong WavpackGetSampleIndex (WavpackContext *wpc); 415uint32_t WavpackGetSampleIndex (WavpackContext *wpc);
417int WavpackGetNumErrors (WavpackContext *wpc); 416int WavpackGetNumErrors (WavpackContext *wpc);
418int WavpackLossyBlocks (WavpackContext *wpc); 417int WavpackLossyBlocks (WavpackContext *wpc);
419ulong WavpackGetSampleRate (WavpackContext *wpc); 418uint32_t WavpackGetSampleRate (WavpackContext *wpc);
420int WavpackGetBitsPerSample (WavpackContext *wpc); 419int WavpackGetBitsPerSample (WavpackContext *wpc);
421int WavpackGetBytesPerSample (WavpackContext *wpc); 420int WavpackGetBytesPerSample (WavpackContext *wpc);
422int WavpackGetNumChannels (WavpackContext *wpc); 421int WavpackGetNumChannels (WavpackContext *wpc);
423int WavpackGetReducedChannels (WavpackContext *wpc); 422int WavpackGetReducedChannels (WavpackContext *wpc);
424WavpackContext *WavpackOpenFileOutput (void); 423WavpackContext *WavpackOpenFileOutput (void);
425int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong total_samples); 424int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples);
426void WavpackAddWrapper (WavpackContext *wpc, void *data, ulong bcount); 425void WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount);
427int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end); 426int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end);
428int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_count); 427int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count);
429ulong WavpackFinishBlock (WavpackContext *wpc); 428uint32_t WavpackFinishBlock (WavpackContext *wpc);
430 429
431 430
diff --git a/apps/codecs/libwavpack/words.c b/apps/codecs/libwavpack/words.c
index 96e3b60ebb..ccbd77f8f9 100644
--- a/apps/codecs/libwavpack/words.c
+++ b/apps/codecs/libwavpack/words.c
@@ -141,7 +141,7 @@ void init_words (WavpackStream *wps)
141 CLEAR (wps->w); 141 CLEAR (wps->w);
142} 142}
143 143
144static int mylog2 (unsigned long avalue); 144static int mylog2 (unsigned int32_t avalue);
145 145
146// Read the median log2 values from the specifed metadata structure, convert 146// Read the median log2 values from the specifed metadata structure, convert
147// them back to 32-bit unsigned values and store them. If length is not 147// 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)
221 } 221 }
222 } 222 }
223 223
224 wps->w.bitrate_acc [0] = (long)(byteptr [0] + (byteptr [1] << 8)) << 16; 224 wps->w.bitrate_acc [0] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16;
225 byteptr += 2; 225 byteptr += 2;
226 226
227 if (!(wps->wphdr.flags & MONO_FLAG)) { 227 if (!(wps->wphdr.flags & MONO_FLAG)) {
228 wps->w.bitrate_acc [1] = (long)(byteptr [0] + (byteptr [1] << 8)) << 16; 228 wps->w.bitrate_acc [1] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16;
229 byteptr += 2; 229 byteptr += 2;
230 } 230 }
231 231
@@ -253,7 +253,7 @@ int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd)
253// currently implemented) this is calculated from the slow_level values and the 253// currently implemented) this is calculated from the slow_level values and the
254// bitrate accumulators. Note that the bitrate accumulators can be changing. 254// bitrate accumulators. Note that the bitrate accumulators can be changing.
255 255
256void update_error_limit (struct words_data *w, ulong flags) 256void update_error_limit (struct words_data *w, uint32_t flags)
257{ 257{
258 int bitrate_0 = (w->bitrate_acc [0] += w->bitrate_delta [0]) >> 16; 258 int bitrate_0 = (w->bitrate_acc [0] += w->bitrate_delta [0]) >> 16;
259 259
@@ -310,7 +310,7 @@ void update_error_limit (struct words_data *w, ulong flags)
310 } 310 }
311} 311}
312 312
313static ulong read_code (Bitstream *bs, ulong maxcode); 313static uint32_t read_code (Bitstream *bs, uint32_t maxcode);
314 314
315// Read the next word from the bitstream "wvbits" and return the value. This 315// Read the next word from the bitstream "wvbits" and return the value. This
316// function can be used for hybrid or lossless streams, but since an 316// function can be used for hybrid or lossless streams, but since an
@@ -320,7 +320,7 @@ static ulong read_code (Bitstream *bs, ulong maxcode);
320// of WORD_EOF indicates that the end of the bitstream was reached (all 1s) or 320// of WORD_EOF indicates that the end of the bitstream was reached (all 1s) or
321// some other error occurred. 321// some other error occurred.
322 322
323long get_words (long *buffer, int nsamples, ulong flags, 323int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags,
324 struct words_data *w, Bitstream *bs) 324 struct words_data *w, Bitstream *bs)
325{ 325{
326 register struct entropy_data *c = w->c; 326 register struct entropy_data *c = w->c;
@@ -330,13 +330,13 @@ long get_words (long *buffer, int nsamples, ulong flags,
330 nsamples *= 2; 330 nsamples *= 2;
331 331
332 for (csamples = 0; csamples < nsamples; ++csamples) { 332 for (csamples = 0; csamples < nsamples; ++csamples) {
333 ulong ones_count, low, mid, high; 333 uint32_t ones_count, low, mid, high;
334 334
335 if (!(flags & MONO_FLAG)) 335 if (!(flags & MONO_FLAG))
336 c = w->c + (csamples & 1); 336 c = w->c + (csamples & 1);
337 337
338 if (!(w->c [0].median [0] & ~1) && !w->holding_zero && !w->holding_one && !(w->c [1].median [0] & ~1)) { 338 if (!(w->c [0].median [0] & ~1) && !w->holding_zero && !w->holding_one && !(w->c [1].median [0] & ~1)) {
339 ulong mask; 339 uint32_t mask;
340 int cbits; 340 int cbits;
341 341
342 if (w->zeros_acc) { 342 if (w->zeros_acc) {
@@ -397,7 +397,7 @@ long get_words (long *buffer, int nsamples, ulong flags,
397 break; 397 break;
398 398
399 if (ones_count == LIMIT_ONES) { 399 if (ones_count == LIMIT_ONES) {
400 ulong mask; 400 uint32_t mask;
401 int cbits; 401 int cbits;
402 402
403 for (cbits = 0; cbits < 33 && getbit (bs); ++cbits); 403 for (cbits = 0; cbits < 33 && getbit (bs); ++cbits);
@@ -493,10 +493,10 @@ long get_words (long *buffer, int nsamples, ulong flags,
493// minimum number of bits and then determines whether another bit is needed 493// minimum number of bits and then determines whether another bit is needed
494// to define the code. 494// to define the code.
495 495
496static ulong read_code (Bitstream *bs, ulong maxcode) 496static uint32_t read_code (Bitstream *bs, uint32_t maxcode)
497{ 497{
498 int bitcount = count_bits (maxcode); 498 int bitcount = count_bits (maxcode);
499 ulong extras = (1L << bitcount) - maxcode - 1, code; 499 uint32_t extras = (1L << bitcount) - maxcode - 1, code;
500 500
501 if (!bitcount) 501 if (!bitcount)
502 return 0; 502 return 0;
@@ -514,7 +514,7 @@ static ulong read_code (Bitstream *bs, ulong maxcode)
514 return code; 514 return code;
515} 515}
516 516
517void send_words (long *buffer, int nsamples, ulong flags, 517void send_words (int32_t *buffer, int nsamples, uint32_t flags,
518 struct words_data *w, Bitstream *bs) 518 struct words_data *w, Bitstream *bs)
519{ 519{
520 register struct entropy_data *c = w->c; 520 register struct entropy_data *c = w->c;
@@ -523,9 +523,9 @@ void send_words (long *buffer, int nsamples, ulong flags,
523 nsamples *= 2; 523 nsamples *= 2;
524 524
525 while (nsamples--) { 525 while (nsamples--) {
526 long value = *buffer++; 526 int32_t value = *buffer++;
527 int sign = (value < 0) ? 1 : 0; 527 int sign = (value < 0) ? 1 : 0;
528 ulong ones_count, low, high; 528 uint32_t ones_count, low, high;
529 529
530 if (!(flags & MONO_FLAG)) 530 if (!(flags & MONO_FLAG))
531 c = w->c + (~nsamples & 1); 531 c = w->c + (~nsamples & 1);
@@ -553,7 +553,7 @@ void send_words (long *buffer, int nsamples, ulong flags,
553 if (sign) 553 if (sign)
554 value = ~value; 554 value = ~value;
555 555
556 if ((unsigned long) value < GET_MED (0)) { 556 if ((unsigned int32_t) value < GET_MED (0)) {
557 ones_count = low = 0; 557 ones_count = low = 0;
558 high = GET_MED (0) - 1; 558 high = GET_MED (0) - 1;
559 DEC_MED0 (); 559 DEC_MED0 ();
@@ -604,9 +604,9 @@ void send_words (long *buffer, int nsamples, ulong flags,
604 w->holding_one = ones_count * 2; 604 w->holding_one = ones_count * 2;
605 605
606 if (high != low) { 606 if (high != low) {
607 ulong maxcode = high - low, code = value - low; 607 uint32_t maxcode = high - low, code = value - low;
608 int bitcount = count_bits (maxcode); 608 int bitcount = count_bits (maxcode);
609 ulong extras = (1L << bitcount) - maxcode - 1; 609 uint32_t extras = (1L << bitcount) - maxcode - 1;
610 610
611 if (code < extras) { 611 if (code < extras) {
612 w->pend_data |= code << w->pend_count; 612 w->pend_data |= code << w->pend_count;
@@ -619,7 +619,7 @@ void send_words (long *buffer, int nsamples, ulong flags,
619 } 619 }
620 } 620 }
621 621
622 w->pend_data |= ((long) sign << w->pend_count++); 622 w->pend_data |= ((int32_t) sign << w->pend_count++);
623 623
624 if (!w->holding_zero) 624 if (!w->holding_zero)
625 flush_word (w, bs); 625 flush_word (w, bs);
@@ -709,7 +709,7 @@ void flush_word (struct words_data *w, Bitstream *bs)
709// This function returns the log2 for the specified 32-bit unsigned value. 709// This function returns the log2 for the specified 32-bit unsigned value.
710// The maximum value allowed is about 0xff800000 and returns 8447. 710// The maximum value allowed is about 0xff800000 and returns 8447.
711 711
712static int mylog2 (unsigned long avalue) 712static int mylog2 (unsigned int32_t avalue)
713{ 713{
714 int dbits; 714 int dbits;
715 715
@@ -733,7 +733,7 @@ static int mylog2 (unsigned long avalue)
733// All input values are valid and the return values are in the range of 733// All input values are valid and the return values are in the range of
734// +/- 8192. 734// +/- 8192.
735 735
736int log2s (long value) 736int log2s (int32_t value)
737{ 737{
738 return (value < 0) ? -mylog2 (-value) : mylog2 (value); 738 return (value < 0) ? -mylog2 (-value) : mylog2 (value);
739} 739}
@@ -743,9 +743,9 @@ int log2s (long value)
743// but since a full 32-bit value is returned this can be used for unsigned 743// but since a full 32-bit value is returned this can be used for unsigned
744// conversions as well (i.e. the input range is -8192 to +8447). 744// conversions as well (i.e. the input range is -8192 to +8447).
745 745
746long exp2s (int log) 746int32_t exp2s (int log)
747{ 747{
748 ulong value; 748 uint32_t value;
749 749
750 if (log < 0) 750 if (log < 0)
751 return -exp2s (-log); 751 return -exp2s (-log);
diff --git a/apps/codecs/libwavpack/wputils.c b/apps/codecs/libwavpack/wputils.c
index 549cd8a4fa..7a6cc44ad4 100644
--- a/apps/codecs/libwavpack/wputils.c
+++ b/apps/codecs/libwavpack/wputils.c
@@ -23,12 +23,12 @@ static void strcpy_loc (char *dst, char *src) { while ((*dst++ = *src++) != 0);
23 23
24///////////////////////////// local table storage //////////////////////////// 24///////////////////////////// local table storage ////////////////////////////
25 25
26const ulong sample_rates [] = { 6000, 8000, 9600, 11025, 12000, 16000, 22050, 26const uint32_t sample_rates [] = { 6000, 8000, 9600, 11025, 12000, 16000, 22050,
27 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 }; 27 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
28 28
29///////////////////////////// executable code //////////////////////////////// 29///////////////////////////// executable code ////////////////////////////////
30 30
31static ulong read_next_header (read_stream infile, WavpackHeader *wphdr); 31static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr);
32 32
33// This function reads data from the specified stream in search of a valid 33// This function reads data from the specified stream in search of a valid
34// WavPack 4.0 audio block. If this fails in 1 megabyte (or an invalid or 34// WavPack 4.0 audio block. If this fails in 1 megabyte (or an invalid or
@@ -50,11 +50,11 @@ static WavpackContext wpc IBSS_ATTR;
50WavpackContext *WavpackOpenFileInput (read_stream infile, char *error) 50WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
51{ 51{
52 WavpackStream *wps = &wpc.stream; 52 WavpackStream *wps = &wpc.stream;
53 ulong bcount; 53 uint32_t bcount;
54 54
55 CLEAR (wpc); 55 CLEAR (wpc);
56 wpc.infile = infile; 56 wpc.infile = infile;
57 wpc.total_samples = (ulong) -1; 57 wpc.total_samples = (uint32_t) -1;
58 wpc.norm_offset = 0; 58 wpc.norm_offset = 0;
59 wpc.open_flags = 0; 59 wpc.open_flags = 0;
60 60
@@ -64,7 +64,7 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
64 64
65 bcount = read_next_header (wpc.infile, &wps->wphdr); 65 bcount = read_next_header (wpc.infile, &wps->wphdr);
66 66
67 if (bcount == (ulong) -1) { 67 if (bcount == (uint32_t) -1) {
68 strcpy_loc (error, "invalid WavPack file!"); 68 strcpy_loc (error, "invalid WavPack file!");
69 return NULL; 69 return NULL;
70 } 70 }
@@ -74,7 +74,7 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
74 return NULL; 74 return NULL;
75 } 75 }
76 76
77 if (wps->wphdr.block_samples && wps->wphdr.total_samples != (ulong) -1) 77 if (wps->wphdr.block_samples && wps->wphdr.total_samples != (uint32_t) -1)
78 wpc.total_samples = wps->wphdr.total_samples; 78 wpc.total_samples = wps->wphdr.total_samples;
79 79
80 if (!unpack_init (&wpc)) { 80 if (!unpack_init (&wpc)) {
@@ -148,18 +148,18 @@ int WavpackGetMode (WavpackContext *wpc)
148 148
149// Unpack the specified number of samples from the current file position. 149// Unpack the specified number of samples from the current file position.
150// Note that "samples" here refers to "complete" samples, which would be 150// Note that "samples" here refers to "complete" samples, which would be
151// 2 longs for stereo files. The audio data is returned right-justified in 151// 2 int32_t's for stereo files. The audio data is returned right-justified in
152// 32-bit longs in the endian mode native to the executing processor. So, 152// 32-bit int32_t's in the endian mode native to the executing processor. So,
153// if the original data was 16-bit, then the values returned would be 153// if the original data was 16-bit, then the values returned would be
154// +/-32k. Floating point data can also be returned if the source was 154// +/-32k. Floating point data can also be returned if the source was
155// floating point data (and this is normalized to +/-1.0). The actual number 155// floating point data (and this is normalized to +/-1.0). The actual number
156// of samples unpacked is returned, which should be equal to the number 156// of samples unpacked is returned, which should be equal to the number
157// requested unless the end of fle is encountered or an error occurs. 157// requested unless the end of fle is encountered or an error occurs.
158 158
159ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples) 159uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples)
160{ 160{
161 WavpackStream *wps = &wpc->stream; 161 WavpackStream *wps = &wpc->stream;
162 ulong bcount, samples_unpacked = 0, samples_to_unpack; 162 uint32_t bcount, samples_unpacked = 0, samples_to_unpack;
163 int num_channels = wpc->config.num_channels; 163 int num_channels = wpc->config.num_channels;
164 164
165 while (samples) { 165 while (samples) {
@@ -167,7 +167,7 @@ ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples)
167 wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) { 167 wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) {
168 bcount = read_next_header (wpc->infile, &wps->wphdr); 168 bcount = read_next_header (wpc->infile, &wps->wphdr);
169 169
170 if (bcount == (ulong) -1) 170 if (bcount == (uint32_t) -1)
171 break; 171 break;
172 172
173 if (wps->wphdr.version < 0x402 || wps->wphdr.version > 0x40f) { 173 if (wps->wphdr.version < 0x402 || wps->wphdr.version > 0x40f) {
@@ -234,19 +234,19 @@ ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples)
234 234
235// Get total number of samples contained in the WavPack file, or -1 if unknown 235// Get total number of samples contained in the WavPack file, or -1 if unknown
236 236
237ulong WavpackGetNumSamples (WavpackContext *wpc) 237uint32_t WavpackGetNumSamples (WavpackContext *wpc)
238{ 238{
239 return wpc ? wpc->total_samples : (ulong) -1; 239 return wpc ? wpc->total_samples : (uint32_t) -1;
240} 240}
241 241
242// Get the current sample index position, or -1 if unknown 242// Get the current sample index position, or -1 if unknown
243 243
244ulong WavpackGetSampleIndex (WavpackContext *wpc) 244uint32_t WavpackGetSampleIndex (WavpackContext *wpc)
245{ 245{
246 if (wpc) 246 if (wpc)
247 return wpc->stream.sample_index; 247 return wpc->stream.sample_index;
248 248
249 return (ulong) -1; 249 return (uint32_t) -1;
250} 250}
251 251
252// Get the number of errors encountered so far 252// Get the number of errors encountered so far
@@ -265,7 +265,7 @@ int WavpackLossyBlocks (WavpackContext *wpc)
265 265
266// Returns the sample rate of the specified WavPack file 266// Returns the sample rate of the specified WavPack file
267 267
268ulong WavpackGetSampleRate (WavpackContext *wpc) 268uint32_t WavpackGetSampleRate (WavpackContext *wpc)
269{ 269{
270 return wpc ? wpc->config.sample_rate : 44100; 270 return wpc ? wpc->config.sample_rate : 44100;
271} 271}
@@ -284,7 +284,7 @@ int WavpackGetNumChannels (WavpackContext *wpc)
284// always has 32 bits, integers may be from 1 to 32 bits each. When this 284// always has 32 bits, integers may be from 1 to 32 bits each. When this
285// value is not a multiple of 8, then the "extra" bits are located in the 285// value is not a multiple of 8, then the "extra" bits are located in the
286// LSBs of the results. That is, values are right justified when unpacked 286// LSBs of the results. That is, values are right justified when unpacked
287// into longs, but are left justified in the number of bytes used by the 287// into int32_t's, but are left justified in the number of bytes used by the
288// original data. 288// original data.
289 289
290int WavpackGetBitsPerSample (WavpackContext *wpc) 290int WavpackGetBitsPerSample (WavpackContext *wpc)
@@ -294,8 +294,8 @@ int WavpackGetBitsPerSample (WavpackContext *wpc)
294 294
295// Returns the number of bytes used for each sample (1 to 4) in the original 295// Returns the number of bytes used for each sample (1 to 4) in the original
296// file. This is required information for the user of this module because the 296// file. This is required information for the user of this module because the
297// audio data is returned in the LOWER bytes of the long buffer and must be 297// audio data is returned in the LOWER bytes of the int32_t buffer and must be
298// left-shifted 8, 16, or 24 bits if normalized longs are required. 298// left-shifted 8, 16, or 24 bits if normalized int32_t's are required.
299 299
300int WavpackGetBytesPerSample (WavpackContext *wpc) 300int WavpackGetBytesPerSample (WavpackContext *wpc)
301{ 301{
@@ -321,10 +321,10 @@ int WavpackGetReducedChannels (WavpackContext *wpc)
321// to indicate the error. No additional bytes are read past the header and it 321// to indicate the error. No additional bytes are read past the header and it
322// is returned in the processor's native endian mode. Seeking is not required. 322// is returned in the processor's native endian mode. Seeking is not required.
323 323
324static ulong read_next_header (read_stream infile, WavpackHeader *wphdr) 324static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr)
325{ 325{
326 char buffer [sizeof (*wphdr)], *sp = buffer + sizeof (*wphdr), *ep = sp; 326 char buffer [sizeof (*wphdr)], *sp = buffer + sizeof (*wphdr), *ep = sp;
327 ulong bytes_skipped = 0; 327 uint32_t bytes_skipped = 0;
328 int bleft; 328 int bleft;
329 329
330 while (1) { 330 while (1) {
@@ -335,7 +335,7 @@ static ulong read_next_header (read_stream infile, WavpackHeader *wphdr)
335 else 335 else
336 bleft = 0; 336 bleft = 0;
337 337
338 if (infile (buffer + bleft, sizeof (*wphdr) - bleft) != (long) sizeof (*wphdr) - bleft) 338 if (infile (buffer + bleft, sizeof (*wphdr) - bleft) != (int32_t) sizeof (*wphdr) - bleft)
339 return -1; 339 return -1;
340 340
341 sp = buffer; 341 sp = buffer;
@@ -407,10 +407,10 @@ WavpackContext *WavpackOpenFileOutput (void)
407// WavPack file will not be directly unpackable to a valid wav file (although 407// WavPack file will not be directly unpackable to a valid wav file (although
408// it will still be usable by itself). A return of FALSE indicates an error. 408// it will still be usable by itself). A return of FALSE indicates an error.
409 409
410int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong total_samples) 410int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples)
411{ 411{
412 WavpackStream *wps = &wpc->stream; 412 WavpackStream *wps = &wpc->stream;
413 ulong flags = (config->bytes_per_sample - 1), shift = 0; 413 uint32_t flags = (config->bytes_per_sample - 1), shift = 0;
414 int num_chans = config->num_channels; 414 int num_chans = config->num_channels;
415 int i; 415 int i;
416 416
@@ -467,7 +467,7 @@ int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong t
467// first block written and update the header directly. An example of this can 467// first block written and update the header directly. An example of this can
468// be found in the Audition filter. 468// be found in the Audition filter.
469 469
470void WavpackAddWrapper (WavpackContext *wpc, void *data, ulong bcount) 470void WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount)
471{ 471{
472 wpc->wrapper_data = data; 472 wpc->wrapper_data = data;
473 wpc->wrapper_bytes = bcount; 473 wpc->wrapper_bytes = bcount;
@@ -484,7 +484,7 @@ int WavpackStartBlock (WavpackContext *wpc, uchar *begin, uchar *end)
484 return pack_start_block (wpc); 484 return pack_start_block (wpc);
485} 485}
486 486
487// Pack the specified samples. Samples must be stored in longs in the native 487// Pack the specified samples. Samples must be stored in int32_ts in the native
488// endian format of the executing processor. The number of samples specified 488// endian format of the executing processor. The number of samples specified
489// indicates composite samples (sometimes called "frames"). So, the actual 489// indicates composite samples (sometimes called "frames"). So, the actual
490// number of data points would be this "sample_count" times the number of 490// 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)
493// many times as desired to build the final block (and performs the actual 493// many times as desired to build the final block (and performs the actual
494// compression during the call). A return of FALSE indicates an error. 494// compression during the call). A return of FALSE indicates an error.
495 495
496int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_count) 496int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count)
497{ 497{
498 if (!sample_count || pack_samples (wpc, sample_buffer, sample_count)) 498 if (!sample_count || pack_samples (wpc, sample_buffer, sample_count))
499 return TRUE; 499 return TRUE;
@@ -506,10 +506,10 @@ int WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_c
506// block in bytes. Note that the possible conversion of the WavPack header to 506// block in bytes. Note that the possible conversion of the WavPack header to
507// little-endian takes place here. 507// little-endian takes place here.
508 508
509ulong WavpackFinishBlock (WavpackContext *wpc) 509uint32_t WavpackFinishBlock (WavpackContext *wpc)
510{ 510{
511 WavpackStream *wps = &wpc->stream; 511 WavpackStream *wps = &wpc->stream;
512 ulong bcount; 512 uint32_t bcount;
513 513
514 pack_finish_block (wpc); 514 pack_finish_block (wpc);
515 bcount = ((WavpackHeader *) wps->blockbuff)->ckSize + 8; 515 bcount = ((WavpackHeader *) wps->blockbuff)->ckSize + 8;
diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c
index ee21347b73..febea1e705 100644
--- a/apps/codecs/wavpack.c
+++ b/apps/codecs/wavpack.c
@@ -26,11 +26,11 @@ static struct codec_api *ci;
26 26
27#define BUFFER_SIZE 4096 27#define BUFFER_SIZE 4096
28 28
29static long temp_buffer [BUFFER_SIZE] IBSS_ATTR; 29static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR;
30 30
31static long read_callback (void *buffer, long bytes) 31static int32_t read_callback (void *buffer, int32_t bytes)
32{ 32{
33 long retval = ci->read_filebuf (buffer, bytes); 33 int32_t retval = ci->read_filebuf (buffer, bytes);
34 ci->id3->offset = ci->curpos; 34 ci->id3->offset = ci->curpos;
35 return retval; 35 return retval;
36} 36}
@@ -63,7 +63,7 @@ enum codec_status codec_start(struct codec_api* api)
63 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 63 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
64 64
65 ci->configure(DSP_DITHER, (bool *)false); 65 ci->configure(DSP_DITHER, (bool *)false);
66 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(27)); // should be 28... 66 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(28));
67 67
68 next_track: 68 next_track:
69 69
@@ -97,7 +97,7 @@ enum codec_status codec_start(struct codec_api* api)
97 /* The main decoder loop */ 97 /* The main decoder loop */
98 98
99 while (1) { 99 while (1) {
100 long nsamples; 100 int32_t nsamples;
101 101
102 if (ci->seek_time && ci->taginfo_ready && ci->id3->length) { 102 if (ci->seek_time && ci->taginfo_ready && ci->id3->length) {
103 ci->seek_time--; 103 ci->seek_time--;
@@ -107,13 +107,13 @@ enum codec_status codec_start(struct codec_api* api)
107 if (ci->seek_time > curpos_ms) { 107 if (ci->seek_time > curpos_ms) {
108 n = ci->seek_time - curpos_ms; 108 n = ci->seek_time - curpos_ms;
109 d = ci->id3->length - curpos_ms; 109 d = ci->id3->length - curpos_ms;
110 skip = (int)((long long)(ci->filesize - ci->curpos) * n / d); 110 skip = (int)((int64_t)(ci->filesize - ci->curpos) * n / d);
111 ci->seek_buffer (ci->curpos + skip); 111 ci->seek_buffer (ci->curpos + skip);
112 } 112 }
113 else { 113 else {
114 n = curpos_ms - ci->seek_time; 114 n = curpos_ms - ci->seek_time;
115 d = curpos_ms; 115 d = curpos_ms;
116 skip = (int)((long long) ci->curpos * n / d); 116 skip = (int)((int64_t) ci->curpos * n / d);
117 ci->seek_buffer (ci->curpos - skip); 117 ci->seek_buffer (ci->curpos - skip);
118 } 118 }
119 119
diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c
index 7e85572d78..5b71e7e759 100644
--- a/apps/plugins/wav2wv.c
+++ b/apps/plugins/wav2wv.c
@@ -42,42 +42,42 @@ static int audiobuflen;
42 42
43static struct wav_header { 43static struct wav_header {
44 char ckID [4]; /* RIFF chuck header */ 44 char ckID [4]; /* RIFF chuck header */
45 long ckSize; 45 int32_t ckSize;
46 char formType [4]; 46 char formType [4];
47 47
48 char fmt_ckID [4]; /* format chunk header */ 48 char fmt_ckID [4]; /* format chunk header */
49 long fmt_ckSize; 49 int32_t fmt_ckSize;
50 ushort FormatTag, NumChannels; 50 ushort FormatTag, NumChannels;
51 ulong SampleRate, BytesPerSecond; 51 uint32_t SampleRate, BytesPerSecond;
52 ushort BlockAlign, BitsPerSample; 52 ushort BlockAlign, BitsPerSample;
53 53
54 char data_ckID [4]; /* data chunk header */ 54 char data_ckID [4]; /* data chunk header */
55 long data_ckSize; 55 int32_t data_ckSize;
56} raw_header, native_header; 56} raw_header, native_header;
57 57
58#define WAV_HEADER_FORMAT "4L44LSSLLSS4L" 58#define WAV_HEADER_FORMAT "4L44LSSLLSS4L"
59 59
60static void wvupdate (long start_tick, 60static void wvupdate (int32_t start_tick,
61 long sample_rate, 61 int32_t sample_rate,
62 ulong total_samples, 62 uint32_t total_samples,
63 ulong samples_converted, 63 uint32_t samples_converted,
64 ulong bytes_read, 64 uint32_t bytes_read,
65 ulong bytes_written) 65 uint32_t bytes_written)
66{ 66{
67 long elapsed_ticks = *rb->current_tick - start_tick; 67 int32_t elapsed_ticks = *rb->current_tick - start_tick;
68 int compression = 0, progress = 0, realtime = 0; 68 int compression = 0, progress = 0, realtime = 0;
69 char buf[32]; 69 char buf[32];
70 70
71 if (total_samples) 71 if (total_samples)
72 progress = (int)(((long long) samples_converted * 100 + 72 progress = (int)(((int64_t) samples_converted * 100 +
73 (total_samples/2)) / total_samples); 73 (total_samples/2)) / total_samples);
74 74
75 if (elapsed_ticks) 75 if (elapsed_ticks)
76 realtime = (int)(((long long) samples_converted * 100 * HZ / 76 realtime = (int)(((int64_t) samples_converted * 100 * HZ /
77 sample_rate + (elapsed_ticks/2)) / elapsed_ticks); 77 sample_rate + (elapsed_ticks/2)) / elapsed_ticks);
78 78
79 if (bytes_read) 79 if (bytes_read)
80 compression = (int)(((long long)(bytes_read - bytes_written) * 100 + 80 compression = (int)(((int64_t)(bytes_read - bytes_written) * 100 +
81 (bytes_read/2)) / bytes_read); 81 (bytes_read/2)) / bytes_read);
82 82
83 rb->snprintf(buf, 32, "elapsed time: %d secs", (elapsed_ticks + (HZ/2)) / HZ); 83 rb->snprintf(buf, 32, "elapsed time: %d secs", (elapsed_ticks + (HZ/2)) / HZ);
@@ -99,19 +99,19 @@ static void wvupdate (long start_tick,
99 99
100#define TEMP_SAMPLES 4096 100#define TEMP_SAMPLES 4096
101 101
102static long temp_buffer [TEMP_SAMPLES] IDATA_ATTR; 102static int32_t temp_buffer [TEMP_SAMPLES] IDATA_ATTR;
103 103
104static int wav2wv (char *filename) 104static int wav2wv (char *filename)
105{ 105{
106 int in_fd, out_fd, num_chans, error = false, last_buttons; 106 int in_fd, out_fd, num_chans, error = false, last_buttons;
107 unsigned long total_bytes_read = 0, total_bytes_written = 0; 107 unsigned int32_t total_bytes_read = 0, total_bytes_written = 0;
108 unsigned long total_samples, samples_remaining; 108 unsigned int32_t total_samples, samples_remaining;
109 long *input_buffer = (long *) audiobuf; 109 int32_t *input_buffer = (int32_t *) audiobuf;
110 unsigned char *output_buffer = (unsigned char *)(audiobuf + 0x100000); 110 unsigned char *output_buffer = (unsigned char *)(audiobuf + 0x100000);
111 char *extension, save_a; 111 char *extension, save_a;
112 WavpackConfig config; 112 WavpackConfig config;
113 WavpackContext *wpc; 113 WavpackContext *wpc;
114 long start_tick; 114 int32_t start_tick;
115 115
116 rb->lcd_clear_display(); 116 rb->lcd_clear_display();
117 rb->lcd_puts_scroll(0, 0, (unsigned char *)filename); 117 rb->lcd_puts_scroll(0, 0, (unsigned char *)filename);
@@ -188,9 +188,9 @@ static int wav2wv (char *filename)
188 wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0); 188 wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0);
189 189
190 for (samples_remaining = total_samples; samples_remaining;) { 190 for (samples_remaining = total_samples; samples_remaining;) {
191 unsigned long samples_count, samples_to_pack, bytes_count; 191 unsigned int32_t samples_count, samples_to_pack, bytes_count;
192 int cnt, buttons; 192 int cnt, buttons;
193 long value, *lp; 193 int32_t value, *lp;
194 signed char *cp; 194 signed char *cp;
195 195
196 samples_count = SAMPLES_PER_BLOCK; 196 samples_count = SAMPLES_PER_BLOCK;
@@ -200,7 +200,7 @@ static int wav2wv (char *filename)
200 200
201 bytes_count = samples_count * num_chans * 2; 201 bytes_count = samples_count * num_chans * 2;
202 202
203 if (rb->read (in_fd, input_buffer, bytes_count) != (long) bytes_count) { 203 if (rb->read (in_fd, input_buffer, bytes_count) != (int32_t) bytes_count) {
204 rb->splash(HZ*2, true, "could not read file!"); 204 rb->splash(HZ*2, true, "could not read file!");
205 error = true; 205 error = true;
206 break; 206 break;
@@ -212,7 +212,7 @@ static int wav2wv (char *filename)
212 cp = (signed char *) input_buffer; 212 cp = (signed char *) input_buffer;
213 213
214 while (samples_to_pack) { 214 while (samples_to_pack) {
215 unsigned long samples_this_pass = TEMP_SAMPLES / num_chans; 215 unsigned int32_t samples_this_pass = TEMP_SAMPLES / num_chans;
216 216
217 if (samples_this_pass > samples_to_pack) 217 if (samples_this_pass > samples_to_pack)
218 samples_this_pass = samples_to_pack; 218 samples_this_pass = samples_to_pack;
@@ -250,7 +250,7 @@ static int wav2wv (char *filename)
250 250
251 bytes_count = WavpackFinishBlock (wpc); 251 bytes_count = WavpackFinishBlock (wpc);
252 252
253 if (rb->write (out_fd, output_buffer, bytes_count) != (long) bytes_count) { 253 if (rb->write (out_fd, output_buffer, bytes_count) != (int32_t) bytes_count) {
254 rb->splash(HZ*2, true, "could not write file!"); 254 rb->splash(HZ*2, true, "could not write file!");
255 error = true; 255 error = true;
256 break; 256 break;