xref: /aosp_15_r20/external/libopus/silk/NSQ.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1*a58d3d2aSXin Li /***********************************************************************
2*a58d3d2aSXin Li Copyright (c) 2014 Vidyo.
3*a58d3d2aSXin Li Copyright (c) 2006-2011, Skype Limited. All rights reserved.
4*a58d3d2aSXin Li Redistribution and use in source and binary forms, with or without
5*a58d3d2aSXin Li modification, are permitted provided that the following conditions
6*a58d3d2aSXin Li are met:
7*a58d3d2aSXin Li - Redistributions of source code must retain the above copyright notice,
8*a58d3d2aSXin Li this list of conditions and the following disclaimer.
9*a58d3d2aSXin Li - Redistributions in binary form must reproduce the above copyright
10*a58d3d2aSXin Li notice, this list of conditions and the following disclaimer in the
11*a58d3d2aSXin Li documentation and/or other materials provided with the distribution.
12*a58d3d2aSXin Li - Neither the name of Internet Society, IETF or IETF Trust, nor the
13*a58d3d2aSXin Li names of specific contributors, may be used to endorse or promote
14*a58d3d2aSXin Li products derived from this software without specific prior written
15*a58d3d2aSXin Li permission.
16*a58d3d2aSXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*a58d3d2aSXin Li AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*a58d3d2aSXin Li IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*a58d3d2aSXin Li ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20*a58d3d2aSXin Li LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*a58d3d2aSXin Li CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*a58d3d2aSXin Li SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*a58d3d2aSXin Li INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*a58d3d2aSXin Li CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*a58d3d2aSXin Li ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*a58d3d2aSXin Li POSSIBILITY OF SUCH DAMAGE.
27*a58d3d2aSXin Li ***********************************************************************/
28*a58d3d2aSXin Li #ifndef SILK_NSQ_H
29*a58d3d2aSXin Li #define SILK_NSQ_H
30*a58d3d2aSXin Li 
31*a58d3d2aSXin Li #include "SigProc_FIX.h"
32*a58d3d2aSXin Li 
33*a58d3d2aSXin Li #undef silk_short_prediction_create_arch_coef
34*a58d3d2aSXin Li 
silk_noise_shape_quantizer_short_prediction_c(const opus_int32 * buf32,const opus_int16 * coef16,opus_int order)35*a58d3d2aSXin Li static OPUS_INLINE opus_int32 silk_noise_shape_quantizer_short_prediction_c(const opus_int32 *buf32, const opus_int16 *coef16, opus_int order)
36*a58d3d2aSXin Li {
37*a58d3d2aSXin Li     opus_int32 out;
38*a58d3d2aSXin Li     silk_assert( order == 10 || order == 16 );
39*a58d3d2aSXin Li 
40*a58d3d2aSXin Li     /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
41*a58d3d2aSXin Li     out = silk_RSHIFT( order, 1 );
42*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[  0 ], coef16[ 0 ] );
43*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -1 ], coef16[ 1 ] );
44*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -2 ], coef16[ 2 ] );
45*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -3 ], coef16[ 3 ] );
46*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -4 ], coef16[ 4 ] );
47*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -5 ], coef16[ 5 ] );
48*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -6 ], coef16[ 6 ] );
49*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -7 ], coef16[ 7 ] );
50*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -8 ], coef16[ 8 ] );
51*a58d3d2aSXin Li     out = silk_SMLAWB( out, buf32[ -9 ], coef16[ 9 ] );
52*a58d3d2aSXin Li 
53*a58d3d2aSXin Li     if( order == 16 )
54*a58d3d2aSXin Li     {
55*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -10 ], coef16[ 10 ] );
56*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -11 ], coef16[ 11 ] );
57*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -12 ], coef16[ 12 ] );
58*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -13 ], coef16[ 13 ] );
59*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -14 ], coef16[ 14 ] );
60*a58d3d2aSXin Li         out = silk_SMLAWB( out, buf32[ -15 ], coef16[ 15 ] );
61*a58d3d2aSXin Li     }
62*a58d3d2aSXin Li     return out;
63*a58d3d2aSXin Li }
64*a58d3d2aSXin Li 
65*a58d3d2aSXin Li #define silk_noise_shape_quantizer_short_prediction(in, coef, coefRev, order, arch)  ((void)arch,silk_noise_shape_quantizer_short_prediction_c(in, coef, order))
66*a58d3d2aSXin Li 
silk_NSQ_noise_shape_feedback_loop_c(const opus_int32 * data0,opus_int32 * data1,const opus_int16 * coef,opus_int order)67*a58d3d2aSXin Li static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_c(const opus_int32 *data0, opus_int32 *data1, const opus_int16 *coef, opus_int order)
68*a58d3d2aSXin Li {
69*a58d3d2aSXin Li     opus_int32 out;
70*a58d3d2aSXin Li     opus_int32 tmp1, tmp2;
71*a58d3d2aSXin Li     opus_int j;
72*a58d3d2aSXin Li 
73*a58d3d2aSXin Li     tmp2 = data0[0];
74*a58d3d2aSXin Li     tmp1 = data1[0];
75*a58d3d2aSXin Li     data1[0] = tmp2;
76*a58d3d2aSXin Li 
77*a58d3d2aSXin Li     out = silk_RSHIFT(order, 1);
78*a58d3d2aSXin Li     out = silk_SMLAWB(out, tmp2, coef[0]);
79*a58d3d2aSXin Li 
80*a58d3d2aSXin Li     for (j = 2; j < order; j += 2) {
81*a58d3d2aSXin Li         tmp2 = data1[j - 1];
82*a58d3d2aSXin Li         data1[j - 1] = tmp1;
83*a58d3d2aSXin Li         out = silk_SMLAWB(out, tmp1, coef[j - 1]);
84*a58d3d2aSXin Li         tmp1 = data1[j + 0];
85*a58d3d2aSXin Li         data1[j + 0] = tmp2;
86*a58d3d2aSXin Li         out = silk_SMLAWB(out, tmp2, coef[j]);
87*a58d3d2aSXin Li     }
88*a58d3d2aSXin Li     data1[order - 1] = tmp1;
89*a58d3d2aSXin Li     out = silk_SMLAWB(out, tmp1, coef[order - 1]);
90*a58d3d2aSXin Li     /* Q11 -> Q12 */
91*a58d3d2aSXin Li     out = silk_LSHIFT32( out, 1 );
92*a58d3d2aSXin Li     return out;
93*a58d3d2aSXin Li }
94*a58d3d2aSXin Li 
95*a58d3d2aSXin Li #define silk_NSQ_noise_shape_feedback_loop(data0, data1, coef, order, arch)  ((void)arch,silk_NSQ_noise_shape_feedback_loop_c(data0, data1, coef, order))
96*a58d3d2aSXin Li 
97*a58d3d2aSXin Li #if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
98*a58d3d2aSXin Li #include "arm/NSQ_neon.h"
99*a58d3d2aSXin Li #endif
100*a58d3d2aSXin Li 
101*a58d3d2aSXin Li #endif /* SILK_NSQ_H */
102