1 | /* |
---|
2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
3 | |
---|
4 | This file is part of aubio. |
---|
5 | |
---|
6 | aubio is free software: you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation, either version 3 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | aubio is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | #include "aubio_priv.h" |
---|
22 | #include "types.h" |
---|
23 | #include "fvec.h" |
---|
24 | #include "lvec.h" |
---|
25 | #include "temporal/filter.h" |
---|
26 | #include "temporal/c_weighting.h" |
---|
27 | |
---|
28 | void aubio_filter_set_c_weighting (aubio_filter_t * f) { |
---|
29 | |
---|
30 | uint_t samplerate = aubio_filter_get_samplerate (f); |
---|
31 | lvec_t * bs = aubio_filter_get_feedforward (f); |
---|
32 | lvec_t * as = aubio_filter_get_feedback (f); |
---|
33 | lsmp_t *b = bs->data[0], *a = as->data[0]; |
---|
34 | uint_t order = aubio_filter_get_order (f); |
---|
35 | |
---|
36 | if ( order != 5 ) { |
---|
37 | AUBIO_ERROR ( "order of C-weighting filter must be 5, not %d\n", order ); |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | /* select coefficients according to sampling frequency */ |
---|
42 | switch ( samplerate ) { |
---|
43 | |
---|
44 | // cdsgn 8000 |
---|
45 | case 8000: |
---|
46 | b[0] = 6.782173932405135552414776611840352416038513183593750000e-01; |
---|
47 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
48 | b[2] = -1.356434786481027110482955322368070483207702636718750000e+00; |
---|
49 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
50 | b[4] = 6.782173932405135552414776611840352416038513183593750000e-01; |
---|
51 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
52 | a[1] = -6.589092811505605773447769024642184376716613769531250000e-01; |
---|
53 | a[2] = -1.179445664897062595599663836765103042125701904296875000e+00; |
---|
54 | a[3] = 4.243329729632123736848825501510873436927795410156250000e-01; |
---|
55 | a[4] = 4.147270002091348328754349950031610205769538879394531250e-01; |
---|
56 | break; |
---|
57 | |
---|
58 | // cdsgn 11025 |
---|
59 | case 11025: |
---|
60 | b[0] = 6.002357155402652244546857218665536493062973022460937500e-01; |
---|
61 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
62 | b[2] = -1.200471431080530448909371443733107298612594604492187500e+00; |
---|
63 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
64 | b[4] = 6.002357155402652244546857218665536493062973022460937500e-01; |
---|
65 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
66 | a[1] = -8.705602141280316397242700077185872942209243774414062500e-01; |
---|
67 | a[2] = -9.037199507150940336330791069485712796449661254882812500e-01; |
---|
68 | a[3] = 4.758433040929530011275971901341108605265617370605468750e-01; |
---|
69 | a[4] = 2.987653956523212417373258631414500996470451354980468750e-01; |
---|
70 | break; |
---|
71 | |
---|
72 | // cdsgn 16000 |
---|
73 | case 16000: |
---|
74 | b[0] = 4.971057193673903418229542694461997598409652709960937500e-01; |
---|
75 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
76 | b[2] = -9.942114387347806836459085388923995196819305419921875000e-01; |
---|
77 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
78 | b[4] = 4.971057193673903418229542694461997598409652709960937500e-01; |
---|
79 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
80 | a[1] = -1.162322939286873690889478893950581550598144531250000000e+00; |
---|
81 | a[2] = -4.771961355734982701548574368644040077924728393554687500e-01; |
---|
82 | a[3] = 4.736145114694704227886745684372726827859878540039062500e-01; |
---|
83 | a[4] = 1.660337524309875301131711466950946487486362457275390625e-01; |
---|
84 | break; |
---|
85 | |
---|
86 | // cdsgn 22050 |
---|
87 | case 22050: |
---|
88 | b[0] = 4.033381299002754549754001800465630367398262023925781250e-01; |
---|
89 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
90 | b[2] = -8.066762598005509099508003600931260734796524047851562500e-01; |
---|
91 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
92 | b[4] = 4.033381299002754549754001800465630367398262023925781250e-01; |
---|
93 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
94 | a[1] = -1.449545371157945350404361306573264300823211669921875000e+00; |
---|
95 | a[2] = -1.030104190885922088583015465701464563608169555664062500e-02; |
---|
96 | a[3] = 3.881857047554073680828423675848171114921569824218750000e-01; |
---|
97 | a[4] = 7.171589940116777917022972133054281584918498992919921875e-02; |
---|
98 | break; |
---|
99 | |
---|
100 | // cdsgn 24000 |
---|
101 | case 24000: |
---|
102 | b[0] = 3.786678621924967069745093795063439756631851196289062500e-01; |
---|
103 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
104 | b[2] = -7.573357243849934139490187590126879513263702392578125000e-01; |
---|
105 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
106 | b[4] = 3.786678621924967069745093795063439756631851196289062500e-01; |
---|
107 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
108 | a[1] = -1.529945307555420797029910318087786436080932617187500000e+00; |
---|
109 | a[2] = 1.283553182116208835061854642844991758465766906738281250e-01; |
---|
110 | a[3] = 3.494608072385725350272878131363540887832641601562500000e-01; |
---|
111 | a[4] = 5.217291949300089520802359288609295617789030075073242188e-02; |
---|
112 | break; |
---|
113 | |
---|
114 | // cdsgn 32000 |
---|
115 | case 32000: |
---|
116 | b[0] = 2.977986488230693340462096330156782642006874084472656250e-01; |
---|
117 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
118 | b[2] = -5.955972976461386680924192660313565284013748168945312500e-01; |
---|
119 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
120 | b[4] = 2.977986488230693340462096330156782642006874084472656250e-01; |
---|
121 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
122 | a[1] = -1.812455387128179218336754274787381291389465332031250000e+00; |
---|
123 | a[2] = 6.425013281155662614452239722595550119876861572265625000e-01; |
---|
124 | a[3] = 1.619857574578579817448087396769551560282707214355468750e-01; |
---|
125 | a[4] = 7.987649713547682189807019881300220731645822525024414062e-03; |
---|
126 | break; |
---|
127 | |
---|
128 | // cdsgn 44100 |
---|
129 | case 44100: |
---|
130 | b[0] = 2.170085619492190254220531642204150557518005371093750000e-01; |
---|
131 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
132 | b[2] = -4.340171238984380508441063284408301115036010742187500000e-01; |
---|
133 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
134 | b[4] = 2.170085619492190254220531642204150557518005371093750000e-01; |
---|
135 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
136 | a[1] = -2.134674963687040794013682898366823792457580566406250000e+00; |
---|
137 | a[2] = 1.279333533236062692139967111870646476745605468750000000e+00; |
---|
138 | a[3] = -1.495598460893957093453821016737492755055427551269531250e-01; |
---|
139 | a[4] = 4.908700174624683852664386307651511742733418941497802734e-03; |
---|
140 | break; |
---|
141 | |
---|
142 | // cdsgn 48000 |
---|
143 | case 48000: |
---|
144 | b[0] = 1.978871200263932761398422144338837824761867523193359375e-01; |
---|
145 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
146 | b[2] = -3.957742400527865522796844288677675649523735046386718750e-01; |
---|
147 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
148 | b[4] = 1.978871200263932761398422144338837824761867523193359375e-01; |
---|
149 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
150 | a[1] = -2.219172914052801814932536217384040355682373046875000000e+00; |
---|
151 | a[2] = 1.455135878947171557129536267893854528665542602539062500e+00; |
---|
152 | a[3] = -2.484960738877830532800317087094299495220184326171875000e-01; |
---|
153 | a[4] = 1.253882314727246607977129144728678511455655097961425781e-02; |
---|
154 | break; |
---|
155 | |
---|
156 | // cdsgn 88200 |
---|
157 | case 88200: |
---|
158 | b[0] = 9.221909851156021020734954163344809785485267639160156250e-02; |
---|
159 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
160 | b[2] = -1.844381970231204204146990832668961957097053527832031250e-01; |
---|
161 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
162 | b[4] = 9.221909851156021020734954163344809785485267639160156250e-02; |
---|
163 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
164 | a[1] = -2.785795902923448696952846148633398115634918212890625000e+00; |
---|
165 | a[2] = 2.727736758747444145711824603495188057422637939453125000e+00; |
---|
166 | a[3] = -1.097007502819661528548067508381791412830352783203125000e+00; |
---|
167 | a[4] = 1.550674356752141103132913713125162757933139801025390625e-01; |
---|
168 | break; |
---|
169 | |
---|
170 | // cdsgn 96000 |
---|
171 | case 96000: |
---|
172 | b[0] = 8.182864044979756834585771230194950476288795471191406250e-02; |
---|
173 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
174 | b[2] = -1.636572808995951366917154246038990095257759094238281250e-01; |
---|
175 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
176 | b[4] = 8.182864044979756834585771230194950476288795471191406250e-02; |
---|
177 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
178 | a[1] = -2.856378516857566829401093855267390608787536621093750000e+00; |
---|
179 | a[2] = 2.897640237559524045707348705036565661430358886718750000e+00; |
---|
180 | a[3] = -1.225265958339703198376469117647502571344375610351562500e+00; |
---|
181 | a[4] = 1.840048283551226071530493300087982788681983947753906250e-01; |
---|
182 | break; |
---|
183 | |
---|
184 | // cdsgn 192000 |
---|
185 | case 192000: |
---|
186 | b[0] = 2.784755468532278815940728122768632601946592330932617188e-02; |
---|
187 | b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
188 | b[2] = -5.569510937064557631881456245537265203893184661865234375e-02; |
---|
189 | b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; |
---|
190 | b[4] = 2.784755468532278815940728122768632601946592330932617188e-02; |
---|
191 | a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; |
---|
192 | a[1] = -3.333298856144166322224009491037577390670776367187500000e+00; |
---|
193 | a[2] = 4.111467536240339448738723149290308356285095214843750000e+00; |
---|
194 | a[3] = -2.222889041651291641699117462849244475364685058593750000e+00; |
---|
195 | a[4] = 4.447204118126878991112960193277103826403617858886718750e-01; |
---|
196 | break; |
---|
197 | |
---|
198 | default: |
---|
199 | AUBIO_ERROR ( "sampling rate of C-weighting filter is %d, should be one of\ |
---|
200 | 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 192000.\n", |
---|
201 | samplerate ); |
---|
202 | break; |
---|
203 | |
---|
204 | } |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate, uint_t channels) { |
---|
209 | aubio_filter_t * f = new_aubio_filter(samplerate, 5, channels); |
---|
210 | aubio_filter_set_c_weighting (f); |
---|
211 | return f; |
---|
212 | } |
---|
213 | |
---|