From 00fea26faf8df22b7c686ceb36a7eecdc3d44b10 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 1 May 2012 20:19:28 +0200 Subject: swr: add native matrix for rematrixing Signed-off-by: Michael Niedermayer --- libswresample/rematrix.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libswresample/rematrix.c') 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; -- cgit v1.2.3