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 | 31 |
32 #include "main.h" | 32 #include "main.h" |
| 33 #include "stack_alloc.h" |
33 | 34 |
34 static inline void silk_nsq_scale_states( | 35 static inline void silk_nsq_scale_states( |
35 const silk_encoder_state *psEncC, /* I Encoder State
*/ | 36 const silk_encoder_state *psEncC, /* I Encoder State
*/ |
36 silk_nsq_state *NSQ, /* I/O NSQ state
*/ | 37 silk_nsq_state *NSQ, /* I/O NSQ state
*/ |
37 const opus_int32 x_Q3[], /* I input in Q3
*/ | 38 const opus_int32 x_Q3[], /* I input in Q3
*/ |
38 opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain
*/ | 39 opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain
*/ |
39 const opus_int16 sLTP[], /* I re-whitened LTP state in
Q0 */ | 40 const opus_int16 sLTP[], /* I re-whitened LTP state in
Q0 */ |
40 opus_int32 sLTP_Q15[], /* O LTP state matching scale
d input */ | 41 opus_int32 sLTP_Q15[], /* O LTP state matching scale
d input */ |
41 opus_int subfr, /* I subframe number
*/ | 42 opus_int subfr, /* I subframe number
*/ |
42 const opus_int LTP_scale_Q14, /* I
*/ | 43 const opus_int LTP_scale_Q14, /* I
*/ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I
Low frequency shaping coefs */ | 82 const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I
Low frequency shaping coefs */ |
82 const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I
Quantization step sizes */ | 83 const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I
Quantization step sizes */ |
83 const opus_int pitchL[ MAX_NB_SUBFR ], /* I
Pitch lags */ | 84 const opus_int pitchL[ MAX_NB_SUBFR ], /* I
Pitch lags */ |
84 const opus_int Lambda_Q10, /* I
Rate/distortion tradeoff */ | 85 const opus_int Lambda_Q10, /* I
Rate/distortion tradeoff */ |
85 const opus_int LTP_scale_Q14 /* I
LTP state scaling */ | 86 const opus_int LTP_scale_Q14 /* I
LTP state scaling */ |
86 ) | 87 ) |
87 { | 88 { |
88 opus_int k, lag, start_idx, LSF_interpolation_flag; | 89 opus_int k, lag, start_idx, LSF_interpolation_flag; |
89 const opus_int16 *A_Q12, *B_Q14, *AR_shp_Q13; | 90 const opus_int16 *A_Q12, *B_Q14, *AR_shp_Q13; |
90 opus_int16 *pxq; | 91 opus_int16 *pxq; |
91 opus_int32 sLTP_Q15[ 2 * MAX_FRAME_LENGTH ]; | 92 VARDECL( opus_int32, sLTP_Q15 ); |
92 opus_int16 sLTP[ 2 * MAX_FRAME_LENGTH ]; | 93 VARDECL( opus_int16, sLTP ); |
93 opus_int32 HarmShapeFIRPacked_Q14; | 94 opus_int32 HarmShapeFIRPacked_Q14; |
94 opus_int offset_Q10; | 95 opus_int offset_Q10; |
95 opus_int32 x_sc_Q10[ MAX_SUB_FRAME_LENGTH ]; | 96 VARDECL( opus_int32, x_sc_Q10 ); |
| 97 SAVE_STACK; |
96 | 98 |
97 NSQ->rand_seed = psIndices->Seed; | 99 NSQ->rand_seed = psIndices->Seed; |
98 | 100 |
99 /* Set unvoiced lag to the previous one, overwrite later for voiced */ | 101 /* Set unvoiced lag to the previous one, overwrite later for voiced */ |
100 lag = NSQ->lagPrev; | 102 lag = NSQ->lagPrev; |
101 | 103 |
102 silk_assert( NSQ->prev_gain_Q16 != 0 ); | 104 silk_assert( NSQ->prev_gain_Q16 != 0 ); |
103 | 105 |
104 offset_Q10 = silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ ps
Indices->quantOffsetType ]; | 106 offset_Q10 = silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ ps
Indices->quantOffsetType ]; |
105 | 107 |
106 if( psIndices->NLSFInterpCoef_Q2 == 4 ) { | 108 if( psIndices->NLSFInterpCoef_Q2 == 4 ) { |
107 LSF_interpolation_flag = 0; | 109 LSF_interpolation_flag = 0; |
108 } else { | 110 } else { |
109 LSF_interpolation_flag = 1; | 111 LSF_interpolation_flag = 1; |
110 } | 112 } |
111 | 113 |
| 114 ALLOC( sLTP_Q15, |
| 115 psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); |
| 116 ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 ); |
| 117 ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 ); |
112 /* Set up pointers to start of sub frame */ | 118 /* Set up pointers to start of sub frame */ |
113 NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; | 119 NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; |
114 NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; | 120 NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; |
115 pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; | 121 pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; |
116 for( k = 0; k < psEncC->nb_subfr; k++ ) { | 122 for( k = 0; k < psEncC->nb_subfr; k++ ) { |
117 A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )
) * MAX_LPC_ORDER ]; | 123 A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )
) * MAX_LPC_ORDER ]; |
118 B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; | 124 B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; |
119 AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; | 125 AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; |
120 | 126 |
121 /* Noise shape parameters */ | 127 /* Noise shape parameters */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 pxq += psEncC->subfr_length; | 159 pxq += psEncC->subfr_length; |
154 } | 160 } |
155 | 161 |
156 /* Update lagPrev for next frame */ | 162 /* Update lagPrev for next frame */ |
157 NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; | 163 NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; |
158 | 164 |
159 /* Save quantized speech and noise shaping signals */ | 165 /* Save quantized speech and noise shaping signals */ |
160 /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[ psEncC->ltp_mem_length ], psEncC->fr
ame_length * sizeof( opus_int16 ) ) */ | 166 /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[ psEncC->ltp_mem_length ], psEncC->fr
ame_length * sizeof( opus_int16 ) ) */ |
161 silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ],
psEncC->ltp_mem_length * sizeof( opus_int16 ) ); | 167 silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ],
psEncC->ltp_mem_length * sizeof( opus_int16 ) ); |
162 silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ],
psEncC->ltp_mem_length * sizeof( opus_int32 ) ); | 168 silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ],
psEncC->ltp_mem_length * sizeof( opus_int32 ) ); |
| 169 RESTORE_STACK; |
163 } | 170 } |
164 | 171 |
165 /***********************************/ | 172 /***********************************/ |
166 /* silk_noise_shape_quantizer */ | 173 /* silk_noise_shape_quantizer */ |
167 /***********************************/ | 174 /***********************************/ |
168 static inline void silk_noise_shape_quantizer( | 175 static inline void silk_noise_shape_quantizer( |
169 silk_nsq_state *NSQ, /* I/O NSQ state
*/ | 176 silk_nsq_state *NSQ, /* I/O NSQ state
*/ |
170 opus_int signalType, /* I Signal type
*/ | 177 opus_int signalType, /* I Signal type
*/ |
171 const opus_int32 x_sc_Q10[], /* I
*/ | 178 const opus_int32 x_sc_Q10[], /* I
*/ |
172 opus_int8 pulses[], /* O
*/ | 179 opus_int8 pulses[], /* O
*/ |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 437 |
431 /* Scale short-term prediction and shaping states */ | 438 /* Scale short-term prediction and shaping states */ |
432 for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { | 439 for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { |
433 NSQ->sLPC_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] )
; | 440 NSQ->sLPC_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] )
; |
434 } | 441 } |
435 for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { | 442 for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { |
436 NSQ->sAR2_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] )
; | 443 NSQ->sAR2_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] )
; |
437 } | 444 } |
438 } | 445 } |
439 } | 446 } |
OLD | NEW |