1 /* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2010 Xiph.Org Foundation
3 Copyright (c) 2008 Gregory Maxwell
4 Written by Jean-Marc Valin and Gregory Maxwell */
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 - Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
13 - Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
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.
36 #include "os_support.h"
44 #include "quant_bands.h"
46 #include "stack_alloc.h"
48 #include "float_cast.h"
54 int resampling_factor(opus_int32 rate)
85 void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
86 opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
87 const opus_val16 *window, int overlap)
90 /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */
91 opus_val16 g00, g01, g02, g10, g11, g12;
92 opus_val32 x0, x1, x2, x3, x4;
93 static const opus_val16 gains[3][3] = {
94 {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)},
95 {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)},
96 {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}};
100 /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
105 g00 = MULT16_16_Q15(g0, gains[tapset0][0]);
106 g01 = MULT16_16_Q15(g0, gains[tapset0][1]);
107 g02 = MULT16_16_Q15(g0, gains[tapset0][2]);
108 g10 = MULT16_16_Q15(g1, gains[tapset1][0]);
109 g11 = MULT16_16_Q15(g1, gains[tapset1][1]);
110 g12 = MULT16_16_Q15(g1, gains[tapset1][2]);
115 for (i=0;i<overlap;i++)
119 f = MULT16_16_Q15(window[i],window[i]);
121 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g00),x[i-T0])
122 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g01),ADD32(x[i-T0+1],x[i-T0-1]))
123 + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g02),ADD32(x[i-T0+2],x[i-T0-2]))
124 + MULT16_32_Q15(MULT16_16_Q15(f,g10),x2)
125 + MULT16_32_Q15(MULT16_16_Q15(f,g11),ADD32(x1,x3))
126 + MULT16_32_Q15(MULT16_16_Q15(f,g12),ADD32(x0,x4));
135 /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
137 OPUS_MOVE(y+overlap, x+overlap, N-overlap);
140 /* OPT: For machines where the movs are costly, unroll by 5 */
145 + MULT16_32_Q15(g10,x2)
146 + MULT16_32_Q15(g11,ADD32(x1,x3))
147 + MULT16_32_Q15(g12,ADD32(x0,x4));
155 const signed char tf_select_table[4][8] = {
156 {0, -1, 0, -1, 0,-1, 0,-1},
157 {0, -1, 0, -2, 1, 0, 1,-1},
158 {0, -2, 0, -3, 2, 0, 1,-1},
159 {0, -2, 0, -3, 3, 0, 1,-1},
163 void init_caps(const CELTMode *m,int *cap,int LM,int C)
166 for (i=0;i<m->nbEBands;i++)
169 N=(m->eBands[i+1]-m->eBands[i])<<LM;
170 cap[i] = (m->cache.caps[m->nbEBands*(2*LM+C-1)+i]+64)*C*N>>2;
176 const char *opus_strerror(int error)
178 static const char * const error_strings[8] = {
184 "request not implemented",
186 "memory allocation failed"
188 if (error > 0 || error < -7)
189 return "unknown error";
191 return error_strings[-error];
194 const char *opus_get_version_string(void)
196 return "libopus " OPUS_VERSION