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 /* Convert Left/Right stereo signal to adaptive Mid/Side representation */ | 35 /* Convert Left/Right stereo signal to adaptive Mid/Side representation */ |
35 void silk_stereo_LR_to_MS( | 36 void silk_stereo_LR_to_MS( |
36 stereo_enc_state *state, /* I/O State
*/ | 37 stereo_enc_state *state, /* I/O State
*/ |
37 opus_int16 x1[], /* I/O Left inp
ut signal, becomes mid signal */ | 38 opus_int16 x1[], /* I/O Left inp
ut signal, becomes mid signal */ |
38 opus_int16 x2[], /* I/O Right in
put signal, becomes side signal */ | 39 opus_int16 x2[], /* I/O Right in
put signal, becomes side signal */ |
39 opus_int8 ix[ 2 ][ 3 ], /* O Quantiza
tion indices */ | 40 opus_int8 ix[ 2 ][ 3 ], /* O Quantiza
tion indices */ |
40 opus_int8 *mid_only_flag, /* O Flag: on
ly mid signal coded */ | 41 opus_int8 *mid_only_flag, /* O Flag: on
ly mid signal coded */ |
41 opus_int32 mid_side_rates_bps[], /* O Bitrates
for mid and side signals */ | 42 opus_int32 mid_side_rates_bps[], /* O Bitrates
for mid and side signals */ |
42 opus_int32 total_rate_bps, /* I Total bi
trate */ | 43 opus_int32 total_rate_bps, /* I Total bi
trate */ |
43 opus_int prev_speech_act_Q8, /* I Speech a
ctivity level in previous frame */ | 44 opus_int prev_speech_act_Q8, /* I Speech a
ctivity level in previous frame */ |
44 opus_int toMono, /* I Last fra
me before a stereo->mono transition */ | 45 opus_int toMono, /* I Last fra
me before a stereo->mono transition */ |
45 opus_int fs_kHz, /* I Sample r
ate (kHz) */ | 46 opus_int fs_kHz, /* I Sample r
ate (kHz) */ |
46 opus_int frame_length /* I Number o
f samples */ | 47 opus_int frame_length /* I Number o
f samples */ |
47 ) | 48 ) |
48 { | 49 { |
49 opus_int n, is10msFrame, denom_Q16, delta0_Q13, delta1_Q13; | 50 opus_int n, is10msFrame, denom_Q16, delta0_Q13, delta1_Q13; |
50 opus_int32 sum, diff, smooth_coef_Q16, pred_Q13[ 2 ], pred0_Q13, pred1_Q13; | 51 opus_int32 sum, diff, smooth_coef_Q16, pred_Q13[ 2 ], pred0_Q13, pred1_Q13; |
51 opus_int32 LP_ratio_Q14, HP_ratio_Q14, frac_Q16, frac_3_Q16, min_mid_rate_bp
s, width_Q14, w_Q24, deltaw_Q24; | 52 opus_int32 LP_ratio_Q14, HP_ratio_Q14, frac_Q16, frac_3_Q16, min_mid_rate_bp
s, width_Q14, w_Q24, deltaw_Q24; |
52 opus_int16 side[ MAX_FRAME_LENGTH + 2 ]; | 53 VARDECL( opus_int16, side ); |
53 opus_int16 LP_mid[ MAX_FRAME_LENGTH ], HP_mid[ MAX_FRAME_LENGTH ]; | 54 VARDECL( opus_int16, LP_mid ); |
54 opus_int16 LP_side[ MAX_FRAME_LENGTH ], HP_side[ MAX_FRAME_LENGTH ]; | 55 VARDECL( opus_int16, HP_mid ); |
| 56 VARDECL( opus_int16, LP_side ); |
| 57 VARDECL( opus_int16, HP_side ); |
55 opus_int16 *mid = &x1[ -2 ]; | 58 opus_int16 *mid = &x1[ -2 ]; |
| 59 SAVE_STACK; |
56 | 60 |
| 61 ALLOC( side, frame_length + 2, opus_int16 ); |
57 /* Convert to basic mid/side signals */ | 62 /* Convert to basic mid/side signals */ |
58 for( n = 0; n < frame_length + 2; n++ ) { | 63 for( n = 0; n < frame_length + 2; n++ ) { |
59 sum = x1[ n - 2 ] + (opus_int32)x2[ n - 2 ]; | 64 sum = x1[ n - 2 ] + (opus_int32)x2[ n - 2 ]; |
60 diff = x1[ n - 2 ] - (opus_int32)x2[ n - 2 ]; | 65 diff = x1[ n - 2 ] - (opus_int32)x2[ n - 2 ]; |
61 mid[ n ] = (opus_int16)silk_RSHIFT_ROUND( sum, 1 ); | 66 mid[ n ] = (opus_int16)silk_RSHIFT_ROUND( sum, 1 ); |
62 side[ n ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( diff, 1 ) ); | 67 side[ n ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( diff, 1 ) ); |
63 } | 68 } |
64 | 69 |
65 /* Buffering */ | 70 /* Buffering */ |
66 silk_memcpy( mid, state->sMid, 2 * sizeof( opus_int16 ) ); | 71 silk_memcpy( mid, state->sMid, 2 * sizeof( opus_int16 ) ); |
67 silk_memcpy( side, state->sSide, 2 * sizeof( opus_int16 ) ); | 72 silk_memcpy( side, state->sSide, 2 * sizeof( opus_int16 ) ); |
68 silk_memcpy( state->sMid, &mid[ frame_length ], 2 * sizeof( opus_int16 ) )
; | 73 silk_memcpy( state->sMid, &mid[ frame_length ], 2 * sizeof( opus_int16 ) )
; |
69 silk_memcpy( state->sSide, &side[ frame_length ], 2 * sizeof( opus_int16 ) )
; | 74 silk_memcpy( state->sSide, &side[ frame_length ], 2 * sizeof( opus_int16 ) )
; |
70 | 75 |
71 /* LP and HP filter mid signal */ | 76 /* LP and HP filter mid signal */ |
| 77 ALLOC( LP_mid, frame_length, opus_int16 ); |
| 78 ALLOC( HP_mid, frame_length, opus_int16 ); |
72 for( n = 0; n < frame_length; n++ ) { | 79 for( n = 0; n < frame_length; n++ ) { |
73 sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[
n + 1 ], 1 ), 2 ); | 80 sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[
n + 1 ], 1 ), 2 ); |
74 LP_mid[ n ] = sum; | 81 LP_mid[ n ] = sum; |
75 HP_mid[ n ] = mid[ n + 1 ] - sum; | 82 HP_mid[ n ] = mid[ n + 1 ] - sum; |
76 } | 83 } |
77 | 84 |
78 /* LP and HP filter side signal */ | 85 /* LP and HP filter side signal */ |
| 86 ALLOC( LP_side, frame_length, opus_int16 ); |
| 87 ALLOC( HP_side, frame_length, opus_int16 ); |
79 for( n = 0; n < frame_length; n++ ) { | 88 for( n = 0; n < frame_length; n++ ) { |
80 sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( side[ n ] + side[ n + 2 ], sid
e[ n + 1 ], 1 ), 2 ); | 89 sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( side[ n ] + side[ n + 2 ], sid
e[ n + 1 ], 1 ), 2 ); |
81 LP_side[ n ] = sum; | 90 LP_side[ n ] = sum; |
82 HP_side[ n ] = side[ n + 1 ] - sum; | 91 HP_side[ n ] = side[ n + 1 ] - sum; |
83 } | 92 } |
84 | 93 |
85 /* Find energies and predictors */ | 94 /* Find energies and predictors */ |
86 is10msFrame = frame_length == 10 * fs_kHz; | 95 is10msFrame = frame_length == 10 * fs_kHz; |
87 smooth_coef_Q16 = is10msFrame ? | 96 smooth_coef_Q16 = is10msFrame ? |
88 SILK_FIX_CONST( STEREO_RATIO_SMOOTH_COEF / 2, 16 ) : | 97 SILK_FIX_CONST( STEREO_RATIO_SMOOTH_COEF / 2, 16 ) : |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 w_Q24 = silk_LSHIFT( width_Q14, 10 ); | 218 w_Q24 = silk_LSHIFT( width_Q14, 10 ); |
210 for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) { | 219 for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) { |
211 sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[ n + 1
], 1 ), 9 ); /* Q11 */ | 220 sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[ n + 1
], 1 ), 9 ); /* Q11 */ |
212 sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 )
; /* Q8 */ | 221 sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 )
; /* Q8 */ |
213 sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pre
d1_Q13 ); /* Q8 */ | 222 sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pre
d1_Q13 ); /* Q8 */ |
214 x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); | 223 x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); |
215 } | 224 } |
216 state->pred_prev_Q13[ 0 ] = (opus_int16)pred_Q13[ 0 ]; | 225 state->pred_prev_Q13[ 0 ] = (opus_int16)pred_Q13[ 0 ]; |
217 state->pred_prev_Q13[ 1 ] = (opus_int16)pred_Q13[ 1 ]; | 226 state->pred_prev_Q13[ 1 ] = (opus_int16)pred_Q13[ 1 ]; |
218 state->width_prev_Q14 = (opus_int16)width_Q14; | 227 state->width_prev_Q14 = (opus_int16)width_Q14; |
| 228 RESTORE_STACK; |
219 } | 229 } |
OLD | NEW |