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

Unified · Split

libavfilter/f_ebur128.c+28−10
@@ -42,8 +42,6 @@ · 41 unmodified lines
42#include "formats.h"42#include "formats.h"
43#include "internal.h"43#include "internal.h"
44 44
45#define MAX_CHANNELS 63
46
47#define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold45#define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold
48#define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum)46#define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum)
49#define HIST_GRAIN 100 ///< defines histogram precision47#define HIST_GRAIN 100 ///< defines histogram precision
@@ -63,10 +61,10 @@ struct hist_entry { · 13 unmodified lines
63};61};
64 62
65struct integrator {63struct integrator {
66 double *cache[MAX_CHANNELS]; ///< window of filtered samples (N ms)64 double **cache; ///< window of filtered samples (N ms)
67 int cache_pos; ///< focus on the last added bin in the cache array65 int cache_pos; ///< focus on the last added bin in the cache array
68 int cache_size;66 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)
70 int filled; ///< 1 if the cache is completely filled, 0 otherwise68 int filled; ///< 1 if the cache is completely filled, 0 otherwise
71 double rel_threshold; ///< relative threshold69 double rel_threshold; ///< relative threshold
72 double sum_kept_powers; ///< sum of the powers (weighted sums) above absolute threshold70 double sum_kept_powers; ///< sum of the powers (weighted sums) above absolute threshold
@@ -111,9 +109,9 @@ typedef struct EBUR128Context { · 38 unmodified lines
111 109
112 /* Filter caches.110 /* Filter caches.
113 * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */111 * 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 channel112 double *x; ///< 3 input samples cache for each channel
115 double y[MAX_CHANNELS * 3]; ///< 3 pre-filter samples cache for each channel113 double *y; ///< 3 pre-filter samples cache for each channel
116 double z[MAX_CHANNELS * 3]; ///< 3 RLB-filter samples cache for each channel114 double *z; ///< 3 RLB-filter samples cache for each channel
117 double pre_b[3]; ///< pre-filter numerator coefficients115 double pre_b[3]; ///< pre-filter numerator coefficients
118 double pre_a[3]; ///< pre-filter denominator coefficients116 double pre_a[3]; ///< pre-filter denominator coefficients
119 double rlb_b[3]; ///< rlb-filter numerator coefficients117 double rlb_b[3]; ///< rlb-filter numerator coefficients
@@ -430,13 +428,24 @@ static int config_audio_output(AVFilterLink *outlink) · 310 unmodified lines
430 AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)428 AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)
431 429
432 ebur128->nb_channels = nb_channels;430 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));
433 ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));434 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)
435 return AVERROR(ENOMEM);436 return AVERROR(ENOMEM);
436 437
437#define I400_BINS(x) ((x) * 4 / 10)438#define I400_BINS(x) ((x) * 4 / 10)
438#define I3000_BINS(x) ((x) * 3)439#define I3000_BINS(x) ((x) * 3)
439 440
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
440 for (i = 0; i < nb_channels; i++) {449 for (i = 0; i < nb_channels; i++) {
441 /* channel weighting */450 /* channel weighting */
442 const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i);451 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
993 av_log(ctx, AV_LOG_INFO, "\n");1002 av_log(ctx, AV_LOG_INFO, "\n");
994 1003
995 av_freep(&ebur128->y_line_ref);1004 av_freep(&ebur128->y_line_ref);
1005 av_freep(&ebur128->x);
1006 av_freep(&ebur128->y);
1007 av_freep(&ebur128->z);
996 av_freep(&ebur128->ch_weighting);1008 av_freep(&ebur128->ch_weighting);
997 av_freep(&ebur128->true_peaks);1009 av_freep(&ebur128->true_peaks);
998 av_freep(&ebur128->sample_peaks);1010 av_freep(&ebur128->sample_peaks);
999 av_freep(&ebur128->true_peaks_per_frame);1011 av_freep(&ebur128->true_peaks_per_frame);
1012 av_freep(&ebur128->i400.sum);
1013 av_freep(&ebur128->i3000.sum);
1000 av_freep(&ebur128->i400.histogram);1014 av_freep(&ebur128->i400.histogram);
1001 av_freep(&ebur128->i3000.histogram);1015 av_freep(&ebur128->i3000.histogram);
1002 for (i = 0; i < ebur128->nb_channels; i++) {1016 for (i = 0; i < ebur128->nb_channels; i++) {
1003 av_freep(&ebur128->i400.cache[i]);1017 if (ebur128->i400.cache)
1004 av_freep(&ebur128->i3000.cache[i]);1018 av_freep(&ebur128->i400.cache[i]);
1019 if (ebur128->i3000.cache)
1020 av_freep(&ebur128->i3000.cache[i]);
1005 }1021 }
1022 av_freep(&ebur128->i400.cache);
1023 av_freep(&ebur128->i3000.cache);
1006 av_frame_free(&ebur128->outpicref);1024 av_frame_free(&ebur128->outpicref);
1007#if CONFIG_SWRESAMPLE1025#if CONFIG_SWRESAMPLE
1008 av_freep(&ebur128->swr_buf);1026 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