00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 int RENAME(swri_resample)(ResampleContext *c, DELEM *dst, const DELEM *src, int *consumed, int src_size, int dst_size, int update_ctx){
00029 int dst_index, i;
00030 int index= c->index;
00031 int frac= c->frac;
00032 int dst_incr_frac= c->dst_incr % c->src_incr;
00033 int dst_incr= c->dst_incr / c->src_incr;
00034 int compensation_distance= c->compensation_distance;
00035
00036 av_assert1(c->filter_shift == FILTER_SHIFT);
00037 av_assert1(c->felem_size == sizeof(FELEM));
00038
00039 if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){
00040 int64_t index2= ((int64_t)index)<<32;
00041 int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
00042 dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr);
00043
00044 for(dst_index=0; dst_index < dst_size; dst_index++){
00045 dst[dst_index] = src[index2>>32];
00046 index2 += incr;
00047 }
00048 index += dst_index * dst_incr;
00049 index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr;
00050 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
00051 }else if(compensation_distance == 0 && !c->linear && index >= 0){
00052 for(dst_index=0; dst_index < dst_size; dst_index++){
00053 FELEM *filter= ((FELEM*)c->filter_bank) + c->filter_alloc*(index & c->phase_mask);
00054 int sample_index= index >> c->phase_shift;
00055
00056 if(sample_index + c->filter_length > src_size){
00057 break;
00058 }else{
00059 #ifdef COMMON_CORE
00060 COMMON_CORE
00061 #else
00062 FELEM2 val=0;
00063 for(i=0; i<c->filter_length; i++){
00064 val += src[sample_index + i] * (FELEM2)filter[i];
00065 }
00066 OUT(dst[dst_index], val);
00067 #endif
00068 }
00069
00070 frac += dst_incr_frac;
00071 index += dst_incr;
00072 if(frac >= c->src_incr){
00073 frac -= c->src_incr;
00074 index++;
00075 }
00076 }
00077 }else{
00078 for(dst_index=0; dst_index < dst_size; dst_index++){
00079 FELEM *filter= ((FELEM*)c->filter_bank) + c->filter_alloc*(index & c->phase_mask);
00080 int sample_index= index >> c->phase_shift;
00081 FELEM2 val=0;
00082
00083 if(sample_index + c->filter_length > src_size || -sample_index >= src_size){
00084 break;
00085 }else if(sample_index < 0){
00086 for(i=0; i<c->filter_length; i++)
00087 val += src[FFABS(sample_index + i)] * filter[i];
00088 }else if(c->linear){
00089 FELEM2 v2=0;
00090 for(i=0; i<c->filter_length; i++){
00091 val += src[sample_index + i] * (FELEM2)filter[i];
00092 v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_alloc];
00093 }
00094 val+=(v2-val)*(FELEML)frac / c->src_incr;
00095 }else{
00096 for(i=0; i<c->filter_length; i++){
00097 val += src[sample_index + i] * (FELEM2)filter[i];
00098 }
00099 }
00100
00101 OUT(dst[dst_index], val);
00102
00103 frac += dst_incr_frac;
00104 index += dst_incr;
00105 if(frac >= c->src_incr){
00106 frac -= c->src_incr;
00107 index++;
00108 }
00109
00110 if(dst_index + 1 == compensation_distance){
00111 compensation_distance= 0;
00112 dst_incr_frac= c->ideal_dst_incr % c->src_incr;
00113 dst_incr= c->ideal_dst_incr / c->src_incr;
00114 }
00115 }
00116 }
00117 *consumed= FFMAX(index, 0) >> c->phase_shift;
00118 if(index>=0) index &= c->phase_mask;
00119
00120 if(compensation_distance){
00121 compensation_distance -= dst_index;
00122 av_assert1(compensation_distance > 0);
00123 }
00124 if(update_ctx){
00125 c->frac= frac;
00126 c->index= index;
00127 c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
00128 c->compensation_distance= compensation_distance;
00129 }
00130 #if 0
00131 if(update_ctx && !c->compensation_distance){
00132 #undef rand
00133 av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
00134 av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
00135 }
00136 #endif
00137
00138 return dst_index;
00139 }