1885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/***********************************************************************
2885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgCopyright (c) 2006-2011, Skype Limited. All rights reserved.
3885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgRedistribution and use in source and binary forms, with or without
4885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgmodification, are permitted provided that the following conditions
5885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgare met:
6885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org- Redistributions of source code must retain the above copyright notice,
7885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgthis list of conditions and the following disclaimer.
8885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org- Redistributions in binary form must reproduce the above copyright
9885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgnotice, this list of conditions and the following disclaimer in the
10885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgdocumentation and/or other materials provided with the distribution.
11885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org- Neither the name of Internet Society, IETF or IETF Trust, nor the
12885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgnames of specific contributors, may be used to endorse or promote
13885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgproducts derived from this software without specific prior written
14885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgpermission.
15885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgPOSSIBILITY OF SUCH DAMAGE.
26885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org***********************************************************************/
27885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
28885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#ifdef HAVE_CONFIG_H
29885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#include "config.h"
30885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#endif
31885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
32885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#include "main.h"
33885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
34885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/* Decode mid/side predictors */
35885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgvoid silk_stereo_decode_pred(
36885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    ec_dec                      *psRangeDec,                    /* I/O  Compressor data structure                   */
37885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    opus_int32                  pred_Q13[]                      /* O    Predictors                                  */
38885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org)
39885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org{
40885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    opus_int   n, ix[ 2 ][ 3 ];
41885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    opus_int32 low_Q13, step_Q13;
42885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
43885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    /* Entropy decoding */
44885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    n = ec_dec_icdf( psRangeDec, silk_stereo_pred_joint_iCDF, 8 );
45885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    ix[ 0 ][ 2 ] = silk_DIV32_16( n, 5 );
46885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    ix[ 1 ][ 2 ] = n - 5 * ix[ 0 ][ 2 ];
47885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    for( n = 0; n < 2; n++ ) {
48885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        ix[ n ][ 0 ] = ec_dec_icdf( psRangeDec, silk_uniform3_iCDF, 8 );
49885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        ix[ n ][ 1 ] = ec_dec_icdf( psRangeDec, silk_uniform5_iCDF, 8 );
50885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    }
51885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
52885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    /* Dequantize */
53885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    for( n = 0; n < 2; n++ ) {
54885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        ix[ n ][ 0 ] += 3 * ix[ n ][ 2 ];
55885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        low_Q13 = silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] ];
56885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        step_Q13 = silk_SMULWB( silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] + 1 ] - low_Q13,
57885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org            SILK_FIX_CONST( 0.5 / STEREO_QUANT_SUB_STEPS, 16 ) );
58885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org        pred_Q13[ n ] = silk_SMLABB( low_Q13, step_Q13, 2 * ix[ n ][ 1 ] + 1 );
59885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    }
60885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
61885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    /* Subtract second from first predictor (helps when actually applying these) */
62885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    pred_Q13[ 0 ] -= pred_Q13[ 1 ];
63885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org}
64885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
65885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/* Decode mid-only flag */
66885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgvoid silk_stereo_decode_mid_only(
67885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    ec_dec                      *psRangeDec,                    /* I/O  Compressor data structure                   */
68885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    opus_int                    *decode_only_mid                /* O    Flag that only mid channel has been coded   */
69885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org)
70885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org{
71885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    /* Decode flag that only mid channel is coded */
72885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org    *decode_only_mid = ec_dec_icdf( psRangeDec, silk_stereo_only_code_mid_iCDF, 8 );
73885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org}
74