History

avfilter/af_astats: extend and improve bit depth output

Paul B Mahol committed 3 years ago

Commit fb05bc81 parent 9e768c81 file · +64 −31Browse files

Unified · Split

libavfilter/af_astats.c+64−31
@@ -76,7 +76,7 @@ typedef struct ChannelStats { · 75 unmodified lines
7676 double diff1_sum;
7777 double diff1_sum_x2;
7878 double abs_peak;
79− uint64_t mask, imask;
79+ uint64_t mask[4];
8080 uint64_t min_count, max_count;
8181 uint64_t abs_peak_count;
8282 uint64_t noise_floor_count;
@@ -88,6 +88,7 @@ typedef struct ChannelStats { · 5 unmodified lines
8888 double *win_samples;
8989 double *sorted_samples;
9090 uint64_t ehistogram[HISTOGRAM_SIZE];
91+ int64_t lasti;
9192 int sorted_front;
9293 int sorted_back;
9394 int win_pos;
@@ -178,8 +179,10 @@ static void reset_stats(AudioStatsContext *s) · 84 unmodified lines
178179 p->max_runs = 0;
179180 p->diff1_sum = 0;
180181 p->diff1_sum_x2 = 0;
181− p->mask = 0;
182− p->imask = 0xFFFFFFFFFFFFFFFF;
182+ p->mask[0] = 0;
183+ p->mask[1] = 0;
184+ p->mask[2] =~0;
185+ p->mask[3] = 0;
183186 p->min_count = 0;
184187 p->max_count = 0;
185188 p->abs_peak_count = 0;
@@ -239,20 +242,28 @@ static int config_output(AVFilterLink *outlink) · 53 unmodified lines
239242 return 0;
240243 }
241244
242−static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
245+static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
243246 {
244247 unsigned result = s->maxbitdepth;
248+ uint64_t amask = mask[1] & (~mask[2]);
245249
246− mask = mask & (~imask);
250+ depth[0] = 0;
251+ for (int i = 0; i < result; i++)
252+ depth[0] += !!(mask[0] & (1ULL << i));
247253
248− for (; result && !(mask & 1); --result, mask >>= 1);
254+ depth[1] = 0;
255+ for (int i = 0; i < result; i++)
256+ depth[1] += !!(mask[1] & (1ULL << i));
249257
250− depth->den = result;
251− depth->num = 0;
258+ depth[2] = result;
259+ for (int i = 0; i < result && !(amask & 1); i++) {
260+ depth[2]--;
261+ amask >>= 1;
262+ }
252263
253− for (; result; --result, mask >>= 1)
254− if (mask & 1)
255− depth->num++;
264+ depth[3] = 0;
265+ for (int i = 0; i < result; i++)
266+ depth[3] += !!(mask[3] & (1ULL << i));
256267 }
257268
258269 static double calc_entropy(AudioStatsContext *s, ChannelStats *p)
@@ -389,9 +400,13 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, · 130 unmodified lines
389400 p->diff1_sum += fabs(d - p->last);
390401 p->diff1_sum_x2 += (d - p->last) * (d - p->last);
391402 }
403+ p->mask[0] |= (i < 0) ? -i : i;
404+ p->mask[1] |= i;
405+ p->mask[2] &= i;
406+ if (!isnan(p->last))
407+ p->mask[3] |= i ^ p->lasti;
408+ p->lasti = i;
392409 p->last = d;
393− p->mask |= i;
394− p->imask &= i;
395410
396411 drop = p->win_samples[p->win_pos];
397412 p->win_samples[p->win_pos] = nd;
@@ -462,7 +477,7 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key, · 64 unmodified lines
462477
463478 static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
464479 {
465− uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
480+ uint64_t mask[4], min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
466481 uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
467482 uint64_t abs_peak_count = 0;
468483 double min_runs = 0, max_runs = 0,
@@ -476,9 +491,14 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 7 unmodified lines
476491 entropy = 0,
477492 min_sigma_x2 = DBL_MAX,
478493 max_sigma_x2 =-DBL_MAX;
479− AVRational depth;
494+ uint8_t depth[4];
480495 int c;
481496
497+ mask[0] = 0;
498+ mask[1] = 0;
499+ mask[2] =~0;
500+ mask[3] = 0;
501+
482502 for (c = 0; c < s->nb_channels; c++) {
483503 ChannelStats *p = &s->chstats[c];
484504
@@ -505,8 +525,10 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 20 unmodified lines
505525 abs_peak_count += p->abs_peak_count;
506526 min_runs += p->min_runs;
507527 max_runs += p->max_runs;
508− mask |= p->mask;
509− imask &= p->imask;
528+ mask[0] |= p->mask[0];
529+ mask[1] |= p->mask[1];
530+ mask[2] &= p->mask[2];
531+ mask[3] |= p->mask[3];
510532 nb_samples += p->nb_samples;
511533 nb_nans += p->nb_nans;
512534 nb_infs += p->nb_infs;
@@ -551,9 +573,11 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 38 unmodified lines
551573 if (s->measure_perchannel & MEASURE_ENTROPY)
552574 set_meta(metadata, c + 1, "Entropy", "%f", p->entropy);
553575 if (s->measure_perchannel & MEASURE_BIT_DEPTH) {
554− bit_depth(s, p->mask, p->imask, &depth);
555− set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num);
556− set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den);
576+ bit_depth(s, p->mask, depth);
577+ set_meta(metadata, c + 1, "Bit_depth", "%f", depth[0]);
578+ set_meta(metadata, c + 1, "Bit_depth2", "%f", depth[1]);
579+ set_meta(metadata, c + 1, "Bit_depth3", "%f", depth[2]);
580+ set_meta(metadata, c + 1, "Bit_depth4", "%f", depth[3]);
557581 }
558582 if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE)
559583 set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero));
@@ -604,9 +628,11 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 44 unmodified lines
604628 if (s->measure_overall & MEASURE_ENTROPY)
605629 set_meta(metadata, 0, "Overall.Entropy", "%f", entropy / (double)s->nb_channels);
606630 if (s->measure_overall & MEASURE_BIT_DEPTH) {
607− bit_depth(s, mask, imask, &depth);
608− set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num);
609− set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den);
631+ bit_depth(s, mask, depth);
632+ set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth[0]);
633+ set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth[1]);
634+ set_meta(metadata, 0, "Overall.Bit_depth3", "%f", depth[2]);
635+ set_meta(metadata, 0, "Overall.Bit_depth4", "%f", depth[3]);
610636 }
611637 if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
612638 set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels);
@@ -724,7 +750,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) · 111 unmodified lines
724750 static void print_stats(AVFilterContext *ctx)
725751 {
726752 AudioStatsContext *s = ctx->priv;
727− uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
753+ uint64_t mask[4], min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
728754 uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0, abs_peak_count = 0;
729755 double min_runs = 0, max_runs = 0,
730756 min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
@@ -737,9 +763,14 @@ static void print_stats(AVFilterContext *ctx) · 6 unmodified lines
737763 entropy = 0,
738764 min_sigma_x2 = DBL_MAX,
739765 max_sigma_x2 =-DBL_MAX;
740− AVRational depth;
766+ uint8_t depth[4];
741767 int c;
742768
769+ mask[0] = 0;
770+ mask[1] = 0;
771+ mask[2] =~0;
772+ mask[3] = 0;
773+
743774 for (c = 0; c < s->nb_channels; c++) {
744775 ChannelStats *p = &s->chstats[c];
745776
@@ -769,8 +800,10 @@ static void print_stats(AVFilterContext *ctx) · 23 unmodified lines
769800 noise_floor_count += p->noise_floor_count;
770801 min_runs += p->min_runs;
771802 max_runs += p->max_runs;
772− mask |= p->mask;
773− imask &= p->imask;
803+ mask[0] |= p->mask[0];
804+ mask[1] |= p->mask[1];
805+ mask[2] &= p->mask[2];
806+ mask[3] |= p->mask[3];
774807 nb_samples += p->nb_samples;
775808 nb_nans += p->nb_nans;
776809 nb_infs += p->nb_infs;
@@ -818,8 +851,8 @@ static void print_stats(AVFilterContext *ctx) · 41 unmodified lines
818851 if (s->measure_perchannel & MEASURE_ENTROPY)
819852 av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", p->entropy);
820853 if (s->measure_perchannel & MEASURE_BIT_DEPTH) {
821− bit_depth(s, p->mask, p->imask, &depth);
822− av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
854+ bit_depth(s, p->mask, depth);
855+ av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u/%u/%u\n", depth[0], depth[1], depth[2], depth[3]);
823856 }
824857 if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE)
825858 av_log(ctx, AV_LOG_INFO, "Dynamic range: %f\n", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero));
@@ -876,8 +909,8 @@ static void print_stats(AVFilterContext *ctx) · 50 unmodified lines
876909 if (s->measure_overall & MEASURE_ENTROPY)
877910 av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", entropy / (double)s->nb_channels);
878911 if (s->measure_overall & MEASURE_BIT_DEPTH) {
879− bit_depth(s, mask, imask, &depth);
880− av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
912+ bit_depth(s, mask, depth);
913+ av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u/%u/%u\n", depth[0], depth[1], depth[2], depth[3]);
881914 }
882915 if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
883916 av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t