~ubuntu-branches/ubuntu/precise/gst-plugins-bad0.10/precise-proposed

« back to all changes in this revision

Viewing changes to gst/mve/mveaudioenc.c

Tags: upstream-0.10.5.3
Import upstream version 0.10.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
#include <math.h>
 
23
#include <stdlib.h>
23
24
#include <gst/gst.h>
24
25
 
25
 
static const gint32 dec_table[256] =
26
 
    { 
 
 
b'0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, '
 
 
b'16, 17, 18, 19,'
27
 
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
 
 
b'32, 33, 34, 35, 36, 37,'
28
 
  38, 39, 40, 41, 42, 43, 47, 51, 56, 61, 
 
 
b'66, 72, 79, 86, 94, 102, 112,'
29
 
  122, 133, 145, 158, 173, 189, 206, 225, 245, 
 
 
b'267, 292, 318, 348, 379,'
30
 
  414, 452, 493, 538, 587, 640, 699, 763, 832, 908, 991, 
 
 
b'1081, 1180, 1288,'
 
26
static const gint32 dec_table[256] = {
 
27
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
 
28
  16, 17, 18, 19,
 
29
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
 
30
  32, 33, 34, 35, 36, 37,
 
31
  38, 39, 40, 41, 42, 43, 47, 51, 56, 61,
 
32
  66, 72, 79, 86, 94, 102, 112,
 
33
  122, 133, 145, 158, 173, 189, 206, 225, 245,
 
34
  267, 292, 318, 348, 379,
 
35
  414, 452, 493, 538, 587, 640, 699, 763, 832, 908, 991,
 
36
  1081, 1180, 1288,
31
37
  1405, 1534, 1673, 1826, 1993, 2175, 2373, 2590, 2826, 3084, 3365, 3672,
32
 
  4008, 
 
 
b'4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059, 8794, 9597, 10472,'
33
 
  11428, 12471, 13609, 14851, 16206, 
 
 
b'17685, 19298, 21060, 22981, 25078,'
 
38
  4008,
 
39
  4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059, 8794, 9597, 10472,
 
40
  11428, 12471, 13609, 14851, 16206,
 
41
  17685, 19298, 21060, 22981, 25078,
34
42
  27367, 29864, 32589, 35563, 38808, 42350, 46214, 50431, 55033, 60055,
35
 
  65535, 
 
 
b'1, -65535, -60055, -55033, -50431, -46214, -42350, -38808, -35563,'
36
 
  -32589, -29864, -27367, -25078, -22981, -21060, -19298, 
37
 
17685, -16206,
 
43
  65535,
 
44
  1, -65535, -60055, -55033, -50431, -46214, -42350, -38808, -35563,
 
45
  -32589, -29864, -27367, -25078, -22981, -21060, -19298,
 
46
  -17685, -16206,
38
47
  -14851, -13609, -12471, -11428, -10472, -9597, -8794, -8059, -7385, -6767,
39
 
  -6202, -5683, -5208, -4772, 
40
 
4373, -4008, -3672, -3365, -3084, -2826,
 
48
  -6202, -5683, -5208, -4772,
 
49
  -4373, -4008, -3672, -3365, -3084, -2826,
41
50
  -2590, -2373, -2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180,
42
 
  
43
 
1081, -991, -908, -832, -763, -699, -640, -587, -538, -493, -452, -414,
44
 
  -379, -348, -318, -292, 
45
 
267, -245, -225, -206, -189, -173, -158, -145,
46
 
  -133, -122, -112, -102, -94, -86, -79, -72, 
47
 
66, -61, -56, -51, -47, -43,
48
 
  -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, 
49
 
32, -31, -30, -29,
50
 
  -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, 
51
 
16, -15,
52
 
  -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1 
 
51
 
 
52
  -1081, -991, -908, -832, -763, -699, -640, -587, -538, -493, -452, -414,
 
53
  -379, -348, -318, -292,
 
54
  -267, -245, -225, -206, -189, -173, -158, -145,
 
55
  -133, -122, -112, -102, -94, -86, -79, -72,
 
56
  -66, -61, -56, -51, -47, -43,
 
57
  -42, -41, -40, -39, -38, -37, -36, -35, -34, -33,
 
58
  -32, -31, -30, -29,
 
59
  -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17,
 
60
  -16, -15,
 
61
  -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1
53
62
};
54
63
 
55
 
 
56
 
/* This value could be non-optimal. Without knowledge of the value
57
 
   distribution in the real signal, the actual optimum cannot be evaluated.
58
 
   Should be somewhere between 11.458 and 11.542. */ 
 
64
 
 
65
 
 
66
/* This value could be non-optimal. Without knowledge of the value
 
67
   distribution in the real signal, the actual optimum cannot be evaluated.
 
68
   Should be somewhere between 11.458 and 11.542. */
59
69
static const gdouble DPCM_SCALE = 11.5131;
60
 
 
 
 
b'static gint8'
 
70
 
 
71
static gint8
61
72
mve_enc_delta (guint n)
62
73
{
63
74
  if (n < 44)
81
99
    src += 2;
82
100
 
83
101
    delta = s - prev[cur_chan];
84
 
    
 
 
b'if (delta >= 0)'
85
 
      
 
 
b'v = mve_enc_delta (delta);'
86
 
    
 
102
 
 
103
    if (delta >= 0)
 
104
 
 
105
      v = mve_enc_delta (delta);
 
106
 
87
107
    else
88
 
      
 
 
b'v = 256 - mve_enc_delta (-delta);'
89
 
    
 
 
b'real_res = dec_table[v] + prev[cur_chan];'
90
 
    
 
 
b'if (real_res < -32768 || real_res > 32767) {'
91
 
      
92
 
          /* correct overflow */ 
93
 
          /* GST_DEBUG ("co:%d + %d = %d -> new v:%d, dec_table:%d will be %d",
94
 
             prev[cur_chan], dec_table[v], real_res,
95
 
             v, dec_table[v], prev[cur_chan]+dec_table[v]); */
96
 
          if (s > 0) {
97
 
        
 
 
b'if (real_res > 32767)'
 
108
 
 
109
      v = 256 - mve_enc_delta (-delta);
 
110
 
 
111
 
 
112
    real_res = dec_table[v] + prev[cur_chan];
 
113
 
 
114
    if (real_res < -32768 || real_res > 32767) {
 
115
 
 
116
      /* correct overflow */
 
117
      /* GST_DEBUG ("co:%d + %d = %d -> new v:%d, dec_table:%d will be %d",
 
118
         prev[cur_chan], dec_table[v], real_res,
 
119
         v, dec_table[v], prev[cur_chan]+dec_table[v]); */
 
120
      if (s > 0) {
 
121
 
 
122
        if (real_res > 32767)
98
123
          --v;
99
 
      
 
 
b'} else {'
100
 
        
 
 
b'if (real_res < -32768)'
 
124
 
 
125
      } else {
 
126
 
 
127
        if (real_res < -32768)
101
128
          ++v;
102
 
      
 
 
b'}'
 
129
 
 
130
      }
103
131
 
104
132
      real_res = dec_table[v] + prev[cur_chan];
105
 
    
 
 
b'}'
 
133
 
 
134
    }
106
135
 
107
136
    if (G_UNLIKELY (abs (real_res - s) > 32767)) {
108
137
      GST_ERROR ("sign loss left unfixed in audio stream, deviation:%d",
109
138
          real_res - s);
110
139
      return -1;
111
140
    }
112
 
    
 
 
b'*dest++ = v;'
113
 
    
114
 
-len;
115
 
    /* use previous output instead of input. That way output will not go too far from input. */ 
116
 
        prev[cur_chan] += dec_table[v];
 
141
 
 
142
 
 
143
    *dest++ = v;
 
144
 
 
145
    --len;
 
146
    /* use previous output instead of input. That way output will not go too far from input. */
 
147
    prev[cur_chan] += dec_table[v];
117
148
    cur_chan = channels - 1 - cur_chan;
118
 
  
 
 
b'}'
 
149
 
 
150
  }
119
151
 
120
152
  return 0;
121
153
}