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 #ifdef FIXED_POINT | 31 #ifdef FIXED_POINT |
32 #include "main_FIX.h" | 32 #include "main_FIX.h" |
33 #define silk_encoder_state_Fxx silk_encoder_state_FIX | 33 #define silk_encoder_state_Fxx silk_encoder_state_FIX |
34 #else | 34 #else |
35 #include "main_FLP.h" | 35 #include "main_FLP.h" |
36 #define silk_encoder_state_Fxx silk_encoder_state_FLP | 36 #define silk_encoder_state_Fxx silk_encoder_state_FLP |
37 #endif | 37 #endif |
| 38 #include "stack_alloc.h" |
38 #include "tuning_parameters.h" | 39 #include "tuning_parameters.h" |
39 #include "pitch_est_defines.h" | 40 #include "pitch_est_defines.h" |
40 | 41 |
41 static opus_int silk_setup_resamplers( | 42 static opus_int silk_setup_resamplers( |
42 silk_encoder_state_Fxx *psEnc, /* I/O
*/ | 43 silk_encoder_state_Fxx *psEnc, /* I/O
*/ |
43 opus_int fs_kHz /* I
*/ | 44 opus_int fs_kHz /* I
*/ |
44 ); | 45 ); |
45 | 46 |
46 static opus_int silk_setup_fs( | 47 static opus_int silk_setup_fs( |
47 silk_encoder_state_Fxx *psEnc, /* I/O
*/ | 48 silk_encoder_state_Fxx *psEnc, /* I/O
*/ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 131 |
131 return ret; | 132 return ret; |
132 } | 133 } |
133 | 134 |
134 static opus_int silk_setup_resamplers( | 135 static opus_int silk_setup_resamplers( |
135 silk_encoder_state_Fxx *psEnc, /* I/O
*/ | 136 silk_encoder_state_Fxx *psEnc, /* I/O
*/ |
136 opus_int fs_kHz /* I
*/ | 137 opus_int fs_kHz /* I
*/ |
137 ) | 138 ) |
138 { | 139 { |
139 opus_int ret = SILK_NO_ERROR; | 140 opus_int ret = SILK_NO_ERROR; |
140 opus_int32 nSamples_temp; | 141 SAVE_STACK; |
141 | 142 |
142 if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCm
n.API_fs_Hz ) | 143 if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCm
n.API_fs_Hz ) |
143 { | 144 { |
144 if( psEnc->sCmn.fs_kHz == 0 ) { | 145 if( psEnc->sCmn.fs_kHz == 0 ) { |
145 /* Initialize the resampler for enc_API.c preparing resampling from
API_fs_Hz to fs_kHz */ | 146 /* Initialize the resampler for enc_API.c preparing resampling from
API_fs_Hz to fs_kHz */ |
146 ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCm
n.API_fs_Hz, fs_kHz * 1000, 1 ); | 147 ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCm
n.API_fs_Hz, fs_kHz * 1000, 1 ); |
147 } else { | 148 } else { |
148 /* Allocate worst case space for temporary upsampling, 8 to 48 kHz,
so a factor 6 */ | 149 VARDECL( opus_int16, x_buf_API_fs_Hz ); |
149 opus_int16 x_buf_API_fs_Hz[ ( 2 * MAX_FRAME_LENGTH_MS + LA_SHAPE_MS
) * MAX_API_FS_KHZ ]; | 150 VARDECL( silk_resampler_state_struct, temp_resampler_state ); |
150 silk_resampler_state_struct temp_resampler_state; | |
151 #ifdef FIXED_POINT | 151 #ifdef FIXED_POINT |
152 opus_int16 *x_bufFIX = psEnc->x_buf; | 152 opus_int16 *x_bufFIX = psEnc->x_buf; |
153 #else | 153 #else |
154 opus_int16 x_bufFIX[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; | 154 VARDECL( opus_int16, x_bufFIX ); |
| 155 opus_int32 new_buf_samples; |
155 #endif | 156 #endif |
| 157 opus_int32 api_buf_samples; |
| 158 opus_int32 old_buf_samples; |
| 159 opus_int32 buf_length_ms; |
156 | 160 |
157 nSamples_temp = silk_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAP
E_MS * psEnc->sCmn.fs_kHz; | 161 buf_length_ms = silk_LSHIFT( psEnc->sCmn.nb_subfr * 5, 1 ) + LA_SHAP
E_MS; |
| 162 old_buf_samples = buf_length_ms * psEnc->sCmn.fs_kHz; |
158 | 163 |
159 #ifndef FIXED_POINT | 164 #ifndef FIXED_POINT |
160 silk_float2short_array( x_bufFIX, psEnc->x_buf, nSamples_temp ); | 165 new_buf_samples = buf_length_ms * fs_kHz; |
| 166 ALLOC( x_bufFIX, silk_max( old_buf_samples, new_buf_samples ), |
| 167 opus_int16 ); |
| 168 silk_float2short_array( x_bufFIX, psEnc->x_buf, old_buf_samples ); |
161 #endif | 169 #endif |
162 | 170 |
163 /* Initialize resampler for temporary resampling of x_buf data to AP
I_fs_Hz */ | 171 /* Initialize resampler for temporary resampling of x_buf data to AP
I_fs_Hz */ |
164 ret += silk_resampler_init( &temp_resampler_state, silk_SMULBB( psEn
c->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz, 0 ); | 172 ALLOC( temp_resampler_state, 1, silk_resampler_state_struct ); |
| 173 ret += silk_resampler_init( temp_resampler_state, silk_SMULBB( psEnc
->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz, 0 ); |
| 174 |
| 175 /* Calculate number of samples to temporarily upsample */ |
| 176 api_buf_samples = buf_length_ms * silk_DIV32_16( psEnc->sCmn.API_fs_
Hz, 1000 ); |
165 | 177 |
166 /* Temporary resampling of x_buf data to API_fs_Hz */ | 178 /* Temporary resampling of x_buf data to API_fs_Hz */ |
167 ret += silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, x_buf
FIX, nSamples_temp ); | 179 ALLOC( x_buf_API_fs_Hz, api_buf_samples, opus_int16 ); |
168 | 180 ret += silk_resampler( temp_resampler_state, x_buf_API_fs_Hz, x_bufF
IX, old_buf_samples ); |
169 /* Calculate number of samples that has been temporarily upsampled *
/ | |
170 nSamples_temp = silk_DIV32_16( nSamples_temp * psEnc->sCmn.API_fs_Hz
, silk_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) ); | |
171 | 181 |
172 /* Initialize the resampler for enc_API.c preparing resampling from
API_fs_Hz to fs_kHz */ | 182 /* Initialize the resampler for enc_API.c preparing resampling from
API_fs_Hz to fs_kHz */ |
173 ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCm
n.API_fs_Hz, silk_SMULBB( fs_kHz, 1000 ), 1 ); | 183 ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCm
n.API_fs_Hz, silk_SMULBB( fs_kHz, 1000 ), 1 ); |
174 | 184 |
175 /* Correct resampler state by resampling buffered data from API_fs_H
z to fs_kHz */ | 185 /* Correct resampler state by resampling buffered data from API_fs_H
z to fs_kHz */ |
176 ret += silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf
_API_fs_Hz, nSamples_temp ); | 186 ret += silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf
_API_fs_Hz, api_buf_samples ); |
177 | 187 |
178 #ifndef FIXED_POINT | 188 #ifndef FIXED_POINT |
179 silk_short2float_array( psEnc->x_buf, x_bufFIX, ( 2 * MAX_FRAME_LENG
TH_MS + LA_SHAPE_MS ) * fs_kHz ); | 189 silk_short2float_array( psEnc->x_buf, x_bufFIX, new_buf_samples); |
180 #endif | 190 #endif |
181 } | 191 } |
182 } | 192 } |
183 | 193 |
184 psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz; | 194 psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz; |
185 | 195 |
| 196 RESTORE_STACK; |
186 return ret; | 197 return ret; |
187 } | 198 } |
188 | 199 |
189 static opus_int silk_setup_fs( | 200 static opus_int silk_setup_fs( |
190 silk_encoder_state_Fxx *psEnc, /* I/O
*/ | 201 silk_encoder_state_Fxx *psEnc, /* I/O
*/ |
191 opus_int fs_kHz, /* I
*/ | 202 opus_int fs_kHz, /* I
*/ |
192 opus_int PacketSize_ms /* I
*/ | 203 opus_int PacketSize_ms /* I
*/ |
193 ) | 204 ) |
194 { | 205 { |
195 opus_int ret = SILK_NO_ERROR; | 206 opus_int ret = SILK_NO_ERROR; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 413 |
403 if( TargetRate_bps > LBRR_rate_thres_bps ) { | 414 if( TargetRate_bps > LBRR_rate_thres_bps ) { |
404 /* Set gain increase for coding LBRR excitation */ | 415 /* Set gain increase for coding LBRR excitation */ |
405 psEncC->LBRR_enabled = 1; | 416 psEncC->LBRR_enabled = 1; |
406 psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_in
t32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); | 417 psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_in
t32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); |
407 } | 418 } |
408 } | 419 } |
409 | 420 |
410 return ret; | 421 return ret; |
411 } | 422 } |
OLD | NEW |