Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/mpegaudiodsp.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2011 Mans Rullgard
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#include "config.h"
22
#include "libavutil/attributes.h"
23
#include "libavutil/thread.h"
24
#include "mpegaudio.h"
25
#include "mpegaudiodsp.h"
26
#include "dct32.h"
27
28
static AVOnce mpadsp_table_init = AV_ONCE_INIT;
29
30
static av_cold void mpadsp_init_tabs(void)
31
14
{
32
14
    int i, j;
33
    /* compute mdct windows */
34
518
    for (i = 0; i < 36; i++) {
35
2.52k
        for (j = 0; j < 4; j++) {
36
2.01k
            double d;
37
38
2.01k
            if (j == 2 && i % 3 != 1)
39
336
                continue;
40
41
1.68k
            d = sin(M_PI * (i + 0.5) / 36.0);
42
1.68k
            if (j == 1) {
43
504
                if      (i >= 30) d = 0;
44
420
                else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0);
45
336
                else if (i >= 18) d = 1;
46
1.17k
            } else if (j == 3) {
47
504
                if      (i <   6) d = 0;
48
420
                else if (i <  12) d = sin(M_PI * (i -  6 + 0.5) / 12.0);
49
336
                else if (i <  18) d = 1;
50
504
            }
51
            //merge last stage of imdct into the window coefficients
52
1.68k
            d *= 0.5 * IMDCT_SCALAR / cos(M_PI * (2 * i + 19) / 72);
53
54
1.68k
            if (j == 2) {
55
168
                ff_mdct_win_float[j][i/3] = d / (1 << 5);
56
168
                ff_mdct_win_fixed[j][i/3] = d / (1 << 5) * (1LL << 32) + 0.5;
57
1.51k
            } else {
58
1.51k
                int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18);
59
1.51k
                ff_mdct_win_float[j][idx] = d / (1 << 5);
60
1.51k
                ff_mdct_win_fixed[j][idx] = d / (1 << 5) * (1LL << 32) + 0.5;
61
1.51k
            }
62
1.68k
        }
63
504
    }
64
65
    /* NOTE: we do frequency inversion after the MDCT by changing
66
        the sign of the right window coefs */
67
70
    for (j = 0; j < 4; j++) {
68
1.17k
        for (i = 0; i < MDCT_BUF_SIZE; i += 2) {
69
1.12k
            ff_mdct_win_float[j + 4][i    ] =  ff_mdct_win_float[j][i    ];
70
1.12k
            ff_mdct_win_float[j + 4][i + 1] = -ff_mdct_win_float[j][i + 1];
71
1.12k
            ff_mdct_win_fixed[j + 4][i    ] =  ff_mdct_win_fixed[j][i    ];
72
1.12k
            ff_mdct_win_fixed[j + 4][i + 1] = -ff_mdct_win_fixed[j][i + 1];
73
1.12k
        }
74
56
    }
75
76
14
#if ARCH_X86
77
14
    ff_mpadsp_init_x86_tabs();
78
14
#endif
79
14
}
80
81
av_cold void ff_mpadsp_init(MPADSPContext *s)
82
34.4k
{
83
34.4k
    ff_thread_once(&mpadsp_table_init, &mpadsp_init_tabs);
84
85
34.4k
    s->apply_window_float = ff_mpadsp_apply_window_float;
86
34.4k
    s->apply_window_fixed = ff_mpadsp_apply_window_fixed;
87
88
34.4k
    s->dct32_float = ff_dct32_float;
89
34.4k
    s->dct32_fixed = ff_dct32_fixed;
90
91
34.4k
    s->imdct36_blocks_float = ff_imdct36_blocks_float;
92
34.4k
    s->imdct36_blocks_fixed = ff_imdct36_blocks_fixed;
93
94
#if ARCH_AARCH64
95
    ff_mpadsp_init_aarch64(s);
96
#elif ARCH_ARM
97
    ff_mpadsp_init_arm(s);
98
#elif ARCH_PPC
99
    ff_mpadsp_init_ppc(s);
100
#elif ARCH_X86
101
    ff_mpadsp_init_x86(s);
102
34.4k
#endif
103
#if HAVE_MIPSFPU
104
    ff_mpadsp_init_mipsfpu(s);
105
#endif
106
#if HAVE_MIPSDSP
107
    ff_mpadsp_init_mipsdsp(s);
108
#endif
109
34.4k
}