Coverage Report

Created: 2026-12-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/external/faac/libfaad/imdct_window.inc
Line
Count
Source
1
/*
2
 * FAAD - Freeware Advanced Audio Decoder
3
 * Copyright (C) 2026 Nils Schimmelmann
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 */
15
16
/* Body of imdct_window() for one frame length, included once per length with
17
 * IMDCT_FRAME_LEN a literal so the loops and tables fold without relying on
18
 * the compiler to clone a large function. */
19
static void IMDCT_WINDOW_FN(struct faad_decoder *dec, uint8_t window_sequence, uint8_t window_shape,
20
                  uint8_t prev_shape, float * restrict overlap,
21
                  float * restrict spec, float * restrict out_pcm)
22
29.0k
{
23
29.0k
    float * restrict work = dec->scratch->work;
24
29.0k
    const int frame_len_long = IMDCT_FRAME_LEN;
25
29.0k
    int short_len = (frame_len_long == 960) ? 120 : 128;
26
29.0k
    int short_win_len = 2 * short_len;
27
29.0k
    int long_win_len = 2 * frame_len_long;
28
29
29.0k
#ifndef FAAD_DISABLE_DAB
30
18.4E
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
31
18.4E
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
32
18.4E
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
33
18.4E
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
34
#else
35
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
36
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
37
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
38
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
39
#endif
40
41
42
29.0k
    if (window_sequence == EIGHT_SHORT_SEQUENCE) {
43
2.19k
        int n_flat = (frame_len_long - short_len) / 2; /* 448 for 1024, 420 for 960 */
44
2.19k
        int acc_len = 8 * short_len + short_len;       /* 1152 for 1024, 1080 for 960 */
45
2.19k
        float * restrict acc = work;
46
2.19k
        float * restrict block = work + acc_len;
47
2.19k
        float * restrict tmp = work + acc_len + short_win_len;
48
2.19k
        memset(acc, 0, sizeof(float) * acc_len);
49
50
19.7k
        for (int w = 0; w < 8; w++) {
51
17.5k
            fast_imdct(spec + w * short_len, block, short_win_len, tmp);
52
17.5k
            const float * restrict wl = (w == 0) ? win_short_l : win_short;
53
17.5k
            float *dst = acc + w * short_len;
54
2.19M
            for (int i = 0; i < short_len; i++) {
55
2.17M
                dst[i]                       += block[i] * wl[i];
56
2.17M
                dst[short_win_len - 1 - i] += block[short_win_len - 1 - i] * win_short[i];
57
2.17M
            }
58
17.5k
        }
59
60
954k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
61
1.22M
        for (int i = n_flat; i < frame_len_long; i++) out_pcm[i] = acc[i - n_flat] + overlap[i];
62
63
2.19k
        int remaining = acc_len - (frame_len_long - n_flat); /* 576 for 1024, 540 for 960 */
64
1.22M
        for (int i = 0; i < remaining; i++) overlap[i] = acc[i + (frame_len_long - n_flat)];
65
2.19k
        memset(overlap + remaining, 0, sizeof(float) * n_flat);
66
2.19k
        return;
67
2.19k
    }
68
69
26.8k
    float * restrict u = work;
70
26.8k
    const float scale = 2.0f / (float)long_win_len;
71
26.8k
    dct4(spec, work, frame_len_long);
72
73
26.8k
    if (window_sequence == ONLY_LONG_SEQUENCE) {
74
26.3k
        if (frame_len_long == 1024) {
75
12.3k
            imdct_emit_long(out_pcm, overlap, u, scale, win_long_l, win_long);
76
13.9k
        } else {
77
6.71M
            for (int i = 0; i < 480; i++)     out_pcm[i] = u[480 + i] * scale * win_long_l[i] + overlap[i];
78
6.71M
            for (int i = 480; i < 960; i++)   out_pcm[i] = -u[1439 - i] * scale * win_long_l[i] + overlap[i];
79
6.71M
            for (int i = 960; i < 1440; i++)  overlap[i - 960] = -u[1439 - i] * scale * win_long[1919 - i];
80
6.71M
            for (int i = 1440; i < 1920; i++) overlap[i - 960] = -u[i - 1440] * scale * win_long[1919 - i];
81
13.9k
        }
82
26.3k
        return;
83
26.3k
    }
84
85
516
    int n_flat = (frame_len_long - short_len) / 2; /* 448 or 420 */
86
87
516
    if (window_sequence == LONG_STOP_SEQUENCE) {
88
99.4k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
89
229
        imdct_emit(out_pcm, overlap, u, scale, n_flat, n_flat + short_len, win_short_l, 1, 0.0f, frame_len_long);
90
229
        imdct_emit(out_pcm, overlap, u, scale, n_flat + short_len, frame_len_long, NULL, 0, 1.0f, frame_len_long);
91
287
    } else {
92
287
        imdct_emit(out_pcm, overlap, u, scale, 0, frame_len_long, win_long_l, 1, 0.0f, frame_len_long);
93
287
    }
94
95
516
    if (window_sequence == LONG_START_SEQUENCE) {
96
287
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, frame_len_long + n_flat, NULL, 0, 1.0f, frame_len_long);
97
287
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long + n_flat, frame_len_long + n_flat + short_len, win_short, -1, 0.0f, frame_len_long);
98
287
        memset(overlap + (long_win_len - frame_len_long - n_flat), 0, sizeof(float) * n_flat);
