summaryrefslogtreecommitdiff
path: root/libswresample/resample.c
diff options
context:
space:
mode:
authorRob Sykes <aquegg@yahoo.co.uk>2012-12-11 18:36:58 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-12-11 22:04:00 +0100
commit5a5d70748c5d606b055fedce30a84e31790d6d15 (patch)
tree4996c759f4f30c590611424f3f0a547fa09ff35a /libswresample/resample.c
parente8e575633faf19711910cf9caf59f7db300a9ccd (diff)
downloadffmpeg-5a5d70748c5d606b055fedce30a84e31790d6d15.tar.gz
swr: Add API to make resample engine selectable.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/resample.c')
-rw-r--r--libswresample/resample.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 2096e43db6..f3881cdd57 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -195,7 +195,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
return 0;
}
-ResampleContext *swri_resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
+static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta){
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
int phase_count= 1<<phase_shift;
@@ -259,28 +259,14 @@ error:
return NULL;
}
-void swri_resample_free(ResampleContext **c){
+static void resample_free(ResampleContext **c){
if(!*c)
return;
av_freep(&(*c)->filter_bank);
av_freep(c);
}
-int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance){
- ResampleContext *c;
- int ret;
-
- if (!s || compensation_distance < 0)
- return AVERROR(EINVAL);
- if (!compensation_distance && sample_delta)
- return AVERROR(EINVAL);
- if (!s->resample) {
- s->flags |= SWR_FLAG_RESAMPLE;
- ret = swr_init(s);
- if (ret < 0)
- return ret;
- }
- c= s->resample;
+static int set_compensation(ResampleContext *c, int sample_delta, int compensation_distance){
c->compensation_distance= compensation_distance;
if (compensation_distance)
c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
@@ -322,7 +308,7 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
#endif // HAVE_MMXEXT_INLINE
-int swri_multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){
+static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){
int i, ret= -1;
int av_unused mm_flags = av_get_cpu_flags();
int need_emms= 0;
@@ -348,17 +334,20 @@ int swri_multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, Aud
return ret;
}
-int64_t swr_get_delay(struct SwrContext *s, int64_t base){
+static int64_t get_delay(struct SwrContext *s, int64_t base){
ResampleContext *c = s->resample;
- if(c){
- int64_t num = s->in_buffer_count - (c->filter_length-1)/2;
- num <<= c->phase_shift;
- num -= c->index;
- num *= c->src_incr;
- num -= c->frac;
-
- return av_rescale(num, base, s->in_sample_rate*(int64_t)c->src_incr << c->phase_shift);
- }else{
- return (s->in_buffer_count*base + (s->in_sample_rate>>1))/ s->in_sample_rate;
- }
+ int64_t num = s->in_buffer_count - (c->filter_length-1)/2;
+ num <<= c->phase_shift;
+ num -= c->index;
+ num *= c->src_incr;
+ num -= c->frac;
+ return av_rescale(num, base, s->in_sample_rate*(int64_t)c->src_incr << c->phase_shift);
}
+
+struct Resampler const swri_resampler={
+ resample_init,
+ resample_free,
+ multiple_resample,
+ set_compensation,
+ get_delay,
+};