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
26#include "avfilter.h"26#include "avfilter.h"
27#include "internal.h"27#include "internal.h"
28 28
29#define BINS 10000
30
29typedef struct ChannelStats {31typedef struct ChannelStats {
30 uint64_t nb_samples;32 uint64_t nb_samples;
31 uint64_t blknum;33 uint64_t blknum;
32 float peak;34 float peak;
33 float sum;35 float sum;
34 uint32_t peaks[10001];36 uint32_t peaks[BINS+1];
35 uint32_t rms[10001];37 uint32_t rms[BINS+1];
36} ChannelStats;38} ChannelStats;
37 39
38typedef struct DRMeterContext {40typedef struct DRMeterContext {
@@ -73,8 +75,8 @@ static void finish_block(ChannelStats *p) · 34 unmodified lines
73 75
74 rms = sqrt(2 * p->sum / p->nb_samples);76 rms = sqrt(2 * p->sum / p->nb_samples);
75 peak = p->peak;77 peak = p->peak;
76 rms_bin = av_clip(rms * 10000, 0, 10000);78 rms_bin = av_clip(rms * BINS, 0, BINS);
77 peak_bin = av_clip(peak * 10000, 0, 10000);79 peak_bin = av_clip(peak * BINS, 0, BINS);
78 p->rms[rms_bin]++;80 p->rms[rms_bin]++;
79 p->peaks[peak_bin]++;81 p->peaks[peak_bin]++;
80 82
@@ -144,29 +146,29 @@ static void print_stats(AVFilterContext *ctx) · 63 unmodified lines
144 146
145 finish_block(p);147 finish_block(p);
146 148
147 for (i = 0; i <= 10000; i++) {149 for (i = 0; i <= BINS; i++) {
148 if (p->peaks[10000 - i]) {150 if (p->peaks[BINS - i]) {
149 if (first)151 if (first)
150 break;152 break;
151 first = 1;153 first = 1;
152 }154 }
153 }155 }
154 156
155 secondpeak = (10000 - i) / 10000.;157 secondpeak = (BINS - i) / (double)BINS;
156 158
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--) {
158 if (p->rms[i]) {160 if (p->rms[i]) {
159 rmssum += SQR(i / 10000.) * p->rms[i];161 rmssum += SQR(i / (double)BINS) * p->rms[i];
160 j += p->rms[i];162 j += p->rms[i];
161 }163 }
162 }164 }
163 165
164 chdr = 20 * log10(secondpeak / sqrt(rmssum / (0.2 * p->blknum)));166 chdr = 20 * log10(secondpeak / sqrt(rmssum / (0.2 * p->blknum)));
165 dr += chdr;167 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);
167 }169 }
168 170
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);
170}172}
171 173
172static av_cold void uninit(AVFilterContext *ctx)174static 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