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