aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2023-02-25 19:27:58 +0100
committerTristan Matthews <tmatth@videolan.org>2023-02-25 14:07:44 -0500
commitbd9162cd7f58af6ec5087992b861fc9360c00a77 (patch)
tree9eb8da45fcca758efc4679380fffe44d2ed873cc
parent70f2cf7ea32324af5c40b5f564eeb05830c89507 (diff)
downloadspeex-bd9162cd7f58af6ec5087992b861fc9360c00a77.tar.gz
Factor out magic_samples access
-rw-r--r--libspeexdsp/resample.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/libspeexdsp/resample.c b/libspeexdsp/resample.c
index 80b5ff1..f4a5a23 100644
--- a/libspeexdsp/resample.c
+++ b/libspeexdsp/resample.c
@@ -734,15 +734,16 @@ static int update_filter(SpeexResamplerState *st)
spx_uint32_t j;
spx_uint32_t olen = old_length;
spx_uint32_t start = i*st->mem_alloc_size;
+ spx_uint32_t magic_samples = st->magic_samples[i];
/*if (st->magic_samples[i])*/
{
/* Try and remove the magic samples as if nothing had happened */
/* FIXME: This is wrong but for now we need it to avoid going over the array bounds */
- olen = old_length + 2*st->magic_samples[i];
- for (j=old_length-1+st->magic_samples[i];j--;)
- st->mem[start+j+st->magic_samples[i]] = st->mem[i*old_alloc_size+j];
- for (j=0;j<st->magic_samples[i];j++)
+ olen = old_length + 2*magic_samples;
+ for (j=old_length-1+magic_samples;j--;)
+ st->mem[start+j+magic_samples] = st->mem[i*old_alloc_size+j];
+ for (j=0;j<magic_samples;j++)
st->mem[start+j] = 0;
st->magic_samples[i] = 0;
}
@@ -759,9 +760,10 @@ static int update_filter(SpeexResamplerState *st)
st->last_sample[i] += (st->filt_len - olen)/2;
} else {
/* Put back some of the magic! */
- st->magic_samples[i] = (olen - st->filt_len)/2;
- for (j=0;j<st->filt_len-1+st->magic_samples[i];j++)
- st->mem[start+j] = st->mem[start+j+st->magic_samples[i]];
+ magic_samples = (olen - st->filt_len)/2;
+ for (j=0;j<st->filt_len-1+magic_samples;j++)
+ st->mem[start+j] = st->mem[start+j+magic_samples];
+ st->magic_samples[i] = magic_samples;
}
}
} else if (st->filt_len < old_length)