[FFmpeg-devel] [PATCH] chorus filter

Michael Niedermayer michaelni at gmx.at
Sat Apr 4 12:47:35 CEST 2015


On Wed, Apr 01, 2015 at 04:04:57PM +0000, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
[...]
> +static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    ChorusContext *s = ctx->priv;
> +    AVFrame *out_frame;
> +    int c, i, n;
> +
> +    if (av_frame_is_writable(frame)) {
> +        out_frame = frame;
> +    } else {
> +        out_frame = ff_get_audio_buffer(inlink, frame->nb_samples);
> +        if (!out_frame)
> +            return AVERROR(ENOMEM);
> +        av_frame_copy_props(out_frame, frame);
> +    }
> +
> +    for (c = 0; c < inlink->channels; c++) {
> +        const float *src = (const float *)frame->extended_data[c];
> +        float *dst = (float *)out_frame->extended_data[c];
> +        float *chorusbuf = s->chorusbuf[c];
> +        int *phase = s->phase[c];
> +
> +        for (i = 0; i < frame->nb_samples; i++) {
> +            float out, in = src[i];
> +
> +            out = in * s->in_gain;
> +

> +            for (n = 0; n < s->num_chorus; n++)
> +                out += chorusbuf[(s->max_samples + s->counter[c] -
> +                                  s->lookup_table[n][phase[n]]) %
> +                                  s->max_samples] * s->decays[n];

the % should be avoided in the inner loop as its probably a major
factor in the performace of the filter if there are many iterations

a power of 2 could be used or alternatively the buffer could be
reorganized in some other way like writing to a larger area than
max_samples, ensuring that theres no need to handle wrap around but
rather write more samples occasionally

also other minor things could likely be factored out of the loop



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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- 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/20150404/d0ed06f3/attachment.asc>


More information about the ffmpeg-devel mailing list