Coverage Report

Created: 2026-03-20 06:59

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
673k
{
87
673k
    uint8_t w, f, tns_order;
88
673k
    int8_t inc;
89
673k
    int16_t size;
90
673k
    uint16_t bottom, top, start, end;
91
673k
    uint16_t nshort = frame_len/8;
92
673k
    real_t lpc[TNS_MAX_ORDER+1];
93
673k
    uint8_t exp;
94
95
673k
    if (!ics->tns_data_present)
96
630k
        return;
97
98
128k
    for (w = 0; w < ics->num_windows; w++)
99
84.8k
    {
100
84.8k
        bottom = ics->num_swb;
101
102
126k
        for (f = 0; f < tns->n_filt[w]; f++)
103
41.7k
        {
104
41.7k
            top = bottom;
105
41.7k
            bottom = max(top - tns->length[w][f], 0);
106
41.7k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
107
41.7k
            if (!tns_order)
108
17.0k
                continue;
109
110
24.6k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
111
24.6k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
112
113
24.6k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
114
24.6k
            start = min(start, ics->max_sfb);
115
24.6k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
116
117
24.6k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
118
24.6k
            end = min(end, ics->max_sfb);
119
24.6k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
120
121
24.6k
            size = end - start;
122
24.6k
            if (size <= 0)
123
20.8k
                continue;
124
125
3.88k
            if (tns->direction[w][f])
126
2.60k
            {
127
2.60k
                inc = -1;
128
2.60k
                start = end - 1;
129
2.60k
            } else {
130
1.27k
                inc = 1;
131
1.27k
            }
132
133
3.88k
            tns_ar_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
134
3.88k
        }
135
84.8k
    }
136
43.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
13.8k
{
142
13.8k
    uint8_t w, f, tns_order;
143
13.8k
    int8_t inc;
144
13.8k
    int16_t size;
145
13.8k
    uint16_t bottom, top, start, end;
146
13.8k
    uint16_t nshort = frame_len/8;
147
13.8k
    real_t lpc[TNS_MAX_ORDER+1];
148
13.8k
    uint8_t exp;
149
150
13.8k
    if (!ics->tns_data_present)
151
11.6k
        return;
152
153
4.28k
    for (w = 0; w < ics->num_windows; w++)
154
2.14k
    {
155
2.14k
        bottom = ics->num_swb;
156
157
7.24k
        for (f = 0; f < tns->n_filt[w]; f++)
158
5.10k
        {
159
5.10k
            top = bottom;
160
5.10k
            bottom = max(top - tns->length[w][f], 0);
161
5.10k
            tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
162
5.10k
            if (!tns_order)
163
1.11k
                continue;
164
165
3.99k
            exp = tns_decode_coef(tns_order, tns->coef_res[w]+3,
166
3.99k
                tns->coef_compress[w][f], tns->coef[w][f], lpc);
167
168
3.99k
            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
169
3.99k
            start = min(start, ics->max_sfb);
170
3.99k
            start = min(ics->swb_offset[start], ics->swb_offset_max);
171
172
3.99k
            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
173
3.99k
            end = min(end, ics->max_sfb);
174
3.99k
            end = min(ics->swb_offset[end], ics->swb_offset_max);
175
176
3.99k
            size = end - start;
177
3.99k
            if (size <= 0)
178
2.45k
                continue;
179
180
1.54k
            if (tns->direction[w][f])
181
1.02k
            {
182
1.02k
                inc = -1;
183
1.02k
                start = end - 1;
184
1.02k
            } else {
185
518
                inc = 1;
186
518
            }
187
188
1.54k
            tns_ma_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order, exp);
189
1.54k
        }
190
2.14k
    }
191
2.14k
}
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
28.6k
{
197
28.6k
    uint8_t i, m;
198
28.6k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
28.6k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
28.6k
    real_t* tns_coef = all_tns_coefs[table_index];
201
28.6k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
204k
    for (i = 0; i < order; i++)
205
175k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
28.6k
    a[0] = COEF_CONST(1.0);
209
204k
    for (m = 1; m <= order; m++)
210
175k
    {
211
175k
        a[m] = tmp2[m-1]; /* changed */
212
1.19M
        for (i = 1; i < m; i++) /* loop only while i<m */
213
1.02M
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
1.19M
        for (i = 1; i < m; i++) /* loop only while i<m */
216
1.02M
            a[i] = b[i];
217
218
#ifdef FIXED_POINT
219
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
85.1k
        if (m < order)
223
70.2k
        {
224
70.2k
            real_t sum_abs = COEF_CONST(0.0);
225
538k
            for (i = 1; i <= m; ++i)
226
467k
            {
227
467k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
467k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
70.2k
            if (sum_abs >= COEF_CONST(3.5))
231
9.21k
            {
232
9.21k
                exp++;
233
106k
                for (i = 1; i <= m; ++i)
234
97.3k
                {
235
97.3k
                    a[i] >>= 1;
236
97.3k
                }
237
9.21k
            }
238
70.2k
        }
239
#endif
240
175k
    }
241
28.6k
    return exp;
242
28.6k
}
tns.c:tns_decode_coef
Line
Count
Source
196
14.8k
{
197
14.8k
    uint8_t i, m;
198
14.8k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
14.8k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
14.8k
    real_t* tns_coef = all_tns_coefs[table_index];
201
14.8k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
100k
    for (i = 0; i < order; i++)
205
85.1k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
14.8k
    a[0] = COEF_CONST(1.0);
209
100k
    for (m = 1; m <= order; m++)
210
85.1k
    {
211
85.1k
        a[m] = tmp2[m-1]; /* changed */
212
553k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
467k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
553k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
467k
            a[i] = b[i];
217
218
85.1k
#ifdef FIXED_POINT
219
85.1k
        a[m] >>= exp;
220
221
        /* OK not to check after the last iteration. */
222
85.1k
        if (m < order)
223
70.2k
        {
224
70.2k
            real_t sum_abs = COEF_CONST(0.0);
225
538k
            for (i = 1; i <= m; ++i)
226
467k
            {
227
467k
                sum_abs += (a[i] >= 0) ? a[i] : -a[i];
228
467k
            }
229
            /* Next iteration would turn sum to 2*sum + 1; maximal "coef" is 7.999 */
230
70.2k
            if (sum_abs >= COEF_CONST(3.5))
231
9.21k
            {
232
9.21k
                exp++;
233
106k
                for (i = 1; i <= m; ++i)
234
97.3k
                {
235
97.3k
                    a[i] >>= 1;
236
97.3k
                }
237
9.21k
            }
238
70.2k
        }
239
85.1k
#endif
240
85.1k
    }
241
14.8k
    return exp;
242
14.8k
}
tns.c:tns_decode_coef
Line
Count
Source
196
13.8k
{
197
13.8k
    uint8_t i, m;
198
13.8k
    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
199
13.8k
    uint8_t table_index = 2 * (coef_compress != 0) + (coef_res_bits != 3);
200
13.8k
    real_t* tns_coef = all_tns_coefs[table_index];
201
13.8k
    uint8_t exp = 0;
202
203
    /* Conversion to signed integer */
204
104k
    for (i = 0; i < order; i++)
205
90.5k
        tmp2[i] = tns_coef[coef[i]];
206
207
    /* Conversion to LPC coefficients */
208
13.8k
    a[0] = COEF_CONST(1.0);
209
104k
    for (m = 1; m <= order; m++)
210
90.5k
    {
211
90.5k
        a[m] = tmp2[m-1]; /* changed */
212
646k
        for (i = 1; i < m; i++) /* loop only while i<m */
213
555k
            b[i] = a[i] + MUL_C(a[m], a[m-i]);
214
215
646k
        for (i = 1; i < m; i++) /* loop only while i<m */
216
555k
            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
90.5k
    }
241
13.8k
    return exp;
242
13.8k
}
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
3.88k
{
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
3.88k
    uint8_t j;
257
3.88k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
3.88k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
3.88k
    int8_t state_index = 0;
261
3.88k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
1.96k
    if (exp >= 4)
265
507
        return;
266
1.45k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
214k
    for (i = 0; i < size; i++)
272
211k
    {
273
211k
        real_t y = REAL_CONST(0.0);
274
2.04M
        for (j = 0; j < order; j++)
275
1.83M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
211k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
211k
        state_index--;
280
211k
        if (state_index < 0)
281
44.9k
            state_index = order-1;
282
211k
        state[state_index] = state[state_index + order] = y;
283
284
211k
        *spectrum = y;
285
211k
        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
211k
    }
293
1.45k
}
tns.c:tns_ar_filter
Line
Count
Source
246
1.96k
{
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
1.96k
    uint8_t j;
257
1.96k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
1.96k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
1.96k
    int8_t state_index = 0;
261
1.96k
    int32_t mul = 1;
262
263
1.96k
#ifdef FIXED_POINT
264
1.96k
    if (exp >= 4)
265
507
        return;
266
1.45k
    mul = 1 << exp;
267
#else
268
    (void)exp;
269
#endif
270
271
75.4k
    for (i = 0; i < size; i++)
272
73.9k
    {
273
73.9k
        real_t y = REAL_CONST(0.0);
274
680k
        for (j = 0; j < order; j++)
275
606k
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
73.9k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
73.9k
        state_index--;
280
73.9k
        if (state_index < 0)
281
18.0k
            state_index = order-1;
282
73.9k
        state[state_index] = state[state_index + order] = y;
283
284
73.9k
        *spectrum = y;
285
73.9k
        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
73.9k
    }
293
1.45k
}
tns.c:tns_ar_filter
Line
Count
Source
246
1.92k
{
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
1.92k
    uint8_t j;
257
1.92k
    uint16_t i;
258
    /* state is stored as a double ringbuffer */
259
1.92k
    real_t state[2*TNS_MAX_ORDER] = {0};
260
1.92k
    int8_t state_index = 0;
261
1.92k
    int32_t mul = 1;
262
263
#ifdef FIXED_POINT
264
    if (exp >= 4)
265
        return;
266
    mul = 1 << exp;
267
#else
268
1.92k
    (void)exp;
269
1.92k
#endif
270
271
139k
    for (i = 0; i < size; i++)
272
137k
    {
273
137k
        real_t y = REAL_CONST(0.0);
274
1.36M
        for (j = 0; j < order; j++)
275
1.23M
            y += MUL_C(state[state_index+j], lpc[j+1]);
276
137k
        y = *spectrum - (y * mul);
277
278
        /* double ringbuffer state */
279
137k
        state_index--;
280
137k
        if (state_index < 0)
281
26.8k
            state_index = order-1;
282
137k
        state[state_index] = state[state_index + order] = y;
283
284
137k
        *spectrum = y;
285
137k
        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
137k
    }
293
1.92k
}
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.54k
{
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.54k
    uint8_t j;
308
1.54k
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
1.54k
    real_t state[2*TNS_MAX_ORDER] = {0};
311
1.54k
    int8_t state_index = 0;
312
1.54k
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
702
    if (exp >= 4)
316
183
        return;
317
519
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
30.4k
    for (i = 0; i < size; i++)
323
29.1k
    {
324
29.1k
        real_t y = REAL_CONST(0.0);
325
431k
        for (j = 0; j < order; j++)
326
402k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
29.1k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
29.1k
        state_index--;
332
29.1k
        if (state_index < 0)
333
6.34k
            state_index = order-1;
334
29.1k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
29.1k
        *spectrum = y;
337
29.1k
        spectrum += inc;
338
29.1k
    }
339
519
}
tns.c:tns_ma_filter
Line
Count
Source
297
702
{
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
702
    uint8_t j;
308
702
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
702
    real_t state[2*TNS_MAX_ORDER] = {0};
311
702
    int8_t state_index = 0;
312
702
    int32_t mul = 1;
313
314
702
#ifdef FIXED_POINT
315
702
    if (exp >= 4)
316
183
        return;
317
519
    mul = 1 << exp;
318
#else
319
    (void)exp;
320
#endif
321
322
9.79k
    for (i = 0; i < size; i++)
323
9.28k
    {
324
9.28k
        real_t y = REAL_CONST(0.0);
325
104k
        for (j = 0; j < order; j++)
326
95.3k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
9.28k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
9.28k
        state_index--;
332
9.28k
        if (state_index < 0)
333
3.03k
            state_index = order-1;
334
9.28k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
9.28k
        *spectrum = y;
337
9.28k
        spectrum += inc;
338
9.28k
    }
339
519
}
tns.c:tns_ma_filter
Line
Count
Source
297
839
{
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
839
    uint8_t j;
308
839
    uint16_t i;
309
    /* state is stored as a double ringbuffer */
310
839
    real_t state[2*TNS_MAX_ORDER] = {0};
311
839
    int8_t state_index = 0;
312
839
    int32_t mul = 1;
313
314
#ifdef FIXED_POINT
315
    if (exp >= 4)
316
        return;
317
    mul = 1 << exp;
318
#else
319
839
    (void)exp;
320
839
#endif
321
322
20.6k
    for (i = 0; i < size; i++)
323
19.8k
    {
324
19.8k
        real_t y = REAL_CONST(0.0);
325
326k
        for (j = 0; j < order; j++)
326
306k
            y += MUL_C(state[state_index+j], lpc[j+1]);
327
328
19.8k
        y = *spectrum + (y * mul);
329
330
        /* double ringbuffer state */
331
19.8k
        state_index--;
332
19.8k
        if (state_index < 0)
333
3.30k
            state_index = order-1;
334
19.8k
        state[state_index] = state[state_index + order] = *spectrum;
335
336
19.8k
        *spectrum = y;
337
19.8k
        spectrum += inc;
338
19.8k
    }
339
839
}