00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AVCODEC_QDM2_TABLEGEN_H
00024 #define AVCODEC_QDM2_TABLEGEN_H
00025
00026 #include <stdint.h>
00027 #include <math.h>
00028 #include "libavutil/attributes.h"
00029
00030 #define SOFTCLIP_THRESHOLD 27600
00031 #define HARDCLIP_THRESHOLD 35716
00032
00033 #if CONFIG_HARDCODED_TABLES
00034 #define softclip_table_init()
00035 #define rnd_table_init()
00036 #define init_noise_samples()
00037 #include "libavcodec/qdm2_tables.h"
00038 #else
00039 static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
00040 static float noise_table[4096];
00041 static uint8_t random_dequant_index[256][5];
00042 static uint8_t random_dequant_type24[128][3];
00043 static float noise_samples[128];
00044
00045 static av_cold void softclip_table_init(void) {
00046 int i;
00047 double dfl = SOFTCLIP_THRESHOLD - 32767;
00048 float delta = 1.0 / -dfl;
00049 for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
00050 softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
00051 }
00052
00053
00054
00055 static av_cold void rnd_table_init(void) {
00056 int i,j;
00057 uint32_t ldw,hdw;
00058 uint64_t tmp64_1;
00059 uint64_t random_seed = 0;
00060 float delta = 1.0 / 16384.0;
00061 for(i = 0; i < 4096 ;i++) {
00062 random_seed = random_seed * 214013 + 2531011;
00063 noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
00064 }
00065
00066 for (i = 0; i < 256 ;i++) {
00067 random_seed = 81;
00068 ldw = i;
00069 for (j = 0; j < 5 ;j++) {
00070 random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
00071 ldw = (uint32_t)ldw % (uint32_t)random_seed;
00072 tmp64_1 = (random_seed * 0x55555556);
00073 hdw = (uint32_t)(tmp64_1 >> 32);
00074 random_seed = (uint64_t)(hdw + (ldw >> 31));
00075 }
00076 }
00077 for (i = 0; i < 128 ;i++) {
00078 random_seed = 25;
00079 ldw = i;
00080 for (j = 0; j < 3 ;j++) {
00081 random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
00082 ldw = (uint32_t)ldw % (uint32_t)random_seed;
00083 tmp64_1 = (random_seed * 0x66666667);
00084 hdw = (uint32_t)(tmp64_1 >> 33);
00085 random_seed = hdw + (ldw >> 31);
00086 }
00087 }
00088 }
00089
00090
00091 static av_cold void init_noise_samples(void) {
00092 int i;
00093 int random_seed = 0;
00094 float delta = 1.0 / 16384.0;
00095 for (i = 0; i < 128;i++) {
00096 random_seed = random_seed * 214013 + 2531011;
00097 noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
00098 }
00099 }
00100 #endif
00101
00102 #endif