diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-02-16 11:26:32 +0100 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-02-20 20:46:35 +0100 |
commit | 560b224f53fd553262790216d18c64665ebf436d (patch) | |
tree | 74c87cf7cc43391b7517c001b980856a2ea95bbc /libswresample/rematrix.c | |
parent | 016c7bb762edded8d64f986e40b6f4cd739dd597 (diff) |
libswr: allow to set custom matrices.
Diffstat (limited to 'libswresample/rematrix.c')
-rw-r--r-- | libswresample/rematrix.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 0e4d9630c8..da817e1455 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -61,6 +61,24 @@ #define TOP_BACK_CENTER 16 #define TOP_BACK_RIGHT 17 +int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) +{ + int nb_in, nb_out, in, out; + + if (!s || s->in_convert) // s needs to be allocated but not initialized + return AVERROR(EINVAL); + memset(s->matrix, 0, sizeof(s->matrix)); + nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout); + nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout); + for (out = 0; out < nb_out; out++) { + for (in = 0; in < nb_in; in++) + s->matrix[out][in] = matrix[in]; + matrix += stride; + } + s->rematrix_custom = 1; + return 0; +} + static int even(int64_t layout){ if(!layout) return 1; if(layout&(layout-1)) return 1; @@ -84,12 +102,14 @@ static int sane_layout(int64_t layout){ return 1; } -int swri_rematrix_init(SwrContext *s){ +static int auto_matrix(SwrContext *s) +{ int i, j, out_i; double matrix[64][64]={{0}}; int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout; double maxcoef=0; + memset(s->matrix, 0, sizeof(s->matrix)); for(i=0; i<64; i++){ if(s->in_ch_layout & s->out_ch_layout & (1LL<<i)) matrix[i][i]= 1.0; @@ -189,23 +209,17 @@ int swri_rematrix_init(SwrContext *s){ }else av_assert0(0); } - - //FIXME quantize for integeres for(out_i=i=0; i<64; i++){ double sum=0; int in_i=0; - int ch_in=0; for(j=0; j<64; j++){ s->matrix[out_i][in_i]= matrix[i][j]; - s->matrix32[out_i][in_i]= lrintf(matrix[i][j] * 32768); if(matrix[i][j]){ - s->matrix_ch[out_i][++ch_in]= in_i; sum += fabs(matrix[i][j]); } if(s->in_ch_layout & (1ULL<<j)) in_i++; } - s->matrix_ch[out_i][0]= ch_in; maxcoef= FFMAX(maxcoef, sum); if(s->out_ch_layout & (1ULL<<i)) out_i++; @@ -218,7 +232,6 @@ int swri_rematrix_init(SwrContext *s){ for(i=0; i<SWR_CH_MAX; i++) for(j=0; j<SWR_CH_MAX; j++){ s->matrix[i][j] /= maxcoef; - s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768); } } @@ -226,7 +239,6 @@ int swri_rematrix_init(SwrContext *s){ for(i=0; i<SWR_CH_MAX; i++) for(j=0; j<SWR_CH_MAX; j++){ s->matrix[i][j] *= s->rematrix_volume; - s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768); } } @@ -239,6 +251,27 @@ int swri_rematrix_init(SwrContext *s){ return 0; } +int swri_rematrix_init(SwrContext *s){ + int i, j; + + if (!s->rematrix_custom) { + int r = auto_matrix(s); + if (r) + return r; + } + //FIXME quantize for integeres + for (i = 0; i < SWR_CH_MAX; i++) { + int ch_in=0; + for (j = 0; j < SWR_CH_MAX; j++) { + s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768); + if(s->matrix[i][j]) + s->matrix_ch[i][++ch_in]= j; + } + s->matrix_ch[i][0]= ch_in; + } + return 0; +} + int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){ int out_i, in_i, i, j; |