OLD | NEW |
1 /* Copyright (c) 2009-2010 Xiph.Org Foundation | 1 /* Copyright (c) 2008-2011 Octasic Inc. |
2 Written by Jean-Marc Valin */ | 2 Written by Jean-Marc Valin */ |
3 /* | 3 /* |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 | 10 |
11 - Redistributions in binary form must reproduce the above copyright | 11 - Redistributions in binary form must reproduce the above copyright |
12 notice, this list of conditions and the following disclaimer in the | 12 notice, this list of conditions and the following disclaimer in the |
13 documentation and/or other materials provided with the distribution. | 13 documentation and/or other materials provided with the distribution. |
14 | 14 |
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #ifndef PLC_H | 28 #ifndef _MLP_TRAIN_H_ |
29 #define PLC_H | 29 #define _MLP_TRAIN_H_ |
30 | 30 |
31 #include "arch.h" | 31 #include <math.h> |
| 32 #include <stdlib.h> |
32 | 33 |
33 #define LPC_ORDER 24 | 34 double tansig_table[501]; |
| 35 static inline double tansig_double(double x) |
| 36 { |
| 37 » return 2./(1.+exp(-2.*x)) - 1.; |
| 38 } |
| 39 static inline void build_tansig_table() |
| 40 { |
| 41 » int i; |
| 42 » for (i=0;i<501;i++) |
| 43 » » tansig_table[i] = tansig_double(.04*(i-250)); |
| 44 } |
34 | 45 |
35 void _celt_lpc(opus_val16 *_lpc, const opus_val32 *ac, int p); | 46 static inline double tansig_approx(double x) |
| 47 { |
| 48 » int i; |
| 49 » double y, dy; |
| 50 » if (x>=10) |
| 51 » » return 1; |
| 52 » if (x<=-10) |
| 53 » » return -1; |
| 54 » i = lrint(25*x); |
| 55 » x -= .04*i; |
| 56 » y = tansig_table[250+i]; |
| 57 » dy = 1-y*y; |
| 58 » y = y + x*dy*(1 - y*x); |
| 59 » return y; |
| 60 } |
36 | 61 |
37 void celt_fir(const opus_val16 *x, | 62 inline float randn(float sd) |
38 const opus_val16 *num, | 63 { |
39 opus_val16 *y, | 64 float U1, U2, S, x; |
40 int N, | 65 do { |
41 int ord, | 66 U1 = ((float)rand())/RAND_MAX; |
42 opus_val16 *mem); | 67 U2 = ((float)rand())/RAND_MAX; |
| 68 U1 = 2*U1-1; |
| 69 U2 = 2*U2-1; |
| 70 S = U1*U1 + U2*U2; |
| 71 } while (S >= 1 || S == 0.0f); |
| 72 x = sd*sqrt(-2 * log(S) / S) * U1; |
| 73 return x; |
| 74 } |
43 | 75 |
44 void celt_iir(const opus_val32 *x, | |
45 const opus_val16 *den, | |
46 opus_val32 *y, | |
47 int N, | |
48 int ord, | |
49 opus_val16 *mem); | |
50 | 76 |
51 void _celt_autocorr(const opus_val16 *x, opus_val32 *ac, const opus_val16 *windo
w, int overlap, int lag, int n); | 77 typedef struct { |
| 78 » int layers; |
| 79 » int *topo; |
| 80 » double **weights; |
| 81 » double **best_weights; |
| 82 » double *in_rate; |
| 83 } MLPTrain; |
52 | 84 |
53 #endif /* PLC_H */ | 85 |
| 86 #endif /* _MLP_TRAIN_H_ */ |
OLD | NEW |