Coverage Report

Created: 2026-02-14 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/sbr_tf_grid.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: sbr_tf_grid.c,v 1.20 2008/09/19 22:50:20 menno Exp $
29
**/
30
31
/* Time/Frequency grid */
32
33
#include "common.h"
34
#include "structs.h"
35
36
#ifdef SBR_DEC
37
38
#include <stdlib.h>
39
40
#include "sbr_syntax.h"
41
#include "sbr_tf_grid.h"
42
43
44
/* static function declarations */
45
#if 0
46
static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l);
47
static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l);
48
#endif
49
static uint8_t middleBorder(sbr_info *sbr, uint8_t ch);
50
51
52
/* function constructs new time border vector */
53
/* first build into temp vector to be able to use previous vector on error */
54
uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
55
83.5k
{
56
83.5k
    uint8_t l, border, temp, trail;
57
83.5k
    uint8_t t_E_temp[6] = {0};
58
59
83.5k
    trail = sbr->abs_bord_trail[ch];
60
83.5k
    t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch];
61
83.5k
    t_E_temp[sbr->L_E[ch]] = sbr->rate * trail;
62
63
83.5k
    switch (sbr->bs_frame_class[ch])
64
83.5k
    {
65
29.8k
    case FIXFIX:
66
29.8k
        switch (sbr->L_E[ch])
67
29.8k
        {
68
4.95k
        case 4:
69
4.95k
            temp = (sbr->numTimeSlots / 4);
70
4.95k
            t_E_temp[3] = sbr->rate * 3 * temp;
71
4.95k
            t_E_temp[2] = sbr->rate * 2 * temp;
72
4.95k
            t_E_temp[1] = sbr->rate * temp;
73
4.95k
            break;
74
4.70k
        case 2:
75
4.70k
            t_E_temp[1] = sbr->rate * (sbr->numTimeSlots / 2);
76
4.70k
            break;
77
20.2k
        default:
78
20.2k
            break;
79
29.8k
        }
80
29.8k
        break;
81
82
29.8k
    case FIXVAR:
83
16.7k
        if (sbr->L_E[ch] > 1)
84
7.70k
        {
85
7.70k
            int8_t i = sbr->L_E[ch];
86
7.70k
            border = sbr->abs_bord_trail[ch];
87
88
24.4k
            for (l = 0; l < (sbr->L_E[ch] - 1); l++)
89
17.2k
            {
90
17.2k
                if (border < sbr->bs_rel_bord[ch][l])
91
565
                    return 1;
92
93
16.7k
                border -= sbr->bs_rel_bord[ch][l];
94
16.7k
                t_E_temp[--i] = sbr->rate * border;
95
16.7k
            }
96
7.70k
        }
97
16.1k
        break;
98
99
19.2k
    case VARFIX:
100
19.2k
        if (sbr->L_E[ch] > 1)
101
9.99k
        {
102
9.99k
            int8_t i = 1;
103
9.99k
            border = sbr->abs_bord_lead[ch];
104
105
29.3k
            for (l = 0; l < (sbr->L_E[ch] - 1); l++)
106
20.3k
            {
107
20.3k
                border += sbr->bs_rel_bord[ch][l];
108
109
20.3k
                if (border > trail)
110
1.06k
                    return 1;
111
112
19.3k
                t_E_temp[i++] = sbr->rate * border;
113
19.3k
            }
114
9.99k
        }
115
18.1k
        break;
116
117
18.1k
    case VARVAR:
118
17.6k
        if (sbr->bs_num_rel_0[ch])
119
11.5k
        {
120
11.5k
            int8_t i = 1;
121
11.5k
            border = sbr->abs_bord_lead[ch];
122
123
37.7k
            for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
124
27.1k
            {
125
27.1k
                border += sbr->bs_rel_bord_0[ch][l];
126
127
27.1k
                if (border > trail)
128
920
                    return 1;
129
130
26.2k
                t_E_temp[i++] = sbr->rate * border;
131
26.2k
            }
132
11.5k
        }
133
134
16.7k
        if (sbr->bs_num_rel_1[ch])
135
12.1k
        {
136
12.1k
            int8_t i = sbr->L_E[ch];
137
12.1k
            border = sbr->abs_bord_trail[ch];
138
139
38.6k
            for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
140
27.4k
            {
141
27.4k
                if (border < sbr->bs_rel_bord_1[ch][l])
142
1.00k
                    return 1;
143
144
26.4k
                border -= sbr->bs_rel_bord_1[ch][l];
145
26.4k
                t_E_temp[--i] = sbr->rate * border;
146
26.4k
            }
147
12.1k
        }
148
15.7k
        break;
149
83.5k
    }
