GNOME Bugzilla – Bug 604352
[rganalysis] miscomputes timestamps
Last modified: 2009-12-17 16:38:14 UTC
When calculating the data for the audio gain messages, rganalysis does not properly round up the timestamp. The result is that for messages generated at the beginning of a stream, the calculated timestamp can be negative. The following fix works for me: --- gst/replaygain/rganalysis.c (original) +++ gst/replaygain/rganalysis.c (fixed) @@ -711,7 +711,8 @@ /* Compute the per-window gain */ const gdouble gain = PINK_REF - (gdouble) ival / STEPS_PER_DB; const GstClockTime timestamp = (ctx->buffer_timestamp - + ctx->buffer_n_samples_done * GST_SECOND / ctx->sample_rate + + (ctx->buffer_n_samples_done * GST_SECOND + ctx->sample_rate - 1) + / ctx->sample_rate - RMS_WINDOW_MSECS * GST_MSECOND);
You should use gst_util_uint64_scale_ceil() or _scale_round() here instead. That will prevent overflows and also make the line a bit more readable :)
Interesting. I'll update the patch.
Here's the updated patch: --- gstreamer/good/gst/replaygain/rganalysis.c (original) +++ gstreamer/good/gst/replaygain/rganalysis.c (fixed) @@ -710,9 +710,11 @@ (gint) G_N_ELEMENTS (ctx->track.histogram) - 1); /* Compute the per-window gain */ const gdouble gain = PINK_REF - (gdouble) ival / STEPS_PER_DB; - const GstClockTime timestamp = (ctx->buffer_timestamp - + ctx->buffer_n_samples_done * GST_SECOND / ctx->sample_rate - - RMS_WINDOW_MSECS * GST_MSECOND); + const GstClockTime timestamp = ctx->buffer_timestamp + + gst_util_uint64_scale_int_ceil(GST_SECOND, + ctx->buffer_n_samples_done, + ctx->sample_rate) + - RMS_WINDOW_MSECS * GST_MSECOND; ctx->post_message (ctx->analysis, timestamp, RMS_WINDOW_MSECS * GST_MSECOND, -gain);
commit 7b107f64f33108658f2883d74de3303c07f3a154 Author: Branko Čibej <brane at xbc.nu> Date: Thu Dec 17 17:37:03 2009 +0100 rganalysis: fix timestamp rounding Use scaling function to round and avoid overflows. Fixes #604352