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; } /* @@ -131,19 +133,37 @@ /* * NAME: bit->read() * DESCRIPTION: read an arbitrary number of bits and return their UIMSBF value + * ROCKBOX change: To avoid unneeded calls of betoh32() and loads from DRAM + (bitptr->ptr is not located in IRAM) two variables and a logic was introduced. + If a new address must be loaded, the loaded and betoh32()-converted data is + saved to a buffer variable that is located in IRAM. Further calls of + mad_bit_read() will use this buffered data as long as the data's address does + not change. The check whether a new address needs to be loaded is done via + another buffer variable that holds the address of the current buffered data. */ 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]; + + /* rockbox: Do we need to load (and LE-convert) data from a new address? */ + 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 *);