aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-08-25 05:52:19 -0700
committerChris Robinson <[email protected]>2017-08-25 05:52:19 -0700
commit561e95528f55be2837541239236281c4cd63d728 (patch)
tree6d57db817feef0cc132293e0c319dd2796a8bc41 /utils
parent9ea32713b57fd95832172de5e8d8534339bb646b (diff)
Rename the bsinc resampler to bsinc12
Diffstat (limited to 'utils')
-rw-r--r--utils/bsincgen.c94
1 files changed, 48 insertions, 46 deletions
diff --git a/utils/bsincgen.c b/utils/bsincgen.c
index 15813e36..0064060f 100644
--- a/utils/bsincgen.c
+++ b/utils/bsincgen.c
@@ -239,31 +239,50 @@ static void BsiGenerateTables(const char *tabname, const double rejection, const
for(si = 0; si < BSINC_SCALE_COUNT; si++)
mt[si] = (mt[si]+3) & ~3;
+ fprintf(stdout,
+"/* This %d%s order filter has a rejection of -%.0fdB, yielding a transition width\n"
+" * of ~%.3f (normalized frequency). Order increases when downsampling to a\n"
+" * limit of one octave, after which the quality of the filter (transition\n"
+" * width) suffers to reduce the CPU cost. The bandlimiting will cut all sound\n"
+" * after downsampling by ~%.2f octaves.\n"
+" */\n"
+"static const BSincTable %s = {\n",
+ order, (((order%100)/10) == 1) ? "th" :
+ ((order%10) == 1) ? "st" :
+ ((order%10) == 2) ? "nd" :
+ ((order%10) == 3) ? "rd" : "th",
+ rejection, width, log2(1.0/scaleBase), tabname);
+
+ /* 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, " /* 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, " /* filterOffset */ {");
+ fprintf(stdout, " %d", 0);
+ i = mt[0]*4*BSINC_PHASE_COUNT;
+ for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ {
+ fprintf(stdout, ", %d", i);
+ i += mt[si]*4*BSINC_PHASE_COUNT;
+ }
+
+ fprintf(stdout, " },\n");
+
// Calculate the table size.
i = 0;
for(si = 0; si < BSINC_SCALE_COUNT; si++)
i += 4 * BSINC_PHASE_COUNT * mt[si];
- fprintf(stdout, "/* Generated by bsincgen, do not edit! */\n\n"
-"/* Table of windowed sinc coefficients and deltas. This %d%s order filter\n"
-" * has a rejection of -%gdB, yielding a transition width of ~%.3f\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 ~%.2f 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 filterOffset[BSINC_SCALE_COUNT];\n"
-"} %s = {\n", order, (((order%100)/10) == 1) ? "th" :
- ((order%10) == 1) ? "st" :
- ((order%10) == 2) ? "nd" :
- ((order%10) == 3) ? "rd" : "th",
- rejection, width, log2(1.0/scaleBase), i, tabname);
-
- fprintf(stdout, " /* Tab */ {\n");
+ fprintf(stdout, "\n /* Tab (%d entries) */ {\n", i);
for(si = 0; si < BSINC_SCALE_COUNT; si++)
{
const int m = mt[si];
@@ -287,31 +306,7 @@ static void BsiGenerateTables(const char *tabname, const double rejection, const
fprintf(stdout, "\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, " /* 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, " /* filterOffset */ {");
- fprintf(stdout, " %d", 0);
- i = mt[0]*4*BSINC_PHASE_COUNT;
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- {
- fprintf(stdout, ", %d", i);
- i += mt[si]*4*BSINC_PHASE_COUNT;
- }
-
- fprintf(stdout, " }\n};\n\n");
+ fprintf(stdout, " }\n};\n\n");
}
@@ -358,8 +353,15 @@ static void Sinc4GenerateTables(const double rejection)
int main(void)
{
+ fprintf(stdout, "/* Generated by bsincgen, do not edit! */\n\n"
+"typedef struct BSincTable {\n"
+" const float scaleBase, scaleRange;\n"
+" const int m[BSINC_SCALE_COUNT];\n"
+" const int filterOffset[BSINC_SCALE_COUNT];\n"
+" alignas(16) const float Tab[];\n"
+"} BSincTable;\n\n");
/* An 11th order filter with a -60dB drop at nyquist. */
- BsiGenerateTables("bsinc", 60.0, 11);
+ BsiGenerateTables("bsinc12", 60.0, 11);
Sinc4GenerateTables(60.0);
return 0;
}