summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-09-07 23:45:42 +0000
committerJens Arnold <amiconn@rockbox.org>2007-09-07 23:45:42 +0000
commitaebeabdade29ad959f1ed2ae36bafa9c3eed3a48 (patch)
treec74506974e5be5029bf78530b2439eec18a122f1
parentb69556f3eb35da3de7dc8f31e1accf7850522f37 (diff)
downloadrockbox-aebeabdade29ad959f1ed2ae36bafa9c3eed3a48.tar.gz
rockbox-aebeabdade29ad959f1ed2ae36bafa9c3eed3a48.zip
Stop libmad from crashing on 64 bit simulators.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14636 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libmad/bit.c20
-rw-r--r--apps/codecs/libmad/bit.h8
-rw-r--r--apps/codecs/libmad/synth.c7
3 files changed, 20 insertions, 15 deletions
diff --git a/apps/codecs/libmad/bit.c b/apps/codecs/libmad/bit.c
index 6c984ef078..f132347c25 100644
--- a/apps/codecs/libmad/bit.c
+++ b/apps/codecs/libmad/bit.c
@@ -82,14 +82,18 @@ unsigned short const crc_table[256] = {
# define CRC_POLY 0x8005
+#if INT_MAX != 0x7fffffff
+#warning current libmad bit handling is optimized for architectures using 32 bit integers
+#endif
+
/*
* NAME: bit->init()
* DESCRIPTION: initialize bit pointer struct
*/
void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte)
{
- bitptr->ptr = (unsigned long*)((long)byte & ~3);
- bitptr->readbit = ((unsigned long)byte & 3) << 3;
+ bitptr->ptr = (uint32_t*)((uintptr_t)byte & ~3);
+ bitptr->readbit = ((uintptr_t)byte & 3) << 3;
}
/*
@@ -129,14 +133,14 @@ void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len)
* DESCRIPTION: read an arbitrary number of bits and return their UIMSBF value
*/
-unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len) ICODE_ATTR;
-unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
+uint32_t mad_bit_read(struct mad_bitptr *bitptr, unsigned int len) ICODE_ATTR;
+uint32_t mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
{
- unsigned long *curr = &bitptr->ptr[bitptr->readbit>>5];
+ uint32_t *curr = &bitptr->ptr[bitptr->readbit>>5];
if(len)
{
- unsigned long r = betoh32(curr[0]) << (bitptr->readbit & 31);
+ uint32_t r = betoh32(curr[0]) << (bitptr->readbit & 31);
if((bitptr->readbit & 31) + len > 32)
r += betoh32(curr[1]) >> (-bitptr->readbit & 31);
@@ -154,7 +158,7 @@ unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
* DESCRIPTION: write an arbitrary number of bits
*/
void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
- unsigned long value)
+ uint32_t value)
{
unsigned char *ptr;
@@ -174,7 +178,7 @@ unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
register unsigned int crc;
for (crc = init; len >= 32; len -= 32) {
- register unsigned long data;
+ register uint32_t data;
data = mad_bit_read(&bitptr, 32);
diff --git a/apps/codecs/libmad/bit.h b/apps/codecs/libmad/bit.h
index 026b501b57..615cabee89 100644
--- a/apps/codecs/libmad/bit.h
+++ b/apps/codecs/libmad/bit.h
@@ -23,8 +23,8 @@
# define LIBMAD_BIT_H
struct mad_bitptr {
- unsigned long *ptr;
- unsigned long readbit;
+ uint32_t *ptr;
+ uint32_t readbit;
};
void mad_bit_init(struct mad_bitptr *, unsigned char const *);
@@ -38,8 +38,8 @@ unsigned char mad_bit_bitsleft(struct mad_bitptr const *bitptr);
unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *);
void mad_bit_skip(struct mad_bitptr *, unsigned int);
-unsigned long mad_bit_read(struct mad_bitptr *, unsigned int);
-void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long);
+uint32_t mad_bit_read(struct mad_bitptr *, unsigned int);
+void mad_bit_write(struct mad_bitptr *, unsigned int, uint32_t);
unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short);
diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c
index 6f5d2ec975..c023f01ae5 100644
--- a/apps/codecs/libmad/synth.c
+++ b/apps/codecs/libmad/synth.c
@@ -589,7 +589,8 @@ static
void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
unsigned int nch, unsigned int ns)
{
- unsigned int phase, ch, s, sb, p;
+ int sb;
+ unsigned int phase, ch, s, p;
mad_fixed_t *pcm, (*filter)[2][2][16][8];
mad_fixed_t const (*sbsample)[36][32];
mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
@@ -1190,8 +1191,8 @@ static
void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
unsigned int nch, unsigned int ns)
{
- int p;
- unsigned int phase, ch, s, sb;
+ int p, sb;
+ unsigned int phase, ch, s;
mad_fixed_t *pcm, (*filter)[2][2][16][8];
mad_fixed_t const (*sbsample)[36][32];
mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];