From 49d97d9bcab888bcdac6b8635428bd7c88149d90 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 13 Dec 2015 11:52:23 +0100 Subject: [PATCH] avfilter/af_sofalizer: move modulo operation out of loop Signed-off-by: Paul B Mahol --- libavfilter/af_sofalizer.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c index 46e8e83f42..d0aa92ad8b 100644 --- a/libavfilter/af_sofalizer.c +++ b/libavfilter/af_sofalizer.c @@ -654,15 +654,15 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n const int n_samples = s->sofa.n_samples; /* length of one IR */ const float *src = (const float *)in->data[0]; /* get pointer to audio input buffer */ float *dst = (float *)out->data[0]; /* get pointer to audio output buffer */ - int in_channels = in->channels; /* number of input channels */ + const int in_channels = in->channels; /* number of input channels */ /* ring buffer length is: longest IR plus max. delay -> next power of 2 */ - int buffer_length = s->buffer_length; + const int buffer_length = s->buffer_length; /* -1 for AND instead of MODULO (applied to powers of 2): */ - uint32_t modulo = (uint32_t)buffer_length - 1; + const uint32_t modulo = (uint32_t)buffer_length - 1; float *buffer[10]; /* holds ringbuffer for each input channel */ int wr = *write; int read; - int i, j, l; + int i, l; dst += offset; for (l = 0; l < in_channels; l++) { @@ -688,8 +688,12 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n * (mod buffer length) */ read = (wr - *(delay + l) - (n_samples - 1) + buffer_length) & modulo; - for (j = 0; j < n_samples; j++) - temp_src[j] = bptr[(read + j) & modulo]; + if (read + n_samples < buffer_length) { + memcpy(temp_src, bptr + read, n_samples * sizeof(*temp_src)); + } else { + memcpy(temp_src, bptr + read, (buffer_length - read) * sizeof(*temp_src)); + memcpy(temp_src + (buffer_length - read), bptr, (read - n_samples) * sizeof(*temp_src)); + } /* multiply signal and IR, and add up the results */ dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, n_samples);