summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2017-05-12 18:13:17 +0200
committerPaul B Mahol <onemda@gmail.com>2017-05-12 18:14:45 +0200
commite312ed0504c1ba45e1e1f8e3071100b602a939c1 (patch)
treef83726ab2aa84efa21b83555d73bc538f4722de2 /libavfilter
parent9cd62b2ca49be372b95e54202c0dac0de4f8a464 (diff)
downloadffmpeg-e312ed0504c1ba45e1e1f8e3071100b602a939c1.tar.gz
avfilter/af_astats: add RMS difference too
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/af_astats.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index 8813b52109..51fc2cc0ae 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -36,6 +36,7 @@ typedef struct ChannelStats {
double min_runs, max_runs;
double min_diff, max_diff;
double diff1_sum;
+ double diff1_sum_x2;
uint64_t mask, imask;
uint64_t min_count, max_count;
uint64_t nb_samples;
@@ -121,6 +122,7 @@ static void reset_stats(AudioStatsContext *s)
p->min_runs = 0;
p->max_runs = 0;
p->diff1_sum = 0;
+ p->diff1_sum_x2 = 0;
p->mask = 0;
p->imask = 0xFFFFFFFFFFFFFFFF;
p->min_count = 0;
@@ -197,6 +199,7 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
p->diff1_sum += fabs(d - p->last);
+ p->diff1_sum_x2 += (d - p->last) * (d - p->last);
p->last = d;
p->mask |= i;
p->imask &= i;
@@ -232,6 +235,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
nmin = DBL_MAX, nmax = DBL_MIN,
max_sigma_x = 0,
diff1_sum = 0,
+ diff1_sum_x2 = 0,
sigma_x = 0,
sigma_x2 = 0,
min_sigma_x2 = DBL_MAX,
@@ -251,7 +255,8 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
nmax = FFMAX(nmax, p->nmax);
min_diff = FFMIN(min_diff, p->min_diff);
max_diff = FFMAX(max_diff, p->max_diff);
- diff1_sum += p->diff1_sum,
+ diff1_sum += p->diff1_sum;
+ diff1_sum_x2 += p->diff1_sum_x2;
min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
sigma_x += p->sigma_x;
@@ -272,6 +277,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta(metadata, c + 1, "Min_difference", "%f", p->min_diff);
set_meta(metadata, c + 1, "Max_difference", "%f", p->max_diff);
set_meta(metadata, c + 1, "Mean_difference", "%f", p->diff1_sum / (p->nb_samples - 1));
+ set_meta(metadata, c + 1, "RMS_difference", "%f", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
set_meta(metadata, c + 1, "Peak_level", "%f", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
set_meta(metadata, c + 1, "RMS_level", "%f", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
set_meta(metadata, c + 1, "RMS_peak", "%f", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
@@ -290,6 +296,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta(metadata, 0, "Overall.Min_difference", "%f", min_diff);
set_meta(metadata, 0, "Overall.Max_difference", "%f", max_diff);
set_meta(metadata, 0, "Overall.Mean_difference", "%f", diff1_sum / (nb_samples - s->nb_channels));
+ set_meta(metadata, 0, "Overall.RMS_difference", "%f", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
set_meta(metadata, 0, "Overall.Peak_level", "%f", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
set_meta(metadata, 0, "Overall.RMS_level", "%f", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
set_meta(metadata, 0, "Overall.RMS_peak", "%f", LINEAR_TO_DB(sqrt(max_sigma_x2)));
@@ -419,6 +426,7 @@ static void print_stats(AVFilterContext *ctx)
min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0,
nmin = DBL_MAX, nmax = DBL_MIN,
max_sigma_x = 0,
+ diff1_sum_x2 = 0,
diff1_sum = 0,
sigma_x = 0,
sigma_x2 = 0,
@@ -439,7 +447,8 @@ static void print_stats(AVFilterContext *ctx)
nmax = FFMAX(nmax, p->nmax);
min_diff = FFMIN(min_diff, p->min_diff);
max_diff = FFMAX(max_diff, p->max_diff);
- diff1_sum += p->diff1_sum,
+ diff1_sum_x2 += p->diff1_sum_x2;
+ diff1_sum += p->diff1_sum;
min_sigma_x2 = FFMIN(min_sigma_x2, p->min_sigma_x2);
max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
sigma_x += p->sigma_x;
@@ -461,6 +470,7 @@ static void print_stats(AVFilterContext *ctx)
av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", p->min_diff);
av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", p->max_diff);
av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", p->diff1_sum / (p->nb_samples - 1));
+ av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(p->diff1_sum_x2 / (p->nb_samples - 1)));
av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-p->nmin, p->nmax)));
av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(p->sigma_x2 / p->nb_samples)));
av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(p->max_sigma_x2)));
@@ -480,6 +490,7 @@ static void print_stats(AVFilterContext *ctx)
av_log(ctx, AV_LOG_INFO, "Min difference: %f\n", min_diff);
av_log(ctx, AV_LOG_INFO, "Max difference: %f\n", max_diff);
av_log(ctx, AV_LOG_INFO, "Mean difference: %f\n", diff1_sum / (nb_samples - s->nb_channels));
+ av_log(ctx, AV_LOG_INFO, "RMS difference: %f\n", sqrt(diff1_sum_x2 / (nb_samples - s->nb_channels)));
av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-nmin, nmax)));
av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));