Mercurial > fife-parpg
annotate ext/openal-soft/Alc/bs2b.c @ 246:8156de05a544
Documentation for the World
class in rio de hola.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 25 Mar 2009 15:42:14 +0000 |
parents | a18f09b604f2 |
children |
rev | line source |
---|---|
214
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
1 /*- |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
2 * Copyright (c) 2005 Boris Mikhaylov |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
3 * |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
10 * the following conditions: |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
11 * |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
12 * The above copyright notice and this permission notice shall be |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
13 * included in all copies or substantial portions of the Software. |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
14 * |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
22 */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
23 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
24 #include "config.h" |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
25 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
26 #include <math.h> |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
27 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
28 #include "bs2b.h" |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
29 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
30 #ifndef M_PI |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
31 #define M_PI 3.14159265358979323846 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
32 #endif |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
33 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
34 /* Single pole IIR filter. |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
35 * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1] |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
36 */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
37 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
38 /* Lowpass filter */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
39 #define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1)) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
40 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
41 /* Highboost filter */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
42 #define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1)) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
43 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
44 /* Set up all data. */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
45 static void init(struct bs2b *bs2b) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
46 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
47 double Fc_lo, Fc_hi; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
48 double G_lo, G_hi; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
49 double x; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
50 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
51 if ((bs2b->srate > 192000) || (bs2b->srate < 2000)) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
52 bs2b->srate = BS2B_DEFAULT_SRATE; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
53 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
54 switch(bs2b->level) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
55 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
56 case BS2B_LOW_CLEVEL: /* Low crossfeed level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
57 Fc_lo = 360.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
58 Fc_hi = 501.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
59 G_lo = 0.398107170553497; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
60 G_hi = 0.205671765275719; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
61 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
62 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
63 case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
64 Fc_lo = 500.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
65 Fc_hi = 711.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
66 G_lo = 0.459726988530872; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
67 G_hi = 0.228208484414988; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
68 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
69 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
70 case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
71 Fc_lo = 700.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
72 Fc_hi = 1021.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
73 G_lo = 0.530884444230988; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
74 G_hi = 0.250105790667544; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
75 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
76 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
77 case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
78 Fc_lo = 360.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
79 Fc_hi = 494.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
80 G_lo = 0.316227766016838; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
81 G_hi = 0.168236228897329; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
82 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
83 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
84 case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
85 Fc_lo = 500.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
86 Fc_hi = 689.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
87 G_lo = 0.354813389233575; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
88 G_hi = 0.187169483835901; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
89 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
90 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
91 default: /* High easy crossfeed level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
92 bs2b->level = BS2B_HIGH_ECLEVEL; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
93 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
94 Fc_lo = 700.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
95 Fc_hi = 975.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
96 G_lo = 0.398107170553497; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
97 G_hi = 0.205671765275719; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
98 break; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
99 } /* switch */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
100 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
101 /* $fc = $Fc / $s; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
102 * $d = 1 / 2 / pi / $fc; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
103 * $x = exp(-1 / $d); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
104 */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
105 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
106 x = exp(-2.0 * M_PI * Fc_lo / bs2b->srate); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
107 bs2b->b1_lo = x; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
108 bs2b->a0_lo = G_lo * (1.0 - x); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
109 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
110 x = exp(-2.0 * M_PI * Fc_hi / bs2b->srate); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
111 bs2b->b1_hi = x; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
112 bs2b->a0_hi = 1.0 - G_hi * (1.0 - x); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
113 bs2b->a1_hi = -x; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
114 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
115 bs2b->gain = 1.0 / (1.0 - G_hi + G_lo); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
116 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
117 bs2b_clear(bs2b); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
118 } /* init */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
119 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
120 /* Exported functions. |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
121 * See descriptions in "bs2b.h" |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
122 */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
123 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
124 void bs2b_set_level(struct bs2b *bs2b, int level) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
125 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
126 if(level == bs2b->level) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
127 return; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
128 bs2b->level = level; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
129 init(bs2b); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
130 } /* bs2b_set_level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
131 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
132 int bs2b_get_level(struct bs2b *bs2b) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
133 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
134 return bs2b->level; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
135 } /* bs2b_get_level */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
136 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
137 void bs2b_set_srate(struct bs2b *bs2b, int srate) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
138 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
139 if (srate == bs2b->srate) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
140 return; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
141 bs2b->srate = srate; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
142 init(bs2b); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
143 } /* bs2b_set_srate */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
144 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
145 int bs2b_get_srate(struct bs2b *bs2b) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
146 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
147 return bs2b->srate; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
148 } /* bs2b_get_srate */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
149 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
150 void bs2b_clear(struct bs2b *bs2b) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
151 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
152 int loopv = sizeof(bs2b->last_sample); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
153 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
154 while (loopv) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
155 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
156 ((char *)&bs2b->last_sample)[--loopv] = 0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
157 } |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
158 } /* bs2b_clear */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
159 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
160 int bs2b_is_clear(struct bs2b *bs2b) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
161 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
162 int loopv = sizeof(bs2b->last_sample); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
163 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
164 while (loopv) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
165 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
166 if (((char *)&bs2b->last_sample)[--loopv] != 0) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
167 return 0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
168 } |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
169 return 1; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
170 } /* bs2b_is_clear */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
171 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
172 void bs2b_cross_feed(struct bs2b *bs2b, float *sample) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
173 { |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
174 /* Lowpass filter */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
175 bs2b->last_sample.lo[0] = lo_filter(sample[0], bs2b->last_sample.lo[0]); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
176 bs2b->last_sample.lo[1] = lo_filter(sample[1], bs2b->last_sample.lo[1]); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
177 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
178 /* Highboost filter */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
179 bs2b->last_sample.hi[0] = hi_filter(sample[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
180 bs2b->last_sample.hi[1] = hi_filter(sample[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]); |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
181 bs2b->last_sample.asis[0] = sample[0]; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
182 bs2b->last_sample.asis[1] = sample[1]; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
183 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
184 /* Crossfeed */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
185 sample[0] = bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
186 sample[1] = bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
187 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
188 /* Bass boost cause allpass attenuation */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
189 sample[0] *= bs2b->gain; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
190 sample[1] *= bs2b->gain; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
191 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
192 /* Clipping of overloaded samples */ |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
193 #if 0 |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
194 if (sample[0] > 1.0) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
195 sample[0] = 1.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
196 if (sample[0] < -1.0) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
197 sample[0] = -1.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
198 if (sample[1] > 1.0) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
199 sample[1] = 1.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
200 if (sample[1] < -1.0) |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
201 sample[1] = -1.0; |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
202 #endif |
a18f09b604f2
Added svn:eol-style on files that didn't already have that property.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
203 } /* bs2b_cross_feed */ |