3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 while (y > 0 && x != 0) {
58 function calcdiv(r, x, y, z)
63 while (shr((y * x), z) < 1)
66 while ((y % 2) == 0 && z > 0) {
77 FXONE = shl(1, FXSHIFT);
86 SND_MAX_ALIGN = SND_CHN_MAX * PCM_32_BPS;
88 for (i = 1; i <= SND_CHN_MAX; i++) {
89 aligns[PCM_8_BPS * i] = 1;
90 aligns[PCM_16_BPS * i] = 1;
91 aligns[PCM_24_BPS * i] = 1;
92 aligns[PCM_32_BPS * i] = 1;
95 printf("#ifndef _SND_FXDIV_GEN_H_\n");
96 printf("#define _SND_FXDIV_GEN_H_\n\n");
99 printf(" * Generated using snd_fxdiv_gen.awk, heaven, wind and awesome.\n");
101 printf(" * DO NOT EDIT!\n");
103 printf("#ifdef SND_USE_FXDIV\n\n");
106 printf(" * Fast unsigned 32bit integer division and rounding, accurate for\n");
107 printf(" * x = 1 - %d. This table should be enough to handle possible\n", FXONE);
108 printf(" * division for 1 - 508 (more can be generated though..).\n");
110 printf(" * 508 = SND_CHN_MAX * PCM_32_BPS, which is why....\n");
113 printf("extern const uint32_t snd_fxdiv_table[%d][2];\n\n", SND_MAX_ALIGN + 1);
115 printf("#ifdef SND_DECLARE_FXDIV\n");
116 printf("const uint32_t snd_fxdiv_table[%d][2] = {\n", SND_MAX_ALIGN + 1);
118 for (i = 1; i <= SND_MAX_ALIGN; i++) {
122 printf("\t[0x%02x] = { 0x%04x, 0x%02x },", \
123 i, r["mul"], r["shift"]);
124 printf("\t/* x / %-2d = (x * %-5d) >> %-2d */\n", \
125 i, r["mul"], r["shift"]);
128 printf("};\n#endif\n\n");
130 printf("#define SND_FXDIV_MAX\t\t0x%08x\n", FXONE);
131 printf("#define SND_FXDIV(x, y)\t\t(((uint32_t)(x) *\t\t\t\\\n");
132 printf("\t\t\t\t snd_fxdiv_table[y][0]) >>\t\t\\\n");
133 printf("\t\t\t\t snd_fxdiv_table[y][1])\n");
134 printf("#define SND_FXROUND(x, y)\t(SND_FXDIV(x, y) * (y))\n");
135 printf("#define SND_FXMOD(x, y)\t\t((x) - SND_FXROUND(x, y))\n\n");
137 printf("#else\t/* !SND_USE_FXDIV */\n\n");
139 printf("#define SND_FXDIV_MAX\t\t0x%08x\n", 131072);
140 printf("#define SND_FXDIV(x, y)\t\t((x) / (y))\n");
141 printf("#define SND_FXROUND(x, y)\t((x) - ((x) %% (y)))\n");
142 printf("#define SND_FXMOD(x, y)\t\t((x) %% (y))\n\n");
144 printf("#endif\t/* SND_USE_FXDIV */\n\n");
146 printf("#endif\t/* !_SND_FXDIV_GEN_H_ */\n");