History

avfilter/f_ebur128: simplify sample cache array

We don't need an X sample cache anymore, and we also can simplify the access macro slightly.

Niklas Haas committed 1 year ago

Commit 2d9435d1 parent c5f30331 file · +11 −18Browse files

Unified · Split

libavfilter/f_ebur128.c+11−18
@@ -115,7 +115,6 @@ typedef struct EBUR128Context { · 114 unmodified lines
115 115
116 /* Filter caches.116 /* Filter caches.
117 * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */117 * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */
118 double *x; ///< 3 input samples cache for each channel
119 double *y; ///< 3 pre-filter samples cache for each channel118 double *y; ///< 3 pre-filter samples cache for each channel
120 double *z; ///< 3 RLB-filter samples cache for each channel119 double *z; ///< 3 RLB-filter samples cache for each channel
121 double pre_b[3]; ///< pre-filter numerator coefficients120 double pre_b[3]; ///< pre-filter numerator coefficients
@@ -446,11 +445,10 @@ static int config_audio_output(AVFilterLink *outlink) · 324 unmodified lines
446 AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)445 AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)
447 446
448 ebur128->nb_channels = nb_channels;447 ebur128->nb_channels = nb_channels;
449 ebur128->x = av_calloc(nb_channels, 3 * sizeof(*ebur128->x));
450 ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y));448 ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y));
451 ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z));449 ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z));
452 ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));450 ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
453 if (!ebur128->ch_weighting || !ebur128->x || !ebur128->y || !ebur128->z)451 if (!ebur128->ch_weighting || !ebur128->y || !ebur128->z)
454 return AVERROR(ENOMEM);452 return AVERROR(ENOMEM);
455 453
456#define I400_BINS(x) ((x) * 4 / 10)454#define I400_BINS(x) ((x) * 4 / 10)
@@ -673,34 +671,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) · 216 unmodified lines
673 MOVE_TO_NEXT_CACHED_ENTRY(3000);671 MOVE_TO_NEXT_CACHED_ENTRY(3000);
674 672
675 for (ch = 0; ch < nb_channels; ch++) {673 for (ch = 0; ch < nb_channels; ch++) {
676 double bin;
677
678 if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS)674 if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS)
679 ebur128->sample_peaks[ch] = FFMAX(ebur128->sample_peaks[ch], fabs(samples[idx_insample * nb_channels + ch]));675 ebur128->sample_peaks[ch] = FFMAX(ebur128->sample_peaks[ch], fabs(samples[idx_insample * nb_channels + ch]));
680 676
681 ebur128->x[ch * 3] = samples[idx_insample * nb_channels + ch]; // set X[i]
682
683 if (!ebur128->ch_weighting[ch])677 if (!ebur128->ch_weighting[ch])
684 continue;678 continue;
685 679
686 /* Y[i] = X[i]*b0 + X[i-1]*b1 + X[i-2]*b2 - Y[i-1]*a1 - Y[i-2]*a2 */680 /* Y[i] = X[i]*b0 + X[i-1]*b1 + X[i-2]*b2 - Y[i-1]*a1 - Y[i-2]*a2 */
687#define FILTER(Y, X, NUM, DEN) do { \681#define FILTER(DST, SRC, NUM, DEN) do { \
688 double *dst = ebur128->Y + ch*3; \682 const double tmp = DST[0] = NUM[0] * SRC + DST[1]; \
689 double src = ebur128->X[ch*3] ; \683 DST[1] = NUM[1] * SRC + DST[2] - DEN[1] * tmp; \
690 double dst0 = NUM[0] * src + dst[1]; \684 DST[2] = NUM[2] * SRC - DEN[2] * tmp; \
691 dst[1] = NUM[1] * src + dst[2] - DEN[1] * dst0; \
692 dst[2] = NUM[2] * src - DEN[2] * dst0; \
693 dst[0] = dst0; \
694} while (0)685} while (0)
695 686
687 const double x = samples[idx_insample * nb_channels + ch];
688 double *restrict y = &ebur128->y[3 * ch];
689 double *restrict z = &ebur128->z[3 * ch];
690
696 // TODO: merge both filters in one?691 // TODO: merge both filters in one?
697 FILTER(y, x, ebur128->pre_b, ebur128->pre_a); // apply pre-filter692 FILTER(y, x, ebur128->pre_b, ebur128->pre_a); // apply pre-filter
698 FILTER(z, y, ebur128->rlb_b, ebur128->rlb_a); // apply RLB-filter693 FILTER(z, *y, ebur128->rlb_b, ebur128->rlb_a); // apply RLB-filter
699
700 bin = ebur128->z[ch * 3] * ebur128->z[ch * 3];
701 694
702 /* add the new value, and limit the sum to the cache size (400ms or 3s)695 /* add the new value, and limit the sum to the cache size (400ms or 3s)
703 * by removing the oldest one */696 * by removing the oldest one */
697 double bin = *z * *z;
704 ebur128->i400.sum [ch] = ebur128->i400.sum [ch] + bin - ebur128->i400.cache [ch][bin_id_400];698 ebur128->i400.sum [ch] = ebur128->i400.sum [ch] + bin - ebur128->i400.cache [ch][bin_id_400];
705 ebur128->i3000.sum[ch] = ebur128->i3000.sum[ch] + bin - ebur128->i3000.cache[ch][bin_id_3000];699 ebur128->i3000.sum[ch] = ebur128->i3000.sum[ch] + bin - ebur128->i3000.cache[ch][bin_id_3000];
706 700
@@ -1073,7 +1067,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 366 unmodified lines
1073 }1067 }
1074 1068
1075 av_freep(&ebur128->y_line_ref);1069 av_freep(&ebur128->y_line_ref);
1076 av_freep(&ebur128->x);
1077 av_freep(&ebur128->y);1070 av_freep(&ebur128->y);
1078 av_freep(&ebur128->z);1071 av_freep(&ebur128->z);
1079 av_freep(&ebur128->ch_weighting);1072 av_freep(&ebur128->ch_weighting);

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