mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
make most resample filter parameters selectable at runtime
Originally committed as revision 3617 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
f25ba8b393
commit
ed861c6bd2
@ -17,7 +17,7 @@ extern "C" {
|
||||
|
||||
#define FFMPEG_VERSION_INT 0x000409
|
||||
#define FFMPEG_VERSION "0.4.9-pre1"
|
||||
#define LIBAVCODEC_BUILD 4725
|
||||
#define LIBAVCODEC_BUILD 4726
|
||||
|
||||
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
|
||||
#define LIBAVCODEC_VERSION FFMPEG_VERSION
|
||||
@ -1942,7 +1942,7 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels,
|
||||
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
|
||||
void audio_resample_close(ReSampleContext *s);
|
||||
|
||||
struct AVResampleContext *av_resample_init(int out_rate, int in_rate);
|
||||
struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear);
|
||||
int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
|
||||
void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
|
||||
void av_resample_close(struct AVResampleContext *c);
|
||||
|
@ -160,7 +160,7 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels,
|
||||
if(s->filter_channels>2)
|
||||
s->filter_channels = 2;
|
||||
|
||||
s->resample_context= av_resample_init(output_rate, input_rate);
|
||||
s->resample_context= av_resample_init(output_rate, input_rate, 16, 10, 0);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -28,12 +28,6 @@
|
||||
#include "common.h"
|
||||
#include "dsputil.h"
|
||||
|
||||
#define PHASE_SHIFT 10
|
||||
#define PHASE_COUNT (1<<PHASE_SHIFT)
|
||||
#define PHASE_MASK (PHASE_COUNT-1)
|
||||
#define FILTER_SIZE 16
|
||||
//#define LINEAR 1
|
||||
|
||||
#if 1
|
||||
#define FILTER_SHIFT 15
|
||||
|
||||
@ -60,6 +54,9 @@ typedef struct AVResampleContext{
|
||||
int frac;
|
||||
int src_incr;
|
||||
int compensation_distance;
|
||||
int phase_shift;
|
||||
int phase_mask;
|
||||
int linear;
|
||||
}AVResampleContext;
|
||||
|
||||
/**
|
||||
@ -133,21 +130,26 @@ void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_coun
|
||||
* initalizes a audio resampler.
|
||||
* note, if either rate is not a integer then simply scale both rates up so they are
|
||||
*/
|
||||
AVResampleContext *av_resample_init(int out_rate, int in_rate){
|
||||
AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear){
|
||||
AVResampleContext *c= av_mallocz(sizeof(AVResampleContext));
|
||||
double factor= FFMIN(out_rate / (double)in_rate, 1.0);
|
||||
|
||||
int phase_count= 1<<phase_shift;
|
||||
|
||||
memset(c, 0, sizeof(AVResampleContext));
|
||||
|
||||
c->phase_shift= phase_shift;
|
||||
c->phase_mask= phase_count-1;
|
||||
c->linear= linear;
|
||||
|
||||
c->filter_length= ceil(FILTER_SIZE/factor);
|
||||
c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(FELEM));
|
||||
av_build_filter(c->filter_bank, factor, c->filter_length, PHASE_COUNT, 1<<FILTER_SHIFT, 1);
|
||||
memcpy(&c->filter_bank[c->filter_length*PHASE_COUNT+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
|
||||
c->filter_bank[c->filter_length*PHASE_COUNT]= c->filter_bank[c->filter_length - 1];
|
||||
c->filter_length= ceil(filter_size/factor);
|
||||
c->filter_bank= av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM));
|
||||
av_build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<<FILTER_SHIFT, 1);
|
||||
memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
|
||||
c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
|
||||
|
||||
c->src_incr= out_rate;
|
||||
c->ideal_dst_incr= c->dst_incr= in_rate * PHASE_COUNT;
|
||||
c->index= -PHASE_COUNT*((c->filter_length-1)/2);
|
||||
c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
|
||||
c->index= -phase_count*((c->filter_length-1)/2);
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -181,8 +183,8 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
|
||||
int compensation_distance= c->compensation_distance;
|
||||
|
||||
for(dst_index=0; dst_index < dst_size; dst_index++){
|
||||
FELEM *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK);
|
||||
int sample_index= index >> PHASE_SHIFT;
|
||||
FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
|
||||
int sample_index= index >> c->phase_shift;
|
||||
FELEM2 val=0;
|
||||
|
||||
if(sample_index < 0){
|
||||
@ -190,8 +192,7 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
|
||||
val += src[ABS(sample_index + i) % src_size] * filter[i];
|
||||
}else if(sample_index + c->filter_length > src_size){
|
||||
break;
|
||||
}else{
|
||||
#ifdef LINEAR
|
||||
}else if(c->linear){
|
||||
int64_t v=0;
|
||||
int sub_phase= (frac<<8) / c->src_incr;
|
||||
for(i=0; i<c->filter_length; i++){
|
||||
@ -199,11 +200,10 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
|
||||
v += src[sample_index + i] * coeff;
|
||||
}
|
||||
val= v>>8;
|
||||
#else
|
||||
}else{
|
||||
for(i=0; i<c->filter_length; i++){
|
||||
val += src[sample_index + i] * (FELEM2)filter[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
|
||||
@ -222,7 +222,7 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
|
||||
dst_incr= c->ideal_dst_incr / c->src_incr;
|
||||
}
|
||||
}
|
||||
*consumed= FFMAX(index, 0) >> PHASE_SHIFT;
|
||||
*consumed= FFMAX(index, 0) >> c->phase_shift;
|
||||
index= FFMIN(index, 0);
|
||||
|
||||
if(compensation_distance){
|
||||
|
Loading…
Reference in New Issue
Block a user