Coverage Report

Created: 2026-10-17 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/tns.c
Line
Count
Source
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**
28
** $Id: tns.c,v 1.40 2007/11/01 12:33:40 menno Exp $
29
**/
30
31
#include "common.h"
32
#include "structs.h"
33
34
#include "syntax.h"
35
#include "tns.h"
36
37
38
/* static function declarations */
39
/* returns exp */
40
static uint8_t tns_decode_coef(uint8_t order, uint8_t coef_res_bits,
41
                               uint8_t coef_compress, uint8_t *coef, real_t *a);
42
static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
43
                          uint8_t order, uint8_t exp);
44
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
45
                          uint8_t order, uint8_t exp);
46
47
48
#ifdef _MSC_VER
49
#pragma warning(disable:4305)
50
#pragma warning(disable:4244)
51
#endif
52
static real_t tns_coef_0_3[] =
53
{
54
    COEF_CONST(0.0), COEF_CONST(0.4338837391), COEF_CONST(0.7818314825), COEF_CONST(0.9749279122),
55
    COEF_CONST(-0.9848077530), COEF_CONST(-0.8660254038), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
56
    COEF_CONST(-0.4338837391), COEF_CONST(-0.7818314825), COEF_CONST(-0.9749279122), COEF_CONST(-0.9749279122),
57
    COEF_CONST(-0.9848077530), COEF_CONST(-0.8660254038), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433)
58
};
59
static real_t tns_coef_0_4[] =
60
{
61
    COEF_CONST(0.0), COEF_CONST(0.2079116908), COEF_CONST(0.4067366431), COEF_CONST(0.5877852523),
62
    COEF_CONST(0.7431448255), COEF_CONST(0.8660254038), COEF_CONST(0.9510565163), COEF_CONST(0.9945218954),
63
    COEF_CONST(-0.9957341763), COEF_CONST(-0.9618256432), COEF_CONST(-0.8951632914), COEF_CONST(-0.7980172273),
64
    COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178)
65
};
66
static real_t tns_coef_1_3[] =
67
{
68
    COEF_CONST(0.0), COEF_CONST(0.4338837391), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
69
    COEF_CONST(0.9749279122), COEF_CONST(0.7818314825), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
70
    COEF_CONST(-0.4338837391), COEF_CONST(-0.7818314825), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
71
    COEF_CONST(-0.7818314825), COEF_CONST(-0.4338837391), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433)
72
};
73
static real_t tns_coef_1_4[] =
74
{
75
    COEF_CONST(0.0), COEF_CONST(0.2079116908), COEF_CONST(0.4067366431), COEF_CONST(0.5877852523),
76
    COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178),
77
    COEF_CONST(0.9945218954), COEF_CONST(0.9510565163), COEF_CONST(0.8660254038), COEF_CONST(0.7431448255),
78
    COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178)
79
};
80
81
static real_t* all_tns_coefs[] = {tns_coef_0_3, tns_coef_0_4, tns_coef_1_3, tns_coef_1_4};
82
83
/* TNS decoding for one channel and frame */
84
void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
85
                      uint8_t object_type, real_t *spec, uint16_t frame_len)
86
950k
{
87
950k
    uint8_t w, f, tns_order;
88
950k
    int8_t inc;
89
950k
    int16_t size;
90
950k
    uint16_t bottom, top, start, end;
91
950k
    uint16_t nshort = frame_len/8;
92
950k
    real_t lpc[TNS_MAX_ORDER+1];
93
950k
    uint8_t exp;
94
95
950k
    if (!ics->tns_data_present)
96
897k
        return;
97
98
158k
    for (w = 0; w < ics->num_windows; w++)
99
105k
    {
100
105k
        bottom = ics->num_swb;
101
102
159k
        for (f = 0; f < tns->n_filt[w]; f++)
103
53.6k
        {
104
53.6k
            top = bottom;
105
53.6k
            bottom = max(top - tns->length[w][f], 0);
106
53.6k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
107
53.6k
            if (!tns_order)
108
21.9k
                continue;
109
110
31.7k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
111
31.7k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
112
113
31.7k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
114
31.7k
            start = min(start, ics->max_sfb);
115
31.7k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
116
117
31.7k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
118
31.7k
            end = min(end, ics->max_sfb);
119
31.7k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
120
121
31.7k
            size = end - start;
122
31.7k
            if (size <= 0)
123
26.3k
                continue;
124
125
5.36k
            if (tns->direction[w][f])
126
3.30k
            {
127
3.30k
                inc = -1;
128
3.30k
                start = end - 1;
129
3.30k
            } else {
130
2.05k
                inc = 1;
131
2.05k
            }
132
133
5.36k
            tns_ar_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
134
5.36k
        }
135
105k
    }
136
53.0k
}
137
138
/* TNS encoding for one channel and frame */
139
void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
140
                      uint8_t object_type, real_t *spec, uint16_t frame_len)
