| 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. |
| 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the | 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the |
| 12 names of specific contributors, may be used to endorse or promote | 12 names of specific contributors, may be used to endorse or promote |
| 13 products derived from this software without specific prior written | 13 products derived from this software without specific prior written |
| 14 permission. | 14 permission. |
| 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” | 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 POSSIBILITY OF SUCH DAMAGE. | 25 POSSIBILITY OF SUCH DAMAGE. |
| 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 #include "stack_alloc.h" |
| 33 | 34 |
| 34 /*********************************************/ | 35 /*********************************************/ |
| 35 /* Encode quantization indices of excitation */ | 36 /* Encode quantization indices of excitation */ |
| 36 /*********************************************/ | 37 /*********************************************/ |
| 37 | 38 |
| 38 static inline opus_int combine_and_check( /* return ok
*/ | 39 static inline opus_int combine_and_check( /* return ok
*/ |
| 39 opus_int *pulses_comb, /* O
*/ | 40 opus_int *pulses_comb, /* O
*/ |
| 40 const opus_int *pulses_in, /* I
*/ | 41 const opus_int *pulses_in, /* I
*/ |
| 41 opus_int max_pulses, /* I max value for sum of pulses
*/ | 42 opus_int max_pulses, /* I max value for sum of pulses
*/ |
| 42 opus_int len /* I number of output values
*/ | 43 opus_int len /* I number of output values
*/ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 59 void silk_encode_pulses( | 60 void silk_encode_pulses( |
| 60 ec_enc *psRangeEnc, /* I/O compress
or data structure */ | 61 ec_enc *psRangeEnc, /* I/O compress
or data structure */ |
| 61 const opus_int signalType, /* I Signal t
ype */ | 62 const opus_int signalType, /* I Signal t
ype */ |
| 62 const opus_int quantOffsetType, /* I quantOff
setType */ | 63 const opus_int quantOffsetType, /* I quantOff
setType */ |
| 63 opus_int8 pulses[], /* I quantiza
tion indices */ | 64 opus_int8 pulses[], /* I quantiza
tion indices */ |
| 64 const opus_int frame_length /* I Frame le
ngth */ | 65 const opus_int frame_length /* I Frame le
ngth */ |
| 65 ) | 66 ) |
| 66 { | 67 { |
| 67 opus_int i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0; | 68 opus_int i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0; |
| 68 opus_int32 abs_q, minSumBits_Q5, sumBits_Q5; | 69 opus_int32 abs_q, minSumBits_Q5, sumBits_Q5; |
| 69 opus_int abs_pulses[ MAX_FRAME_LENGTH ]; | 70 VARDECL( opus_int, abs_pulses ); |
| 70 opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ]; | 71 VARDECL( opus_int, sum_pulses ); |
| 71 opus_int nRshifts[ MAX_NB_SHELL_BLOCKS ]; | 72 VARDECL( opus_int, nRshifts ); |
| 72 opus_int pulses_comb[ 8 ]; | 73 opus_int pulses_comb[ 8 ]; |
| 73 opus_int *abs_pulses_ptr; | 74 opus_int *abs_pulses_ptr; |
| 74 const opus_int8 *pulses_ptr; | 75 const opus_int8 *pulses_ptr; |
| 75 const opus_uint8 *cdf_ptr; | 76 const opus_uint8 *cdf_ptr; |
| 76 const opus_uint8 *nBits_ptr; | 77 const opus_uint8 *nBits_ptr; |
| 78 SAVE_STACK; |
| 77 | 79 |
| 78 silk_memset( pulses_comb, 0, 8 * sizeof( opus_int ) ); /* Fixing Valgrind re
ported problem*/ | 80 silk_memset( pulses_comb, 0, 8 * sizeof( opus_int ) ); /* Fixing Valgrind re
ported problem*/ |
| 79 | 81 |
| 80 /****************************/ | 82 /****************************/ |
| 81 /* Prepare for shell coding */ | 83 /* Prepare for shell coding */ |
| 82 /****************************/ | 84 /****************************/ |
| 83 /* Calculate number of shell blocks */ | 85 /* Calculate number of shell blocks */ |
| 84 silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH
); | 86 silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH
); |
| 85 iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); | 87 iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); |
| 86 if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) { | 88 if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) { |
| 87 silk_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10
ms @ 12 kHz */ | 89 silk_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10
ms @ 12 kHz */ |
| 88 iter++; | 90 iter++; |
| 89 silk_memset( &pulses[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * size
of(opus_int8)); | 91 silk_memset( &pulses[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * size
of(opus_int8)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 /* Take the absolute value of the pulses */ | 94 /* Take the absolute value of the pulses */ |
| 95 ALLOC( abs_pulses, iter * SHELL_CODEC_FRAME_LENGTH, opus_int ); |
| 96 silk_assert( !( SHELL_CODEC_FRAME_LENGTH & 3 ) ); |
| 93 for( i = 0; i < iter * SHELL_CODEC_FRAME_LENGTH; i+=4 ) { | 97 for( i = 0; i < iter * SHELL_CODEC_FRAME_LENGTH; i+=4 ) { |
| 94 abs_pulses[i+0] = ( opus_int )silk_abs( pulses[ i + 0 ] ); | 98 abs_pulses[i+0] = ( opus_int )silk_abs( pulses[ i + 0 ] ); |
| 95 abs_pulses[i+1] = ( opus_int )silk_abs( pulses[ i + 1 ] ); | 99 abs_pulses[i+1] = ( opus_int )silk_abs( pulses[ i + 1 ] ); |
| 96 abs_pulses[i+2] = ( opus_int )silk_abs( pulses[ i + 2 ] ); | 100 abs_pulses[i+2] = ( opus_int )silk_abs( pulses[ i + 2 ] ); |
| 97 abs_pulses[i+3] = ( opus_int )silk_abs( pulses[ i + 3 ] ); | 101 abs_pulses[i+3] = ( opus_int )silk_abs( pulses[ i + 3 ] ); |
| 98 } | 102 } |
| 99 | 103 |
| 100 /* Calc sum pulses per shell code frame */ | 104 /* Calc sum pulses per shell code frame */ |
| 105 ALLOC( sum_pulses, iter, opus_int ); |
| 106 ALLOC( nRshifts, iter, opus_int ); |
| 101 abs_pulses_ptr = abs_pulses; | 107 abs_pulses_ptr = abs_pulses; |
| 102 for( i = 0; i < iter; i++ ) { | 108 for( i = 0; i < iter; i++ ) { |
| 103 nRshifts[ i ] = 0; | 109 nRshifts[ i ] = 0; |
| 104 | 110 |
| 105 while( 1 ) { | 111 while( 1 ) { |
| 106 /* 1+1 -> 2 */ | 112 /* 1+1 -> 2 */ |
| 107 scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, silk_ma
x_pulses_table[ 0 ], 8 ); | 113 scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, silk_ma
x_pulses_table[ 0 ], 8 ); |
| 108 /* 2+2 -> 4 */ | 114 /* 2+2 -> 4 */ |
| 109 scale_down += combine_and_check( pulses_comb, pulses_comb, silk_max_
pulses_table[ 1 ], 4 ); | 115 scale_down += combine_and_check( pulses_comb, pulses_comb, silk_max_
pulses_table[ 1 ], 4 ); |
| 110 /* 4+4 -> 8 */ | 116 /* 4+4 -> 8 */ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 bit = abs_q & 1; | 195 bit = abs_q & 1; |
| 190 ec_enc_icdf( psRangeEnc, bit, silk_lsb_iCDF, 8 ); | 196 ec_enc_icdf( psRangeEnc, bit, silk_lsb_iCDF, 8 ); |
| 191 } | 197 } |
| 192 } | 198 } |
| 193 } | 199 } |
| 194 | 200 |
| 195 /****************/ | 201 /****************/ |
| 196 /* Encode signs */ | 202 /* Encode signs */ |
| 197 /****************/ | 203 /****************/ |
| 198 silk_encode_signs( psRangeEnc, pulses, frame_length, signalType, quantOffset
Type, sum_pulses ); | 204 silk_encode_signs( psRangeEnc, pulses, frame_length, signalType, quantOffset
Type, sum_pulses ); |
| 205 RESTORE_STACK; |
| 199 } | 206 } |
| OLD | NEW |