summaryrefslogtreecommitdiff
path: root/libswresample/resample.c
diff options
context:
space:
mode:
Diffstat (limited to 'libswresample/resample.c')
-rw-r--r--libswresample/resample.c149
1 files changed, 49 insertions, 100 deletions
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 5b7a0f9f23..9a67e6340c 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -25,32 +25,8 @@
* @author Michael Niedermayer <michaelni@gmx.at>
*/
-#include "libavutil/log.h"
#include "libavutil/avassert.h"
-#include "swresample_internal.h"
-
-
-typedef struct ResampleContext {
- const AVClass *av_class;
- uint8_t *filter_bank;
- int filter_length;
- int filter_alloc;
- int ideal_dst_incr;
- int dst_incr;
- int index;
- int frac;
- int src_incr;
- int compensation_distance;
- int phase_shift;
- int phase_mask;
- int linear;
- enum SwrFilterType filter_type;
- int kaiser_beta;
- double factor;
- enum AVSampleFormat format;
- int felem_size;
- int filter_shift;
-} ResampleContext;
+#include "resample.h"
/**
* 0th order modified bessel function of the first kind.
@@ -197,7 +173,8 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
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 precision, int cheby)
+{
double cutoff = cutoff0? cutoff0 : 0.97;
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
int phase_count= 1<<phase_shift;
@@ -259,6 +236,8 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r
c->index= -phase_count*((c->filter_length-1)/2);
c->frac= 0;
+ swresample_dsp_init(c);
+
return c;
error:
av_freep(&c->filter_bank);
@@ -282,59 +261,53 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati
return 0;
}
-#define TEMPLATE_RESAMPLE_S16
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_S16
-
-#define TEMPLATE_RESAMPLE_S32
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_S32
-
-#define TEMPLATE_RESAMPLE_FLT
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_FLT
-
-#define TEMPLATE_RESAMPLE_DBL
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_DBL
-
-// XXX FIXME the whole C loop should be written in asm so this x86 specific code here isnt needed
-#if HAVE_MMXEXT_INLINE
-
-#include "x86/resample_mmx.h"
-
-#define TEMPLATE_RESAMPLE_S16_MMX2
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_S16_MMX2
-
-#if HAVE_SSE_INLINE
-#define TEMPLATE_RESAMPLE_FLT_SSE
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_FLT_SSE
-#endif
-
-#if HAVE_SSE2_INLINE
-#define TEMPLATE_RESAMPLE_S16_SSE2
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_S16_SSE2
-
-#define TEMPLATE_RESAMPLE_DBL_SSE2
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_DBL_SSE2
-#endif
-
-#if HAVE_AVX_INLINE
-#define TEMPLATE_RESAMPLE_FLT_AVX
-#include "resample_template.c"
-#undef TEMPLATE_RESAMPLE_FLT_AVX
-#endif
+static int swri_resample(ResampleContext *c,
+ uint8_t *dst, const uint8_t *src, int *consumed,
+ int src_size, int dst_size, int update_ctx)
+{
+ int fn_idx = c->format - AV_SAMPLE_FMT_S16P;
+
+ if (c->filter_length == 1 && c->phase_shift == 0) {
+ int index= c->index;
+ int frac= c->frac;
+ int dst_incr_frac= c->dst_incr % c->src_incr;
+ int dst_incr= c->dst_incr / c->src_incr;
+ int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*index;
+ int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
+ int new_size = (src_size * (int64_t)c->src_incr - frac + c->dst_incr - 1) / c->dst_incr;
+
+ dst_size= FFMIN(dst_size, new_size);
+ c->dsp.resample_one[fn_idx](dst, src, dst_size, index2, incr);
+
+ index += dst_size * dst_incr;
+ index += (frac + dst_size * (int64_t)dst_incr_frac) / c->src_incr;
+ av_assert2(index >= 0);
+ *consumed= index;
+ if (update_ctx) {
+ c->frac = (frac + dst_size * (int64_t)dst_incr_frac) % c->src_incr;
+ c->index = 0;
+ }
+ } else {
+ int64_t end_index = (1LL + src_size - c->filter_length) << c->phase_shift;
+ int64_t delta_frac = (end_index - c->index) * c->src_incr - c->frac;
+ int delta_n = (delta_frac + c->dst_incr - 1) / c->dst_incr;
+
+ dst_size = FFMIN(dst_size, delta_n);
+ if (!c->linear) {
+ *consumed = c->dsp.resample_common[fn_idx](c, dst, src, dst_size, update_ctx);
+ } else {
+ *consumed = c->dsp.resample_linear[fn_idx](c, dst, src, dst_size, update_ctx);
+ }
+ }
-#endif // HAVE_MMXEXT_INLINE
+ return dst_size;
+}
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;
+ int need_emms = c->format == AV_SAMPLE_FMT_S16P && ARCH_X86_32 &&
+ (mm_flags & (AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE2)) == AV_CPU_FLAG_MMX2;
int64_t max_src_size = (INT64_MAX >> (c->phase_shift+1)) / c->src_incr;
if (c->compensation_distance)
@@ -342,32 +315,8 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
src_size = FFMIN(src_size, max_src_size);
for(i=0; i<dst->ch_count; i++){
-#if HAVE_MMXEXT_INLINE
-#if HAVE_SSE2_INLINE
- if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_SSE2)) ret= swri_resample_int16_sse2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
- else
-#endif
- if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_MMX2 )){
- ret= swri_resample_int16_mmx2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
- need_emms= 1;
- } else
-#endif
- if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
- else if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-#if HAVE_AVX_INLINE
- else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_AVX))
- ret= swri_resample_float_avx (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-#endif
-#if HAVE_SSE_INLINE
- else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_SSE))
- ret= swri_resample_float_sse (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-#endif
- else if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-#if HAVE_SSE2_INLINE
- else if(c->format == AV_SAMPLE_FMT_DBLP && (mm_flags&AV_CPU_FLAG_SSE2))
- ret= swri_resample_double_sse2(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-#endif
- else if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+ ret= swri_resample(c, dst->ch[i], src->ch[i],
+ consumed, src_size, dst_size, i+1==dst->ch_count);
}
if(need_emms)
emms_c();