summaryrefslogtreecommitdiffstats
path: root/src/libdca-2-normalisation-factor-sqrt2+output-bias.patch
blob: 2d4cdb569215dff43aa5ffc8e7e921b30715c103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
This file is part of MXE.
See index.html for further information.

Taken from libdca svn: svn://svn.videolan.org/libdca/trunk.

r84 | gbazin | 2008-06-01 16:13:33 +0000 (Sun, 01 Jun 2008) | 3 lines
  * libdca/parse.c: Change output normalisation factor from 3/2 to sqrt(2).
    Thanks to Alexander E. Patrakov for finding that this is the proper normalisation factor.
    Fixed a bug where the output bias wasn't applied when downmixing wasn't being done.

--- libdca.orig/libdca/parse.c
+++ libdca/libdca/parse.c
@@ -59,12 +59,11 @@
 static int decode_blockcode (int code, int levels, int *values);
 
 static void qmf_32_subbands (dca_state_t * state, int chans,
-                             double samples_in[32][8], sample_t *samples_out,
-                             double rScale, sample_t bias);
+                             double samples_in[32][8], sample_t *samples_out);
 
 static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
                                    double *samples_in, sample_t *samples_out,
-                                   double rScale, sample_t bias );
+                                   sample_t bias);
 
 static void pre_calc_cosmod( dca_state_t * state );
 
@@ -123,7 +122,9 @@
     bitstream_get (state, 1);
 
     *frame_length = (bitstream_get (state, 7) + 1) * 32;
+    if (*frame_length < 6 * 32) return 0;
     frame_size = bitstream_get (state, 14) + 1;
+    if (frame_size < 96) return 0;
     if (!state->word_mode) frame_size = frame_size * 8 / 14 * 2;
 
     /* Audio channel arrangement */
@@ -981,14 +982,7 @@
     /* 32 subbands QMF */
     for (k = 0; k < state->prim_channels; k++)
     {
-        /*static double pcm_to_float[8] =
-            {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
-
-        qmf_32_subbands (state, k,
-                         subband_samples[k],
-                         &state->samples[256*k],
-          /*WTF ???*/    32768.0*3/2/*pcm_to_float[state->source_pcm_res]*/,
-                         0/*state->bias*/);
+        qmf_32_subbands (state, k, subband_samples[k], &state->samples[256*k]);
     }
 
     /* Down/Up mixing */
@@ -1000,6 +994,10 @@
     {
         dca_downmix (state->samples, state->amode, state->output, state->bias,
                      state->clev, state->slev);
+    } else if (state->bias)
+    {
+        for ( k = 0; k < 256*state->prim_channels; k++ )
+            state->samples[k] += state->bias;
     }
 
     /* Generate LFE samples for this subsubframe FIXME!!! */
@@ -1011,8 +1009,7 @@
         lfe_interpolation_fir (state->lfe, 2 * state->lfe,
                                state->lfe_data + lfe_samples +
                                2 * state->lfe * subsubframe,
-                               &state->samples[256*i_channels],
-                               8388608.0, state->bias);
+                               &state->samples[256*i_channels], state->bias);
         /* Outputs 20bits pcm samples */
     }
 
@@ -1142,9 +1139,9 @@
 }
 
 static void qmf_32_subbands (dca_state_t * state, int chans,
-                             double samples_in[32][8], sample_t *samples_out,
-                             double scale, sample_t bias)
+                             double samples_in[32][8], sample_t *samples_out)
 {
+    static const double scale = 1.4142135623730951 /* sqrt(2) */ * 32768.0;
     const double *prCoeff;
     int i, j, k;
     double raXin[32];
@@ -1211,7 +1208,7 @@
 
         /* Create 32 PCM output samples */
         for (i=0;i<32;i++)
-            samples_out[nChIndex++] = subband_fir_hist2[i] / scale + bias;
+            samples_out[nChIndex++] = subband_fir_hist2[i] / scale;
 
         /* Update working arrays */
         for (i=511;i>=32;i--)
@@ -1225,7 +1222,7 @@
 
 static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
                                    double *samples_in, sample_t *samples_out,
-                                   double scale, sample_t bias)
+                                   sample_t bias)
 {
     /* samples_in: An array holding decimated samples.
      *   Samples in current subframe starts from samples_in[0],
@@ -1235,6 +1232,7 @@
      * samples_out: An array holding interpolated samples
      */
 
+    static const double scale = 8388608.0;
     int nDeciFactor, k, J;
     const double *prCoeff;