changeset 673:8ed0af226d0e trunk

[svn] - calculate vbr bitrate properly. - mainwin shows dynamic bitrate for vbr.
author yaz
date Mon, 19 Feb 2007 04:55:14 -0800
parents ada6a5ad1851
children fadf4c18a1cf
files ChangeLog src/madplug/decoder.c
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Feb 19 00:02:50 2007 -0800
+++ b/ChangeLog	Mon Feb 19 04:55:14 2007 -0800
@@ -1,3 +1,11 @@
+2007-02-19 08:02:50 +0000  
+  revision [1430]
+  fix flac detection, now flac >= 1.1.4 is supported as well
+  
+  trunk/configure.ac |    6 +++++-
+  1 file changed, 5 insertions(+), 1 deletion(-)
+
+
 2007-02-18 22:51:23 +0000  Daniel Bradshaw <nazca@atheme.org>
   revision [1428]
   - Tweak to check we found a file extension before using it to prevent segfault
--- a/src/madplug/decoder.c	Mon Feb 19 00:02:50 2007 -0800
+++ b/src/madplug/decoder.c	Mon Feb 19 04:55:14 2007 -0800
@@ -177,6 +177,7 @@
     unsigned char buffer[BUFFER_SIZE];
     struct mad_frame frame;     /* to read xing data */
     gboolean has_xing = FALSE;
+    int bitrate_frames = 0;
 
     mad_stream_init(&stream);
     mad_header_init(&header);
@@ -290,8 +291,10 @@
                 /* perhaps we have a VRB file */
                 if (info->bitrate != header.bitrate)
                     info->vbr = TRUE;
-                if (info->vbr)
+                if (info->vbr) {
                     info->bitrate += header.bitrate;
+                    bitrate_frames++;
+                }
                 /* check for changin layer/samplerate/channels */
                 if (info->mpeg_layer != header.layer)
                     g_warning("layer varies!!");
@@ -326,7 +329,7 @@
     }
 
     if (info->vbr && !has_xing)
-        info->bitrate = info->bitrate / info->frames;
+        info->bitrate = info->bitrate / bitrate_frames;
 
     mad_frame_finish(&frame);
     mad_header_finish(&header);
@@ -347,6 +350,7 @@
     gboolean seek_skip = FALSE;
     int remainder = 0;
     gint tlen;
+    unsigned int iteration = 0;
 
     /* mad structs */
     struct mad_stream stream;
@@ -503,6 +507,15 @@
                 continue;
             }
 
+            info->bitrate = frame.header.bitrate;
+
+            if (info->vbr && (iteration % 40 == 0)) {
+                mad_plugin->set_info(info->title,
+                                     tlen == 0 ? -1 : tlen,
+                                     info->bitrate, info->freq, info->channels);
+            }
+            iteration++;
+
             if (mad_frame_decode(&frame, &stream) == -1) {
                 if (!MAD_RECOVERABLE(stream.error))
                     break;