Libav 0.7.1
|
00001 /* 00002 * Generate a header file for hardcoded ff_cos_* tables 00003 * 00004 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include <stdio.h> 00024 #include <string.h> 00025 #include <math.h> 00026 00027 #ifndef M_PI 00028 #define M_PI 3.14159265358979323846 00029 #endif 00030 #define BITS 16 00031 #define FLOATFMT "%.18e" 00032 #define FIXEDFMT "%6d" 00033 00034 static int clip_f15(int v) 00035 { 00036 return v < -32767 ? -32767 : 00037 v > 32767 ? 32767 : 00038 v; 00039 } 00040 00041 static void printval(double val, int fixed) 00042 { 00043 if (fixed) 00044 printf(" "FIXEDFMT",", clip_f15(lrint(val * (double)(1<<15)))); 00045 else 00046 printf(" "FLOATFMT",", val); 00047 00048 } 00049 00050 int main(int argc, char *argv[]) 00051 { 00052 int i, j; 00053 int do_sin = argc > 1 && !strcmp(argv[1], "sin"); 00054 int fixed = argc > 1 && strstr(argv[1], "fixed"); 00055 double (*func)(double) = do_sin ? sin : cos; 00056 00057 printf("/* This file was automatically generated. */\n"); 00058 printf("#define CONFIG_FFT_FLOAT %d\n", !fixed); 00059 printf("#include \"libavcodec/%s\"\n", do_sin ? "rdft.h" : "fft.h"); 00060 for (i = 4; i <= BITS; i++) { 00061 int m = 1 << i; 00062 double freq = 2*M_PI/m; 00063 printf("%s(%i) = {\n ", do_sin ? "SINTABLE" : "COSTABLE", m); 00064 for (j = 0; j < m/2 - 1; j++) { 00065 int idx = j > m/4 ? m/2 - j : j; 00066 if (do_sin && j >= m/4) 00067 idx = m/4 - j; 00068 printval(func(idx*freq), fixed); 00069 if ((j & 3) == 3) 00070 printf("\n "); 00071 } 00072 printval(func(do_sin ? -(m/4 - 1)*freq : freq), fixed); 00073 printf("\n};\n"); 00074 } 00075 return 0; 00076 }