FFmpeg
qdm2_tablegen.h
Go to the documentation of this file.
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
42 static float noise_table[4096 + 20];
45 static float noise_samples[128];
46 
47 static av_cold void softclip_table_init(void) {
48  int i;
49  double dfl = SOFTCLIP_THRESHOLD - 32767;
50  float delta = 1.0 / -dfl;
51  for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
52  softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
53 }
54 
55 
56 // random generated table
57 static av_cold void rnd_table_init(void) {
58  int i,j;
59  uint32_t ldw;
60  uint64_t random_seed = 0;
61  float delta = 1.0 / 16384.0;
62  for(i = 0; i < 4096 ;i++) {
63  random_seed = random_seed * 214013 + 2531011;
64  noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
65  }
66 
67  for (i = 0; i < 256 ;i++) {
68  random_seed = 81;
69  ldw = i;
70  for (j = 0; j < 5 ;j++) {
71  random_dequant_index[i][j] = ldw / random_seed;
72  ldw %= random_seed;
73  random_seed /= 3;
74  }
75  }
76  for (i = 0; i < 128 ;i++) {
77  random_seed = 25;
78  ldw = i;
79  for (j = 0; j < 3 ;j++) {
80  random_dequant_type24[i][j] = ldw / random_seed;
81  ldw %= random_seed;
82  random_seed /= 5;
83  }
84  }
85 }
86 
87 
88 static av_cold void init_noise_samples(void) {
89  int i;
90  unsigned random_seed = 0;
91  float delta = 1.0 / 16384.0;
92  for (i = 0; i < 128;i++) {
93  random_seed = random_seed * 214013 + 2531011;
94  noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
95  }
96 }
97 
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 static av_cold void qdm2_init_vlc(void)
119 {
122  init_vlc(&vlc_tab_level, 8, 24,
126 
129  init_vlc(&vlc_tab_diff, 8, 37,
130  vlc_tab_diff_huffbits, 1, 1,
133 
136  init_vlc(&vlc_tab_run, 5, 6,
137  vlc_tab_run_huffbits, 1, 1,
138  vlc_tab_run_huffcodes, 1, 1,
140 
143  qdm2_vlc_offs[3];
148 
151  init_vlc(&fft_level_exp_vlc, 8, 20,
155 
158  qdm2_vlc_offs[5];
163 
166  qdm2_vlc_offs[6];
171 
175  qdm2_vlc_offs[7];
180 
184  qdm2_vlc_offs[8];
189 
193  qdm2_vlc_offs[9];
198 
201  init_vlc(&vlc_tab_type30, 6, 9,
205 
208  init_vlc(&vlc_tab_type34, 5, 10,
212 
216  qdm2_vlc_offs[12];
221 
225  qdm2_vlc_offs[13];
230 
234  qdm2_vlc_offs[14];
239 
243  qdm2_vlc_offs[15];
248 
252  qdm2_vlc_offs[16];
257 }
258 
259 #endif /* CONFIG_HARDCODED_TABLES */
260 
261 #endif /* AVCODEC_QDM2_TABLEGEN_H */
fft_stereo_exp_vlc
static VLC fft_stereo_exp_vlc
Definition: qdm2_tablegen.h:103
qdm2_vlc_offs
static const uint16_t qdm2_vlc_offs[]
Definition: qdm2_tablegen.h:112
qdm2_table
static VLC_TYPE qdm2_table[3838][2]
Definition: qdm2_tablegen.h:116
vlc_tab_type30
static VLC vlc_tab_type30
Definition: qdm2_tablegen.h:108
vlc_tab_type34
static VLC vlc_tab_type34
Definition: qdm2_tablegen.h:109
vlc_tab_fft_tone_offset_1_huffcodes
static const uint16_t vlc_tab_fft_tone_offset_1_huffcodes[28]
Definition: qdm2data.h:135
vlc_tab_run_huffcodes
static const uint8_t vlc_tab_run_huffcodes[6]
Definition: qdm2data.h:64
random_dequant_index
static uint8_t random_dequant_index[256][5]
Definition: qdm2_tablegen.h:43
vlc_tab_fft_tone_offset_4_huffbits
static const uint8_t vlc_tab_fft_tone_offset_4_huffbits[38]
Definition: qdm2data.h:184
vlc_tab_fft_tone_offset_3_huffbits
static const uint8_t vlc_tab_fft_tone_offset_3_huffbits[35]
Definition: qdm2data.h:169
init_vlc
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:38
vlc_tab_type30_huffbits
static const uint8_t vlc_tab_type30_huffbits[9]
Definition: qdm2data.h:110
vlc_tab_level_huffbits
static const uint8_t vlc_tab_level_huffbits[24]
Definition: qdm2data.h:44
vlc_tab_tone_level_idx_hi1
static VLC vlc_tab_tone_level_idx_hi1
Definition: qdm2_tablegen.h:105
SOFTCLIP_THRESHOLD
#define SOFTCLIP_THRESHOLD
Definition: qdm2_tablegen.h:31
INIT_VLC_LE
#define INIT_VLC_LE
Definition: vlc.h:54
softclip_table
static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD+1]
Definition: qdm2_tablegen.h:41
vlc_tab_fft_tone_offset_3_huffcodes
static const uint16_t vlc_tab_fft_tone_offset_3_huffcodes[35]
Definition: qdm2data.h:161
noise_table
static float noise_table[4096+20]
Definition: qdm2_tablegen.h:42
init_noise_samples
static av_cold void init_noise_samples(void)
Definition: qdm2_tablegen.h:88
VLC_TYPE
#define VLC_TYPE
Definition: vlc.h:24
vlc_tab_run_huffbits
static const uint8_t vlc_tab_run_huffbits[6]
Definition: qdm2data.h:68
vlc_tab_level
static VLC vlc_tab_level
Definition: qdm2_tablegen.h:98
rnd_table_init
static av_cold void rnd_table_init(void)
Definition: qdm2_tablegen.h:57
vlc_tab_run
static VLC vlc_tab_run
Definition: qdm2_tablegen.h:100
vlc_tab_fft_tone_offset_0_huffcodes
static const uint16_t vlc_tab_fft_tone_offset_0_huffcodes[23]
Definition: qdm2data.h:124
av_cold
#define av_cold
Definition: attributes.h:84
fft_level_exp_alt_huffcodes
static const uint16_t fft_level_exp_alt_huffcodes[28]
FFT TABLES.
Definition: qdm2data.h:193
HARDCLIP_THRESHOLD
#define HARDCLIP_THRESHOLD
Definition: qdm2_tablegen.h:32
vlc_tab_tone_level_idx_mid_huffcodes
static const uint16_t vlc_tab_tone_level_idx_mid_huffcodes[24]
Definition: qdm2data.h:84
vlc_tab_tone_level_idx_hi1_huffcodes
static const uint16_t vlc_tab_tone_level_idx_hi1_huffcodes[20]
Definition: qdm2data.h:73
int32_t
int32_t
Definition: audio_convert.c:194
vlc_tab_tone_level_idx_hi2_huffbits
static const uint8_t vlc_tab_tone_level_idx_hi2_huffbits[24]
Definition: qdm2data.h:101
fft_stereo_exp_huffbits
static const uint8_t fft_stereo_exp_huffbits[7]
Definition: qdm2data.h:221
fft_level_exp_huffcodes
static const uint16_t fft_level_exp_huffcodes[20]
Definition: qdm2data.h:206
fft_stereo_phase_vlc
static VLC fft_stereo_phase_vlc
Definition: qdm2_tablegen.h:104
vlc_tab_diff_huffcodes
static const uint16_t vlc_tab_diff_huffcodes[37]
Definition: qdm2data.h:49
vlc_tab_fft_tone_offset_2_huffbits
static const uint8_t vlc_tab_fft_tone_offset_2_huffbits[32]
Definition: qdm2data.h:155
vlc_tab_type34_huffbits
static const uint8_t vlc_tab_type34_huffbits[10]
Definition: qdm2data.h:119
INIT_VLC_USE_NEW_STATIC
#define INIT_VLC_USE_NEW_STATIC
Definition: vlc.h:55
fft_stereo_phase_huffbits
static const uint8_t fft_stereo_phase_huffbits[9]
Definition: qdm2data.h:230
fft_stereo_phase_huffcodes
static const uint8_t fft_stereo_phase_huffcodes[9]
Definition: qdm2data.h:226
vlc_tab_level_huffcodes
static const uint16_t vlc_tab_level_huffcodes[24]
VLC TABLES.
Definition: qdm2data.h:38
VLC::table_allocated
int table_allocated
Definition: vlc.h:29
qdm2data.h
vlc_tab_fft_tone_offset_4_huffcodes
static const uint16_t vlc_tab_fft_tone_offset_4_huffcodes[38]
Definition: qdm2data.h:176
fft_level_exp_huffbits
static const uint8_t fft_level_exp_huffbits[20]
Definition: qdm2data.h:212
vlc_tab_diff_huffbits
static const uint8_t vlc_tab_diff_huffbits[37]
Definition: qdm2data.h:57
vlc_tab_type30_huffcodes
static const uint8_t vlc_tab_type30_huffcodes[9]
Definition: qdm2data.h:106
attributes.h
random_dequant_type24
static uint8_t random_dequant_type24[128][3]
Definition: qdm2_tablegen.h:44
vlc_tab_tone_level_idx_mid
static VLC vlc_tab_tone_level_idx_mid
Definition: qdm2_tablegen.h:106
vlc_tab_tone_level_idx_hi1_huffbits
static const uint8_t vlc_tab_tone_level_idx_hi1_huffbits[20]
Definition: qdm2data.h:79
vlc_tab_tone_level_idx_hi2
static VLC vlc_tab_tone_level_idx_hi2
Definition: qdm2_tablegen.h:107
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
vlc_tab_fft_tone_offset_2_huffcodes
static const uint16_t vlc_tab_fft_tone_offset_2_huffcodes[32]
Definition: qdm2data.h:148
delta
float delta
Definition: vorbis_enc_data.h:457
uint8_t
uint8_t
Definition: audio_convert.c:194
qdm2_init_vlc
static av_cold void qdm2_init_vlc(void)
Definition: qdm2_tablegen.h:118
fft_level_exp_alt_vlc
static VLC fft_level_exp_alt_vlc
Definition: qdm2_tablegen.h:101
vlc_tab_fft_tone_offset_0_huffbits
static const uint8_t vlc_tab_fft_tone_offset_0_huffbits[23]
Definition: qdm2data.h:130
fft_level_exp_vlc
static VLC fft_level_exp_vlc
Definition: qdm2_tablegen.h:102
noise_samples
static float noise_samples[128]
Definition: qdm2_tablegen.h:45
fft_stereo_exp_huffcodes
static const uint8_t fft_stereo_exp_huffcodes[7]
Definition: qdm2data.h:217
vlc_tab_tone_level_idx_mid_huffbits
static const uint8_t vlc_tab_tone_level_idx_mid_huffbits[24]
Definition: qdm2data.h:90
VLC
Definition: vlc.h:26
vlc_tab_diff
static VLC vlc_tab_diff
Definition: qdm2_tablegen.h:99
vlc_tab_tone_level_idx_hi2_huffcodes
static const uint16_t vlc_tab_tone_level_idx_hi2_huffcodes[24]
Definition: qdm2data.h:95
vlc_tab_fft_tone_offset_1_huffbits
static const uint8_t vlc_tab_fft_tone_offset_1_huffbits[28]
Definition: qdm2data.h:142
fft_level_exp_alt_huffbits
static const uint8_t fft_level_exp_alt_huffbits[28]
Definition: qdm2data.h:200
vlc_tab_fft_tone_offset
static VLC vlc_tab_fft_tone_offset[5]
Definition: qdm2_tablegen.h:110
vlc_tab_type34_huffcodes
static const uint8_t vlc_tab_type34_huffcodes[10]
Definition: qdm2data.h:115
VLC::table
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
softclip_table_init
static av_cold void softclip_table_init(void)
Definition: qdm2_tablegen.h:47