GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/qdm2_tablegen.h Lines: 106 106 100.0 %
Date: 2020-09-25 23:16:12 Branches: 14 14 100.0 %

Line Branch Exec Source
1
/*
2
 * Header file for hardcoded QDM2 tables
3
 *
4
 * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22
23
#ifndef AVCODEC_QDM2_TABLEGEN_H
24
#define AVCODEC_QDM2_TABLEGEN_H
25
26
#include <stdint.h>
27
#include <math.h>
28
#include "libavutil/attributes.h"
29
#include "qdm2data.h"
30
31
#define SOFTCLIP_THRESHOLD 27600
32
#define HARDCLIP_THRESHOLD 35716
33
34
#if CONFIG_HARDCODED_TABLES
35
#define softclip_table_init()
36
#define rnd_table_init()
37
#define init_noise_samples()
38
#define qdm2_init_vlc()
39
#include "libavcodec/qdm2_tables.h"
40
#else
41
static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
42
static float noise_table[4096 + 20];
43
static uint8_t random_dequant_index[256][5];
44
static uint8_t random_dequant_type24[128][3];
45
static float noise_samples[128];
46
47
1
static av_cold void softclip_table_init(void) {
48
    int i;
49
1
    double dfl = SOFTCLIP_THRESHOLD - 32767;
50
1
    float delta = 1.0 / -dfl;
51
8118
    for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
52
8117
        softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
53
1
}
54
55
56
// random generated table
57
1
static av_cold void rnd_table_init(void) {
58
    int i,j;
59
    uint32_t ldw;
60
1
    uint64_t random_seed = 0;
61
1
    float delta = 1.0 / 16384.0;
62
4097
    for(i = 0; i < 4096 ;i++) {
63
4096
        random_seed = random_seed * 214013 + 2531011;
64
4096
        noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
65
    }
66
67
257
    for (i = 0; i < 256 ;i++) {
68
256
        random_seed = 81;
69
256
        ldw = i;
70
1536
        for (j = 0; j < 5 ;j++) {
71
1280
            random_dequant_index[i][j] = ldw / random_seed;
72
1280
            ldw %= random_seed;
73
1280
            random_seed /= 3;
74
        }
75
    }
76
129
    for (i = 0; i < 128 ;i++) {
77
128
        random_seed = 25;
78
128
        ldw = i;
79
512
        for (j = 0; j < 3 ;j++) {
80
384
            random_dequant_type24[i][j] = ldw / random_seed;
81
384
            ldw %= random_seed;
82
384
            random_seed /= 5;
83
        }
84
    }
85
1
}
86
87
88
1
static av_cold void init_noise_samples(void) {
89
    int i;
90
1
    unsigned random_seed = 0;
91
1
    float delta = 1.0 / 16384.0;
92
129
    for (i = 0; i < 128;i++) {
93
128
        random_seed = random_seed * 214013 + 2531011;
94
128
        noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
95
    }
96
1
}
97
98
static VLC vlc_tab_level;
99
static VLC vlc_tab_diff;
100
static VLC vlc_tab_run;
101
static VLC fft_level_exp_alt_vlc;
102
static VLC fft_level_exp_vlc;
103
static VLC fft_stereo_exp_vlc;
104
static VLC fft_stereo_phase_vlc;
105
static VLC vlc_tab_tone_level_idx_hi1;
106
static VLC vlc_tab_tone_level_idx_mid;
107
static VLC vlc_tab_tone_level_idx_hi2;
108
static VLC vlc_tab_type30;
109
static VLC vlc_tab_type34;
110
static VLC vlc_tab_fft_tone_offset[5];
111
112
static const uint16_t qdm2_vlc_offs[] = {
113
    0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
114
};
115
116
static VLC_TYPE qdm2_table[3838][2];
117
118
1
static av_cold void qdm2_init_vlc(void)
119
{
120
1
    vlc_tab_level.table           = &qdm2_table[qdm2_vlc_offs[0]];
121
1
    vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
122
1
    init_vlc(&vlc_tab_level, 8, 24,
123
             vlc_tab_level_huffbits, 1, 1,
124
             vlc_tab_level_huffcodes, 2, 2,
125
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
126
127
1
    vlc_tab_diff.table           = &qdm2_table[qdm2_vlc_offs[1]];
128
1
    vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
129
1
    init_vlc(&vlc_tab_diff, 8, 37,
130
             vlc_tab_diff_huffbits, 1, 1,
131
             vlc_tab_diff_huffcodes, 2, 2,
132
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
133
134
1
    vlc_tab_run.table           = &qdm2_table[qdm2_vlc_offs[2]];
135
1
    vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
136
1
    init_vlc(&vlc_tab_run, 5, 6,
137
             vlc_tab_run_huffbits, 1, 1,
138
             vlc_tab_run_huffcodes, 1, 1,
139
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
140
141
1
    fft_level_exp_alt_vlc.table           = &qdm2_table[qdm2_vlc_offs[3]];
142
1
    fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
143
1
                                            qdm2_vlc_offs[3];
144
1
    init_vlc(&fft_level_exp_alt_vlc, 8, 28,
145
             fft_level_exp_alt_huffbits, 1, 1,
146
             fft_level_exp_alt_huffcodes, 2, 2,
147
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
148
149
1
    fft_level_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[4]];
150
1
    fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
151
1
    init_vlc(&fft_level_exp_vlc, 8, 20,
152
             fft_level_exp_huffbits, 1, 1,
153
             fft_level_exp_huffcodes, 2, 2,
154
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
155
156
1
    fft_stereo_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[5]];
157
1
    fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
158
1
                                         qdm2_vlc_offs[5];
159
1
    init_vlc(&fft_stereo_exp_vlc, 6, 7,
160
             fft_stereo_exp_huffbits, 1, 1,
161
             fft_stereo_exp_huffcodes, 1, 1,
162
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
163
164
1
    fft_stereo_phase_vlc.table           = &qdm2_table[qdm2_vlc_offs[6]];
165
1
    fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
166
1
                                           qdm2_vlc_offs[6];
167
1
    init_vlc(&fft_stereo_phase_vlc, 6, 9,
168
             fft_stereo_phase_huffbits, 1, 1,
169
             fft_stereo_phase_huffcodes, 1, 1,
170
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
171
172
1
    vlc_tab_tone_level_idx_hi1.table =
173
1
        &qdm2_table[qdm2_vlc_offs[7]];
174
1
    vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
175
1
                                                 qdm2_vlc_offs[7];
176
1
    init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
177
             vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
178
             vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2,
179
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
180
181
1
    vlc_tab_tone_level_idx_mid.table =
182
1
        &qdm2_table[qdm2_vlc_offs[8]];
183
1
    vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
184
1
                                                 qdm2_vlc_offs[8];
185
1
    init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
186
             vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
187
             vlc_tab_tone_level_idx_mid_huffcodes, 2, 2,
188
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
189
190
1
    vlc_tab_tone_level_idx_hi2.table =
191
1
        &qdm2_table[qdm2_vlc_offs[9]];
192
1
    vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
193
1
                                                 qdm2_vlc_offs[9];
194
1
    init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
195
             vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
196
             vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2,
197
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
198
199
1
    vlc_tab_type30.table           = &qdm2_table[qdm2_vlc_offs[10]];
200
1
    vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
201
1
    init_vlc(&vlc_tab_type30, 6, 9,
202
             vlc_tab_type30_huffbits, 1, 1,
203
             vlc_tab_type30_huffcodes, 1, 1,
204
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
205
206
1
    vlc_tab_type34.table           = &qdm2_table[qdm2_vlc_offs[11]];
207
1
    vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
208
1
    init_vlc(&vlc_tab_type34, 5, 10,
209
             vlc_tab_type34_huffbits, 1, 1,
210
             vlc_tab_type34_huffcodes, 1, 1,
211
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
212
213
1
    vlc_tab_fft_tone_offset[0].table =
214
1
        &qdm2_table[qdm2_vlc_offs[12]];
215
1
    vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
216
1
                                                 qdm2_vlc_offs[12];
217
1
    init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
218
             vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
219
             vlc_tab_fft_tone_offset_0_huffcodes, 2, 2,
220
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
221
222
1
    vlc_tab_fft_tone_offset[1].table =
223
1
        &qdm2_table[qdm2_vlc_offs[13]];
224
1
    vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
225
1
                                                 qdm2_vlc_offs[13];
226
1
    init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
227
             vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
228
             vlc_tab_fft_tone_offset_1_huffcodes, 2, 2,
229
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
230
231
1
    vlc_tab_fft_tone_offset[2].table =
232
1
        &qdm2_table[qdm2_vlc_offs[14]];
233
1
    vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
234
1
                                                 qdm2_vlc_offs[14];
235
1
    init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
236
             vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
237
             vlc_tab_fft_tone_offset_2_huffcodes, 2, 2,
238
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
239
240
1
    vlc_tab_fft_tone_offset[3].table =
241
1
        &qdm2_table[qdm2_vlc_offs[15]];
242
1
    vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
243
1
                                                 qdm2_vlc_offs[15];
244
1
    init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
245
             vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
246
             vlc_tab_fft_tone_offset_3_huffcodes, 2, 2,
247
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
248
249
1
    vlc_tab_fft_tone_offset[4].table =
250
1
        &qdm2_table[qdm2_vlc_offs[16]];
251
1
    vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
252
1
                                                 qdm2_vlc_offs[16];
253
1
    init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
254
             vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
255
             vlc_tab_fft_tone_offset_4_huffcodes, 2, 2,
256
             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
257
1
}
258
259
#endif /* CONFIG_HARDCODED_TABLES */
260
261
#endif /* AVCODEC_QDM2_TABLEGEN_H */