[FFmpeg-devel] [PATCH] lavfi: add aecho filter

Paul B Mahol onemda at gmail.com
Tue Jul 9 22:39:39 CEST 2013


On 7/9/13, Stefano Sabatini <stefasab at gmail.com> wrote:
> On date Tuesday 2013-07-09 14:53:14 +0000, Paul B Mahol encoded:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  doc/filters.texi         |  29 +++++
>>  libavfilter/Makefile     |   1 +
>>  libavfilter/af_aecho.c   | 297
>> +++++++++++++++++++++++++++++++++++++++++++++++
>>  libavfilter/allfilters.c |   1 +
>>  4 files changed, 328 insertions(+)
>>  create mode 100644 libavfilter/af_aecho.c
>>
>> diff --git a/doc/filters.texi b/doc/filters.texi
>> index 234ff2e..9472675 100644
>> --- a/doc/filters.texi
>> +++ b/doc/filters.texi
>> @@ -347,6 +347,35 @@ aconvert=u8:auto
>>  @end example
>>  @end itemize
>>
>> + at section aecho
>> +
>> +Apply echoing to the input audio.
>> +
>> +Echoes are reflected sound and can occur naturally amongst mountains
>> +(and sometimes large buildings) when talking or shouting; digital echo
>> +effects emulate this behaviour and are often used to help fill out the
>> +sound of a single instrument or vocal. The time difference between the
>> +original signal and the reflection is the @code{delay}, and the
>> +loudness of the reflected signal is the @code{decay}.
>> +Multiple echoes can have different delays and decays.
>> +
>> +A description of the accepted parameters follows.
>> +
>> + at table @option
>> + at item in_gain
>
>> +Set input volume of reflected signal.
>
> Expressed in? Defaul value is?
>
>> +
>> + at item out_gain
>> +Set output volume of reflected signal.
>
> Same
>
>> +
>> + at item delay1..7
>> +Set time interval in miliseconds between original signal and reflection.
>
> milliseconds
>
> Also what's "delay1..7"??
>
>> +
>> + at item decay1..7
>> +Loudness of reflected signal.
>
> Set loudness ...
>
> Same considerations as above.
>
>> +
>> + at end table
>> +
>>  @section afade
>>
>>  Apply fade-in/out effect to input audio.
>> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
>> index cf76ee1..306b24c 100644
>> --- a/libavfilter/Makefile
>> +++ b/libavfilter/Makefile
>> @@ -52,6 +52,7 @@ OBJS-$(CONFIG_AVFORMAT)                      +=
>> lavfutils.o
>>  OBJS-$(CONFIG_SWSCALE)                       += lswsutils.o
>>
>>  OBJS-$(CONFIG_ACONVERT_FILTER)               += af_aconvert.o
>> +OBJS-$(CONFIG_AECHO_FILTER)                  += af_aecho.o
>>  OBJS-$(CONFIG_AFADE_FILTER)                  += af_afade.o
>>  OBJS-$(CONFIG_AFORMAT_FILTER)                += af_aformat.o
>>  OBJS-$(CONFIG_AINTERLEAVE_FILTER)            += f_interleave.o
>> diff --git a/libavfilter/af_aecho.c b/libavfilter/af_aecho.c
>> new file mode 100644
>> index 0000000..9d4010d
>> --- /dev/null
>> +++ b/libavfilter/af_aecho.c
>> @@ -0,0 +1,297 @@
>> +/*
>> + * Copyright (c) 2013 Paul B Mahol
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>> + *
>> + */
>> +
>> +#include "libavutil/avstring.h"
>> +#include "libavutil/opt.h"
>> +#include "libavutil/samplefmt.h"
>> +#include "libavutil/avassert.h"
>> +#include "avfilter.h"
>> +#include "audio.h"
>> +#include "internal.h"
>> +
>
>> +#define MAX_ECHOS 7
>
> I hate hardcoded arbitrary ranges. Can't you make this value dynamic?
> +1 for psychedelic audio/video effects.

I could.

>
>> +
>> +typedef struct AudioEchoContext {
>> +    const AVClass *class;
>> +    float in_gain, out_gain;
>> +    float delay[MAX_ECHOS], decay[MAX_ECHOS];
>> +    int nb_echos;
>> +    int delay_index;
>> +    uint8_t **delayptrs;
>> +    int max_samples, fade_out;
>> +    int samples[MAX_ECHOS];
>> +    int64_t next_pts;
>> +
>> +    void (*echo_samples)(struct AudioEchoContext *ctx, uint8_t
>> **delayptrs,
>> +                         uint8_t * const *src, uint8_t **dst,
>> +                         int nb_samples, int channels);
>> +} AudioEchoContext;
>> +
>> +#define OFFSET(x) offsetof(AudioEchoContext, x)
>> +#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
>> +
>> +static const AVOption aecho_options[] = {
>> +    { "in_gain",  "", OFFSET(in_gain),  AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "out_gain", "", OFFSET(out_gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay1",   "", OFFSET(delay[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay1",   "", OFFSET(decay[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay2",   "", OFFSET(delay[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay2",   "", OFFSET(decay[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay3",   "", OFFSET(delay[2]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay3",   "", OFFSET(decay[2]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay4",   "", OFFSET(delay[3]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay4",   "", OFFSET(decay[3]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay5",   "", OFFSET(delay[4]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay5",   "", OFFSET(decay[4]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay6",   "", OFFSET(delay[5]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay6",   "", OFFSET(decay[5]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>> +    { "delay7",   "", OFFSET(delay[6]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 90000, A },
>> +    { "decay7",   "", OFFSET(decay[6]), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0,
>> 1, A },
>
> My suggestion is to have a delays=1,2,3,5,8,... decays=1,...

I dislike it littls as I need to manually check values ranges.
AVOption shuld be extended to support list of floats/ints/rationals....

>
> Check example parsing code in lavf/segment.c.
>
>> +    { NULL },
>> +};
>> +
>> +AVFILTER_DEFINE_CLASS(aecho);
>
> nit: aecho is weird, "echo" sounds fine to me

I ignore this one.

>
> [...]


More information about the ffmpeg-devel mailing list