swresample/resample_template: Reorder operations to avoid one addition

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2016-12-10 01:54:13 +01:00
parent b3928a1cc6
commit 34db650784
1 changed files with 9 additions and 6 deletions

View File

@ -32,6 +32,7 @@
# define DELEM double
# define FELEM double
# define FELEM2 double
# define FOFFSET 0
# define OUT(d, v) d = v
#elif defined(TEMPLATE_RESAMPLE_FLT)
@ -41,6 +42,7 @@
# define DELEM float
# define FELEM float
# define FELEM2 float
# define FOFFSET 0
# define OUT(d, v) d = v
#elif defined(TEMPLATE_RESAMPLE_S32)
@ -52,8 +54,8 @@
# define FELEM2 int64_t
# define FELEM_MAX INT32_MAX
# define FELEM_MIN INT32_MIN
# define OUT(d, v) (v) = ((v) + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
(d) = av_clipl_int32(v)
# define FOFFSET (1<<(FILTER_SHIFT-1))
# define OUT(d, v) (d) = av_clipl_int32((v)>>FILTER_SHIFT)
#elif defined(TEMPLATE_RESAMPLE_S16)
@ -65,8 +67,8 @@
# define FELEML int64_t
# define FELEM_MAX INT16_MAX
# define FELEM_MIN INT16_MIN
# define OUT(d, v) (v) = ((v) + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
(d) = av_clip_int16(v)
# define FOFFSET (1<<(FILTER_SHIFT-1))
# define OUT(d, v) (d) = av_clip_int16((v)>>FILTER_SHIFT)
#endif
@ -102,7 +104,7 @@ static int RENAME(resample_common)(ResampleContext *c,
for (dst_index = 0; dst_index < n; dst_index++) {
FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
FELEM2 val=0;
FELEM2 val= FOFFSET;
int i;
for (i = 0; i < c->filter_length; i++) {
val += src[sample_index + i] * (FELEM2)filter[i];
@ -151,7 +153,7 @@ static int RENAME(resample_linear)(ResampleContext *c,
for (dst_index = 0; dst_index < n; dst_index++) {
FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
FELEM2 val=0, v2 = 0;
FELEM2 val = FOFFSET, v2 = FOFFSET;
int i;
for (i = 0; i < c->filter_length; i++) {
@ -199,3 +201,4 @@ static int RENAME(resample_linear)(ResampleContext *c,
#undef FELEM_MAX
#undef FELEM_MIN
#undef OUT
#undef FOFFSET