Browse code

swr: add double precision support to the rematrix code

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/05/02 07:50:00
Showing 2 changed files
... ...
@@ -34,6 +34,18 @@
34 34
 #undef ONE
35 35
 #undef COEFF
36 36
 
37
+#define ONE (1.0)
38
+#define R(x) x
39
+#define SAMPLE double
40
+#define COEFF double
41
+#define RENAME(x) x ## _double
42
+#include "rematrix_template.c"
43
+#undef SAMPLE
44
+#undef RENAME
45
+#undef R
46
+#undef ONE
47
+#undef COEFF
48
+
37 49
 #define ONE (-32768)
38 50
 #define R(x) (((x) + 16384)>>15)
39 51
 #define SAMPLE int16_t
... ...
@@ -297,6 +309,15 @@ int swri_rematrix_init(SwrContext *s){
297 297
         *((float*)s->native_one) = 1.0;
298 298
         s->mix_1_1_f = copy_float;
299 299
         s->mix_2_1_f = sum2_float;
300
+    }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
301
+        s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(double));
302
+        s->native_one    = av_mallocz(sizeof(double));
303
+        for (i = 0; i < nb_out; i++)
304
+            for (j = 0; j < nb_in; j++)
305
+                ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
306
+        *((double*)s->native_one) = 1.0;
307
+        s->mix_1_1_f = copy_double;
308
+        s->mix_2_1_f = sum2_double;
300 309
     }else
301 310
         av_assert0(0);
302 311
     //FIXME quantize for integeres
... ...
@@ -353,6 +374,15 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
353 353
                     }
354 354
                     ((float*)out->ch[out_i])[i]= v;
355 355
                 }
356
+            }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
357
+                for(i=0; i<len; i++){
358
+                    double v=0;
359
+                    for(j=0; j<s->matrix_ch[out_i][0]; j++){
360
+                        in_i= s->matrix_ch[out_i][1+j];
361
+                        v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
362
+                    }
363
+                    ((double*)out->ch[out_i])[i]= v;
364
+                }
356 365
             }else{
357 366
                 for(i=0; i<len; i++){
358 367
                     int v=0;
... ...
@@ -216,8 +216,9 @@ int swr_init(struct SwrContext *s){
216 216
 
217 217
     if(   s->int_sample_fmt != AV_SAMPLE_FMT_S16P
218 218
         &&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
219
-        &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP){
220
-        av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
219
+        &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
220
+        &&s->int_sample_fmt != AV_SAMPLE_FMT_DBLP){
221
+        av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT/DBL is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
221 222
         return AVERROR(EINVAL);
222 223
     }
223 224