| 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_FIX.h" | 32 #include "main_FIX.h" |
| 33 #include "stack_alloc.h" |
| 33 #include "tuning_parameters.h" | 34 #include "tuning_parameters.h" |
| 34 | 35 |
| 35 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ | 36 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ |
| 36 static inline void silk_LBRR_encode_FIX( | 37 static inline void silk_LBRR_encode_FIX( |
| 37 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ | 38 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ |
| 38 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ | 39 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ |
| 39 const opus_int32 xfw_Q3[], /* I
Input signal
*/ | 40 const opus_int32 xfw_Q3[], /* I
Input signal
*/ |
| 40 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ | 41 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ |
| 41 ); | 42 ); |
| 42 | 43 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ | 78 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ |
| 78 opus_int32 *pnBytesOut, /* O
Pointer to number of payload bytes;
*/ | 79 opus_int32 *pnBytesOut, /* O
Pointer to number of payload bytes;
*/ |
| 79 ec_enc *psRangeEnc, /* I
/O compressor data structure
*/ | 80 ec_enc *psRangeEnc, /* I
/O compressor data structure
*/ |
| 80 opus_int condCoding, /* I
The type of conditional coding to use
*/ | 81 opus_int condCoding, /* I
The type of conditional coding to use
*/ |
| 81 opus_int maxBits, /* I
If > 0: maximum number of output bits
*/ | 82 opus_int maxBits, /* I
If > 0: maximum number of output bits
*/ |
| 82 opus_int useCBR /* I
Flag to force constant-bitrate operation
*/ | 83 opus_int useCBR /* I
Flag to force constant-bitrate operation
*/ |
| 83 ) | 84 ) |
| 84 { | 85 { |
| 85 silk_encoder_control_FIX sEncCtrl; | 86 silk_encoder_control_FIX sEncCtrl; |
| 86 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; | 87 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; |
| 87 opus_int16 *x_frame, *res_pitch_frame; | 88 opus_int16 *x_frame; |
| 88 opus_int32 xfw_Q3[ MAX_FRAME_LENGTH ]; | |
| 89 opus_int16 res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; | |
| 90 ec_enc sRangeEnc_copy, sRangeEnc_copy2; | 89 ec_enc sRangeEnc_copy, sRangeEnc_copy2; |
| 91 silk_nsq_state sNSQ_copy, sNSQ_copy2; | 90 silk_nsq_state sNSQ_copy, sNSQ_copy2; |
| 92 opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gai
nMult_upper; | 91 opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gai
nMult_upper; |
| 93 opus_int32 gainsID, gainsID_lower, gainsID_upper; | 92 opus_int32 gainsID, gainsID_lower, gainsID_upper; |
| 94 opus_int16 gainMult_Q8; | 93 opus_int16 gainMult_Q8; |
| 95 opus_int16 ec_prevLagIndex_copy; | 94 opus_int16 ec_prevLagIndex_copy; |
| 96 opus_int ec_prevSignalType_copy; | 95 opus_int ec_prevSignalType_copy; |
| 97 opus_int8 LastGainIndex_copy2; | 96 opus_int8 LastGainIndex_copy2; |
| 98 opus_uint8 ec_buf_copy[ 1275 ]; | 97 SAVE_STACK; |
| 99 | 98 |
| 100 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ | 99 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ |
| 101 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; | 100 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; |
| 102 | 101 |
| 103 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; | 102 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; |
| 104 | 103 |
| 105 /**************************************************************/ | 104 /**************************************************************/ |
| 106 /* Set up Input Pointers, and insert frame in input buffer */ | 105 /* Set up Input Pointers, and insert frame in input buffer */ |
| 107 /*************************************************************/ | 106 /*************************************************************/ |
| 108 /* pointers aligned with start of frame to encode */ | 107 /* start of frame to encode */ |
| 109 x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; /* start of
frame to encode */ | 108 x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; |
| 110 res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; /* start of
pitch LPC residual frame */ | |
| 111 | 109 |
| 112 /***************************************/ | 110 /***************************************/ |
| 113 /* Ensure smooth bandwidth transitions */ | 111 /* Ensure smooth bandwidth transitions */ |
| 114 /***************************************/ | 112 /***************************************/ |
| 115 silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->
sCmn.frame_length ); | 113 silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->
sCmn.frame_length ); |
| 116 | 114 |
| 117 /*******************************************/ | 115 /*******************************************/ |
| 118 /* Copy new frame to front of input buffer */ | 116 /* Copy new frame to front of input buffer */ |
| 119 /*******************************************/ | 117 /*******************************************/ |
| 120 silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBu
f + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) ); | 118 silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBu
f + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) ); |
| 121 | 119 |
| 122 if( !psEnc->sCmn.prefillFlag ) { | 120 if( !psEnc->sCmn.prefillFlag ) { |
| 121 VARDECL( opus_int32, xfw_Q3 ); |
| 122 VARDECL( opus_int16, res_pitch ); |
| 123 VARDECL( opus_uint8, ec_buf_copy ); |
| 124 opus_int16 *res_pitch_frame; |
| 125 |
| 126 ALLOC( res_pitch, |
| 127 psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length |
| 128 + psEnc->sCmn.ltp_mem_length, opus_int16 ); |
| 129 /* start of pitch LPC residual frame */ |
| 130 res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; |
| 131 |
| 123 /*****************************************/ | 132 /*****************************************/ |
| 124 /* Find pitch lags, initial LPC analysis */ | 133 /* Find pitch lags, initial LPC analysis */ |
| 125 /*****************************************/ | 134 /*****************************************/ |
| 126 silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame ); | 135 silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame ); |
| 127 | 136 |
| 128 /************************/ | 137 /************************/ |
| 129 /* Noise shape analysis */ | 138 /* Noise shape analysis */ |
| 130 /************************/ | 139 /************************/ |
| 131 silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e ); | 140 silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e ); |
| 132 | 141 |
| 133 /***************************************************/ | 142 /***************************************************/ |
| 134 /* Find linear prediction coefficients (LPC + LTP) */ | 143 /* Find linear prediction coefficients (LPC + LTP) */ |
| 135 /***************************************************/ | 144 /***************************************************/ |
| 136 silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, condCodi
ng ); | 145 silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, condCodi
ng ); |
| 137 | 146 |
| 138 /****************************************/ | 147 /****************************************/ |
| 139 /* Process gains */ | 148 /* Process gains */ |
| 140 /****************************************/ | 149 /****************************************/ |
| 141 silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding ); | 150 silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding ); |
| 142 | 151 |
| 143 /*****************************************/ | 152 /*****************************************/ |
| 144 /* Prefiltering for noise shaper */ | 153 /* Prefiltering for noise shaper */ |
| 145 /*****************************************/ | 154 /*****************************************/ |
| 155 ALLOC( xfw_Q3, psEnc->sCmn.frame_length, opus_int32 ); |
| 146 silk_prefilter_FIX( psEnc, &sEncCtrl, xfw_Q3, x_frame ); | 156 silk_prefilter_FIX( psEnc, &sEncCtrl, xfw_Q3, x_frame ); |
| 147 | 157 |
| 148 /****************************************/ | 158 /****************************************/ |
| 149 /* Low Bitrate Redundant Encoding */ | 159 /* Low Bitrate Redundant Encoding */ |
| 150 /****************************************/ | 160 /****************************************/ |
| 151 silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw_Q3, condCoding ); | 161 silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw_Q3, condCoding ); |
| 152 | 162 |
| 153 /* Loop over quantizer and entropy coding to control bitrate */ | 163 /* Loop over quantizer and entropy coding to control bitrate */ |
| 154 maxIter = 6; | 164 maxIter = 6; |
| 155 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); | 165 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); |
| 156 found_lower = 0; | 166 found_lower = 0; |
| 157 found_upper = 0; | 167 found_upper = 0; |
| 158 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); | 168 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); |
| 159 gainsID_lower = -1; | 169 gainsID_lower = -1; |
| 160 gainsID_upper = -1; | 170 gainsID_upper = -1; |
| 161 /* Copy part of the input state */ | 171 /* Copy part of the input state */ |
| 162 silk_memcpy( &sRangeEnc_copy, psRangeEnc, sizeof( ec_enc ) ); | 172 silk_memcpy( &sRangeEnc_copy, psRangeEnc, sizeof( ec_enc ) ); |
| 163 silk_memcpy( &sNSQ_copy, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) ); | 173 silk_memcpy( &sNSQ_copy, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) ); |
| 164 seed_copy = psEnc->sCmn.indices.Seed; | 174 seed_copy = psEnc->sCmn.indices.Seed; |
| 165 ec_prevLagIndex_copy = psEnc->sCmn.ec_prevLagIndex; | 175 ec_prevLagIndex_copy = psEnc->sCmn.ec_prevLagIndex; |
| 166 ec_prevSignalType_copy = psEnc->sCmn.ec_prevSignalType; | 176 ec_prevSignalType_copy = psEnc->sCmn.ec_prevSignalType; |
| 177 ALLOC( ec_buf_copy, 1275, opus_uint8 ); |
| 167 for( iter = 0; ; iter++ ) { | 178 for( iter = 0; ; iter++ ) { |
| 168 if( gainsID == gainsID_lower ) { | 179 if( gainsID == gainsID_lower ) { |
| 169 nBits = nBits_lower; | 180 nBits = nBits_lower; |
| 170 } else if( gainsID == gainsID_upper ) { | 181 } else if( gainsID == gainsID_upper ) { |
| 171 nBits = nBits_upper; | 182 nBits = nBits_upper; |
| 172 } else { | 183 } else { |
| 173 /* Restore part of the input state */ | 184 /* Restore part of the input state */ |
| 174 if( iter > 0 ) { | 185 if( iter > 0 ) { |
| 175 silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) )
; | 186 silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) )
; |
| 176 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); | 187 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * size
of( opus_int16 ) ); | 303 ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * size
of( opus_int16 ) ); |
| 293 | 304 |
| 294 /* Parameters needed for next frame */ | 305 /* Parameters needed for next frame */ |
| 295 psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; | 306 psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; |
| 296 psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; | 307 psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; |
| 297 | 308 |
| 298 /* Exit without entropy coding */ | 309 /* Exit without entropy coding */ |
| 299 if( psEnc->sCmn.prefillFlag ) { | 310 if( psEnc->sCmn.prefillFlag ) { |
| 300 /* No payload */ | 311 /* No payload */ |
| 301 *pnBytesOut = 0; | 312 *pnBytesOut = 0; |
| 313 RESTORE_STACK; |
| 302 return ret; | 314 return ret; |
| 303 } | 315 } |
| 304 | 316 |
| 305 /****************************************/ | 317 /****************************************/ |
| 306 /* Finalize payload */ | 318 /* Finalize payload */ |
| 307 /****************************************/ | 319 /****************************************/ |
| 308 psEnc->sCmn.first_frame_after_reset = 0; | 320 psEnc->sCmn.first_frame_after_reset = 0; |
| 309 /* Payload size */ | 321 /* Payload size */ |
| 310 *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); | 322 *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); |
| 311 | 323 |
| 324 RESTORE_STACK; |
| 312 return ret; | 325 return ret; |
| 313 } | 326 } |
| 314 | 327 |
| 315 /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excit
ation at lower bitrate */ | 328 /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excit
ation at lower bitrate */ |
| 316 static inline void silk_LBRR_encode_FIX( | 329 static inline void silk_LBRR_encode_FIX( |
| 317 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ | 330 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ |
| 318 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ | 331 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ |
| 319 const opus_int32 xfw_Q3[], /* I
Input signal
*/ | 332 const opus_int32 xfw_Q3[], /* I
Input signal
*/ |
| 320 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ | 333 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ |
| 321 ) | 334 ) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, | 376 silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, |
| 364 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, | 377 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, |
| 365 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Til
t_Q14, psEncCtrl->LF_shp_Q14, | 378 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Til
t_Q14, psEncCtrl->LF_shp_Q14, |
| 366 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14 ); | 379 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14 ); |
| 367 } | 380 } |
| 368 | 381 |
| 369 /* Restore original gains */ | 382 /* Restore original gains */ |
| 370 silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr *
sizeof( opus_int32 ) ); | 383 silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr *
sizeof( opus_int32 ) ); |
| 371 } | 384 } |
| 372 } | 385 } |
| OLD | NEW |