/src/opus/silk/decode_pulses.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*********************************************************************** |
2 | | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 | | Redistribution and use in source and binary forms, with or without |
4 | | modification, are permitted provided that the following conditions |
5 | | are met: |
6 | | - Redistributions of source code must retain the above copyright notice, |
7 | | this list of conditions and the following disclaimer. |
8 | | - Redistributions in binary form must reproduce the above copyright |
9 | | notice, this list of conditions and the following disclaimer in the |
10 | | documentation and/or other materials provided with the distribution. |
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 |
13 | | products derived from this software without specific prior written |
14 | | permission. |
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 |
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
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 |
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 |
25 | | POSSIBILITY OF SUCH DAMAGE. |
26 | | ***********************************************************************/ |
27 | | |
28 | | #ifdef HAVE_CONFIG_H |
29 | | #include "config.h" |
30 | | #endif |
31 | | |
32 | | #include "main.h" |
33 | | |
34 | | /*********************************************/ |
35 | | /* Decode quantization indices of excitation */ |
36 | | /*********************************************/ |
37 | | void silk_decode_pulses( |
38 | | ec_dec *psRangeDec, /* I/O Compressor data structure */ |
39 | | opus_int16 pulses[], /* O Excitation signal */ |
40 | | const opus_int signalType, /* I Sigtype */ |
41 | | const opus_int quantOffsetType, /* I quantOffsetType */ |
42 | | const opus_int frame_length /* I Frame length */ |
43 | | ) |
44 | 0 | { |
45 | 0 | opus_int i, j, k, iter, abs_q, nLS, RateLevelIndex; |
46 | 0 | opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ]; |
47 | 0 | opus_int16 *pulses_ptr; |
48 | 0 | const opus_uint8 *cdf_ptr; |
49 | | |
50 | | /*********************/ |
51 | | /* Decode rate level */ |
52 | | /*********************/ |
53 | 0 | RateLevelIndex = ec_dec_icdf( psRangeDec, silk_rate_levels_iCDF[ signalType >> 1 ], 8 ); |
54 | | |
55 | | /* Calculate number of shell blocks */ |
56 | 0 | silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); |
57 | 0 | iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); |
58 | 0 | if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) { |
59 | 0 | celt_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */ |
60 | 0 | iter++; |
61 | 0 | } |
62 | | |
63 | | /***************************************************/ |
64 | | /* Sum-Weighted-Pulses Decoding */ |
65 | | /***************************************************/ |
66 | 0 | cdf_ptr = silk_pulses_per_block_iCDF[ RateLevelIndex ]; |
67 | 0 | for( i = 0; i < iter; i++ ) { |
68 | 0 | nLshifts[ i ] = 0; |
69 | 0 | sum_pulses[ i ] = ec_dec_icdf( psRangeDec, cdf_ptr, 8 ); |
70 | | |
71 | | /* LSB indication */ |
72 | 0 | while( sum_pulses[ i ] == SILK_MAX_PULSES + 1 ) { |
73 | 0 | nLshifts[ i ]++; |
74 | | /* When we've already got 10 LSBs, we shift the table to not allow (SILK_MAX_PULSES + 1) */ |
75 | 0 | sum_pulses[ i ] = ec_dec_icdf( psRangeDec, |
76 | 0 | silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1] + ( nLshifts[ i ] == 10 ), 8 ); |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | /***************************************************/ |
81 | | /* Shell decoding */ |
82 | | /***************************************************/ |
83 | 0 | for( i = 0; i < iter; i++ ) { |
84 | 0 | if( sum_pulses[ i ] > 0 ) { |
85 | 0 | silk_shell_decoder( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] ); |
86 | 0 | } else { |
87 | 0 | silk_memset( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( pulses[0] ) ); |
88 | 0 | } |
89 | 0 | } |
90 | | |
91 | | /***************************************************/ |
92 | | /* LSB Decoding */ |
93 | | /***************************************************/ |
94 | 0 | for( i = 0; i < iter; i++ ) { |
95 | 0 | if( nLshifts[ i ] > 0 ) { |
96 | 0 | nLS = nLshifts[ i ]; |
97 | 0 | pulses_ptr = &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ]; |
98 | 0 | for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { |
99 | 0 | abs_q = pulses_ptr[ k ]; |
100 | 0 | for( j = 0; j < nLS; j++ ) { |
101 | 0 | abs_q = silk_LSHIFT( abs_q, 1 ); |
102 | 0 | abs_q += ec_dec_icdf( psRangeDec, silk_lsb_iCDF, 8 ); |
103 | 0 | } |
104 | 0 | pulses_ptr[ k ] = abs_q; |
105 | 0 | } |
106 | | /* Mark the number of pulses non-zero for sign decoding. */ |
107 | 0 | sum_pulses[ i ] |= nLS << 5; |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | | /****************************************/ |
112 | | /* Decode and add signs to pulse signal */ |
113 | | /****************************************/ |
114 | 0 | silk_decode_signs( psRangeDec, pulses, frame_length, signalType, quantOffsetType, sum_pulses ); |
115 | 0 | } |