---<br> dlls/dsound/mkfir.c | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++<br> 1 files changed, 202 insertions(+), 0 deletions(-)<br> create mode 100644 dlls/dsound/mkfir.c<br><br>diff --git a/dlls/dsound/mkfir.c b/dlls/dsound/mkfir.c<br>
new file mode 100644<br>index 0000000..001778b<br>--- /dev/null<br>+++ b/dlls/dsound/mkfir.c<br>@@ -0,0 +1,202 @@<br>+/* DirectSound<br>+ *<br>+ * Resample filter table generator<br>+ * Copyright 2010 Krzysztof Nikiel<br>
+ *<br>+ * Initially based on resample:<br>+ * <a href="http://www-ccrma.stanford.edu/~jos/resample/">http://www-ccrma.stanford.edu/~jos/resample/</a><br>+ *<br>+ *<br>+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Lesser General Public<br>+ * License as published by the Free Software Foundation; either<br>+ * version 2.1 of the License, or (at your option) any later version.<br>+ *<br>+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>+ * Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public<br>
+ * License along with this library; if not, write to the Free Software<br>+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA<br>+ */<br>+<br>+#include <stdio.h><br>+#include <stdlib.h><br>
+#include <string.h><br>+#include <math.h><br>+#include <stdint.h><br>+#include <time.h><br>+<br>+#ifndef RESAMPLE_INSANE<br>+#define RESAMPLE_INSANE 0<br>+#endif<br>+<br>+#define FREE(x) if(x)free(x);x=NULL<br>
+#define ALLOC(x,size) FREE(x);x=malloc(size*sizeof(x[0]));\<br>+ memset(x,0,size*sizeof(x[0]))<br>+<br>+<br>+typedef struct {<br>+ double *wing;<br>+ int size;<br>+ int step;<br>+} fir_t;<br>+<br>+static fir_t FIR;<br>
+static fir_t *g_fir = &FIR;<br>+<br>+static struct {<br>+ const char *const name;<br>+ const int step;<br>+ const double Beta;<br>+ const double width0;<br>+ const double passband;<br>+ const char *const comment;<br>
+} firparams[] = {<br>+ {"fast",<br>+ 12, 4, 4, 0.8<br>+ },<br>+ {"good",<br>+ 22, 6, 10, 0.92<br>+ },<br>+ {"best",<br>+ 62, 8, 16, 0.94<br>+ },<br>+ {"slow",<br>+ 502, 12, 28, 0.95<br>
+ },<br>+#if RESAMPLE_INSANE<br>+ {"insane",<br>+ 2381, 16.2, 142.8975, 0.965,<br>+ "same as libsamplerate high_qual"},<br>+#endif<br>+ {NULL}<br>+};<br>+<br>+<br>+/**<br>+ * Kaiser windowed filter generator<br>
+ */<br>+static double Izero(double x)<br>+{<br>+ const double IzeroEPSILON = 1e-30; /* Max error acceptable in Izero */<br>+ double sum, u, halfx, temp;<br>+ int n;<br>+<br>+ sum = u = n = 1;<br>+ halfx = x / 2.0;<br>
+ do<br>+ {<br>+ temp = halfx / (double) n;<br>+ n += 1;<br>+ temp *= temp;<br>+ u *= temp;<br>+ sum += u;<br>+ }<br>+ while (u >= IzeroEPSILON * sum);<br>+<br>+ return (sum);<br>+}<br>+<br>+static void makefir(int idx)<br>
+{<br>+ int cnt;<br>+ double IBeta;<br>+ double tmp, tmp2;<br>+ double cutoff;<br>+<br>+ for (cnt = 0; cnt <= idx; cnt++)<br>+ {<br>+ if (!firparams[cnt].name)<br>+ break;<br>+ }<br>+ idx = cnt - 1;<br>
+<br>+ fprintf(stderr, "creating %s filter...", firparams[idx].name);<br>+ fflush(stderr);<br>+<br>+ g_fir->step = firparams[idx].step;<br>+ g_fir->size = firparams[idx].width0 * g_fir->step;<br>+ ALLOC(g_fir->wing, g_fir->size);<br>
+<br>+ IBeta = 1.0 / Izero(firparams[idx].Beta);<br>+ cutoff = firparams[idx].passband / g_fir->step;<br>+ g_fir->wing[0] = 1.0;<br>+<br>+ for (cnt = 1; cnt < g_fir->size; cnt++)<br>+ {<br>+ tmp = (double) (cnt) / g_fir->size;<br>
+ tmp2 = M_PI * cnt * cutoff;<br>+<br>+ /* Kaiser windowed sinc */<br>+ g_fir->wing[cnt] = sin(tmp2) / tmp2<br>+ * Izero(firparams[idx].Beta * sqrt(1.0 - tmp * tmp)) * IBeta;<br>+ }<br>+<br>+ /* normalize the table */<br>
+ tmp = g_fir->wing[0];<br>+ for (cnt = 1; cnt < g_fir->size; cnt++)<br>+ tmp += 2.0 * g_fir->wing[cnt];<br>+ tmp = 1.0 / tmp;<br>+ for (cnt = 0; cnt < g_fir->size; cnt++)<br>+ g_fir->wing[cnt] *= tmp;<br>
+<br>+ fprintf(stderr, "OK\n");<br>+}<br>+<br>+static void deletefir(void)<br>+{<br>+ FREE(g_fir->wing);<br>+ g_fir->size = 0;<br>+}<br>+<br>+static void printhdr(char *item)<br>+{<br>+ time_t t;<br>+<br>
+ time(&t);<br>+ printf("/* %s autogenerated on %s */\n", item, ctime(&t));<br>+}<br>+<br>+static void printfir(const char *name)<br>+{<br>+ int cnt;<br>+<br>+ printf("fir_t fir%s = {\n%d,\n%d,\n{\n", name, g_fir->size, g_fir->step);<br>
+<br>+ for (cnt = 0; cnt < g_fir->size - 1; cnt++)<br>+ printf("%.18g,\n", g_fir->wing[cnt]);<br>+<br>+ printf("%.18g\n}};\n\n", g_fir->wing[cnt]);<br>+}<br>+<br>+int main(void)<br>+{<br>
+ int firidx;<br>+<br>+ memset(g_fir, 0, sizeof(g_fir));<br>+<br>+ printhdr("File");<br>+<br>+ printf("\n#define RESAMPLE_INSANE %d\n", RESAMPLE_INSANE);<br>+<br>+ printf("\ntypedef struct {\n"<br>
+ "int size;\n"<br>+ "int step;\n"<br>+ "double wing[];\n"<br>+ "} fir_t;\n\n");<br>+<br>+ for (firidx = 0; firparams[firidx].name; firidx++)<br>+ {<br>
+ makefir(firidx);<br>+ fprintf(stderr, "size:%d\n", g_fir->size);<br>+ if (firparams[firidx].comment)<br>+ printf("/* %s */\n", firparams[firidx].comment);<br>+ printfir(firparams[firidx].name);<br>
+ deletefir();<br>+ }<br>+<br>+ return 0;<br>+}<br>-- <br>1.7.2.3<br><br><br>