summaryrefslogtreecommitdiff
path: root/libavfilter/af_sofalizer.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2015-12-13 11:52:23 +0100
committerPaul B Mahol <onemda@gmail.com>2015-12-13 12:57:33 +0100
commit49d97d9bcab888bcdac6b8635428bd7c88149d90 (patch)
treebeb1b1021d25e5109f33b16e52878ada2e0c0aef /libavfilter/af_sofalizer.c
parent1acc90eaa54ad82a21474ed759b8ed3a0f3d482d (diff)
avfilter/af_sofalizer: move modulo operation out of loop
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/af_sofalizer.c')
-rw-r--r--libavfilter/af_sofalizer.c16
1 files 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);