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 39static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; 40static float noise_table[4096 + 20]; 41static uint8_t random_dequant_index[256][5]; 42static uint8_t random_dequant_type24[128][3]; 43static float noise_samples[128]; 44 45static 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 55static av_cold void rnd_table_init(void) { 56 int i,j; 57 uint32_t ldw; 58 uint64_t random_seed = 0; 59 float delta = 1.0 / 16384.0; 60 for(i = 0; i < 4096 ;i++) { 61 random_seed = random_seed * 214013 + 2531011; 62 noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3; 63 } 64 65 for (i = 0; i < 256 ;i++) { 66 random_seed = 81; 67 ldw = i; 68 for (j = 0; j < 5 ;j++) { 69 random_dequant_index[i][j] = ldw / random_seed; 70 ldw %= random_seed; 71 random_seed /= 3; 72 } 73 } 74 for (i = 0; i < 128 ;i++) { 75 random_seed = 25; 76 ldw = i; 77 for (j = 0; j < 3 ;j++) { 78 random_dequant_type24[i][j] = ldw / random_seed; 79 ldw %= random_seed; 80 random_seed /= 5; 81 } 82 } 83} 84 85 86static av_cold void init_noise_samples(void) { 87 int i; 88 unsigned random_seed = 0; 89 float delta = 1.0 / 16384.0; 90 for (i = 0; i < 128;i++) { 91 random_seed = random_seed * 214013 + 2531011; 92 noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0); 93 } 94} 95#endif /* CONFIG_HARDCODED_TABLES */ 96 97#endif /* AVCODEC_QDM2_TABLEGEN_H */ 98