swr: remove div/mod from DSP functions.

Also fix a bug with resample_compensation resetting dst_incr.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/76/merge
Ronald S. Bultje 11 years ago committed by Michael Niedermayer
parent 076ab9f7e3
commit cbf21628a5
  1. 21
      libswresample/resample.c
  2. 2
      libswresample/resample.h
  3. 6
      libswresample/resample_template.c

@ -232,6 +232,8 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r
if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2)) if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2))
goto error; goto error;
c->ideal_dst_incr = c->dst_incr; c->ideal_dst_incr = c->dst_incr;
c->dst_incr_div = c->dst_incr / c->src_incr;
c->dst_incr_mod = c->dst_incr % c->src_incr;
c->index= -phase_count*((c->filter_length-1)/2); c->index= -phase_count*((c->filter_length-1)/2);
c->frac= 0; c->frac= 0;
@ -258,6 +260,10 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati
c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance; c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
else else
c->dst_incr = c->ideal_dst_incr; c->dst_incr = c->ideal_dst_incr;
c->dst_incr_div = c->dst_incr / c->src_incr;
c->dst_incr_mod = c->dst_incr % c->src_incr;
return 0; return 0;
} }
@ -270,8 +276,6 @@ static int swri_resample(ResampleContext *c,
if (c->filter_length == 1 && c->phase_shift == 0) { if (c->filter_length == 1 && c->phase_shift == 0) {
int index= c->index; int index= c->index;
int frac= c->frac; int frac= c->frac;
int dst_incr_frac= c->dst_incr % c->src_incr;
int dst_incr= c->dst_incr / c->src_incr;
int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*index; int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*index;
int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
int new_size = (src_size * (int64_t)c->src_incr - frac + c->dst_incr - 1) / c->dst_incr; int new_size = (src_size * (int64_t)c->src_incr - frac + c->dst_incr - 1) / c->dst_incr;
@ -279,12 +283,12 @@ static int swri_resample(ResampleContext *c,
dst_size= FFMIN(dst_size, new_size); dst_size= FFMIN(dst_size, new_size);
c->dsp.resample_one[fn_idx](dst, src, dst_size, index2, incr); c->dsp.resample_one[fn_idx](dst, src, dst_size, index2, incr);
index += dst_size * dst_incr; index += dst_size * c->dst_incr_div;
index += (frac + dst_size * (int64_t)dst_incr_frac) / c->src_incr; index += (frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr;
av_assert2(index >= 0); av_assert2(index >= 0);
*consumed= index; *consumed= index;
if (update_ctx) { if (update_ctx) {
c->frac = (frac + dst_size * (int64_t)dst_incr_frac) % c->src_incr; c->frac = (frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr;
c->index = 0; c->index = 0;
} }
} else { } else {
@ -323,8 +327,11 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
if (c->compensation_distance) { if (c->compensation_distance) {
c->compensation_distance -= ret; c->compensation_distance -= ret;
if (!c->compensation_distance) if (!c->compensation_distance) {
c->dst_incr = c->ideal_dst_incr / c->src_incr; c->dst_incr = c->ideal_dst_incr;
c->dst_incr_div = c->dst_incr / c->src_incr;
c->dst_incr_mod = c->dst_incr % c->src_incr;
}
} }
return ret; return ret;

@ -39,6 +39,8 @@ typedef struct ResampleContext {
int filter_alloc; int filter_alloc;
int ideal_dst_incr; int ideal_dst_incr;
int dst_incr; int dst_incr;
int dst_incr_div;
int dst_incr_mod;
int index; int index;
int frac; int frac;
int src_incr; int src_incr;

@ -126,8 +126,6 @@ int RENAME(swri_resample_common)(ResampleContext *c,
int dst_index; int dst_index;
int index= c->index; int index= c->index;
int frac= c->frac; int frac= c->frac;
int dst_incr_frac= c->dst_incr % c->src_incr;
int dst_incr= c->dst_incr / c->src_incr;
int sample_index = index >> c->phase_shift; int sample_index = index >> c->phase_shift;
index &= c->phase_mask; index &= c->phase_mask;
@ -145,8 +143,8 @@ int RENAME(swri_resample_common)(ResampleContext *c,
OUT(dst[dst_index], val); OUT(dst[dst_index], val);
#endif #endif
frac += dst_incr_frac; frac += c->dst_incr_mod;
index += dst_incr; index += c->dst_incr_div;
if (frac >= c->src_incr) { if (frac >= c->src_incr) {
frac -= c->src_incr; frac -= c->src_incr;
index++; index++;

Loading…
Cancel
Save