00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if defined(CONFIG_RESAMPLE_DBL)
00022 #define SET_TYPE(func) func ## _dbl
00023 #define FELEM double
00024 #define FELEM2 double
00025 #define FELEML double
00026 #define OUT(d, v) d = v
00027 #define DBL_TO_FELEM(d, v) d = v
00028 #elif defined(CONFIG_RESAMPLE_FLT)
00029 #define SET_TYPE(func) func ## _flt
00030 #define FELEM float
00031 #define FELEM2 float
00032 #define FELEML float
00033 #define OUT(d, v) d = v
00034 #define DBL_TO_FELEM(d, v) d = v
00035 #elif defined(CONFIG_RESAMPLE_S32)
00036 #define SET_TYPE(func) func ## _s32
00037 #define FELEM int32_t
00038 #define FELEM2 int64_t
00039 #define FELEML int64_t
00040 #define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
00041 #define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
00042 #else
00043 #define SET_TYPE(func) func ## _s16
00044 #define FELEM int16_t
00045 #define FELEM2 int32_t
00046 #define FELEML int64_t
00047 #define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
00048 #define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
00049 #endif
00050
00051 static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
00052 void *dst0, int dst_index, const void *src0,
00053 int src_size, int index, int frac)
00054 {
00055 FELEM *dst = dst0;
00056 const FELEM *src = src0;
00057
00058 if (no_filter) {
00059 dst[dst_index] = src[index];
00060 } else {
00061 int i;
00062 int sample_index = index >> c->phase_shift;
00063 FELEM2 val = 0;
00064 FELEM *filter = ((FELEM *)c->filter_bank) +
00065 c->filter_length * (index & c->phase_mask);
00066
00067 if (sample_index < 0) {
00068 for (i = 0; i < c->filter_length; i++)
00069 val += src[FFABS(sample_index + i) % src_size] *
00070 (FELEM2)filter[i];
00071 } else if (c->linear) {
00072 FELEM2 v2 = 0;
00073 for (i = 0; i < c->filter_length; i++) {
00074 val += src[abs(sample_index + i)] * (FELEM2)filter[i];
00075 v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
00076 }
00077 val += (v2 - val) * (FELEML)frac / c->src_incr;
00078 } else {
00079 for (i = 0; i < c->filter_length; i++)
00080 val += src[sample_index + i] * (FELEM2)filter[i];
00081 }
00082
00083 OUT(dst[dst_index], val);
00084 }
00085 }
00086
00087 static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
00088 int tap_count)
00089 {
00090 int i;
00091 FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
00092 for (i = 0; i < tap_count; i++) {
00093 DBL_TO_FELEM(filter[i], tab[i]);
00094 }
00095 }
00096
00097 #undef SET_TYPE
00098 #undef FELEM
00099 #undef FELEM2
00100 #undef FELEML
00101 #undef OUT
00102 #undef DBL_TO_FELEM