media/libopus/silk/shell_coder.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /***********************************************************************
michael@0 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
michael@0 3 Redistribution and use in source and binary forms, with or without
michael@0 4 modification, are permitted provided that the following conditions
michael@0 5 are met:
michael@0 6 - Redistributions of source code must retain the above copyright notice,
michael@0 7 this list of conditions and the following disclaimer.
michael@0 8 - Redistributions in binary form must reproduce the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer in the
michael@0 10 documentation and/or other materials provided with the distribution.
michael@0 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
michael@0 12 names of specific contributors, may be used to endorse or promote
michael@0 13 products derived from this software without specific prior written
michael@0 14 permission.
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 25 POSSIBILITY OF SUCH DAMAGE.
michael@0 26 ***********************************************************************/
michael@0 27
michael@0 28 #ifdef HAVE_CONFIG_H
michael@0 29 #include "config.h"
michael@0 30 #endif
michael@0 31
michael@0 32 #include "main.h"
michael@0 33
michael@0 34 /* shell coder; pulse-subframe length is hardcoded */
michael@0 35
michael@0 36 static OPUS_INLINE void combine_pulses(
michael@0 37 opus_int *out, /* O combined pulses vector [len] */
michael@0 38 const opus_int *in, /* I input vector [2 * len] */
michael@0 39 const opus_int len /* I number of OUTPUT samples */
michael@0 40 )
michael@0 41 {
michael@0 42 opus_int k;
michael@0 43 for( k = 0; k < len; k++ ) {
michael@0 44 out[ k ] = in[ 2 * k ] + in[ 2 * k + 1 ];
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 static OPUS_INLINE void encode_split(
michael@0 49 ec_enc *psRangeEnc, /* I/O compressor data structure */
michael@0 50 const opus_int p_child1, /* I pulse amplitude of first child subframe */
michael@0 51 const opus_int p, /* I pulse amplitude of current subframe */
michael@0 52 const opus_uint8 *shell_table /* I table of shell cdfs */
michael@0 53 )
michael@0 54 {
michael@0 55 if( p > 0 ) {
michael@0 56 ec_enc_icdf( psRangeEnc, p_child1, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 );
michael@0 57 }
michael@0 58 }
michael@0 59
michael@0 60 static OPUS_INLINE void decode_split(
michael@0 61 opus_int *p_child1, /* O pulse amplitude of first child subframe */
michael@0 62 opus_int *p_child2, /* O pulse amplitude of second child subframe */
michael@0 63 ec_dec *psRangeDec, /* I/O Compressor data structure */
michael@0 64 const opus_int p, /* I pulse amplitude of current subframe */
michael@0 65 const opus_uint8 *shell_table /* I table of shell cdfs */
michael@0 66 )
michael@0 67 {
michael@0 68 if( p > 0 ) {
michael@0 69 p_child1[ 0 ] = ec_dec_icdf( psRangeDec, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 );
michael@0 70 p_child2[ 0 ] = p - p_child1[ 0 ];
michael@0 71 } else {
michael@0 72 p_child1[ 0 ] = 0;
michael@0 73 p_child2[ 0 ] = 0;
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 /* Shell encoder, operates on one shell code frame of 16 pulses */
michael@0 78 void silk_shell_encoder(
michael@0 79 ec_enc *psRangeEnc, /* I/O compressor data structure */
michael@0 80 const opus_int *pulses0 /* I data: nonnegative pulse amplitudes */
michael@0 81 )
michael@0 82 {
michael@0 83 opus_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];
michael@0 84
michael@0 85 /* this function operates on one shell code frame of 16 pulses */
michael@0 86 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
michael@0 87
michael@0 88 /* tree representation per pulse-subframe */
michael@0 89 combine_pulses( pulses1, pulses0, 8 );
michael@0 90 combine_pulses( pulses2, pulses1, 4 );
michael@0 91 combine_pulses( pulses3, pulses2, 2 );
michael@0 92 combine_pulses( pulses4, pulses3, 1 );
michael@0 93
michael@0 94 encode_split( psRangeEnc, pulses3[ 0 ], pulses4[ 0 ], silk_shell_code_table3 );
michael@0 95
michael@0 96 encode_split( psRangeEnc, pulses2[ 0 ], pulses3[ 0 ], silk_shell_code_table2 );
michael@0 97
michael@0 98 encode_split( psRangeEnc, pulses1[ 0 ], pulses2[ 0 ], silk_shell_code_table1 );
michael@0 99 encode_split( psRangeEnc, pulses0[ 0 ], pulses1[ 0 ], silk_shell_code_table0 );
michael@0 100 encode_split( psRangeEnc, pulses0[ 2 ], pulses1[ 1 ], silk_shell_code_table0 );
michael@0 101
michael@0 102 encode_split( psRangeEnc, pulses1[ 2 ], pulses2[ 1 ], silk_shell_code_table1 );
michael@0 103 encode_split( psRangeEnc, pulses0[ 4 ], pulses1[ 2 ], silk_shell_code_table0 );
michael@0 104 encode_split( psRangeEnc, pulses0[ 6 ], pulses1[ 3 ], silk_shell_code_table0 );
michael@0 105
michael@0 106 encode_split( psRangeEnc, pulses2[ 2 ], pulses3[ 1 ], silk_shell_code_table2 );
michael@0 107
michael@0 108 encode_split( psRangeEnc, pulses1[ 4 ], pulses2[ 2 ], silk_shell_code_table1 );
michael@0 109 encode_split( psRangeEnc, pulses0[ 8 ], pulses1[ 4 ], silk_shell_code_table0 );
michael@0 110 encode_split( psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], silk_shell_code_table0 );
michael@0 111
michael@0 112 encode_split( psRangeEnc, pulses1[ 6 ], pulses2[ 3 ], silk_shell_code_table1 );
michael@0 113 encode_split( psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], silk_shell_code_table0 );
michael@0 114 encode_split( psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], silk_shell_code_table0 );
michael@0 115 }
michael@0 116
michael@0 117
michael@0 118 /* Shell decoder, operates on one shell code frame of 16 pulses */
michael@0 119 void silk_shell_decoder(
michael@0 120 opus_int *pulses0, /* O data: nonnegative pulse amplitudes */
michael@0 121 ec_dec *psRangeDec, /* I/O Compressor data structure */
michael@0 122 const opus_int pulses4 /* I number of pulses per pulse-subframe */
michael@0 123 )
michael@0 124 {
michael@0 125 opus_int pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ];
michael@0 126
michael@0 127 /* this function operates on one shell code frame of 16 pulses */
michael@0 128 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
michael@0 129
michael@0 130 decode_split( &pulses3[ 0 ], &pulses3[ 1 ], psRangeDec, pulses4, silk_shell_code_table3 );
michael@0 131
michael@0 132 decode_split( &pulses2[ 0 ], &pulses2[ 1 ], psRangeDec, pulses3[ 0 ], silk_shell_code_table2 );
michael@0 133
michael@0 134 decode_split( &pulses1[ 0 ], &pulses1[ 1 ], psRangeDec, pulses2[ 0 ], silk_shell_code_table1 );
michael@0 135 decode_split( &pulses0[ 0 ], &pulses0[ 1 ], psRangeDec, pulses1[ 0 ], silk_shell_code_table0 );
michael@0 136 decode_split( &pulses0[ 2 ], &pulses0[ 3 ], psRangeDec, pulses1[ 1 ], silk_shell_code_table0 );
michael@0 137
michael@0 138 decode_split( &pulses1[ 2 ], &pulses1[ 3 ], psRangeDec, pulses2[ 1 ], silk_shell_code_table1 );
michael@0 139 decode_split( &pulses0[ 4 ], &pulses0[ 5 ], psRangeDec, pulses1[ 2 ], silk_shell_code_table0 );
michael@0 140 decode_split( &pulses0[ 6 ], &pulses0[ 7 ], psRangeDec, pulses1[ 3 ], silk_shell_code_table0 );
michael@0 141
michael@0 142 decode_split( &pulses2[ 2 ], &pulses2[ 3 ], psRangeDec, pulses3[ 1 ], silk_shell_code_table2 );
michael@0 143
michael@0 144 decode_split( &pulses1[ 4 ], &pulses1[ 5 ], psRangeDec, pulses2[ 2 ], silk_shell_code_table1 );
michael@0 145 decode_split( &pulses0[ 8 ], &pulses0[ 9 ], psRangeDec, pulses1[ 4 ], silk_shell_code_table0 );
michael@0 146 decode_split( &pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], silk_shell_code_table0 );
michael@0 147
michael@0 148 decode_split( &pulses1[ 6 ], &pulses1[ 7 ], psRangeDec, pulses2[ 3 ], silk_shell_code_table1 );
michael@0 149 decode_split( &pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], silk_shell_code_table0 );
michael@0 150 decode_split( &pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], silk_shell_code_table0 );
michael@0 151 }

mercurial