diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-05-01 20:19:28 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-05-01 20:19:28 +0200 |
commit | 00fea26faf8df22b7c686ceb36a7eecdc3d44b10 (patch) | |
tree | 12e613d2be518af38e034e521dd945ee481fc372 /libswresample | |
parent | f08397642fed84ac7e6eaffbe3e05e96ecaf5aa1 (diff) | |
download | ffmpeg-00fea26faf8df22b7c686ceb36a7eecdc3d44b10.tar.gz |
swr: add native matrix for rematrixing
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample')
-rw-r--r-- | libswresample/rematrix.c | 23 | ||||
-rw-r--r-- | libswresample/swresample.c | 2 | ||||
-rw-r--r-- | libswresample/swresample_internal.h | 3 |
3 files changed, 28 insertions, 0 deletions
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 415fb1e0f5..329bd66381 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -253,12 +253,30 @@ static int auto_matrix(SwrContext *s) int swri_rematrix_init(SwrContext *s){ int i, j; + int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout); + int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout); if (!s->rematrix_custom) { int r = auto_matrix(s); if (r) return r; } + if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){ + s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(int)); + s->native_one = av_mallocz(sizeof(int)); + for (i = 0; i < nb_out; i++) + 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; + }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)); + for (i = 0; i < nb_out; i++) + 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; + }else + av_assert0(0); //FIXME quantize for integeres for (i = 0; i < SWR_CH_MAX; i++) { int ch_in=0; @@ -281,6 +299,11 @@ void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const vo } } +void swri_rematrix_free(SwrContext *s){ + av_freep(&s->native_matrix); + av_freep(&s->native_one); +} + int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){ int out_i, in_i, i, j; diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 9429c1ee45..9a4f6a7597 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -176,6 +176,7 @@ void swr_free(SwrContext **ss){ swri_audio_convert_free(&s->out_convert); swri_audio_convert_free(&s->full_convert); swri_resample_free(&s->resample); + swri_rematrix_free(s); } av_freep(ss); @@ -193,6 +194,7 @@ int swr_init(struct SwrContext *s){ swri_audio_convert_free(&s-> in_convert); swri_audio_convert_free(&s->out_convert); swri_audio_convert_free(&s->full_convert); + swri_rematrix_free(s); s->flushed = 0; diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index bd46976812..d34a75285c 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -80,6 +80,8 @@ struct SwrContext { struct ResampleContext *resample; ///< resampling context float matrix[SWR_CH_MAX][SWR_CH_MAX]; ///< floating point rematrixing coefficients + uint8_t *native_matrix; + 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 @@ -96,6 +98,7 @@ int swri_resample_float(struct ResampleContext *c, float *dst, const float * int swri_resample_double(struct ResampleContext *c,double *dst, const double *src, int *consumed, int src_size, int dst_size, int update_ctx); 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); |