141
15.9k
{
142
15.9k
    uint8_t w, f, tns_order;
143
15.9k
    int8_t inc;
144
15.9k
    int16_t size;
145
15.9k
    uint16_t bottom, top, start, end;
146
15.9k
    uint16_t nshort = frame_len/8;
147
15.9k
    real_t lpc[TNS_MAX_ORDER+1];
148
15.9k
    uint8_t exp;
149
150
15.9k
    if (!ics->tns_data_present)
151
13.4k
        return;
152
153
5.03k
    for (w = 0; w < ics->num_windows; w++)
154
2.51k
    {
155
2.51k
        bottom = ics->num_swb;
156
157
8.32k
        for (f = 0; f < tns->n_filt[w]; f++)
158
5.80k
        {
159
5.80k
            top = bottom;
160
5.80k
            bottom = max(top - tns->length[w][f], 0);
161
5.80k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
162
5.80k
            if (!tns_order)
163
1.14k
                continue;
164
165
4.65k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
166
4.65k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
167
168
4.65k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
169
4.65k
            start = min(start, ics->max_sfb);
170
4.65k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
171
172
4.65k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
173
4.65k
            end = min(end, ics->max_sfb);
174
4.65k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
175
176
4.65k
            size = end - start;
177
4.65k
            if (size <= 0)
178
2.89k
                continue;
179
180
1.76k
            if (tns->direction[w][f])
181
917
            {
182
917
                inc = -1;
183
917
                start = end - 1;
184
917
            } else {
185
843
                inc = 1;
186
843
            }
187
188
1.76k
            tns_ma_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
189
1.76k
        }
190
2.51k
    }
191
2.51k
}
192
193
/* Decoder transmitted coefficients for one TNS filter */
194
static uint8_t tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
195
                            uint8_t *coef, real_t *a)
