[FFmpeg-cvslog] resample: split linear into its own function
Anton Khirnov
git at videolan.org
Fri Apr 11 21:07:04 CEST 2014
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Mar 4 17:12:33 2014 +0100| [254c95cdd1b669a722204a4a65974fc2523c8f83] | committer: Anton Khirnov
resample: split linear into its own function
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=254c95cdd1b669a722204a4a65974fc2523c8f83
---
libavresample/resample.c | 8 ++++----
libavresample/resample_template.c | 34 +++++++++++++++++++++++-----------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/libavresample/resample.c b/libavresample/resample.c
index c02bba4..2aa7141 100644
--- a/libavresample/resample.c
+++ b/libavresample/resample.c
@@ -181,22 +181,22 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr)
switch (avr->internal_sample_fmt) {
case AV_SAMPLE_FMT_DBLP:
- c->resample_one = resample_one_dbl;
+ c->resample_one = c->linear ? resample_linear_dbl : resample_one_dbl;
c->resample_nearest = resample_nearest_dbl;
c->set_filter = set_filter_dbl;
break;
case AV_SAMPLE_FMT_FLTP:
- c->resample_one = resample_one_flt;
+ c->resample_one = c->linear ? resample_linear_flt : resample_one_flt;
c->resample_nearest = resample_nearest_flt;
c->set_filter = set_filter_flt;
break;
case AV_SAMPLE_FMT_S32P:
- c->resample_one = resample_one_s32;
+ c->resample_one = c->linear ? resample_linear_s32 : resample_one_s32;
c->resample_nearest = resample_nearest_s32;
c->set_filter = set_filter_s32;
break;
case AV_SAMPLE_FMT_S16P:
- c->resample_one = resample_one_s16;
+ c->resample_one = c->linear ? resample_linear_s16 : resample_one_s16;
c->resample_nearest = resample_nearest_s16;
c->set_filter = set_filter_s16;
break;
diff --git a/libavresample/resample_template.c b/libavresample/resample_template.c
index 661dd0d..d8ddcc9 100644
--- a/libavresample/resample_template.c
+++ b/libavresample/resample_template.c
@@ -61,6 +61,27 @@ static void SET_TYPE(resample_nearest)(void *dst0, int dst_index, const void *sr
dst[dst_index] = src[index];
}
+static void SET_TYPE(resample_linear)(ResampleContext *c, void *dst0, int dst_index,
+ const void *src0, unsigned int index, int frac)
+{
+ FELEM *dst = dst0;
+ const FELEM *src = src0;
+ int i;
+ unsigned int sample_index = index >> c->phase_shift;
+ FELEM2 val = 0;
+ FELEM *filter = ((FELEM *)c->filter_bank) +
+ c->filter_length * (index & c->phase_mask);
+ FELEM2 v2 = 0;
+
+ for (i = 0; i < c->filter_length; i++) {
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
+ }
+ val += (v2 - val) * (FELEML)frac / c->src_incr;
+
+ OUT(dst[dst_index], val);
+}
+
static void SET_TYPE(resample_one)(ResampleContext *c,
void *dst0, int dst_index, const void *src0,
unsigned int index, int frac)
@@ -73,17 +94,8 @@ static void SET_TYPE(resample_one)(ResampleContext *c,
FELEM *filter = ((FELEM *)c->filter_bank) +
c->filter_length * (index & c->phase_mask);
- if (c->linear) {
- FELEM2 v2 = 0;
- for (i = 0; i < c->filter_length; i++) {
- val += src[sample_index + i] * (FELEM2)filter[i];
- v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
- }
- val += (v2 - val) * (FELEML)frac / c->src_incr;
- } else {
- for (i = 0; i < c->filter_length; i++)
- val += src[sample_index + i] * (FELEM2)filter[i];
- }
+ for (i = 0; i < c->filter_length; i++)
+ val += src[sample_index + i] * (FELEM2)filter[i];
OUT(dst[dst_index], val);
}
More information about the ffmpeg-cvslog
mailing list