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

Pavel Koshevoy pkoshevoy at gmail.com
Wed Jun 13 05:40:53 CEST 2012


On 6/12/2012 8:34 PM, Michael Niedermayer wrote:
> On Tue, Jun 12, 2012 at 07:19:54PM -0600, Pavel Koshevoy wrote:
>> On 06/12/2012 05:07 PM, Michael Niedermayer wrote:
>>> On Mon, Jun 11, 2012 at 09:18:02PM -0600, Pavel Koshevoy wrote:
>> [...]
>>
>>>> +/**
>>>> + * 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
>> I'll look into that, thank you.
>>
>>>
>>>> +
>>>> +    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
>> My DSP experience is limited.  What is the procedure for computing
>> cross correlation of two signals using rDFT?
> basically same procedure, its just half the real scalar values the
> fft deals with thus 2x as fast
>

I need to know how the coefficients are stored after R2C transform.  Is 
it a simple array of (N/2 + 1) complex numbers (or N + 2 scalars), or is 
it a bit more complicated -- Y[0] and Y[N/2] are purely real and 
therefore their imaginary component is not stored, thus requiring only N 
scalar values for storage.  That's how FFTW does it.

It matters because I need to calculate a product of complex numbers, 
therefore I need to know where each Re and Im component is stored.

Also, is there an ffmpeg utility function for multiplying two vectors of 
complex numbers?

Thank you,
     Pavel.



More information about the ffmpeg-devel mailing list