Skip to content

Commit

Permalink
various resampling fixes
Browse files Browse the repository at this point in the history
Originally committed as revision 3271 to svn://svn.ffmpeg.org/ffmpeg/trunk
  • Loading branch information
michaelni committed Jun 30, 2004
1 parent 2d48edd commit b9d2085
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libavcodec/resample.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
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;
Expand Down
12 changes: 7 additions & 5 deletions libavcodec/resample2.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate){
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;
Expand Down Expand Up @@ -170,7 +170,7 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int

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{
Expand Down Expand Up @@ -199,16 +199,18 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
index++;
}
}
*consumed= FFMAX(index, 0) >> PHASE_SHIFT;
index= FFMIN(index, 0);

if(update_ctx){
if(c->compensation_distance){
c->compensation_distance -= dst_index;
if(!c->compensation_distance)
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
Expand Down

0 comments on commit b9d2085

Please sign in to comment.