diff options
author | Paul B Mahol <onemda@gmail.com> | 2022-11-27 19:42:23 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2022-11-27 19:53:16 +0100 |
commit | 2324b917fce0eb0175ed3c135a51213e1bf7bc18 (patch) | |
tree | 71a1dbb079eff0de5bf501c69f069b455d3ae1eb | |
parent | 100939695307743396e30e6310d2ea9cf42f9aab (diff) | |
download | ffmpeg-2324b917fce0eb0175ed3c135a51213e1bf7bc18.tar.gz |
avfilter/avf_avectorscope: simplify code a little
-rw-r--r-- | libavfilter/avf_avectorscope.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c index 81f22bbe8c..15d9526946 100644 --- a/libavfilter/avf_avectorscope.c +++ b/libavfilter/avf_avectorscope.c @@ -252,6 +252,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; + const int16_t *samples = (const int16_t *)insamples->data[0]; + const float *samplesf = (const float *)insamples->data[0]; AudioVectorScopeContext *s = ctx->priv; const int hw = s->hw; const int hh = s->hh; @@ -259,7 +261,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) unsigned x, y; unsigned prev_x = s->prev_x, prev_y = s->prev_y; double zoom = s->zoom; - int i; if (!s->outpicref || s->outpicref->width != outlink->w || s->outpicref->height != outlink->h) { @@ -271,7 +272,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } s->outpicref->sample_aspect_ratio = (AVRational){1,1}; - for (i = 0; i < outlink->h; i++) + for (int i = 0; i < outlink->h; i++) memset(s->outpicref->data[0] + i * s->outpicref->linesize[0], 0, outlink->w * 4); } s->outpicref->pts = av_rescale_q(insamples->pts, inlink->time_base, outlink->time_base); @@ -284,22 +285,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) float max = 0; switch (insamples->format) { - case AV_SAMPLE_FMT_S16: { - int16_t *samples = (int16_t *)insamples->data[0]; - - for (i = 0; i < insamples->nb_samples * 2; i++) { + case AV_SAMPLE_FMT_S16: + for (int i = 0; i < insamples->nb_samples * 2; i++) { float sample = samples[i] / (float)INT16_MAX; max = FFMAX(FFABS(sample), max); } - - } break; - case AV_SAMPLE_FMT_FLT: { - float *samples = (float *)insamples->data[0]; - - for (i = 0; i < insamples->nb_samples * 2; i++) { - max = FFMAX(FFABS(samples[i]), max); - } + case AV_SAMPLE_FMT_FLT: + for (int i = 0; i < insamples->nb_samples * 2; i++) { + max = FFMAX(FFABS(samplesf[i]), max); } break; default: @@ -321,19 +315,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) zoom = 1. / max; } - for (i = 0; i < insamples->nb_samples; i++) { - int16_t *samples = (int16_t *)insamples->data[0] + i * 2; - float *samplesf = (float *)insamples->data[0] + i * 2; + for (int i = 0; i < insamples->nb_samples; i++) { float src[2]; switch (insamples->format) { case AV_SAMPLE_FMT_S16: - src[0] = samples[0] / (float)INT16_MAX; - src[1] = samples[1] / (float)INT16_MAX; + src[0] = samples[i*2+0] / (float)INT16_MAX; + src[1] = samples[i*2+1] / (float)INT16_MAX; break; case AV_SAMPLE_FMT_FLT: - src[0] = samplesf[0]; - src[1] = samplesf[1]; + src[0] = samplesf[i*2+0]; + src[1] = samplesf[i*2+1]; break; default: av_assert2(0); |