[FFmpeg-devel] [PATCH][BULK][again] new multimedia filter avf_showcqt.c

Michael Niedermayer michaelni at gmx.at
Sat May 31 03:09:15 CEST 2014


On Thu, May 29, 2014 at 07:57:39PM -0700, Muhammad Faiz wrote:
> On Wed, May 28, 2014 at 12:03 AM, Clément Bœsch <u at pkh.me> wrote:
> 
> > On Wed, May 28, 2014 at 10:59:20AM +0700, Muhammad Faiz wrote:
> > > Hi,
> > > this filter is same as showspectrum but with constant Q transform,
> > > so frequency is spaced logarithmically
> >
> > > diff -ruN a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> > > --- a/libavfilter/allfilters.c        2014-05-19 13:35:09.327627603 +0700
> > > +++ b/libavfilter/allfilters.c        2014-05-19 11:07:44.977770955 +0700
> >
> > Would it be possible to provide a git-format-patch instead?
> >
> >
> Thank's for all helps and suggestions.

[...]
> +    av_log(ctx, AV_LOG_INFO, "Calculating spectral kernel, please wait\n");
> +    for (k = 0; k < VIDEO_WIDTH; k++)
> +    {
> +        int hlen = fft_len >> 1;
> +        float total = 0;
> +        float partial = 0;
> +        double freq = BASE_FREQ * exp2(k * (1.0/192.0));
> +        double tlen = rate * (24.0 * 16.0) /freq;
> +        tlen = tlen * max_len / (tlen + max_len);
> +        s->fft_data[0].re = 0;
> +        s->fft_data[0].im = 0;
> +        s->fft_data[hlen].re = window_function(0) * (1.0/tlen) * s->volume * (1.0/fft_len);
> +        s->fft_data[hlen].im = 0;
> +        for (x = 1; x < hlen; x++)
> +        {
> +            double sv, cv, w;
> +            w = window_function(x * (1.0/tlen)) * (1.0/tlen) * s->volume * (1.0/fft_len);
> +            if (!w)
> +                break;
> +            sv = sin(2.0*M_PI*freq*x*(1.0/rate));
> +            cv = cos(2.0*M_PI*freq*x*(1.0/rate));
> +            s->fft_data[hlen + x].re = w * cv;
> +            s->fft_data[hlen + x].im = w * sv;
> +            s->fft_data[hlen - x].re = s->fft_data[hlen + x].re;
> +            s->fft_data[hlen - x].im = -s->fft_data[hlen + x].im;
> +        }
> +        for (; x < hlen; x++)
> +        {
> +            s->fft_data[hlen + x].re = 0;
> +            s->fft_data[hlen + x].im = 0;
> +            s->fft_data[hlen - x].re = 0;
> +            s->fft_data[hlen - x].im = 0;
> +        }
> +        av_fft_permute(s->fft_context, s->fft_data);
> +        av_fft_calc(s->fft_context, s->fft_data);
> +
> +        for (x = 0; x < fft_len; x++)
> +        {
> +            s->coeff_sort[x].index = x;
> +            s->coeff_sort[x].value = s->fft_data[x].re;
> +        }
> +

> +        qsort(s->coeff_sort, fft_len, sizeof(*s->coeff_sort), qsort_sparsecoeff);

you can try libavutil/qsort.h which would avoid some overhead of
qsort()
also the abs() does not need to be done in the compare function,
it could be done outside

or if its still slow, this can be done using a radix sort
(this would require the floats to be read as integers)


[...]
> +        for (x = 0; x < VIDEO_WIDTH; x += VIDEO_WIDTH/10)
> +        {
> +            int u;

> +            const char *str = "EF G A BC D ";

static const

and SIMD optimizations of the most speed critical part would make
sense if you know asm

Also you probably want to add yourself to the MAINTAINERs file for
showcqt


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140531/09527a2b/attachment.asc>


More information about the ffmpeg-devel mailing list