Skip to content

Commit bd9162c

Browse files
lu-zerotmatth
authored andcommitted
Factor out magic_samples access
1 parent 70f2cf7 commit bd9162c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libspeexdsp/resample.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,16 @@ static int update_filter(SpeexResamplerState *st)
734734
spx_uint32_t j;
735735
spx_uint32_t olen = old_length;
736736
spx_uint32_t start = i*st->mem_alloc_size;
737+
spx_uint32_t magic_samples = st->magic_samples[i];
737738
/*if (st->magic_samples[i])*/
738739
{
739740
/* Try and remove the magic samples as if nothing had happened */
740741

741742
/* FIXME: This is wrong but for now we need it to avoid going over the array bounds */
742-
olen = old_length + 2*st->magic_samples[i];
743-
for (j=old_length-1+st->magic_samples[i];j--;)
744-
st->mem[start+j+st->magic_samples[i]] = st->mem[i*old_alloc_size+j];
745-
for (j=0;j<st->magic_samples[i];j++)
743+
olen = old_length + 2*magic_samples;
744+
for (j=old_length-1+magic_samples;j--;)
745+
st->mem[start+j+magic_samples] = st->mem[i*old_alloc_size+j];
746+
for (j=0;j<magic_samples;j++)
746747
st->mem[start+j] = 0;
747748
st->magic_samples[i] = 0;
748749
}
@@ -759,9 +760,10 @@ static int update_filter(SpeexResamplerState *st)
759760
st->last_sample[i] += (st->filt_len - olen)/2;
760761
} else {
761762
/* Put back some of the magic! */
762-
st->magic_samples[i] = (olen - st->filt_len)/2;
763-
for (j=0;j<st->filt_len-1+st->magic_samples[i];j++)
764-
st->mem[start+j] = st->mem[start+j+st->magic_samples[i]];
763+
magic_samples = (olen - st->filt_len)/2;
764+
for (j=0;j<st->filt_len-1+magic_samples;j++)
765+
st->mem[start+j] = st->mem[start+j+magic_samples];
766+
st->magic_samples[i] = magic_samples;
765767
}
766768
}
767769
} else if (st->filt_len < old_length)

0 commit comments

Comments
 (0)