Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: opus/silk/gain_quant.c

Issue 11196031: Add copy of opus library in deps/third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « opus/silk/float/wrappers_FLP.c ('k') | opus/silk/init_decoder.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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 #define OFFSET ( ( MIN_QGAIN_DB * 128 ) / 6 + 16 * 128 )
35 #define SCALE_Q16 ( ( 65536 * ( N_LEVELS_QGAIN - 1 ) ) / ( ( ( MAX _QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) )
36 #define INV_SCALE_Q16 ( ( 65536 * ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) ) / ( N_LEVELS_QGAIN - 1 ) )
37
38 /* Gain scalar quantization with hysteresis, uniform on log scale */
39 void silk_gains_quant(
40 opus_int8 ind[ MAX_NB_SUBFR ], /* O gain ind ices */
41 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (q uantized out) */
42 opus_int8 *prev_ind, /* I/O last ind ex in previous frame */
43 const opus_int conditional, /* I first ga in is delta coded if 1 */
44 const opus_int nb_subfr /* I number o f subframes */
45 )
46 {
47 opus_int 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_SMULWB( SCALE_Q16, silk_lin2log( gain_Q16[ k ] ) - OFFSE T );
52
53 /* Round towards previous quantized gain (hysteresis) */
54 if( ind[ k ] < *prev_ind ) {
55 ind[ k ]++;
56 }
57 ind[ k ] = silk_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 );
58
59 /* Compute delta indices and limit */
60 if( k == 0 && conditional == 0 ) {
61 /* Full index */
62 ind[ k ] = silk_LIMIT_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUAN T, N_LEVELS_QGAIN - 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 th at the max gain level can be reached */
69 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGA IN + *prev_ind;
70 if( ind[ k ] > double_step_size_threshold ) {
71 ind[ k ] = double_step_size_threshold + silk_RSHIFT( ind[ k ] - double_step_size_threshold + 1, 1 );
72 }
73
74 ind[ k ] = silk_LIMIT_int( ind[ k ], MIN_DELTA_GAIN_QUANT, MAX_DELTA _GAIN_QUANT );
75
76 /* Accumulate deltas */
77 if( ind[ k ] > double_step_size_threshold ) {
78 *prev_ind += silk_LSHIFT( ind[ k ], 1 ) - double_step_size_thres hold;
79 } else {
80 *prev_ind += ind[ k ];
81 }
82
83 /* Shift to make non-negative */
84 ind[ k ] -= MIN_DELTA_GAIN_QUANT;
85 }
86
87 /* Scale and convert to linear scale */
88 gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, * prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
89 }
90 }
91
92 /* Gains scalar dequantization, uniform on log scale */
93 void silk_gains_dequant(
94 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantize d gains */
95 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain ind ices */
96 opus_int8 *prev_ind, /* I/O last ind ex in previous frame */
97 const opus_int conditional, /* I first ga in is delta coded if 1 */
98 const opus_int nb_subfr /* I number o f subframes */
99 )
100 {
101 opus_int k, ind_tmp, double_step_size_threshold;
102
103 for( k = 0; k < nb_subfr; k++ ) {
104 if( k == 0 && conditional == 0 ) {
105 /* Gain index is not allowed to go down more than 16 steps (~21.8 dB ) */
106 *prev_ind = silk_max_int( ind[ k ], *prev_ind - 16 );
107 } else {
108 /* Delta index */
109 ind_tmp = ind[ k ] + MIN_DELTA_GAIN_QUANT;
110
111 /* Accumulate deltas */
112 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGA IN + *prev_ind;
113 if( ind_tmp > double_step_size_threshold ) {
114 *prev_ind += silk_LSHIFT( ind_tmp, 1 ) - double_step_size_thresh old;
115 } else {
116 *prev_ind += ind_tmp;
117 }
118 }
119 *prev_ind = silk_LIMIT_int( *prev_ind, 0, N_LEVELS_QGAIN - 1 );
120
121 /* Scale and convert to linear scale */
122 gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, * prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
123 }
124 }
125
126 /* Compute unique identifier of gain indices vector */
127 opus_int32 silk_gains_ID( /* O returns unique identifier of gains */
128 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain ind ices */
129 const opus_int nb_subfr /* I number o f subframes */
130 )
131 {
132 opus_int k;
133 opus_int32 gainsID;
134
135 gainsID = 0;
136 for( k = 0; k < nb_subfr; k++ ) {
137 gainsID = silk_ADD_LSHIFT32( ind[ k ], gainsID, 8 );
138 }
139
140 return gainsID;
141 }
OLDNEW
« no previous file with comments | « opus/silk/float/wrappers_FLP.c ('k') | opus/silk/init_decoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698