Index: apps/codecs/libmad/mad.h =================================================================== --- apps/codecs/libmad/mad.h (revision 26801) +++ apps/codecs/libmad/mad.h (working copy) @@ -540,6 +540,8 @@ unsigned char const *byte; unsigned short cache; unsigned short left; + unsigned int dummy1; /* IMPORTANT: Need to add dummy1/2 to have the same */ + unsigned int dummy2; /* struct size as mad_bitptr in bit.h */ }; void mad_bit_init(struct mad_bitptr *, unsigned char const *); Index: apps/codecs/libmad/bit.c =================================================================== --- apps/codecs/libmad/bit.c (revision 26801) +++ apps/codecs/libmad/bit.c (working copy) @@ -94,6 +94,8 @@ { bitptr->ptr = (uint32_t*)((uintptr_t)byte & ~3); bitptr->readbit = ((uintptr_t)byte & 3) << 3; + bitptr->buffered_addr = 0; + bitptr->buffered_dword = 0; } /* @@ -132,18 +134,32 @@ * NAME: bit->read() * DESCRIPTION: read an arbitrary number of bits and return their UIMSBF value */ + +//static uint32_t* last_addr IBSS_ATTR = 0; +//static uint32_t last_value IBSS_ATTR = 0; 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) { uint32_t *curr = &bitptr->ptr[bitptr->readbit>>5]; + + /* Do we need to load a new value? */ + if (bitptr->buffered_addr != curr) + { + bitptr->buffered_addr = curr; + bitptr->buffered_dword = betoh32(curr[0]); + } if(len) { - uint32_t r = betoh32(curr[0]) << (bitptr->readbit & 31); + uint32_t r = bitptr->buffered_dword << (bitptr->readbit & 31); if((bitptr->readbit & 31) + len > 32) - r += betoh32(curr[1]) >> (-bitptr->readbit & 31); + { + bitptr->buffered_addr = &curr[1]; + bitptr->buffered_dword = betoh32(curr[1]); + r += bitptr->buffered_dword >> (-bitptr->readbit & 31); + } bitptr->readbit += len; return r >> (32 - len); Index: apps/codecs/libmad/bit.h =================================================================== --- apps/codecs/libmad/bit.h (revision 26801) +++ apps/codecs/libmad/bit.h (working copy) @@ -25,6 +25,8 @@ struct mad_bitptr { uint32_t *ptr; uint32_t readbit; + uint32_t *buffered_addr; /* rockbox: buffer bitstream data address */ + uint32_t buffered_dword; /* rockbox: buffer bitstream data */ }; void mad_bit_init(struct mad_bitptr *, unsigned char const *);