| OLD | NEW |
| 1 /* Copyright (c) 2008-2011 Octasic Inc. | 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 #ifdef HAVE_CONFIG_H | 28 #ifdef HAVE_CONFIG_H |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 #include "opus_types.h" |
| 33 #include "opus_defines.h" |
| 34 |
| 32 #include <math.h> | 35 #include <math.h> |
| 33 #include "mlp.h" | 36 #include "mlp.h" |
| 34 #include "arch.h" | 37 #include "arch.h" |
| 35 #include "tansig_table.h" | 38 #include "tansig_table.h" |
| 36 #define MAX_NEURONS 100 | 39 #define MAX_NEURONS 100 |
| 37 | 40 |
| 38 #if 0 | 41 #if 0 |
| 39 static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ | 42 static OPUS_INLINE opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ |
| 40 { | 43 { |
| 41 int i; | 44 int i; |
| 42 opus_val16 xx; /* Q11 */ | 45 opus_val16 xx; /* Q11 */ |
| 43 /*double x, y;*/ | 46 /*double x, y;*/ |
| 44 opus_val16 dy, yy; /* Q14 */ | 47 opus_val16 dy, yy; /* Q14 */ |
| 45 /*x = 1.9073e-06*_x;*/ | 48 /*x = 1.9073e-06*_x;*/ |
| 46 if (_x>=QCONST32(8,19)) | 49 if (_x>=QCONST32(8,19)) |
| 47 return QCONST32(1.,14); | 50 return QCONST32(1.,14); |
| 48 if (_x<=-QCONST32(8,19)) | 51 if (_x<=-QCONST32(8,19)) |
| 49 return -QCONST32(1.,14); | 52 return -QCONST32(1.,14); |
| 50 xx = EXTRACT16(SHR32(_x, 8)); | 53 xx = EXTRACT16(SHR32(_x, 8)); |
| 51 /*i = lrint(25*x);*/ | 54 /*i = lrint(25*x);*/ |
| 52 i = SHR32(ADD32(1024,MULT16_16(25, xx)),11); | 55 i = SHR32(ADD32(1024,MULT16_16(25, xx)),11); |
| 53 /*x -= .04*i;*/ | 56 /*x -= .04*i;*/ |
| 54 xx -= EXTRACT16(SHR32(MULT16_16(20972,i),8)); | 57 xx -= EXTRACT16(SHR32(MULT16_16(20972,i),8)); |
| 55 /*x = xx*(1./2048);*/ | 58 /*x = xx*(1./2048);*/ |
| 56 /*y = tansig_table[250+i];*/ | 59 /*y = tansig_table[250+i];*/ |
| 57 yy = tansig_table[250+i]; | 60 yy = tansig_table[250+i]; |
| 58 /*y = yy*(1./16384);*/ | 61 /*y = yy*(1./16384);*/ |
| 59 dy = 16384-MULT16_16_Q14(yy,yy); | 62 dy = 16384-MULT16_16_Q14(yy,yy); |
| 60 yy = yy + MULT16_16_Q14(MULT16_16_Q11(xx,dy),(16384 - MULT16_16_Q11(yy,x
x))); | 63 yy = yy + MULT16_16_Q14(MULT16_16_Q11(xx,dy),(16384 - MULT16_16_Q11(yy,x
x))); |
| 61 return yy; | 64 return yy; |
| 62 } | 65 } |
| 63 #else | 66 #else |
| 64 /*extern const float tansig_table[501];*/ | 67 /*extern const float tansig_table[501];*/ |
| 65 static inline float tansig_approx(float x) | 68 static OPUS_INLINE float tansig_approx(float x) |
| 66 { | 69 { |
| 67 int i; | 70 int i; |
| 68 float y, dy; | 71 float y, dy; |
| 69 float sign=1; | 72 float sign=1; |
| 70 if (x>=8) | 73 » /* Tests are reversed to catch NaNs */ |
| 74 if (!(x<8)) |
| 71 return 1; | 75 return 1; |
| 72 if (x<=-8) | 76 if (!(x>-8)) |
| 73 return -1; | 77 return -1; |
| 74 if (x<0) | 78 if (x<0) |
| 75 { | 79 { |
| 76 x=-x; | 80 x=-x; |
| 77 sign=-1; | 81 sign=-1; |
| 78 } | 82 } |
| 79 i = (int)floor(.5f+25*x); | 83 i = (int)floor(.5f+25*x); |
| 80 x -= .04f*i; | 84 x -= .04f*i; |
| 81 y = tansig_table[i]; | 85 y = tansig_table[i]; |
| 82 dy = 1-y*y; | 86 dy = 1-y*y; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 for (j=0;j<m->topo[2];j++) | 131 for (j=0;j<m->topo[2];j++) |
| 128 { | 132 { |
| 129 int k; | 133 int k; |
| 130 float sum = *W++; | 134 float sum = *W++; |
| 131 for (k=0;k<m->topo[1];k++) | 135 for (k=0;k<m->topo[1];k++) |
| 132 sum = sum + hidden[k]**W++; | 136 sum = sum + hidden[k]**W++; |
| 133 out[j] = tansig_approx(sum); | 137 out[j] = tansig_approx(sum); |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 #endif | 140 #endif |
| OLD | NEW |