double freq;
double depth;
double *table;
+ int table_size;
int index;
} TremoloContext;
dst += channels;
src += channels;
s->index++;
- if (s->index >= inlink->sample_rate / s->freq)
+ if (s->index >= s->table_size)
s->index = 0;
}
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;
{ NULL }
};
-AVFilter ff_af_tremolo = {
+const AVFilter ff_af_tremolo = {
.name = "tremolo",
.description = NULL_IF_CONFIG_SMALL("Apply tremolo effect."),
.priv_size = sizeof(TremoloContext),