/* Default property value. */
#define FORCED_DEFAULT TRUE
+#define DEFAULT_MESSAGE FALSE
enum
{
PROP_0,
PROP_NUM_TRACKS,
PROP_FORCED,
- PROP_REFERENCE_LEVEL
+ PROP_REFERENCE_LEVEL,
+ PROP_MESSAGE
};
/* The ReplayGain algorithm is intended for use with mono and stereo
"Reference level [dB]", 0.0, 150., RG_REFERENCE_LEVEL,
G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MESSAGE,
+ g_param_spec_boolean ("message", "Message",
+ "Post statics messages",
+ DEFAULT_MESSAGE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
trans_class = (GstBaseTransformClass *) klass;
trans_class->start = GST_DEBUG_FUNCPTR (gst_rg_analysis_start);
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_rg_analysis_set_caps);
filter->num_tracks = 0;
filter->forced = FORCED_DEFAULT;
+ filter->message = DEFAULT_MESSAGE;
filter->reference_level = RG_REFERENCE_LEVEL;
filter->ctx = NULL;
{
GstRgAnalysis *filter = GST_RG_ANALYSIS (object);
+ GST_OBJECT_LOCK (filter);
switch (prop_id) {
case PROP_NUM_TRACKS:
filter->num_tracks = g_value_get_int (value);
case PROP_REFERENCE_LEVEL:
filter->reference_level = g_value_get_double (value);
break;
+ case PROP_MESSAGE:
+ filter->message = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
+ GST_OBJECT_UNLOCK (filter);
}
static void
{
GstRgAnalysis *filter = GST_RG_ANALYSIS (object);
+ GST_OBJECT_LOCK (filter);
switch (prop_id) {
case PROP_NUM_TRACKS:
g_value_set_int (value, filter->num_tracks);
case PROP_REFERENCE_LEVEL:
g_value_set_double (value, filter->reference_level);
break;
+ case PROP_MESSAGE:
+ g_value_set_boolean (value, filter->message);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
+ GST_OBJECT_UNLOCK (filter);
}
+static void
+gst_rg_analysis_post_message (gpointer rganalysis, GstClockTime timestamp,
+ GstClockTime duration, gdouble rglevel)
+{
+ GstRgAnalysis *filter = GST_RG_ANALYSIS (rganalysis);
+ if (filter->message) {
+ GstMessage *m;
+
+ m = gst_message_new_element (GST_OBJECT_CAST (rganalysis),
+ gst_structure_new ("rganalysis",
+ "timestamp", G_TYPE_UINT64, timestamp,
+ "duration", G_TYPE_UINT64, duration,
+ "rglevel", G_TYPE_DOUBLE, rglevel, NULL));
+
+ gst_element_post_message (GST_ELEMENT_CAST (rganalysis), m);
+ }
+}
+
+
static gboolean
gst_rg_analysis_start (GstBaseTransform * base)
{
filter->has_album_peak = FALSE;
filter->ctx = rg_analysis_new ();
+ GST_OBJECT_LOCK (filter);
+ rg_analysis_init_silence_detection (filter->ctx, gst_rg_analysis_post_message,
+ filter);
+ GST_OBJECT_UNLOCK (filter);
filter->analyze = NULL;
GST_LOG_OBJECT (filter, "started");
if (filter->skip)
return GST_FLOW_OK;
- /* Buffers made up of silence have no influence on the analysis: */
- if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP))
- return GST_FLOW_OK;
-
GST_LOG_OBJECT (filter, "processing buffer of size %u",
GST_BUFFER_SIZE (buf));
+ rg_analysis_start_buffer (filter->ctx, GST_BUFFER_TIMESTAMP (buf));
filter->analyze (filter->ctx, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf),
filter->depth);
RgAnalysisAcc track;
RgAnalysisAcc album;
+ void (*post_message) (gpointer analysis,
+ GstClockTime timestamp, GstClockTime duration, gdouble rglevel);
+ gpointer analysis;
+ /* The timestamp of the current incoming buffer. */
+ GstClockTime buffer_timestamp;
+ /* Number of samples processed in current buffer, during emit_signal,
+ this will always be on an RMS window boundary. */
+ guint buffer_n_samples_done;
};
/* Filter coefficients for the IIR filters that form the equal
return ctx;
}
+static void
+reset_silence_detection (RgAnalysisCtx * ctx)
+{
+ ctx->buffer_timestamp = GST_CLOCK_TIME_NONE;
+ ctx->buffer_n_samples_done = 0;
+}
+
/* Adapt to given sample rate. Does nothing if already the current
* rate (returns TRUE then). Returns FALSE only if given sample rate
* is not supported. If the configured rate changes, the last
/ 1000);
reset_filters (ctx);
+ reset_silence_detection (ctx);
return TRUE;
}
+void
+rg_analysis_init_silence_detection (RgAnalysisCtx * ctx,
+ void (*post_message) (gpointer analysis, GstClockTime timestamp,
+ GstClockTime duration, gdouble rglevel), gpointer analysis)
+{
+ ctx->post_message = post_message;
+ ctx->analysis = analysis;
+ reset_silence_detection (ctx);
+}
+
+void
+rg_analysis_start_buffer (RgAnalysisCtx * ctx, GstClockTime buffer_timestamp)
+{
+ ctx->buffer_timestamp = buffer_timestamp;
+ ctx->buffer_n_samples_done = 0;
+}
+
void
rg_analysis_destroy (RgAnalysisCtx * ctx)
{
* ctx->out_r[ctx->window_n_samples_done + i];
ctx->window_n_samples_done += n_samples_current;
+ ctx->buffer_n_samples_done += n_samples_current;
g_return_if_fail (ctx->window_n_samples_done <= ctx->window_n_samples);
ctx->window_n_samples * 0.5 + 1.e-37);
gint ival = CLAMP ((gint) val, 0,
(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);
+
+ ctx->post_message (ctx->analysis, timestamp,
+ RMS_WINDOW_MSECS * GST_MSECOND, -gain);
+
ctx->track.histogram[ival]++;
ctx->window_square_sum = 0.;
accumulator_clear (&ctx->track);
reset_filters (ctx);
+ reset_silence_detection (ctx);
return result;
}
reset_filters (ctx);
accumulator_clear (&ctx->track);
accumulator_clear (&ctx->album);
+ reset_silence_detection (ctx);
}