Module Name:    src
Committed By:   christos
Date:           Mon Jan 30 15:50:21 UTC 2017

Modified Files:
        src/usr.sbin/bta2dpd/cosdata-gen: cosdata.c

Log Message:
dedup.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c
diff -u src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c:1.2 src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c:1.3
--- src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c:1.2	Mon Jan 30 09:55:17 2017
+++ src/usr.sbin/bta2dpd/cosdata-gen/cosdata.c	Mon Jan 30 10:50:21 2017
@@ -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 <[email protected]>
@@ -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 @@ static const double sbc8_coeffs[] = {
 	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 @@ static const double sbc4_coeffs[] = {
 	 3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04, 
 };
 
-#define COEFFS_MULTI	(float)(1 << 12)
-#define SI_MULTI	(float)512
+#define COEFFS_MULTI	(1 << 12)
+#define SI_MULTI	512
 
-int
-main (void)
+static void
+arrayprint(const char *name, const double *arr, size_t len)
 {
-	float S[8][16], val;
-	int i,k, count = 0;
-	int vali;
-
-	printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
-	    "\n");
-
-	vali = SI_MULTI;
-	printf("#define SIMULTI\t%d\n\n", vali);
-	vali = COEFFS_MULTI;
-	printf("#define COEFFSMULTI\t%d\n\n", vali);
+	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};\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\t");
+		printf("%d, ", (int)roundf((float)arr[k] * COEFFS_MULTI));
 	}
 	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)));
+#define ARRAYPRINT(a)	arrayprint(#a, a, sizeof(a) / sizeof(a[0]))
 
-			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");
+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;
 
-	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)));
+	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 == 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)));
+			val = cosf((i + 0.5) * ((int)k + dk) * mp);
+			printf("%d, ", (int)roundf(val * SI_MULTI));
 
-			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)
+			if (k == mk - 1)
 				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)));
+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("{ ");
+	printf("#define\tSIMULTI\t%d\n\n", SI_MULTI);
+	printf("#define\tCOEFFSMULTI\t%d\n\n", COEFFS_MULTI);
 
-			val = S[i][k] * SI_MULTI;
-			vali = (int)roundf(val);
-			printf("%d, ",vali);
+	ARRAYPRINT(sbc_coeffs8);
+	ARRAYPRINT(sbc_coeffs4);
 
-			if (k == 7)
-				printf("},");
-			count++;
-		}
-	}
-	printf("\n};\n");
+	cosprint(2, -1);
+	cosprint(1, -1);
+	cosprint(2, 1);
+	cosprint(1, 1);
 
 	return 0;
 }
-

Reply via email to