return 0;
}
-ResampleContext *swri_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){
+static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
+ double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta,
+ double precision, int cheby){
+ double cutoff = cutoff0? cutoff0 : 0.8;
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
int phase_count= 1<<phase_shift;
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;
#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;
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);
+}
+
+static int resample_flush(struct SwrContext *s) {
+ AudioData *a= &s->in_buffer;
+ int i, j, ret;
+ if((ret = swri_realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0)
+ return ret;
+ av_assert0(a->planar);
+ for(i=0; i<a->ch_count; i++){
+ for(j=0; j<s->in_buffer_count; j++){
+ memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j )*a->bps,
+ a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps, a->bps);
+ }
}
+ s->in_buffer_count += (s->in_buffer_count+1)/2;
+ return 0;
}
+
+struct Resampler const swri_resampler={
+ resample_init,
+ resample_free,
+ multiple_resample,
+ resample_flush,
+ set_compensation,
+ get_delay,
+};