3 # Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # $FreeBSD: head/sys/tools/sound/snd_fxdiv_gen.awk 193889 2009-06-10 06:49:45Z ariff $
49 while (y
> 0 && x
!= 0) {
56 function calcdiv
(r
, x
, y
, z
)
61 while (shr
((y
* x
), z
) < 1)
64 while ((y %
2) ==
0 && z
> 0) {
75 FXONE = shl
(1, FXSHIFT
);
84 SND_MAX_ALIGN = SND_CHN_MAX
* PCM_32_BPS
;
86 for (i =
1; i
<= SND_CHN_MAX
; i
++) {
87 aligns
[PCM_8_BPS
* i
] =
1;
88 aligns
[PCM_16_BPS
* i
] =
1;
89 aligns
[PCM_24_BPS
* i
] =
1;
90 aligns
[PCM_32_BPS
* i
] =
1;
93 printf("#ifndef _SND_FXDIV_GEN_H_\n");
94 printf("#define _SND_FXDIV_GEN_H_\n\n");
97 printf(" * Generated using snd_fxdiv_gen.awk, heaven, wind and awesome.\n");
99 printf(" * DO NOT EDIT!\n");
101 printf("#ifdef SND_USE_FXDIV\n\n");
104 printf(" * Fast unsigned 32bit integer division and rounding, accurate for\n");
105 printf(" * x = 1 - %d. This table should be enough to handle possible\n", FXONE
);
106 printf(" * division for 1 - 72 (more can be generated though..).\n");
108 printf(" * 72 = SND_CHN_MAX * PCM_32_BPS, which is why....\n");
111 printf("static const uint32_t snd_fxdiv_table[][2] = {\n");
113 for (i =
1; i
<= SND_MAX_ALIGN
; i
++) {
117 printf("\t[0x%02x] = { 0x%04x, 0x%02x },", \
118 i
, r
["mul"], r
["shift"]);
119 printf("\t/* x / %-2d = (x * %-5d) >> %-2d */\n", \
120 i
, r
["mul"], r
["shift"]);
125 printf("#define SND_FXDIV_MAX\t\t0x%08x\n", FXONE
);
126 printf("#define SND_FXDIV(x, y)\t\t(((uint32_t)(x) *\t\t\t\\\n");
127 printf("\t\t\t\t snd_fxdiv_table[y][0]) >>\t\t\\\n");
128 printf("\t\t\t\t snd_fxdiv_table[y][1])\n");
129 printf("#define SND_FXROUND(x, y)\t(SND_FXDIV(x, y) * (y))\n");
130 printf("#define SND_FXMOD(x, y)\t\t((x) - SND_FXROUND(x, y))\n\n");
132 printf("#else\t/* !SND_USE_FXDIV */\n\n");
134 printf("#define SND_FXDIV_MAX\t\t0x%08x\n", 131072);
135 printf("#define SND_FXDIV(x, y)\t\t((x) / (y))\n");
136 printf("#define SND_FXROUND(x, y)\t((x) - ((x) %% (y)))\n");
137 printf("#define SND_FXMOD(x, y)\t\t((x) %% (y))\n\n");
139 printf("#endif\t/* SND_USE_FXDIV */\n\n");
141 printf("#endif\t/* !_SND_FXDIV_GEN_H_ */\n");