diff mbox series

[FFmpeg-devel,v3,3/5] avfilter/af_volumedetect.c: Added functions for int/float and planar/packed

Message ID 20240702013354.14942-4-yigithanyigitdevel@gmail.com
State New
Headers show
Series avfilter/af_volumedetect.c: Add 32bit float audio | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Yigithan Yigit July 2, 2024, 1:33 a.m. UTC
---
 libavfilter/af_volumedetect.c | 66 +++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

Comments

Anton Khirnov July 2, 2024, 7:50 a.m. UTC | #1
Why did you ignore my comment from the last iteration?
diff mbox series

Patch

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index edd2d56f7a..778f0cac6c 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -71,6 +71,64 @@  static void update_float_stats(VolDetectContext *vd, float *audio_data)
     vd->nb_samples++;
 }
 
+static void process_float_planar_samples(VolDetectContext *vd, AVFrame *samples)
+{
+    int plane, i;
+    int nb_channels = samples->ch_layout.nb_channels;
+    int nb_samples  = samples->nb_samples;
+    float *audio_data;
+    for (plane = 0; plane < nb_channels; plane++) {
+        audio_data = (float *)samples->extended_data[plane];
+        for (i = 0; i < nb_samples; i++) {
+            update_float_stats(vd, &audio_data[i]);
+        }
+    }
+}
+
+static void process_float_packed_samples(VolDetectContext *vd, AVFrame *samples)
+{
+    int i, j;
+    int nb_channels = samples->ch_layout.nb_channels;
+    int nb_samples  = samples->nb_samples;
+    float *audio_data;
+    for (i = 0; i < nb_samples; i++) {
+        audio_data = (float *)samples->extended_data[0];
+        for (j = 0; j < nb_channels; j++) {
+           update_float_stats(vd, &audio_data[i * nb_channels + j]);
+        }
+    }
+}
+
+static void process_int_planar_samples(VolDetectContext *vd, AVFrame *samples)
+{
+    int plane, i;
+    int nb_channels = samples->ch_layout.nb_channels;
+    int nb_samples  = samples->nb_samples;
+    int16_t *pcm;
+    for (plane = 0; plane < nb_channels; plane++) {
+        pcm = (int16_t *)samples->extended_data[plane];
+        for (i = 0; i < nb_samples; i++) {
+            vd->histogram[pcm[i] + 0x8000]++;
+            vd->nb_samples++;
+        }
+    }
+}
+
+static void process_int_packed_samples(VolDetectContext *vd, AVFrame *samples)
+{
+    int i, j;
+    int nb_channels = samples->ch_layout.nb_channels;
+    int nb_samples  = samples->nb_samples;
+    int16_t *pcm;
+    for (i = 0; i < nb_samples; i++) {
+        pcm = (int16_t *)samples->extended_data[0];
+        for (j = 0; j < nb_channels; j++) {
+            vd->histogram[pcm[i * nb_channels + j] + 0x8000]++;
+            vd->nb_samples++;
+        }
+    }
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -157,12 +215,20 @@  static int config_output(AVFilterLink *outlink)
         * The extra element is there for symmetry.
         */
         histogram_size = HISTOGRAM_SIZE + 1;
+        if (av_sample_fmt_is_planar(outlink->format))
+             vd->process_samples = process_int_planar_samples;
+         else
+             vd->process_samples = process_int_packed_samples;
     } else {
         /*
         * The histogram is used to store the number of samples at each dB
         * instead of the number of samples at each PCM value.
         */
         histogram_size = HISTOGRAM_SIZE_FLT + 1;
+        if (av_sample_fmt_is_planar(outlink->format))
+             vd->process_samples = process_float_planar_samples;
+         else
+             vd->process_samples = process_float_packed_samples;
     }
     vd->histogram = av_calloc(histogram_size, sizeof(uint64_t));
     if (!vd->histogram)