---<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 &lt;stdio.h&gt;<br>+#include &lt;stdlib.h&gt;<br>
+#include &lt;string.h&gt;<br>+#include &lt;math.h&gt;<br>+#include &lt;stdint.h&gt;<br>+#include &lt;time.h&gt;<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 = &amp;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>+  {&quot;fast&quot;,<br>+  12, 4, 4, 0.8<br>+  },<br>+  {&quot;good&quot;,<br>+  22, 6, 10, 0.92<br>+  },<br>+  {&quot;best&quot;,<br>+  62, 8, 16, 0.94<br>+  },<br>+  {&quot;slow&quot;,<br>+  502, 12, 28, 0.95<br>
+  },<br>+#if RESAMPLE_INSANE<br>+  {&quot;insane&quot;,<br>+  2381, 16.2, 142.8975, 0.965,<br>+  &quot;same as libsamplerate high_qual&quot;},<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 &gt;= 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 &lt;= idx; cnt++)<br>+  {<br>+    if (!firparams[cnt].name)<br>+      break;<br>+  }<br>+  idx = cnt - 1;<br>
+<br>+  fprintf(stderr, &quot;creating %s filter...&quot;, firparams[idx].name);<br>+  fflush(stderr);<br>+<br>+  g_fir-&gt;step = firparams[idx].step;<br>+  g_fir-&gt;size = firparams[idx].width0 * g_fir-&gt;step;<br>+  ALLOC(g_fir-&gt;wing, g_fir-&gt;size);<br>
+<br>+  IBeta = 1.0 / Izero(firparams[idx].Beta);<br>+  cutoff = firparams[idx].passband / g_fir-&gt;step;<br>+  g_fir-&gt;wing[0] = 1.0;<br>+<br>+  for (cnt = 1; cnt &lt; g_fir-&gt;size; cnt++)<br>+  {<br>+    tmp = (double) (cnt) / g_fir-&gt;size;<br>
+    tmp2 = M_PI * cnt * cutoff;<br>+<br>+    /* Kaiser windowed sinc */<br>+    g_fir-&gt;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-&gt;wing[0];<br>+  for (cnt = 1; cnt &lt; g_fir-&gt;size; cnt++)<br>+    tmp += 2.0 * g_fir-&gt;wing[cnt];<br>+  tmp = 1.0 / tmp;<br>+  for (cnt = 0; cnt &lt; g_fir-&gt;size; cnt++)<br>+    g_fir-&gt;wing[cnt] *= tmp;<br>
+<br>+  fprintf(stderr, &quot;OK\n&quot;);<br>+}<br>+<br>+static void deletefir(void)<br>+{<br>+  FREE(g_fir-&gt;wing);<br>+  g_fir-&gt;size = 0;<br>+}<br>+<br>+static void printhdr(char *item)<br>+{<br>+  time_t t;<br>+<br>
+  time(&amp;t);<br>+  printf(&quot;/* %s autogenerated on %s */\n&quot;, item, ctime(&amp;t));<br>+}<br>+<br>+static void printfir(const char *name)<br>+{<br>+  int cnt;<br>+<br>+  printf(&quot;fir_t fir%s = {\n%d,\n%d,\n{\n&quot;, name, g_fir-&gt;size, g_fir-&gt;step);<br>
+<br>+  for (cnt = 0; cnt &lt; g_fir-&gt;size - 1; cnt++)<br>+    printf(&quot;%.18g,\n&quot;, g_fir-&gt;wing[cnt]);<br>+<br>+  printf(&quot;%.18g\n}};\n\n&quot;, g_fir-&gt;wing[cnt]);<br>+}<br>+<br>+int main(void)<br>+{<br>
+  int firidx;<br>+<br>+  memset(g_fir, 0, sizeof(g_fir));<br>+<br>+  printhdr(&quot;File&quot;);<br>+<br>+  printf(&quot;\n#define RESAMPLE_INSANE %d\n&quot;, RESAMPLE_INSANE);<br>+<br>+  printf(&quot;\ntypedef struct {\n&quot;<br>
+         &quot;int size;\n&quot;<br>+         &quot;int step;\n&quot;<br>+         &quot;double wing[];\n&quot;<br>+         &quot;} fir_t;\n\n&quot;);<br>+<br>+  for (firidx = 0; firparams[firidx].name; firidx++)<br>+  {<br>
+    makefir(firidx);<br>+    fprintf(stderr, &quot;size:%d\n&quot;, g_fir-&gt;size);<br>+    if (firparams[firidx].comment)<br>+      printf(&quot;/* %s */\n&quot;, 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>