Debian Codegraph @

external/opusfile/opus/silk/gain_quant.c

raw symbols SCIP
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 "opus__config.h"cxx . . $ `<file>/external/opusfile/opus/opus__config.h`/
30 //#endif
31
32 #include "main.h"cxx . . $ `<file>/external/opusfile/opus/silk/main.h`/
33
34 #define OFFSETcxx . . $ `external/opusfile/opus/silk/gain_quant.c:34:9`! ( ( MIN_QGAIN_DBcxx . . $ `external/opusfile/opus/silk/define.h:119:9`! * 128 ) / 6 + 16 * 128 )
35 #define SCALE_Q16cxx . . $ `external/opusfile/opus/silk/gain_quant.c:35:9`! ( ( 65536 * ( N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 ) ) / ( ( ( MAX_QGAIN_DBcxx . . $ `external/opusfile/opus/silk/define.h:121:9`! - MIN_QGAIN_DBcxx . . $ `external/opusfile/opus/silk/define.h:119:9`! ) * 128 ) / 6 ) )
36 #define INV_SCALE_Q16cxx . . $ `external/opusfile/opus/silk/gain_quant.c:36:9`! ( ( 65536 * ( ( ( MAX_QGAIN_DBcxx . . $ `external/opusfile/opus/silk/define.h:121:9`! - MIN_QGAIN_DBcxx . . $ `external/opusfile/opus/silk/define.h:119:9`! ) * 128 ) / 6 ) ) / ( N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 ) )
37
38 /* Gain scalar quantization with hysteresis, uniform on log scale */
39 void silk_gains_quantcxx . . $ silk_gains_quant(fe48b9a386c4132d).(
40 opus_int8cxx . . $ opus_int8# ind[ MAX_NB_SUBFRcxx . . $ `external/opusfile/opus/silk/define.h:90:9`! ], /* O gain indices */
41 opus_int32cxx . . $ opus_int32# gain_Q16[ MAX_NB_SUBFRcxx . . $ `external/opusfile/opus/silk/define.h:90:9`! ], /* I/O gains (quantized out) */
42 opus_int8cxx . . $ opus_int8# *prev_ind, /* I/O last index in previous frame */
43 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! conditional, /* I first gain is delta coded if 1 */
44 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! nb_subfr /* I number of subframes */
45 )
46 {
47 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! k, double_step_size_threshold;
48
49 for( k = 0; k < nb_subfr; k++ ) {
50 /* Convert to log scale, scale, floor() */
51 ind[ k ] = silk_SMULWBcxx . . $ `external/opusfile/opus/silk/macros.h:43:9`!( SCALE_Q16cxx . . $ `external/opusfile/opus/silk/gain_quant.c:35:9`!, silk_lin2log( gain_Q16[ k ] ) - OFFSETcxx . . $ `external/opusfile/opus/silk/gain_quant.c:34:9`! );
52
53 /* Round towards previous quantized gain (hysteresis) */
54 if( ind[ k ] < *prev_ind ) {
55 ind[ k ]++;
56 }
57 ind[ k ] = silk_LIMIT_intcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:584:9`!( ind[ k ], 0, N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 );
58
59 /* Compute delta indices and limit */
60 if( k == 0 && conditional == 0 ) {
61 /* Full index */
62 ind[ k ] = silk_LIMIT_intcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:584:9`!( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:127:9`!, N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 );
63 *prev_ind = ind[ k ];
64 } else {
65 /* Delta index */
66 ind[ k ] = ind[ k ] - *prev_ind;
67
68 /* Double the quantization step size for large gain increases, so that the max gain level can be reached */
69 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:125:9`! - N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! + *prev_ind;
70 if( ind[ k ] > double_step_size_threshold ) {
71 ind[ k ] = double_step_size_threshold + silk_RSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:511:9`!( ind[ k ] - double_step_size_threshold + 1, 1 );
72 }
73
74 ind[ k ] = silk_LIMIT_intcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:584:9`!( ind[ k ], MIN_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:127:9`!, MAX_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:125:9`! );
75
76 /* Accumulate deltas */
77 if( ind[ k ] > double_step_size_threshold ) {
78 *prev_ind += silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( ind[ k ], 1 ) - double_step_size_threshold;
79 *prev_ind = silk_min_intcxx . . $ silk_min_int(9b79fb6aee4c0440).( *prev_ind, N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 );
80 } else {
81 *prev_ind += ind[ k ];
82 }
83
84 /* Shift to make non-negative */
85 ind[ k ] -= MIN_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:127:9`!;
86 }
87
88 /* Scale and convert to linear scale */
89 gain_Q16[ k ] = silk_log2lincxx . . $ silk_log2lin(7864480464b09eea).( silk_min_32cxx . . $ silk_min_32(9b79fb6aee4c0440).( silk_SMULWBcxx . . $ `external/opusfile/opus/silk/macros.h:43:9`!( INV_SCALE_Q16cxx . . $ `external/opusfile/opus/silk/gain_quant.c:36:9`!, *prev_ind ) + OFFSETcxx . . $ `external/opusfile/opus/silk/gain_quant.c:34:9`!, 3967 ) ); /* 3967 = 31 in Q7 */
90 }
91 }
92
93 /* Gains scalar dequantization, uniform on log scale */
94 void silk_gains_dequantcxx . . $ silk_gains_dequant(e7a7ed9bd36c8e0d).(
95 opus_int32cxx . . $ opus_int32# gain_Q16[ MAX_NB_SUBFRcxx . . $ `external/opusfile/opus/silk/define.h:90:9`! ], /* O quantized gains */
96 const opus_int8cxx . . $ opus_int8# ind[ MAX_NB_SUBFRcxx . . $ `external/opusfile/opus/silk/define.h:90:9`! ], /* I gain indices */
97 opus_int8cxx . . $ opus_int8# *prev_ind, /* I/O last index in previous frame */
98 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! conditional, /* I first gain is delta coded if 1 */
99 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! nb_subfr /* I number of subframes */
100 )
101 {
102 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! k, ind_tmp, double_step_size_threshold;
103
104 for( k = 0; k < nb_subfr; k++ ) {
105 if( k == 0 && conditional == 0 ) {
106 /* Gain index is not allowed to go down more than 16 steps (~21.8 dB) */
107 *prev_ind = silk_max_intcxx . . $ silk_max_int(9b79fb6aee4c0440).( ind[ k ], *prev_ind - 16 );
108 } else {
109 /* Delta index */
110 ind_tmp = ind[ k ] + MIN_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:127:9`!;
111
112 /* Accumulate deltas */
113 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANTcxx . . $ `external/opusfile/opus/silk/define.h:125:9`! - N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! + *prev_ind;
114 if( ind_tmp > double_step_size_threshold ) {
115 *prev_ind += silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( ind_tmp, 1 ) - double_step_size_threshold;
116 } else {
117 *prev_ind += ind_tmp;
118 }
119 }
120 *prev_ind = silk_LIMIT_intcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:584:9`!( *prev_ind, 0, N_LEVELS_QGAINcxx . . $ `external/opusfile/opus/silk/define.h:123:9`! - 1 );
121
122 /* Scale and convert to linear scale */
123 gain_Q16[ k ] = silk_log2lincxx . . $ silk_log2lin(7864480464b09eea).( silk_min_32cxx . . $ silk_min_32(9b79fb6aee4c0440).( silk_SMULWBcxx . . $ `external/opusfile/opus/silk/macros.h:43:9`!( INV_SCALE_Q16cxx . . $ `external/opusfile/opus/silk/gain_quant.c:36:9`!, *prev_ind ) + OFFSETcxx . . $ `external/opusfile/opus/silk/gain_quant.c:34:9`!, 3967 ) ); /* 3967 = 31 in Q7 */
124 }
125 }
126
127 /* Compute unique identifier of gain indices vector */
128 opus_int32cxx . . $ opus_int32# silk_gains_IDcxx . . $ silk_gains_ID(1380bfeceff4370d).( /* O returns unique identifier of gains */
129 const opus_int8cxx . . $ opus_int8# ind[ MAX_NB_SUBFRcxx . . $ `external/opusfile/opus/silk/define.h:90:9`! ], /* I gain indices */
130 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! nb_subfr /* I number of subframes */
131 )
132 {
133 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! k;
134 opus_int32cxx . . $ opus_int32# gainsID;
135
136 gainsID = 0;
137 for( k = 0; k < nb_subfr; k++ ) {
138 gainsID = silk_ADD_LSHIFT32cxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:522:9`!( ind[ k ], gainsID, 8 );
139 }
140
141 return gainsID;
142 }