28 #if defined(TEMPLATE_RESAMPLE_DBL)
29 # define RENAME(N) N ## _double
30 # define FILTER_SHIFT 0
33 # define FELEM2 double
34 # define FELEML double
35 # define OUT(d, v) d = v
37 #elif defined(TEMPLATE_RESAMPLE_FLT)
38 # define RENAME(N) N ## _float
39 # define FILTER_SHIFT 0
44 # define OUT(d, v) d = v
46 #elif defined(TEMPLATE_RESAMPLE_S32)
47 # define RENAME(N) N ## _int32
48 # define FILTER_SHIFT 30
49 # define DELEM int32_t
50 # define FELEM int32_t
51 # define FELEM2 int64_t
52 # define FELEML int64_t
53 # define FELEM_MAX INT32_MAX
54 # define FELEM_MIN INT32_MIN
55 # define OUT(d, v) v = (v + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
56 d = (uint64_t)(v + 0x80000000) > 0xFFFFFFFF ? (v>>63) ^ 0x7FFFFFFF : v
58 #elif defined(TEMPLATE_RESAMPLE_S16) \
59 || defined(TEMPLATE_RESAMPLE_S16_MMX2) \
60 || defined(TEMPLATE_RESAMPLE_S16_SSSE3)
62 # define FILTER_SHIFT 15
63 # define DELEM int16_t
64 # define FELEM int16_t
65 # define FELEM2 int32_t
66 # define FELEML int64_t
67 # define FELEM_MAX INT16_MAX
68 # define FELEM_MIN INT16_MIN
69 # define OUT(d, v) v = (v + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
70 d = (unsigned)(v + 32768) > 65535 ? (v>>31) ^ 32767 : v
72 # if defined(TEMPLATE_RESAMPLE_S16)
73 # define RENAME(N) N ## _int16
74 # elif defined(TEMPLATE_RESAMPLE_S16_MMX2)
75 # define COMMON_CORE COMMON_CORE_INT16_MMX2
76 # define RENAME(N) N ## _int16_mmx2
77 # elif defined(TEMPLATE_RESAMPLE_S16_SSSE3)
78 # define COMMON_CORE COMMON_CORE_INT16_SSSE3
79 # define RENAME(N) N ## _int16_ssse3
84 int RENAME(swri_resample)(
ResampleContext *
c, DELEM *
dst,
const DELEM *src,
int *consumed,
int src_size,
int dst_size,
int update_ctx){
88 int dst_incr_frac=
c->dst_incr %
c->src_incr;
89 int dst_incr=
c->dst_incr /
c->src_incr;
90 int compensation_distance=
c->compensation_distance;
95 if(compensation_distance == 0 &&
c->filter_length == 1 &&
c->phase_shift==0){
96 int64_t index2= ((int64_t)index)<<32;
97 int64_t incr= (1LL<<32) *
c->dst_incr /
c->src_incr;
98 dst_size=
FFMIN(dst_size, (src_size-1-index) * (int64_t)
c->src_incr /
c->dst_incr);
100 for(dst_index=0; dst_index < dst_size; dst_index++){
101 dst[dst_index] = src[index2>>32];
104 index += dst_index * dst_incr;
105 index += (frac + dst_index * (int64_t)dst_incr_frac) /
c->src_incr;
106 frac = (frac + dst_index * (int64_t)dst_incr_frac) %
c->src_incr;
108 *consumed= index >>
c->phase_shift;
109 index &=
c->phase_mask;
110 }
else if(compensation_distance == 0 && !
c->linear && index >= 0){
111 int sample_index = 0;
112 for(dst_index=0; dst_index < dst_size; dst_index++){
114 sample_index += index >>
c->phase_shift;
115 index &=
c->phase_mask;
116 filter= ((
FELEM*)
c->filter_bank) +
c->filter_alloc*
index;
118 if(sample_index +
c->filter_length > src_size){
125 for(i=0; i<
c->filter_length; i++){
126 val += src[sample_index + i] * (
FELEM2)filter[i];
132 frac += dst_incr_frac;
134 if(frac >=
c->src_incr){
139 *consumed = sample_index;
141 int sample_index = 0;
142 for(dst_index=0; dst_index < dst_size; dst_index++){
146 sample_index += index >>
c->phase_shift;
147 index &=
c->phase_mask;
148 filter = ((
FELEM*)
c->filter_bank) +
c->filter_alloc*
index;
150 if(sample_index +
c->filter_length > src_size || -sample_index >= src_size){
152 }
else if(sample_index < 0){
153 for(i=0; i<
c->filter_length; i++)
154 val += src[
FFABS(sample_index + i)] * (
FELEM2)filter[i];
157 for(i=0; i<
c->filter_length; i++){
158 val += src[sample_index + i] * (
FELEM2)filter[i];
159 v2 += src[sample_index + i] * (
FELEM2)filter[i +
c->filter_alloc];
161 val+=(v2-val)*(
FELEML)frac /
c->src_incr;
163 for(i=0; i<
c->filter_length; i++){
164 val += src[sample_index + i] * (
FELEM2)filter[i];
170 frac += dst_incr_frac;
172 if(frac >=
c->src_incr){
177 if(dst_index + 1 == compensation_distance){
178 compensation_distance= 0;
179 dst_incr_frac=
c->ideal_dst_incr %
c->src_incr;
180 dst_incr=
c->ideal_dst_incr /
c->src_incr;
183 *consumed=
FFMAX(sample_index, 0);
184 index +=
FFMIN(sample_index, 0) <<
c->phase_shift;
186 if(compensation_distance){
187 compensation_distance -= dst_index;
195 c->dst_incr= dst_incr_frac +
c->src_incr*dst_incr;
196 c->compensation_distance= compensation_distance;