Coverage Report

Created: 2025-11-24 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libldac/src/quant_ldac.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2003 - 2016 Sony Corporation
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "ldac.h"
18
19
/***************************************************************************************************
20
    Subfunction: Get Scale Factor Index
21
***************************************************************************************************/
22
__inline static int get_scale_factor_id_ldac(
23
SCALAR val)
24
1.14k
{
25
1.14k
    int id;
26
1.14k
    IEEE754_FI fi;
27
28
1.14k
    fi.f = val;
29
1.14k
    id = ((fi.i & 0x7fffffff) >> 23) - 111;
30
31
1.14k
    if (id < 0) {
32
0
        id = 0;
33
0
    }
34
1.14k
    if (id > LDAC_NIDSF-1) {
35
0
        id = LDAC_NIDSF-1;
36
0
    }
37
38
1.14k
    return id;
39
1.14k
}
40
41
/***************************************************************************************************
42
    Normalize Spectrum
43
***************************************************************************************************/
44
static SCALAR sa_val_ldac[LDAC_MAXNSPS] = {
45
    -0.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
46
};
47
48
DECLFUNC void norm_spectrum_ldac(
49
AC *p_ac)
50
44
{
51
44
    int iqu, isp;
52
44
    int lsp, hsp;
53
44
    int nqus = p_ac->p_ab->nqus;
54
44
    int idsf;
55
44
    int *p_idsf = p_ac->a_idsf;
56
44
    SCALAR maxspec, tmp;
57
44
    SCALAR *p_spec = p_ac->p_acsub->a_spec;
58
59
1.18k
    for (iqu = 0; iqu < nqus; iqu++) {
60
1.14k
        lsp = ga_isp_ldac[iqu];
61
1.14k
        hsp = ga_isp_ldac[iqu+1];
62
63
1.14k
        maxspec = fabs(p_spec[lsp]);
64
5.63k
        for (isp = lsp+1; isp < hsp; isp++) {
65
4.48k
            tmp = fabs(p_spec[isp]);
66
4.48k
            if (maxspec < tmp) {
67
1.56k
                maxspec = tmp;
68
1.56k
            }
69
4.48k
        }
70
1.14k
        idsf = get_scale_factor_id_ldac(maxspec);
71
72
1.14k
        if (idsf > 0) {
73
1.14k
            tmp = ga_isf_ldac[idsf];
74
6.77k
            for (isp = lsp; isp < hsp; isp++) {
75
5.63k
                p_spec[isp] *= tmp;
76
5.63k
            }
77
1.14k
        }
78
0
        else {
79
0
            for (isp = lsp; isp < hsp; isp++) {
80
0
                p_spec[isp] = sa_val_ldac[isp-lsp];
81
0
            }
82
0
        }
83
84
1.14k
        p_idsf[iqu] = idsf;
85
1.14k
    }
86
87
44
    return;
88
44
}
89
90
/***************************************************************************************************
91
    Subfunction: Quantize Spectrum Core
92
***************************************************************************************************/
93
__inline static void quant_spectrum_core_ldac(
94
AC *p_ac,
95
int iqu)
96
1.14k
{
97
1.14k
    int i;
98
1.14k
    int isp = ga_isp_ldac[iqu];
99
1.14k
    int nsps = ga_nsps_ldac[iqu];
100
1.14k
    int *p_qspec = p_ac->a_qspec+isp;
101
1.14k
    SCALAR qf = ga_qf_ldac[p_ac->a_idwl1[iqu]];
102
1.14k
    SCALAR *p_nspec = p_ac->p_acsub->a_spec+isp;
103
104
1.14k
    IEEE754_FI fi;
105
1.14k
    const float fc = (float)((1 << 23) + (1 << 22));
106
107
6.77k
    for (i = 0; i < nsps; i++) {
108
5.63k
        fi.f = p_nspec[i] * qf + fc;
109
5.63k
        p_qspec[i] = (short)fi.i;
110
5.63k
    }
111
112
1.14k
    return;
113
1.14k
}
114
115
/***************************************************************************************************
116
    Quantize Spectrum
117
***************************************************************************************************/
118
DECLFUNC void quant_spectrum_ldac(
119
AC *p_ac)
120
44
{
121
44
    int iqu;
122
44
    int nqus = p_ac->p_ab->nqus;
123
124
1.18k
    for (iqu = 0; iqu < nqus; iqu++) {
125
1.14k
        quant_spectrum_core_ldac(p_ac, iqu);
126
1.14k
    }
127
128
44
    return;
129
44
}
130
131
/***************************************************************************************************
132
    Subfunction: Quantize Residual Spectrum Core
133
***************************************************************************************************/
134
__inline static void quant_residual_core_ldac(
135
AC *p_ac,
136
int iqu)
137
0
{
138
0
    int i;
139
0
    int isp = ga_isp_ldac[iqu];
140
0
    int nsps = ga_nsps_ldac[iqu];
141
0
    int *p_qspec = p_ac->a_qspec+isp;
142
0
    int *p_rspec = p_ac->a_rspec+isp;
143
0
    SCALAR ldqspec;
144
0
    SCALAR iqf = ga_iqf_ldac[LDAC_MAXIDWL1];
145
0
    SCALAR rqsf = ga_qf_ldac[p_ac->a_idwl2[iqu]] * ga_irsf_ldac[LDAC_MAXIDWL1]
146
0
            * _scalar(0.996093750);
147
0
    SCALAR *p_nspec = p_ac->p_acsub->a_spec+isp;
148
149
0
    IEEE754_FI fi;
150
0
    const float fc = (float)((1 << 23) + (1 << 22));
151
152
0
    for (i = 0; i < nsps; i++) {
153
0
        ldqspec = p_qspec[i] * iqf;
154
0
        fi.f = (p_nspec[i] - ldqspec) * rqsf + fc;
155
0
        p_rspec[i] = (short)fi.i;
156
0
    }
157
158
0
    return;
159
0
}
160
161
/***************************************************************************************************
162
    Quantize Residual Spectrum
163
***************************************************************************************************/
164
DECLFUNC void quant_residual_ldac(
165
AC *p_ac)
166
44
{
167
44
    int iqu;
168
44
    int nqus = p_ac->p_ab->nqus;
169
44
    int *p_idwl2 = p_ac->a_idwl2;
170
171
1.18k
    for (iqu = 0; iqu < nqus; iqu++) {
172
1.14k
        if (p_idwl2[iqu] > 0) {
173
0
            quant_residual_core_ldac(p_ac, iqu);
174
0
        }
175
1.14k
    }
176
177
44
    return;
178
44
}
179