Index: id3.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/id3.c,v
retrieving revision 1.30
diff -u -r1.30 id3.c
--- id3.c	5 Jul 2002 07:13:42 -0000	1.30
+++ id3.c	5 Jul 2002 20:22:05 -0000
@@ -518,6 +518,21 @@
     return filetime;
 }
 
+/*
+ * Calculates the average bitrate for a VBR MP3 file.
+ *
+ * Arguments: entry - the entry to update with the length
+ *
+ * Returns: the average bitrate
+ */
+static void setavgvbrbitrate(struct mp3entry *entry)
+{
+    /* length of song in bytes */
+    int songbytes = entry->filesize - entry->id3v1len - entry->id3v2len;
+    
+    /* songbytes * 8 b/B * 1000 ms/s / seconds / 1000 b/kb */
+    entry->bitrate = (songbytes * 8) / entry->length;
+}
 
 /*
  * Checks all relevant information (such as ID3v1 tag, ID3v2 tag, length etc)
@@ -549,11 +564,15 @@
     
     if(HASID3V2(entry))
         setid3v2title(fd, entry);
-    entry->length = getsonglength(fd, entry);
 
     entry->id3v1len = getid3v1len(fd);
     if(HASID3V1(entry) && !entry->title)
         setid3v1title(fd, entry);
+
+    entry->length = getsonglength(fd, entry);
+
+    if (entry->vbr)
+        setavgvbrbitrate(entry);
 
     close(fd);
 

