Home | History | Annotate | Line # | Download | only in cosdata-gen
cosdata.c revision 1.2
      1 /* $NetBSD: cosdata.c,v 1.2 2017/01/30 14:55:17 jakllsch Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss (at) yahoo.com.au>
      5  * All rights reserved.
      6  *
      7  *		This software is dedicated to the memory of -
      8  *	   Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
      9  *
     10  *		Barry was a man who loved his music.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <math.h>
     35 #include <stdio.h>
     36 
     37 static const double sbc8_coeffs[] = {
     38 	0.00000000e+00, 1.56575398e-04, 3.43256425e-04, 5.54620202e-04,
     39 	8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03,
     40 	2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03,
     41 	9.02154502e-04, -1.78805361e-04, -1.64973098e-03, -3.49717454e-03,
     42 	5.65949473e-03, 8.02941163e-03, 1.04584443e-02, 1.27472335e-02,
     43 	1.46525263e-02, 1.59045603e-02, 1.62208471e-02, 1.53184106e-02,
     44 	1.29371806e-02, 8.85757540e-03, 2.92408442e-03, -4.91578024e-03,
     45 	-1.46404076e-02, -2.61098752e-02, -3.90751381e-02, -5.31873032e-02,
     46 	6.79989431e-02, 8.29847578e-02, 9.75753918e-02, 1.11196689e-01,
     47 	1.23264548e-01, 1.33264415e-01, 1.40753505e-01, 1.45389847e-01,
     48 	1.46955068e-01, 1.45389847e-01, 1.40753505e-01, 1.33264415e-01,
     49 	1.23264548e-01, 1.11196689e-01, 9.75753918e-02, 8.29847578e-02,
     50 	-6.79989431e-02, -5.31873032e-02, -3.90751381e-02, -2.61098752e-02,
     51 	-1.46404076e-02, -4.91578024e-03, 2.92408442e-03, 8.85757540e-03,
     52 	1.29371806e-02, 1.53184106e-02, 1.62208471e-02, 1.59045603e-02,
     53 	1.46525263e-02, 1.27472335e-02, 1.04584443e-02, 8.02941163e-03,
     54 	-5.65949473e-03, -3.49717454e-03, -1.64973098e-03, -1.78805361e-04,
     55 	9.02154502e-04, 1.61656283e-03, 1.99454554e-03, 2.10371989e-03,
     56 	2.01182542e-03, 1.78371725e-03, 1.47640169e-03, 1.13992507e-03,
     57 	8.23919506e-04, 5.54620202e-04, 3.43256425e-04, 1.56575398e-04,
     58 };
     59 
     60 static const double sbc4_coeffs[] = {
     61 	 0.00000000e+00, 5.36548976e-04, 1.49188357e-03, 2.73370904e-03,
     62 	 3.83720193e-03, 3.89205149e-03, 1.86581691e-03,-3.06012286e-03,
     63 	 1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02,
     64 	 2.58767811e-02, 6.13245186e-03,-2.88217274e-02,-7.76463494e-02,
     65 	 1.35593274e-01, 1.94987841e-01, 2.46636662e-01, 2.81828203e-01,
     66 	 2.94315332e-01, 2.81828203e-01, 2.46636662e-01, 1.94987841e-01,
     67 	-1.35593274e-01,-7.76463494e-02,-2.88217274e-02, 6.13245186e-03,
     68 	 2.58767811e-02, 3.21939290e-02, 2.88757392e-02, 2.04385087e-02,
     69 	-1.09137620e-02,-3.06012286e-03, 1.86581691e-03, 3.89205149e-03,
     70 	 3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04,
     71 };
     72 
     73 #define COEFFS_MULTI	(float)(1 << 12)
     74 #define SI_MULTI	(float)512
     75 
     76 int
     77 main (void)
     78 {
     79 	float S[8][16], val;
     80 	int i,k, count = 0;
     81 	int vali;
     82 
     83 	printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
     84 	    "\n");
     85 
     86 	vali = SI_MULTI;
     87 	printf("#define SIMULTI\t%d\n\n", vali);
     88 	vali = COEFFS_MULTI;
     89 	printf("#define COEFFSMULTI\t%d\n\n", vali);
     90 
     91 	printf("static const int32_t sbc_coeffs8[] = {\n    ");
     92 	for (k = 0;k < (int)(sizeof(sbc8_coeffs)/sizeof(sbc8_coeffs[0]));k++) {
     93 		if (count % 8 == 0 && count != 0)
     94 			printf("\n    ");
     95 		val = (float)(sbc8_coeffs[k] * COEFFS_MULTI);
     96 		vali = (int)roundf(val);
     97 		printf("%d, ",vali);
     98 		count++;
     99 	}
    100 	printf("\n};\n");
    101 
    102 	count = 0;
    103 	printf("static const int32_t sbc_coeffs4[] = {\n    ");
    104 	for (k = 0;k < (int)(sizeof(sbc4_coeffs)/sizeof(sbc4_coeffs[0]));k++) {
    105 		if (count % 8 == 0 && count != 0)
    106 			printf("\n    ");
    107 		val = (float)(sbc4_coeffs[k] * COEFFS_MULTI);
    108 		vali = (int)roundf(val);
    109 		printf("%d, ",vali);
    110 		count++;
    111 	}
    112 	printf("\n};\n");
    113 
    114 	count = 0;
    115 	printf("static const int32_t cosdata8[8][16] = {\n    ");
    116 	for (i = 0; i < 8; i++) {
    117 		for (k = 0;k < 16;k++) {
    118 			S[i][k] = cosf((float)((i+0.5)*(k-4)*(M_PI_4/2)));
    119 
    120 			if (count % 8 == 0 && count != 0)
    121 				printf("\n    ");
    122 			if (k == 0)
    123 				printf("{ ");
    124 			val = S[i][k] * SI_MULTI;
    125 			vali = (int)roundf(val);
    126 			printf("%d, ",vali);
    127 
    128 			if (k == 15)
    129 				printf("},");
    130 			count++;
    131 		}
    132 	}
    133 	printf("\n};\n");
    134 
    135 	count = 0;
    136 	printf("static const int32_t cosdata4[4][8] = {\n    ");
    137 	for (i = 0; i < 4; i++) {
    138 		for (k = 0;k < 8;k++) {
    139 			S[i][k] = cosf((float)((i+0.5)*(k-2)*(M_PI_4)));
    140 
    141 			if (count % 8 == 0 && count != 0)
    142 				printf("\n    ");
    143 			if (k == 0)
    144 				printf("{ ");
    145 
    146 			val = S[i][k] * SI_MULTI;
    147 			vali = (int)roundf(val);
    148 			printf("%d, ",vali);
    149 
    150 			if (k == 7)
    151 				printf("},");
    152 			count++;
    153 		}
    154 	}
    155 	printf("\n};\n");
    156 
    157 	count = 0;
    158 	printf("static const int32_t cosdecdata8[8][16] = {\n    ");
    159 	for (i = 0; i < 8; i++) {
    160 		for (k = 0;k < 16;k++) {
    161 			S[i][k] = cosf((float)((i+0.5)*(k+4)*(M_PI_4/2)));
    162 
    163 			if (count % 8 == 0 && count != 0)
    164 				printf("\n    ");
    165 			if (k == 0)
    166 				printf("{ ");
    167 			val = S[i][k] * SI_MULTI;
    168 			vali = (int)roundf(val);
    169 			printf("%d, ",vali);
    170 
    171 			if (k == 15)
    172 				printf("},");
    173 			count++;
    174 		}
    175 	}
    176 	printf("\n};\n");
    177 
    178 	count = 0;
    179 	printf("static const int32_t cosdecdata4[4][8] = {\n    ");
    180 	for (i = 0; i < 4; i++) {
    181 		for (k = 0;k < 8;k++) {
    182 			S[i][k] = cosf((float)((i+0.5)*(k+2)*(M_PI_4)));
    183 
    184 			if (count % 8 == 0 && count != 0)
    185 				printf("\n    ");
    186 			if (k == 0)
    187 				printf("{ ");
    188 
    189 			val = S[i][k] * SI_MULTI;
    190 			vali = (int)roundf(val);
    191 			printf("%d, ",vali);
    192 
    193 			if (k == 7)
    194 				printf("},");
    195 			count++;
    196 		}
    197 	}
    198 	printf("\n};\n");
    199 
    200 	return 0;
    201 }
    202 
    203