[FFmpeg-devel] [PATCH] libavfilter: add atempo filter (revised patch v5)

Michael Niedermayer michaelni at gmx.at
Wed Jun 13 01:07:45 CEST 2012


On Mon, Jun 11, 2012 at 09:18:02PM -0600, Pavel Koshevoy wrote:
> Add atempo audio filter for adjusting audio tempo without affecting
> pitch. This filter implements WSOLA algorithm with fast cross
> correlation calculation in frequency domain.
[...]
> +#define REALLOC_OR_FAIL(field, field_size)                      \
> +    do {                                                        \
> +        field = av_realloc(field, (field_size));                \
> +        if (!field)                                             \
> +            return AVERROR(ENOMEM);                             \
> +    } while (0)
> +

> +/**
> + * Prepare filter for processing audio data of given format,
> + * sample rate and number of channels.
> + */
> +static int yae_reset(ATempoContext *atempo,
> +                     enum AVSampleFormat format,
> +                     int sample_rate,
> +                     int channels)
> +{
> +    const int sample_size = av_get_bytes_per_sample(format);
> +    uint32_t nlevels  = 0;
> +    uint32_t pot;
> +    int i;
> +
> +    atempo->format   = format;
> +    atempo->channels = channels;
> +    atempo->stride   = sample_size * channels;
> +
> +    // pick a segment window size:
> +    atempo->window = sample_rate / 24;
> +
> +    // adjust window size to be a power-of-two integer:
> +    nlevels = av_log2(atempo->window);
> +    pot = 1 << nlevels;
> +    av_assert0(pot <= atempo->window);
> +
> +    if (pot < atempo->window) {
> +        atempo->window = pot * 2;
> +        nlevels++;
> +    }
> +
> +    // initialize audio fragment buffers:
> +    REALLOC_OR_FAIL(atempo->frag[0].data,
> +                    atempo->window * atempo->stride);
> +
> +    REALLOC_OR_FAIL(atempo->frag[1].data,
> +                    atempo->window * atempo->stride);
> +
> +    REALLOC_OR_FAIL(atempo->frag[0].xdat,
> +                    atempo->window * 2 * sizeof(FFTComplex));
> +
> +    REALLOC_OR_FAIL(atempo->frag[1].xdat,
> +                    atempo->window * 2 * sizeof(FFTComplex));
> +
> +    // initialize FFT contexts:
> +    av_fft_end(atempo->fft_forward);
> +    av_fft_end(atempo->fft_inverse);

maybe this should call uninit()

also if something in this fails then the resuslting state is a mess
some arrays one size some others another some memleaks and the ffts
might even end with a double free i think


> +
> +    atempo->fft_forward = av_fft_init(nlevels + 1, 0);
> +    if (!atempo->fft_forward) {
> +        return AVERROR(ENOMEM);
> +    }
> +
> +    atempo->fft_inverse = av_fft_init(nlevels + 1, 1);
> +    if (!atempo->fft_inverse) {
> +        return AVERROR(ENOMEM);
> +    }

by using a RDFT you can cut the computations needed down by a factor
of 2


[...]
> +            // build a multi-resolution pyramid for fragment alignment:
> +            yae_downmix(atempo, yae_curr_frag(atempo));

i see no multi-resolution pyramid

overall i have the feeling this filter could be implemented in less
code and with less complexity but thats not an objection from me.

ill leave further review & applying to stefano

if you want to maintain this filter once its
in git, then you should get a public git clone of ffmpeg (for example
on github) so you can conveniently maintain it. And once you have
some changes in your git repository with which you are happy just
ask me to merge them ...

thanks

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

No great genius has ever existed without some touch of madness. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120613/f33bffaf/attachment.asc>


More information about the ffmpeg-devel mailing list