summaryrefslogtreecommitdiff
path: root/firmware/id3.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-07-10 13:17:31 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-07-10 13:17:31 +0000
commit5e2898f3d4d1bdd832334225a2ffbd9f121dabca (patch)
treecb732013f1fc89aec407602c884b46c53d6e8795 /firmware/id3.c
parent7c342b8d332c69f377a2af3081e03c2418ea8532 (diff)
Added average bitrate for VBR mp3
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1346 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/id3.c')
-rw-r--r--firmware/id3.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/firmware/id3.c b/firmware/id3.c
index b363adc0dd..ebfa1d368f 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -364,8 +364,7 @@ static int getsonglength(int fd, struct mp3entry *entry)
unsigned int filetime = 0;
unsigned long header=0;
unsigned char tmp;
- unsigned char frame[200];
- unsigned int framecount;
+ unsigned char frame[64];
int version;
int layer;
@@ -458,7 +457,6 @@ static int getsonglength(int fd, struct mp3entry *entry)
#endif
entry->version = version;
entry->layer = layer;
- entry->bitrate = bitrate;
entry->frequency = frequency;
/* Calculate bytes per frame, calculation depends on layer */
@@ -482,7 +480,7 @@ static int getsonglength(int fd, struct mp3entry *entry)
tpf = bs[layer] / freqtab[version-1][freqindex] << (version - 1);
/* OK, we have found a frame. Let's see if it has a Xing header */
- if(read(fd, frame, 200) < 0)
+ if(read(fd, frame, sizeof frame) < 0)
return -1;
if(frame[32] == 'X' &&
@@ -495,15 +493,23 @@ static int getsonglength(int fd, struct mp3entry *entry)
if(frame[39] & 0x01) /* Is the frame count there? */
{
- framecount = (frame[40] << 24) | (frame[41] << 16) |
+ int framecount = (frame[40] << 24) | (frame[41] << 16) |
(frame[42] << 8) | frame[43];
filetime = framecount * tpf;
}
- /* We don't care about the file size and the TOC just yet. Maybe
- another time. */
+ if (frame[39] & 0x02) /* is byte count there? */
+ {
+ int bytecount = (frame[44] << 24) | (frame[45] << 16) |
+ (frame[46] << 8) | frame[47];
+
+ bitrate = bytecount * 8 / filetime;
+ }
+ /* We don't care about the TOC just yet. Maybe another time. */
}
+ entry->bitrate = bitrate;
+
/* If the file time hasn't been established, this may be a fixed
rate MP3, so just use the default formula */
if(filetime == 0)