Coverage Report

Created: 2026-09-14 06:52

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
700k
{
87
700k
    uint8_t w, f, tns_order;
88
700k
    int8_t inc;
89
700k
    int16_t size;
90
700k
    uint16_t bottom, top, start, end;
91
700k
    uint16_t nshort = frame_len/8;
92
700k
    real_t lpc[TNS_MAX_ORDER+1];
93
700k
    uint8_t exp;
94
95
700k
    if (!ics->tns_data_present)
96
653k
        return;
97
98
145k
    for (w = 0; w < ics->num_windows; w++)
99
98.7k
    {
100
98.7k
        bottom = ics->num_swb;
101
102
146k
        for (f = 0; f < tns->n_filt[w]; f++)
103
47.9k
        {
104
47.9k
            top = bottom;
105
47.9k
            bottom = max(top - tns->length[w][f], 0);
106
47.9k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
107
47.9k
            if (!tns_order)
108
19.8k
                continue;
109
110
28.0k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
111
28.0k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
112
113
28.0k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
114
28.0k
            start = min(start, ics->max_sfb);
115
28.0k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
116
117
28.0k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
118
28.0k
            end = min(end, ics->max_sfb);
119
28.0k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
120
121
28.0k
            size = end - start;
122
28.0k
            if (size <= 0)
123
23.4k
                continue;
124
125
4.65k
            if (tns->direction[w][f])
126
2.48k
            {
127
2.48k
                inc = -1;
128
2.48k
                start = end - 1;
129
2.48k
            } else {
130
2.16k
                inc = 1;
131
2.16k
            }
132
133
4.65k
            tns_ar_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
134
4.65k
        }
135
98.7k
    }
136
47.1k
}
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
14.9k
{
142
14.9k
    uint8_t w, f, tns_order;
143
14.9k
    int8_t inc;
144
14.9k
    int16_t size;
145
14.9k
    uint16_t bottom, top, start, end;
146
14.9k
    uint16_t nshort = frame_len/8;
147
14.9k
    real_t lpc[TNS_MAX_ORDER+1];
148
14.9k
    uint8_t exp;
149
150
14.9k
    if (!ics->tns_data_present)
151
12.7k
        return;
152
153
4.51k
    for (w = 0; w < ics->num_windows; w++)
154
2.25k
    {
155
2.25k
        bottom = ics->num_swb;
156
157
7.48k
        for (f = 0; f < tns->n_filt[w]; f++)
158
5.23k
        {
159
5.23k
            top = bottom;
160
5.23k
            bottom = max(top - tns->length[w][f], 0);
161
5.23k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
162
5.23k
            if (!tns_order)
163
897
                continue;
164
165
4.33k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
166
4.33k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
167
168
4.33k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
169
4.33k
            start = min(start, ics->max_sfb);
170
4.33k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
171
172
4.33k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
173
4.33k
            end = min(end, ics->max_sfb);
174
4.33k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
175
176
4.33k
            size = end - start;
177
4.33k
            if (size <= 0)
178
2.40k
                continue;
179
180
1.93k
            if (tns->direction[w][f])
181
694
            {
182
694
                inc = -1;
183
694
                start = end - 1;
184
1.24k
            } else {
185
1.24k
                inc = 1;
186
1.24k
            }
187
188
1.93k
            tns_ma_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
189
1.93k
        }
190
2.25k
    }
191
2.25k
}
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
32.4k
{
197
32.4k
    uint8_t i, m;
198
32.4k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
32.4k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
32.4k
    real_t* tns_coef = all_tns_coefs[table_index];
201
32.4k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
215k
    for (i = 0; i < order; i++)
205
182k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
32.4k
    a[0] = COEF_CONST(1.0);
209
215k
    for (m = 1; m <= order; m++)
210
182k
    {
211
182k
        a[m] = tmp2[m-1]; /* changed */
212
1.14M
        for (i = 1; i < m; i++) /* loop only while i<m */
213
958k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
1.14M
        for (i = 1; i < m; i++) /* loop only while i<m */
216
958k
            a[i] = b[i];
217
218
#ifdef FIXED_POINT
219
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
91.8k
        if (m < order)
223
75.9k
        {
224
75.9k
            real_t sum_abs = COEF_CONST(0.0);
225
576k
            for (i = 1; i <= m; ++i)
226
500k
            {
227
500k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
500k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
75.9k
            if (sum_abs >= COEF_CONST(3.5))
231
10.6k
            {
232
10.6k
                exp++;
233
120k
                for (i = 1; i <= m; ++i)
234
109k
                {
235
109k
                    a[i] >>= 1;
236
109k
                }
237
10.6k
            }
238
75.9k
        }
239
#endif
240
182k
    }
241
32.4k
    return exp;
242
32.4k
}
tns.c:tns_decode_coef
Line
Count
Source
196
15.8k
{
197
15.8k
    uint8_t i, m;
198
15.8k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
15.8k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
15.8k
    real_t* tns_coef = all_tns_coefs[table_index];
201
15.8k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
107k
    for (i = 0; i < order; i++)
205
91.8k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
15.8k
    a[0] = COEF_CONST(1.0);
209
107k
    for (m = 1; m <= order; m++)
210
91.8k
    {
211
91.8k
        a[m] = tmp2[m-1]; /* changed */
212
592k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
500k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
592k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
500k
            a[i] = b[i];
217
218
91.8k
#ifdef FIXED_POINT
219
91.8k
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
91.8k
        if (m < order)
223
75.9k
        {
224
75.9k
            real_t sum_abs = COEF_CONST(0.0);
225
576k
            for (i = 1; i <= m; ++i)
226
500k
            {
227
500k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
500k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
75.9k
            if (sum_abs >= COEF_CONST(3.5))
231
10.6k
            {
232
10.6k
                exp++;
233
120k
                for (i = 1; i <= m; ++i)
234
109k
                {
235
109k
                    a[i] >>= 1;
236
109k
                }
237
10.6k
            }
238
75.9k
        }
239
91.8k
#endif
240
91.8k
    }
241
15.8k
    return exp;
242
15.8k
}
tns.c:tns_decode_coef
Line
Count
Source
196
16.5k
{
197
16.5k
    uint8_t i, m;
198
16.5k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
16.5k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
16.5k
    real_t* tns_coef = all_tns_coefs[table_index];
201
16.5k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
107k
    for (i = 0; i < order; i++)
205
91.0k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
16.5k
    a[0] = COEF_CONST(1.0);
209
107k
    for (m = 1; m <= order; m++)
210
91.0k
    {
211
91.0k
        a[m] = tmp2[m-1]; /* changed */
212
548k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
457k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
548k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
457k
            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
91.0k
    }
241
16.5k
    return exp;
242
16.5k
}
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
4.65k
{
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
4.65k
    uint8_t j;
257
4.65k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
4.65k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
4.65k
    int8_t state_index = 0;
261
4.65k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
2.19k
    if (exp >= 4)
265
593
        return;
266
1.60k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
267k
    for (i = 0; i < size; i++)
272
263k
    {
273
263k
        real_t y = REAL_CONST(0.0);
274
2.69M
        for (j = 0; j < order; j++)
275
2.43M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
263k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
263k
        state_index--;
280
263k
        if (state_index < 0)
281
52.1k
            state_index = order-1;
282
263k
        state[state_index] = state[state_index + order] = y;
283
284
263k
        *spectrum = y;
285
263k
        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
263k
    }
293
1.60k
}
tns.c:tns_ar_filter
Line
Count
Source
246
2.19k
{
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.19k
    uint8_t j;
257
2.19k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
2.19k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
2.19k
    int8_t state_index = 0;
261
2.19k
    int32_t mul = 1;
262
263
2.19k
#ifdef FIXED_POINT
264
2.19k
    if (exp >= 4)
265
593
        return;
266
1.60k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
111k
    for (i = 0; i < size; i++)
272
109k
    {
273
109k
        real_t y = REAL_CONST(0.0);
274
1.20M
        for (j = 0; j < order; j++)
275
1.10M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
109k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
109k
        state_index--;
280
109k
        if (state_index < 0)
281
21.2k
            state_index = order-1;
282
109k
        state[state_index] = state[state_index + order] = y;
283
284
109k
        *spectrum = y;
285
109k
        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
109k
    }
293
1.60k
}
tns.c:tns_ar_filter
Line
Count
Source
246
2.46k
{
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.46k
    uint8_t j;
257
2.46k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
2.46k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
2.46k
    int8_t state_index = 0;
261
2.46k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
    if (exp >= 4)
265
        return;
266
    mul = 1 << exp;
267
#else
268
2.46k
    (void)exp;
269
2.46k
#endif
270
271
156k
    for (i = 0; i < size; i++)
272
154k
    {
273
154k
        real_t y = REAL_CONST(0.0);
274
1.48M
        for (j = 0; j < order; j++)
275
1.33M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
154k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
154k
        state_index--;
280
154k
        if (state_index < 0)
281
30.8k
            state_index = order-1;
282
154k
        state[state_index] = state[state_index + order] = y;
283
284
154k
        *spectrum = y;
285
154k
        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
154k
    }
293
2.46k
}
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.93k
{
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.93k
    uint8_t j;
308
1.93k
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
1.93k
    real_t state[2*TNS_MAX_ORDER] = {0};
311
1.93k
    int8_t state_index = 0;
312
1.93k
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
782
    if (exp >= 4)
316
179
        return;
317
603
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
40.5k
    for (i = 0; i < size; i++)
323
38.7k
    {
324
38.7k
        real_t y = REAL_CONST(0.0);
325
444k
        for (j = 0; j < order; j++)
326
405k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
38.7k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
38.7k
        state_index--;
332
38.7k
        if (state_index < 0)
333
10.8k
            state_index = order-1;
334
38.7k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
38.7k
        *spectrum = y;
337
38.7k
        spectrum += inc;
338
38.7k
    }
339
603
}
tns.c:tns_ma_filter
Line
Count
Source
297
782
{
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
782
    uint8_t j;
308
782
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
782
    real_t state[2*TNS_MAX_ORDER] = {0};
311
782
    int8_t state_index = 0;
312
782
    int32_t mul = 1;
313
314
782
#ifdef FIXED_POINT
315
782
    if (exp >= 4)
316
179
        return;
317
603
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
7.63k
    for (i = 0; i < size; i++)
323
7.03k
    {
324
7.03k
        real_t y = REAL_CONST(0.0);
325
53.6k
        for (j = 0; j < order; j++)
326
46.5k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
7.03k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
7.03k
        state_index--;
332
7.03k
        if (state_index < 0)
333
3.19k
            state_index = order-1;
334
7.03k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
7.03k
        *spectrum = y;
337
7.03k
        spectrum += inc;
338
7.03k
    }
339
603
}
tns.c:tns_ma_filter
Line
Count
Source
297
1.15k
{
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.15k
    uint8_t j;
308
1.15k
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
1.15k
    real_t state[2*TNS_MAX_ORDER] = {0};
311
1.15k
    int8_t state_index = 0;
312
1.15k
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
    if (exp >= 4)
316
        return;
317
    mul = 1 << exp;
318
#else
319
1.15k
    (void)exp;
320
1.15k
#endif
321
322
32.8k
    for (i = 0; i < size; i++)
323
31.7k
    {
324
31.7k
        real_t y = REAL_CONST(0.0);
325
390k
        for (j = 0; j < order; j++)
326
358k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
31.7k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
31.7k
        state_index--;
332
31.7k
        if (state_index < 0)
333
7.61k
            state_index = order-1;
334
31.7k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
31.7k
        *spectrum = y;
337
31.7k
        spectrum += inc;
338
31.7k
    }
339
1.15k
}