150
151
    /* no error occured, we can safely use this t_E vector */
152
559k
    for (l = 0; l < 6; l++)
153
479k
    {
154
479k
        sbr->t_E[ch][l] = t_E_temp[l];
155
479k
    }
156
157
79.9k
    return 0;
158
83.5k
}
159
160
void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
161
79.9k
{
162
79.9k
    sbr->t_Q[ch][0] = sbr->t_E[ch][0];
163
164
79.9k
    if (sbr->L_E[ch] == 1)
165
41.1k
    {
166
41.1k
        sbr->t_Q[ch][1] = sbr->t_E[ch][1];
167
41.1k
        sbr->t_Q[ch][2] = 0;
168
41.1k
    } else {
169
38.7k
        uint8_t index = middleBorder(sbr, ch);
170
38.7k
        sbr->t_Q[ch][1] = sbr->t_E[ch][index];
171
38.7k
        sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
172
38.7k
    }
173
79.9k
}
174
175
#if 0
176
static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
177
{
178
    uint8_t i;
179
    int16_t acc = 0;
180
181
    switch (sbr->bs_frame_class[ch])
182
    {
183
    case FIXFIX:
184
        return sbr->numTimeSlots/sbr->L_E[ch];
185
    case FIXVAR:
186
        return 0;
187
    case VARFIX:
188
        for (i = 0; i < l; i++)
189
        {
190
            acc += sbr->bs_rel_bord[ch][i];
191
        }
192
        return acc;
193
    case VARVAR:
194
        for (i = 0; i < l; i++)
195
        {
196
            acc += sbr->bs_rel_bord_0[ch][i];
197
        }
198
        return acc;
199
    }
200
201
    return 0;
202
}
203
204
static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
205
{
206
    uint8_t i;
207
    int16_t acc = 0;
208
209
    switch (sbr->bs_frame_class[ch])
210
    {
211
    case FIXFIX:
212
    case VARFIX:
213
        return 0;
214
    case FIXVAR:
215
        for (i = 0; i < l; i++)
216
        {
217
            acc += sbr->bs_rel_bord[ch][i];
218
        }
219
        return acc;
220
    case VARVAR:
221
        for (i = 0; i < l; i++)
222
        {
223
            acc += sbr->bs_rel_bord_1[ch][i];
224
        }
225
        return acc;
226
    }
227
228
    return 0;
229
}
230
#endif
231
232
static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
233
38.7k
{
234
38.7k
    int8_t retval = 0;
235
236
38.7k
    switch (sbr->bs_frame_class[ch])
237
38.7k
    {
238
9.66k
    case FIXFIX:
239
9.66k
        retval = sbr->L_E[ch]/2;
240
9.66k
        break;
241
8.92k
    case VARFIX:
242
8.92k
        if (sbr->bs_pointer[ch] == 0)
243
2.83k
            retval = 1;
244
6.09k
        else if (sbr->bs_pointer[ch] == 1)
245
2.32k
            retval = sbr->L_E[ch] - 1;
246
3.77k
        else
247
3.77k
            retval = sbr->bs_pointer[ch] - 1;
248
8.92k
        break;
249
7.14k
    case FIXVAR:
250
20.2k
    case VARVAR:
251
20.2k
        if (sbr->bs_pointer[ch] > 1)
252
7.45k
            retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
253
12.7k
        else
254
12.7k
            retval = sbr->L_E[ch] - 1;
255
20.2k
        break;
256
38.7k
    }
257
258
38.7k
    return (retval > 0) ? retval : 0;
259
38.7k
}
260
261
262
#endif