History

avfilter/af_drmeter: refactor number of bins out

Paul B Mahol committed 4 years ago

Commit 2f472d51 parent 9b15f431 file · +13 −11Browse files

Unified · Split

libavfilter/af_drmeter.c+13−11
@@ -26,13 +26,15 @@ · 25 unmodified lines
2626 #include "avfilter.h"
2727 #include "internal.h"
2828
29+#define BINS 10000
30+
2931 typedef struct ChannelStats {
3032 uint64_t nb_samples;
3133 uint64_t blknum;
3234 float peak;
3335 float sum;
34− uint32_t peaks[10001];
35− uint32_t rms[10001];
36+ uint32_t peaks[BINS+1];
37+ uint32_t rms[BINS+1];
3638 } ChannelStats;
3739
3840 typedef struct DRMeterContext {
@@ -73,8 +75,8 @@ static void finish_block(ChannelStats *p) · 34 unmodified lines
7375
7476 rms = sqrt(2 * p->sum / p->nb_samples);
7577 peak = p->peak;
76− rms_bin = av_clip(rms * 10000, 0, 10000);
77− peak_bin = av_clip(peak * 10000, 0, 10000);
78+ rms_bin = av_clip(rms * BINS, 0, BINS);
79+ peak_bin = av_clip(peak * BINS, 0, BINS);
7880 p->rms[rms_bin]++;
7981 p->peaks[peak_bin]++;
8082
@@ -144,29 +146,29 @@ static void print_stats(AVFilterContext *ctx) · 63 unmodified lines
144146
145147 finish_block(p);
146148
147− for (i = 0; i <= 10000; i++) {
148− if (p->peaks[10000 - i]) {
149+ for (i = 0; i <= BINS; i++) {
150+ if (p->peaks[BINS - i]) {
149151 if (first)
150152 break;
151153 first = 1;
152154 }
153155 }
154156
155− secondpeak = (10000 - i) / 10000.;
157+ secondpeak = (BINS - i) / (double)BINS;
156158
157− for (i = 10000, j = 0; i >= 0 && j < 0.2 * p->blknum; i--) {
159+ for (i = BINS, j = 0; i >= 0 && j < 0.2 * p->blknum; i--) {
158160 if (p->rms[i]) {
159− rmssum += SQR(i / 10000.) * p->rms[i];
161+ rmssum += SQR(i / (double)BINS) * p->rms[i];
160162 j += p->rms[i];
161163 }
162164 }
163165
164166 chdr = 20 * log10(secondpeak / sqrt(rmssum / (0.2 * p->blknum)));
165167 dr += chdr;
166− av_log(ctx, AV_LOG_INFO, "Channel %d: DR: %.1f\n", ch + 1, chdr);
168+ av_log(ctx, AV_LOG_INFO, "Channel %d: DR: %g\n", ch + 1, chdr);
167169 }
168170
169− av_log(ctx, AV_LOG_INFO, "Overall DR: %.1f\n", dr / s->nb_channels);
171+ av_log(ctx, AV_LOG_INFO, "Overall DR: %g\n", dr / s->nb_channels);
170172 }
171173
172174 static av_cold void uninit(AVFilterContext *ctx)

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