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{
00052 for(dst_index=0; dst_index < dst_size; dst_index++){
00053 FELEM *filter= ((FELEM*)c->filter_bank) + c->filter_length*(index & c->phase_mask);
00054 int sample_index= index >> c->phase_shift;
00055 FELEM2 val=0;
00056
00057 if(sample_index + c->filter_length > src_size || -sample_index >= src_size){
00058 break;
00059 }else if(sample_index < 0){
00060 for(i=0; i<c->filter_length; i++)
00061 val += src[FFABS(sample_index + i)] * filter[i];
00062 }else if(c->linear){
00063 FELEM2 v2=0;
00064 for(i=0; i<c->filter_length; i++){
00065 val += src[sample_index + i] * (FELEM2)filter[i];
00066 v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
00067 }
00068 val+=(v2-val)*(FELEML)frac / c->src_incr;
00069 }else{
00070 for(i=0; i<c->filter_length; i++){
00071 val += src[sample_index + i] * (FELEM2)filter[i];
00072 }
00073 }
00074
00075 OUT(dst[dst_index], val);
00076
00077 frac += dst_incr_frac;
00078 index += dst_incr;
00079 if(frac >= c->src_incr){
00080 frac -= c->src_incr;
00081 index++;
00082 }
00083
00084 if(dst_index + 1 == compensation_distance){
00085 compensation_distance= 0;
00086 dst_incr_frac= c->ideal_dst_incr % c->src_incr;
00087 dst_incr= c->ideal_dst_incr / c->src_incr;
00088 }
00089 }
00090 }
00091 *consumed= FFMAX(index, 0) >> c->phase_shift;
00092 if(index>=0) index &= c->phase_mask;
00093
00094 if(compensation_distance){
00095 compensation_distance -= dst_index;
00096 assert(compensation_distance > 0);
00097 }
00098 if(update_ctx){
00099 c->frac= frac;
00100 c->index= index;
00101 c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
00102 c->compensation_distance= compensation_distance;
00103 }
00104 #if 0
00105 if(update_ctx && !c->compensation_distance){
00106 #undef rand
00107 av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
00108 av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
00109 }
00110 #endif
00111
00112 return dst_index;
00113 }