From 4dd53ab9429f0ca561dfd45f8f6022ae9871455a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 15 Aug 2017 04:15:50 -0700 Subject: Keep bsinc info together in a struct --- utils/bsincgen.c | 98 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 37 deletions(-) (limited to 'utils') diff --git a/utils/bsincgen.c b/utils/bsincgen.c index 33783a27..fcc5ec85 100644 --- a/utils/bsincgen.c +++ b/utils/bsincgen.c @@ -245,16 +245,32 @@ static void BsiGenerateTables() for(si = 1; si < BSINC_SCALE_COUNT; si++) i += BSINC_PHASE_COUNT * mt[si]; - fprintf(stdout, "static const float bsincTab[%d] =\n{\n", i); - + fprintf(stdout, "/* Generated by bsincgen, do not edit! */\n\n" +"/* Table of windowed sinc coefficients and deltas. This 11th order filter\n" +" * has a rejection of -60 dB, yielding a transition width of ~0.302\n" +" * (normalized frequency). Order increases when downsampling to a limit of\n" +" * one octave, after which the quality of the filter (transition width)\n" +" * suffers to reduce the CPU cost. The bandlimiting will cut all sound after\n" +" * downsampling by ~2.73 octaves.\n" +" */\n" +"static const struct {\n" +" alignas(16) const float Tab[%d];\n" +" const float scaleBase, scaleRange;\n" +" const int m[BSINC_SCALE_COUNT];\n" +" const int to[4][BSINC_SCALE_COUNT];\n" +" const int tm[2][BSINC_SCALE_COUNT];\n" +"} bsinc = {\n", i); + + fprintf(stdout, " /* Tab */ {\n"); /* Only output enough coefficients for the first (cut) scale as needed to perform interpolation without extra branching. */ - fprintf(stdout, " /* %2d,%2d */", mt[0], 0); + fprintf(stdout, " /* %2d,%2d */", mt[0], 0); for(i = 0; i < mt[0]; i++) fprintf(stdout, " %+14.9ef,", filter[0][0][i]); fprintf(stdout, "\n\n"); + fprintf(stdout, " /* Filters */\n"); for(si = 1; si < BSINC_SCALE_COUNT; si++) { const int m = mt[si]; @@ -262,7 +278,7 @@ static void BsiGenerateTables() for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) { - fprintf(stdout, " /* %2d,%2d */", m, pi); + fprintf(stdout, " /* %2d,%2d */", m, pi); for(i = 0; i < m; i++) fprintf(stdout, " %+14.9ef,", filter[si][pi][o + i]); fprintf(stdout, "\n"); @@ -271,6 +287,7 @@ static void BsiGenerateTables() fprintf(stdout, "\n"); // There are N-1 scale deltas for N scales. + fprintf(stdout, " /* Scale deltas */\n"); for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) { const int m = mt[si]; @@ -278,7 +295,7 @@ static void BsiGenerateTables() for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) { - fprintf(stdout, " /* %2d,%2d */", m, pi); + fprintf(stdout, " /* %2d,%2d */", m, pi); for(i = 0; i < m; i++) fprintf(stdout, " %+14.9ef,", scDeltas[si][pi][o + i]); fprintf(stdout, "\n"); @@ -287,6 +304,7 @@ static void BsiGenerateTables() fprintf(stdout, "\n"); // Exclude phases for the first (cut) scale. + fprintf(stdout, " /* Phase deltas */\n"); for(si = 1; si < BSINC_SCALE_COUNT; si++) { const int m = mt[si]; @@ -294,7 +312,7 @@ static void BsiGenerateTables() for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) { - fprintf(stdout, " /* %2d,%2d */", m, pi); + fprintf(stdout, " /* %2d,%2d */", m, pi); for(i = 0; i < m; i++) fprintf(stdout, " %+14.9ef,", phDeltas[si][pi][o + i]); fprintf(stdout, "\n"); @@ -302,6 +320,7 @@ static void BsiGenerateTables() } fprintf(stdout, "\n"); + fprintf(stdout, " /* Scale phase deltas */\n"); for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) { const int m = mt[si]; @@ -309,67 +328,67 @@ static void BsiGenerateTables() for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) { - fprintf(stdout, " /* %2d,%2d */", m, pi); + fprintf(stdout, " /* %2d,%2d */", m, pi); for(i = 0; i < m; i++) fprintf(stdout, " %+14.9ef,", spDeltas[si][pi][o + i]); fprintf(stdout, "\n"); } } - fprintf(stdout, "};\n\n"); + fprintf(stdout, " },\n\n"); /* The scaleBase is calculated from the Kaiser window transition width. It represents the absolute limit to the filter before it fully cuts the signal. The limit in octaves can be calculated by taking the base-2 logarithm of its inverse: log_2(1 / scaleBase) */ - fprintf(stdout, " static const ALfloat scaleBase = %.9ef, scaleRange = %.9ef;\n", scaleBase, 1.0 / scaleRange); - fprintf(stdout, " static const ALuint m[BSINC_SCALE_COUNT] = {"); + fprintf(stdout, " /* scaleBase */ %.9ef, /* scaleRange */ %.9ef,\n", scaleBase, 1.0 / scaleRange); + fprintf(stdout, " /* m */ {"); fprintf(stdout, " %d", mt[0]); for(si = 1; si < BSINC_SCALE_COUNT; si++) fprintf(stdout, ", %d", mt[si]); - fprintf(stdout, " };\n"); - fprintf(stdout, " static const ALuint to[4][BSINC_SCALE_COUNT] =\n {\n { 0"); + fprintf(stdout, " },\n"); + fprintf(stdout, " /* to */ {\n { %5d", 0); i = mt[0]; for(si = 1; si < BSINC_SCALE_COUNT; si++) { - fprintf(stdout, ", %d", i); + fprintf(stdout, ", %5d", i); i += BSINC_PHASE_COUNT * mt[si]; } fprintf(stdout, " },\n {"); for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) { - fprintf(stdout, " %d,", i); + fprintf(stdout, " %5d,", i); i += BSINC_PHASE_COUNT * mt[si]; } - fprintf(stdout, " 0 },\n { 0"); + fprintf(stdout, " %5d },\n { %5d", 0, 0); for(si = 1; si < BSINC_SCALE_COUNT; si++) { - fprintf(stdout, ", %d", i); + fprintf(stdout, ", %5d", i); i += BSINC_PHASE_COUNT * mt[si]; } fprintf (stdout, " },\n {"); for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) { - fprintf(stdout, " %d,", i); + fprintf(stdout, " %5d,", i); i += BSINC_PHASE_COUNT * mt[si]; } - fprintf(stdout, " 0 }\n };\n"); + fprintf(stdout, " %5d }\n },\n", 0); - fprintf(stdout, " static const ALuint tm[2][BSINC_SCALE_COUNT] = \n {\n { 0"); + fprintf(stdout, " /* tm */ {\n { 0"); for(si = 1; si < BSINC_SCALE_COUNT; si++) fprintf(stdout, ", %d", mt[si]); fprintf(stdout, " },\n {"); for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) fprintf(stdout, " %d,", mt[si]); - fprintf(stdout, " 0 }\n };\n\n"); + fprintf(stdout, " 0 }\n }\n};\n\n"); } /* These methods generate a much simplified 4-point sinc interpolator using a - * Kaiser windows. This is much simpler to process at run-time, but has notably + * Kaiser window. This is much simpler to process at run-time, but has notably * more aliasing noise. */ @@ -377,30 +396,35 @@ static void BsiGenerateTables() #define FRACTIONBITS (12) #define FRACTIONONE (1<