99
287
    } else {
100
229
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, long_win_len, win_long, -1, 0.0f, frame_len_long);
101
229
    }
102
516
}
imdct.c:imdct_window_960
Line
Count
Source
22
15.3k
{
23
15.3k
    float * restrict work = dec->scratch->work;
24
15.3k
    const int frame_len_long = IMDCT_FRAME_LEN;
25
15.3k
    int short_len = (frame_len_long == 960) ? 120 : 128;
26
15.3k
    int short_win_len = 2 * short_len;
27
15.3k
    int long_win_len = 2 * frame_len_long;
28
29
15.3k
#ifndef FAAD_DISABLE_DAB
30
18.4E
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
31
18.4E
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
32
18.4E
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
33
18.4E
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
34
#else
35
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
36
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
37
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
38
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
39
#endif
40
41
42
15.3k
    if (window_sequence == EIGHT_SHORT_SEQUENCE) {
43
1.06k
        int n_flat = (frame_len_long - short_len) / 2; /* 448 for 1024, 420 for 960 */
44
1.06k
        int acc_len = 8 * short_len + short_len;       /* 1152 for 1024, 1080 for 960 */
45
1.06k
        float * restrict acc = work;
46
1.06k
        float * restrict block = work + acc_len;
47
1.06k
        float * restrict tmp = work + acc_len + short_win_len;
48
1.06k
        memset(acc, 0, sizeof(float) * acc_len);
49
50
9.61k
        for (int w = 0; w < 8; w++) {
51
8.54k
            fast_imdct(spec + w * short_len, block, short_win_len, tmp);
52
8.54k
            const float * restrict wl = (w == 0) ? win_short_l : win_short;
53
8.54k
            float *dst = acc + w * short_len;
54
1.03M
            for (int i = 0; i < short_len; i++) {
55
1.02M
                dst[i]                       += block[i] * wl[i];
56
1.02M
                dst[short_win_len - 1 - i] += block[short_win_len - 1 - i] * win_short[i];
57
1.02M
            }
58
8.54k
        }
59
60
449k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
61
577k
        for (int i = n_flat; i < frame_len_long; i++) out_pcm[i] = acc[i - n_flat] + overlap[i];
62
63
1.06k
        int remaining = acc_len - (frame_len_long - n_flat); /* 576 for 1024, 540 for 960 */
64
577k
        for (int i = 0; i < remaining; i++) overlap[i] = acc[i + (frame_len_long - n_flat)];
65
1.06k
        memset(overlap + remaining, 0, sizeof(float) * n_flat);
66
1.06k
        return;
67
1.06k
    }
68
69
14.2k
    float * restrict u = work;
70
14.2k
    const float scale = 2.0f / (float)long_win_len;
71
14.2k
    dct4(spec, work, frame_len_long);
72
73
14.2k
    if (window_sequence == ONLY_LONG_SEQUENCE) {
74
13.9k
        if (frame_len_long == 1024) {
75
0
            imdct_emit_long(out_pcm, overlap, u, scale, win_long_l, win_long);
76
13.9k
        } else {
77
6.71M
            for (int i = 0; i < 480; i++)     out_pcm[i] = u[480 + i] * scale * win_long_l[i] + overlap[i];
78
6.71M
            for (int i = 480; i < 960; i++)   out_pcm[i] = -u[1439 - i] * scale * win_long_l[i] + overlap[i];
79
6.71M
            for (int i = 960; i < 1440; i++)  overlap[i - 960] = -u[1439 - i] * scale * win_long[1919 - i];
80
6.71M
            for (int i = 1440; i < 1920; i++) overlap[i - 960] = -u[i - 1440] * scale * win_long[1919 - i];
81
13.9k
        }
82
13.9k
        return;
83
13.9k
    }
84
85
284
    int n_flat = (frame_len_long - short_len) / 2; /* 448 or 420 */
86
87
284
    if (window_sequence == LONG_STOP_SEQUENCE) {
88
50.5k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
89
120
        imdct_emit(out_pcm, overlap, u, scale, n_flat, n_flat + short_len, win_short_l, 1, 0.0f, frame_len_long);
90
120
        imdct_emit(out_pcm, overlap, u, scale, n_flat + short_len, frame_len_long, NULL, 0, 1.0f, frame_len_long);
91
164
    } else {
92
164
        imdct_emit(out_pcm, overlap, u, scale, 0, frame_len_long, win_long_l, 1, 0.0f, frame_len_long);
93
164
    }
94
95
284
    if (window_sequence == LONG_START_SEQUENCE) {
96
164
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, frame_len_long + n_flat, NULL, 0, 1.0f, frame_len_long);
97
164
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long + n_flat, frame_len_long + n_flat + short_len, win_short, -1, 0.0f, frame_len_long);
98
164
        memset(overlap + (long_win_len - frame_len_long - n_flat), 0, sizeof(float) * n_flat);
