Revision 1be0fc29 libavcodec/ra288.c

View differences:

libavcodec/ra288.c
23 23
#define ALT_BITSTREAM_READER_LE
24 24
#include "bitstream.h"
25 25
#include "ra288.h"
26
#include "lpc.h"
26 27

  
27 28
typedef struct {
28 29
    float sp_lpc[36];      ///< LPC coefficients for speech data (spec: A)
......
113 114
        block[i] = av_clipf(block[i] + buffer[i], -4095, 4095);
114 115
}
115 116

  
116
/**
117
 * Converts autocorrelation coefficients to LPC coefficients using the
118
 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification.
119
 *
120
 * @return 0 if success, -1 if fail
121
 */
122
static int eval_lpc_coeffs(const float *in, float *tgt, int n)
123
{
124
    int i, j;
125
    double f0, f1, f2;
126

  
127
    if (in[n] == 0)
128
        return -1;
129

  
130
    if ((f0 = *in) <= 0)
131
        return -1;
132

  
133
    in--; // To avoid a -1 subtraction in the inner loop
134

  
135
    for (i=1; i <= n; i++) {
136
        f1 = in[i+1];
137

  
138
        for (j=0; j < i - 1; j++)
139
            f1 += in[i-j]*tgt[j];
140

  
141
        tgt[i-1] = f2 = -f1/f0;
142
        for (j=0; j < i >> 1; j++) {
143
            float temp = tgt[j] + tgt[i-j-2]*f2;
144
            tgt[i-j-2] += tgt[j]*f2;
145
            tgt[j] = temp;
146
        }
147
        if ((f0 += f1*f2) < 0)
148
            return -1;
149
    }
150

  
151
    return 0;
152
}
153

  
154 117
static void convolve(float *tgt, const float *src, int len, int n)
155 118
{
156 119
    for (; n >= 0; n--)
......
210 173
    do_hybrid_window(36, 40, 35, ractx->sp_block+1, temp1, ractx->sp_hist,
211 174
                     ractx->sp_rec, syn_window);
212 175

  
213
    if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36))
176
    if (!compute_lpc_coefs(temp1, 36, ractx->sp_lpc, 0, 1, 1))
214 177
        colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36);
215 178

  
216 179
    do_hybrid_window(10, 8, 20, ractx->gain_block+2, temp2, ractx->gain_hist,
217 180
                     ractx->gain_rec, gain_window);
218 181

  
219
    if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10))
182
    if (!compute_lpc_coefs(temp2, 10, ractx->gain_lpc, 0, 1, 1))
220 183
        colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10);
221 184
}
222 185

  

Also available in: Unified diff