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

Side by Side Diff: silk/CNG.c

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 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
« no previous file with comments | « silk/API.h ('k') | silk/LPC_analysis_filter.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
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 #include "stack_alloc.h"
34 34
35 /* Generates excitation for CNG LPC synthesis */ 35 /* Generates excitation for CNG LPC synthesis */
36 static OPUS_INLINE void silk_CNG_exc( 36 static OPUS_INLINE void silk_CNG_exc(
37 opus_int32 residual_Q10[], /* O CNG residual si gnal Q10 */ 37 opus_int32 exc_Q10[], /* O CNG excitation signal Q10 */
38 opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */ 38 opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */
39 opus_int32 Gain_Q16, /* I Gain to apply */ 39 opus_int32 Gain_Q16, /* I Gain to apply */
40 opus_int length, /* I Length */ 40 opus_int length, /* I Length */
41 opus_int32 *rand_seed /* I/O Seed to random index generator */ 41 opus_int32 *rand_seed /* I/O Seed to random index generator */
42 ) 42 )
43 { 43 {
44 opus_int32 seed; 44 opus_int32 seed;
45 opus_int i, idx, exc_mask; 45 opus_int i, idx, exc_mask;
46 46
47 exc_mask = CNG_BUF_MASK_MAX; 47 exc_mask = CNG_BUF_MASK_MAX;
48 while( exc_mask > length ) { 48 while( exc_mask > length ) {
49 exc_mask = silk_RSHIFT( exc_mask, 1 ); 49 exc_mask = silk_RSHIFT( exc_mask, 1 );
50 } 50 }
51 51
52 seed = *rand_seed; 52 seed = *rand_seed;
53 for( i = 0; i < length; i++ ) { 53 for( i = 0; i < length; i++ ) {
54 seed = silk_RAND( seed ); 54 seed = silk_RAND( seed );
55 idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask ); 55 idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask );
56 silk_assert( idx >= 0 ); 56 silk_assert( idx >= 0 );
57 silk_assert( idx <= CNG_BUF_MASK_MAX ); 57 silk_assert( idx <= CNG_BUF_MASK_MAX );
58 residual_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ id x ], Gain_Q16 >> 4 ) ); 58 exc_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
59 } 59 }
60 *rand_seed = seed; 60 *rand_seed = seed;
61 } 61 }
62 62
63 void silk_CNG_Reset( 63 void silk_CNG_Reset(
64 silk_decoder_state *psDec /* I/O Decoder state */ 64 silk_decoder_state *psDec /* I/O Decoder state */
65 ) 65 )
66 { 66 {
67 opus_int i, NLSF_step_Q15, NLSF_acc_Q15; 67 opus_int i, NLSF_step_Q15, NLSF_acc_Q15;
68 68
69 NLSF_step_Q15 = silk_DIV32_16( silk_int16_MAX, psDec->LPC_order + 1 ); 69 NLSF_step_Q15 = silk_DIV32_16( silk_int16_MAX, psDec->LPC_order + 1 );
70 NLSF_acc_Q15 = 0; 70 NLSF_acc_Q15 = 0;
71 for( i = 0; i < psDec->LPC_order; i++ ) { 71 for( i = 0; i < psDec->LPC_order; i++ ) {
72 NLSF_acc_Q15 += NLSF_step_Q15; 72 NLSF_acc_Q15 += NLSF_step_Q15;
73 psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15; 73 psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15;
74 } 74 }
75 psDec->sCNG.CNG_smth_Gain_Q16 = 0; 75 psDec->sCNG.CNG_smth_Gain_Q16 = 0;
76 psDec->sCNG.rand_seed = 3176576; 76 psDec->sCNG.rand_seed = 3176576;
77 } 77 }
78 78
79 /* Updates CNG estimate, and applies the CNG when packet was lost */ 79 /* Updates CNG estimate, and applies the CNG when packet was lost */
80 void silk_CNG( 80 void silk_CNG(
81 silk_decoder_state *psDec, /* I/O Decoder state */ 81 silk_decoder_state *psDec, /* I/O Decoder state */
82 silk_decoder_control *psDecCtrl, /* I/O Decoder control */ 82 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
83 opus_int16 frame[], /* I/O Signal */ 83 opus_int16 frame[], /* I/O Signal */
84 opus_int length /* I Length o f residual */ 84 opus_int length /* I Length o f residual */
85 ) 85 )
86 { 86 {
87 opus_int i, subfr; 87 opus_int i, subfr;
88 opus_int32 sum_Q6, max_Gain_Q16; 88 opus_int32 sum_Q6, max_Gain_Q16, gain_Q16;
89 opus_int16 A_Q12[ MAX_LPC_ORDER ]; 89 opus_int16 A_Q12[ MAX_LPC_ORDER ];
90 silk_CNG_struct *psCNG = &psDec->sCNG; 90 silk_CNG_struct *psCNG = &psDec->sCNG;
91 SAVE_STACK; 91 SAVE_STACK;
92 92
93 if( psDec->fs_kHz != psCNG->fs_kHz ) { 93 if( psDec->fs_kHz != psCNG->fs_kHz ) {
94 /* Reset state */ 94 /* Reset state */
95 silk_CNG_Reset( psDec ); 95 silk_CNG_Reset( psDec );
96 96
97 psCNG->fs_kHz = psDec->fs_kHz; 97 psCNG->fs_kHz = psDec->fs_kHz;
98 } 98 }
(...skipping 19 matching lines...) Expand all
118 118
119 /* Smooth gains */ 119 /* Smooth gains */
120 for( i = 0; i < psDec->nb_subfr; i++ ) { 120 for( i = 0; i < psDec->nb_subfr; i++ ) {
121 psCNG->CNG_smth_Gain_Q16 += silk_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 ); 121 psCNG->CNG_smth_Gain_Q16 += silk_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 );
122 } 122 }
123 } 123 }
124 124
125 /* Add CNG when packet is lost or during DTX */ 125 /* Add CNG when packet is lost or during DTX */
126 if( psDec->lossCnt ) { 126 if( psDec->lossCnt ) {
127 VARDECL( opus_int32, CNG_sig_Q10 ); 127 VARDECL( opus_int32, CNG_sig_Q10 );
128
129 ALLOC( CNG_sig_Q10, length + MAX_LPC_ORDER, opus_int32 ); 128 ALLOC( CNG_sig_Q10, length + MAX_LPC_ORDER, opus_int32 );
130 129
131 /* Generate CNG excitation */ 130 /* Generate CNG excitation */
132 silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, psCNG ->CNG_smth_Gain_Q16, length, &psCNG->rand_seed ); 131 gain_Q16 = silk_SMULWW( psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_ Q16[1] );
132 if( gain_Q16 >= (1 << 21) || psCNG->CNG_smth_Gain_Q16 > (1 << 23) ) {
133 gain_Q16 = silk_SMULTT( gain_Q16, gain_Q16 );
134 gain_Q16 = silk_SUB_LSHIFT32(silk_SMULTT( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
135 gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 16 );
136 } else {
137 gain_Q16 = silk_SMULWW( gain_Q16, gain_Q16 );
138 gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
139 gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 );
140 }
141 silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, gain_ Q16, length, &psCNG->rand_seed );
133 142
134 /* Convert CNG NLSF to filter representation */ 143 /* Convert CNG NLSF to filter representation */
135 silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order ); 144 silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
136 145
137 /* Generate CNG signal, by synthesis filtering */ 146 /* Generate CNG signal, by synthesis filtering */
138 silk_memcpy( CNG_sig_Q10, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof ( opus_int32 ) ); 147 silk_memcpy( CNG_sig_Q10, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof ( opus_int32 ) );
139 for( i = 0; i < length; i++ ) { 148 for( i = 0; i < length; i++ ) {
140 silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 ); 149 silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 );
141 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ 150 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
142 sum_Q6 = silk_RSHIFT( psDec->LPC_order, 1 ); 151 sum_Q6 = silk_RSHIFT( psDec->LPC_order, 1 );
(...skipping 12 matching lines...) Expand all
155 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 2 ], A_Q12[ 11 ] ); 164 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 2 ], A_Q12[ 11 ] );
156 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 3 ], A_Q12[ 12 ] ); 165 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 3 ], A_Q12[ 12 ] );
157 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 4 ], A_Q12[ 13 ] ); 166 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 4 ], A_Q12[ 13 ] );
158 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 5 ], A_Q12[ 14 ] ); 167 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 5 ], A_Q12[ 14 ] );
159 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 6 ], A_Q12[ 15 ] ); 168 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 6 ], A_Q12[ 15 ] );
160 } 169 }
161 170
162 /* Update states */ 171 /* Update states */
163 CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX _LPC_ORDER + i ], sum_Q6, 4 ); 172 CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX _LPC_ORDER + i ], sum_Q6, 4 );
164 173
165 frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( sum_Q6, 6 ) ); 174 frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( CNG_sig_ Q10[ MAX_LPC_ORDER + i ], 10 ) );
166 } 175 }
167 silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORD ER * sizeof( opus_int32 ) ); 176 silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORD ER * sizeof( opus_int32 ) );
168 } else { 177 } else {
169 silk_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof( opus _int32 ) ); 178 silk_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof( opus _int32 ) );
170 } 179 }
171 RESTORE_STACK; 180 RESTORE_STACK;
172 } 181 }
OLDNEW
« no previous file with comments | « silk/API.h ('k') | silk/LPC_analysis_filter.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698