From: "Rémi Denis-Courmont" <remi@remlab.net> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 2/3] avfilter/af_volumedetect.c: Add 32bit float audio support Date: Tue, 18 Jun 2024 08:55:59 +0200 Message-ID: <64B43C84-3B8C-49D1-A3DA-005CDE234788@remlab.net> (raw) In-Reply-To: <CAPYw7P55RP1O+nB-Z38x5_HG4OkTAG+-gjy+bQJ2eE-oiKGp2g@mail.gmail.com> Le 17 juin 2024 19:52:10 GMT+02:00, Paul B Mahol <onemda@gmail.com> a écrit : >On Mon, Jun 17, 2024 at 4:52 PM Rémi Denis-Courmont <remi@remlab.net> wrote: > >> >> >> Le 17 juin 2024 13:18:11 GMT+02:00, Yigithan Yigit < >> yigithanyigitdevel@gmail.com> a écrit : >> >--- >> > libavfilter/af_volumedetect.c | 159 ++++++++++++++++++++++++++++------ >> > 1 file changed, 133 insertions(+), 26 deletions(-) >> > >> >diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c >> >index 327801a7f9..dbbcd037a5 100644 >> >--- a/libavfilter/af_volumedetect.c >> >+++ b/libavfilter/af_volumedetect.c >> >@@ -20,27 +20,51 @@ >> > >> > #include "libavutil/channel_layout.h" >> > #include "libavutil/avassert.h" >> >+#include "libavutil/mem.h" >> > #include "audio.h" >> > #include "avfilter.h" >> > #include "internal.h" >> > >> >+#define MAX_DB_FLT 1024 >> > #define MAX_DB 91 >> >+#define HISTOGRAM_SIZE 0x10000 >> >+#define HISTOGRAM_SIZE_FLT (MAX_DB_FLT*2) >> > >> > typedef struct VolDetectContext { >> >- /** >> >- * Number of samples at each PCM value. >> >- * histogram[0x8000 + i] is the number of samples at value i. >> >- * The extra element is there for symmetry. >> >- */ >> >- uint64_t histogram[0x10001]; >> >+ uint64_t* histogram; ///< for integer number of samples at each PCM >> value, for float number of samples at each dB >> >+ uint64_t nb_samples; ///< number of samples >> >+ double sum2; ///< sum of the squares of the samples >> >+ double max; ///< maximum sample value >> >+ int is_float; ///< true if the input is in floating point >> > } VolDetectContext; >> > >> >-static inline double logdb(uint64_t v) >> >+static inline double logdb(double v, enum AVSampleFormat sample_fmt) >> > { >> >- double d = v / (double)(0x8000 * 0x8000); >> >- if (!v) >> >- return MAX_DB; >> >- return -log10(d) * 10; >> >+ if (sample_fmt == AV_SAMPLE_FMT_FLT) { >> >+ if (!v) >> >+ return MAX_DB_FLT; >> >+ return -log10(v) * 10; >> >+ } else { >> >+ double d = v / (double)(0x8000 * 0x8000); >> >+ if (!v) >> >+ return MAX_DB; >> >+ return -log10(d) * 10; >> >+ } >> >+} >> >+ >> >+static void update_float_stats(VolDetectContext *vd, float *audio_data) >> >+{ >> >+ double sample; >> >+ int idx; >> >+ if(!isnormal(*audio_data)) >> >+ return; >> >> Do we really need to classify floats here? That's probably going to hurt >> perfs badly, and makes an otherwise very vectorisable function not so >> easily vectored. >> > >This is fast, it should translate to checking few bits of memory. Sure but the branch is what irks me here, not the classification per se. And I don't get why it's needed here, where most of the code base seems to assume that floats are always numeric. It's also not clear why subnormals are disallowed here. IMO all that needs justification in the commit message which I find lacking. Or if it's unjustified then it shouldn't be there. >> >+ sample = fabsf(*audio_data); >> >+ if (sample > vd->max) >> >+ vd->max = sample; >> >+ vd->sum2 += sample * sample; >> >+ idx = lrintf(floorf(logdb(sample * sample, AV_SAMPLE_FMT_FLT))) + >> MAX_DB_FLT; >> >> You're recomputing the same value again, and you seem to be rounding twice >> in a row? _______________________________________________ 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-06-18 6:56 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-06-17 11:18 [FFmpeg-devel] [PATCH 0/3] " Yigithan Yigit 2024-06-17 11:18 ` [FFmpeg-devel] [PATCH 1/3] avfilter/af_volumedetect.c: Move logdb function Yigithan Yigit 2024-06-17 11:18 ` [FFmpeg-devel] [PATCH 2/3] avfilter/af_volumedetect.c: Add 32bit float audio support Yigithan Yigit 2024-06-17 14:52 ` Rémi Denis-Courmont 2024-06-17 17:52 ` Paul B Mahol 2024-06-18 6:55 ` Rémi Denis-Courmont [this message] 2024-06-18 7:48 ` Paul B Mahol 2024-06-18 9:16 ` Yigithan Yigit 2024-06-17 11:18 ` [FFmpeg-devel] [PATCH 3/3] avfilter/af_volumedetect.c: reindent after last commit 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=64B43C84-3B8C-49D1-A3DA-005CDE234788@remlab.net \ --to=remi@remlab.net \ --cc=ffmpeg-devel@ffmpeg.org \ /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