This commit is contained in:
christos 2017-01-30 15:50:21 +00:00
parent 64b2ce979c
commit 5b72d547e7

View File

@ -1,4 +1,4 @@
/* $NetBSD: cosdata.c,v 1.2 2017/01/30 14:55:17 jakllsch Exp $ */ /* $NetBSD: cosdata.c,v 1.3 2017/01/30 15:50:21 christos Exp $ */
/*- /*-
* Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
@ -34,7 +34,7 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
static const double sbc8_coeffs[] = { static const double sbc_coeffs8[] = {
0.00000000e+00, 1.56575398e-04, 3.43256425e-04, 5.54620202e-04, 0.00000000e+00, 1.56575398e-04, 3.43256425e-04, 5.54620202e-04,
8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03, 8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03,
2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03, 2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03,
@ -57,7 +57,7 @@ static const double sbc8_coeffs[] = {
8.23919506e-04, 5.54620202e-04, 3.43256425e-04, 1.56575398e-04, 8.23919506e-04, 5.54620202e-04, 3.43256425e-04, 1.56575398e-04,
}; };
static const double sbc4_coeffs[] = { static const double sbc_coeffs4[] = {
0.00000000e+00, 5.36548976e-04, 1.49188357e-03, 2.73370904e-03, 0.00000000e+00, 5.36548976e-04, 1.49188357e-03, 2.73370904e-03,
3.83720193e-03, 3.89205149e-03, 1.86581691e-03,-3.06012286e-03, 3.83720193e-03, 3.89205149e-03, 1.86581691e-03,-3.06012286e-03,
1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02, 1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02,
@ -70,133 +70,71 @@ static const double sbc4_coeffs[] = {
3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04, 3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04,
}; };
#define COEFFS_MULTI (float)(1 << 12) #define COEFFS_MULTI (1 << 12)
#define SI_MULTI (float)512 #define SI_MULTI 512
static void
arrayprint(const char *name, const double *arr, size_t len)
{
size_t k, count;
printf("static const int32_t %s[] = {\n\t", name);
for (count = k = 0; k < len; k++, count++) {
if (count % 8 == 0 && count != 0)
printf("\n\t");
printf("%d, ", (int)roundf((float)arr[k] * COEFFS_MULTI));
}
printf("\n};\n");
}
#define ARRAYPRINT(a) arrayprint(#a, a, sizeof(a) / sizeof(a[0]))
static void
cosprint(int lim, int sgn)
{
size_t count, i, k;
size_t mi = lim * 4;
size_t mk = mi * 2;
int dk = sgn * lim * 2;
double mp = M_PI_4 / lim;
float val;
printf("static const int32_t cos%sdata%zu[%zu][%zu] = {\n\t",
sgn == -1 ? "" : "dec", mi, mi, mk);
for (count = 0, i = 0; i < mi; i++) {
for (k = 0; k < mk; k++, count++) {
if (count % 8 == 0 && count != 0)
printf("\n\t");
if (k == 0)
printf("{ ");
val = cosf((i + 0.5) * ((int)k + dk) * mp);
printf("%d, ", (int)roundf(val * SI_MULTI));
if (k == mk - 1)
printf("},");
}
}
printf("\n};\n");
}
int int
main (void) main(void)
{ {
float S[8][16], val;
int i,k, count = 0;
int vali;
printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n" printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
"\n"); "\n");
vali = SI_MULTI; printf("#define\tSIMULTI\t%d\n\n", SI_MULTI);
printf("#define SIMULTI\t%d\n\n", vali); printf("#define\tCOEFFSMULTI\t%d\n\n", COEFFS_MULTI);
vali = COEFFS_MULTI;
printf("#define COEFFSMULTI\t%d\n\n", vali);
printf("static const int32_t sbc_coeffs8[] = {\n "); ARRAYPRINT(sbc_coeffs8);
for (k = 0;k < (int)(sizeof(sbc8_coeffs)/sizeof(sbc8_coeffs[0]));k++) { ARRAYPRINT(sbc_coeffs4);
if (count % 8 == 0 && count != 0)
printf("\n ");
val = (float)(sbc8_coeffs[k] * COEFFS_MULTI);
vali = (int)roundf(val);
printf("%d, ",vali);
count++;
}
printf("\n};\n");
count = 0; cosprint(2, -1);
printf("static const int32_t sbc_coeffs4[] = {\n "); cosprint(1, -1);
for (k = 0;k < (int)(sizeof(sbc4_coeffs)/sizeof(sbc4_coeffs[0]));k++) { cosprint(2, 1);
if (count % 8 == 0 && count != 0) cosprint(1, 1);
printf("\n ");
val = (float)(sbc4_coeffs[k] * COEFFS_MULTI);
vali = (int)roundf(val);
printf("%d, ",vali);
count++;
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdata8[8][16] = {\n ");
for (i = 0; i < 8; i++) {
for (k = 0;k < 16;k++) {
S[i][k] = cosf((float)((i+0.5)*(k-4)*(M_PI_4/2)));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = (int)roundf(val);
printf("%d, ",vali);
if (k == 15)
printf("},");
count++;
}
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdata4[4][8] = {\n ");
for (i = 0; i < 4; i++) {
for (k = 0;k < 8;k++) {
S[i][k] = cosf((float)((i+0.5)*(k-2)*(M_PI_4)));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = (int)roundf(val);
printf("%d, ",vali);
if (k == 7)
printf("},");
count++;
}
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdecdata8[8][16] = {\n ");
for (i = 0; i < 8; i++) {
for (k = 0;k < 16;k++) {
S[i][k] = cosf((float)((i+0.5)*(k+4)*(M_PI_4/2)));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = (int)roundf(val);
printf("%d, ",vali);
if (k == 15)
printf("},");
count++;
}
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdecdata4[4][8] = {\n ");
for (i = 0; i < 4; i++) {
for (k = 0;k < 8;k++) {
S[i][k] = cosf((float)((i+0.5)*(k+2)*(M_PI_4)));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = (int)roundf(val);
printf("%d, ",vali);
if (k == 7)
printf("},");
count++;
}
}
printf("\n};\n");
return 0; return 0;
} }