diff src/madplug/decoder.c @ 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 8829833d37bc
children fadf4c18a1cf
line wrap: on
line diff
--- 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;