[FFmpeg-devel] [PATCH] avfilter/avf_showspectrum: properly calculate w factor
Paul B Mahol
onemda at gmail.com
Tue Dec 29 00:06:39 CET 2015
It is used in calculating loudness of each frequency bin.
This increases contrast for all scale modes except log.
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavfilter/avf_showspectrum.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 55cc668..ff991e0 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -57,6 +57,7 @@ typedef struct {
FFTSample **rdft_data; ///< bins holder for each (displayed) channels
float *window_func_lut; ///< Window function LUT
int win_func;
+ double win_scale;
float overlap;
float *combine_buffer; ///< color combining buffer (3 * h items)
} ShowSpectrumContext;
@@ -218,6 +219,10 @@ static int config_output(AVFilterLink *outlink)
return AVERROR(ENOMEM);
ff_generate_window_func(s->window_func_lut, win_size, s->win_func, &s->overlap);
+ for (s->win_scale = 0, i = 0; i < win_size; i++) {
+ s->win_scale += s->window_func_lut[i] * s->window_func_lut[i];
+ }
+
/* prepare the initial picref buffer (black frame) */
av_frame_free(&s->outpicref);
s->outpicref = outpicref =
@@ -285,7 +290,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
* height (or half the RDFT window size) */
const int nb_freq = 1 << (s->rdft_bits - 1);
const int win_size = nb_freq << 1;
- const double w = 1. / (sqrt(nb_freq) * 32768.);
+ const double w = 1. / (s->win_scale * s->win_scale);
int h = s->channel_height;
int ch, plane, n, y;
--
1.9.1
More information about the ffmpeg-devel
mailing list