| OLD | NEW |
| 1 /* Copyright (c) 2007-2008 CSIRO | 1 /* Copyright (c) 2007-2008 CSIRO |
| 2 Copyright (c) 2007-2010 Xiph.Org Foundation | 2 Copyright (c) 2007-2010 Xiph.Org Foundation |
| 3 Copyright (c) 2008 Gregory Maxwell | 3 Copyright (c) 2008 Gregory Maxwell |
| 4 Written by Jean-Marc Valin and Gregory Maxwell */ | 4 Written by Jean-Marc Valin and Gregory Maxwell */ |
| 5 /* | 5 /* |
| 6 Redistribution and use in source and binary forms, with or without | 6 Redistribution and use in source and binary forms, with or without |
| 7 modification, are permitted provided that the following conditions | 7 modification, are permitted provided that the following conditions |
| 8 are met: | 8 are met: |
| 9 | 9 |
| 10 - Redistributions of source code must retain the above copyright | 10 - Redistributions of source code must retain the above copyright |
| 11 notice, this list of conditions and the following disclaimer. | 11 notice, this list of conditions and the following disclaimer. |
| 12 | 12 |
| 13 - Redistributions in binary form must reproduce the above copyright | 13 - Redistributions in binary form must reproduce the above copyright |
| 14 notice, this list of conditions and the following disclaimer in the | 14 notice, this list of conditions and the following disclaimer in the |
| 15 documentation and/or other materials provided with the distribution. | 15 documentation and/or other materials provided with the distribution. |
| 16 | 16 |
| 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 21 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 21 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 22 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 24 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #ifndef __CELT_MIPSR1_H__ |
| 31 #define __CELT_MIPSR1_H__ |
| 32 |
| 30 #ifdef HAVE_CONFIG_H | 33 #ifdef HAVE_CONFIG_H |
| 31 #include "config.h" | 34 #include "config.h" |
| 32 #endif | 35 #endif |
| 33 | 36 |
| 34 #define CELT_C | 37 #define CELT_C |
| 35 | 38 |
| 36 #include "os_support.h" | 39 #include "os_support.h" |
| 37 #include "mdct.h" | 40 #include "mdct.h" |
| 38 #include <math.h> | 41 #include <math.h> |
| 39 #include "celt.h" | 42 #include "celt.h" |
| 40 #include "pitch.h" | 43 #include "pitch.h" |
| 41 #include "bands.h" | 44 #include "bands.h" |
| 42 #include "modes.h" | 45 #include "modes.h" |
| 43 #include "entcode.h" | 46 #include "entcode.h" |
| 44 #include "quant_bands.h" | 47 #include "quant_bands.h" |
| 45 #include "rate.h" | 48 #include "rate.h" |
| 46 #include "stack_alloc.h" | 49 #include "stack_alloc.h" |
| 47 #include "mathops.h" | 50 #include "mathops.h" |
| 48 #include "float_cast.h" | 51 #include "float_cast.h" |
| 49 #include <stdarg.h> | 52 #include <stdarg.h> |
| 50 #include "celt_lpc.h" | 53 #include "celt_lpc.h" |
| 51 #include "vq.h" | 54 #include "vq.h" |
| 52 | 55 |
| 53 #ifndef PACKAGE_VERSION | 56 #define OVERRIDE_comb_filter |
| 54 #define PACKAGE_VERSION "unknown" | |
| 55 #endif | |
| 56 | |
| 57 | |
| 58 int resampling_factor(opus_int32 rate) | |
| 59 { | |
| 60 int ret; | |
| 61 switch (rate) | |
| 62 { | |
| 63 case 48000: | |
| 64 ret = 1; | |
| 65 break; | |
| 66 case 24000: | |
| 67 ret = 2; | |
| 68 break; | |
| 69 case 16000: | |
| 70 ret = 3; | |
| 71 break; | |
| 72 case 12000: | |
| 73 ret = 4; | |
| 74 break; | |
| 75 case 8000: | |
| 76 ret = 6; | |
| 77 break; | |
| 78 default: | |
| 79 #ifndef CUSTOM_MODES | |
| 80 celt_assert(0); | |
| 81 #endif | |
| 82 ret = 0; | |
| 83 break; | |
| 84 } | |
| 85 return ret; | |
| 86 } | |
| 87 | |
| 88 #ifndef OVERRIDE_COMB_FILTER_CONST | |
| 89 static void comb_filter_const(opus_val32 *y, opus_val32 *x, int T, int N, | |
| 90 opus_val16 g10, opus_val16 g11, opus_val16 g12) | |
| 91 { | |
| 92 opus_val32 x0, x1, x2, x3, x4; | |
| 93 int i; | |
| 94 x4 = x[-T-2]; | |
| 95 x3 = x[-T-1]; | |
| 96 x2 = x[-T]; | |
| 97 x1 = x[-T+1]; | |
| 98 for (i=0;i<N;i++) | |
| 99 { | |
| 100 x0=x[i-T+2]; | |
| 101 y[i] = x[i] | |
| 102 + MULT16_32_Q15(g10,x2) | |
| 103 + MULT16_32_Q15(g11,ADD32(x1,x3)) | |
| 104 + MULT16_32_Q15(g12,ADD32(x0,x4)); | |
| 105 x4=x3; | |
| 106 x3=x2; | |
| 107 x2=x1; | |
| 108 x1=x0; | |
| 109 } | |
| 110 | |
| 111 } | |
| 112 #endif | |
| 113 | |
| 114 void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, | 57 void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, |
| 115 opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, | 58 opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, |
| 116 const opus_val16 *window, int overlap) | 59 const opus_val16 *window, int overlap) |
| 117 { | 60 { |
| 118 int i; | 61 int i; |
| 62 opus_val32 x0, x1, x2, x3, x4; |
| 63 |
| 119 /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */ | 64 /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */ |
| 120 opus_val16 g00, g01, g02, g10, g11, g12; | 65 opus_val16 g00, g01, g02, g10, g11, g12; |
| 121 opus_val32 x0, x1, x2, x3, x4; | |
| 122 static const opus_val16 gains[3][3] = { | 66 static const opus_val16 gains[3][3] = { |
| 123 {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1
296386719f, 15)}, | 67 {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1
296386719f, 15)}, |
| 124 {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f
, 15)}, | 68 {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f
, 15)}, |
| 125 {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f
, 15)}}; | 69 {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f
, 15)}}; |
| 126 | 70 |
| 127 if (g0==0 && g1==0) | 71 if (g0==0 && g1==0) |
| 128 { | 72 { |
| 129 /* OPT: Happens to work without the OPUS_MOVE(), but only because the curr
ent encoder already copies x to y */ | 73 /* OPT: Happens to work without the OPUS_MOVE(), but only because the curr
ent encoder already copies x to y */ |
| 130 if (x!=y) | 74 if (x!=y) |
| 131 OPUS_MOVE(y, x, N); | 75 OPUS_MOVE(y, x, N); |
| 132 return; | 76 return; |
| 133 } | 77 } |
| 134 g00 = MULT16_16_Q15(g0, gains[tapset0][0]); | 78 |
| 135 g01 = MULT16_16_Q15(g0, gains[tapset0][1]); | 79 g00 = MULT16_16_P15(g0, gains[tapset0][0]); |
| 136 g02 = MULT16_16_Q15(g0, gains[tapset0][2]); | 80 g01 = MULT16_16_P15(g0, gains[tapset0][1]); |
| 137 g10 = MULT16_16_Q15(g1, gains[tapset1][0]); | 81 g02 = MULT16_16_P15(g0, gains[tapset0][2]); |
| 138 g11 = MULT16_16_Q15(g1, gains[tapset1][1]); | 82 g10 = MULT16_16_P15(g1, gains[tapset1][0]); |
| 139 g12 = MULT16_16_Q15(g1, gains[tapset1][2]); | 83 g11 = MULT16_16_P15(g1, gains[tapset1][1]); |
| 84 g12 = MULT16_16_P15(g1, gains[tapset1][2]); |
| 140 x1 = x[-T1+1]; | 85 x1 = x[-T1+1]; |
| 141 x2 = x[-T1 ]; | 86 x2 = x[-T1 ]; |
| 142 x3 = x[-T1-1]; | 87 x3 = x[-T1-1]; |
| 143 x4 = x[-T1-2]; | 88 x4 = x[-T1-2]; |
| 89 /* If the filter didn't change, we don't need the overlap */ |
| 90 if (g0==g1 && T0==T1 && tapset0==tapset1) |
| 91 overlap=0; |
| 92 |
| 144 for (i=0;i<overlap;i++) | 93 for (i=0;i<overlap;i++) |
| 145 { | 94 { |
| 146 opus_val16 f; | 95 opus_val16 f; |
| 147 x0=x[i-T1+2]; | 96 opus_val32 res; |
| 148 f = MULT16_16_Q15(window[i],window[i]); | 97 f = MULT16_16_Q15(window[i],window[i]); |
| 149 y[i] = x[i] | 98 x0= x[i-T1+2]; |
| 150 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g00),x[i-T0]) | 99 |
| 151 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g01),ADD32(x[i-T0+1],x[i
-T0-1])) | 100 asm volatile("MULT $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g0
0)), "r" ((int)x[i-T0])); |
| 152 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g02),ADD32(x[i-T0+2],x[i
-T0-2])) | 101 |
| 153 + MULT16_32_Q15(MULT16_16_Q15(f,g10),x2) | 102 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g0
1)), "r" ((int)ADD32(x[i-T0-1],x[i-T0+1]))); |
| 154 + MULT16_32_Q15(MULT16_16_Q15(f,g11),ADD32(x1,x3)) | 103 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g0
2)), "r" ((int)ADD32(x[i-T0-2],x[i-T0+2]))); |
| 155 + MULT16_32_Q15(MULT16_16_Q15(f,g12),ADD32(x0,x4)); | 104 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g10)), "r"
((int)x2)); |
| 105 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g11)), "r"
((int)ADD32(x3,x1))); |
| 106 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g12)), "r"
((int)ADD32(x4,x0))); |
| 107 |
| 108 asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15)); |
| 109 |
| 110 y[i] = x[i] + res; |
| 111 |
| 156 x4=x3; | 112 x4=x3; |
| 157 x3=x2; | 113 x3=x2; |
| 158 x2=x1; | 114 x2=x1; |
| 159 x1=x0; | 115 x1=x0; |
| 116 } |
| 160 | 117 |
| 161 } | 118 x4 = x[i-T1-2]; |
| 119 x3 = x[i-T1-1]; |
| 120 x2 = x[i-T1]; |
| 121 x1 = x[i-T1+1]; |
| 122 |
| 162 if (g1==0) | 123 if (g1==0) |
| 163 { | 124 { |
| 164 /* OPT: Happens to work without the OPUS_MOVE(), but only because the curr
ent encoder already copies x to y */ | 125 /* OPT: Happens to work without the OPUS_MOVE(), but only because the curr
ent encoder already copies x to y */ |
| 165 if (x!=y) | 126 if (x!=y) |
| 166 OPUS_MOVE(y+overlap, x+overlap, N-overlap); | 127 OPUS_MOVE(y+overlap, x+overlap, N-overlap); |
| 167 return; | 128 return; |
| 168 } | 129 } |
| 169 | 130 |
| 170 /* Compute the part with the constant filter. */ | 131 for (i=overlap;i<N;i++) |
| 171 comb_filter_const(y+i, x+i, T1, N-i, g10, g11, g12); | 132 { |
| 172 } | 133 opus_val32 res; |
| 134 x0=x[i-T1+2]; |
| 173 | 135 |
| 174 const signed char tf_select_table[4][8] = { | 136 asm volatile("MULT $ac1, %0, %1" : : "r" ((int)g10), "r" ((int)x2)); |
| 175 {0, -1, 0, -1, 0,-1, 0,-1}, | |
| 176 {0, -1, 0, -2, 1, 0, 1,-1}, | |
| 177 {0, -2, 0, -3, 2, 0, 1,-1}, | |
| 178 {0, -2, 0, -3, 3, 0, 1,-1}, | |
| 179 }; | |
| 180 | 137 |
| 181 | 138 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g11), "r" ((int)ADD32(x3,x1
))); |
| 182 void init_caps(const CELTMode *m,int *cap,int LM,int C) | 139 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g12), "r" ((int)ADD32(x4,x0
))); |
| 183 { | 140 asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15)); |
| 184 int i; | 141 y[i] = x[i] + res; |
| 185 for (i=0;i<m->nbEBands;i++) | 142 x4=x3; |
| 186 { | 143 x3=x2; |
| 187 int N; | 144 x2=x1; |
| 188 N=(m->eBands[i+1]-m->eBands[i])<<LM; | 145 x1=x0; |
| 189 cap[i] = (m->cache.caps[m->nbEBands*(2*LM+C-1)+i]+64)*C*N>>2; | |
| 190 } | 146 } |
| 191 } | 147 } |
| 192 | 148 |
| 193 | 149 #endif /* __CELT_MIPSR1_H__ */ |
| 194 | |
| 195 const char *opus_strerror(int error) | |
| 196 { | |
| 197 static const char * const error_strings[8] = { | |
| 198 "success", | |
| 199 "invalid argument", | |
| 200 "buffer too small", | |
| 201 "internal error", | |
| 202 "corrupted stream", | |
| 203 "request not implemented", | |
| 204 "invalid state", | |
| 205 "memory allocation failed" | |
| 206 }; | |
| 207 if (error > 0 || error < -7) | |
| 208 return "unknown error"; | |
| 209 else | |
| 210 return error_strings[-error]; | |
| 211 } | |
| 212 | |
| 213 const char *opus_get_version_string(void) | |
| 214 { | |
| 215 return "libopus " PACKAGE_VERSION | |
| 216 #ifdef FIXED_POINT | |
| 217 "-fixed" | |
| 218 #endif | |
| 219 #ifdef FUZZING | |
| 220 "-fuzzing" | |
| 221 #endif | |
| 222 ; | |
| 223 } | |
| OLD | NEW |