summaryrefslogtreecommitdiff
path: root/libavfilter/avf_showspectrum.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2016-01-10 18:30:16 +0100
committerPaul B Mahol <onemda@gmail.com>2016-01-12 21:21:50 +0100
commit57df71eaf7c472e8fa3f51a01b5b75cf7c7f9b25 (patch)
tree2f634140c901b6a5a9025bac8859177f7b8d13fc /libavfilter/avf_showspectrum.c
parent2009d922db7aeaffd73e23e56580d8d34322ae65 (diff)
avfilter/avf_showspectrum: reduce number of operations
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/avf_showspectrum.c')
-rw-r--r--libavfilter/avf_showspectrum.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 7fd0ea99d0..424d1f2f55 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -451,13 +451,15 @@ static void run_fft(ShowSpectrumContext *s, AVFrame *fin)
static void calc_magnitudes(ShowSpectrumContext *s)
{
+ const double w = s->win_scale * (s->scale == LOG ? s->win_scale : 1);
int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
+ const float f = s->gain * w;
for (ch = 0; ch < s->nb_display_channels; ch++) {
float *magnitudes = s->magnitudes[ch];
for (y = 0; y < h; y++)
- magnitudes[y] = MAGNITUDE(y, ch);
+ magnitudes[y] = MAGNITUDE(y, ch) * f;
}
}
@@ -475,13 +477,15 @@ static void calc_phases(ShowSpectrumContext *s)
static void acalc_magnitudes(ShowSpectrumContext *s)
{
+ const double w = s->win_scale * (s->scale == LOG ? s->win_scale : 1);
int ch, y, h = s->orientation == VERTICAL ? s->h : s->w;
+ const float f = s->gain * w;
for (ch = 0; ch < s->nb_display_channels; ch++) {
float *magnitudes = s->magnitudes[ch];
for (y = 0; y < h; y++)
- magnitudes[y] += MAGNITUDE(y, ch);
+ magnitudes[y] += MAGNITUDE(y, ch) * f;
}
}
@@ -611,8 +615,6 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
AVFilterLink *outlink = ctx->outputs[0];
ShowSpectrumContext *s = ctx->priv;
AVFrame *outpicref = s->outpicref;
- const double w = s->data == D_PHASE ? 1 : s->win_scale;
- const float g = s->gain;
int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
int ch, plane, x, y;
@@ -638,7 +640,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
switch (s->data) {
case D_MAGNITUDE:
/* get magnitude */
- a = g * w * magnitudes[y];
+ a = magnitudes[y];
break;
case D_PHASE:
/* get phase */
@@ -666,7 +668,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
a = av_clipf(pow(a, 0.20), 0, 1);
break;
case LOG:
- a = 1 + log10(av_clipd(a * w, 1e-6, 1)) / 6; // zero = -120dBFS
+ a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6; // zero = -120dBFS
break;
default:
av_assert0(0);