]> git.sesse.net Git - ffmpeg/blobdiff - libswresample/rematrix.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libswresample / rematrix.c
index 15e3ead06e6ce00d6ed954185623a887a8647b7e..5fa77ce5f9fae619e20a170b15c9c23d9a5c9c56 100644 (file)
@@ -26,6 +26,7 @@
 #define R(x) x
 #define SAMPLE float
 #define COEFF float
+#define INTER float
 #define RENAME(x) x ## _float
 #include "rematrix_template.c"
 #undef SAMPLE
 #undef R
 #undef ONE
 #undef COEFF
+#undef INTER
 
 #define ONE (1.0)
 #define R(x) x
 #define SAMPLE double
 #define COEFF double
+#define INTER double
 #define RENAME(x) x ## _double
 #include "rematrix_template.c"
 #undef SAMPLE
 #undef R
 #undef ONE
 #undef COEFF
+#undef INTER
 
 #define ONE (-32768)
 #define R(x) (((x) + 16384)>>15)
 #define SAMPLE int16_t
 #define COEFF int
+#define INTER int
 #define RENAME(x) x ## _s16
 #include "rematrix_template.c"
 
@@ -286,6 +291,8 @@ int swri_rematrix_init(SwrContext *s){
     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);
 
+    s->mix_any_f = NULL;
+
     if (!s->rematrix_custom) {
         int r = auto_matrix(s);
         if (r)
@@ -300,6 +307,7 @@ int swri_rematrix_init(SwrContext *s){
         *((int*)s->native_one) = 32768;
         s->mix_1_1_f = copy_s16;
         s->mix_2_1_f = sum2_s16;
+        s->mix_any_f = get_mix_any_func_s16(s);
     }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));
@@ -309,6 +317,7 @@ int swri_rematrix_init(SwrContext *s){
         *((float*)s->native_one) = 1.0;
         s->mix_1_1_f = copy_float;
         s->mix_2_1_f = sum2_float;
+        s->mix_any_f = get_mix_any_func_float(s);
     }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
         s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(double));
         s->native_one    = av_mallocz(sizeof(double));
@@ -318,6 +327,7 @@ int swri_rematrix_init(SwrContext *s){
         *((double*)s->native_one) = 1.0;
         s->mix_1_1_f = copy_double;
         s->mix_2_1_f = sum2_double;
+        s->mix_any_f = get_mix_any_func_double(s);
     }else
         av_assert0(0);
     //FIXME quantize for integeres
@@ -341,13 +351,19 @@ void swri_rematrix_free(SwrContext *s){
 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
     int out_i, in_i, i, j;
 
+    if(s->mix_any_f) {
+        s->mix_any_f(out->ch, in->ch, s->native_matrix, len);
+        return 0;
+    }
+
     av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
     av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
 
     for(out_i=0; out_i<out->ch_count; out_i++){
         switch(s->matrix_ch[out_i][0]){
         case 0:
-            memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
+            if(mustcopy)
+                memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
             break;
         case 1:
             in_i= s->matrix_ch[out_i][1];