History

avfilter/f_ebur128: add support for any number of channels

Paul B Mahol committed 4 years ago

Commit df98e8e1 parent 01440e21 file · +28 −10Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/f_ebur128.c+28−10
@@ -42,8 +42,6 @@ · 41 unmodified lines
4242 #include "formats.h"
4343 #include "internal.h"
4444
45−#define MAX_CHANNELS 63
46−
4745 #define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold
4846 #define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum)
4947 #define HIST_GRAIN 100 ///< defines histogram precision
@@ -63,10 +61,10 @@ struct hist_entry { · 13 unmodified lines
6361 };
6462
6563 struct integrator {
66− double *cache[MAX_CHANNELS]; ///< window of filtered samples (N ms)
64+ double **cache; ///< window of filtered samples (N ms)
6765 int cache_pos; ///< focus on the last added bin in the cache array
6866 int cache_size;
69− double sum[MAX_CHANNELS]; ///< sum of the last N ms filtered samples (cache content)
67+ double *sum; ///< sum of the last N ms filtered samples (cache content)
7068 int filled; ///< 1 if the cache is completely filled, 0 otherwise
7169 double rel_threshold; ///< relative threshold
7270 double sum_kept_powers; ///< sum of the powers (weighted sums) above absolute threshold
@@ -111,9 +109,9 @@ typedef struct EBUR128Context { · 38 unmodified lines
111109
112110 /* Filter caches.
113111 * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */
114− double x[MAX_CHANNELS * 3]; ///< 3 input samples cache for each channel
115− double y[MAX_CHANNELS * 3]; ///< 3 pre-filter samples cache for each channel
116− double z[MAX_CHANNELS * 3]; ///< 3 RLB-filter samples cache for each channel
112+ double *x; ///< 3 input samples cache for each channel
113+ double *y; ///< 3 pre-filter samples cache for each channel
114+ double *z; ///< 3 RLB-filter samples cache for each channel
117115 double pre_b[3]; ///< pre-filter numerator coefficients
118116 double pre_a[3]; ///< pre-filter denominator coefficients
119117 double rlb_b[3]; ///< rlb-filter numerator coefficients
@@ -430,13 +428,24 @@ static int config_audio_output(AVFilterLink *outlink) · 310 unmodified lines
430428 AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)
431429
432430 ebur128->nb_channels = nb_channels;
431+ ebur128->x = av_calloc(nb_channels, 3 * sizeof(*ebur128->x));
432+ ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y));
433+ ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z));
433434 ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
434− if (!ebur128->ch_weighting)
435+ if (!ebur128->ch_weighting || !ebur128->x || !ebur128->y || !ebur128->z)
435436 return AVERROR(ENOMEM);
436437
437438 #define I400_BINS(x) ((x) * 4 / 10)
438439 #define I3000_BINS(x) ((x) * 3)
439440
441+ ebur128->i400.sum = av_calloc(nb_channels, sizeof(*ebur128->i400.sum));
442+ ebur128->i3000.sum = av_calloc(nb_channels, sizeof(*ebur128->i3000.sum));
443+ ebur128->i400.cache = av_calloc(nb_channels, sizeof(*ebur128->i400.cache));
444+ ebur128->i3000.cache = av_calloc(nb_channels, sizeof(*ebur128->i3000.cache));
445+ if (!ebur128->i400.sum || !ebur128->i3000.sum ||
446+ !ebur128->i400.cache || !ebur128->i3000.cache)
447+ return AVERROR(ENOMEM);
448+
440449 for (i = 0; i < nb_channels; i++) {
441450 /* channel weighting */
442451 const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i);
@@ -993,16 +1002,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 550 unmodified lines
9931002 av_log(ctx, AV_LOG_INFO, "\n");
9941003
9951004 av_freep(&ebur128->y_line_ref);
1005+ av_freep(&ebur128->x);
1006+ av_freep(&ebur128->y);
1007+ av_freep(&ebur128->z);
9961008 av_freep(&ebur128->ch_weighting);
9971009 av_freep(&ebur128->true_peaks);
9981010 av_freep(&ebur128->sample_peaks);
9991011 av_freep(&ebur128->true_peaks_per_frame);
1012+ av_freep(&ebur128->i400.sum);
1013+ av_freep(&ebur128->i3000.sum);
10001014 av_freep(&ebur128->i400.histogram);
10011015 av_freep(&ebur128->i3000.histogram);
10021016 for (i = 0; i < ebur128->nb_channels; i++) {
1003− av_freep(&ebur128->i400.cache[i]);
1004− av_freep(&ebur128->i3000.cache[i]);
1017+ if (ebur128->i400.cache)
1018+ av_freep(&ebur128->i400.cache[i]);
1019+ if (ebur128->i3000.cache)
1020+ av_freep(&ebur128->i3000.cache[i]);
10051021 }
1022+ av_freep(&ebur128->i400.cache);
1023+ av_freep(&ebur128->i3000.cache);
10061024 av_frame_free(&ebur128->outpicref);
10071025 #if CONFIG_SWRESAMPLE
10081026 av_freep(&ebur128->swr_buf);

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