From: Yigithan Yigit <yigithanyigitdevel@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: thilo.borgmann@mail.de, yigithanyigitdevel@gmail.com
Subject: [FFmpeg-devel] [PATCH v3 3/5] avfilter/af_volumedetect.c: Added functions for int/float and planar/packed
Date: Tue, 2 Jul 2024 04:33:52 +0300
Message-ID: <20240702013354.14942-4-yigithanyigitdevel@gmail.com> (raw)
In-Reply-To: <20240702013354.14942-1-yigithanyigitdevel@gmail.com>
---
libavfilter/af_volumedetect.c | 66 +++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
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)
--
2.45.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-07-02 1:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 1:33 [FFmpeg-devel] [PATCH v3 0/5] avfilter/af_volumedetect.c: Add 32bit float audio Yigithan Yigit
2024-07-02 1:33 ` [FFmpeg-devel] [PATCH v3 1/5] avfilter/af_volumedetect.c: Move logdb function Yigithan Yigit
2024-07-02 1:33 ` [FFmpeg-devel] [PATCH v3 2/5] avfilter/af_volumedetect.c: Add 32bit float audio support Yigithan Yigit
2024-07-02 5:46 ` Rémi Denis-Courmont
2024-07-02 5:49 ` Rémi Denis-Courmont
2024-07-02 5:51 ` Rémi Denis-Courmont
2024-07-02 11:46 ` Yigithan Yigit
2024-07-02 1:33 ` Yigithan Yigit [this message]
2024-07-02 7:50 ` [FFmpeg-devel] [PATCH v3 3/5] avfilter/af_volumedetect.c: Added functions for int/float and planar/packed Anton Khirnov
2024-07-02 1:33 ` [FFmpeg-devel] [PATCH v3 4/5] avfilter/af_volumedetect.c: reindent after last commit Yigithan Yigit
2024-07-02 1:33 ` [FFmpeg-devel] [PATCH v3 5/5] Replace division with ldexp Yigithan Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240702013354.14942-4-yigithanyigitdevel@gmail.com \
--to=yigithanyigitdevel@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=thilo.borgmann@mail.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git