From aab5a4521c4034c218cbd72325b5d1946a3ec3c2 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 1 May 2012 20:20:21 +0200 Subject: [PATCH] swr: add and use function pointers for rematrix Signed-off-by: Michael Niedermayer --- libswresample/rematrix.c | 31 ++++++++++++----------------- libswresample/rematrix_template.c | 17 ++++++++-------- libswresample/swresample.c | 5 +++-- libswresample/swresample_internal.h | 6 +++++- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 329bd66381..27c4e1b2dc 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -268,6 +268,8 @@ int swri_rematrix_init(SwrContext *s){ for (j = 0; j < nb_in; j++) ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768); *((int*)s->native_one) = 32768; + s->mix_1_1_f = copy_s16; + s->mix_2_1_f = sum2_s16; }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){ s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(float)); s->native_one = av_mallocz(sizeof(float)); @@ -275,6 +277,8 @@ int swri_rematrix_init(SwrContext *s){ for (j = 0; j < nb_in; j++) ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j]; *((float*)s->native_one) = 1.0; + s->mix_1_1_f = copy_float; + s->mix_2_1_f = sum2_float; }else av_assert0(0); //FIXME quantize for integeres @@ -290,15 +294,6 @@ int swri_rematrix_init(SwrContext *s){ return 0; } -void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len){ - if(format == AV_SAMPLE_FMT_FLTP){ - sum2_float((float *)dst, (const float *)src0, (const float *)src1, coef0, coef1, len); - }else{ - av_assert1(format == AV_SAMPLE_FMT_S16P); - sum2_s16 ((int16_t*)dst, (const int16_t*)src0, (const int16_t*)src1, lrintf(coef0 * 32768), lrintf(coef1 * 32768), len); - } -} - void swri_rematrix_free(SwrContext *s){ av_freep(&s->native_matrix); av_freep(&s->native_one); @@ -317,19 +312,19 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus break; case 1: in_i= s->matrix_ch[out_i][1]; - if(mustcopy || s->matrix[out_i][in_i]!=1.0){ - if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){ - copy_float((float *)out->ch[out_i], (const float *)in->ch[in_i], s->matrix [out_i][in_i], len); - }else - copy_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix32[out_i][in_i], len); + if(s->matrix[out_i][in_i]!=1.0){ + s->mix_1_1_f(out->ch[out_i], in->ch[in_i], s->native_matrix, in->ch_count*out_i + in_i, len); + }else if(mustcopy){ + memcpy(out->ch[out_i], in->ch[in_i], len*out->bps); }else{ out->ch[out_i]= in->ch[in_i]; } break; - case 2: - swri_sum2(s->int_sample_fmt, out->ch[out_i], in->ch[ s->matrix_ch[out_i][1] ], in->ch[ s->matrix_ch[out_i][2] ], - s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ], len); - break; + case 2: { + int in_i1 = s->matrix_ch[out_i][1]; + int in_i2 = s->matrix_ch[out_i][2]; + s->mix_2_1_f(out->ch[out_i], in->ch[in_i1], in->ch[in_i2], s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len); + break;} default: if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){ for(i=0; iout.ch_count); s->dither = s->preout; - if(s->rematrix) + if(s->rematrix || s->dither_method) return swri_rematrix_init(s); return 0; @@ -554,8 +554,9 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co if(s->dither_pos + out_count > s->dither.count) s->dither_pos = 0; + for(ch=0; chch_count; ch++) - swri_sum2(s->int_sample_fmt, preout->ch[ch], preout->ch[ch], s->dither.ch[ch] + s->dither.bps * s->dither_pos, 1, 1, out_count); + s->mix_2_1_f(preout->ch[ch], preout->ch[ch], s->dither.ch[ch] + s->dither.bps * s->dither_pos, s->native_one, 0, 0, out_count); s->dither_pos += out_count; } diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index d34a75285c..550d7f0eb2 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -23,6 +23,9 @@ #include "swresample.h" +typedef void (mix_1_1_func_type)(void *out, const void *in, void *coeffp, int index, int len); +typedef void (mix_2_1_func_type)(void *out, const void *in1, const void *in2, void *coeffp, int index1, int index2, int len); + typedef struct AudioData{ uint8_t *ch[SWR_CH_MAX]; ///< samples buffer per channel uint8_t *data; ///< samples buffer @@ -84,6 +87,8 @@ struct SwrContext { uint8_t *native_one; int32_t matrix32[SWR_CH_MAX][SWR_CH_MAX]; ///< 17.15 fixed point rematrixing coefficients uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1]; ///< Lists of input channels per output channel that have non zero rematrixing coefficients + mix_1_1_func_type *mix_1_1_f; + mix_2_1_func_type *mix_2_1_f; /* TODO: callbacks for ASM optimizations */ }; @@ -100,7 +105,6 @@ int swri_resample_double(struct ResampleContext *c,double *dst, const double * int swri_rematrix_init(SwrContext *s); void swri_rematrix_free(SwrContext *s); int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy); -void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len); void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);