196
36.3k
{
197
36.3k
    uint8_t i, m;
198
36.3k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
36.3k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
36.3k
    real_t* tns_coef = all_tns_coefs[table_index];
201
36.3k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
237k
    for (i = 0; i < order; i++)
205
201k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
36.3k
    a[0] = COEF_CONST(1.0);
209
237k
    for (m = 1; m <= order; m++)
210
201k
    {
211
201k
        a[m] = tmp2[m-1]; /* changed */
212
1.25M
        for (i = 1; i < m; i++) /* loop only while i<m */
213
1.05M
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
1.25M
        for (i = 1; i < m; i++) /* loop only while i<m */
216
1.05M
            a[i] = b[i];
217
218
#ifdef FIXED_POINT
219
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
100k
        if (m < order)
223
81.7k
        {
224
81.7k
            real_t sum_abs = COEF_CONST(0.0);
225
587k
            for (i = 1; i <= m; ++i)
226
505k
            {
227
505k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
505k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
81.7k
            if (sum_abs >= COEF_CONST(3.5))
231
10.2k
            {
232
10.2k
                exp++;
233
112k
                for (i = 1; i <= m; ++i)
234
102k
                {
235
102k
                    a[i] >>= 1;
236
102k
                }
237
10.2k
            }
238
81.7k
        }
239
#endif
240
201k
    }
241
36.3k
    return exp;
242
36.3k
}
tns.c:tns_decode_coef
Line
Count
Source
196
18.9k
{
197
18.9k
    uint8_t i, m;
198
18.9k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
18.9k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
18.9k
    real_t* tns_coef = all_tns_coefs[table_index];
201
18.9k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
119k
    for (i = 0; i < order; i++)
205
100k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
18.9k
    a[0] = COEF_CONST(1.0);
209
119k
    for (m = 1; m <= order; m++)
210
100k
    {
211
100k
        a[m] = tmp2[m-1]; /* changed */
212
606k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
505k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
606k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
505k
            a[i] = b[i];
217
218
100k
#ifdef FIXED_POINT
219
100k
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
100k
        if (m < order)
223
81.7k
        {
224
81.7k
            real_t sum_abs = COEF_CONST(0.0);
225
587k
            for (i = 1; i <= m; ++i)
226
505k
            {
227
505k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
505k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
81.7k
            if (sum_abs >= COEF_CONST(3.5))
231
10.2k
            {
232
10.2k
                exp++;
233
112k
                for (i = 1; i <= m; ++i)
234
102k
                {
235
102k
                    a[i] >>= 1;
236
102k
                }
237
10.2k
            }
238
81.7k
        }
239
100k
#endif
240
100k
    }
241
18.9k
    return exp;
242
18.9k
}
tns.c:tns_decode_coef
Line
Count
Source
196
17.4k
{
197
17.4k
    uint8_t i, m;
198
17.4k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
17.4k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
17.4k
    real_t* tns_coef = all_tns_coefs[table_index];
201
17.4k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
118k
    for (i = 0; i < order; i++)
205
100k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
17.4k
    a[0] = COEF_CONST(1.0);
209
118k
    for (m = 1; m <= order; m++)
210
100k
    {
211
100k
        a[m] = tmp2[m-1]; /* changed */
212
645k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
545k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
645k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
545k
            a[i] = b[i];
217
218
#ifdef FIXED_POINT
219
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
        if (m < order)
223
        {
224
            real_t sum_abs = COEF_CONST(0.0);
225
            for (i = 1; i <= m; ++i)
226
            {
227
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
            if (sum_abs >= COEF_CONST(3.5))
231
            {
232
                exp++;
233
                for (i = 1; i <= m; ++i)
234
                {
235
                    a[i] >>= 1;
236
                }
237
            }
238
        }
239
#endif
240
100k
    }
241
17.4k
    return exp;
242
17.4k
}
243
244
static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
245
                          uint8_t order, uint8_t exp)
246
5.36k
{
247
    /*
248
     - Simple all-pole filter of order "order" defined by
249
       y(n) = x(n) - lpc[1]*y(n-1) - ... - lpc[order]*y(n-order)
250
     - The state variables of the filter are initialized to zero every time
251
     - The output data is written over the input data ("in-place operation")
252
     - An input vector of "size" samples is processed and the index increment
253
       to the next data sample is given by "inc"
254
    */
255
256
5.36k
    uint8_t j;
257
5.36k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
5.36k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
5.36k
    int8_t state_index = 0;
261
5.36k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
2.69k
    if (exp >= 4)
265
499
        return;
266
2.19k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
374k
    for (i = 0; i < size; i++)
272
369k
    {
273
369k
        real_t y = REAL_CONST(0.0);
274
3.65M
        for (j = 0; j < order; j++)
275
3.28M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
369k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
369k
        state_index--;
280
369k
        if (state_index < 0)
281
74.2k
            state_index = order-1;
282
369k
        state[state_index] = state[state_index + order] = y;
283
284
369k
        *spectrum = y;
285
369k
        spectrum += inc;
286
287
//#define TNS_PRINT
288
#ifdef TNS_PRINT
289
        //printf("%d\n", y);
290
        printf("0x%.8X\n", y);
291
#endif
292
369k
    }
293
2.19k
}
tns.c:tns_ar_filter
Line
Count
Source
246
2.69k
{
247
    /*
248
     - Simple all-pole filter of order "order" defined by
249
       y(n) = x(n) - lpc[1]*y(n-1) - ... - lpc[order]*y(n-order)
250
     - The state variables of the filter are initialized to zero every time
251
     - The output data is written over the input data ("in-place operation")
252
     - An input vector of "size" samples is processed and the index increment
253
       to the next data sample is given by "inc"
254
    */
255
256
2.69k
    uint8_t j;
257
2.69k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
2.69k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
2.69k
    int8_t state_index = 0;
261
2.69k
    int32_t mul = 1;
262
263
2.69k
#ifdef FIXED_POINT
264
2.69k
    if (exp >= 4)
265
499
        return;
266
2.19k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
165k
    for (i = 0; i < size; i++)
272
163k
    {
273
163k
        real_t y = REAL_CONST(0.0);
274
1.62M
        for (j = 0; j < order; j++)
275
1.46M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
163k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
163k
        state_index--;
280
163k
        if (state_index < 0)
281
37.5k
            state_index = order-1;
282
163k
        state[state_index] = state[state_index + order] = y;
283
284
163k
        *spectrum = y;
285
163k
        spectrum += inc;
286
287
//#define TNS_PRINT
288
#ifdef TNS_PRINT
289
        //printf("%d\n", y);
290
        printf("0x%.8X\n", y);
291
#endif
292
163k
    }
293
2.19k
}
tns.c:tns_ar_filter
Line
Count
Source
246
2.67k
{
247
    /*
248
     - Simple all-pole filter of order "order" defined by
249
       y(n) = x(n) - lpc[1]*y(n-1) - ... - lpc[order]*y(n-order)
250
     - The state variables of the filter are initialized to zero every time
251
     - The output data is written over the input data ("in-place operation")
252
     - An input vector of "size" samples is processed and the index increment
253
       to the next data sample is given by "inc"
254
    */
255
256
2.67k
    uint8_t j;
257
2.67k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
2.67k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
2.67k
    int8_t state_index = 0;
261
2.67k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
    if (exp >= 4)
265
        return;
266
    mul = 1 << exp;
267
#else
268
2.67k
    (void)exp;
269
2.67k
#endif
270
271
208k
    for (i = 0; i < size; i++)
272
206k
    {
273
206k
        real_t y = REAL_CONST(0.0);
274
2.02M
        for (j = 0; j < order; j++)
275
1.82M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
206k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
206k
        state_index--;
280
206k
        if (state_index < 0)
281
36.7k
            state_index = order-1;
282
206k
        state[state_index] = state[state_index + order] = y;
283
284
206k
        *spectrum = y;
285
206k
        spectrum += inc;
286
287
//#define TNS_PRINT
288
#ifdef TNS_PRINT
289
        //printf("%d\n", y);
290
        printf("0x%.8X\n", y);
291
#endif
292
206k
    }
293
2.67k
}
294
295
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
296
                          uint8_t order, uint8_t exp)
297
1.76k
{
298
    /*
299
     - Simple all-zero filter of order "order" defined by
300
       y(n) =  x(n) + a(2)*x(n-1) + ... + a(order+1)*x(n-order)
301
     - The state variables of the filter are initialized to zero every time
302
     - The output data is written over the input data ("in-place operation")
303
     - An input vector of "size" samples is processed and the index increment
304
       to the next data sample is given by "inc"
305
    */
306
307
1.76k
    uint8_t j;
308
1.76k
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
1.76k
    real_t state[2*TNS_MAX_ORDER] = {0};
311
1.76k
    int8_t state_index = 0;
312
1.76k
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
821
    if (exp >= 4)
316
176
        return;
317
645
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
51.7k
    for (i = 0; i < size; i++)
323
50.1k
    {
324
50.1k
        real_t y = REAL_CONST(0.0);
325
765k
        for (j = 0; j < order; j++)
326
715k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
50.1k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
50.1k
        state_index--;
332
50.1k
        if (state_index < 0)
333
10.0k
            state_index = order-1;
334
50.1k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
50.1k
        *spectrum = y;
337
50.1k
        spectrum += inc;
338
50.1k
    }
339
645
}
tns.c:tns_ma_filter
Line
Count
Source
297
821
{
298
    /*
299
     - Simple all-zero filter of order "order" defined by
300
       y(n) =  x(n) + a(2)*x(n-1) + ... + a(order+1)*x(n-order)
301
     - The state variables of the filter are initialized to zero every time
302
     - The output data is written over the input data ("in-place operation")
303
     - An input vector of "size" samples is processed and the index increment
304
       to the next data sample is given by "inc"
305
    */
306
307
821
    uint8_t j;
308
821
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
821
    real_t state[2*TNS_MAX_ORDER] = {0};
311
821
    int8_t state_index = 0;
312
821
    int32_t mul = 1;
313
314
821
#ifdef FIXED_POINT
315
821
    if (exp >= 4)
316
176
        return;
317
645
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
11.2k
    for (i = 0; i < size; i++)
323
10.5k
    {
324
10.5k
        real_t y = REAL_CONST(0.0);
325
112k
        for (j = 0; j < order; j++)
326
102k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
10.5k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
10.5k
        state_index--;
332
10.5k
        if (state_index < 0)
333
3.65k
            state_index = order-1;
334
10.5k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
10.5k
        *spectrum = y;
337
10.5k
        spectrum += inc;
338
10.5k
    }
339
645
}
tns.c:tns_ma_filter
Line
Count
Source
297
939
{
298
    /*
299
     - Simple all-zero filter of order "order" defined by
300
       y(n) =  x(n) + a(2)*x(n-1) + ... + a(order+1)*x(n-order)
301
     - The state variables of the filter are initialized to zero every time
302
     - The output data is written over the input data ("in-place operation")
303
     - An input vector of "size" samples is processed and the index increment
304
       to the next data sample is given by "inc"
305
    */
306
307
939
    uint8_t j;
308
939
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
939
    real_t state[2*TNS_MAX_ORDER] = {0};
311
939
    int8_t state_index = 0;
312
939
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
    if (exp >= 4)
316
        return;
317
    mul = 1 << exp;
318
#else
319
939
    (void)exp;
320
939
#endif
321
322
40.5k
    for (i = 0; i < size; i++)
323
39.5k
    {
324
39.5k
        real_t y = REAL_CONST(0.0);
325
652k
        for (j = 0; j < order; j++)
326
613k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
39.5k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
39.5k
        state_index--;
332
39.5k
        if (state_index < 0)
333
6.38k
            state_index = order-1;
334
39.5k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
39.5k
        *spectrum = y;
337
39.5k
        spectrum += inc;
338
39.5k
    }
339
939
}