X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Faf_tremolo.c;h=8f9e3100409fb64b4a0599d223bb34fafc2d6552;hb=a04ad248a05e7b613abe09b3bb067f555108d794;hp=8cbc79892d1236d6c224b1ffbc2f3c1551fe6669;hpb=5c1aafff2d844b177b0b20db4a38d8460992558b;p=ffmpeg diff --git a/libavfilter/af_tremolo.c b/libavfilter/af_tremolo.c index 8cbc79892d1..8f9e3100409 100644 --- a/libavfilter/af_tremolo.c +++ b/libavfilter/af_tremolo.c @@ -28,6 +28,7 @@ typedef struct TremoloContext { double freq; double depth; double *table; + int table_size; int index; } TremoloContext; @@ -72,7 +73,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) dst += channels; src += channels; s->index++; - if (s->index >= inlink->sample_rate / s->freq) + if (s->index >= s->table_size) s->index = 0; } @@ -125,11 +126,12 @@ static int config_input(AVFilterLink *inlink) const double offset = 1. - s->depth / 2.; int i; - s->table = av_malloc_array(inlink->sample_rate / s->freq, sizeof(*s->table)); + s->table_size = lrint(inlink->sample_rate / s->freq + 0.5); + s->table = av_malloc_array(s->table_size, sizeof(*s->table)); if (!s->table) return AVERROR(ENOMEM); - for (i = 0; i < inlink->sample_rate / s->freq; i++) { + for (i = 0; i < s->table_size; i++) { double env = s->freq * i / inlink->sample_rate; env = sin(2 * M_PI * fmod(env + 0.25, 1.0)); s->table[i] = env * (1 - fabs(offset)) + offset; @@ -158,7 +160,7 @@ static const AVFilterPad avfilter_af_tremolo_outputs[] = { { NULL } }; -AVFilter ff_af_tremolo = { +const AVFilter ff_af_tremolo = { .name = "tremolo", .description = NULL_IF_CONFIG_SMALL("Apply tremolo effect."), .priv_size = sizeof(TremoloContext),