OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. | 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 Redistribution and use in source and binary forms, with or without | 3 Redistribution and use in source and binary forms, with or without |
4 modification, are permitted provided that the following conditions | 4 modification, are permitted provided that the following conditions |
5 are met: | 5 are met: |
6 - Redistributions of source code must retain the above copyright notice, | 6 - Redistributions of source code must retain the above copyright notice, |
7 this list of conditions and the following disclaimer. | 7 this list of conditions and the following disclaimer. |
8 - Redistributions in binary form must reproduce the above copyright | 8 - Redistributions in binary form must reproduce the above copyright |
9 notice, this list of conditions and the following disclaimer in the | 9 notice, this list of conditions and the following disclaimer in the |
10 documentation and/or other materials provided with the distribution. | 10 documentation and/or other materials provided with the distribution. |
(...skipping 15 matching lines...) Expand all Loading... |
26 ***********************************************************************/ | 26 ***********************************************************************/ |
27 | 27 |
28 #ifdef HAVE_CONFIG_H | 28 #ifdef HAVE_CONFIG_H |
29 #include "config.h" | 29 #include "config.h" |
30 #endif | 30 #endif |
31 | 31 |
32 #include "main.h" | 32 #include "main.h" |
33 | 33 |
34 /* Compute quantization errors for an LPC_order element input vector for a VQ co
debook */ | 34 /* Compute quantization errors for an LPC_order element input vector for a VQ co
debook */ |
35 void silk_NLSF_VQ( | 35 void silk_NLSF_VQ( |
36 opus_int32 err_Q26[], /* O Quantiza
tion errors [K] */ | 36 opus_int32 err_Q24[], /* O Quantiza
tion errors [K] */ |
37 const opus_int16 in_Q15[], /* I Input ve
ctors to be quantized [LPC_order] */ | 37 const opus_int16 in_Q15[], /* I Input ve
ctors to be quantized [LPC_order] */ |
38 const opus_uint8 pCB_Q8[], /* I Codebook
vectors [K*LPC_order] */ | 38 const opus_uint8 pCB_Q8[], /* I Codebook
vectors [K*LPC_order] */ |
| 39 const opus_int16 pWght_Q9[], /* I Codebook
weights [K*LPC_order] */ |
39 const opus_int K, /* I Number o
f codebook vectors */ | 40 const opus_int K, /* I Number o
f codebook vectors */ |
40 const opus_int LPC_order /* I Number o
f LPCs */ | 41 const opus_int LPC_order /* I Number o
f LPCs */ |
41 ) | 42 ) |
42 { | 43 { |
43 opus_int i, m; | 44 opus_int i, m; |
44 opus_int32 diff_Q15, sum_error_Q30, sum_error_Q26; | 45 opus_int32 diff_Q15, diffw_Q24, sum_error_Q24, pred_Q24; |
| 46 const opus_int16 *w_Q9_ptr; |
| 47 const opus_uint8 *cb_Q8_ptr; |
45 | 48 |
46 silk_assert( LPC_order <= 16 ); | |
47 silk_assert( ( LPC_order & 1 ) == 0 ); | 49 silk_assert( ( LPC_order & 1 ) == 0 ); |
48 | 50 |
49 /* Loop over codebook */ | 51 /* Loop over codebook */ |
| 52 cb_Q8_ptr = pCB_Q8; |
| 53 w_Q9_ptr = pWght_Q9; |
50 for( i = 0; i < K; i++ ) { | 54 for( i = 0; i < K; i++ ) { |
51 sum_error_Q26 = 0; | 55 sum_error_Q24 = 0; |
52 for( m = 0; m < LPC_order; m += 2 ) { | 56 pred_Q24 = 0; |
53 /* Compute weighted squared quantization error for index m */ | 57 for( m = LPC_order-2; m >= 0; m -= 2 ) { |
54 diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m ], (opus_int32)*pCB_Q8++, 7
); /* range: [ -32767 : 32767 ]*/ | 58 /* Compute weighted absolute predictive quantization error for index
m + 1 */ |
55 sum_error_Q30 = silk_SMULBB( diff_Q15, diff_Q15 ); | 59 diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m + 1 ], (opus_int32)cb_Q8_ptr
[ m + 1 ], 7 ); /* range: [ -32767 : 32767 ]*/ |
| 60 diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m + 1 ] ); |
| 61 sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT
32( diffw_Q24, pred_Q24, 1 ) ) ); |
| 62 pred_Q24 = diffw_Q24; |
56 | 63 |
57 /* Compute weighted squared quantization error for index m + 1 */ | 64 /* Compute weighted absolute predictive quantization error for index
m */ |
58 diff_Q15 = silk_SUB_LSHIFT32( in_Q15[m + 1], (opus_int32)*pCB_Q8++,
7 ); /* range: [ -32767 : 32767 ]*/ | 65 diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m ], (opus_int32)cb_Q8_ptr[ m
], 7 ); /* range: [ -32767 : 32767 ]*/ |
59 sum_error_Q30 = silk_SMLABB( sum_error_Q30, diff_Q15, diff_Q15 ); | 66 diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m ] ); |
| 67 sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT
32( diffw_Q24, pred_Q24, 1 ) ) ); |
| 68 pred_Q24 = diffw_Q24; |
60 | 69 |
61 sum_error_Q26 = silk_ADD_RSHIFT32( sum_error_Q26, sum_error_Q30, 4 )
; | 70 silk_assert( sum_error_Q24 >= 0 ); |
62 | |
63 silk_assert( sum_error_Q26 >= 0 ); | |
64 silk_assert( sum_error_Q30 >= 0 ); | |
65 } | 71 } |
66 err_Q26[ i ] = sum_error_Q26; | 72 err_Q24[ i ] = sum_error_Q24; |
| 73 cb_Q8_ptr += LPC_order; |
| 74 w_Q9_ptr += LPC_order; |
67 } | 75 } |
68 } | 76 } |
OLD | NEW |