
commit 5b64cf7c4d67af9050bc959996ef976ce6326888 Author: Jean-Marc Valin <jean-marc.valin@octasic.com> Date: Thu May 19 16:40:35 2011 -0400 Fixes a few bugs introduced in the latest update commit b91eb86025d2de3c4cf04f4fb1aa48a28ad676a3 Author: Timothy B. Terriberry <tterribe@xiph.org> Date: Thu May 19 16:12:02 2011 -0400 build_draft.sh fixes commit 0b10c30db7ad60ff7d4bfc1139bdb86e0543c035 Author: Jean-Marc Valin <jean-marc.valin@octasic.com> Date: Thu May 19 15:30:21 2011 -0400 Fixes the draft build commit 164424cded5978e657105104e171ac202dde5e5b Author: Jean-Marc Valin <jean-marc.valin@octasic.com> Date: Thu May 19 15:00:23 2011 -0400 Updated build system commit 188d9fcba8c3a1b1ad67c67c430e1b37e3658a40 Author: Koen Vos <koen.vos@skype.net> Date: Thu May 19 17:14:57 2011 -0400 SILK/Opus update
107 lines
5.6 KiB
C
107 lines
5.6 KiB
C
/***********************************************************************
|
|
Copyright (c) 2006-2011, Skype Limited. All rights reserved.
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, (subject to the limitations in the disclaimer below)
|
|
are permitted provided that the following conditions are met:
|
|
- Redistributions of source code must retain the above copyright notice,
|
|
this list of conditions and the following disclaimer.
|
|
- Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
- Neither the name of Skype Limited, nor the names of specific
|
|
contributors, may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
|
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
|
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
***********************************************************************/
|
|
|
|
#include "silk_main.h"
|
|
|
|
/* Entropy constrained matrix-weighted VQ, hard-coded to 5-element vectors, for a single input data vector */
|
|
void silk_VQ_WMat_EC(
|
|
SKP_int8 *ind, /* O index of best codebook vector */
|
|
SKP_int32 *rate_dist_Q14, /* O best weighted quantization error + mu * rate*/
|
|
const SKP_int16 *in_Q14, /* I input vector to be quantized */
|
|
const SKP_int32 *W_Q18, /* I weighting matrix */
|
|
const SKP_int8 *cb_Q7, /* I codebook */
|
|
const SKP_uint8 *cl_Q5, /* I code length for each codebook vector */
|
|
const SKP_int mu_Q9, /* I tradeoff between weighted error and rate */
|
|
SKP_int L /* I number of vectors in codebook */
|
|
)
|
|
{
|
|
SKP_int k;
|
|
const SKP_int8 *cb_row_Q7;
|
|
SKP_int16 diff_Q14[ 5 ];
|
|
SKP_int32 sum1_Q14, sum2_Q16;
|
|
|
|
/* Loop over codebook */
|
|
*rate_dist_Q14 = SKP_int32_MAX;
|
|
cb_row_Q7 = cb_Q7;
|
|
for( k = 0; k < L; k++ ) {
|
|
diff_Q14[ 0 ] = in_Q14[ 0 ] - SKP_LSHIFT( cb_row_Q7[ 0 ], 7 );
|
|
diff_Q14[ 1 ] = in_Q14[ 1 ] - SKP_LSHIFT( cb_row_Q7[ 1 ], 7 );
|
|
diff_Q14[ 2 ] = in_Q14[ 2 ] - SKP_LSHIFT( cb_row_Q7[ 2 ], 7 );
|
|
diff_Q14[ 3 ] = in_Q14[ 3 ] - SKP_LSHIFT( cb_row_Q7[ 3 ], 7 );
|
|
diff_Q14[ 4 ] = in_Q14[ 4 ] - SKP_LSHIFT( cb_row_Q7[ 4 ], 7 );
|
|
|
|
/* Weighted rate */
|
|
sum1_Q14 = SKP_SMULBB( mu_Q9, cl_Q5[ k ] );
|
|
|
|
SKP_assert( sum1_Q14 >= 0 );
|
|
|
|
/* first row of W_Q18 */
|
|
sum2_Q16 = SKP_SMULWB( W_Q18[ 1 ], diff_Q14[ 1 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14[ 2 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 3 ], diff_Q14[ 3 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14[ 4 ] );
|
|
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14[ 0 ] );
|
|
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 0 ] );
|
|
|
|
/* second row of W_Q18 */
|
|
sum2_Q16 = SKP_SMULWB( W_Q18[ 7 ], diff_Q14[ 2 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 8 ], diff_Q14[ 3 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14[ 4 ] );
|
|
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 6 ], diff_Q14[ 1 ] );
|
|
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 1 ] );
|
|
|
|
/* third row of W_Q18 */
|
|
sum2_Q16 = SKP_SMULWB( W_Q18[ 13 ], diff_Q14[ 3 ] );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] );
|
|
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] );
|
|
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 2 ] );
|
|
|
|
/* fourth row of W_Q18 */
|
|
sum2_Q16 = SKP_SMULWB( W_Q18[ 19 ], diff_Q14[ 4 ] );
|
|
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
|
|
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] );
|
|
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 3 ] );
|
|
|
|
/* last row of W_Q18 */
|
|
sum2_Q16 = SKP_SMULWB( W_Q18[ 24 ], diff_Q14[ 4 ] );
|
|
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 4 ] );
|
|
|
|
SKP_assert( sum1_Q14 >= 0 );
|
|
|
|
/* find best */
|
|
if( sum1_Q14 < *rate_dist_Q14 ) {
|
|
*rate_dist_Q14 = sum1_Q14;
|
|
*ind = (SKP_int8)k;
|
|
}
|
|
|
|
/* Go to next cbk vector */
|
|
cb_row_Q7 += LTP_ORDER;
|
|
}
|
|
}
|