From aa8761fccc5ac005b8284246c7c637595cc9489e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 15 Feb 2007 22:55:22 +0000 Subject: Shave a few bytes off the binary size, especially on hwcodec targets git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12323 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.c | 13 ------------- apps/tagcache.h | 1 - firmware/export/mp3data.h | 5 +++++ firmware/id3.c | 43 +++++++++++++++++++++++-------------------- firmware/mp3data.c | 36 +++++++++++++++++++++++------------- 5 files changed, 51 insertions(+), 47 deletions(-) diff --git a/apps/tagcache.c b/apps/tagcache.c index 6ef0755809..43b4ad6e3b 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -226,19 +226,6 @@ static int processed_dir_count; static volatile int write_lock; static volatile int read_lock; -int tagcache_str_to_tag(const char *str) -{ - int i; - - for (i = 0; i < (long)(sizeof(tags_str)/sizeof(tags_str[0])); i++) - { - if (!strcasecmp(tags_str[i], str)) - return i; - } - - return -1; -} - const char* tagcache_tag_to_str(int tag) { return tags_str[tag]; diff --git a/apps/tagcache.h b/apps/tagcache.h index 5140aa1989..771629f6f2 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -142,7 +142,6 @@ void build_tagcache(const char *path); void tagcache_reverse_scan(void); #endif -int tagcache_str_to_tag(const char *str); const char* tagcache_tag_to_str(int tag); bool tagcache_is_numeric_tag(int type); diff --git a/firmware/export/mp3data.h b/firmware/export/mp3data.h index f36120a4e5..6ae97376c8 100644 --- a/firmware/export/mp3data.h +++ b/firmware/export/mp3data.h @@ -73,4 +73,9 @@ int create_xing_header(int fd, long startpos, long filesize, unsigned long rec_time, unsigned long header_template, void (*progressfunc)(int), bool generate_toc); +extern unsigned long bytes2int(unsigned long b0, + unsigned long b1, + unsigned long b2, + unsigned long b3); + #endif diff --git a/firmware/id3.c b/firmware/id3.c index 0547bed3af..dd20926df2 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -137,15 +137,16 @@ const int afmt_rec_format[AFMT_NUM_CODECS] = #endif /* CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) */ /****/ -#define UNSYNC(b0,b1,b2,b3) (((long)(b0 & 0x7F) << (3*7)) | \ - ((long)(b1 & 0x7F) << (2*7)) | \ - ((long)(b2 & 0x7F) << (1*7)) | \ - ((long)(b3 & 0x7F) << (0*7))) - -#define BYTES2INT(b0,b1,b2,b3) (((long)(b0 & 0xFF) << (3*8)) | \ - ((long)(b1 & 0xFF) << (2*8)) | \ - ((long)(b2 & 0xFF) << (1*8)) | \ - ((long)(b3 & 0xFF) << (0*8))) +unsigned long unsync(unsigned long b0, + unsigned long b1, + unsigned long b2, + unsigned long b3) +{ + return (((long)(b0 & 0x7F) << (3*7)) | + ((long)(b1 & 0x7F) << (2*7)) | + ((long)(b2 & 0x7F) << (1*7)) | + ((long)(b3 & 0x7F) << (0*7))); +} static const char* const genres[] = { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", @@ -500,7 +501,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) { /* Handle frames with more than one string (needed for TXXX frames).*/ do { - tmp = BYTES2INT(0, 0, str[0], str[1]); + tmp = bytes2int(0, 0, str[0], str[1]); /* Now check if there is a BOM (zero-width non-breaking space, 0xfeff) @@ -706,9 +707,9 @@ static void setid3v2title(int fd, struct mp3entry *entry) /* The 2.3 extended header size doesn't include the following data, so we have to find out the size by checking the flags. Also, it is not unsynched. */ - framelen = BYTES2INT(header[0], header[1], header[2], header[3]) + - BYTES2INT(header[6], header[7], header[8], header[9]); - flags = BYTES2INT(0, 0, header[4], header[5]); + framelen = bytes2int(header[0], header[1], header[2], header[3]) + + bytes2int(header[6], header[7], header[8], header[9]); + flags = bytes2int(0, 0, header[4], header[5]); if(flags & 0x8000) framelen += 4; /* CRC */ @@ -721,7 +722,7 @@ static void setid3v2title(int fd, struct mp3entry *entry) /* The 2.4 extended header size does include the entire header, so here we can just skip it. This header is unsynched. */ - framelen = UNSYNC(header[0], header[1], + framelen = unsync(header[0], header[1], header[2], header[3]); lseek(fd, framelen - 4, SEEK_CUR); @@ -751,15 +752,15 @@ static void setid3v2title(int fd, struct mp3entry *entry) /* Adjust for the 10 bytes we read */ size -= 10; - flags = BYTES2INT(0, 0, header[8], header[9]); + flags = bytes2int(0, 0, header[8], header[9]); if (version >= ID3_VER_2_4) { - framelen = UNSYNC(header[4], header[5], + framelen = unsync(header[4], header[5], header[6], header[7]); } else { /* version .3 files don't use synchsafe ints for * size */ - framelen = BYTES2INT(header[4], header[5], + framelen = bytes2int(header[4], header[5], header[6], header[7]); } } else { @@ -768,7 +769,7 @@ static void setid3v2title(int fd, struct mp3entry *entry) /* Adjust for the 6 bytes we read */ size -= 6; - framelen = BYTES2INT(0, header[3], header[4], header[5]); + framelen = bytes2int(0, header[3], header[4], header[5]); } /* Keep track of the total size */ @@ -818,7 +819,7 @@ static void setid3v2title(int fd, struct mp3entry *entry) if(4 != read(fd, tmp, 4)) return; - data_length_ind = UNSYNC(tmp[0], tmp[1], tmp[2], tmp[3]); + data_length_ind = unsync(tmp[0], tmp[1], tmp[2], tmp[3]); framelen -= 4; } } @@ -963,7 +964,7 @@ int getid3v2len(int fd) if(read(fd, buf, 4) != 4) offset = 0; else - offset = UNSYNC(buf[0], buf[1], buf[2], buf[3]) + 10; + offset = unsync(buf[0], buf[1], buf[2], buf[3]) + 10; DEBUGF("ID3V2 Length: 0x%x\n", offset); return offset; @@ -1066,8 +1067,10 @@ static int getsonglength(int fd, struct mp3entry *entry) entry->vbr = info.is_vbr; entry->has_toc = info.has_toc; +#if CONFIC_CODEC==SWCODEC entry->lead_trim = info.enc_delay; entry->tail_trim = info.enc_padding; +#endif memcpy(entry->toc, info.toc, sizeof(info.toc)); diff --git a/firmware/mp3data.c b/firmware/mp3data.c index 49b95f2d9e..2ebb620ed6 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c @@ -40,11 +40,6 @@ #define DEBUG_VERBOSE -#define BYTES2INT(b1,b2,b3,b4) (((long)(b1 & 0xFF) << (3*8)) | \ - ((long)(b2 & 0xFF) << (2*8)) | \ - ((long)(b3 & 0xFF) << (1*8)) | \ - ((long)(b4 & 0xFF) << (0*8))) - #define SYNC_MASK (0x7ffL << 21) #define VERSION_MASK (3L << 19) #define LAYER_MASK (3L << 17) @@ -82,13 +77,24 @@ static const short *bitrate_table[3][3] = }; /* Sampling frequency table, indexed by version and frequency index */ -static const long freq_table[3][3] = +static const unsigned short freq_table[3][3] = { {44100, 48000, 32000}, /* MPEG Version 1 */ {22050, 24000, 16000}, /* MPEG version 2 */ {11025, 12000, 8000}, /* MPEG version 2.5 */ }; +unsigned long bytes2int(unsigned long b0, + unsigned long b1, + unsigned long b2, + unsigned long b3) +{ + return (((long)(b0 & 0xFF) << (3*8)) | + ((long)(b1 & 0xFF) << (2*8)) | + ((long)(b2 & 0xFF) << (1*8)) | + ((long)(b3 & 0xFF) << (0*8))); +} + /* check if 'head' is a valid mp3 frame header */ static bool is_mp3frameheader(unsigned long head) { @@ -357,9 +363,11 @@ int get_mp3file_info(int fd, struct mp3info *info) return -1; memset(info, 0, sizeof(struct mp3info)); +#if CONFIG_CODEC==SWCODEC /* These two are needed for proper LAME gapless MP3 playback */ info->enc_delay = -1; info->enc_padding = -1; +#endif if(!mp3headerinfo(info, header)) return -2; @@ -416,7 +424,7 @@ int get_mp3file_info(int fd, struct mp3info *info) if (vbrheader[7] & VBR_FRAMES_FLAG) /* Is the frame count there? */ { - info->frame_count = BYTES2INT(vbrheader[i], vbrheader[i+1], + info->frame_count = bytes2int(vbrheader[i], vbrheader[i+1], vbrheader[i+2], vbrheader[i+3]); if (info->frame_count <= ULONG_MAX / info->ft_num) info->file_time = info->frame_count * info->ft_num / info->ft_den; @@ -427,7 +435,7 @@ int get_mp3file_info(int fd, struct mp3info *info) if (vbrheader[7] & VBR_BYTES_FLAG) /* Is byte count there? */ { - info->byte_count = BYTES2INT(vbrheader[i], vbrheader[i+1], + info->byte_count = bytes2int(vbrheader[i], vbrheader[i+1], vbrheader[i+2], vbrheader[i+3]); i += 4; } @@ -453,6 +461,7 @@ int get_mp3file_info(int fd, struct mp3info *info) /* We don't care about this, but need to skip it */ i += 4; } +#if CONFIG_CODEC==SWCODEC i += 21; info->enc_delay = (vbrheader[i] << 4) | (vbrheader[i + 1] >> 4); info->enc_padding = ((vbrheader[i + 1] & 0x0f) << 8) | vbrheader[i + 2]; @@ -465,6 +474,7 @@ int get_mp3file_info(int fd, struct mp3info *info) info->enc_delay = -1; info->enc_padding = -1; } +#endif } if (!memcmp(vbrheader, "VBRI", 4)) @@ -500,9 +510,9 @@ int get_mp3file_info(int fd, struct mp3info *info) info->is_vbri_vbr = true; info->has_toc = false; /* We don't parse the TOC (yet) */ - info->byte_count = BYTES2INT(vbrheader[10], vbrheader[11], + info->byte_count = bytes2int(vbrheader[10], vbrheader[11], vbrheader[12], vbrheader[13]); - info->frame_count = BYTES2INT(vbrheader[14], vbrheader[15], + info->frame_count = bytes2int(vbrheader[14], vbrheader[15], vbrheader[16], vbrheader[17]); if (info->frame_count <= ULONG_MAX / info->ft_num) info->file_time = info->frame_count * info->ft_num / info->ft_den; @@ -515,8 +525,8 @@ int get_mp3file_info(int fd, struct mp3info *info) info->bitrate = info->byte_count / (info->file_time >> 3); /* We don't parse the TOC, since we don't yet know how to (FIXME) */ - num_offsets = BYTES2INT(0, 0, vbrheader[18], vbrheader[19]); - frames_per_entry = BYTES2INT(0, 0, vbrheader[24], vbrheader[25]); + num_offsets = bytes2int(0, 0, vbrheader[18], vbrheader[19]); + frames_per_entry = bytes2int(0, 0, vbrheader[24], vbrheader[25]); DEBUGF("Frame size (%dkpbs): %d bytes (0x%x)\n", info->bitrate, info->frame_size, info->frame_size); DEBUGF("Frame count: %x\n", info->frame_count); @@ -528,7 +538,7 @@ int get_mp3file_info(int fd, struct mp3info *info) for(i = 0;i < num_offsets;i++) { - j = BYTES2INT(0, 0, vbrheader[26+i*2], vbrheader[27+i*2]); + j = bytes2int(0, 0, vbrheader[26+i*2], vbrheader[27+i*2]); offset += j; DEBUGF("%03d: %x (%x)\n", i, offset - bytecount, j); } -- cgit v1.2.3