99
164
    } else {
100
120
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, long_win_len, win_long, -1, 0.0f, frame_len_long);
101
120
    }
102
284
}
imdct.c:imdct_window_1024
Line
Count
Source
22
13.7k
{
23
13.7k
    float * restrict work = dec->scratch->work;
24
13.7k
    const int frame_len_long = IMDCT_FRAME_LEN;
25
13.7k
    int short_len = (frame_len_long == 960) ? 120 : 128;
26
13.7k
    int short_win_len = 2 * short_len;
27
13.7k
    int long_win_len = 2 * frame_len_long;
28
29
13.7k
#ifndef FAAD_DISABLE_DAB
30
13.7k
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
31
13.7k
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
32
13.7k
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_1920 : kbd_window_2048) : ((frame_len_long == 960) ? sine_window_1920 : sine_window_2048);
33
13.7k
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? ((frame_len_long == 960) ? kbd_window_240 : kbd_window_256) : ((frame_len_long == 960) ? sine_window_240 : sine_window_256);
34
#else
35
    const float * restrict win_long_l = (prev_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
36
    const float * restrict win_short_l = (prev_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
37
    const float * restrict win_long = (window_shape == KBD_WINDOW) ? kbd_window_2048 : sine_window_2048;
38
    const float * restrict win_short = (window_shape == KBD_WINDOW) ? kbd_window_256 : sine_window_256;
39
#endif
40
41
42
13.7k
    if (window_sequence == EIGHT_SHORT_SEQUENCE) {
43
1.12k
        int n_flat = (frame_len_long - short_len) / 2; /* 448 for 1024, 420 for 960 */
44
1.12k
        int acc_len = 8 * short_len + short_len;       /* 1152 for 1024, 1080 for 960 */
45
1.12k
        float * restrict acc = work;
46
1.12k
        float * restrict block = work + acc_len;
47
1.12k
        float * restrict tmp = work + acc_len + short_win_len;
48
1.12k
        memset(acc, 0, sizeof(float) * acc_len);
49
50
10.1k
        for (int w = 0; w < 8; w++) {
51
8.99k
            fast_imdct(spec + w * short_len, block, short_win_len, tmp);
52
8.99k
            const float * restrict wl = (w == 0) ? win_short_l : win_short;
53
8.99k
            float *dst = acc + w * short_len;
54
1.15M
            for (int i = 0; i < short_len; i++) {
55
1.15M
                dst[i]                       += block[i] * wl[i];
56
1.15M
                dst[short_win_len - 1 - i] += block[short_win_len - 1 - i] * win_short[i];
57
1.15M
            }
58
8.99k
        }
59
60
504k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
61
648k
        for (int i = n_flat; i < frame_len_long; i++) out_pcm[i] = acc[i - n_flat] + overlap[i];
62
63
1.12k
        int remaining = acc_len - (frame_len_long - n_flat); /* 576 for 1024, 540 for 960 */
64
648k
        for (int i = 0; i < remaining; i++) overlap[i] = acc[i + (frame_len_long - n_flat)];
65
1.12k
        memset(overlap + remaining, 0, sizeof(float) * n_flat);
66
1.12k
        return;
67
1.12k
    }
68
69
12.5k
    float * restrict u = work;
70
12.5k
    const float scale = 2.0f / (float)long_win_len;
71
12.5k
    dct4(spec, work, frame_len_long);
72
73
12.5k
    if (window_sequence == ONLY_LONG_SEQUENCE) {
74
12.3k
        if (frame_len_long == 1024) {
75
12.3k
            imdct_emit_long(out_pcm, overlap, u, scale, win_long_l, win_long);
76
12.3k
        } else {
77
0
            for (int i = 0; i < 480; i++)     out_pcm[i] = u[480 + i] * scale * win_long_l[i] + overlap[i];
78
0
            for (int i = 480; i < 960; i++)   out_pcm[i] = -u[1439 - i] * scale * win_long_l[i] + overlap[i];
79
0
            for (int i = 960; i < 1440; i++)  overlap[i - 960] = -u[1439 - i] * scale * win_long[1919 - i];
80
0
            for (int i = 1440; i < 1920; i++) overlap[i - 960] = -u[i - 1440] * scale * win_long[1919 - i];
81
0
        }
82
12.3k
        return;
83
12.3k
    }
84
85
232
    int n_flat = (frame_len_long - short_len) / 2; /* 448 or 420 */
86
87
232
    if (window_sequence == LONG_STOP_SEQUENCE) {
88
48.9k
        for (int i = 0; i < n_flat; i++) out_pcm[i] = overlap[i];
89
109
        imdct_emit(out_pcm, overlap, u, scale, n_flat, n_flat + short_len, win_short_l, 1, 0.0f, frame_len_long);
90
109
        imdct_emit(out_pcm, overlap, u, scale, n_flat + short_len, frame_len_long, NULL, 0, 1.0f, frame_len_long);
91
123
    } else {
92
123
        imdct_emit(out_pcm, overlap, u, scale, 0, frame_len_long, win_long_l, 1, 0.0f, frame_len_long);
93
123
    }
94
95
232
    if (window_sequence == LONG_START_SEQUENCE) {
96
123
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, frame_len_long + n_flat, NULL, 0, 1.0f, frame_len_long);
97
123
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long + n_flat, frame_len_long + n_flat + short_len, win_short, -1, 0.0f, frame_len_long);
98
123
        memset(overlap + (long_win_len - frame_len_long - n_flat), 0, sizeof(float) * n_flat);
99
123
    } else {
100
109
        imdct_emit(out_pcm, overlap, u, scale, frame_len_long, long_win_len, win_long, -1, 0.0f, frame_len_long);
101
109
    }
102
232
}