FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
30 #define SOFTCLIP_THRESHOLD 27600
31 #define HARDCLIP_THRESHOLD 35716
32 
33 #if CONFIG_HARDCODED_TABLES
34 #define softclip_table_init()
35 #define rnd_table_init()
36 #define init_noise_samples()
37 #include "libavcodec/qdm2_tables.h"
38 #else
40 static float noise_table[4096];
43 static float noise_samples[128];
44 
45 static av_cold void softclip_table_init(void) {
46  int i;
47  double dfl = SOFTCLIP_THRESHOLD - 32767;
48  float delta = 1.0 / -dfl;
49  for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
50  softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
51 }
52 
53 
54 // random generated table
55 static av_cold void rnd_table_init(void) {
56  int i,j;
57  uint32_t ldw,hdw;
58  uint64_t tmp64_1;
59  uint64_t random_seed = 0;
60  float delta = 1.0 / 16384.0;
61  for(i = 0; i < 4096 ;i++) {
62  random_seed = random_seed * 214013 + 2531011;
63  noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
64  }
65 
66  for (i = 0; i < 256 ;i++) {
67  random_seed = 81;
68  ldw = i;
69  for (j = 0; j < 5 ;j++) {
70  random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
71  ldw = (uint32_t)ldw % (uint32_t)random_seed;
72  tmp64_1 = (random_seed * 0x55555556);
73  hdw = (uint32_t)(tmp64_1 >> 32);
74  random_seed = (uint64_t)(hdw + (ldw >> 31));
75  }
76  }
77  for (i = 0; i < 128 ;i++) {
78  random_seed = 25;
79  ldw = i;
80  for (j = 0; j < 3 ;j++) {
81  random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
82  ldw = (uint32_t)ldw % (uint32_t)random_seed;
83  tmp64_1 = (random_seed * 0x66666667);
84  hdw = (uint32_t)(tmp64_1 >> 33);
85  random_seed = hdw + (ldw >> 31);
86  }
87  }
88 }
89 
90 
91 static av_cold void init_noise_samples(void) {
92  int i;
93  unsigned random_seed = 0;
94  float delta = 1.0 / 16384.0;
95  for (i = 0; i < 128;i++) {
96  random_seed = random_seed * 214013 + 2531011;
97  noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
98  }
99 }
100 #endif /* CONFIG_HARDCODED_TABLES */
101 
102 #endif /* AVCODEC_QDM2_TABLEGEN_H */