summaryrefslogtreecommitdiff
path: root/libswresample/rematrix.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-05-01 20:19:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-05-01 20:19:28 +0200
commit00fea26faf8df22b7c686ceb36a7eecdc3d44b10 (patch)
tree12e613d2be518af38e034e521dd945ee481fc372 /libswresample/rematrix.c
parentf08397642fed84ac7e6eaffbe3e05e96ecaf5aa1 (diff)
swr: add native matrix for rematrixing
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/rematrix.c')
-rw-r--r--libswresample/rematrix.c23
1 files changed, 23 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;