[vlc-devel] [RFC PATCH 1/7] aout: add "audio-meter" filter type

Thomas Guillem thomas at gllm.fr
Fri Aug 14 15:18:01 CEST 2020


---
 include/vlc_aout.h         | 14 ++++++++++++++
 src/audio_output/filters.c |  5 +++++
 src/audio_output/output.c  | 17 +++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 49527f30fb5..bab4d106883 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -112,6 +112,20 @@
 /* FIXME to remove once aout.h is cleaned a bit more */
 #include <vlc_block.h>
 
+struct vlc_audio_loudness_meter
+{
+    /** Momentary loudness, in LUFS */
+    double loudness_momentary;
+    /** Short term loudness, in LUFS (VLC_PLAYER_AOUT_LOUDNESS_METER_FULL) */
+    double loudness_shortterm;
+    /** Integrated loudness, in LUFS (VLC_PLAYER_AOUT_LOUDNESS_METER_FULL) */
+    double loudness_integrated;
+    /** Loudness range, in LU (VLC_PLAYER_AOUT_LOUDNESS_METER_FULL) */
+    double loudness_range;
+    /** True Peak, in dBTP (VLC_PLAYER_AOUT_LOUDNESS_METER_FULL) */
+    double truepeak;
+};
+
 struct vlc_audio_output_events {
     void (*timing_report)(audio_output_t *, vlc_tick_t system_now, vlc_tick_t pts);
     void (*volume_report)(audio_output_t *, float);
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index a297f4c6974..d91d8ae3fca 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -619,6 +619,11 @@ aout_filters_t *aout_FiltersNewWithClock(vlc_object_t *obj, const vlc_clock_t *c
                      &input_format, &output_format, NULL);
     free(visual);
 
+    char *meter = var_InheritString(obj, "audio-meter");
+    if (meter != NULL && strcasecmp(meter, "none"))
+        AppendFilter(obj, "audio meter", meter, filters, &input_format,
+                     &output_format, NULL);
+
     /* convert to the output format (minus resampling) if necessary */
     output_format.i_rate = input_format.i_rate;
     if (aout_FiltersPipelineCreate (obj, filters->tab, &filters->count,
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 260e27700ef..748ddec443f 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -177,6 +177,18 @@ static int FilterCallback (vlc_object_t *obj, const char *var,
     return VLC_SUCCESS;
 }
 
+static int MeterCallback (vlc_object_t *obj, const char *var,
+                          vlc_value_t prev, vlc_value_t cur, void *data)
+{
+    /* Don't request a restart when the meter is removed to avoid an audio
+     * glitch */
+    if (cur.psz_string != NULL)
+        aout_InputRequestRestart ((audio_output_t *)obj);
+
+    (void) var; (void) prev; (void) data;
+    return VLC_SUCCESS;
+}
+
 static int StereoModeCallback (vlc_object_t *obj, const char *varname,
                                vlc_value_t oldval, vlc_value_t newval, void *data)
 {
@@ -232,6 +244,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
     var_AddCallback (aout, "mute", var_Copy, parent);
     var_Create (aout, "device", VLC_VAR_STRING);
     var_AddCallback (aout, "device", var_CopyDevice, parent);
+    var_Create (aout, "loudness-meter", VLC_VAR_ADDRESS);
 
     aout->events = &aout_events;
 
@@ -311,6 +324,9 @@ audio_output_t *aout_New (vlc_object_t *parent)
     var_Change(aout, "audio-visual", VLC_VAR_SETTEXT,
                _("Audio visualizations"));
 
+    var_Create (aout, "audio-meter", VLC_VAR_STRING);
+    var_AddCallback (aout, "audio-meter", MeterCallback, NULL);
+
     /* Replay gain */
     var_Create (aout, "audio-replay-gain-mode",
                 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
@@ -367,6 +383,7 @@ void aout_Destroy (audio_output_t *aout)
 
     var_DelCallback (aout, "viewpoint", ViewpointCallback, NULL);
     var_DelCallback (aout, "audio-filter", FilterCallback, NULL);
+    var_DelCallback (aout, "audio-meter", MeterCallback, NULL);
     var_DelCallback(aout, "device", var_CopyDevice, vlc_object_parent(aout));
     var_DelCallback(aout, "mute", var_Copy, vlc_object_parent(aout));
     var_SetFloat (aout, "volume", -1.f);
-- 
2.28.0



More information about the vlc-devel mailing list