changeset 2109:84637c6ca74e libavcodec

various resampling fixes
author michael
date Wed, 30 Jun 2004 14:15:31 +0000
parents ce669c39e3d5
children 96b05a70a154
files resample.c resample2.c
diffstat 2 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/resample.c	Wed Jun 30 14:10:17 2004 +0000
+++ b/resample.c	Wed Jun 30 14:15:31 2004 +0000
@@ -175,7 +175,7 @@
     short *buftmp2[2], *buftmp3[2];
     int lenout;
 
-    if (s->input_channels == s->output_channels && s->ratio == 1.0) {
+    if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
         /* nothing to do */
         memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
         return nb_samples;
--- a/resample2.c	Wed Jun 30 14:10:17 2004 +0000
+++ b/resample2.c	Wed Jun 30 14:15:31 2004 +0000
@@ -123,8 +123,8 @@
     c->filter_length= ceil(16.0/factor);
     c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(short));
     av_build_filter(c->filter_bank, factor, c->filter_length, PHASE_COUNT, 1<<FILTER_SHIFT, 1);
-    c->filter_bank[c->filter_length*PHASE_COUNT + (c->filter_length-1) + 1]= (1<<FILTER_SHIFT)-1;
-    c->filter_bank[c->filter_length*PHASE_COUNT + (c->filter_length-1) + 2]= 1;
+    c->filter_bank[c->filter_length*PHASE_COUNT + (c->filter_length-1)/2 + 1]= (1<<FILTER_SHIFT)-1;
+    c->filter_bank[c->filter_length*PHASE_COUNT + (c->filter_length-1)/2 + 2]= 1;
 
     c->src_incr= out_rate;
     c->ideal_dst_incr= c->dst_incr= in_rate * PHASE_COUNT;
@@ -170,7 +170,7 @@
         
         if(sample_index < 0){
             for(i=0; i<c->filter_length; i++)
-                val += src[ABS(sample_index + i)] * filter[i];
+                val += src[ABS(sample_index + i) % src_size] * filter[i];
         }else if(sample_index + c->filter_length > src_size){
             break;
         }else{
@@ -199,6 +199,9 @@
             index++;
         }
     }
+    *consumed= FFMAX(index, 0) >> PHASE_SHIFT;
+    index= FFMIN(index, 0);
+
     if(update_ctx){
         if(c->compensation_distance){
             c->compensation_distance -= dst_index;
@@ -206,9 +209,8 @@
                 c->dst_incr= c->ideal_dst_incr;
         }
         c->frac= frac;
-        c->index=0;
+        c->index= index;
     }
-    *consumed= index >> PHASE_SHIFT;
 #if 0    
     if(update_ctx && !c->compensation_distance){
 #undef rand