Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/bta2dpd/cosdata-gen dedup.



details:   https://anonhg.NetBSD.org/src/rev/a53d8428cbd1
branches:  trunk
changeset: 821258:a53d8428cbd1
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jan 30 15:50:21 2017 +0000

description:
dedup.

diffstat:

 usr.sbin/bta2dpd/cosdata-gen/cosdata.c |  158 ++++++++++----------------------
 1 files changed, 48 insertions(+), 110 deletions(-)

diffs (206 lines):

diff -r f7752e46acf6 -r a53d8428cbd1 usr.sbin/bta2dpd/cosdata-gen/cosdata.c
--- a/usr.sbin/bta2dpd/cosdata-gen/cosdata.c    Mon Jan 30 14:55:58 2017 +0000
+++ b/usr.sbin/bta2dpd/cosdata-gen/cosdata.c    Mon Jan 30 15:50:21 2017 +0000
@@ -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@localhost>
@@ -34,7 +34,7 @@
 #include <math.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,
        8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03,
        2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03,
@@ -57,7 +57,7 @@
        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,
         3.83720193e-03, 3.89205149e-03, 1.86581691e-03,-3.06012286e-03,
         1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02,
@@ -70,133 +70,71 @@
         3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04, 
 };
 
-#define COEFFS_MULTI   (float)(1 << 12)
-#define SI_MULTI       (float)512
-
-int
-main (void)
-{
-       float S[8][16], val;
-       int i,k, count = 0;
-       int vali;
-
-       printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
-           "\n");
+#define COEFFS_MULTI   (1 << 12)
+#define SI_MULTI       512
 
-       vali = SI_MULTI;
-       printf("#define SIMULTI\t%d\n\n", vali);
-       vali = COEFFS_MULTI;
-       printf("#define COEFFSMULTI\t%d\n\n", vali);
+static void
+arrayprint(const char *name, const double *arr, size_t len)
+{
+       size_t k, count;
 
-       printf("static const int32_t sbc_coeffs8[] = {\n    ");
-       for (k = 0;k < (int)(sizeof(sbc8_coeffs)/sizeof(sbc8_coeffs[0]));k++) {
+       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    ");
-               val = (float)(sbc8_coeffs[k] * COEFFS_MULTI);
-               vali = (int)roundf(val);
-               printf("%d, ",vali);
-               count++;
+                       printf("\n\t");
+               printf("%d, ", (int)roundf((float)arr[k] * COEFFS_MULTI));
        }
        printf("\n};\n");
+}
 
-       count = 0;
-       printf("static const int32_t sbc_coeffs4[] = {\n    ");
-       for (k = 0;k < (int)(sizeof(sbc4_coeffs)/sizeof(sbc4_coeffs[0]));k++) {
-               if (count % 8 == 0 && count != 0)
-                       printf("\n    ");
-               val = (float)(sbc4_coeffs[k] * COEFFS_MULTI);
-               vali = (int)roundf(val);
-               printf("%d, ",vali);
-               count++;
-       }
-       printf("\n};\n");
+#define ARRAYPRINT(a)  arrayprint(#a, a, sizeof(a) / sizeof(a[0]))
 
-       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)));
+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    ");
+                               printf("\n\t");
                        if (k == 0)
                                printf("{ ");
-                       val = S[i][k] * SI_MULTI;
-                       vali = (int)roundf(val);
-                       printf("%d, ",vali);
 
-                       if (k == 15)
+                       val = cosf((i + 0.5) * ((int)k + dk) * mp);
+                       printf("%d, ", (int)roundf(val * SI_MULTI));
+
+                       if (k == mk - 1)
                                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)));
+int
+main(void)
+{
+       printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
+           "\n");
 
-                       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");
+       printf("#define\tSIMULTI\t%d\n\n", SI_MULTI);
+       printf("#define\tCOEFFSMULTI\t%d\n\n", COEFFS_MULTI);
 
-       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("{ ");
+       ARRAYPRINT(sbc_coeffs8);
+       ARRAYPRINT(sbc_coeffs4);
 
-                       val = S[i][k] * SI_MULTI;
-                       vali = (int)roundf(val);
-                       printf("%d, ",vali);
-
-                       if (k == 7)
-                               printf("},");
-                       count++;
-               }
-       }
-       printf("\n};\n");
+       cosprint(2, -1);
+       cosprint(1, -1);
+       cosprint(2, 1);
+       cosprint(1, 1);
 
        return 0;
 }
-



Home | Main Index | Thread Index | Old Index