summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libopus/silk
diff options
context:
space:
mode:
authorFrederik M J Vestre <freqmod@gmail.com>2012-07-26 14:38:32 +0200
committerBertrik Sikken <bertrik@sikken.nl>2012-09-20 20:47:44 +0200
commit1b8e3801b2444f6e466e1b7c09cfc51605e80fb3 (patch)
treebd1d6fe08452d388d0d160ec02e03963f3f9525d /lib/rbcodec/codecs/libopus/silk
parent72ebcbf73b4db911d517a66c820fdceccb8ec798 (diff)
downloadrockbox-1b8e3801b2444f6e466e1b7c09cfc51605e80fb3.tar.gz
rockbox-1b8e3801b2444f6e466e1b7c09cfc51605e80fb3.zip
Initial opus codec support
Synchronised with opus repo on github (https://github.com/freqmod/rockbox-opus) Status: * Seeking ported from speex, but fails on some cases (e.g. seek to granule 0) * ReplayGain parsing needs to be reworked, we do vorbis-style replaygain now. http://wiki.xiph.org/OggOpus#Comment_Header explicitly forbids these in favour of R128_TRACK_GAIN tag. * No optimisation yet, source files still nearly identical to opus upstream * Multi-stream opus files may not be parsed correctly Change-Id: Ia66f1027dc1d288083e3c57b2816700078376f9a Reviewed-on: http://gerrit.rockbox.org/300 Reviewed-by: Bertrik Sikken <bertrik@sikken.nl> Tested-by: Bertrik Sikken <bertrik@sikken.nl>
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk')
-rw-r--r--lib/rbcodec/codecs/libopus/silk/API.h132
-rw-r--r--lib/rbcodec/codecs/libopus/silk/CNG.c167
-rw-r--r--lib/rbcodec/codecs/libopus/silk/Inlines.h188
-rw-r--r--lib/rbcodec/codecs/libopus/silk/LPC_analysis_filter.c85
-rw-r--r--lib/rbcodec/codecs/libopus/silk/LPC_inv_pred_gain.c154
-rw-r--r--lib/rbcodec/codecs/libopus/silk/MacroCount.h718
-rw-r--r--lib/rbcodec/codecs/libopus/silk/MacroDebug.h952
-rw-r--r--lib/rbcodec/codecs/libopus/silk/NLSF2A.c178
-rw-r--r--lib/rbcodec/codecs/libopus/silk/NLSF_VQ_weights_laroia.c80
-rw-r--r--lib/rbcodec/codecs/libopus/silk/NLSF_decode.c101
-rw-r--r--lib/rbcodec/codecs/libopus/silk/NLSF_stabilize.c142
-rw-r--r--lib/rbcodec/codecs/libopus/silk/NLSF_unpack.c55
-rw-r--r--lib/rbcodec/codecs/libopus/silk/PLC.c423
-rw-r--r--lib/rbcodec/codecs/libopus/silk/PLC.h61
-rw-r--r--lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h589
-rw-r--r--lib/rbcodec/codecs/libopus/silk/bwexpander.c51
-rw-r--r--lib/rbcodec/codecs/libopus/silk/bwexpander_32.c50
-rw-r--r--lib/rbcodec/codecs/libopus/silk/code_signs.c115
-rw-r--r--lib/rbcodec/codecs/libopus/silk/control.h139
-rw-r--r--lib/rbcodec/codecs/libopus/silk/dec_API.c392
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_core.c238
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_frame.c128
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_indices.c151
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_parameters.c115
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_pitch.c77
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_pulses.c115
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decoder_set_fs.c108
-rw-r--r--lib/rbcodec/codecs/libopus/silk/define.h235
-rw-r--r--lib/rbcodec/codecs/libopus/silk/errors.h98
-rw-r--r--lib/rbcodec/codecs/libopus/silk/gain_quant.c141
-rw-r--r--lib/rbcodec/codecs/libopus/silk/init_decoder.c56
-rw-r--r--lib/rbcodec/codecs/libopus/silk/lin2log.c46
-rw-r--r--lib/rbcodec/codecs/libopus/silk/log2lin.c56
-rw-r--r--lib/rbcodec/codecs/libopus/silk/macros.h135
-rw-r--r--lib/rbcodec/codecs/libopus/silk/main.h434
-rw-r--r--lib/rbcodec/codecs/libopus/silk/pitch_est_defines.h88
-rw-r--r--lib/rbcodec/codecs/libopus/silk/pitch_est_tables.c99
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler.c215
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private.h88
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private_AR2.c55
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c103
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private_down_FIR.c189
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private_up2_HQ.c113
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_rom.c96
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_rom.h68
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_structs.h57
-rw-r--r--lib/rbcodec/codecs/libopus/silk/shell_coder.c151
-rw-r--r--lib/rbcodec/codecs/libopus/silk/sort.c154
-rw-r--r--lib/rbcodec/codecs/libopus/silk/stereo_MS_to_LR.c85
-rw-r--r--lib/rbcodec/codecs/libopus/silk/stereo_decode_pred.c73
-rw-r--r--lib/rbcodec/codecs/libopus/silk/structs.h324
-rw-r--r--lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c85
-rw-r--r--lib/rbcodec/codecs/libopus/silk/table_LSF_cos.c70
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables.h120
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_LTP.c272
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_NB_MB.c159
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_WB.c198
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_gain.c63
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_other.c138
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_pitch_lag.c69
-rw-r--r--lib/rbcodec/codecs/libopus/silk/tables_pulses_per_block.c264
-rw-r--r--lib/rbcodec/codecs/libopus/silk/typedef.h77
62 files changed, 10378 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libopus/silk/API.h b/lib/rbcodec/codecs/libopus/silk/API.h
new file mode 100644
index 0000000000..4b8ca12ac6
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/API.h
@@ -0,0 +1,132 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_API_H
29#define SILK_API_H
30
31#include "control.h"
32#include "typedef.h"
33#include "errors.h"
34#include "entenc.h"
35#include "entdec.h"
36
37#ifdef __cplusplus
38extern "C"
39{
40#endif
41
42#define SILK_MAX_FRAMES_PER_PACKET 3
43
44/* Struct for TOC (Table of Contents) */
45typedef struct {
46 opus_int VADFlag; /* Voice activity for packet */
47 opus_int VADFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Voice activity for each frame in packet */
48 opus_int inbandFECFlag; /* Flag indicating if packet contains in-band FEC */
49} silk_TOC_struct;
50
51/****************************************/
52/* Encoder functions */
53/****************************************/
54
55/***********************************************/
56/* Get size in bytes of the Silk encoder state */
57/***********************************************/
58opus_int silk_Get_Encoder_Size( /* O Returns error code */
59 opus_int *encSizeBytes /* O Number of bytes in SILK encoder state */
60);
61
62/*************************/
63/* Init or reset encoder */
64/*************************/
65opus_int silk_InitEncoder( /* O Returns error code */
66 void *encState, /* I/O State */
67 silk_EncControlStruct *encStatus /* O Encoder Status */
68);
69
70/**************************/
71/* Encode frame with Silk */
72/**************************/
73/* Note: if prefillFlag is set, the input must contain 10 ms of audio, irrespective of what */
74/* encControl->payloadSize_ms is set to */
75opus_int silk_Encode( /* O Returns error code */
76 void *encState, /* I/O State */
77 silk_EncControlStruct *encControl, /* I Control status */
78 const opus_int16 *samplesIn, /* I Speech sample input vector */
79 opus_int nSamplesIn, /* I Number of samples in input vector */
80 ec_enc *psRangeEnc, /* I/O Compressor data structure */
81 opus_int32 *nBytesOut, /* I/O Number of bytes in payload (input: Max bytes) */
82 const opus_int prefillFlag /* I Flag to indicate prefilling buffers no coding */
83);
84
85/****************************************/
86/* Decoder functions */
87/****************************************/
88
89/***********************************************/
90/* Get size in bytes of the Silk decoder state */
91/***********************************************/
92opus_int silk_Get_Decoder_Size( /* O Returns error code */
93 opus_int *decSizeBytes /* O Number of bytes in SILK decoder state */
94);
95
96/*************************/
97/* Init or Reset decoder */
98/*************************/
99opus_int silk_InitDecoder( /* O Returns error code */
100 void *decState /* I/O State */
101);
102
103/******************/
104/* Decode a frame */
105/******************/
106opus_int silk_Decode( /* O Returns error code */
107 void* decState, /* I/O State */
108 silk_DecControlStruct* decControl, /* I/O Control Structure */
109 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
110 opus_int newPacketFlag, /* I Indicates first decoder call for this packet */
111 ec_dec *psRangeDec, /* I/O Compressor data structure */
112 opus_int16 *samplesOut, /* O Decoded output speech vector */
113 opus_int32 *nSamplesOut /* O Number of samples decoded */
114);
115
116#if 0
117/**************************************/
118/* Get table of contents for a packet */
119/**************************************/
120opus_int silk_get_TOC(
121 const opus_uint8 *payload, /* I Payload data */
122 const opus_int nBytesIn, /* I Number of input bytes */
123 const opus_int nFramesPerPayload, /* I Number of SILK frames per payload */
124 silk_TOC_struct *Silk_TOC /* O Type of content */
125);
126#endif
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/CNG.c b/lib/rbcodec/codecs/libopus/silk/CNG.c
new file mode 100644
index 0000000000..fc19391057
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/CNG.c
@@ -0,0 +1,167 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Generates excitation for CNG LPC synthesis */
35static inline void silk_CNG_exc(
36 opus_int32 residual_Q10[], /* O CNG residual signal Q10 */
37 opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */
38 opus_int32 Gain_Q16, /* I Gain to apply */
39 opus_int length, /* I Length */
40 opus_int32 *rand_seed /* I/O Seed to random index generator */
41)
42{
43 opus_int32 seed;
44 opus_int i, idx, exc_mask;
45
46 exc_mask = CNG_BUF_MASK_MAX;
47 while( exc_mask > length ) {
48 exc_mask = silk_RSHIFT( exc_mask, 1 );
49 }
50
51 seed = *rand_seed;
52 for( i = 0; i < length; i++ ) {
53 seed = silk_RAND( seed );
54 idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask );
55 silk_assert( idx >= 0 );
56 silk_assert( idx <= CNG_BUF_MASK_MAX );
57 residual_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
58 }
59 *rand_seed = seed;
60}
61
62void silk_CNG_Reset(
63 silk_decoder_state *psDec /* I/O Decoder state */
64)
65{
66 opus_int i, NLSF_step_Q15, NLSF_acc_Q15;
67
68 NLSF_step_Q15 = silk_DIV32_16( silk_int16_MAX, psDec->LPC_order + 1 );
69 NLSF_acc_Q15 = 0;
70 for( i = 0; i < psDec->LPC_order; i++ ) {
71 NLSF_acc_Q15 += NLSF_step_Q15;
72 psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15;
73 }
74 psDec->sCNG.CNG_smth_Gain_Q16 = 0;
75 psDec->sCNG.rand_seed = 3176576;
76}
77
78/* Updates CNG estimate, and applies the CNG when packet was lost */
79void silk_CNG(
80 silk_decoder_state *psDec, /* I/O Decoder state */
81 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
82 opus_int16 frame[], /* I/O Signal */
83 opus_int length /* I Length of residual */
84)
85{
86 opus_int i, subfr;
87 opus_int32 sum_Q6, max_Gain_Q16;
88 opus_int16 A_Q12[ MAX_LPC_ORDER ];
89 opus_int32 CNG_sig_Q10[ MAX_FRAME_LENGTH + MAX_LPC_ORDER ];
90 silk_CNG_struct *psCNG = &psDec->sCNG;
91
92 if( psDec->fs_kHz != psCNG->fs_kHz ) {
93 /* Reset state */
94 silk_CNG_Reset( psDec );
95
96 psCNG->fs_kHz = psDec->fs_kHz;
97 }
98 if( psDec->lossCnt == 0 && psDec->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) {
99 /* Update CNG parameters */
100
101 /* Smoothing of LSF's */
102 for( i = 0; i < psDec->LPC_order; i++ ) {
103 psCNG->CNG_smth_NLSF_Q15[ i ] += silk_SMULWB( (opus_int32)psDec->prevNLSF_Q15[ i ] - (opus_int32)psCNG->CNG_smth_NLSF_Q15[ i ], CNG_NLSF_SMTH_Q16 );
104 }
105 /* Find the subframe with the highest gain */
106 max_Gain_Q16 = 0;
107 subfr = 0;
108 for( i = 0; i < psDec->nb_subfr; i++ ) {
109 if( psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16 ) {
110 max_Gain_Q16 = psDecCtrl->Gains_Q16[ i ];
111 subfr = i;
112 }
113 }
114 /* Update CNG excitation buffer with excitation from this subframe */
115 silk_memmove( &psCNG->CNG_exc_buf_Q14[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q14, ( psDec->nb_subfr - 1 ) * psDec->subfr_length * sizeof( opus_int32 ) );
116 silk_memcpy( psCNG->CNG_exc_buf_Q14, &psDec->exc_Q14[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof( opus_int32 ) );
117
118 /* Smooth gains */
119 for( i = 0; i < psDec->nb_subfr; i++ ) {
120 psCNG->CNG_smth_Gain_Q16 += silk_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 );
121 }
122 }
123
124 /* Add CNG when packet is lost or during DTX */
125 if( psDec->lossCnt ) {
126
127 /* Generate CNG excitation */
128 silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, psCNG->CNG_smth_Gain_Q16, length, &psCNG->rand_seed );
129
130 /* Convert CNG NLSF to filter representation */
131 silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
132
133 /* Generate CNG signal, by synthesis filtering */
134 silk_memcpy( CNG_sig_Q10, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof( opus_int32 ) );
135 for( i = 0; i < length; i++ ) {
136 silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 );
137 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
138 sum_Q6 = silk_RSHIFT( psDec->LPC_order, 1 );
139 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] );
140 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] );
141 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] );
142 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] );
143 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] );
144 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] );
145 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] );
146 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] );
147 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] );
148 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] );
149 if( psDec->LPC_order == 16 ) {
150 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 11 ], A_Q12[ 10 ] );
151 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 12 ], A_Q12[ 11 ] );
152 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 13 ], A_Q12[ 12 ] );
153 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 14 ], A_Q12[ 13 ] );
154 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 15 ], A_Q12[ 14 ] );
155 sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 16 ], A_Q12[ 15 ] );
156 }
157
158 /* Update states */
159 CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX_LPC_ORDER + i ], sum_Q6, 4 );
160
161 frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( sum_Q6, 6 ) );
162 }
163 silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
164 } else {
165 silk_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof( opus_int32 ) );
166 }
167}
diff --git a/lib/rbcodec/codecs/libopus/silk/Inlines.h b/lib/rbcodec/codecs/libopus/silk/Inlines.h
new file mode 100644
index 0000000000..87ac2e20d6
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/Inlines.h
@@ -0,0 +1,188 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28/*! \file silk_Inlines.h
29 * \brief silk_Inlines.h defines inline signal processing functions.
30 */
31
32#ifndef SILK_FIX_INLINES_H
33#define SILK_FIX_INLINES_H
34
35#ifdef __cplusplus
36extern "C"
37{
38#endif
39
40/* count leading zeros of opus_int64 */
41static inline opus_int32 silk_CLZ64( opus_int64 in )
42{
43 opus_int32 in_upper;
44
45 in_upper = (opus_int32)silk_RSHIFT64(in, 32);
46 if (in_upper == 0) {
47 /* Search in the lower 32 bits */
48 return 32 + silk_CLZ32( (opus_int32) in );
49 } else {
50 /* Search in the upper 32 bits */
51 return silk_CLZ32( in_upper );
52 }
53}
54
55/* get number of leading zeros and fractional part (the bits right after the leading one */
56static inline void silk_CLZ_FRAC(
57 opus_int32 in, /* I input */
58 opus_int32 *lz, /* O number of leading zeros */
59 opus_int32 *frac_Q7 /* O the 7 bits right after the leading one */
60)
61{
62 opus_int32 lzeros = silk_CLZ32(in);
63
64 * lz = lzeros;
65 * frac_Q7 = silk_ROR32(in, 24 - lzeros) & 0x7f;
66}
67
68/* Approximation of square root */
69/* Accuracy: < +/- 10% for output values > 15 */
70/* < +/- 2.5% for output values > 120 */
71static inline opus_int32 silk_SQRT_APPROX( opus_int32 x )
72{
73 opus_int32 y, lz, frac_Q7;
74
75 if( x <= 0 ) {
76 return 0;
77 }
78
79 silk_CLZ_FRAC(x, &lz, &frac_Q7);
80
81 if( lz & 1 ) {
82 y = 32768;
83 } else {
84 y = 46214; /* 46214 = sqrt(2) * 32768 */
85 }
86
87 /* get scaling right */
88 y >>= silk_RSHIFT(lz, 1);
89
90 /* increment using fractional part of input */
91 y = silk_SMLAWB(y, y, silk_SMULBB(213, frac_Q7));
92
93 return y;
94}
95
96/* Divide two int32 values and return result as int32 in a given Q-domain */
97static inline opus_int32 silk_DIV32_varQ( /* O returns a good approximation of "(a32 << Qres) / b32" */
98 const opus_int32 a32, /* I numerator (Q0) */
99 const opus_int32 b32, /* I denominator (Q0) */
100 const opus_int Qres /* I Q-domain of result (>= 0) */
101)
102{
103 opus_int a_headrm, b_headrm, lshift;
104 opus_int32 b32_inv, a32_nrm, b32_nrm, result;
105
106 silk_assert( b32 != 0 );
107 silk_assert( Qres >= 0 );
108
109 /* Compute number of bits head room and normalize inputs */
110 a_headrm = silk_CLZ32( silk_abs(a32) ) - 1;
111 a32_nrm = silk_LSHIFT(a32, a_headrm); /* Q: a_headrm */
112 b_headrm = silk_CLZ32( silk_abs(b32) ) - 1;
113 b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */
114
115 /* Inverse of b32, with 14 bits of precision */
116 b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */
117
118 /* First approximation */
119 result = silk_SMULWB(a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */
120
121 /* Compute residual by subtracting product of denominator and first approximation */
122 /* It's OK to overflow because the final value of a32_nrm should always be small */
123 a32_nrm = silk_SUB32_ovflw(a32_nrm, silk_LSHIFT_ovflw( silk_SMMUL(b32_nrm, result), 3 )); /* Q: a_headrm */
124
125 /* Refinement */
126 result = silk_SMLAWB(result, a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */
127
128 /* Convert to Qres domain */
129 lshift = 29 + a_headrm - b_headrm - Qres;
130 if( lshift < 0 ) {
131 return silk_LSHIFT_SAT32(result, -lshift);
132 } else {
133 if( lshift < 32){
134 return silk_RSHIFT(result, lshift);
135 } else {
136 /* Avoid undefined result */
137 return 0;
138 }
139 }
140}
141
142/* Invert int32 value and return result as int32 in a given Q-domain */
143static inline opus_int32 silk_INVERSE32_varQ( /* O returns a good approximation of "(1 << Qres) / b32" */
144 const opus_int32 b32, /* I denominator (Q0) */
145 const opus_int Qres /* I Q-domain of result (> 0) */
146)
147{
148 opus_int b_headrm, lshift;
149 opus_int32 b32_inv, b32_nrm, err_Q32, result;
150
151 silk_assert( b32 != 0 );
152 silk_assert( Qres > 0 );
153
154 /* Compute number of bits head room and normalize input */
155 b_headrm = silk_CLZ32( silk_abs(b32) ) - 1;
156 b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */
157
158 /* Inverse of b32, with 14 bits of precision */
159 b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */
160
161 /* First approximation */
162 result = silk_LSHIFT(b32_inv, 16); /* Q: 61 - b_headrm */
163
164 /* Compute residual by subtracting product of denominator and first approximation from one */
165 err_Q32 = silk_LSHIFT( ((opus_int32)1<<29) - silk_SMULWB(b32_nrm, b32_inv), 3 ); /* Q32 */
166
167 /* Refinement */
168 result = silk_SMLAWW(result, err_Q32, b32_inv); /* Q: 61 - b_headrm */
169
170 /* Convert to Qres domain */
171 lshift = 61 - b_headrm - Qres;
172 if( lshift <= 0 ) {
173 return silk_LSHIFT_SAT32(result, -lshift);
174 } else {
175 if( lshift < 32){
176 return silk_RSHIFT(result, lshift);
177 }else{
178 /* Avoid undefined result */
179 return 0;
180 }
181 }
182}
183
184#ifdef __cplusplus
185}
186#endif
187
188#endif /* SILK_FIX_INLINES_H */
diff --git a/lib/rbcodec/codecs/libopus/silk/LPC_analysis_filter.c b/lib/rbcodec/codecs/libopus/silk/LPC_analysis_filter.c
new file mode 100644
index 0000000000..7d4458a637
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/LPC_analysis_filter.c
@@ -0,0 +1,85 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34/*******************************************/
35/* LPC analysis filter */
36/* NB! State is kept internally and the */
37/* filter always starts with zero state */
38/* first d output samples are set to zero */
39/*******************************************/
40
41void silk_LPC_analysis_filter(
42 opus_int16 *out, /* O Output signal */
43 const opus_int16 *in, /* I Input signal */
44 const opus_int16 *B, /* I MA prediction coefficients, Q12 [order] */
45 const opus_int32 len, /* I Signal length */
46 const opus_int32 d /* I Filter order */
47)
48{
49 opus_int ix, j;
50 opus_int32 out32_Q12, out32;
51 const opus_int16 *in_ptr;
52
53 silk_assert( d >= 6 );
54 silk_assert( (d & 1) == 0 );
55 silk_assert( d <= len );
56
57 for( ix = d; ix < len; ix++ ) {
58 in_ptr = &in[ ix - 1 ];
59
60 out32_Q12 = silk_SMULBB( in_ptr[ 0 ], B[ 0 ] );
61 /* Allowing wrap around so that two wraps can cancel each other. The rare
62 cases where the result wraps around can only be triggered by invalid streams*/
63 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -1 ], B[ 1 ] );
64 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -2 ], B[ 2 ] );
65 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -3 ], B[ 3 ] );
66 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -4 ], B[ 4 ] );
67 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -5 ], B[ 5 ] );
68 for( j = 6; j < d; j += 2 ) {
69 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -j ], B[ j ] );
70 out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -j - 1 ], B[ j + 1 ] );
71 }
72
73 /* Subtract prediction */
74 out32_Q12 = silk_SUB32_ovflw( silk_LSHIFT( (opus_int32)in_ptr[ 1 ], 12 ), out32_Q12 );
75
76 /* Scale to Q0 */
77 out32 = silk_RSHIFT_ROUND( out32_Q12, 12 );
78
79 /* Saturate output */
80 out[ ix ] = (opus_int16)silk_SAT16( out32 );
81 }
82
83 /* Set first d output samples to zero */
84 silk_memset( out, 0, d * sizeof( opus_int16 ) );
85}
diff --git a/lib/rbcodec/codecs/libopus/silk/LPC_inv_pred_gain.c b/lib/rbcodec/codecs/libopus/silk/LPC_inv_pred_gain.c
new file mode 100644
index 0000000000..afbb48ae1d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/LPC_inv_pred_gain.c
@@ -0,0 +1,154 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34#define QA 24
35#define A_LIMIT SILK_FIX_CONST( 0.99975, QA )
36
37#define MUL32_FRAC_Q(a32, b32, Q) ((opus_int32)(silk_RSHIFT_ROUND64(silk_SMULL(a32, b32), Q)))
38
39/* Compute inverse of LPC prediction gain, and */
40/* test if LPC coefficients are stable (all poles within unit circle) */
41static opus_int32 LPC_inverse_pred_gain_QA( /* O Returns inverse prediction gain in energy domain, Q30 */
42 opus_int32 A_QA[ 2 ][ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */
43 const opus_int order /* I Prediction order */
44)
45{
46 opus_int k, n, mult2Q;
47 opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp_QA;
48 opus_int32 *Aold_QA, *Anew_QA;
49
50 Anew_QA = A_QA[ order & 1 ];
51
52 invGain_Q30 = (opus_int32)1 << 30;
53 for( k = order - 1; k > 0; k-- ) {
54 /* Check for stability */
55 if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {
56 return 0;
57 }
58
59 /* Set RC equal to negated AR coef */
60 rc_Q31 = -silk_LSHIFT( Anew_QA[ k ], 31 - QA );
61
62 /* rc_mult1_Q30 range: [ 1 : 2^30 ] */
63 rc_mult1_Q30 = ( (opus_int32)1 << 30 ) - silk_SMMUL( rc_Q31, rc_Q31 );
64 silk_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */
65 silk_assert( rc_mult1_Q30 <= ( 1 << 30 ) );
66
67 /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */
68 mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) );
69 rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 );
70
71 /* Update inverse gain */
72 /* invGain_Q30 range: [ 0 : 2^30 ] */
73 invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 );
74 silk_assert( invGain_Q30 >= 0 );
75 silk_assert( invGain_Q30 <= ( 1 << 30 ) );
76
77 /* Swap pointers */
78 Aold_QA = Anew_QA;
79 Anew_QA = A_QA[ k & 1 ];
80
81 /* Update AR coefficient */
82 for( n = 0; n < k; n++ ) {
83 tmp_QA = Aold_QA[ n ] - MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 );
84 Anew_QA[ n ] = MUL32_FRAC_Q( tmp_QA, rc_mult2 , mult2Q );
85 }
86 }
87
88 /* Check for stability */
89 if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {
90 return 0;
91 }
92
93 /* Set RC equal to negated AR coef */
94 rc_Q31 = -silk_LSHIFT( Anew_QA[ 0 ], 31 - QA );
95
96 /* Range: [ 1 : 2^30 ] */
97 rc_mult1_Q30 = ( (opus_int32)1 << 30 ) - silk_SMMUL( rc_Q31, rc_Q31 );
98
99 /* Update inverse gain */
100 /* Range: [ 0 : 2^30 ] */
101 invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 );
102 silk_assert( invGain_Q30 >= 0 );
103 silk_assert( invGain_Q30 <= 1<<30 );
104
105 return invGain_Q30;
106}
107
108/* For input in Q12 domain */
109opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse prediction gain in energy domain, Q30 */
110 const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */
111 const opus_int order /* I Prediction order */
112)
113{
114 opus_int k;
115 opus_int32 Atmp_QA[ 2 ][ SILK_MAX_ORDER_LPC ];
116 opus_int32 *Anew_QA;
117 opus_int32 DC_resp = 0;
118
119 Anew_QA = Atmp_QA[ order & 1 ];
120
121 /* Increase Q domain of the AR coefficients */
122 for( k = 0; k < order; k++ ) {
123 DC_resp += (opus_int32)A_Q12[ k ];
124 Anew_QA[ k ] = silk_LSHIFT32( (opus_int32)A_Q12[ k ], QA - 12 );
125 }
126 /* If the DC is unstable, we don't even need to do the full calculations */
127 if( DC_resp >= 4096 ) {
128 return 0;
129 }
130 return LPC_inverse_pred_gain_QA( Atmp_QA, order );
131}
132
133#ifdef FIXED_POINT
134
135/* For input in Q24 domain */
136opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse prediction gain in energy domain, Q30 */
137 const opus_int32 *A_Q24, /* I Prediction coefficients [order] */
138 const opus_int order /* I Prediction order */
139)
140{
141 opus_int k;
142 opus_int32 Atmp_QA[ 2 ][ SILK_MAX_ORDER_LPC ];
143 opus_int32 *Anew_QA;
144
145 Anew_QA = Atmp_QA[ order & 1 ];
146
147 /* Increase Q domain of the AR coefficients */
148 for( k = 0; k < order; k++ ) {
149 Anew_QA[ k ] = silk_RSHIFT32( A_Q24[ k ], 24 - QA );
150 }
151
152 return LPC_inverse_pred_gain_QA( Atmp_QA, order );
153}
154#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/MacroCount.h b/lib/rbcodec/codecs/libopus/silk/MacroCount.h
new file mode 100644
index 0000000000..2829e8ccb4
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/MacroCount.h
@@ -0,0 +1,718 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SIGPROCFIX_API_MACROCOUNT_H
29#define SIGPROCFIX_API_MACROCOUNT_H
30#include <stdio.h>
31
32#ifdef silk_MACRO_COUNT
33#define varDefine opus_int64 ops_count = 0;
34
35extern opus_int64 ops_count;
36
37static inline opus_int64 silk_SaveCount(){
38 return(ops_count);
39}
40
41static inline opus_int64 silk_SaveResetCount(){
42 opus_int64 ret;
43
44 ret = ops_count;
45 ops_count = 0;
46 return(ret);
47}
48
49static inline silk_PrintCount(){
50 printf("ops_count = %d \n ", (opus_int32)ops_count);
51}
52
53#undef silk_MUL
54static inline opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
55 opus_int32 ret;
56 ops_count += 4;
57 ret = a32 * b32;
58 return ret;
59}
60
61#undef silk_MUL_uint
62static inline opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
63 opus_uint32 ret;
64 ops_count += 4;
65 ret = a32 * b32;
66 return ret;
67}
68#undef silk_MLA
69static inline opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
70 opus_int32 ret;
71 ops_count += 4;
72 ret = a32 + b32 * c32;
73 return ret;
74}
75
76#undef silk_MLA_uint
77static inline opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
78 opus_uint32 ret;
79 ops_count += 4;
80 ret = a32 + b32 * c32;
81 return ret;
82}
83
84#undef silk_SMULWB
85static inline opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
86 opus_int32 ret;
87 ops_count += 5;
88 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
89 return ret;
90}
91#undef silk_SMLAWB
92static inline opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
93 opus_int32 ret;
94 ops_count += 5;
95 ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)));
96 return ret;
97}
98
99#undef silk_SMULWT
100static inline opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
101 opus_int32 ret;
102 ops_count += 4;
103 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
104 return ret;
105}
106#undef silk_SMLAWT
107static inline opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
108 opus_int32 ret;
109 ops_count += 4;
110 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
111 return ret;
112}
113
114#undef silk_SMULBB
115static inline opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
116 opus_int32 ret;
117 ops_count += 1;
118 ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32);
119 return ret;
120}
121#undef silk_SMLABB
122static inline opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
123 opus_int32 ret;
124 ops_count += 1;
125 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
126 return ret;
127}
128
129#undef silk_SMULBT
130static inline opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
131 opus_int32 ret;
132 ops_count += 4;
133 ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16);
134 return ret;
135}
136
137#undef silk_SMLABT
138static inline opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
139 opus_int32 ret;
140 ops_count += 1;
141 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
142 return ret;
143}
144
145#undef silk_SMULTT
146static inline opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
147 opus_int32 ret;
148 ops_count += 1;
149 ret = (a32 >> 16) * (b32 >> 16);
150 return ret;
151}
152
153#undef silk_SMLATT
154static inline opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
155 opus_int32 ret;
156 ops_count += 1;
157 ret = a32 + (b32 >> 16) * (c32 >> 16);
158 return ret;
159}
160
161
162/* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/
163#undef silk_MLA_ovflw
164#define silk_MLA_ovflw silk_MLA
165
166#undef silk_SMLABB_ovflw
167#define silk_SMLABB_ovflw silk_SMLABB
168
169#undef silk_SMLABT_ovflw
170#define silk_SMLABT_ovflw silk_SMLABT
171
172#undef silk_SMLATT_ovflw
173#define silk_SMLATT_ovflw silk_SMLATT
174
175#undef silk_SMLAWB_ovflw
176#define silk_SMLAWB_ovflw silk_SMLAWB
177
178#undef silk_SMLAWT_ovflw
179#define silk_SMLAWT_ovflw silk_SMLAWT
180
181#undef silk_SMULL
182static inline opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
183 opus_int64 ret;
184 ops_count += 8;
185 ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32));
186 return ret;
187}
188
189#undef silk_SMLAL
190static inline opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
191 opus_int64 ret;
192 ops_count += 8;
193 ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32));
194 return ret;
195}
196#undef silk_SMLALBB
197static inline opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
198 opus_int64 ret;
199 ops_count += 4;
200 ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16));
201 return ret;
202}
203
204#undef SigProcFIX_CLZ16
205static inline opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
206{
207 opus_int32 out32 = 0;
208 ops_count += 10;
209 if( in16 == 0 ) {
210 return 16;
211 }
212 /* test nibbles */
213 if( in16 & 0xFF00 ) {
214 if( in16 & 0xF000 ) {
215 in16 >>= 12;
216 } else {
217 out32 += 4;
218 in16 >>= 8;
219 }
220 } else {
221 if( in16 & 0xFFF0 ) {
222 out32 += 8;
223 in16 >>= 4;
224 } else {
225 out32 += 12;
226 }
227 }
228 /* test bits and return */
229 if( in16 & 0xC ) {
230 if( in16 & 0x8 )
231 return out32 + 0;
232 else
233 return out32 + 1;
234 } else {
235 if( in16 & 0xE )
236 return out32 + 2;
237 else
238 return out32 + 3;
239 }
240}
241
242#undef SigProcFIX_CLZ32
243static inline opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
244{
245 /* test highest 16 bits and convert to opus_int16 */
246 ops_count += 2;
247 if( in32 & 0xFFFF0000 ) {
248 return SigProcFIX_CLZ16((opus_int16)(in32 >> 16));
249 } else {
250 return SigProcFIX_CLZ16((opus_int16)in32) + 16;
251 }
252}
253
254#undef silk_DIV32
255static inline opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
256 ops_count += 64;
257 return a32 / b32;
258}
259
260#undef silk_DIV32_16
261static inline opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
262 ops_count += 32;
263 return a32 / b32;
264}
265
266#undef silk_SAT8
267static inline opus_int8 silk_SAT8(opus_int64 a){
268 opus_int8 tmp;
269 ops_count += 1;
270 tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \
271 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)));
272 return(tmp);
273}
274
275#undef silk_SAT16
276static inline opus_int16 silk_SAT16(opus_int64 a){
277 opus_int16 tmp;
278 ops_count += 1;
279 tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \
280 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)));
281 return(tmp);
282}
283#undef silk_SAT32
284static inline opus_int32 silk_SAT32(opus_int64 a){
285 opus_int32 tmp;
286 ops_count += 1;
287 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \
288 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)));
289 return(tmp);
290}
291#undef silk_POS_SAT32
292static inline opus_int32 silk_POS_SAT32(opus_int64 a){
293 opus_int32 tmp;
294 ops_count += 1;
295 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a));
296 return(tmp);
297}
298
299#undef silk_ADD_POS_SAT8
300static inline opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
301 opus_int8 tmp;
302 ops_count += 1;
303 tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)));
304 return(tmp);
305}
306#undef silk_ADD_POS_SAT16
307static inline opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
308 opus_int16 tmp;
309 ops_count += 1;
310 tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)));
311 return(tmp);
312}
313
314#undef silk_ADD_POS_SAT32
315static inline opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
316 opus_int32 tmp;
317 ops_count += 1;
318 tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)));
319 return(tmp);
320}
321
322#undef silk_ADD_POS_SAT64
323static inline opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){
324 opus_int64 tmp;
325 ops_count += 1;
326 tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)));
327 return(tmp);
328}
329
330#undef silk_LSHIFT8
331static inline opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
332 opus_int8 ret;
333 ops_count += 1;
334 ret = a << shift;
335 return ret;
336}
337#undef silk_LSHIFT16
338static inline opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
339 opus_int16 ret;
340 ops_count += 1;
341 ret = a << shift;
342 return ret;
343}
344#undef silk_LSHIFT32
345static inline opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
346 opus_int32 ret;
347 ops_count += 1;
348 ret = a << shift;
349 return ret;
350}
351#undef silk_LSHIFT64
352static inline opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
353 ops_count += 1;
354 return a << shift;
355}
356
357#undef silk_LSHIFT_ovflw
358static inline opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
359 ops_count += 1;
360 return a << shift;
361}
362
363#undef silk_LSHIFT_uint
364static inline opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
365 opus_uint32 ret;
366 ops_count += 1;
367 ret = a << shift;
368 return ret;
369}
370
371#undef silk_RSHIFT8
372static inline opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
373 ops_count += 1;
374 return a >> shift;
375}
376#undef silk_RSHIFT16
377static inline opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
378 ops_count += 1;
379 return a >> shift;
380}
381#undef silk_RSHIFT32
382static inline opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
383 ops_count += 1;
384 return a >> shift;
385}
386#undef silk_RSHIFT64
387static inline opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
388 ops_count += 1;
389 return a >> shift;
390}
391
392#undef silk_RSHIFT_uint
393static inline opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
394 ops_count += 1;
395 return a >> shift;
396}
397
398#undef silk_ADD_LSHIFT
399static inline opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
400 opus_int32 ret;
401 ops_count += 1;
402 ret = a + (b << shift);
403 return ret; /* shift >= 0*/
404}
405#undef silk_ADD_LSHIFT32
406static inline opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
407 opus_int32 ret;
408 ops_count += 1;
409 ret = a + (b << shift);
410 return ret; /* shift >= 0*/
411}
412#undef silk_ADD_LSHIFT_uint
413static inline opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
414 opus_uint32 ret;
415 ops_count += 1;
416 ret = a + (b << shift);
417 return ret; /* shift >= 0*/
418}
419#undef silk_ADD_RSHIFT
420static inline opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
421 opus_int32 ret;
422 ops_count += 1;
423 ret = a + (b >> shift);
424 return ret; /* shift > 0*/
425}
426#undef silk_ADD_RSHIFT32
427static inline opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
428 opus_int32 ret;
429 ops_count += 1;
430 ret = a + (b >> shift);
431 return ret; /* shift > 0*/
432}
433#undef silk_ADD_RSHIFT_uint
434static inline opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
435 opus_uint32 ret;
436 ops_count += 1;
437 ret = a + (b >> shift);
438 return ret; /* shift > 0*/
439}
440#undef silk_SUB_LSHIFT32
441static inline opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
442 opus_int32 ret;
443 ops_count += 1;
444 ret = a - (b << shift);
445 return ret; /* shift >= 0*/
446}
447#undef silk_SUB_RSHIFT32
448static inline opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
449 opus_int32 ret;
450 ops_count += 1;
451 ret = a - (b >> shift);
452 return ret; /* shift > 0*/
453}
454
455#undef silk_RSHIFT_ROUND
456static inline opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
457 opus_int32 ret;
458 ops_count += 3;
459 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
460 return ret;
461}
462
463#undef silk_RSHIFT_ROUND64
464static inline opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
465 opus_int64 ret;
466 ops_count += 6;
467 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
468 return ret;
469}
470
471#undef silk_abs_int64
472static inline opus_int64 silk_abs_int64(opus_int64 a){
473 ops_count += 1;
474 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
475}
476
477#undef silk_abs_int32
478static inline opus_int32 silk_abs_int32(opus_int32 a){
479 ops_count += 1;
480 return silk_abs(a);
481}
482
483
484#undef silk_min
485static silk_min(a, b){
486 ops_count += 1;
487 return (((a) < (b)) ? (a) : (b));
488}
489#undef silk_max
490static silk_max(a, b){
491 ops_count += 1;
492 return (((a) > (b)) ? (a) : (b));
493}
494#undef silk_sign
495static silk_sign(a){
496 ops_count += 1;
497 return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
498}
499
500#undef silk_ADD16
501static inline opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
502 opus_int16 ret;
503 ops_count += 1;
504 ret = a + b;
505 return ret;
506}
507
508#undef silk_ADD32
509static inline opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
510 opus_int32 ret;
511 ops_count += 1;
512 ret = a + b;
513 return ret;
514}
515
516#undef silk_ADD64
517static inline opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
518 opus_int64 ret;
519 ops_count += 2;
520 ret = a + b;
521 return ret;
522}
523
524#undef silk_SUB16
525static inline opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
526 opus_int16 ret;
527 ops_count += 1;
528 ret = a - b;
529 return ret;
530}
531
532#undef silk_SUB32
533static inline opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
534 opus_int32 ret;
535 ops_count += 1;
536 ret = a - b;
537 return ret;
538}
539
540#undef silk_SUB64
541static inline opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
542 opus_int64 ret;
543 ops_count += 2;
544 ret = a - b;
545 return ret;
546}
547
548#undef silk_ADD_SAT16
549static inline opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
550 opus_int16 res;
551 /* Nb will be counted in AKP_add32 and silk_SAT16*/
552 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
553 return res;
554}
555
556#undef silk_ADD_SAT32
557static inline opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
558 opus_int32 res;
559 ops_count += 1;
560 res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
561 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
562 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
563 return res;
564}
565
566#undef silk_ADD_SAT64
567static inline opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
568 opus_int64 res;
569 ops_count += 1;
570 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
571 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
572 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
573 return res;
574}
575
576#undef silk_SUB_SAT16
577static inline opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
578 opus_int16 res;
579 silk_assert(0);
580 /* Nb will be counted in sub-macros*/
581 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
582 return res;
583}
584
585#undef silk_SUB_SAT32
586static inline opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
587 opus_int32 res;
588 ops_count += 1;
589 res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
590 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
591 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
592 return res;
593}
594
595#undef silk_SUB_SAT64
596static inline opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
597 opus_int64 res;
598 ops_count += 1;
599 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
600 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
601 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
602
603 return res;
604}
605
606#undef silk_SMULWW
607static inline opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
608 opus_int32 ret;
609 /* Nb will be counted in sub-macros*/
610 ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
611 return ret;
612}
613
614#undef silk_SMLAWW
615static inline opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
616 opus_int32 ret;
617 /* Nb will be counted in sub-macros*/
618 ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
619 return ret;
620}
621
622#undef silk_min_int
623static inline opus_int silk_min_int(opus_int a, opus_int b)
624{
625 ops_count += 1;
626 return (((a) < (b)) ? (a) : (b));
627}
628
629#undef silk_min_16
630static inline opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
631{
632 ops_count += 1;
633 return (((a) < (b)) ? (a) : (b));
634}
635#undef silk_min_32
636static inline opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
637{
638 ops_count += 1;
639 return (((a) < (b)) ? (a) : (b));
640}
641#undef silk_min_64
642static inline opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
643{
644 ops_count += 1;
645 return (((a) < (b)) ? (a) : (b));
646}
647
648/* silk_min() versions with typecast in the function call */
649#undef silk_max_int
650static inline opus_int silk_max_int(opus_int a, opus_int b)
651{
652 ops_count += 1;
653 return (((a) > (b)) ? (a) : (b));
654}
655#undef silk_max_16
656static inline opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
657{
658 ops_count += 1;
659 return (((a) > (b)) ? (a) : (b));
660}
661#undef silk_max_32
662static inline opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
663{
664 ops_count += 1;
665 return (((a) > (b)) ? (a) : (b));
666}
667
668#undef silk_max_64
669static inline opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
670{
671 ops_count += 1;
672 return (((a) > (b)) ? (a) : (b));
673}
674
675
676#undef silk_LIMIT_int
677static inline opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
678{
679 opus_int ret;
680 ops_count += 6;
681
682 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
683 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
684
685 return(ret);
686}
687
688#undef silk_LIMIT_16
689static inline opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
690{
691 opus_int16 ret;
692 ops_count += 6;
693
694 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
695 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
696
697return(ret);
698}
699
700
701#undef silk_LIMIT_32
702static inline opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
703{
704 opus_int32 ret;
705 ops_count += 6;
706
707 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
708 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
709 return(ret);
710}
711
712#else
713#define varDefine
714#define silk_SaveCount()
715
716#endif
717#endif
718
diff --git a/lib/rbcodec/codecs/libopus/silk/MacroDebug.h b/lib/rbcodec/codecs/libopus/silk/MacroDebug.h
new file mode 100644
index 0000000000..ecd90bc4de
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/MacroDebug.h
@@ -0,0 +1,952 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Copyright (C) 2012 Xiph.Org Foundation
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions
6are met:
7- Redistributions of source code must retain the above copyright notice,
8this list of conditions and the following disclaimer.
9- Redistributions in binary form must reproduce the above copyright
10notice, this list of conditions and the following disclaimer in the
11documentation and/or other materials provided with the distribution.
12- Neither the name of Internet Society, IETF or IETF Trust, nor the
13names of specific contributors, may be used to endorse or promote
14products derived from this software without specific prior written
15permission.
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26POSSIBILITY OF SUCH DAMAGE.
27***********************************************************************/
28
29#ifndef MACRO_DEBUG_H
30#define MACRO_DEBUG_H
31
32/* Redefine macro functions with extensive assertion in DEBUG mode.
33 As functions can't be undefined, this file can't work with SigProcFIX_MacroCount.h */
34
35#if ( defined (FIXED_DEBUG) || ( 0 && defined (_DEBUG) ) ) && !defined (silk_MACRO_COUNT)
36
37#undef silk_ADD16
38#define silk_ADD16(a,b) silk_ADD16_((a), (b), __FILE__, __LINE__)
39static inline opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file, int line){
40 opus_int16 ret;
41
42 ret = a + b;
43 if ( ret != silk_ADD_SAT16( a, b ) )
44 {
45 fprintf (stderr, "silk_ADD16(%d, %d) in %s: line %d\n", a, b, file, line);
46#ifdef FIXED_DEBUG_ASSERT
47 silk_assert( 0 );
48#endif
49 }
50 return ret;
51}
52
53#undef silk_ADD32
54#define silk_ADD32(a,b) silk_ADD32_((a), (b), __FILE__, __LINE__)
55static inline opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line){
56 opus_int32 ret;
57
58 ret = a + b;
59 if ( ret != silk_ADD_SAT32( a, b ) )
60 {
61 fprintf (stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line);
62#ifdef FIXED_DEBUG_ASSERT
63 silk_assert( 0 );
64#endif
65 }
66 return ret;
67}
68
69#undef silk_ADD64
70#define silk_ADD64(a,b) silk_ADD64_((a), (b), __FILE__, __LINE__)
71static inline opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file, int line){
72 opus_int64 ret;
73
74 ret = a + b;
75 if ( ret != silk_ADD_SAT64( a, b ) )
76 {
77 fprintf (stderr, "silk_ADD64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
78#ifdef FIXED_DEBUG_ASSERT
79 silk_assert( 0 );
80#endif
81 }
82 return ret;
83}
84
85#undef silk_SUB16
86#define silk_SUB16(a,b) silk_SUB16_((a), (b), __FILE__, __LINE__)
87static inline opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file, int line){
88 opus_int16 ret;
89
90 ret = a - b;
91 if ( ret != silk_SUB_SAT16( a, b ) )
92 {
93 fprintf (stderr, "silk_SUB16(%d, %d) in %s: line %d\n", a, b, file, line);
94#ifdef FIXED_DEBUG_ASSERT
95 silk_assert( 0 );
96#endif
97 }
98 return ret;
99}
100
101#undef silk_SUB32
102#define silk_SUB32(a,b) silk_SUB32_((a), (b), __FILE__, __LINE__)
103static inline opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file, int line){
104 opus_int32 ret;
105
106 ret = a - b;
107 if ( ret != silk_SUB_SAT32( a, b ) )
108 {
109 fprintf (stderr, "silk_SUB32(%d, %d) in %s: line %d\n", a, b, file, line);
110#ifdef FIXED_DEBUG_ASSERT
111 silk_assert( 0 );
112#endif
113 }
114 return ret;
115}
116
117#undef silk_SUB64
118#define silk_SUB64(a,b) silk_SUB64_((a), (b), __FILE__, __LINE__)
119static inline opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file, int line){
120 opus_int64 ret;
121
122 ret = a - b;
123 if ( ret != silk_SUB_SAT64( a, b ) )
124 {
125 fprintf (stderr, "silk_SUB64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
126#ifdef FIXED_DEBUG_ASSERT
127 silk_assert( 0 );
128#endif
129 }
130 return ret;
131}
132
133#undef silk_ADD_SAT16
134#define silk_ADD_SAT16(a,b) silk_ADD_SAT16_((a), (b), __FILE__, __LINE__)
135static inline opus_int16 silk_ADD_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line) {
136 opus_int16 res;
137 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
138 if ( res != silk_SAT16( (opus_int32)a16 + (opus_int32)b16 ) )
139 {
140 fprintf (stderr, "silk_ADD_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
141#ifdef FIXED_DEBUG_ASSERT
142 silk_assert( 0 );
143#endif
144 }
145 return res;
146}
147
148#undef silk_ADD_SAT32
149#define silk_ADD_SAT32(a,b) silk_ADD_SAT32_((a), (b), __FILE__, __LINE__)
150static inline opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line){
151 opus_int32 res;
152 res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \
153 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
154 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
155 if ( res != silk_SAT32( (opus_int64)a32 + (opus_int64)b32 ) )
156 {
157 fprintf (stderr, "silk_ADD_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
158#ifdef FIXED_DEBUG_ASSERT
159 silk_assert( 0 );
160#endif
161 }
162 return res;
163}
164
165#undef silk_ADD_SAT64
166#define silk_ADD_SAT64(a,b) silk_ADD_SAT64_((a), (b), __FILE__, __LINE__)
167static inline opus_int64 silk_ADD_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line) {
168 opus_int64 res;
169 int fail = 0;
170 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
171 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
172 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
173 if( res != a64 + b64 ) {
174 /* Check that we saturated to the correct extreme value */
175 if ( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
176 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ) )
177 {
178 fail = 1;
179 }
180 } else {
181 /* Saturation not necessary */
182 fail = res != a64 + b64;
183 }
184 if ( fail )
185 {
186 fprintf (stderr, "silk_ADD_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
187#ifdef FIXED_DEBUG_ASSERT
188 silk_assert( 0 );
189#endif
190 }
191 return res;
192}
193
194#undef silk_SUB_SAT16
195#define silk_SUB_SAT16(a,b) silk_SUB_SAT16_((a), (b), __FILE__, __LINE__)
196static inline opus_int16 silk_SUB_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line ) {
197 opus_int16 res;
198 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
199 if ( res != silk_SAT16( (opus_int32)a16 - (opus_int32)b16 ) )
200 {
201 fprintf (stderr, "silk_SUB_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
202#ifdef FIXED_DEBUG_ASSERT
203 silk_assert( 0 );
204#endif
205 }
206 return res;
207}
208
209#undef silk_SUB_SAT32
210#define silk_SUB_SAT32(a,b) silk_SUB_SAT32_((a), (b), __FILE__, __LINE__)
211static inline opus_int32 silk_SUB_SAT32_( opus_int32 a32, opus_int32 b32, char *file, int line ) {
212 opus_int32 res;
213 res = ((((opus_uint32)(a32)-(opus_uint32)(b32)) & 0x80000000) == 0 ? \
214 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
215 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
216 if ( res != silk_SAT32( (opus_int64)a32 - (opus_int64)b32 ) )
217 {
218 fprintf (stderr, "silk_SUB_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
219#ifdef FIXED_DEBUG_ASSERT
220 silk_assert( 0 );
221#endif
222 }
223 return res;
224}
225
226#undef silk_SUB_SAT64
227#define silk_SUB_SAT64(a,b) silk_SUB_SAT64_((a), (b), __FILE__, __LINE__)
228static inline opus_int64 silk_SUB_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line ) {
229 opus_int64 res;
230 int fail = 0;
231 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
232 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
233 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
234 if( res != a64 - b64 ) {
235 /* Check that we saturated to the correct extreme value */
236 if( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
237 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ))
238 {
239 fail = 1;
240 }
241 } else {
242 /* Saturation not necessary */
243 fail = res != a64 - b64;
244 }
245 if ( fail )
246 {
247 fprintf (stderr, "silk_SUB_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
248#ifdef FIXED_DEBUG_ASSERT
249 silk_assert( 0 );
250#endif
251 }
252 return res;
253}
254
255#undef silk_MUL
256#define silk_MUL(a,b) silk_MUL_((a), (b), __FILE__, __LINE__)
257static inline opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line){
258 opus_int32 ret;
259 opus_int64 ret64;
260 ret = a32 * b32;
261 ret64 = (opus_int64)a32 * (opus_int64)b32;
262 if ( (opus_int64)ret != ret64 )
263 {
264 fprintf (stderr, "silk_MUL(%d, %d) in %s: line %d\n", a32, b32, file, line);
265#ifdef FIXED_DEBUG_ASSERT
266 silk_assert( 0 );
267#endif
268 }
269 return ret;
270}
271
272#undef silk_MUL_uint
273#define silk_MUL_uint(a,b) silk_MUL_uint_((a), (b), __FILE__, __LINE__)
274static inline opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, char *file, int line){
275 opus_uint32 ret;
276 ret = a32 * b32;
277 if ( (opus_uint64)ret != (opus_uint64)a32 * (opus_uint64)b32 )
278 {
279 fprintf (stderr, "silk_MUL_uint(%u, %u) in %s: line %d\n", a32, b32, file, line);
280#ifdef FIXED_DEBUG_ASSERT
281 silk_assert( 0 );
282#endif
283 }
284 return ret;
285}
286
287#undef silk_MLA
288#define silk_MLA(a,b,c) silk_MLA_((a), (b), (c), __FILE__, __LINE__)
289static inline opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
290 opus_int32 ret;
291 ret = a32 + b32 * c32;
292 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
293 {
294 fprintf (stderr, "silk_MLA(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
295#ifdef FIXED_DEBUG_ASSERT
296 silk_assert( 0 );
297#endif
298 }
299 return ret;
300}
301
302#undef silk_MLA_uint
303#define silk_MLA_uint(a,b,c) silk_MLA_uint_((a), (b), (c), __FILE__, __LINE__)
304static inline opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32, char *file, int line){
305 opus_uint32 ret;
306 ret = a32 + b32 * c32;
307 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
308 {
309 fprintf (stderr, "silk_MLA_uint(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
310#ifdef FIXED_DEBUG_ASSERT
311 silk_assert( 0 );
312#endif
313 }
314 return ret;
315}
316
317#undef silk_SMULWB
318#define silk_SMULWB(a,b) silk_SMULWB_((a), (b), __FILE__, __LINE__)
319static inline opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char *file, int line){
320 opus_int32 ret;
321 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
322 if ( (opus_int64)ret != ((opus_int64)a32 * (opus_int16)b32) >> 16 )
323 {
324 fprintf (stderr, "silk_SMULWB(%d, %d) in %s: line %d\n", a32, b32, file, line);
325#ifdef FIXED_DEBUG_ASSERT
326 silk_assert( 0 );
327#endif
328 }
329 return ret;
330}
331
332#undef silk_SMLAWB
333#define silk_SMLAWB(a,b,c) silk_SMLAWB_((a), (b), (c), __FILE__, __LINE__)
334static inline opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
335 opus_int32 ret;
336 ret = silk_ADD32( a32, silk_SMULWB( b32, c32 ) );
337 if ( silk_ADD32( a32, silk_SMULWB( b32, c32 ) ) != silk_ADD_SAT32( a32, silk_SMULWB( b32, c32 ) ) )
338 {
339 fprintf (stderr, "silk_SMLAWB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
340#ifdef FIXED_DEBUG_ASSERT
341 silk_assert( 0 );
342#endif
343 }
344 return ret;
345}
346
347#undef silk_SMULWT
348#define silk_SMULWT(a,b) silk_SMULWT_((a), (b), __FILE__, __LINE__)
349static inline opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char *file, int line){
350 opus_int32 ret;
351 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
352 if ( (opus_int64)ret != ((opus_int64)a32 * (b32 >> 16)) >> 16 )
353 {
354 fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line);
355#ifdef FIXED_DEBUG_ASSERT
356 silk_assert( 0 );
357#endif
358 }
359 return ret;
360}
361
362#undef silk_SMLAWT
363#define silk_SMLAWT(a,b,c) silk_SMLAWT_((a), (b), (c), __FILE__, __LINE__)
364static inline opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
365 opus_int32 ret;
366 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
367 if ( (opus_int64)ret != (opus_int64)a32 + (((opus_int64)b32 * (c32 >> 16)) >> 16) )
368 {
369 fprintf (stderr, "silk_SMLAWT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
370#ifdef FIXED_DEBUG_ASSERT
371 silk_assert( 0 );
372#endif
373 }
374 return ret;
375}
376
377#undef silk_SMULL
378#define silk_SMULL(a,b) silk_SMULL_((a), (b), __FILE__, __LINE__)
379static inline opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char *file, int line){
380 opus_int64 ret64;
381 int fail = 0;
382 ret64 = a64 * b64;
383 if( b64 != 0 ) {
384 fail = a64 != (ret64 / b64);
385 } else if( a64 != 0 ) {
386 fail = b64 != (ret64 / a64);
387 }
388 if ( fail )
389 {
390 fprintf (stderr, "silk_SMULL(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
391#ifdef FIXED_DEBUG_ASSERT
392 silk_assert( 0 );
393#endif
394 }
395 return ret64;
396}
397
398/* no checking needed for silk_SMULBB */
399#undef silk_SMLABB
400#define silk_SMLABB(a,b,c) silk_SMLABB_((a), (b), (c), __FILE__, __LINE__)
401static inline opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
402 opus_int32 ret;
403 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
404 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int16)c32 )
405 {
406 fprintf (stderr, "silk_SMLABB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
407#ifdef FIXED_DEBUG_ASSERT
408 silk_assert( 0 );
409#endif
410 }
411 return ret;
412}
413
414/* no checking needed for silk_SMULBT */
415#undef silk_SMLABT
416#define silk_SMLABT(a,b,c) silk_SMLABT_((a), (b), (c), __FILE__, __LINE__)
417static inline opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
418 opus_int32 ret;
419 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
420 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (c32 >> 16) )
421 {
422 fprintf (stderr, "silk_SMLABT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
423#ifdef FIXED_DEBUG_ASSERT
424 silk_assert( 0 );
425#endif
426 }
427 return ret;
428}
429
430/* no checking needed for silk_SMULTT */
431#undef silk_SMLATT
432#define silk_SMLATT(a,b,c) silk_SMLATT_((a), (b), (c), __FILE__, __LINE__)
433static inline opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
434 opus_int32 ret;
435 ret = a32 + (b32 >> 16) * (c32 >> 16);
436 if ( (opus_int64)ret != (opus_int64)a32 + (b32 >> 16) * (c32 >> 16) )
437 {
438 fprintf (stderr, "silk_SMLATT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
439#ifdef FIXED_DEBUG_ASSERT
440 silk_assert( 0 );
441#endif
442 }
443 return ret;
444}
445
446#undef silk_SMULWW
447#define silk_SMULWW(a,b) silk_SMULWW_((a), (b), __FILE__, __LINE__)
448static inline opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char *file, int line){
449 opus_int32 ret, tmp1, tmp2;
450 opus_int64 ret64;
451 int fail = 0;
452
453 ret = silk_SMULWB( a32, b32 );
454 tmp1 = silk_RSHIFT_ROUND( b32, 16 );
455 tmp2 = silk_MUL( a32, tmp1 );
456
457 fail |= (opus_int64)tmp2 != (opus_int64) a32 * (opus_int64) tmp1;
458
459 tmp1 = ret;
460 ret = silk_ADD32( tmp1, tmp2 );
461 fail |= silk_ADD32( tmp1, tmp2 ) != silk_ADD_SAT32( tmp1, tmp2 );
462
463 ret64 = silk_RSHIFT64( silk_SMULL( a32, b32 ), 16 );
464 fail |= (opus_int64)ret != ret64;
465
466 if ( fail )
467 {
468 fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line);
469#ifdef FIXED_DEBUG_ASSERT
470 silk_assert( 0 );
471#endif
472 }
473
474 return ret;
475}
476
477#undef silk_SMLAWW
478#define silk_SMLAWW(a,b,c) silk_SMLAWW_((a), (b), (c), __FILE__, __LINE__)
479static inline opus_int32 silk_SMLAWW_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
480 opus_int32 ret, tmp;
481
482 tmp = silk_SMULWW( b32, c32 );
483 ret = silk_ADD32( a32, tmp );
484 if ( ret != silk_ADD_SAT32( a32, tmp ) )
485 {
486 fprintf (stderr, "silk_SMLAWW(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
487#ifdef FIXED_DEBUG_ASSERT
488 silk_assert( 0 );
489#endif
490 }
491 return ret;
492}
493
494/* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */
495#undef silk_MLA_ovflw
496#define silk_MLA_ovflw(a32, b32, c32) ((a32) + ((b32) * (c32)))
497#undef silk_SMLABB_ovflw
498#define silk_SMLABB_ovflw(a32, b32, c32) ((a32) + ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32)))
499
500/* no checking needed for silk_SMULL
501 no checking needed for silk_SMLAL
502 no checking needed for silk_SMLALBB
503 no checking needed for SigProcFIX_CLZ16
504 no checking needed for SigProcFIX_CLZ32*/
505
506#undef silk_DIV32
507#define silk_DIV32(a,b) silk_DIV32_((a), (b), __FILE__, __LINE__)
508static inline opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char *file, int line){
509 if ( b32 == 0 )
510 {
511 fprintf (stderr, "silk_DIV32(%d, %d) in %s: line %d\n", a32, b32, file, line);
512#ifdef FIXED_DEBUG_ASSERT
513 silk_assert( 0 );
514#endif
515 }
516 return a32 / b32;
517}
518
519#undef silk_DIV32_16
520#define silk_DIV32_16(a,b) silk_DIV32_16_((a), (b), __FILE__, __LINE__)
521static inline opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, char *file, int line){
522 int fail = 0;
523 fail |= b32 == 0;
524 fail |= b32 > silk_int16_MAX;
525 fail |= b32 < silk_int16_MIN;
526 if ( fail )
527 {
528 fprintf (stderr, "silk_DIV32_16(%d, %d) in %s: line %d\n", a32, b32, file, line);
529#ifdef FIXED_DEBUG_ASSERT
530 silk_assert( 0 );
531#endif
532 }
533 return a32 / b32;
534}
535
536/* no checking needed for silk_SAT8
537 no checking needed for silk_SAT16
538 no checking needed for silk_SAT32
539 no checking needed for silk_POS_SAT32
540 no checking needed for silk_ADD_POS_SAT8
541 no checking needed for silk_ADD_POS_SAT16
542 no checking needed for silk_ADD_POS_SAT32
543 no checking needed for silk_ADD_POS_SAT64 */
544
545#undef silk_LSHIFT8
546#define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__)
547static inline opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
548 opus_int8 ret;
549 int fail = 0;
550 ret = a << shift;
551 fail |= shift < 0;
552 fail |= shift >= 8;
553 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
554 if ( fail )
555 {
556 fprintf (stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line);
557#ifdef FIXED_DEBUG_ASSERT
558 silk_assert( 0 );
559#endif
560 }
561 return ret;
562}
563
564#undef silk_LSHIFT16
565#define silk_LSHIFT16(a,b) silk_LSHIFT16_((a), (b), __FILE__, __LINE__)
566static inline opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
567 opus_int16 ret;
568 int fail = 0;
569 ret = a << shift;
570 fail |= shift < 0;
571 fail |= shift >= 16;
572 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
573 if ( fail )
574 {
575 fprintf (stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line);
576#ifdef FIXED_DEBUG_ASSERT
577 silk_assert( 0 );
578#endif
579 }
580 return ret;
581}
582
583#undef silk_LSHIFT32
584#define silk_LSHIFT32(a,b) silk_LSHIFT32_((a), (b), __FILE__, __LINE__)
585static inline opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
586 opus_int32 ret;
587 int fail = 0;
588 ret = a << shift;
589 fail |= shift < 0;
590 fail |= shift >= 32;
591 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
592 if ( fail )
593 {
594 fprintf (stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line);
595#ifdef FIXED_DEBUG_ASSERT
596 silk_assert( 0 );
597#endif
598 }
599 return ret;
600}
601
602#undef silk_LSHIFT64
603#define silk_LSHIFT64(a,b) silk_LSHIFT64_((a), (b), __FILE__, __LINE__)
604static inline opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line){
605 opus_int64 ret;
606 int fail = 0;
607 ret = a << shift;
608 fail |= shift < 0;
609 fail |= shift >= 64;
610 fail |= (ret>>shift) != ((opus_int64)a);
611 if ( fail )
612 {
613 fprintf (stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
614#ifdef FIXED_DEBUG_ASSERT
615 silk_assert( 0 );
616#endif
617 }
618 return ret;
619}
620
621#undef silk_LSHIFT_ovflw
622#define silk_LSHIFT_ovflw(a,b) silk_LSHIFT_ovflw_((a), (b), __FILE__, __LINE__)
623static inline opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line){
624 if ( (shift < 0) || (shift >= 32) ) /* no check for overflow */
625 {
626 fprintf (stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line);
627#ifdef FIXED_DEBUG_ASSERT
628 silk_assert( 0 );
629#endif
630 }
631 return a << shift;
632}
633
634#undef silk_LSHIFT_uint
635#define silk_LSHIFT_uint(a,b) silk_LSHIFT_uint_((a), (b), __FILE__, __LINE__)
636static inline opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
637 opus_uint32 ret;
638 ret = a << shift;
639 if ( (shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift))
640 {
641 fprintf (stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
642#ifdef FIXED_DEBUG_ASSERT
643 silk_assert( 0 );
644#endif
645 }
646 return ret;
647}
648
649#undef silk_RSHIFT8
650#define silk_RSHITF8(a,b) silk_RSHIFT8_((a), (b), __FILE__, __LINE__)
651static inline opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
652 if ( (shift < 0) || (shift>=8) )
653 {
654 fprintf (stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line);
655#ifdef FIXED_DEBUG_ASSERT
656 silk_assert( 0 );
657#endif
658 }
659 return a >> shift;
660}
661
662#undef silk_RSHIFT16
663#define silk_RSHITF16(a,b) silk_RSHIFT16_((a), (b), __FILE__, __LINE__)
664static inline opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
665 if ( (shift < 0) || (shift>=16) )
666 {
667 fprintf (stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line);
668#ifdef FIXED_DEBUG_ASSERT
669 silk_assert( 0 );
670#endif
671 }
672 return a >> shift;
673}
674
675#undef silk_RSHIFT32
676#define silk_RSHIFT32(a,b) silk_RSHIFT32_((a), (b), __FILE__, __LINE__)
677static inline opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
678 if ( (shift < 0) || (shift>=32) )
679 {
680 fprintf (stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line);
681#ifdef FIXED_DEBUG_ASSERT
682 silk_assert( 0 );
683#endif
684 }
685 return a >> shift;
686}
687
688#undef silk_RSHIFT64
689#define silk_RSHIFT64(a,b) silk_RSHIFT64_((a), (b), __FILE__, __LINE__)
690static inline opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line){
691 if ( (shift < 0) || (shift>=64) )
692 {
693 fprintf (stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line);
694#ifdef FIXED_DEBUG_ASSERT
695 silk_assert( 0 );
696#endif
697 }
698 return a >> shift;
699}
700
701#undef silk_RSHIFT_uint
702#define silk_RSHIFT_uint(a,b) silk_RSHIFT_uint_((a), (b), __FILE__, __LINE__)
703static inline opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
704 if ( (shift < 0) || (shift>32) )
705 {
706 fprintf (stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
707#ifdef FIXED_DEBUG_ASSERT
708 silk_assert( 0 );
709#endif
710 }
711 return a >> shift;
712}
713
714#undef silk_ADD_LSHIFT
715#define silk_ADD_LSHIFT(a,b,c) silk_ADD_LSHIFT_((a), (b), (c), __FILE__, __LINE__)
716static inline int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line){
717 opus_int16 ret;
718 ret = a + (b << shift);
719 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
720 {
721 fprintf (stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
722#ifdef FIXED_DEBUG_ASSERT
723 silk_assert( 0 );
724#endif
725 }
726 return ret; /* shift >= 0 */
727}
728
729#undef silk_ADD_LSHIFT32
730#define silk_ADD_LSHIFT32(a,b,c) silk_ADD_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
731static inline opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
732 opus_int32 ret;
733 ret = a + (b << shift);
734 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
735 {
736 fprintf (stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
737#ifdef FIXED_DEBUG_ASSERT
738 silk_assert( 0 );
739#endif
740 }
741 return ret; /* shift >= 0 */
742}
743
744#undef silk_ADD_LSHIFT_uint
745#define silk_ADD_LSHIFT_uint(a,b,c) silk_ADD_LSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
746static inline opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
747 opus_uint32 ret;
748 ret = a + (b << shift);
749 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
750 {
751 fprintf (stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
752#ifdef FIXED_DEBUG_ASSERT
753 silk_assert( 0 );
754#endif
755 }
756 return ret; /* shift >= 0 */
757}
758
759#undef silk_ADD_RSHIFT
760#define silk_ADD_RSHIFT(a,b,c) silk_ADD_RSHIFT_((a), (b), (c), __FILE__, __LINE__)
761static inline int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line){
762 opus_int16 ret;
763 ret = a + (b >> shift);
764 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
765 {
766 fprintf (stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
767#ifdef FIXED_DEBUG_ASSERT
768 silk_assert( 0 );
769#endif
770 }
771 return ret; /* shift > 0 */
772}
773
774#undef silk_ADD_RSHIFT32
775#define silk_ADD_RSHIFT32(a,b,c) silk_ADD_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
776static inline opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
777 opus_int32 ret;
778 ret = a + (b >> shift);
779 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
780 {
781 fprintf (stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
782#ifdef FIXED_DEBUG_ASSERT
783 silk_assert( 0 );
784#endif
785 }
786 return ret; /* shift > 0 */
787}
788
789#undef silk_ADD_RSHIFT_uint
790#define silk_ADD_RSHIFT_uint(a,b,c) silk_ADD_RSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
791static inline opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
792 opus_uint32 ret;
793 ret = a + (b >> shift);
794 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
795 {
796 fprintf (stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
797#ifdef FIXED_DEBUG_ASSERT
798 silk_assert( 0 );
799#endif
800 }
801 return ret; /* shift > 0 */
802}
803
804#undef silk_SUB_LSHIFT32
805#define silk_SUB_LSHIFT32(a,b,c) silk_SUB_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
806static inline opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
807 opus_int32 ret;
808 ret = a - (b << shift);
809 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) << shift)) )
810 {
811 fprintf (stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
812#ifdef FIXED_DEBUG_ASSERT
813 silk_assert( 0 );
814#endif
815 }
816 return ret; /* shift >= 0 */
817}
818
819#undef silk_SUB_RSHIFT32
820#define silk_SUB_RSHIFT32(a,b,c) silk_SUB_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
821static inline opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
822 opus_int32 ret;
823 ret = a - (b >> shift);
824 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift)) )
825 {
826 fprintf (stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
827#ifdef FIXED_DEBUG_ASSERT
828 silk_assert( 0 );
829#endif
830 }
831 return ret; /* shift > 0 */
832}
833
834#undef silk_RSHIFT_ROUND
835#define silk_RSHIFT_ROUND(a,b) silk_RSHIFT_ROUND_((a), (b), __FILE__, __LINE__)
836static inline opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line){
837 opus_int32 ret;
838 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
839 /* the marco definition can't handle a shift of zero */
840 if ( (shift <= 0) || (shift>31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift) )
841 {
842 fprintf (stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line);
843#ifdef FIXED_DEBUG_ASSERT
844 silk_assert( 0 );
845#endif
846 }
847 return ret;
848}
849
850#undef silk_RSHIFT_ROUND64
851#define silk_RSHIFT_ROUND64(a,b) silk_RSHIFT_ROUND64_((a), (b), __FILE__, __LINE__)
852static inline opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line){
853 opus_int64 ret;
854 /* the marco definition can't handle a shift of zero */
855 if ( (shift <= 0) || (shift>=64) )
856 {
857 fprintf (stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
858#ifdef FIXED_DEBUG_ASSERT
859 silk_assert( 0 );
860#endif
861 }
862 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
863 return ret;
864}
865
866/* silk_abs is used on floats also, so doesn't work... */
867/*#undef silk_abs
868static inline opus_int32 silk_abs(opus_int32 a){
869 silk_assert(a != 0x80000000);
870 return (((a) > 0) ? (a) : -(a)); // Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN
871}*/
872
873#undef silk_abs_int64
874#define silk_abs_int64(a) silk_abs_int64_((a), __FILE__, __LINE__)
875static inline opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line){
876 if ( a == silk_int64_MIN )
877 {
878 fprintf (stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line);
879#ifdef FIXED_DEBUG_ASSERT
880 silk_assert( 0 );
881#endif
882 }
883 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
884}
885
886#undef silk_abs_int32
887#define silk_abs_int32(a) silk_abs_int32_((a), __FILE__, __LINE__)
888static inline opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line){
889 if ( a == silk_int32_MIN )
890 {
891 fprintf (stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line);
892#ifdef FIXED_DEBUG_ASSERT
893 silk_assert( 0 );
894#endif
895 }
896 return silk_abs(a);
897}
898
899#undef silk_CHECK_FIT8
900#define silk_CHECK_FIT8(a) silk_CHECK_FIT8_((a), __FILE__, __LINE__)
901static inline opus_int8 silk_CHECK_FIT8_( opus_int64 a, char *file, int line ){
902 opus_int8 ret;
903 ret = (opus_int8)a;
904 if ( (opus_int64)ret != a )
905 {
906 fprintf (stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line);
907#ifdef FIXED_DEBUG_ASSERT
908 silk_assert( 0 );
909#endif
910 }
911 return( ret );
912}
913
914#undef silk_CHECK_FIT16
915#define silk_CHECK_FIT16(a) silk_CHECK_FIT16_((a), __FILE__, __LINE__)
916static inline opus_int16 silk_CHECK_FIT16_( opus_int64 a, char *file, int line ){
917 opus_int16 ret;
918 ret = (opus_int16)a;
919 if ( (opus_int64)ret != a )
920 {
921 fprintf (stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line);
922#ifdef FIXED_DEBUG_ASSERT
923 silk_assert( 0 );
924#endif
925 }
926 return( ret );
927}
928
929#undef silk_CHECK_FIT32
930#define silk_CHECK_FIT32(a) silk_CHECK_FIT32_((a), __FILE__, __LINE__)
931static inline opus_int32 silk_CHECK_FIT32_( opus_int64 a, char *file, int line ){
932 opus_int32 ret;
933 ret = (opus_int32)a;
934 if ( (opus_int64)ret != a )
935 {
936 fprintf (stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line);
937#ifdef FIXED_DEBUG_ASSERT
938 silk_assert( 0 );
939#endif
940 }
941 return( ret );
942}
943
944/* no checking for silk_NSHIFT_MUL_32_32
945 no checking for silk_NSHIFT_MUL_16_16
946 no checking needed for silk_min
947 no checking needed for silk_max
948 no checking needed for silk_sign
949*/
950
951#endif
952#endif /* MACRO_DEBUG_H */
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF2A.c b/lib/rbcodec/codecs/libopus/silk/NLSF2A.c
new file mode 100644
index 0000000000..ffc2a96939
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/NLSF2A.c
@@ -0,0 +1,178 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/* conversion between prediction filter coefficients and LSFs */
33/* order should be even */
34/* a piecewise linear approximation maps LSF <-> cos(LSF) */
35/* therefore the result is not accurate LSFs, but the two */
36/* functions are accurate inverses of each other */
37
38#include "SigProc_FIX.h"
39#include "tables.h"
40
41#define QA 16
42
43/* helper function for NLSF2A(..) */
44static inline void silk_NLSF2A_find_poly(
45 opus_int32 *out, /* O intermediate polynomial, QA [dd+1] */
46 const opus_int32 *cLSF, /* I vector of interleaved 2*cos(LSFs), QA [d] */
47 opus_int dd /* I polynomial order (= 1/2 * filter order) */
48)
49{
50 opus_int k, n;
51 opus_int32 ftmp;
52
53 out[0] = silk_LSHIFT( 1, QA );
54 out[1] = -cLSF[0];
55 for( k = 1; k < dd; k++ ) {
56 ftmp = cLSF[2*k]; /* QA*/
57 out[k+1] = silk_LSHIFT( out[k-1], 1 ) - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[k] ), QA );
58 for( n = k; n > 1; n-- ) {
59 out[n] += out[n-2] - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[n-1] ), QA );
60 }
61 out[1] -= ftmp;
62 }
63}
64
65/* compute whitening filter coefficients from normalized line spectral frequencies */
66void silk_NLSF2A(
67 opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
68 const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */
69 const opus_int d /* I filter order (should be even) */
70)
71{
72 /* This ordering was found to maximize quality. It improves numerical accuracy of
73 silk_NLSF2A_find_poly() compared to "standard" ordering. */
74 static const unsigned char ordering16[16] = {
75 0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1
76 };
77 static const unsigned char ordering10[10] = {
78 0, 9, 6, 3, 4, 5, 8, 1, 2, 7
79 };
80 const unsigned char *ordering;
81 opus_int k, i, dd;
82 opus_int32 cos_LSF_QA[ SILK_MAX_ORDER_LPC ];
83 opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ];
84 opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta;
85 opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ];
86 opus_int32 maxabs, absval, idx=0, sc_Q16;
87
88 silk_assert( LSF_COS_TAB_SZ_FIX == 128 );
89 silk_assert( d==10||d==16 );
90
91 /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */
92 ordering = d == 16 ? ordering16 : ordering10;
93 for( k = 0; k < d; k++ ) {
94 silk_assert(NLSF[k] >= 0 );
95
96 /* f_int on a scale 0-127 (rounded down) */
97 f_int = silk_RSHIFT( NLSF[k], 15 - 7 );
98
99 /* f_frac, range: 0..255 */
100 f_frac = NLSF[k] - silk_LSHIFT( f_int, 15 - 7 );
101
102 silk_assert(f_int >= 0);
103 silk_assert(f_int < LSF_COS_TAB_SZ_FIX );
104
105 /* Read start and end value from table */
106 cos_val = silk_LSFCosTab_FIX_Q12[ f_int ]; /* Q12 */
107 delta = silk_LSFCosTab_FIX_Q12[ f_int + 1 ] - cos_val; /* Q12, with a range of 0..200 */
108
109 /* Linear interpolation */
110 cos_LSF_QA[ordering[k]] = silk_RSHIFT_ROUND( silk_LSHIFT( cos_val, 8 ) + silk_MUL( delta, f_frac ), 20 - QA ); /* QA */
111 }
112
113 dd = silk_RSHIFT( d, 1 );
114
115 /* generate even and odd polynomials using convolution */
116 silk_NLSF2A_find_poly( P, &cos_LSF_QA[ 0 ], dd );
117 silk_NLSF2A_find_poly( Q, &cos_LSF_QA[ 1 ], dd );
118
119 /* convert even and odd polynomials to opus_int32 Q12 filter coefs */
120 for( k = 0; k < dd; k++ ) {
121 Ptmp = P[ k+1 ] + P[ k ];
122 Qtmp = Q[ k+1 ] - Q[ k ];
123
124 /* the Ptmp and Qtmp values at this stage need to fit in int32 */
125 a32_QA1[ k ] = -Qtmp - Ptmp; /* QA+1 */
126 a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */
127 }
128
129 /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */
130 for( i = 0; i < 10; i++ ) {
131 /* Find maximum absolute value and its index */
132 maxabs = 0;
133 for( k = 0; k < d; k++ ) {
134 absval = silk_abs( a32_QA1[k] );
135 if( absval > maxabs ) {
136 maxabs = absval;
137 idx = k;
138 }
139 }
140 maxabs = silk_RSHIFT_ROUND( maxabs, QA + 1 - 12 ); /* QA+1 -> Q12 */
141
142 if( maxabs > silk_int16_MAX ) {
143 /* Reduce magnitude of prediction coefficients */
144 maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */
145 sc_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ),
146 silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) );
147 silk_bwexpander_32( a32_QA1, d, sc_Q16 );
148 } else {
149 break;
150 }
151 }
152
153 if( i == 10 ) {
154 /* Reached the last iteration, clip the coefficients */
155 for( k = 0; k < d; k++ ) {
156 a_Q12[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ) ); /* QA+1 -> Q12 */
157 a32_QA1[ k ] = silk_LSHIFT( (opus_int32)a_Q12[ k ], QA + 1 - 12 );
158 }
159 } else {
160 for( k = 0; k < d; k++ ) {
161 a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */
162 }
163 }
164
165 for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {
166 if( silk_LPC_inverse_pred_gain( a_Q12, d ) < SILK_FIX_CONST( 1.0 / MAX_PREDICTION_POWER_GAIN, 30 ) ) {
167 /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */
168 /* on the unscaled coefficients, convert to Q12 and measure again */
169 silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) );
170 for( k = 0; k < d; k++ ) {
171 a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */
172 }
173 } else {
174 break;
175 }
176 }
177}
178
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF_VQ_weights_laroia.c b/lib/rbcodec/codecs/libopus/silk/NLSF_VQ_weights_laroia.c
new file mode 100644
index 0000000000..a89d6405ac
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/NLSF_VQ_weights_laroia.c
@@ -0,0 +1,80 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "define.h"
33#include "SigProc_FIX.h"
34
35/*
36R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP
37Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech,
38Signal Processing, pp. 641-644, 1991.
39*/
40
41/* Laroia low complexity NLSF weights */
42void silk_NLSF_VQ_weights_laroia(
43 opus_int16 *pNLSFW_Q_OUT, /* O Pointer to input vector weights [D] */
44 const opus_int16 *pNLSF_Q15, /* I Pointer to input vector [D] */
45 const opus_int D /* I Input vector dimension (even) */
46)
47{
48 opus_int k;
49 opus_int32 tmp1_int, tmp2_int;
50
51 silk_assert( D > 0 );
52 silk_assert( ( D & 1 ) == 0 );
53
54 /* First value */
55 tmp1_int = silk_max_int( pNLSF_Q15[ 0 ], 1 );
56 tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int );
57 tmp2_int = silk_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], 1 );
58 tmp2_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp2_int );
59 pNLSFW_Q_OUT[ 0 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX );
60 silk_assert( pNLSFW_Q_OUT[ 0 ] > 0 );
61
62 /* Main loop */
63 for( k = 1; k < D - 1; k += 2 ) {
64 tmp1_int = silk_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], 1 );
65 tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int );
66 pNLSFW_Q_OUT[ k ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX );
67 silk_assert( pNLSFW_Q_OUT[ k ] > 0 );
68
69 tmp2_int = silk_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], 1 );
70 tmp2_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp2_int );
71 pNLSFW_Q_OUT[ k + 1 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX );
72 silk_assert( pNLSFW_Q_OUT[ k + 1 ] > 0 );
73 }
74
75 /* Last value */
76 tmp1_int = silk_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], 1 );
77 tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int );
78 pNLSFW_Q_OUT[ D - 1 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX );
79 silk_assert( pNLSFW_Q_OUT[ D - 1 ] > 0 );
80}
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF_decode.c b/lib/rbcodec/codecs/libopus/silk/NLSF_decode.c
new file mode 100644
index 0000000000..6c2db4fd9d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/NLSF_decode.c
@@ -0,0 +1,101 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Predictive dequantizer for NLSF residuals */
35static inline void silk_NLSF_residual_dequant( /* O Returns RD value in Q30 */
36 opus_int16 x_Q10[], /* O Output [ order ] */
37 const opus_int8 indices[], /* I Quantization indices [ order ] */
38 const opus_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
39 const opus_int quant_step_size_Q16, /* I Quantization step size */
40 const opus_int16 order /* I Number of input values */
41)
42{
43 opus_int i, out_Q10, pred_Q10;
44
45 out_Q10 = 0;
46 for( i = order-1; i >= 0; i-- ) {
47 pred_Q10 = silk_RSHIFT( silk_SMULBB( out_Q10, (opus_int16)pred_coef_Q8[ i ] ), 8 );
48 out_Q10 = silk_LSHIFT( indices[ i ], 10 );
49 if( out_Q10 > 0 ) {
50 out_Q10 = silk_SUB16( out_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
51 } else if( out_Q10 < 0 ) {
52 out_Q10 = silk_ADD16( out_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
53 }
54 out_Q10 = silk_SMLAWB( pred_Q10, (opus_int32)out_Q10, quant_step_size_Q16 );
55 x_Q10[ i ] = out_Q10;
56 }
57}
58
59
60/***********************/
61/* NLSF vector decoder */
62/***********************/
63void silk_NLSF_decode(
64 opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
65 opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
66 const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
67)
68{
69 opus_int i;
70 opus_uint8 pred_Q8[ MAX_LPC_ORDER ];
71 opus_int16 ec_ix[ MAX_LPC_ORDER ];
72 opus_int16 res_Q10[ MAX_LPC_ORDER ];
73 opus_int16 W_tmp_QW[ MAX_LPC_ORDER ];
74 opus_int32 W_tmp_Q9, NLSF_Q15_tmp;
75 const opus_uint8 *pCB_element;
76
77 /* Decode first stage */
78 pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
79 for( i = 0; i < psNLSF_CB->order; i++ ) {
80 pNLSF_Q15[ i ] = silk_LSHIFT( (opus_int16)pCB_element[ i ], 7 );
81 }
82
83 /* Unpack entropy table indices and predictor for current CB1 index */
84 silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] );
85
86 /* Predictive residual dequantizer */
87 silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order );
88
89 /* Weights from codebook vector */
90 silk_NLSF_VQ_weights_laroia( W_tmp_QW, pNLSF_Q15, psNLSF_CB->order );
91
92 /* Apply inverse square-rooted weights and add to output */
93 for( i = 0; i < psNLSF_CB->order; i++ ) {
94 W_tmp_Q9 = silk_SQRT_APPROX( silk_LSHIFT( (opus_int32)W_tmp_QW[ i ], 18 - NLSF_W_Q ) );
95 NLSF_Q15_tmp = silk_ADD32( pNLSF_Q15[ i ], silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), W_tmp_Q9 ) );
96 pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT( NLSF_Q15_tmp, 0, 32767 );
97 }
98
99 /* NLSF stabilization */
100 silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order );
101}
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF_stabilize.c b/lib/rbcodec/codecs/libopus/silk/NLSF_stabilize.c
new file mode 100644
index 0000000000..25ec49f4c1
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/NLSF_stabilize.c
@@ -0,0 +1,142 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/* NLSF stabilizer: */
33/* */
34/* - Moves NLSFs futher apart if they are too close */
35/* - Moves NLSFs away from borders if they are too close */
36/* - High effort to achieve a modification with minimum */
37/* Euclidean distance to input vector */
38/* - Output are sorted NLSF coefficients */
39/* */
40
41#include "SigProc_FIX.h"
42
43/* Constant Definitions */
44#define MAX_LOOPS 20
45
46/* NLSF stabilizer, for a single input data vector */
47void silk_NLSF_stabilize(
48 opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */
49 const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */
50 const opus_int L /* I Number of NLSF parameters in the input vector */
51)
52{
53 opus_int i, I=0, k, loops;
54 opus_int16 center_freq_Q15;
55 opus_int32 diff_Q15, min_diff_Q15, min_center_Q15, max_center_Q15;
56
57 /* This is necessary to ensure an output within range of a opus_int16 */
58 silk_assert( NDeltaMin_Q15[L] >= 1 );
59
60 for( loops = 0; loops < MAX_LOOPS; loops++ ) {
61 /**************************/
62 /* Find smallest distance */
63 /**************************/
64 /* First element */
65 min_diff_Q15 = NLSF_Q15[0] - NDeltaMin_Q15[0];
66 I = 0;
67 /* Middle elements */
68 for( i = 1; i <= L-1; i++ ) {
69 diff_Q15 = NLSF_Q15[i] - ( NLSF_Q15[i-1] + NDeltaMin_Q15[i] );
70 if( diff_Q15 < min_diff_Q15 ) {
71 min_diff_Q15 = diff_Q15;
72 I = i;
73 }
74 }
75 /* Last element */
76 diff_Q15 = ( 1 << 15 ) - ( NLSF_Q15[L-1] + NDeltaMin_Q15[L] );
77 if( diff_Q15 < min_diff_Q15 ) {
78 min_diff_Q15 = diff_Q15;
79 I = L;
80 }
81
82 /***************************************************/
83 /* Now check if the smallest distance non-negative */
84 /***************************************************/
85 if( min_diff_Q15 >= 0 ) {
86 return;
87 }
88
89 if( I == 0 ) {
90 /* Move away from lower limit */
91 NLSF_Q15[0] = NDeltaMin_Q15[0];
92
93 } else if( I == L) {
94 /* Move away from higher limit */
95 NLSF_Q15[L-1] = ( 1 << 15 ) - NDeltaMin_Q15[L];
96
97 } else {
98 /* Find the lower extreme for the location of the current center frequency */
99 min_center_Q15 = 0;
100 for( k = 0; k < I; k++ ) {
101 min_center_Q15 += NDeltaMin_Q15[k];
102 }
103 min_center_Q15 += silk_RSHIFT( NDeltaMin_Q15[I], 1 );
104
105 /* Find the upper extreme for the location of the current center frequency */
106 max_center_Q15 = 1 << 15;
107 for( k = L; k > I; k-- ) {
108 max_center_Q15 -= NDeltaMin_Q15[k];
109 }
110 max_center_Q15 -= silk_RSHIFT( NDeltaMin_Q15[I], 1 );
111
112 /* Move apart, sorted by value, keeping the same center frequency */
113 center_freq_Q15 = (opus_int16)silk_LIMIT_32( silk_RSHIFT_ROUND( (opus_int32)NLSF_Q15[I-1] + (opus_int32)NLSF_Q15[I], 1 ),
114 min_center_Q15, max_center_Q15 );
115 NLSF_Q15[I-1] = center_freq_Q15 - silk_RSHIFT( NDeltaMin_Q15[I], 1 );
116 NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I];
117 }
118 }
119
120 /* Safe and simple fall back method, which is less ideal than the above */
121 if( loops == MAX_LOOPS )
122 {
123 /* Insertion sort (fast for already almost sorted arrays): */
124 /* Best case: O(n) for an already sorted array */
125 /* Worst case: O(n^2) for an inversely sorted array */
126 silk_insertion_sort_increasing_all_values_int16( &NLSF_Q15[0], L );
127
128 /* First NLSF should be no less than NDeltaMin[0] */
129 NLSF_Q15[0] = silk_max_int( NLSF_Q15[0], NDeltaMin_Q15[0] );
130
131 /* Keep delta_min distance between the NLSFs */
132 for( i = 1; i < L; i++ )
133 NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], NLSF_Q15[i-1] + NDeltaMin_Q15[i] );
134
135 /* Last NLSF should be no higher than 1 - NDeltaMin[L] */
136 NLSF_Q15[L-1] = silk_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] );
137
138 /* Keep NDeltaMin distance between the NLSFs */
139 for( i = L-2; i >= 0; i-- )
140 NLSF_Q15[i] = silk_min_int( NLSF_Q15[i], NLSF_Q15[i+1] - NDeltaMin_Q15[i+1] );
141 }
142}
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF_unpack.c b/lib/rbcodec/codecs/libopus/silk/NLSF_unpack.c
new file mode 100644
index 0000000000..5e059f2615
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/NLSF_unpack.c
@@ -0,0 +1,55 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Unpack predictor values and indices for entropy coding tables */
35void silk_NLSF_unpack(
36 opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */
37 opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */
38 const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
39 const opus_int CB1_index /* I Index of vector in first LSF codebook */
40)
41{
42 opus_int i;
43 opus_uint8 entry;
44 const opus_uint8 *ec_sel_ptr;
45
46 ec_sel_ptr = &psNLSF_CB->ec_sel[ CB1_index * psNLSF_CB->order / 2 ];
47 for( i = 0; i < psNLSF_CB->order; i += 2 ) {
48 entry = *ec_sel_ptr++;
49 ec_ix [ i ] = silk_SMULBB( silk_RSHIFT( entry, 1 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 );
50 pred_Q8[ i ] = psNLSF_CB->pred_Q8[ i + ( entry & 1 ) * ( psNLSF_CB->order - 1 ) ];
51 ec_ix [ i + 1 ] = silk_SMULBB( silk_RSHIFT( entry, 5 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 );
52 pred_Q8[ i + 1 ] = psNLSF_CB->pred_Q8[ i + ( silk_RSHIFT( entry, 4 ) & 1 ) * ( psNLSF_CB->order - 1 ) + 1 ];
53 }
54}
55
diff --git a/lib/rbcodec/codecs/libopus/silk/PLC.c b/lib/rbcodec/codecs/libopus/silk/PLC.c
new file mode 100644
index 0000000000..08ae5b7617
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/PLC.c
@@ -0,0 +1,423 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33#include "stack_alloc.h"
34#include "PLC.h"
35
36#define NB_ATT 2
37static const opus_int16 HARM_ATT_Q15[NB_ATT] = { 32440, 31130 }; /* 0.99, 0.95 */
38static const opus_int16 PLC_RAND_ATTENUATE_V_Q15[NB_ATT] = { 31130, 26214 }; /* 0.95, 0.8 */
39static const opus_int16 PLC_RAND_ATTENUATE_UV_Q15[NB_ATT] = { 32440, 29491 }; /* 0.99, 0.9 */
40
41static inline void silk_PLC_update(
42 silk_decoder_state *psDec, /* I/O Decoder state */
43 silk_decoder_control *psDecCtrl /* I/O Decoder control */
44);
45
46static inline void silk_PLC_conceal(
47 silk_decoder_state *psDec, /* I/O Decoder state */
48 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
49 opus_int16 frame[] /* O LPC residual signal */
50);
51
52
53void silk_PLC_Reset(
54 silk_decoder_state *psDec /* I/O Decoder state */
55)
56{
57 psDec->sPLC.pitchL_Q8 = silk_LSHIFT( psDec->frame_length, 8 - 1 );
58 psDec->sPLC.prevGain_Q16[ 0 ] = SILK_FIX_CONST( 1, 16 );
59 psDec->sPLC.prevGain_Q16[ 1 ] = SILK_FIX_CONST( 1, 16 );
60 psDec->sPLC.subfr_length = 20;
61 psDec->sPLC.nb_subfr = 2;
62}
63
64void silk_PLC(
65 silk_decoder_state *psDec, /* I/O Decoder state */
66 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
67 opus_int16 frame[], /* I/O signal */
68 opus_int lost /* I Loss flag */
69)
70{
71 /* PLC control function */
72 if( psDec->fs_kHz != psDec->sPLC.fs_kHz ) {
73 silk_PLC_Reset( psDec );
74 psDec->sPLC.fs_kHz = psDec->fs_kHz;
75 }
76
77 if( lost ) {
78 /****************************/
79 /* Generate Signal */
80 /****************************/
81 silk_PLC_conceal( psDec, psDecCtrl, frame );
82
83 psDec->lossCnt++;
84 } else {
85 /****************************/
86 /* Update state */
87 /****************************/
88 silk_PLC_update( psDec, psDecCtrl );
89 }
90}
91
92/**************************************************/
93/* Update state of PLC */
94/**************************************************/
95static inline void silk_PLC_update(
96 silk_decoder_state *psDec, /* I/O Decoder state */
97 silk_decoder_control *psDecCtrl /* I/O Decoder control */
98)
99{
100 opus_int32 LTP_Gain_Q14, temp_LTP_Gain_Q14;
101 opus_int i, j;
102 silk_PLC_struct *psPLC;
103
104 psPLC = &psDec->sPLC;
105
106 /* Update parameters used in case of packet loss */
107 psDec->prevSignalType = psDec->indices.signalType;
108 LTP_Gain_Q14 = 0;
109 if( psDec->indices.signalType == TYPE_VOICED ) {
110 /* Find the parameters for the last subframe which contains a pitch pulse */
111 for( j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; j++ ) {
112 if( j == psDec->nb_subfr ) {
113 break;
114 }
115 temp_LTP_Gain_Q14 = 0;
116 for( i = 0; i < LTP_ORDER; i++ ) {
117 temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( psDec->nb_subfr - 1 - j ) * LTP_ORDER + i ];
118 }
119 if( temp_LTP_Gain_Q14 > LTP_Gain_Q14 ) {
120 LTP_Gain_Q14 = temp_LTP_Gain_Q14;
121 silk_memcpy( psPLC->LTPCoef_Q14,
122 &psDecCtrl->LTPCoef_Q14[ silk_SMULBB( psDec->nb_subfr - 1 - j, LTP_ORDER ) ],
123 LTP_ORDER * sizeof( opus_int16 ) );
124
125 psPLC->pitchL_Q8 = silk_LSHIFT( psDecCtrl->pitchL[ psDec->nb_subfr - 1 - j ], 8 );
126 }
127 }
128
129 silk_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( opus_int16 ) );
130 psPLC->LTPCoef_Q14[ LTP_ORDER / 2 ] = LTP_Gain_Q14;
131
132 /* Limit LT coefs */
133 if( LTP_Gain_Q14 < V_PITCH_GAIN_START_MIN_Q14 ) {
134 opus_int scale_Q10;
135 opus_int32 tmp;
136
137 tmp = silk_LSHIFT( V_PITCH_GAIN_START_MIN_Q14, 10 );
138 scale_Q10 = silk_DIV32( tmp, silk_max( LTP_Gain_Q14, 1 ) );
139 for( i = 0; i < LTP_ORDER; i++ ) {
140 psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT( silk_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q10 ), 10 );
141 }
142 } else if( LTP_Gain_Q14 > V_PITCH_GAIN_START_MAX_Q14 ) {
143 opus_int scale_Q14;
144 opus_int32 tmp;
145
146 tmp = silk_LSHIFT( V_PITCH_GAIN_START_MAX_Q14, 14 );
147 scale_Q14 = silk_DIV32( tmp, silk_max( LTP_Gain_Q14, 1 ) );
148 for( i = 0; i < LTP_ORDER; i++ ) {
149 psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT( silk_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q14 ), 14 );
150 }
151 }
152 } else {
153 psPLC->pitchL_Q8 = silk_LSHIFT( silk_SMULBB( psDec->fs_kHz, 18 ), 8 );
154 silk_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( opus_int16 ));
155 }
156
157 /* Save LPC coeficients */
158 silk_memcpy( psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) );
159 psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;
160
161 /* Save last two gains */
162 silk_memcpy( psPLC->prevGain_Q16, &psDecCtrl->Gains_Q16[ psDec->nb_subfr - 2 ], 2 * sizeof( opus_int32 ) );
163
164 psPLC->subfr_length = psDec->subfr_length;
165 psPLC->nb_subfr = psDec->nb_subfr;
166}
167
168static inline void silk_PLC_conceal(
169 silk_decoder_state *psDec, /* I/O Decoder state */
170 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
171 opus_int16 frame[] /* O LPC residual signal */
172)
173{
174 opus_int i, j, k;
175 opus_int lag, idx, sLTP_buf_idx, shift1, shift2;
176 opus_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15, inv_gain_Q30;
177 opus_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr;
178 opus_int32 LPC_pred_Q10, LTP_pred_Q12;
179 opus_int16 rand_scale_Q14;
180 opus_int16 *B_Q14, *exc_buf_ptr;
181 opus_int32 *sLPC_Q14_ptr;
182 VARDECL( opus_int16, exc_buf );
183 opus_int16 A_Q12[ MAX_LPC_ORDER ];
184 VARDECL( opus_int16, sLTP );
185 VARDECL( opus_int32, sLTP_Q14 );
186 silk_PLC_struct *psPLC = &psDec->sPLC;
187 opus_int32 prevGain_Q10[2];
188 SAVE_STACK;
189
190 ALLOC( exc_buf, 2*psPLC->subfr_length, opus_int16 );
191 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 );
192 ALLOC( sLTP_Q14, psDec->ltp_mem_length + psDec->frame_length, opus_int32 );
193
194 prevGain_Q10[0] = silk_RSHIFT( psPLC->prevGain_Q16[ 0 ], 6);
195 prevGain_Q10[1] = silk_RSHIFT( psPLC->prevGain_Q16[ 1 ], 6);
196
197 if( psDec->first_frame_after_reset ) {
198 silk_memset( psPLC->prevLPC_Q12, 0, sizeof( psPLC->prevLPC_Q12 ) );
199 }
200
201 /* Find random noise component */
202 /* Scale previous excitation signal */
203 exc_buf_ptr = exc_buf;
204 for( k = 0; k < 2; k++ ) {
205 for( i = 0; i < psPLC->subfr_length; i++ ) {
206 exc_buf_ptr[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT(
207 silk_SMULWW( psDec->exc_Q14[ i + ( k + psPLC->nb_subfr - 2 ) * psPLC->subfr_length ], prevGain_Q10[ k ] ), 8 ) );
208 }
209 exc_buf_ptr += psPLC->subfr_length;
210 }
211 /* Find the subframe with lowest energy of the last two and use that as random noise generator */
212 silk_sum_sqr_shift( &energy1, &shift1, exc_buf, psPLC->subfr_length );
213 silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psPLC->subfr_length ], psPLC->subfr_length );
214
215 if( silk_RSHIFT( energy1, shift2 ) < silk_RSHIFT( energy2, shift1 ) ) {
216 /* First sub-frame has lowest energy */
217 rand_ptr = &psDec->exc_Q14[ silk_max_int( 0, ( psPLC->nb_subfr - 1 ) * psPLC->subfr_length - RAND_BUF_SIZE ) ];
218 } else {
219 /* Second sub-frame has lowest energy */
220 rand_ptr = &psDec->exc_Q14[ silk_max_int( 0, psPLC->nb_subfr * psPLC->subfr_length - RAND_BUF_SIZE ) ];
221 }
222
223 /* Set up Gain to random noise component */
224 B_Q14 = psPLC->LTPCoef_Q14;
225 rand_scale_Q14 = psPLC->randScale_Q14;
226
227 /* Set up attenuation gains */
228 harm_Gain_Q15 = HARM_ATT_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ];
229 if( psDec->prevSignalType == TYPE_VOICED ) {
230 rand_Gain_Q15 = PLC_RAND_ATTENUATE_V_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ];
231 } else {
232 rand_Gain_Q15 = PLC_RAND_ATTENUATE_UV_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ];
233 }
234
235 /* LPC concealment. Apply BWE to previous LPC */
236 silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, SILK_FIX_CONST( BWE_COEF, 16 ) );
237
238 /* Preload LPC coeficients to array on stack. Gives small performance gain */
239 silk_memcpy( A_Q12, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( opus_int16 ) );
240
241 /* First Lost frame */
242 if( psDec->lossCnt == 0 ) {
243 rand_scale_Q14 = 1 << 14;
244
245 /* Reduce random noise Gain for voiced frames */
246 if( psDec->prevSignalType == TYPE_VOICED ) {
247 for( i = 0; i < LTP_ORDER; i++ ) {
248 rand_scale_Q14 -= B_Q14[ i ];
249 }
250 rand_scale_Q14 = silk_max_16( 3277, rand_scale_Q14 ); /* 0.2 */
251 rand_scale_Q14 = (opus_int16)silk_RSHIFT( silk_SMULBB( rand_scale_Q14, psPLC->prevLTP_scale_Q14 ), 14 );
252 } else {
253 /* Reduce random noise for unvoiced frames with high LPC gain */
254 opus_int32 invGain_Q30, down_scale_Q30;
255
256 invGain_Q30 = silk_LPC_inverse_pred_gain( psPLC->prevLPC_Q12, psDec->LPC_order );
257
258 down_scale_Q30 = silk_min_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 );
259 down_scale_Q30 = silk_max_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 );
260 down_scale_Q30 = silk_LSHIFT( down_scale_Q30, LOG2_INV_LPC_GAIN_HIGH_THRES );
261
262 rand_Gain_Q15 = silk_RSHIFT( silk_SMULWB( down_scale_Q30, rand_Gain_Q15 ), 14 );
263 }
264 }
265
266 rand_seed = psPLC->rand_seed;
267 lag = silk_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
268 sLTP_buf_idx = psDec->ltp_mem_length;
269
270 /* Rewhiten LTP state */
271 idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2;
272 silk_assert( idx > 0 );
273 silk_LPC_analysis_filter( &sLTP[ idx ], &psDec->outBuf[ idx ], A_Q12, psDec->ltp_mem_length - idx, psDec->LPC_order );
274 /* Scale LTP state */
275 inv_gain_Q30 = silk_INVERSE32_varQ( psPLC->prevGain_Q16[ 1 ], 46 );
276 inv_gain_Q30 = silk_min( inv_gain_Q30, silk_int32_MAX >> 1 );
277 for( i = idx + psDec->LPC_order; i < psDec->ltp_mem_length; i++ ) {
278 sLTP_Q14[ i ] = silk_SMULWB( inv_gain_Q30, sLTP[ i ] );
279 }
280
281 /***************************/
282 /* LTP synthesis filtering */
283 /***************************/
284 for( k = 0; k < psDec->nb_subfr; k++ ) {
285 /* Set up pointer */
286 pred_lag_ptr = &sLTP_Q14[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
287 for( i = 0; i < psDec->subfr_length; i++ ) {
288 /* Unrolled loop */
289 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
290 LTP_pred_Q12 = 2;
291 LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ 0 ], B_Q14[ 0 ] );
292 LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );
293 LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );
294 LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );
295 LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );
296 pred_lag_ptr++;
297
298 /* Generate LPC excitation */
299 rand_seed = silk_RAND( rand_seed );
300 idx = silk_RSHIFT( rand_seed, 25 ) & RAND_BUF_MASK;
301 sLTP_Q14[ sLTP_buf_idx ] = silk_LSHIFT32( silk_SMLAWB( LTP_pred_Q12, rand_ptr[ idx ], rand_scale_Q14 ), 2 );
302 sLTP_buf_idx++;
303 }
304
305 /* Gradually reduce LTP gain */
306 for( j = 0; j < LTP_ORDER; j++ ) {
307 B_Q14[ j ] = silk_RSHIFT( silk_SMULBB( harm_Gain_Q15, B_Q14[ j ] ), 15 );
308 }
309 /* Gradually reduce excitation gain */
310 rand_scale_Q14 = silk_RSHIFT( silk_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 );
311
312 /* Slowly increase pitch lag */
313 psPLC->pitchL_Q8 = silk_SMLAWB( psPLC->pitchL_Q8, psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16 );
314 psPLC->pitchL_Q8 = silk_min_32( psPLC->pitchL_Q8, silk_LSHIFT( silk_SMULBB( MAX_PITCH_LAG_MS, psDec->fs_kHz ), 8 ) );
315 lag = silk_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
316 }
317
318 /***************************/
319 /* LPC synthesis filtering */
320 /***************************/
321 sLPC_Q14_ptr = &sLTP_Q14[ psDec->ltp_mem_length - MAX_LPC_ORDER ];
322
323 /* Copy LPC state */
324 silk_memcpy( sLPC_Q14_ptr, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof( opus_int32 ) );
325
326 silk_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */
327 for( i = 0; i < psDec->frame_length; i++ ) {
328 /* partly unrolled */
329 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
330 LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 );
331 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] );
332 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] );
333 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] );
334 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] );
335 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] );
336 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] );
337 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] );
338 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] );
339 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] );
340 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] );
341 for( j = 10; j < psDec->LPC_order; j++ ) {
342 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - j - 1 ], A_Q12[ j ] );
343 }
344
345 /* Add prediction to LPC excitation */
346 sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], LPC_pred_Q10, 4 );
347
348 /* Scale with Gain */
349 frame[ i ] = (opus_int16)silk_SAT16( silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], prevGain_Q10[ 1 ] ), 8 ) ) );
350 }
351
352 /* Save LPC state */
353 silk_memcpy( psDec->sLPC_Q14_buf, &sLPC_Q14_ptr[ psDec->frame_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
354
355 /**************************************/
356 /* Update states */
357 /**************************************/
358 psPLC->rand_seed = rand_seed;
359 psPLC->randScale_Q14 = rand_scale_Q14;
360 for( i = 0; i < MAX_NB_SUBFR; i++ ) {
361 psDecCtrl->pitchL[ i ] = lag;
362 }
363 RESTORE_STACK;
364}
365
366/* Glues concealed frames with new good recieved frames */
367void silk_PLC_glue_frames(
368 silk_decoder_state *psDec, /* I/O decoder state */
369 opus_int16 frame[], /* I/O signal */
370 opus_int length /* I length of signal */
371)
372{
373 opus_int i, energy_shift;
374 opus_int32 energy;
375 silk_PLC_struct *psPLC;
376 psPLC = &psDec->sPLC;
377
378 if( psDec->lossCnt ) {
379 /* Calculate energy in concealed residual */
380 silk_sum_sqr_shift( &psPLC->conc_energy, &psPLC->conc_energy_shift, frame, length );
381
382 psPLC->last_frame_lost = 1;
383 } else {
384 if( psDec->sPLC.last_frame_lost ) {
385 /* Calculate residual in decoded signal if last frame was lost */
386 silk_sum_sqr_shift( &energy, &energy_shift, frame, length );
387
388 /* Normalize energies */
389 if( energy_shift > psPLC->conc_energy_shift ) {
390 psPLC->conc_energy = silk_RSHIFT( psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift );
391 } else if( energy_shift < psPLC->conc_energy_shift ) {
392 energy = silk_RSHIFT( energy, psPLC->conc_energy_shift - energy_shift );
393 }
394
395 /* Fade in the energy difference */
396 if( energy > psPLC->conc_energy ) {
397 opus_int32 frac_Q24, LZ;
398 opus_int32 gain_Q16, slope_Q16;
399
400 LZ = silk_CLZ32( psPLC->conc_energy );
401 LZ = LZ - 1;
402 psPLC->conc_energy = silk_LSHIFT( psPLC->conc_energy, LZ );
403 energy = silk_RSHIFT( energy, silk_max_32( 24 - LZ, 0 ) );
404
405 frac_Q24 = silk_DIV32( psPLC->conc_energy, silk_max( energy, 1 ) );
406
407 gain_Q16 = silk_LSHIFT( silk_SQRT_APPROX( frac_Q24 ), 4 );
408 slope_Q16 = silk_DIV32_16( ( (opus_int32)1 << 16 ) - gain_Q16, length );
409 /* Make slope 4x steeper to avoid missing onsets after DTX */
410 slope_Q16 = silk_LSHIFT( slope_Q16, 2 );
411
412 for( i = 0; i < length; i++ ) {
413 frame[ i ] = silk_SMULWB( gain_Q16, frame[ i ] );
414 gain_Q16 += slope_Q16;
415 if( gain_Q16 > (opus_int32)1 << 16 ) {
416 break;
417 }
418 }
419 }
420 }
421 psPLC->last_frame_lost = 0;
422 }
423}
diff --git a/lib/rbcodec/codecs/libopus/silk/PLC.h b/lib/rbcodec/codecs/libopus/silk/PLC.h
new file mode 100644
index 0000000000..1d2d9061d9
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/PLC.h
@@ -0,0 +1,61 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_PLC_H
29#define SILK_PLC_H
30
31#include "main.h"
32
33#define BWE_COEF 0.99
34#define V_PITCH_GAIN_START_MIN_Q14 11469 /* 0.7 in Q14 */
35#define V_PITCH_GAIN_START_MAX_Q14 15565 /* 0.95 in Q14 */
36#define MAX_PITCH_LAG_MS 18
37#define RAND_BUF_SIZE 128
38#define RAND_BUF_MASK ( RAND_BUF_SIZE - 1 )
39#define LOG2_INV_LPC_GAIN_HIGH_THRES 3 /* 2^3 = 8 dB LPC gain */
40#define LOG2_INV_LPC_GAIN_LOW_THRES 8 /* 2^8 = 24 dB LPC gain */
41#define PITCH_DRIFT_FAC_Q16 655 /* 0.01 in Q16 */
42
43void silk_PLC_Reset(
44 silk_decoder_state *psDec /* I/O Decoder state */
45);
46
47void silk_PLC(
48 silk_decoder_state *psDec, /* I/O Decoder state */
49 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
50 opus_int16 frame[], /* I/O signal */
51 opus_int lost /* I Loss flag */
52);
53
54void silk_PLC_glue_frames(
55 silk_decoder_state *psDec, /* I/O decoder state */
56 opus_int16 frame[], /* I/O signal */
57 opus_int length /* I length of signal */
58);
59
60#endif
61
diff --git a/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h b/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h
new file mode 100644
index 0000000000..72ec26a67f
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h
@@ -0,0 +1,589 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_SIGPROC_FIX_H
29#define SILK_SIGPROC_FIX_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#endif
35
36/*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */
37
38#define SILK_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */
39
40#include <string.h> /* for memset(), memcpy(), memmove() */
41#include "typedef.h"
42#include "resampler_structs.h"
43#include "macros.h"
44
45
46/********************************************************************/
47/* SIGNAL PROCESSING FUNCTIONS */
48/********************************************************************/
49
50/*!
51 * Initialize/reset the resampler state for a given pair of input/output sampling rates
52*/
53opus_int silk_resampler_init(
54 silk_resampler_state_struct *S, /* I/O Resampler state */
55 opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
56 opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
57 opus_int forEnc /* I If 1: encoder; if 0: decoder */
58);
59
60/*!
61 * Resampler: convert from one sampling rate to another
62 */
63opus_int silk_resampler(
64 silk_resampler_state_struct *S, /* I/O Resampler state */
65 opus_int16 out[], /* O Output signal */
66 const opus_int16 in[], /* I Input signal */
67 opus_int32 inLen /* I Number of input samples */
68);
69
70/*!
71* Downsample 2x, mediocre quality
72*/
73void silk_resampler_down2(
74 opus_int32 *S, /* I/O State vector [ 2 ] */
75 opus_int16 *out, /* O Output signal [ len ] */
76 const opus_int16 *in, /* I Input signal [ floor(len/2) ] */
77 opus_int32 inLen /* I Number of input samples */
78);
79
80/*!
81 * Downsample by a factor 2/3, low quality
82*/
83void silk_resampler_down2_3(
84 opus_int32 *S, /* I/O State vector [ 6 ] */
85 opus_int16 *out, /* O Output signal [ floor(2*inLen/3) ] */
86 const opus_int16 *in, /* I Input signal [ inLen ] */
87 opus_int32 inLen /* I Number of input samples */
88);
89
90/*!
91 * second order ARMA filter;
92 * slower than biquad() but uses more precise coefficients
93 * can handle (slowly) varying coefficients
94 */
95void silk_biquad_alt(
96 const opus_int16 *in, /* I input signal */
97 const opus_int32 *B_Q28, /* I MA coefficients [3] */
98 const opus_int32 *A_Q28, /* I AR coefficients [2] */
99 opus_int32 *S, /* I/O State vector [2] */
100 opus_int16 *out, /* O output signal */
101 const opus_int32 len, /* I signal length (must be even) */
102 opus_int stride /* I Operate on interleaved signal if > 1 */
103);
104
105/* Variable order MA prediction error filter. */
106void silk_LPC_analysis_filter(
107 opus_int16 *out, /* O Output signal */
108 const opus_int16 *in, /* I Input signal */
109 const opus_int16 *B, /* I MA prediction coefficients, Q12 [order] */
110 const opus_int32 len, /* I Signal length */
111 const opus_int32 d /* I Filter order */
112);
113
114/* Chirp (bandwidth expand) LP AR filter */
115void silk_bwexpander(
116 opus_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */
117 const opus_int d, /* I Length of ar */
118 opus_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */
119);
120
121/* Chirp (bandwidth expand) LP AR filter */
122void silk_bwexpander_32(
123 opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */
124 const opus_int d, /* I Length of ar */
125 opus_int32 chirp_Q16 /* I Chirp factor in Q16 */
126);
127
128/* Compute inverse of LPC prediction gain, and */
129/* test if LPC coefficients are stable (all poles within unit circle) */
130opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse prediction gain in energy domain, Q30 */
131 const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */
132 const opus_int order /* I Prediction order */
133);
134
135/* For input in Q24 domain */
136opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse prediction gain in energy domain, Q30 */
137 const opus_int32 *A_Q24, /* I Prediction coefficients [order] */
138 const opus_int order /* I Prediction order */
139);
140
141/* Split signal in two decimated bands using first-order allpass filters */
142void silk_ana_filt_bank_1(
143 const opus_int16 *in, /* I Input signal [N] */
144 opus_int32 *S, /* I/O State vector [2] */
145 opus_int16 *outL, /* O Low band [N/2] */
146 opus_int16 *outH, /* O High band [N/2] */
147 const opus_int32 N /* I Number of input samples */
148);
149
150/********************************************************************/
151/* SCALAR FUNCTIONS */
152/********************************************************************/
153
154/* Approximation of 128 * log2() (exact inverse of approx 2^() below) */
155/* Convert input to a log scale */
156opus_int32 silk_lin2log(
157 const opus_int32 inLin /* I input in linear scale */
158);
159
160/* Approximation of a sigmoid function */
161opus_int silk_sigm_Q15(
162 opus_int in_Q5 /* I */
163);
164
165/* Approximation of 2^() (exact inverse of approx log2() above) */
166/* Convert input to a linear scale */
167opus_int32 silk_log2lin(
168 const opus_int32 inLog_Q7 /* I input on log scale */
169);
170
171/* Function that returns the maximum absolut value of the input vector */
172opus_int16 silk_int16_array_maxabs( /* O Maximum absolute value, max: 2^15-1 */
173 const opus_int16 *vec, /* I Input vector [len] */
174 const opus_int32 len /* I Length of input vector */
175);
176
177/* Compute number of bits to right shift the sum of squares of a vector */
178/* of int16s to make it fit in an int32 */
179void silk_sum_sqr_shift(
180 opus_int32 *energy, /* O Energy of x, after shifting to the right */
181 opus_int *shift, /* O Number of bits right shift applied to energy */
182 const opus_int16 *x, /* I Input vector */
183 opus_int len /* I Length of input vector */
184);
185
186/* Calculates the reflection coefficients from the correlation sequence */
187/* Faster than schur64(), but much less accurate. */
188/* uses SMLAWB(), requiring armv5E and higher. */
189opus_int32 silk_schur( /* O Returns residual energy */
190 opus_int16 *rc_Q15, /* O reflection coefficients [order] Q15 */
191 const opus_int32 *c, /* I correlations [order+1] */
192 const opus_int32 order /* I prediction order */
193);
194
195/* Calculates the reflection coefficients from the correlation sequence */
196/* Slower than schur(), but more accurate. */
197/* Uses SMULL(), available on armv4 */
198opus_int32 silk_schur64( /* O returns residual energy */
199 opus_int32 rc_Q16[], /* O Reflection coefficients [order] Q16 */
200 const opus_int32 c[], /* I Correlations [order+1] */
201 opus_int32 order /* I Prediction order */
202);
203
204/* Step up function, converts reflection coefficients to prediction coefficients */
205void silk_k2a(
206 opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */
207 const opus_int16 *rc_Q15, /* I Reflection coefficients [order] Q15 */
208 const opus_int32 order /* I Prediction order */
209);
210
211/* Step up function, converts reflection coefficients to prediction coefficients */
212void silk_k2a_Q16(
213 opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */
214 const opus_int32 *rc_Q16, /* I Reflection coefficients [order] Q16 */
215 const opus_int32 order /* I Prediction order */
216);
217
218/* Apply sine window to signal vector. */
219/* Window types: */
220/* 1 -> sine window from 0 to pi/2 */
221/* 2 -> sine window from pi/2 to pi */
222/* every other sample of window is linearly interpolated, for speed */
223void silk_apply_sine_window(
224 opus_int16 px_win[], /* O Pointer to windowed signal */
225 const opus_int16 px[], /* I Pointer to input signal */
226 const opus_int win_type, /* I Selects a window type */
227 const opus_int length /* I Window length, multiple of 4 */
228);
229
230/* Compute autocorrelation */
231void silk_autocorr(
232 opus_int32 *results, /* O Result (length correlationCount) */
233 opus_int *scale, /* O Scaling of the correlation vector */
234 const opus_int16 *inputData, /* I Input data to correlate */
235 const opus_int inputDataSize, /* I Length of input */
236 const opus_int correlationCount /* I Number of correlation taps to compute */
237);
238
239void silk_decode_pitch(
240 opus_int16 lagIndex, /* I */
241 opus_int8 contourIndex, /* O */
242 opus_int pitch_lags[], /* O 4 pitch values */
243 const opus_int Fs_kHz, /* I sampling frequency (kHz) */
244 const opus_int nb_subfr /* I number of sub frames */
245);
246
247opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */
248 const opus_int16 *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
249 opus_int *pitch_out, /* O 4 pitch lag values */
250 opus_int16 *lagIndex, /* O Lag Index */
251 opus_int8 *contourIndex, /* O Pitch contour Index */
252 opus_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */
253 opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
254 const opus_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */
255 const opus_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */
256 const opus_int Fs_kHz, /* I Sample frequency (kHz) */
257 const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
258 const opus_int nb_subfr /* I number of 5 ms subframes */
259);
260
261/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */
262/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */
263void silk_A2NLSF(
264 opus_int16 *NLSF, /* O Normalized Line Spectral Frequencies in Q15 (0..2^15-1) [d] */
265 opus_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */
266 const opus_int d /* I Filter order (must be even) */
267);
268
269/* compute whitening filter coefficients from normalized line spectral frequencies */
270void silk_NLSF2A(
271 opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
272 const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */
273 const opus_int d /* I filter order (should be even) */
274);
275
276void silk_insertion_sort_increasing(
277 opus_int32 *a, /* I/O Unsorted / Sorted vector */
278 opus_int *idx, /* O Index vector for the sorted elements */
279 const opus_int L, /* I Vector length */
280 const opus_int K /* I Number of correctly sorted positions */
281);
282
283void silk_insertion_sort_decreasing_int16(
284 opus_int16 *a, /* I/O Unsorted / Sorted vector */
285 opus_int *idx, /* O Index vector for the sorted elements */
286 const opus_int L, /* I Vector length */
287 const opus_int K /* I Number of correctly sorted positions */
288);
289
290void silk_insertion_sort_increasing_all_values_int16(
291 opus_int16 *a, /* I/O Unsorted / Sorted vector */
292 const opus_int L /* I Vector length */
293);
294
295/* NLSF stabilizer, for a single input data vector */
296void silk_NLSF_stabilize(
297 opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */
298 const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */
299 const opus_int L /* I Number of NLSF parameters in the input vector */
300);
301
302/* Laroia low complexity NLSF weights */
303void silk_NLSF_VQ_weights_laroia(
304 opus_int16 *pNLSFW_Q_OUT, /* O Pointer to input vector weights [D] */
305 const opus_int16 *pNLSF_Q15, /* I Pointer to input vector [D] */
306 const opus_int D /* I Input vector dimension (even) */
307);
308
309/* Compute reflection coefficients from input signal */
310void silk_burg_modified(
311 opus_int32 *res_nrg, /* O Residual energy */
312 opus_int *res_nrg_Q, /* O Residual energy Q value */
313 opus_int32 A_Q16[], /* O Prediction coefficients (length order) */
314 const opus_int16 x[], /* I Input signal, length: nb_subfr * ( D + subfr_length ) */
315 const opus_int32 minInvGain_Q30, /* I Inverse of max prediction gain */
316 const opus_int subfr_length, /* I Input signal subframe length (incl. D preceeding samples) */
317 const opus_int nb_subfr, /* I Number of subframes stacked in x */
318 const opus_int D /* I Order */
319);
320
321/* Copy and multiply a vector by a constant */
322void silk_scale_copy_vector16(
323 opus_int16 *data_out,
324 const opus_int16 *data_in,
325 opus_int32 gain_Q16, /* I Gain in Q16 */
326 const opus_int dataSize /* I Length */
327);
328
329/* Some for the LTP related function requires Q26 to work.*/
330void silk_scale_vector32_Q26_lshift_18(
331 opus_int32 *data1, /* I/O Q0/Q18 */
332 opus_int32 gain_Q26, /* I Q26 */
333 opus_int dataSize /* I length */
334);
335
336/********************************************************************/
337/* INLINE ARM MATH */
338/********************************************************************/
339
340/* return sum( inVec1[i] * inVec2[i] ) */
341opus_int32 silk_inner_prod_aligned(
342 const opus_int16 *const inVec1, /* I input vector 1 */
343 const opus_int16 *const inVec2, /* I input vector 2 */
344 const opus_int len /* I vector lengths */
345);
346
347opus_int32 silk_inner_prod_aligned_scale(
348 const opus_int16 *const inVec1, /* I input vector 1 */
349 const opus_int16 *const inVec2, /* I input vector 2 */
350 const opus_int scale, /* I number of bits to shift */
351 const opus_int len /* I vector lengths */
352);
353
354opus_int64 silk_inner_prod16_aligned_64(
355 const opus_int16 *inVec1, /* I input vector 1 */
356 const opus_int16 *inVec2, /* I input vector 2 */
357 const opus_int len /* I vector lengths */
358);
359
360/********************************************************************/
361/* MACROS */
362/********************************************************************/
363
364/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating
365 left. Output is 32bit int.
366 Note: contemporary compilers recognize the C expression below and
367 compile it into a 'ror' instruction if available. No need for inline ASM! */
368static inline opus_int32 silk_ROR32( opus_int32 a32, opus_int rot )
369{
370 opus_uint32 x = (opus_uint32) a32;
371 opus_uint32 r = (opus_uint32) rot;
372 opus_uint32 m = (opus_uint32) -rot;
373 if( rot == 0 ) {
374 return a32;
375 } else if( rot < 0 ) {
376 return (opus_int32) ((x << m) | (x >> (32 - m)));
377 } else {
378 return (opus_int32) ((x << (32 - r)) | (x >> r));
379 }
380}
381
382/* Allocate opus_int16 alligned to 4-byte memory address */
383#if EMBEDDED_ARM
384#define silk_DWORD_ALIGN __attribute__((aligned(4)))
385#else
386#define silk_DWORD_ALIGN
387#endif
388
389/* Useful Macros that can be adjusted to other platforms */
390#define silk_memcpy(dest, src, size) memcpy((dest), (src), (size))
391#define silk_memset(dest, src, size) memset((dest), (src), (size))
392#define silk_memmove(dest, src, size) memmove((dest), (src), (size))
393
394/* Fixed point macros */
395
396/* (a32 * b32) output have to be 32bit int */
397#define silk_MUL(a32, b32) ((a32) * (b32))
398
399/* (a32 * b32) output have to be 32bit uint */
400#define silk_MUL_uint(a32, b32) silk_MUL(a32, b32)
401
402/* a32 + (b32 * c32) output have to be 32bit int */
403#define silk_MLA(a32, b32, c32) silk_ADD32((a32),((b32) * (c32)))
404
405/* a32 + (b32 * c32) output have to be 32bit uint */
406#define silk_MLA_uint(a32, b32, c32) silk_MLA(a32, b32, c32)
407
408/* ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */
409#define silk_SMULTT(a32, b32) (((a32) >> 16) * ((b32) >> 16))
410
411/* a32 + ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */
412#define silk_SMLATT(a32, b32, c32) silk_ADD32((a32),((b32) >> 16) * ((c32) >> 16))
413
414#define silk_SMLALBB(a64, b16, c16) silk_ADD64((a64),(opus_int64)((opus_int32)(b16) * (opus_int32)(c16)))
415
416/* (a32 * b32) */
417#define silk_SMULL(a32, b32) ((opus_int64)(a32) * /*(opus_int64)*/(b32))
418
419/* Adds two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour
420 (just standard two's complement implementation-specific behaviour) */
421#define silk_ADD32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) + (opus_uint32)(b)))
422/* Subtractss two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour
423 (just standard two's complement implementation-specific behaviour) */
424#define silk_SUB32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) - (opus_uint32)(b)))
425
426/* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */
427#define silk_MLA_ovflw(a32, b32, c32) silk_ADD32_ovflw((a32), (opus_uint32)(b32) * (opus_uint32)(c32))
428#define silk_SMLABB_ovflw(a32, b32, c32) (silk_ADD32_ovflw((a32) , ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32))))
429
430#define silk_DIV32_16(a32, b16) ((opus_int32)((a32) / (b16)))
431#define silk_DIV32(a32, b32) ((opus_int32)((a32) / (b32)))
432
433/* These macros enables checking for overflow in silk_API_Debug.h*/
434#define silk_ADD16(a, b) ((a) + (b))
435#define silk_ADD32(a, b) ((a) + (b))
436#define silk_ADD64(a, b) ((a) + (b))
437
438#define silk_SUB16(a, b) ((a) - (b))
439#define silk_SUB32(a, b) ((a) - (b))
440#define silk_SUB64(a, b) ((a) - (b))
441
442#define silk_SAT8(a) ((a) > silk_int8_MAX ? silk_int8_MAX : \
443 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)))
444#define silk_SAT16(a) ((a) > silk_int16_MAX ? silk_int16_MAX : \
445 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)))
446#define silk_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : \
447 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)))
448
449#define silk_CHECK_FIT8(a) (a)
450#define silk_CHECK_FIT16(a) (a)
451#define silk_CHECK_FIT32(a) (a)
452
453#define silk_ADD_SAT16(a, b) (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a), (b) ) )
454#define silk_ADD_SAT64(a, b) ((((a) + (b)) & 0x8000000000000000LL) == 0 ? \
455 ((((a) & (b)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a)+(b)) : \
456 ((((a) | (b)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a)+(b)) )
457
458#define silk_SUB_SAT16(a, b) (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a), (b) ) )
459#define silk_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL) == 0 ? \
460 (( (a) & ((b)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a)-(b)) : \
461 ((((a)^0x8000000000000000LL) & (b) & 0x8000000000000000LL) ? silk_int64_MAX : (a)-(b)) )
462
463/* Saturation for positive input values */
464#define silk_POS_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : (a))
465
466/* Add with saturation for positive input values */
467#define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)))
468#define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)))
469#define silk_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)))
470#define silk_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)))
471
472#define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift))) /* shift >= 0, shift < 8 */
473#define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shift))) /* shift >= 0, shift < 16 */
474#define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shift))) /* shift >= 0, shift < 32 */
475#define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shift))) /* shift >= 0, shift < 64 */
476#define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift) /* shift >= 0, shift < 32 */
477
478#define silk_RSHIFT8(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 8 */
479#define silk_RSHIFT16(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 16 */
480#define silk_RSHIFT32(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 32 */
481#define silk_RSHIFT64(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 64 */
482#define silk_RSHIFT(a, shift) silk_RSHIFT32(a, shift) /* shift >= 0, shift < 32 */
483
484/* saturates before shifting */
485#define silk_LSHIFT_SAT32(a, shift) (silk_LSHIFT32( silk_LIMIT( (a), silk_RSHIFT32( silk_int32_MIN, (shift) ), \
486 silk_RSHIFT32( silk_int32_MAX, (shift) ) ), (shift) ))
487
488#define silk_LSHIFT_ovflw(a, shift) ((opus_int32)((opus_uint32)(a) << (shift))) /* shift >= 0, allowed to overflow */
489#define silk_LSHIFT_uint(a, shift) ((a) << (shift)) /* shift >= 0 */
490#define silk_RSHIFT_uint(a, shift) ((a) >> (shift)) /* shift >= 0 */
491
492#define silk_ADD_LSHIFT(a, b, shift) ((a) + silk_LSHIFT((b), (shift))) /* shift >= 0 */
493#define silk_ADD_LSHIFT32(a, b, shift) silk_ADD32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */
494#define silk_ADD_LSHIFT_uint(a, b, shift) ((a) + silk_LSHIFT_uint((b), (shift))) /* shift >= 0 */
495#define silk_ADD_RSHIFT(a, b, shift) ((a) + silk_RSHIFT((b), (shift))) /* shift >= 0 */
496#define silk_ADD_RSHIFT32(a, b, shift) silk_ADD32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */
497#define silk_ADD_RSHIFT_uint(a, b, shift) ((a) + silk_RSHIFT_uint((b), (shift))) /* shift >= 0 */
498#define silk_SUB_LSHIFT32(a, b, shift) silk_SUB32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */
499#define silk_SUB_RSHIFT32(a, b, shift) silk_SUB32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */
500
501/* Requires that shift > 0 */
502#define silk_RSHIFT_ROUND(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
503#define silk_RSHIFT_ROUND64(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
504
505/* Number of rightshift required to fit the multiplication */
506#define silk_NSHIFT_MUL_32_32(a, b) ( -(31- (32-silk_CLZ32(silk_abs(a)) + (32-silk_CLZ32(silk_abs(b))))) )
507#define silk_NSHIFT_MUL_16_16(a, b) ( -(15- (16-silk_CLZ16(silk_abs(a)) + (16-silk_CLZ16(silk_abs(b))))) )
508
509
510#define silk_min(a, b) (((a) < (b)) ? (a) : (b))
511#define silk_max(a, b) (((a) > (b)) ? (a) : (b))
512
513/* Macro to convert floating-point constants to fixed-point */
514#define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5))
515
516/* silk_min() versions with typecast in the function call */
517static inline opus_int silk_min_int(opus_int a, opus_int b)
518{
519 return (((a) < (b)) ? (a) : (b));
520}
521static inline opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
522{
523 return (((a) < (b)) ? (a) : (b));
524}
525static inline opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
526{
527 return (((a) < (b)) ? (a) : (b));
528}
529static inline opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
530{
531 return (((a) < (b)) ? (a) : (b));
532}
533
534/* silk_min() versions with typecast in the function call */
535static inline opus_int silk_max_int(opus_int a, opus_int b)
536{
537 return (((a) > (b)) ? (a) : (b));
538}
539static inline opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
540{
541 return (((a) > (b)) ? (a) : (b));
542}
543static inline opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
544{
545 return (((a) > (b)) ? (a) : (b));
546}
547static inline opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
548{
549 return (((a) > (b)) ? (a) : (b));
550}
551
552#define silk_LIMIT( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
553 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))))
554
555#define silk_LIMIT_int silk_LIMIT
556#define silk_LIMIT_16 silk_LIMIT
557#define silk_LIMIT_32 silk_LIMIT
558
559#define silk_abs(a) (((a) > 0) ? (a) : -(a)) /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
560#define silk_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))) - ((a) >> (8 * sizeof(a) - 1)))
561#define silk_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31))
562#define silk_abs_int64(a) (((a) > 0) ? (a) : -(a))
563
564#define silk_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ))
565
566/* PSEUDO-RANDOM GENERATOR */
567/* Make sure to store the result as the seed for the next call (also in between */
568/* frames), otherwise result won't be random at all. When only using some of the */
569/* bits, take the most significant bits by right-shifting. */
570#define silk_RAND(seed) (silk_MLA_ovflw(907633515, (seed), 196314165))
571
572/* Add some multiplication functions that can be easily mapped to ARM. */
573
574/* silk_SMMUL: Signed top word multiply.
575 ARMv6 2 instruction cycles.
576 ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.(except xM)*/
577/*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/
578/* the following seems faster on x86 */
579#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL((a32), (b32)), 32)
580
581#include "Inlines.h"
582#include "MacroCount.h"
583#include "MacroDebug.h"
584
585#ifdef __cplusplus
586}
587#endif
588
589#endif /* SILK_SIGPROC_FIX_H */
diff --git a/lib/rbcodec/codecs/libopus/silk/bwexpander.c b/lib/rbcodec/codecs/libopus/silk/bwexpander.c
new file mode 100644
index 0000000000..9bb5f62810
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/bwexpander.c
@@ -0,0 +1,51 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34/* Chirp (bandwidth expand) LP AR filter */
35void silk_bwexpander(
36 opus_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */
37 const opus_int d, /* I Length of ar */
38 opus_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */
39)
40{
41 opus_int i;
42 opus_int32 chirp_minus_one_Q16 = chirp_Q16 - 65536;
43
44 /* NB: Dont use silk_SMULWB, instead of silk_RSHIFT_ROUND( silk_MUL(), 16 ), below. */
45 /* Bias in silk_SMULWB can lead to unstable filters */
46 for( i = 0; i < d - 1; i++ ) {
47 ar[ i ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ i ] ), 16 );
48 chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 );
49 }
50 ar[ d - 1 ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ d - 1 ] ), 16 );
51}
diff --git a/lib/rbcodec/codecs/libopus/silk/bwexpander_32.c b/lib/rbcodec/codecs/libopus/silk/bwexpander_32.c
new file mode 100644
index 0000000000..fe3cc4c9d1
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/bwexpander_32.c
@@ -0,0 +1,50 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34/* Chirp (bandwidth expand) LP AR filter */
35void silk_bwexpander_32(
36 opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */
37 const opus_int d, /* I Length of ar */
38 opus_int32 chirp_Q16 /* I Chirp factor in Q16 */
39)
40{
41 opus_int i;
42 opus_int32 chirp_minus_one_Q16 = chirp_Q16 - 65536;
43
44 for( i = 0; i < d - 1; i++ ) {
45 ar[ i ] = silk_SMULWW( chirp_Q16, ar[ i ] );
46 chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 );
47 }
48 ar[ d - 1 ] = silk_SMULWW( chirp_Q16, ar[ d - 1 ] );
49}
50
diff --git a/lib/rbcodec/codecs/libopus/silk/code_signs.c b/lib/rbcodec/codecs/libopus/silk/code_signs.c
new file mode 100644
index 0000000000..3903eb1f16
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/code_signs.c
@@ -0,0 +1,115 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/*#define silk_enc_map(a) ((a) > 0 ? 1 : 0)*/
35/*#define silk_dec_map(a) ((a) > 0 ? 1 : -1)*/
36/* shifting avoids if-statement */
37#define silk_enc_map(a) ( silk_RSHIFT( (a), 15 ) + 1 )
38#define silk_dec_map(a) ( silk_LSHIFT( (a), 1 ) - 1 )
39
40/* Encodes signs of excitation */
41void silk_encode_signs(
42 ec_enc *psRangeEnc, /* I/O Compressor data structure */
43 const opus_int8 pulses[], /* I pulse signal */
44 opus_int length, /* I length of input */
45 const opus_int signalType, /* I Signal type */
46 const opus_int quantOffsetType, /* I Quantization offset type */
47 const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
48)
49{
50 opus_int i, j, p;
51 opus_uint8 icdf[ 2 ];
52 const opus_int8 *q_ptr;
53 const opus_uint8 *icdf_ptr;
54
55 icdf[ 1 ] = 0;
56 q_ptr = pulses;
57 i = silk_SMULBB( 7, silk_ADD_LSHIFT( quantOffsetType, signalType, 1 ) );
58 icdf_ptr = &silk_sign_iCDF[ i ];
59 length = silk_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH );
60 for( i = 0; i < length; i++ ) {
61 p = sum_pulses[ i ];
62 if( p > 0 ) {
63 icdf[ 0 ] = icdf_ptr[ silk_min( p & 0x1F, 6 ) ];
64 for( j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++ ) {
65 if( q_ptr[ j ] != 0 ) {
66 ec_enc_icdf( psRangeEnc, silk_enc_map( q_ptr[ j ]), icdf, 8 );
67 }
68 }
69 }
70 q_ptr += SHELL_CODEC_FRAME_LENGTH;
71 }
72}
73
74/* Decodes signs of excitation */
75void silk_decode_signs(
76 ec_dec *psRangeDec, /* I/O Compressor data structure */
77 opus_int pulses[], /* I/O pulse signal */
78 opus_int length, /* I length of input */
79 const opus_int signalType, /* I Signal type */
80 const opus_int quantOffsetType, /* I Quantization offset type */
81 const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
82)
83{
84 opus_int i, j, p;
85 opus_uint8 icdf[ 2 ];
86 opus_int *q_ptr;
87 const opus_uint8 *icdf_ptr;
88
89 icdf[ 1 ] = 0;
90 q_ptr = pulses;
91 i = silk_SMULBB( 7, silk_ADD_LSHIFT( quantOffsetType, signalType, 1 ) );
92 icdf_ptr = &silk_sign_iCDF[ i ];
93 length = silk_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH );
94 for( i = 0; i < length; i++ ) {
95 p = sum_pulses[ i ];
96 if( p > 0 ) {
97 icdf[ 0 ] = icdf_ptr[ silk_min( p & 0x1F, 6 ) ];
98 for( j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++ ) {
99 if( q_ptr[ j ] > 0 ) {
100 /* attach sign */
101#if 0
102 /* conditional implementation */
103 if( ec_dec_icdf( psRangeDec, icdf, 8 ) == 0 ) {
104 q_ptr[ j ] = -q_ptr[ j ];
105 }
106#else
107 /* implementation with shift, subtraction, multiplication */
108 q_ptr[ j ] *= silk_dec_map( ec_dec_icdf( psRangeDec, icdf, 8 ) );
109#endif
110 }
111 }
112 }
113 q_ptr += SHELL_CODEC_FRAME_LENGTH;
114 }
115}
diff --git a/lib/rbcodec/codecs/libopus/silk/control.h b/lib/rbcodec/codecs/libopus/silk/control.h
new file mode 100644
index 0000000000..c52ec3fe38
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/control.h
@@ -0,0 +1,139 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_CONTROL_H
29#define SILK_CONTROL_H
30
31#include "typedef.h"
32
33#ifdef __cplusplus
34extern "C"
35{
36#endif
37
38/* Decoder API flags */
39#define FLAG_DECODE_NORMAL 0
40#define FLAG_PACKET_LOST 1
41#define FLAG_DECODE_LBRR 2
42
43/***********************************************/
44/* Structure for controlling encoder operation */
45/***********************************************/
46typedef struct {
47 /* I: Number of channels; 1/2 */
48 opus_int32 nChannelsAPI;
49
50 /* I: Number of channels; 1/2 */
51 opus_int32 nChannelsInternal;
52
53 /* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */
54 opus_int32 API_sampleRate;
55
56 /* I: Maximum internal sampling rate in Hertz; 8000/12000/16000 */
57 opus_int32 maxInternalSampleRate;
58
59 /* I: Minimum internal sampling rate in Hertz; 8000/12000/16000 */
60 opus_int32 minInternalSampleRate;
61
62 /* I: Soft request for internal sampling rate in Hertz; 8000/12000/16000 */
63 opus_int32 desiredInternalSampleRate;
64
65 /* I: Number of samples per packet in milliseconds; 10/20/40/60 */
66 opus_int payloadSize_ms;
67
68 /* I: Bitrate during active speech in bits/second; internally limited */
69 opus_int32 bitRate;
70
71 /* I: Uplink packet loss in percent (0-100) */
72 opus_int packetLossPercentage;
73
74 /* I: Complexity mode; 0 is lowest, 10 is highest complexity */
75 opus_int complexity;
76
77 /* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */
78 opus_int useInBandFEC;
79
80 /* I: Flag to enable discontinuous transmission (DTX); 0/1 */
81 opus_int useDTX;
82
83 /* I: Flag to use constant bitrate */
84 opus_int useCBR;
85
86 /* I: Maximum number of bits allowed for the frame */
87 opus_int maxBits;
88
89 /* I: Causes a smooth downmix to mono */
90 opus_int toMono;
91
92 /* I: Opus encoder is allowing us to switch bandwidth */
93 opus_int opusCanSwitch;
94
95 /* O: Internal sampling rate used, in Hertz; 8000/12000/16000 */
96 opus_int32 internalSampleRate;
97
98 /* O: Flag that bandwidth switching is allowed (because low voice activity) */
99 opus_int allowBandwidthSwitch;
100
101 /* O: Flag that SILK runs in WB mode without variable LP filter (use for switching between WB/SWB/FB) */
102 opus_int inWBmodeWithoutVariableLP;
103
104 /* O: Stereo width */
105 opus_int stereoWidth_Q14;
106
107 /* O: Tells the Opus encoder we're ready to switch */
108 opus_int switchReady;
109
110} silk_EncControlStruct;
111
112/**************************************************************************/
113/* Structure for controlling decoder operation and reading decoder status */
114/**************************************************************************/
115typedef struct {
116 /* I: Number of channels; 1/2 */
117 opus_int32 nChannelsAPI;
118
119 /* I: Number of channels; 1/2 */
120 opus_int32 nChannelsInternal;
121
122 /* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */
123 opus_int32 API_sampleRate;
124
125 /* I: Internal sampling rate used, in Hertz; 8000/12000/16000 */
126 opus_int32 internalSampleRate;
127
128 /* I: Number of samples per packet in milliseconds; 10/20/40/60 */
129 opus_int payloadSize_ms;
130
131 /* O: Pitch lag of previous frame (0 if unvoiced), measured in samples at 48 kHz */
132 opus_int prevPitchLag;
133} silk_DecControlStruct;
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/dec_API.c b/lib/rbcodec/codecs/libopus/silk/dec_API.c
new file mode 100644
index 0000000000..908e6033b1
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/dec_API.c
@@ -0,0 +1,392 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31#include "API.h"
32#include "main.h"
33#include "stack_alloc.h"
34
35/************************/
36/* Decoder Super Struct */
37/************************/
38typedef struct {
39 silk_decoder_state channel_state[ DECODER_NUM_CHANNELS ];
40 stereo_dec_state sStereo;
41 opus_int nChannelsAPI;
42 opus_int nChannelsInternal;
43 opus_int prev_decode_only_middle;
44} silk_decoder;
45
46/*********************/
47/* Decoder functions */
48/*********************/
49
50opus_int silk_Get_Decoder_Size( /* O Returns error code */
51 opus_int *decSizeBytes /* O Number of bytes in SILK decoder state */
52)
53{
54 opus_int ret = SILK_NO_ERROR;
55
56 *decSizeBytes = sizeof( silk_decoder );
57
58 return ret;
59}
60
61/* Reset decoder state */
62opus_int silk_InitDecoder( /* O Returns error code */
63 void *decState /* I/O State */
64)
65{
66 opus_int n, ret = SILK_NO_ERROR;
67 silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state;
68
69 for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) {
70 ret = silk_init_decoder( &channel_state[ n ] );
71 }
72
73 return ret;
74}
75
76/* Decode a frame */
77opus_int silk_Decode( /* O Returns error code */
78 void* decState, /* I/O State */
79 silk_DecControlStruct* decControl, /* I/O Control Structure */
80 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
81 opus_int newPacketFlag, /* I Indicates first decoder call for this packet */
82 ec_dec *psRangeDec, /* I/O Compressor data structure */
83 opus_int16 *samplesOut, /* O Decoded output speech vector */
84 opus_int32 *nSamplesOut /* O Number of samples decoded */
85)
86{
87 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR;
88 opus_int32 nSamplesOutDec, LBRR_symbol;
89 opus_int16 *samplesOut1_tmp[ 2 ];
90 VARDECL( opus_int16, samplesOut1_tmp_storage );
91 VARDECL( opus_int16, samplesOut2_tmp );
92 opus_int32 MS_pred_Q13[ 2 ] = { 0 };
93 opus_int16 *resample_out_ptr;
94 silk_decoder *psDec = ( silk_decoder * )decState;
95 silk_decoder_state *channel_state = psDec->channel_state;
96 opus_int has_side;
97 opus_int stereo_to_mono;
98 SAVE_STACK;
99
100 /**********************************/
101 /* Test if first frame in payload */
102 /**********************************/
103 if( newPacketFlag ) {
104 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
105 channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in packet */
106 }
107 }
108
109 /* If Mono -> Stereo transition in bitstream: init state of second channel */
110 if( decControl->nChannelsInternal > psDec->nChannelsInternal ) {
111 ret += silk_init_decoder( &channel_state[ 1 ] );
112 }
113
114 stereo_to_mono = decControl->nChannelsInternal == 1 && psDec->nChannelsInternal == 2 &&
115 ( decControl->internalSampleRate == 1000*channel_state[ 0 ].fs_kHz );
116
117 if( channel_state[ 0 ].nFramesDecoded == 0 ) {
118 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
119 opus_int fs_kHz_dec;
120 if( decControl->payloadSize_ms == 0 ) {
121 /* Assuming packet loss, use 10 ms */
122 channel_state[ n ].nFramesPerPacket = 1;
123 channel_state[ n ].nb_subfr = 2;
124 } else if( decControl->payloadSize_ms == 10 ) {
125 channel_state[ n ].nFramesPerPacket = 1;
126 channel_state[ n ].nb_subfr = 2;
127 } else if( decControl->payloadSize_ms == 20 ) {
128 channel_state[ n ].nFramesPerPacket = 1;
129 channel_state[ n ].nb_subfr = 4;
130 } else if( decControl->payloadSize_ms == 40 ) {
131 channel_state[ n ].nFramesPerPacket = 2;
132 channel_state[ n ].nb_subfr = 4;
133 } else if( decControl->payloadSize_ms == 60 ) {
134 channel_state[ n ].nFramesPerPacket = 3;
135 channel_state[ n ].nb_subfr = 4;
136 } else {
137 silk_assert( 0 );
138 RESTORE_STACK;
139 return SILK_DEC_INVALID_FRAME_SIZE;
140 }
141 fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1;
142 if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) {
143 silk_assert( 0 );
144 RESTORE_STACK;
145 return SILK_DEC_INVALID_SAMPLING_FREQUENCY;
146 }
147 ret += silk_decoder_set_fs( &channel_state[ n ], fs_kHz_dec, decControl->API_sampleRate );
148 }
149 }
150
151 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 && ( psDec->nChannelsAPI == 1 || psDec->nChannelsInternal == 1 ) ) {
152 silk_memset( psDec->sStereo.pred_prev_Q13, 0, sizeof( psDec->sStereo.pred_prev_Q13 ) );
153 silk_memset( psDec->sStereo.sSide, 0, sizeof( psDec->sStereo.sSide ) );
154 silk_memcpy( &channel_state[ 1 ].resampler_state, &channel_state[ 0 ].resampler_state, sizeof( silk_resampler_state_struct ) );
155 }
156 psDec->nChannelsAPI = decControl->nChannelsAPI;
157 psDec->nChannelsInternal = decControl->nChannelsInternal;
158
159 if( decControl->API_sampleRate > (opus_int32)MAX_API_FS_KHZ * 1000 || decControl->API_sampleRate < 8000 ) {
160 ret = SILK_DEC_INVALID_SAMPLING_FREQUENCY;
161 RESTORE_STACK;
162 return( ret );
163 }
164
165 if( lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0 ) {
166 /* First decoder call for this payload */
167 /* Decode VAD flags and LBRR flag */
168 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
169 for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) {
170 channel_state[ n ].VAD_flags[ i ] = ec_dec_bit_logp(psRangeDec, 1);
171 }
172 channel_state[ n ].LBRR_flag = ec_dec_bit_logp(psRangeDec, 1);
173 }
174 /* Decode LBRR flags */
175 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
176 silk_memset( channel_state[ n ].LBRR_flags, 0, sizeof( channel_state[ n ].LBRR_flags ) );
177 if( channel_state[ n ].LBRR_flag ) {
178 if( channel_state[ n ].nFramesPerPacket == 1 ) {
179 channel_state[ n ].LBRR_flags[ 0 ] = 1;
180 } else {
181 LBRR_symbol = ec_dec_icdf( psRangeDec, silk_LBRR_flags_iCDF_ptr[ channel_state[ n ].nFramesPerPacket - 2 ], 8 ) + 1;
182 for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) {
183 channel_state[ n ].LBRR_flags[ i ] = silk_RSHIFT( LBRR_symbol, i ) & 1;
184 }
185 }
186 }
187 }
188
189 if( lostFlag == FLAG_DECODE_NORMAL ) {
190 /* Regular decoding: skip all LBRR data */
191 for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) {
192 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
193 if( channel_state[ n ].LBRR_flags[ i ] ) {
194 opus_int pulses[ MAX_FRAME_LENGTH ];
195 opus_int condCoding;
196
197 if( decControl->nChannelsInternal == 2 && n == 0 ) {
198 silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 );
199 if( channel_state[ 1 ].LBRR_flags[ i ] == 0 ) {
200 silk_stereo_decode_mid_only( psRangeDec, &decode_only_middle );
201 }
202 }
203 /* Use conditional coding if previous frame available */
204 if( i > 0 && channel_state[ n ].LBRR_flags[ i - 1 ] ) {
205 condCoding = CODE_CONDITIONALLY;
206 } else {
207 condCoding = CODE_INDEPENDENTLY;
208 }
209 silk_decode_indices( &channel_state[ n ], psRangeDec, i, 1, condCoding );
210 silk_decode_pulses( psRangeDec, pulses, channel_state[ n ].indices.signalType,
211 channel_state[ n ].indices.quantOffsetType, channel_state[ n ].frame_length );
212 }
213 }
214 }
215 }
216 }
217
218 /* Get MS predictor index */
219 if( decControl->nChannelsInternal == 2 ) {
220 if( lostFlag == FLAG_DECODE_NORMAL ||
221 ( lostFlag == FLAG_DECODE_LBRR && channel_state[ 0 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 1 ) )
222 {
223 silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 );
224 /* For LBRR data, decode mid-only flag only if side-channel's LBRR flag is false */
225 if( ( lostFlag == FLAG_DECODE_NORMAL && channel_state[ 1 ].VAD_flags[ channel_state[ 0 ].nFramesDecoded ] == 0 ) ||
226 ( lostFlag == FLAG_DECODE_LBRR && channel_state[ 1 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 0 ) )
227 {
228 silk_stereo_decode_mid_only( psRangeDec, &decode_only_middle );
229 } else {
230 decode_only_middle = 0;
231 }
232 } else {
233 for( n = 0; n < 2; n++ ) {
234 MS_pred_Q13[ n ] = psDec->sStereo.pred_prev_Q13[ n ];
235 }
236 }
237 }
238
239 /* Reset side channel decoder prediction memory for first frame with side coding */
240 if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec->prev_decode_only_middle == 1 ) {
241 silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_state[ 1 ].outBuf) );
242 silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->channel_state[ 1 ].sLPC_Q14_buf) );
243 psDec->channel_state[ 1 ].lagPrev = 100;
244 psDec->channel_state[ 1 ].LastGainIndex = 10;
245 psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY;
246 psDec->channel_state[ 1 ].first_frame_after_reset = 1;
247 }
248
249 ALLOC( samplesOut1_tmp_storage,
250 decControl->nChannelsInternal*(
251 channel_state[ 0 ].frame_length + 2 ),
252 opus_int16 );
253 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage;
254 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage
255 + channel_state[ 0 ].frame_length + 2;
256
257 if( lostFlag == FLAG_DECODE_NORMAL ) {
258 has_side = !decode_only_middle;
259 } else {
260 has_side = !psDec->prev_decode_only_middle
261 || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 );
262 }
263 /* Call decoder for one frame */
264 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
265 if( n == 0 || has_side ) {
266 opus_int FrameIndex;
267 opus_int condCoding;
268
269 FrameIndex = channel_state[ 0 ].nFramesDecoded - n;
270 /* Use independent coding if no previous frame available */
271 if( FrameIndex <= 0 ) {
272 condCoding = CODE_INDEPENDENTLY;
273 } else if( lostFlag == FLAG_DECODE_LBRR ) {
274 condCoding = channel_state[ n ].LBRR_flags[ FrameIndex - 1 ] ? CODE_CONDITIONALLY : CODE_INDEPENDENTLY;
275 } else if( n > 0 && psDec->prev_decode_only_middle ) {
276 /* If we skipped a side frame in this packet, we don't
277 need LTP scaling; the LTP state is well-defined. */
278 condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING;
279 } else {
280 condCoding = CODE_CONDITIONALLY;
281 }
282 ret += silk_decode_frame( &channel_state[ n ], psRangeDec, &samplesOut1_tmp[ n ][ 2 ], &nSamplesOutDec, lostFlag, condCoding);
283 } else {
284 silk_memset( &samplesOut1_tmp[ n ][ 2 ], 0, nSamplesOutDec * sizeof( opus_int16 ) );
285 }
286 channel_state[ n ].nFramesDecoded++;
287 }
288
289 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 ) {
290 /* Convert Mid/Side to Left/Right */
291 silk_stereo_MS_to_LR( &psDec->sStereo, samplesOut1_tmp[ 0 ], samplesOut1_tmp[ 1 ], MS_pred_Q13, channel_state[ 0 ].fs_kHz, nSamplesOutDec );
292 } else {
293 /* Buffering */
294 silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus_int16 ) );
295 silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec ], 2 * sizeof( opus_int16 ) );
296 }
297
298 /* Number of output samples */
299 *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) );
300
301 /* Set up pointers to temp buffers */
302 ALLOC( samplesOut2_tmp,
303 decControl->nChannelsAPI == 2 ? *nSamplesOut : 0, opus_int16 );
304 if( decControl->nChannelsAPI == 2 ) {
305 resample_out_ptr = samplesOut2_tmp;
306 } else {
307 resample_out_ptr = samplesOut;
308 }
309
310 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInternal ); n++ ) {
311
312 /* Resample decoded signal to API_sampleRate */
313 ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec );
314
315 /* Interleave if stereo output and stereo stream */
316 if( decControl->nChannelsAPI == 2 ) {
317 for( i = 0; i < *nSamplesOut; i++ ) {
318 samplesOut[ n + 2 * i ] = resample_out_ptr[ i ];
319 }
320 }
321 }
322
323 /* Create two channel output from mono stream */
324 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 1 ) {
325 if ( stereo_to_mono ){
326 /* Resample right channel for newly collapsed stereo just in case
327 we weren't doing collapsing when switching to mono */
328 ret += silk_resampler( &channel_state[ 1 ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ 0 ][ 1 ], nSamplesOutDec );
329
330 for( i = 0; i < *nSamplesOut; i++ ) {
331 samplesOut[ 1 + 2 * i ] = resample_out_ptr[ i ];
332 }
333 } else {
334 for( i = 0; i < *nSamplesOut; i++ ) {
335 samplesOut[ 1 + 2 * i ] = samplesOut[ 0 + 2 * i ];
336 }
337 }
338 }
339
340 /* Export pitch lag, measured at 48 kHz sampling rate */
341 if( channel_state[ 0 ].prevSignalType == TYPE_VOICED ) {
342 int mult_tab[ 3 ] = { 6, 4, 3 };
343 decControl->prevPitchLag = channel_state[ 0 ].lagPrev * mult_tab[ ( channel_state[ 0 ].fs_kHz - 8 ) >> 2 ];
344 } else {
345 decControl->prevPitchLag = 0;
346 }
347
348 if( lostFlag == FLAG_PACKET_LOST ) {
349 /* On packet loss, remove the gain clamping to prevent having the energy "bounce back"
350 if we lose packets when the energy is going down */
351 for ( i = 0; i < psDec->nChannelsInternal; i++ )
352 psDec->channel_state[ i ].LastGainIndex = 10;
353 } else {
354 psDec->prev_decode_only_middle = decode_only_middle;
355 }
356 RESTORE_STACK;
357 return ret;
358}
359
360#if 0
361/* Getting table of contents for a packet */
362opus_int silk_get_TOC(
363 const opus_uint8 *payload, /* I Payload data */
364 const opus_int nBytesIn, /* I Number of input bytes */
365 const opus_int nFramesPerPayload, /* I Number of SILK frames per payload */
366 silk_TOC_struct *Silk_TOC /* O Type of content */
367)
368{
369 opus_int i, flags, ret = SILK_NO_ERROR;
370
371 if( nBytesIn < 1 ) {
372 return -1;
373 }
374 if( nFramesPerPayload < 0 || nFramesPerPayload > 3 ) {
375 return -1;
376 }
377
378 silk_memset( Silk_TOC, 0, sizeof( *Silk_TOC ) );
379
380 /* For stereo, extract the flags for the mid channel */
381 flags = silk_RSHIFT( payload[ 0 ], 7 - nFramesPerPayload ) & ( silk_LSHIFT( 1, nFramesPerPayload + 1 ) - 1 );
382
383 Silk_TOC->inbandFECFlag = flags & 1;
384 for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) {
385 flags = silk_RSHIFT( flags, 1 );
386 Silk_TOC->VADFlags[ i ] = flags & 1;
387 Silk_TOC->VADFlag |= flags & 1;
388 }
389
390 return ret;
391}
392#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_core.c b/lib/rbcodec/codecs/libopus/silk/decode_core.c
new file mode 100644
index 0000000000..f4ed7e0f6d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_core.c
@@ -0,0 +1,238 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33#include "stack_alloc.h"
34
35/**********************************************************/
36/* Core decoder. Performs inverse NSQ operation LTP + LPC */
37/**********************************************************/
38void silk_decode_core(
39 silk_decoder_state *psDec, /* I/O Decoder state */
40 silk_decoder_control *psDecCtrl, /* I Decoder control */
41 opus_int16 xq[], /* O Decoded speech */
42 const opus_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */
43)
44{
45 opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
46 opus_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
47 VARDECL( opus_int16, sLTP );
48 VARDECL( opus_int32, sLTP_Q15 );
49 opus_int32 LTP_pred_Q13, LPC_pred_Q10, Gain_Q10, inv_gain_Q31, gain_adj_Q16, rand_seed, offset_Q10;
50 opus_int32 *pred_lag_ptr, *pexc_Q14, *pres_Q14;
51 VARDECL( opus_int32, res_Q14 );
52 VARDECL( opus_int32, sLPC_Q14 );
53 SAVE_STACK;
54
55 silk_assert( psDec->prev_gain_Q16 != 0 );
56
57 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 );
58 ALLOC( sLTP_Q15, psDec->ltp_mem_length + psDec->frame_length, opus_int32 );
59 ALLOC( res_Q14, psDec->subfr_length, opus_int32 );
60 ALLOC( sLPC_Q14, psDec->subfr_length + MAX_LPC_ORDER, opus_int32 );
61
62 offset_Q10 = silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ][ psDec->indices.quantOffsetType ];
63
64 if( psDec->indices.NLSFInterpCoef_Q2 < 1 << 2 ) {
65 NLSF_interpolation_flag = 1;
66 } else {
67 NLSF_interpolation_flag = 0;
68 }
69
70 /* Decode excitation */
71 rand_seed = psDec->indices.Seed;
72 for( i = 0; i < psDec->frame_length; i++ ) {
73 rand_seed = silk_RAND( rand_seed );
74 psDec->exc_Q14[ i ] = silk_LSHIFT( (opus_int32)pulses[ i ], 14 );
75 if( psDec->exc_Q14[ i ] > 0 ) {
76 psDec->exc_Q14[ i ] -= QUANT_LEVEL_ADJUST_Q10 << 4;
77 } else
78 if( psDec->exc_Q14[ i ] < 0 ) {
79 psDec->exc_Q14[ i ] += QUANT_LEVEL_ADJUST_Q10 << 4;
80 }
81 psDec->exc_Q14[ i ] += offset_Q10 << 4;
82 if( rand_seed < 0 ) {
83 psDec->exc_Q14[ i ] = -psDec->exc_Q14[ i ];
84 }
85
86 rand_seed = silk_ADD32_ovflw( rand_seed, pulses[ i ] );
87 }
88
89 /* Copy LPC state */
90 silk_memcpy( sLPC_Q14, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof( opus_int32 ) );
91
92 pexc_Q14 = psDec->exc_Q14;
93 pxq = xq;
94 sLTP_buf_idx = psDec->ltp_mem_length;
95 /* Loop over subframes */
96 for( k = 0; k < psDec->nb_subfr; k++ ) {
97 pres_Q14 = res_Q14;
98 A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ];
99
100 /* Preload LPC coeficients to array on stack. Gives small performance gain */
101 silk_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( opus_int16 ) );
102 B_Q14 = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ];
103 signalType = psDec->indices.signalType;
104
105 Gain_Q10 = silk_RSHIFT( psDecCtrl->Gains_Q16[ k ], 6 );
106 inv_gain_Q31 = silk_INVERSE32_varQ( psDecCtrl->Gains_Q16[ k ], 47 );
107
108 /* Calculate gain adjustment factor */
109 if( psDecCtrl->Gains_Q16[ k ] != psDec->prev_gain_Q16 ) {
110 gain_adj_Q16 = silk_DIV32_varQ( psDec->prev_gain_Q16, psDecCtrl->Gains_Q16[ k ], 16 );
111
112 /* Scale short term state */
113 for( i = 0; i < MAX_LPC_ORDER; i++ ) {
114 sLPC_Q14[ i ] = silk_SMULWW( gain_adj_Q16, sLPC_Q14[ i ] );
115 }
116 } else {
117 gain_adj_Q16 = (opus_int32)1 << 16;
118 }
119
120 /* Save inv_gain */
121 silk_assert( inv_gain_Q31 != 0 );
122 psDec->prev_gain_Q16 = psDecCtrl->Gains_Q16[ k ];
123
124 /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */
125 if( psDec->lossCnt && psDec->prevSignalType == TYPE_VOICED &&
126 psDec->indices.signalType != TYPE_VOICED && k < MAX_NB_SUBFR/2 ) {
127
128 silk_memset( B_Q14, 0, LTP_ORDER * sizeof( opus_int16 ) );
129 B_Q14[ LTP_ORDER/2 ] = SILK_FIX_CONST( 0.25, 14 );
130
131 signalType = TYPE_VOICED;
132 psDecCtrl->pitchL[ k ] = psDec->lagPrev;
133 }
134
135 if( signalType == TYPE_VOICED ) {
136 /* Voiced */
137 lag = psDecCtrl->pitchL[ k ];
138
139 /* Re-whitening */
140 if( k == 0 || ( k == 2 && NLSF_interpolation_flag ) ) {
141 /* Rewhiten with new A coefs */
142 start_idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2;
143 silk_assert( start_idx > 0 );
144
145 if( k == 2 ) {
146 silk_memcpy( &psDec->outBuf[ psDec->ltp_mem_length ], xq, 2 * psDec->subfr_length * sizeof( opus_int16 ) );
147 }
148
149 silk_LPC_analysis_filter( &sLTP[ start_idx ], &psDec->outBuf[ start_idx + k * psDec->subfr_length ],
150 A_Q12, psDec->ltp_mem_length - start_idx, psDec->LPC_order );
151
152 /* After rewhitening the LTP state is unscaled */
153 if( k == 0 ) {
154 /* Do LTP downscaling to reduce inter-packet dependency */
155 inv_gain_Q31 = silk_LSHIFT( silk_SMULWB( inv_gain_Q31, psDecCtrl->LTP_scale_Q14 ), 2 );
156 }
157 for( i = 0; i < lag + LTP_ORDER/2; i++ ) {
158 sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWB( inv_gain_Q31, sLTP[ psDec->ltp_mem_length - i - 1 ] );
159 }
160 } else {
161 /* Update LTP state when Gain changes */
162 if( gain_adj_Q16 != (opus_int32)1 << 16 ) {
163 for( i = 0; i < lag + LTP_ORDER/2; i++ ) {
164 sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWW( gain_adj_Q16, sLTP_Q15[ sLTP_buf_idx - i - 1 ] );
165 }
166 }
167 }
168 }
169
170 /* Long-term prediction */
171 if( signalType == TYPE_VOICED ) {
172 /* Set up pointer */
173 pred_lag_ptr = &sLTP_Q15[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
174 for( i = 0; i < psDec->subfr_length; i++ ) {
175 /* Unrolled loop */
176 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
177 LTP_pred_Q13 = 2;
178 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ 0 ], B_Q14[ 0 ] );
179 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );
180 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );
181 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );
182 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );
183 pred_lag_ptr++;
184
185 /* Generate LPC excitation */
186 pres_Q14[ i ] = silk_ADD_LSHIFT32( pexc_Q14[ i ], LTP_pred_Q13, 1 );
187
188 /* Update states */
189 sLTP_Q15[ sLTP_buf_idx ] = silk_LSHIFT( pres_Q14[ i ], 1 );
190 sLTP_buf_idx++;
191 }
192 } else {
193 pres_Q14 = pexc_Q14;
194 }
195
196 for( i = 0; i < psDec->subfr_length; i++ ) {
197 /* Short-term prediction */
198 silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 );
199 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
200 LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 );
201 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] );
202 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] );
203 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] );
204 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] );
205 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] );
206 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] );
207 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] );
208 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] );
209 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] );
210 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] );
211 if( psDec->LPC_order == 16 ) {
212 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12_tmp[ 10 ] );
213 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12_tmp[ 11 ] );
214 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12_tmp[ 12 ] );
215 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12_tmp[ 13 ] );
216 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12_tmp[ 14 ] );
217 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12_tmp[ 15 ] );
218 }
219
220 /* Add prediction to LPC excitation */
221 sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( pres_Q14[ i ], LPC_pred_Q10, 4 );
222
223 /* Scale with gain */
224 pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) );
225 }
226
227 /* DEBUG_STORE_DATA( dec.pcm, pxq, psDec->subfr_length * sizeof( opus_int16 ) ) */
228
229 /* Update LPC filter state */
230 silk_memcpy( sLPC_Q14, &sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
231 pexc_Q14 += psDec->subfr_length;
232 pxq += psDec->subfr_length;
233 }
234
235 /* Save LPC state */
236 silk_memcpy( psDec->sLPC_Q14_buf, sLPC_Q14, MAX_LPC_ORDER * sizeof( opus_int32 ) );
237 RESTORE_STACK;
238}
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_frame.c b/lib/rbcodec/codecs/libopus/silk/decode_frame.c
new file mode 100644
index 0000000000..349df506e5
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_frame.c
@@ -0,0 +1,128 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33#include "stack_alloc.h"
34#include "PLC.h"
35
36/****************/
37/* Decode frame */
38/****************/
39opus_int silk_decode_frame(
40 silk_decoder_state *psDec, /* I/O Pointer to Silk decoder state */
41 ec_dec *psRangeDec, /* I/O Compressor data structure */
42 opus_int16 pOut[], /* O Pointer to output speech frame */
43 opus_int32 *pN, /* O Pointer to size of output frame */
44 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
45 opus_int condCoding /* I The type of conditional coding to use */
46)
47{
48 VARDECL( silk_decoder_control, psDecCtrl );
49 opus_int L, mv_len, ret = 0;
50 VARDECL( opus_int, pulses );
51 SAVE_STACK;
52
53 L = psDec->frame_length;
54 ALLOC( psDecCtrl, 1, silk_decoder_control );
55 ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) &
56 ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int );
57 psDecCtrl->LTP_scale_Q14 = 0;
58
59 /* Safety checks */
60 silk_assert( L > 0 && L <= MAX_FRAME_LENGTH );
61
62 if( lostFlag == FLAG_DECODE_NORMAL ||
63 ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) )
64 {
65 /*********************************************/
66 /* Decode quantization indices of side info */
67 /*********************************************/
68 silk_decode_indices( psDec, psRangeDec, psDec->nFramesDecoded, lostFlag, condCoding );
69
70 /*********************************************/
71 /* Decode quantization indices of excitation */
72 /*********************************************/
73 silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType,
74 psDec->indices.quantOffsetType, psDec->frame_length );
75
76 /********************************************/
77 /* Decode parameters and pulse signal */
78 /********************************************/
79 silk_decode_parameters( psDec, psDecCtrl, condCoding );
80
81 /********************************************************/
82 /* Run inverse NSQ */
83 /********************************************************/
84 silk_decode_core( psDec, psDecCtrl, pOut, pulses );
85
86 /********************************************************/
87 /* Update PLC state */
88 /********************************************************/
89 silk_PLC( psDec, psDecCtrl, pOut, 0 );
90
91 psDec->lossCnt = 0;
92 psDec->prevSignalType = psDec->indices.signalType;
93 silk_assert( psDec->prevSignalType >= 0 && psDec->prevSignalType <= 2 );
94
95 /* A frame has been decoded without errors */
96 psDec->first_frame_after_reset = 0;
97 } else {
98 /* Handle packet loss by extrapolation */
99 silk_PLC( psDec, psDecCtrl, pOut, 1 );
100 }
101
102 /*************************/
103 /* Update output buffer. */
104 /*************************/
105 silk_assert( psDec->ltp_mem_length >= psDec->frame_length );
106 mv_len = psDec->ltp_mem_length - psDec->frame_length;
107 silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) );
108 silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) );
109
110 /****************************************************************/
111 /* Ensure smooth connection of extrapolated and good frames */
112 /****************************************************************/
113 silk_PLC_glue_frames( psDec, pOut, L );
114
115 /************************************************/
116 /* Comfort noise generation / estimation */
117 /************************************************/
118 silk_CNG( psDec, psDecCtrl, pOut, L );
119
120 /* Update some decoder state variables */
121 psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ];
122
123 /* Set output frame length */
124 *pN = L;
125
126 RESTORE_STACK;
127 return ret;
128}
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_indices.c b/lib/rbcodec/codecs/libopus/silk/decode_indices.c
new file mode 100644
index 0000000000..00eef1de52
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_indices.c
@@ -0,0 +1,151 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Decode side-information parameters from payload */
35void silk_decode_indices(
36 silk_decoder_state *psDec, /* I/O State */
37 ec_dec *psRangeDec, /* I/O Compressor data structure */
38 opus_int FrameIndex, /* I Frame number */
39 opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */
40 opus_int condCoding /* I The type of conditional coding to use */
41)
42{
43 opus_int i, k, Ix;
44 opus_int decode_absolute_lagIndex, delta_lagIndex;
45 opus_int16 ec_ix[ MAX_LPC_ORDER ];
46 opus_uint8 pred_Q8[ MAX_LPC_ORDER ];
47
48 /*******************************************/
49 /* Decode signal type and quantizer offset */
50 /*******************************************/
51 if( decode_LBRR || psDec->VAD_flags[ FrameIndex ] ) {
52 Ix = ec_dec_icdf( psRangeDec, silk_type_offset_VAD_iCDF, 8 ) + 2;
53 } else {
54 Ix = ec_dec_icdf( psRangeDec, silk_type_offset_no_VAD_iCDF, 8 );
55 }
56 psDec->indices.signalType = (opus_int8)silk_RSHIFT( Ix, 1 );
57 psDec->indices.quantOffsetType = (opus_int8)( Ix & 1 );
58
59 /****************/
60 /* Decode gains */
61 /****************/
62 /* First subframe */
63 if( condCoding == CODE_CONDITIONALLY ) {
64 /* Conditional coding */
65 psDec->indices.GainsIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 );
66 } else {
67 /* Independent coding, in two stages: MSB bits followed by 3 LSBs */
68 psDec->indices.GainsIndices[ 0 ] = (opus_int8)silk_LSHIFT( ec_dec_icdf( psRangeDec, silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 );
69 psDec->indices.GainsIndices[ 0 ] += (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform8_iCDF, 8 );
70 }
71
72 /* Remaining subframes */
73 for( i = 1; i < psDec->nb_subfr; i++ ) {
74 psDec->indices.GainsIndices[ i ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 );
75 }
76
77 /**********************/
78 /* Decode LSF Indices */
79 /**********************/
80 psDec->indices.NLSFIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[ ( psDec->indices.signalType >> 1 ) * psDec->psNLSF_CB->nVectors ], 8 );
81 silk_NLSF_unpack( ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ] );
82 silk_assert( psDec->psNLSF_CB->order == psDec->LPC_order );
83 for( i = 0; i < psDec->psNLSF_CB->order; i++ ) {
84 Ix = ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
85 if( Ix == 0 ) {
86 Ix -= ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 );
87 } else if( Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE ) {
88 Ix += ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 );
89 }
90 psDec->indices.NLSFIndices[ i+1 ] = (opus_int8)( Ix - NLSF_QUANT_MAX_AMPLITUDE );
91 }
92
93 /* Decode LSF interpolation factor */
94 if( psDec->nb_subfr == MAX_NB_SUBFR ) {
95 psDec->indices.NLSFInterpCoef_Q2 = (opus_int8)ec_dec_icdf( psRangeDec, silk_NLSF_interpolation_factor_iCDF, 8 );
96 } else {
97 psDec->indices.NLSFInterpCoef_Q2 = 4;
98 }
99
100 if( psDec->indices.signalType == TYPE_VOICED )
101 {
102 /*********************/
103 /* Decode pitch lags */
104 /*********************/
105 /* Get lag index */
106 decode_absolute_lagIndex = 1;
107 if( condCoding == CODE_CONDITIONALLY && psDec->ec_prevSignalType == TYPE_VOICED ) {
108 /* Decode Delta index */
109 delta_lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_delta_iCDF, 8 );
110 if( delta_lagIndex > 0 ) {
111 delta_lagIndex = delta_lagIndex - 9;
112 psDec->indices.lagIndex = (opus_int16)( psDec->ec_prevLagIndex + delta_lagIndex );
113 decode_absolute_lagIndex = 0;
114 }
115 }
116 if( decode_absolute_lagIndex ) {
117 /* Absolute decoding */
118 psDec->indices.lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_lag_iCDF, 8 ) * silk_RSHIFT( psDec->fs_kHz, 1 );
119 psDec->indices.lagIndex += (opus_int16)ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 );
120 }
121 psDec->ec_prevLagIndex = psDec->indices.lagIndex;
122
123 /* Get countour index */
124 psDec->indices.contourIndex = (opus_int8)ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 );
125
126 /********************/
127 /* Decode LTP gains */
128 /********************/
129 /* Decode PERIndex value */
130 psDec->indices.PERIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_per_index_iCDF, 8 );
131
132 for( k = 0; k < psDec->nb_subfr; k++ ) {
133 psDec->indices.LTPIndex[ k ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8 );
134 }
135
136 /**********************/
137 /* Decode LTP scaling */
138 /**********************/
139 if( condCoding == CODE_INDEPENDENTLY ) {
140 psDec->indices.LTP_scaleIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTPscale_iCDF, 8 );
141 } else {
142 psDec->indices.LTP_scaleIndex = 0;
143 }
144 }
145 psDec->ec_prevSignalType = psDec->indices.signalType;
146
147 /***************/
148 /* Decode seed */
149 /***************/
150 psDec->indices.Seed = (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform4_iCDF, 8 );
151}
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_parameters.c b/lib/rbcodec/codecs/libopus/silk/decode_parameters.c
new file mode 100644
index 0000000000..f7c6e2f112
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_parameters.c
@@ -0,0 +1,115 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Decode parameters from payload */
35void silk_decode_parameters(
36 silk_decoder_state *psDec, /* I/O State */
37 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
38 opus_int condCoding /* I The type of conditional coding to use */
39)
40{
41 opus_int i, k, Ix;
42 opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
43 const opus_int8 *cbk_ptr_Q7;
44
45 /* Dequant Gains */
46 silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices,
47 &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr );
48
49 /****************/
50 /* Decode NLSFs */
51 /****************/
52 silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB );
53
54 /* Convert NLSF parameters to AR prediction filter coefficients */
55 silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );
56
57 /* If just reset, e.g., because internal Fs changed, do not allow interpolation */
58 /* improves the case of packet loss in the first frame after a switch */
59 if( psDec->first_frame_after_reset == 1 ) {
60 psDec->indices.NLSFInterpCoef_Q2 = 4;
61 }
62
63 if( psDec->indices.NLSFInterpCoef_Q2 < 4 ) {
64 /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */
65 /* the previous NLSF1, and the current NLSF1 */
66 for( i = 0; i < psDec->LPC_order; i++ ) {
67 pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + silk_RSHIFT( silk_MUL( psDec->indices.NLSFInterpCoef_Q2,
68 pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ), 2 );
69 }
70
71 /* Convert NLSF parameters to AR prediction filter coefficients */
72 silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order );
73 } else {
74 /* Copy LPC coefficients for first half from second half */
75 silk_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) );
76 }
77
78 silk_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( opus_int16 ) );
79
80 /* After a packet loss do BWE of LPC coefs */
81 if( psDec->lossCnt ) {
82 silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
83 silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
84 }
85
86 if( psDec->indices.signalType == TYPE_VOICED ) {
87 /*********************/
88 /* Decode pitch lags */
89 /*********************/
90
91 /* Decode pitch values */
92 silk_decode_pitch( psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr );
93
94 /* Decode Codebook Index */
95 cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ psDec->indices.PERIndex ]; /* set pointer to start of codebook */
96
97 for( k = 0; k < psDec->nb_subfr; k++ ) {
98 Ix = psDec->indices.LTPIndex[ k ];
99 for( i = 0; i < LTP_ORDER; i++ ) {
100 psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = silk_LSHIFT( cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7 );
101 }
102 }
103
104 /**********************/
105 /* Decode LTP scaling */
106 /**********************/
107 Ix = psDec->indices.LTP_scaleIndex;
108 psDecCtrl->LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix ];
109 } else {
110 silk_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( opus_int ) );
111 silk_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof( opus_int16 ) );
112 psDec->indices.PERIndex = 0;
113 psDecCtrl->LTP_scale_Q14 = 0;
114 }
115}
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_pitch.c b/lib/rbcodec/codecs/libopus/silk/decode_pitch.c
new file mode 100644
index 0000000000..8190a19e51
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_pitch.c
@@ -0,0 +1,77 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/***********************************************************
33* Pitch analyser function
34********************************************************** */
35#include "SigProc_FIX.h"
36#include "pitch_est_defines.h"
37
38void silk_decode_pitch(
39 opus_int16 lagIndex, /* I */
40 opus_int8 contourIndex, /* O */
41 opus_int pitch_lags[], /* O 4 pitch values */
42 const opus_int Fs_kHz, /* I sampling frequency (kHz) */
43 const opus_int nb_subfr /* I number of sub frames */
44)
45{
46 opus_int lag, k, min_lag, max_lag, cbk_size;
47 const opus_int8 *Lag_CB_ptr;
48
49 if( Fs_kHz == 8 ) {
50 if( nb_subfr == PE_MAX_NB_SUBFR ) {
51 Lag_CB_ptr = &silk_CB_lags_stage2[ 0 ][ 0 ];
52 cbk_size = PE_NB_CBKS_STAGE2_EXT;
53 } else {
54 silk_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1 );
55 Lag_CB_ptr = &silk_CB_lags_stage2_10_ms[ 0 ][ 0 ];
56 cbk_size = PE_NB_CBKS_STAGE2_10MS;
57 }
58 } else {
59 if( nb_subfr == PE_MAX_NB_SUBFR ) {
60 Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ];
61 cbk_size = PE_NB_CBKS_STAGE3_MAX;
62 } else {
63 silk_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1 );
64 Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ];
65 cbk_size = PE_NB_CBKS_STAGE3_10MS;
66 }
67 }
68
69 min_lag = silk_SMULBB( PE_MIN_LAG_MS, Fs_kHz );
70 max_lag = silk_SMULBB( PE_MAX_LAG_MS, Fs_kHz );
71 lag = min_lag + lagIndex;
72
73 for( k = 0; k < nb_subfr; k++ ) {
74 pitch_lags[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, contourIndex, cbk_size );
75 pitch_lags[ k ] = silk_LIMIT( pitch_lags[ k ], min_lag, max_lag );
76 }
77}
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_pulses.c b/lib/rbcodec/codecs/libopus/silk/decode_pulses.c
new file mode 100644
index 0000000000..78fc2032e8
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decode_pulses.c
@@ -0,0 +1,115 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/*********************************************/
35/* Decode quantization indices of excitation */
36/*********************************************/
37void silk_decode_pulses(
38 ec_dec *psRangeDec, /* I/O Compressor data structure */
39 opus_int pulses[], /* O Excitation signal */
40 const opus_int signalType, /* I Sigtype */
41 const opus_int quantOffsetType, /* I quantOffsetType */
42 const opus_int frame_length /* I Frame length */
43)
44{
45 opus_int i, j, k, iter, abs_q, nLS, RateLevelIndex;
46 opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ];
47 opus_int *pulses_ptr;
48 const opus_uint8 *cdf_ptr;
49
50 /*********************/
51 /* Decode rate level */
52 /*********************/
53 RateLevelIndex = ec_dec_icdf( psRangeDec, silk_rate_levels_iCDF[ signalType >> 1 ], 8 );
54
55 /* Calculate number of shell blocks */
56 silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH );
57 iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH );
58 if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) {
59 silk_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */
60 iter++;
61 }
62
63 /***************************************************/
64 /* Sum-Weighted-Pulses Decoding */
65 /***************************************************/
66 cdf_ptr = silk_pulses_per_block_iCDF[ RateLevelIndex ];
67 for( i = 0; i < iter; i++ ) {
68 nLshifts[ i ] = 0;
69 sum_pulses[ i ] = ec_dec_icdf( psRangeDec, cdf_ptr, 8 );
70
71 /* LSB indication */
72 while( sum_pulses[ i ] == MAX_PULSES + 1 ) {
73 nLshifts[ i ]++;
74 /* When we've already got 10 LSBs, we shift the table to not allow (MAX_PULSES + 1) */
75 sum_pulses[ i ] = ec_dec_icdf( psRangeDec,
76 silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1] + ( nLshifts[ i ] == 10 ), 8 );
77 }
78 }
79
80 /***************************************************/
81 /* Shell decoding */
82 /***************************************************/
83 for( i = 0; i < iter; i++ ) {
84 if( sum_pulses[ i ] > 0 ) {
85 silk_shell_decoder( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] );
86 } else {
87 silk_memset( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( opus_int ) );
88 }
89 }
90
91 /***************************************************/
92 /* LSB Decoding */
93 /***************************************************/
94 for( i = 0; i < iter; i++ ) {
95 if( nLshifts[ i ] > 0 ) {
96 nLS = nLshifts[ i ];
97 pulses_ptr = &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ];
98 for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {
99 abs_q = pulses_ptr[ k ];
100 for( j = 0; j < nLS; j++ ) {
101 abs_q = silk_LSHIFT( abs_q, 1 );
102 abs_q += ec_dec_icdf( psRangeDec, silk_lsb_iCDF, 8 );
103 }
104 pulses_ptr[ k ] = abs_q;
105 }
106 /* Mark the number of pulses non-zero for sign decoding. */
107 sum_pulses[ i ] |= nLS << 5;
108 }
109 }
110
111 /****************************************/
112 /* Decode and add signs to pulse signal */
113 /****************************************/
114 silk_decode_signs( psRangeDec, pulses, frame_length, signalType, quantOffsetType, sum_pulses );
115}
diff --git a/lib/rbcodec/codecs/libopus/silk/decoder_set_fs.c b/lib/rbcodec/codecs/libopus/silk/decoder_set_fs.c
new file mode 100644
index 0000000000..fcc26d7a0e
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/decoder_set_fs.c
@@ -0,0 +1,108 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Set decoder sampling rate */
35opus_int silk_decoder_set_fs(
36 silk_decoder_state *psDec, /* I/O Decoder state pointer */
37 opus_int fs_kHz, /* I Sampling frequency (kHz) */
38 opus_int32 fs_API_Hz /* I API Sampling frequency (Hz) */
39)
40{
41 opus_int frame_length, ret = 0;
42
43 silk_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 );
44 silk_assert( psDec->nb_subfr == MAX_NB_SUBFR || psDec->nb_subfr == MAX_NB_SUBFR/2 );
45
46 /* New (sub)frame length */
47 psDec->subfr_length = silk_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz );
48 frame_length = silk_SMULBB( psDec->nb_subfr, psDec->subfr_length );
49
50 /* Initialize resampler when switching internal or external sampling frequency */
51 if( psDec->fs_kHz != fs_kHz || psDec->fs_API_hz != fs_API_Hz ) {
52 /* Initialize the resampler for dec_API.c preparing resampling from fs_kHz to API_fs_Hz */
53 ret += silk_resampler_init( &psDec->resampler_state, silk_SMULBB( fs_kHz, 1000 ), fs_API_Hz, 0 );
54
55 psDec->fs_API_hz = fs_API_Hz;
56 }
57
58 if( psDec->fs_kHz != fs_kHz || frame_length != psDec->frame_length ) {
59 if( fs_kHz == 8 ) {
60 if( psDec->nb_subfr == MAX_NB_SUBFR ) {
61 psDec->pitch_contour_iCDF = silk_pitch_contour_NB_iCDF;
62 } else {
63 psDec->pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF;
64 }
65 } else {
66 if( psDec->nb_subfr == MAX_NB_SUBFR ) {
67 psDec->pitch_contour_iCDF = silk_pitch_contour_iCDF;
68 } else {
69 psDec->pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF;
70 }
71 }
72 if( psDec->fs_kHz != fs_kHz ) {
73 psDec->ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz );
74 if( fs_kHz == 8 || fs_kHz == 12 ) {
75 psDec->LPC_order = MIN_LPC_ORDER;
76 psDec->psNLSF_CB = &silk_NLSF_CB_NB_MB;
77 } else {
78 psDec->LPC_order = MAX_LPC_ORDER;
79 psDec->psNLSF_CB = &silk_NLSF_CB_WB;
80 }
81 if( fs_kHz == 16 ) {
82 psDec->pitch_lag_low_bits_iCDF = silk_uniform8_iCDF;
83 } else if( fs_kHz == 12 ) {
84 psDec->pitch_lag_low_bits_iCDF = silk_uniform6_iCDF;
85 } else if( fs_kHz == 8 ) {
86 psDec->pitch_lag_low_bits_iCDF = silk_uniform4_iCDF;
87 } else {
88 /* unsupported sampling rate */
89 silk_assert( 0 );
90 }
91 psDec->first_frame_after_reset = 1;
92 psDec->lagPrev = 100;
93 psDec->LastGainIndex = 10;
94 psDec->prevSignalType = TYPE_NO_VOICE_ACTIVITY;
95 silk_memset( psDec->outBuf, 0, sizeof(psDec->outBuf));
96 silk_memset( psDec->sLPC_Q14_buf, 0, sizeof(psDec->sLPC_Q14_buf) );
97 }
98
99 psDec->fs_kHz = fs_kHz;
100 psDec->frame_length = frame_length;
101 }
102
103 /* Check that settings are valid */
104 silk_assert( psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH );
105
106 return ret;
107}
108
diff --git a/lib/rbcodec/codecs/libopus/silk/define.h b/lib/rbcodec/codecs/libopus/silk/define.h
new file mode 100644
index 0000000000..f74f4869c3
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/define.h
@@ -0,0 +1,235 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_DEFINE_H
29#define SILK_DEFINE_H
30
31#include "errors.h"
32#include "typedef.h"
33
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
39/* Max number of encoder channels (1/2) */
40#define ENCODER_NUM_CHANNELS 2
41/* Number of decoder channels (1/2) */
42#define DECODER_NUM_CHANNELS 2
43
44#define MAX_FRAMES_PER_PACKET 3
45
46/* Limits on bitrate */
47#define MIN_TARGET_RATE_BPS 5000
48#define MAX_TARGET_RATE_BPS 80000
49#define TARGET_RATE_TAB_SZ 8
50
51/* LBRR thresholds */
52#define LBRR_NB_MIN_RATE_BPS 12000
53#define LBRR_MB_MIN_RATE_BPS 14000
54#define LBRR_WB_MIN_RATE_BPS 16000
55
56/* DTX settings */
57#define NB_SPEECH_FRAMES_BEFORE_DTX 10 /* eq 200 ms */
58#define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */
59
60/* Maximum sampling frequency */
61#define MAX_FS_KHZ 16
62#define MAX_API_FS_KHZ 48
63
64/* Signal types */
65#define TYPE_NO_VOICE_ACTIVITY 0
66#define TYPE_UNVOICED 1
67#define TYPE_VOICED 2
68
69/* Conditional coding types */
70#define CODE_INDEPENDENTLY 0
71#define CODE_INDEPENDENTLY_NO_LTP_SCALING 1
72#define CODE_CONDITIONALLY 2
73
74/* Settings for stereo processing */
75#define STEREO_QUANT_TAB_SIZE 16
76#define STEREO_QUANT_SUB_STEPS 5
77#define STEREO_INTERP_LEN_MS 8 /* must be even */
78#define STEREO_RATIO_SMOOTH_COEF 0.01 /* smoothing coef for signal norms and stereo width */
79
80/* Range of pitch lag estimates */
81#define PITCH_EST_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */
82#define PITCH_EST_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */
83
84/* Maximum number of subframes */
85#define MAX_NB_SUBFR 4
86
87/* Number of samples per frame */
88#define LTP_MEM_LENGTH_MS 20
89#define SUB_FRAME_LENGTH_MS 5
90#define MAX_SUB_FRAME_LENGTH ( SUB_FRAME_LENGTH_MS * MAX_FS_KHZ )
91#define MAX_FRAME_LENGTH_MS ( SUB_FRAME_LENGTH_MS * MAX_NB_SUBFR )
92#define MAX_FRAME_LENGTH ( MAX_FRAME_LENGTH_MS * MAX_FS_KHZ )
93
94/* Milliseconds of lookahead for pitch analysis */
95#define LA_PITCH_MS 2
96#define LA_PITCH_MAX ( LA_PITCH_MS * MAX_FS_KHZ )
97
98/* Order of LPC used in find pitch */
99#define MAX_FIND_PITCH_LPC_ORDER 16
100
101/* Length of LPC window used in find pitch */
102#define FIND_PITCH_LPC_WIN_MS ( 20 + (LA_PITCH_MS << 1) )
103#define FIND_PITCH_LPC_WIN_MS_2_SF ( 10 + (LA_PITCH_MS << 1) )
104#define FIND_PITCH_LPC_WIN_MAX ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
105
106/* Milliseconds of lookahead for noise shape analysis */
107#define LA_SHAPE_MS 5
108#define LA_SHAPE_MAX ( LA_SHAPE_MS * MAX_FS_KHZ )
109
110/* Maximum length of LPC window used in noise shape analysis */
111#define SHAPE_LPC_WIN_MAX ( 15 * MAX_FS_KHZ )
112
113/* dB level of lowest gain quantization level */
114#define MIN_QGAIN_DB 2
115/* dB level of highest gain quantization level */
116#define MAX_QGAIN_DB 88
117/* Number of gain quantization levels */
118#define N_LEVELS_QGAIN 64
119/* Max increase in gain quantization index */
120#define MAX_DELTA_GAIN_QUANT 36
121/* Max decrease in gain quantization index */
122#define MIN_DELTA_GAIN_QUANT -4
123
124/* Quantization offsets (multiples of 4) */
125#define OFFSET_VL_Q10 32
126#define OFFSET_VH_Q10 100
127#define OFFSET_UVL_Q10 100
128#define OFFSET_UVH_Q10 240
129
130#define QUANT_LEVEL_ADJUST_Q10 80
131
132/* Maximum numbers of iterations used to stabilize an LPC vector */
133#define MAX_LPC_STABILIZE_ITERATIONS 16
134#define MAX_PREDICTION_POWER_GAIN 1e4f
135#define MAX_PREDICTION_POWER_GAIN_AFTER_RESET 1e2f
136
137#define MAX_LPC_ORDER 16
138#define MIN_LPC_ORDER 10
139
140/* Find Pred Coef defines */
141#define LTP_ORDER 5
142
143/* LTP quantization settings */
144#define NB_LTP_CBKS 3
145
146/* Flag to use harmonic noise shaping */
147#define USE_HARM_SHAPING 1
148
149/* Max LPC order of noise shaping filters */
150#define MAX_SHAPE_LPC_ORDER 16
151
152#define HARM_SHAPE_FIR_TAPS 3
153
154/* Maximum number of delayed decision states */
155#define MAX_DEL_DEC_STATES 4
156
157#define LTP_BUF_LENGTH 512
158#define LTP_MASK ( LTP_BUF_LENGTH - 1 )
159
160#define DECISION_DELAY 32
161#define DECISION_DELAY_MASK ( DECISION_DELAY - 1 )
162
163/* Number of subframes for excitation entropy coding */
164#define SHELL_CODEC_FRAME_LENGTH 16
165#define LOG2_SHELL_CODEC_FRAME_LENGTH 4
166#define MAX_NB_SHELL_BLOCKS ( MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH )
167
168/* Number of rate levels, for entropy coding of excitation */
169#define N_RATE_LEVELS 10
170
171/* Maximum sum of pulses per shell coding frame */
172#define MAX_PULSES 16
173
174#define MAX_MATRIX_SIZE MAX_LPC_ORDER /* Max of LPC Order and LTP order */
175
176#if( MAX_LPC_ORDER > DECISION_DELAY )
177# define NSQ_LPC_BUF_LENGTH MAX_LPC_ORDER
178#else
179# define NSQ_LPC_BUF_LENGTH DECISION_DELAY
180#endif
181
182/***************************/
183/* Voice activity detector */
184/***************************/
185#define VAD_N_BANDS 4
186
187#define VAD_INTERNAL_SUBFRAMES_LOG2 2
188#define VAD_INTERNAL_SUBFRAMES ( 1 << VAD_INTERNAL_SUBFRAMES_LOG2 )
189
190#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 1024 /* Must be < 4096 */
191#define VAD_NOISE_LEVELS_BIAS 50
192
193/* Sigmoid settings */
194#define VAD_NEGATIVE_OFFSET_Q5 128 /* sigmoid is 0 at -128 */
195#define VAD_SNR_FACTOR_Q16 45000
196
197/* smoothing for SNR measurement */
198#define VAD_SNR_SMOOTH_COEF_Q18 4096
199
200/* Size of the piecewise linear cosine approximation table for the LSFs */
201#define LSF_COS_TAB_SZ_FIX 128
202
203/******************/
204/* NLSF quantizer */
205/******************/
206#define NLSF_W_Q 2
207#define NLSF_VQ_MAX_VECTORS 32
208#define NLSF_VQ_MAX_SURVIVORS 32
209#define NLSF_QUANT_MAX_AMPLITUDE 4
210#define NLSF_QUANT_MAX_AMPLITUDE_EXT 10
211#define NLSF_QUANT_LEVEL_ADJ 0.1
212#define NLSF_QUANT_DEL_DEC_STATES_LOG2 2
213#define NLSF_QUANT_DEL_DEC_STATES ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )
214
215/* Transition filtering for mode switching */
216#define TRANSITION_TIME_MS 5120 /* 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)*/
217#define TRANSITION_NB 3 /* Hardcoded in tables */
218#define TRANSITION_NA 2 /* Hardcoded in tables */
219#define TRANSITION_INT_NUM 5 /* Hardcoded in tables */
220#define TRANSITION_FRAMES ( TRANSITION_TIME_MS / MAX_FRAME_LENGTH_MS )
221#define TRANSITION_INT_STEPS ( TRANSITION_FRAMES / ( TRANSITION_INT_NUM - 1 ) )
222
223/* BWE factors to apply after packet loss */
224#define BWE_AFTER_LOSS_Q16 63570
225
226/* Defines for CN generation */
227#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */
228#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */
229#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/errors.h b/lib/rbcodec/codecs/libopus/silk/errors.h
new file mode 100644
index 0000000000..0591e0091d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/errors.h
@@ -0,0 +1,98 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_ERRORS_H
29#define SILK_ERRORS_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#endif
35
36/******************/
37/* Error messages */
38/******************/
39#define SILK_NO_ERROR 0
40
41/**************************/
42/* Encoder error messages */
43/**************************/
44
45/* Input length is not a multiple of 10 ms, or length is longer than the packet length */
46#define SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -101
47
48/* Sampling frequency not 8000, 12000 or 16000 Hertz */
49#define SILK_ENC_FS_NOT_SUPPORTED -102
50
51/* Packet size not 10, 20, 40, or 60 ms */
52#define SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -103
53
54/* Allocated payload buffer too short */
55#define SILK_ENC_PAYLOAD_BUF_TOO_SHORT -104
56
57/* Loss rate not between 0 and 100 percent */
58#define SILK_ENC_INVALID_LOSS_RATE -105
59
60/* Complexity setting not valid, use 0...10 */
61#define SILK_ENC_INVALID_COMPLEXITY_SETTING -106
62
63/* Inband FEC setting not valid, use 0 or 1 */
64#define SILK_ENC_INVALID_INBAND_FEC_SETTING -107
65
66/* DTX setting not valid, use 0 or 1 */
67#define SILK_ENC_INVALID_DTX_SETTING -108
68
69/* CBR setting not valid, use 0 or 1 */
70#define SILK_ENC_INVALID_CBR_SETTING -109
71
72/* Internal encoder error */
73#define SILK_ENC_INTERNAL_ERROR -110
74
75/* Internal encoder error */
76#define SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR -111
77
78/**************************/
79/* Decoder error messages */
80/**************************/
81
82/* Output sampling frequency lower than internal decoded sampling frequency */
83#define SILK_DEC_INVALID_SAMPLING_FREQUENCY -200
84
85/* Payload size exceeded the maximum allowed 1024 bytes */
86#define SILK_DEC_PAYLOAD_TOO_LARGE -201
87
88/* Payload has bit errors */
89#define SILK_DEC_PAYLOAD_ERROR -202
90
91/* Payload has bit errors */
92#define SILK_DEC_INVALID_FRAME_SIZE -203
93
94#ifdef __cplusplus
95}
96#endif
97
98#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/gain_quant.c b/lib/rbcodec/codecs/libopus/silk/gain_quant.c
new file mode 100644
index 0000000000..e91ec937e1
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/gain_quant.c
@@ -0,0 +1,141 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34#define OFFSET ( ( MIN_QGAIN_DB * 128 ) / 6 + 16 * 128 )
35#define SCALE_Q16 ( ( 65536 * ( N_LEVELS_QGAIN - 1 ) ) / ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) )
36#define INV_SCALE_Q16 ( ( 65536 * ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) ) / ( N_LEVELS_QGAIN - 1 ) )
37
38/* Gain scalar quantization with hysteresis, uniform on log scale */
39void silk_gains_quant(
40 opus_int8 ind[ MAX_NB_SUBFR ], /* O gain indices */
41 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (quantized out) */
42 opus_int8 *prev_ind, /* I/O last index in previous frame */
43 const opus_int conditional, /* I first gain is delta coded if 1 */
44 const opus_int nb_subfr /* I number of subframes */
45)
46{
47 opus_int k, double_step_size_threshold;
48
49 for( k = 0; k < nb_subfr; k++ ) {
50 /* Convert to log scale, scale, floor() */
51 ind[ k ] = silk_SMULWB( SCALE_Q16, silk_lin2log( gain_Q16[ k ] ) - OFFSET );
52
53 /* Round towards previous quantized gain (hysteresis) */
54 if( ind[ k ] < *prev_ind ) {
55 ind[ k ]++;
56 }
57 ind[ k ] = silk_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 );
58
59 /* Compute delta indices and limit */
60 if( k == 0 && conditional == 0 ) {
61 /* Full index */
62 ind[ k ] = silk_LIMIT_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANT, N_LEVELS_QGAIN - 1 );
63 *prev_ind = ind[ k ];
64 } else {
65 /* Delta index */
66 ind[ k ] = ind[ k ] - *prev_ind;
67
68 /* Double the quantization step size for large gain increases, so that the max gain level can be reached */
69 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGAIN + *prev_ind;
70 if( ind[ k ] > double_step_size_threshold ) {
71 ind[ k ] = double_step_size_threshold + silk_RSHIFT( ind[ k ] - double_step_size_threshold + 1, 1 );
72 }
73
74 ind[ k ] = silk_LIMIT_int( ind[ k ], MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT );
75
76 /* Accumulate deltas */
77 if( ind[ k ] > double_step_size_threshold ) {
78 *prev_ind += silk_LSHIFT( ind[ k ], 1 ) - double_step_size_threshold;
79 } else {
80 *prev_ind += ind[ k ];
81 }
82
83 /* Shift to make non-negative */
84 ind[ k ] -= MIN_DELTA_GAIN_QUANT;
85 }
86
87 /* Scale and convert to linear scale */
88 gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
89 }
90}
91
92/* Gains scalar dequantization, uniform on log scale */
93void silk_gains_dequant(
94 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */
95 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
96 opus_int8 *prev_ind, /* I/O last index in previous frame */
97 const opus_int conditional, /* I first gain is delta coded if 1 */
98 const opus_int nb_subfr /* I number of subframes */
99)
100{
101 opus_int k, ind_tmp, double_step_size_threshold;
102
103 for( k = 0; k < nb_subfr; k++ ) {
104 if( k == 0 && conditional == 0 ) {
105 /* Gain index is not allowed to go down more than 16 steps (~21.8 dB) */
106 *prev_ind = silk_max_int( ind[ k ], *prev_ind - 16 );
107 } else {
108 /* Delta index */
109 ind_tmp = ind[ k ] + MIN_DELTA_GAIN_QUANT;
110
111 /* Accumulate deltas */
112 double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGAIN + *prev_ind;
113 if( ind_tmp > double_step_size_threshold ) {
114 *prev_ind += silk_LSHIFT( ind_tmp, 1 ) - double_step_size_threshold;
115 } else {
116 *prev_ind += ind_tmp;
117 }
118 }
119 *prev_ind = silk_LIMIT_int( *prev_ind, 0, N_LEVELS_QGAIN - 1 );
120
121 /* Scale and convert to linear scale */
122 gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
123 }
124}
125
126/* Compute unique identifier of gain indices vector */
127opus_int32 silk_gains_ID( /* O returns unique identifier of gains */
128 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
129 const opus_int nb_subfr /* I number of subframes */
130)
131{
132 opus_int k;
133 opus_int32 gainsID;
134
135 gainsID = 0;
136 for( k = 0; k < nb_subfr; k++ ) {
137 gainsID = silk_ADD_LSHIFT32( ind[ k ], gainsID, 8 );
138 }
139
140 return gainsID;
141}
diff --git a/lib/rbcodec/codecs/libopus/silk/init_decoder.c b/lib/rbcodec/codecs/libopus/silk/init_decoder.c
new file mode 100644
index 0000000000..139cf02014
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/init_decoder.c
@@ -0,0 +1,56 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/************************/
35/* Init Decoder State */
36/************************/
37opus_int silk_init_decoder(
38 silk_decoder_state *psDec /* I/O Decoder state pointer */
39)
40{
41 /* Clear the entire encoder state, except anything copied */
42 silk_memset( psDec, 0, sizeof( silk_decoder_state ) );
43
44 /* Used to deactivate LSF interpolation */
45 psDec->first_frame_after_reset = 1;
46 psDec->prev_gain_Q16 = 65536;
47
48 /* Reset CNG state */
49 silk_CNG_Reset( psDec );
50
51 /* Reset PLC state */
52 silk_PLC_Reset( psDec );
53
54 return(0);
55}
56
diff --git a/lib/rbcodec/codecs/libopus/silk/lin2log.c b/lib/rbcodec/codecs/libopus/silk/lin2log.c
new file mode 100644
index 0000000000..68ea030c89
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/lin2log.c
@@ -0,0 +1,46 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33/* Approximation of 128 * log2() (very close inverse of silk_log2lin()) */
34/* Convert input to a log scale */
35opus_int32 silk_lin2log(
36 const opus_int32 inLin /* I input in linear scale */
37)
38{
39 opus_int32 lz, frac_Q7;
40
41 silk_CLZ_FRAC( inLin, &lz, &frac_Q7 );
42
43 /* Piece-wise parabolic approximation */
44 return silk_LSHIFT( 31 - lz, 7 ) + silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 );
45}
46
diff --git a/lib/rbcodec/codecs/libopus/silk/log2lin.c b/lib/rbcodec/codecs/libopus/silk/log2lin.c
new file mode 100644
index 0000000000..d80472c69f
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/log2lin.c
@@ -0,0 +1,56 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34/* Approximation of 2^() (very close inverse of silk_lin2log()) */
35/* Convert input to a linear scale */
36opus_int32 silk_log2lin(
37 const opus_int32 inLog_Q7 /* I input on log scale */
38)
39{
40 opus_int32 out, frac_Q7;
41
42 if( inLog_Q7 < 0 ) {
43 return 0;
44 }
45
46 out = silk_LSHIFT( 1, silk_RSHIFT( inLog_Q7, 7 ) );
47 frac_Q7 = inLog_Q7 & 0x7F;
48 if( inLog_Q7 < 2048 ) {
49 /* Piece-wise parabolic approximation */
50 out = silk_ADD_RSHIFT32( out, silk_MUL( out, silk_SMLAWB( frac_Q7, silk_SMULBB( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 );
51 } else {
52 /* Piece-wise parabolic approximation */
53 out = silk_MLA( out, silk_RSHIFT( out, 7 ), silk_SMLAWB( frac_Q7, silk_SMULBB( frac_Q7, 128 - frac_Q7 ), -174 ) );
54 }
55 return out;
56}
diff --git a/lib/rbcodec/codecs/libopus/silk/macros.h b/lib/rbcodec/codecs/libopus/silk/macros.h
new file mode 100644
index 0000000000..d84cd73522
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/macros.h
@@ -0,0 +1,135 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_MACROS_H
29#define SILK_MACROS_H
30
31#ifdef HAVE_CONFIG_H
32#include "opus_config.h"
33#endif
34
35/* This is an inline header file for general platform. */
36
37/* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
38#define silk_SMULWB(a32, b32) ((((a32) >> 16) * (opus_int32)((opus_int16)(b32))) + ((((a32) & 0x0000FFFF) * (opus_int32)((opus_int16)(b32))) >> 16))
39
40/* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
41#define silk_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)))
42
43/* (a32 * (b32 >> 16)) >> 16 */
44#define silk_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
45
46/* a32 + (b32 * (c32 >> 16)) >> 16 */
47#define silk_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
48
49/* (opus_int32)((opus_int16)(a3))) * (opus_int32)((opus_int16)(b32)) output have to be 32bit int */
50#define silk_SMULBB(a32, b32) ((opus_int32)((opus_int16)(a32)) * (opus_int32)((opus_int16)(b32)))
51
52/* a32 + (opus_int32)((opus_int16)(b32)) * (opus_int32)((opus_int16)(c32)) output have to be 32bit int */
53#define silk_SMLABB(a32, b32, c32) ((a32) + ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32)))
54
55/* (opus_int32)((opus_int16)(a32)) * (b32 >> 16) */
56#define silk_SMULBT(a32, b32) ((opus_int32)((opus_int16)(a32)) * ((b32) >> 16))
57
58/* a32 + (opus_int32)((opus_int16)(b32)) * (c32 >> 16) */
59#define silk_SMLABT(a32, b32, c32) ((a32) + ((opus_int32)((opus_int16)(b32))) * ((c32) >> 16))
60
61/* a64 + (b32 * c32) */
62#define silk_SMLAL(a64, b32, c32) (silk_ADD64((a64), ((opus_int64)(b32) * (opus_int64)(c32))))
63
64/* (a32 * b32) >> 16 */
65#define silk_SMULWW(a32, b32) silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16))
66
67/* a32 + ((b32 * c32) >> 16) */
68#define silk_SMLAWW(a32, b32, c32) silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16))
69
70/* add/subtract with output saturated */
71#define silk_ADD_SAT32(a, b) ((((opus_uint32)(a) + (opus_uint32)(b)) & 0x80000000) == 0 ? \
72 ((((a) & (b)) & 0x80000000) != 0 ? silk_int32_MIN : (a)+(b)) : \
73 ((((a) | (b)) & 0x80000000) == 0 ? silk_int32_MAX : (a)+(b)) )
74
75#define silk_SUB_SAT32(a, b) ((((opus_uint32)(a)-(opus_uint32)(b)) & 0x80000000) == 0 ? \
76 (( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \
77 ((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) )
78
79static inline opus_int32 silk_CLZ16(opus_int16 in16)
80{
81 opus_int32 out32 = 0;
82 if( in16 == 0 ) {
83 return 16;
84 }
85 /* test nibbles */
86 if( in16 & 0xFF00 ) {
87 if( in16 & 0xF000 ) {
88 in16 >>= 12;
89 } else {
90 out32 += 4;
91 in16 >>= 8;
92 }
93 } else {
94 if( in16 & 0xFFF0 ) {
95 out32 += 8;
96 in16 >>= 4;
97 } else {
98 out32 += 12;
99 }
100 }
101 /* test bits and return */
102 if( in16 & 0xC ) {
103 if( in16 & 0x8 )
104 return out32 + 0;
105 else
106 return out32 + 1;
107 } else {
108 if( in16 & 0xE )
109 return out32 + 2;
110 else
111 return out32 + 3;
112 }
113}
114
115static inline opus_int32 silk_CLZ32(opus_int32 in32)
116{
117 /* test highest 16 bits and convert to opus_int16 */
118 if( in32 & 0xFFFF0000 ) {
119 return silk_CLZ16((opus_int16)(in32 >> 16));
120 } else {
121 return silk_CLZ16((opus_int16)in32) + 16;
122 }
123}
124
125/* Row based */
126#define matrix_ptr(Matrix_base_adr, row, column, N) *(Matrix_base_adr + ((row)*(N)+(column)))
127#define matrix_adr(Matrix_base_adr, row, column, N) (Matrix_base_adr + ((row)*(N)+(column)))
128
129/* Column based */
130#ifndef matrix_c_ptr
131# define matrix_c_ptr(Matrix_base_adr, row, column, M) *(Matrix_base_adr + ((row)+(M)*(column)))
132#endif
133
134#endif /* SILK_MACROS_H */
135
diff --git a/lib/rbcodec/codecs/libopus/silk/main.h b/lib/rbcodec/codecs/libopus/silk/main.h
new file mode 100644
index 0000000000..32675f6931
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/main.h
@@ -0,0 +1,434 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_MAIN_H
29#define SILK_MAIN_H
30
31#include "SigProc_FIX.h"
32#include "define.h"
33#include "structs.h"
34#include "tables.h"
35#include "PLC.h"
36#include "control.h"
37#include "debug.h"
38#include "entenc.h"
39#include "entdec.h"
40
41/* Convert Left/Right stereo signal to adaptive Mid/Side representation */
42void silk_stereo_LR_to_MS(
43 stereo_enc_state *state, /* I/O State */
44 opus_int16 x1[], /* I/O Left input signal, becomes mid signal */
45 opus_int16 x2[], /* I/O Right input signal, becomes side signal */
46 opus_int8 ix[ 2 ][ 3 ], /* O Quantization indices */
47 opus_int8 *mid_only_flag, /* O Flag: only mid signal coded */
48 opus_int32 mid_side_rates_bps[], /* O Bitrates for mid and side signals */
49 opus_int32 total_rate_bps, /* I Total bitrate */
50 opus_int prev_speech_act_Q8, /* I Speech activity level in previous frame */
51 opus_int toMono, /* I Last frame before a stereo->mono transition */
52 opus_int fs_kHz, /* I Sample rate (kHz) */
53 opus_int frame_length /* I Number of samples */
54);
55
56/* Convert adaptive Mid/Side representation to Left/Right stereo signal */
57void silk_stereo_MS_to_LR(
58 stereo_dec_state *state, /* I/O State */
59 opus_int16 x1[], /* I/O Left input signal, becomes mid signal */
60 opus_int16 x2[], /* I/O Right input signal, becomes side signal */
61 const opus_int32 pred_Q13[], /* I Predictors */
62 opus_int fs_kHz, /* I Samples rate (kHz) */
63 opus_int frame_length /* I Number of samples */
64);
65
66/* Find least-squares prediction gain for one signal based on another and quantize it */
67opus_int32 silk_stereo_find_predictor( /* O Returns predictor in Q13 */
68 opus_int32 *ratio_Q14, /* O Ratio of residual and mid energies */
69 const opus_int16 x[], /* I Basis signal */
70 const opus_int16 y[], /* I Target signal */
71 opus_int32 mid_res_amp_Q0[], /* I/O Smoothed mid, residual norms */
72 opus_int length, /* I Number of samples */
73 opus_int smooth_coef_Q16 /* I Smoothing coefficient */
74);
75
76/* Quantize mid/side predictors */
77void silk_stereo_quant_pred(
78 opus_int32 pred_Q13[], /* I/O Predictors (out: quantized) */
79 opus_int8 ix[ 2 ][ 3 ] /* O Quantization indices */
80);
81
82/* Entropy code the mid/side quantization indices */
83void silk_stereo_encode_pred(
84 ec_enc *psRangeEnc, /* I/O Compressor data structure */
85 opus_int8 ix[ 2 ][ 3 ] /* I Quantization indices */
86);
87
88/* Entropy code the mid-only flag */
89void silk_stereo_encode_mid_only(
90 ec_enc *psRangeEnc, /* I/O Compressor data structure */
91 opus_int8 mid_only_flag
92);
93
94/* Decode mid/side predictors */
95void silk_stereo_decode_pred(
96 ec_dec *psRangeDec, /* I/O Compressor data structure */
97 opus_int32 pred_Q13[] /* O Predictors */
98);
99
100/* Decode mid-only flag */
101void silk_stereo_decode_mid_only(
102 ec_dec *psRangeDec, /* I/O Compressor data structure */
103 opus_int *decode_only_mid /* O Flag that only mid channel has been coded */
104);
105
106/* Encodes signs of excitation */
107void silk_encode_signs(
108 ec_enc *psRangeEnc, /* I/O Compressor data structure */
109 const opus_int8 pulses[], /* I pulse signal */
110 opus_int length, /* I length of input */
111 const opus_int signalType, /* I Signal type */
112 const opus_int quantOffsetType, /* I Quantization offset type */
113 const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
114);
115
116/* Decodes signs of excitation */
117void silk_decode_signs(
118 ec_dec *psRangeDec, /* I/O Compressor data structure */
119 opus_int pulses[], /* I/O pulse signal */
120 opus_int length, /* I length of input */
121 const opus_int signalType, /* I Signal type */
122 const opus_int quantOffsetType, /* I Quantization offset type */
123 const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
124);
125
126/* Check encoder control struct */
127opus_int check_control_input(
128 silk_EncControlStruct *encControl /* I Control structure */
129);
130
131/* Control internal sampling rate */
132opus_int silk_control_audio_bandwidth(
133 silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
134 silk_EncControlStruct *encControl /* I Control structure */
135);
136
137/* Control SNR of redidual quantizer */
138opus_int silk_control_SNR(
139 silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
140 opus_int32 TargetRate_bps /* I Target max bitrate (bps) */
141);
142
143/***************/
144/* Shell coder */
145/***************/
146
147/* Encode quantization indices of excitation */
148void silk_encode_pulses(
149 ec_enc *psRangeEnc, /* I/O compressor data structure */
150 const opus_int signalType, /* I Signal type */
151 const opus_int quantOffsetType, /* I quantOffsetType */
152 opus_int8 pulses[], /* I quantization indices */
153 const opus_int frame_length /* I Frame length */
154);
155
156/* Shell encoder, operates on one shell code frame of 16 pulses */
157void silk_shell_encoder(
158 ec_enc *psRangeEnc, /* I/O compressor data structure */
159 const opus_int *pulses0 /* I data: nonnegative pulse amplitudes */
160);
161
162/* Shell decoder, operates on one shell code frame of 16 pulses */
163void silk_shell_decoder(
164 opus_int *pulses0, /* O data: nonnegative pulse amplitudes */
165 ec_dec *psRangeDec, /* I/O Compressor data structure */
166 const opus_int pulses4 /* I number of pulses per pulse-subframe */
167);
168
169/* Gain scalar quantization with hysteresis, uniform on log scale */
170void silk_gains_quant(
171 opus_int8 ind[ MAX_NB_SUBFR ], /* O gain indices */
172 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (quantized out) */
173 opus_int8 *prev_ind, /* I/O last index in previous frame */
174 const opus_int conditional, /* I first gain is delta coded if 1 */
175 const opus_int nb_subfr /* I number of subframes */
176);
177
178/* Gains scalar dequantization, uniform on log scale */
179void silk_gains_dequant(
180 opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */
181 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
182 opus_int8 *prev_ind, /* I/O last index in previous frame */
183 const opus_int conditional, /* I first gain is delta coded if 1 */
184 const opus_int nb_subfr /* I number of subframes */
185);
186
187/* Compute unique identifier of gain indices vector */
188opus_int32 silk_gains_ID( /* O returns unique identifier of gains */
189 const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
190 const opus_int nb_subfr /* I number of subframes */
191);
192
193/* Interpolate two vectors */
194void silk_interpolate(
195 opus_int16 xi[ MAX_LPC_ORDER ], /* O interpolated vector */
196 const opus_int16 x0[ MAX_LPC_ORDER ], /* I first vector */
197 const opus_int16 x1[ MAX_LPC_ORDER ], /* I second vector */
198 const opus_int ifact_Q2, /* I interp. factor, weight on 2nd vector */
199 const opus_int d /* I number of parameters */
200);
201
202/* LTP tap quantizer */
203void silk_quant_LTP_gains(
204 opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (un)quantized LTP gains */
205 opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */
206 opus_int8 *periodicity_index, /* O Periodicity Index */
207 const opus_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error Weights in Q18 */
208 opus_int mu_Q9, /* I Mu value (R/D tradeoff) */
209 opus_int lowComplexity, /* I Flag for low complexity */
210 const opus_int nb_subfr /* I number of subframes */
211);
212
213/* Entropy constrained matrix-weighted VQ, for a single input data vector */
214void silk_VQ_WMat_EC(
215 opus_int8 *ind, /* O index of best codebook vector */
216 opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */
217 const opus_int16 *in_Q14, /* I input vector to be quantized */
218 const opus_int32 *W_Q18, /* I weighting matrix */
219 const opus_int8 *cb_Q7, /* I codebook */
220 const opus_uint8 *cl_Q5, /* I code length for each codebook vector */
221 const opus_int mu_Q9, /* I tradeoff betw. weighted error and rate */
222 opus_int L /* I number of vectors in codebook */
223);
224
225/************************************/
226/* Noise shaping quantization (NSQ) */
227/************************************/
228void silk_NSQ(
229 const silk_encoder_state *psEncC, /* I/O Encoder State */
230 silk_nsq_state *NSQ, /* I/O NSQ state */
231 SideInfoIndices *psIndices, /* I/O Quantization Indices */
232 const opus_int32 x_Q3[], /* I Prefiltered input signal */
233 opus_int8 pulses[], /* O Quantized pulse signal */
234 const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
235 const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
236 const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
237 const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
238 const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
239 const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
240 const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
241 const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
242 const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
243 const opus_int LTP_scale_Q14 /* I LTP state scaling */
244);
245
246/* Noise shaping using delayed decision */
247void silk_NSQ_del_dec(
248 const silk_encoder_state *psEncC, /* I/O Encoder State */
249 silk_nsq_state *NSQ, /* I/O NSQ state */
250 SideInfoIndices *psIndices, /* I/O Quantization Indices */
251 const opus_int32 x_Q3[], /* I Prefiltered input signal */
252 opus_int8 pulses[], /* O Quantized pulse signal */
253 const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
254 const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
255 const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
256 const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
257 const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
258 const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
259 const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
260 const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
261 const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
262 const opus_int LTP_scale_Q14 /* I LTP state scaling */
263);
264
265/************/
266/* Silk VAD */
267/************/
268/* Initialize the Silk VAD */
269opus_int silk_VAD_Init( /* O Return value, 0 if success */
270 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
271);
272
273/* Get speech activity level in Q8 */
274opus_int silk_VAD_GetSA_Q8( /* O Return value, 0 if success */
275 silk_encoder_state *psEncC, /* I/O Encoder state */
276 const opus_int16 pIn[] /* I PCM input */
277);
278
279/* Low-pass filter with variable cutoff frequency based on */
280/* piece-wise linear interpolation between elliptic filters */
281/* Start by setting transition_frame_no = 1; */
282void silk_LP_variable_cutoff(
283 silk_LP_state *psLP, /* I/O LP filter state */
284 opus_int16 *frame, /* I/O Low-pass filtered output signal */
285 const opus_int frame_length /* I Frame length */
286);
287
288/******************/
289/* NLSF Quantizer */
290/******************/
291/* Limit, stabilize, convert and quantize NLSFs */
292void silk_process_NLSFs(
293 silk_encoder_state *psEncC, /* I/O Encoder state */
294 opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
295 opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
296 const opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
297);
298
299opus_int32 silk_NLSF_encode( /* O Returns RD value in Q25 */
300 opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
301 opus_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
302 const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
303 const opus_int16 *pW_QW, /* I NLSF weight vector [ LPC_ORDER ] */
304 const opus_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */
305 const opus_int nSurvivors, /* I Max survivors after first stage */
306 const opus_int signalType /* I Signal type: 0/1/2 */
307);
308
309/* Compute quantization errors for an LPC_order element input vector for a VQ codebook */
310void silk_NLSF_VQ(
311 opus_int32 err_Q26[], /* O Quantization errors [K] */
312 const opus_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */
313 const opus_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */
314 const opus_int K, /* I Number of codebook vectors */
315 const opus_int LPC_order /* I Number of LPCs */
316);
317
318/* Delayed-decision quantizer for NLSF residuals */
319opus_int32 silk_NLSF_del_dec_quant( /* O Returns RD value in Q25 */
320 opus_int8 indices[], /* O Quantization indices [ order ] */
321 const opus_int16 x_Q10[], /* I Input [ order ] */
322 const opus_int16 w_Q5[], /* I Weights [ order ] */
323 const opus_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
324 const opus_int16 ec_ix[], /* I Indices to entropy coding tables [ order ] */
325 const opus_uint8 ec_rates_Q5[], /* I Rates [] */
326 const opus_int quant_step_size_Q16, /* I Quantization step size */
327 const opus_int16 inv_quant_step_size_Q6, /* I Inverse quantization step size */
328 const opus_int32 mu_Q20, /* I R/D tradeoff */
329 const opus_int16 order /* I Number of input values */
330);
331
332/* Unpack predictor values and indices for entropy coding tables */
333void silk_NLSF_unpack(
334 opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */
335 opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */
336 const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
337 const opus_int CB1_index /* I Index of vector in first LSF codebook */
338);
339
340/***********************/
341/* NLSF vector decoder */
342/***********************/
343void silk_NLSF_decode(
344 opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
345 opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
346 const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
347);
348
349/****************************************************/
350/* Decoder Functions */
351/****************************************************/
352opus_int silk_init_decoder(
353 silk_decoder_state *psDec /* I/O Decoder state pointer */
354);
355
356/* Set decoder sampling rate */
357opus_int silk_decoder_set_fs(
358 silk_decoder_state *psDec, /* I/O Decoder state pointer */
359 opus_int fs_kHz, /* I Sampling frequency (kHz) */
360 opus_int32 fs_API_Hz /* I API Sampling frequency (Hz) */
361);
362
363/****************/
364/* Decode frame */
365/****************/
366opus_int silk_decode_frame(
367 silk_decoder_state *psDec, /* I/O Pointer to Silk decoder state */
368 ec_dec *psRangeDec, /* I/O Compressor data structure */
369 opus_int16 pOut[], /* O Pointer to output speech frame */
370 opus_int32 *pN, /* O Pointer to size of output frame */
371 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
372 opus_int condCoding /* I The type of conditional coding to use */
373);
374
375/* Decode indices from bitstream */
376void silk_decode_indices(
377 silk_decoder_state *psDec, /* I/O State */
378 ec_dec *psRangeDec, /* I/O Compressor data structure */
379 opus_int FrameIndex, /* I Frame number */
380 opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */
381 opus_int condCoding /* I The type of conditional coding to use */
382);
383
384/* Decode parameters from payload */
385void silk_decode_parameters(
386 silk_decoder_state *psDec, /* I/O State */
387 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
388 opus_int condCoding /* I The type of conditional coding to use */
389);
390
391/* Core decoder. Performs inverse NSQ operation LTP + LPC */
392void silk_decode_core(
393 silk_decoder_state *psDec, /* I/O Decoder state */
394 silk_decoder_control *psDecCtrl, /* I Decoder control */
395 opus_int16 xq[], /* O Decoded speech */
396 const opus_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */
397);
398
399/* Decode quantization indices of excitation (Shell coding) */
400void silk_decode_pulses(
401 ec_dec *psRangeDec, /* I/O Compressor data structure */
402 opus_int pulses[], /* O Excitation signal */
403 const opus_int signalType, /* I Sigtype */
404 const opus_int quantOffsetType, /* I quantOffsetType */
405 const opus_int frame_length /* I Frame length */
406);
407
408/******************/
409/* CNG */
410/******************/
411
412/* Reset CNG */
413void silk_CNG_Reset(
414 silk_decoder_state *psDec /* I/O Decoder state */
415);
416
417/* Updates CNG estimate, and applies the CNG when packet was lost */
418void silk_CNG(
419 silk_decoder_state *psDec, /* I/O Decoder state */
420 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
421 opus_int16 frame[], /* I/O Signal */
422 opus_int length /* I Length of residual */
423);
424
425/* Encoding of various parameters */
426void silk_encode_indices(
427 silk_encoder_state *psEncC, /* I/O Encoder state */
428 ec_enc *psRangeEnc, /* I/O Compressor data structure */
429 opus_int FrameIndex, /* I Frame number */
430 opus_int encode_LBRR, /* I Flag indicating LBRR data is being encoded */
431 opus_int condCoding /* I The type of conditional coding to use */
432);
433
434#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/pitch_est_defines.h b/lib/rbcodec/codecs/libopus/silk/pitch_est_defines.h
new file mode 100644
index 0000000000..0b6770eb91
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/pitch_est_defines.h
@@ -0,0 +1,88 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_PE_DEFINES_H
29#define SILK_PE_DEFINES_H
30
31#include "SigProc_FIX.h"
32
33/********************************************************/
34/* Definitions for pitch estimator */
35/********************************************************/
36
37#define PE_MAX_FS_KHZ 16 /* Maximum sampling frequency used */
38
39#define PE_MAX_NB_SUBFR 4
40#define PE_SUBFR_LENGTH_MS 5 /* 5 ms */
41
42#define PE_LTP_MEM_LENGTH_MS ( 4 * PE_SUBFR_LENGTH_MS )
43
44#define PE_MAX_FRAME_LENGTH_MS ( PE_LTP_MEM_LENGTH_MS + PE_MAX_NB_SUBFR * PE_SUBFR_LENGTH_MS )
45#define PE_MAX_FRAME_LENGTH ( PE_MAX_FRAME_LENGTH_MS * PE_MAX_FS_KHZ )
46#define PE_MAX_FRAME_LENGTH_ST_1 ( PE_MAX_FRAME_LENGTH >> 2 )
47#define PE_MAX_FRAME_LENGTH_ST_2 ( PE_MAX_FRAME_LENGTH >> 1 )
48
49#define PE_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */
50#define PE_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */
51#define PE_MAX_LAG ( PE_MAX_LAG_MS * PE_MAX_FS_KHZ )
52#define PE_MIN_LAG ( PE_MIN_LAG_MS * PE_MAX_FS_KHZ )
53
54#define PE_D_SRCH_LENGTH 24
55
56#define PE_NB_STAGE3_LAGS 5
57
58#define PE_NB_CBKS_STAGE2 3
59#define PE_NB_CBKS_STAGE2_EXT 11
60
61#define PE_NB_CBKS_STAGE3_MAX 34
62#define PE_NB_CBKS_STAGE3_MID 24
63#define PE_NB_CBKS_STAGE3_MIN 16
64
65#define PE_NB_CBKS_STAGE3_10MS 12
66#define PE_NB_CBKS_STAGE2_10MS 3
67
68#define PE_SHORTLAG_BIAS 0.2f /* for logarithmic weighting */
69#define PE_PREVLAG_BIAS 0.2f /* for logarithmic weighting */
70#define PE_FLATCONTOUR_BIAS 0.05f
71
72#define SILK_PE_MIN_COMPLEX 0
73#define SILK_PE_MID_COMPLEX 1
74#define SILK_PE_MAX_COMPLEX 2
75
76/* Tables for 20 ms frames */
77extern const opus_int8 silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ];
78extern const opus_int8 silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ];
79extern const opus_int8 silk_Lag_range_stage3[ SILK_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ];
80extern const opus_int8 silk_nb_cbk_searchs_stage3[ SILK_PE_MAX_COMPLEX + 1 ];
81
82/* Tables for 10 ms frames */
83extern const opus_int8 silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ 3 ];
84extern const opus_int8 silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 12 ];
85extern const opus_int8 silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ];
86
87#endif
88
diff --git a/lib/rbcodec/codecs/libopus/silk/pitch_est_tables.c b/lib/rbcodec/codecs/libopus/silk/pitch_est_tables.c
new file mode 100644
index 0000000000..e191686b0e
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/pitch_est_tables.c
@@ -0,0 +1,99 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "typedef.h"
33#include "pitch_est_defines.h"
34
35const opus_int8 silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ PE_NB_CBKS_STAGE2_10MS ] =
36{
37 {0, 1, 0},
38 {0, 0, 1}
39};
40
41const opus_int8 silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ PE_NB_CBKS_STAGE3_10MS ] =
42{
43 { 0, 0, 1,-1, 1,-1, 2,-2, 2,-2, 3,-3},
44 { 0, 1, 0, 1,-1, 2,-1, 2,-2, 3,-2, 3}
45};
46
47const opus_int8 silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ] =
48{
49 {-3, 7},
50 {-2, 7}
51};
52
53const opus_int8 silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ] =
54{
55 {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1},
56 {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0},
57 {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
58 {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1}
59};
60
61const opus_int8 silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ] =
62{
63 {0, 0, 1,-1, 0, 1,-1, 0,-1, 1,-2, 2,-2,-2, 2,-3, 2, 3,-3,-4, 3,-4, 4, 4,-5, 5,-6,-5, 6,-7, 6, 5, 8,-9},
64 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 1,-1, 0, 1,-1,-1, 1,-1, 2, 1,-1, 2,-2,-2, 2,-2, 2, 2, 3,-3},
65 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,-1, 1, 0, 0, 2, 1,-1, 2,-1,-1, 2,-1, 2, 2,-1, 3,-2,-2,-2, 3},
66 {0, 1, 0, 0, 1, 0, 1,-1, 2,-1, 2,-1, 2, 3,-2, 3,-2,-2, 4, 4,-3, 5,-3,-4, 6,-4, 6, 5,-5, 8,-6,-5,-7, 9}
67};
68
69const opus_int8 silk_Lag_range_stage3[ SILK_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ] =
70{
71 /* Lags to search for low number of stage3 cbks */
72 {
73 {-5,8},
74 {-1,6},
75 {-1,6},
76 {-4,10}
77 },
78 /* Lags to search for middle number of stage3 cbks */
79 {
80 {-6,10},
81 {-2,6},
82 {-1,6},
83 {-5,10}
84 },
85 /* Lags to search for max number of stage3 cbks */
86 {
87 {-9,12},
88 {-3,7},
89 {-2,7},
90 {-7,13}
91 }
92};
93
94const opus_int8 silk_nb_cbk_searchs_stage3[ SILK_PE_MAX_COMPLEX + 1 ] =
95{
96 PE_NB_CBKS_STAGE3_MIN,
97 PE_NB_CBKS_STAGE3_MID,
98 PE_NB_CBKS_STAGE3_MAX
99};
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler.c b/lib/rbcodec/codecs/libopus/silk/resampler.c
new file mode 100644
index 0000000000..ab81b6013f
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler.c
@@ -0,0 +1,215 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/*
33 * Matrix of resampling methods used:
34 * Fs_out (kHz)
35 * 8 12 16 24 48
36 *
37 * 8 C UF U UF UF
38 * 12 AF C UF U UF
39 * Fs_in (kHz) 16 D AF C UF UF
40 * 24 AF D AF C U
41 * 48 AF AF AF D C
42 *
43 * C -> Copy (no resampling)
44 * D -> Allpass-based 2x downsampling
45 * U -> Allpass-based 2x upsampling
46 * UF -> Allpass-based 2x upsampling followed by FIR interpolation
47 * AF -> AR2 filter followed by FIR interpolation
48 */
49
50#include "resampler_private.h"
51
52/* Tables with delay compensation values to equalize total delay for different modes */
53static const opus_int8 delay_matrix_enc[ 5 ][ 3 ] = {
54/* in \ out 8 12 16 */
55/* 8 */ { 6, 0, 3 },
56/* 12 */ { 0, 7, 3 },
57/* 16 */ { 0, 1, 10 },
58/* 24 */ { 0, 2, 6 },
59/* 48 */ { 18, 10, 12 }
60};
61
62static const opus_int8 delay_matrix_dec[ 3 ][ 5 ] = {
63/* in \ out 8 12 16 24 48 */
64/* 8 */ { 4, 0, 2, 0, 0 },
65/* 12 */ { 0, 9, 4, 7, 4 },
66/* 16 */ { 0, 3, 12, 7, 7 }
67};
68
69/* Simple way to make [8000, 12000, 16000, 24000, 48000] to [0, 1, 2, 3, 4] */
70#define rateID(R) ( ( ( ((R)>>12) - ((R)>16000) ) >> ((R)>24000) ) - 1 )
71
72#define USE_silk_resampler_copy (0)
73#define USE_silk_resampler_private_up2_HQ_wrapper (1)
74#define USE_silk_resampler_private_IIR_FIR (2)
75#define USE_silk_resampler_private_down_FIR (3)
76
77/* Initialize/reset the resampler state for a given pair of input/output sampling rates */
78opus_int silk_resampler_init(
79 silk_resampler_state_struct *S, /* I/O Resampler state */
80 opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
81 opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
82 opus_int forEnc /* I If 1: encoder; if 0: decoder */
83)
84{
85 opus_int up2x;
86
87 /* Clear state */
88 silk_memset( S, 0, sizeof( silk_resampler_state_struct ) );
89
90 /* Input checking */
91 if( forEnc ) {
92 if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000 ) ||
93 ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 ) ) {
94 silk_assert( 0 );
95 return -1;
96 }
97 S->inputDelay = delay_matrix_enc[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
98 } else {
99 if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 ) ||
100 ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000 ) ) {
101 silk_assert( 0 );
102 return -1;
103 }
104 S->inputDelay = delay_matrix_dec[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
105 }
106
107 S->Fs_in_kHz = silk_DIV32_16( Fs_Hz_in, 1000 );
108 S->Fs_out_kHz = silk_DIV32_16( Fs_Hz_out, 1000 );
109
110 /* Number of samples processed per batch */
111 S->batchSize = S->Fs_in_kHz * RESAMPLER_MAX_BATCH_SIZE_MS;
112
113 /* Find resampler with the right sampling ratio */
114 up2x = 0;
115 if( Fs_Hz_out > Fs_Hz_in ) {
116 /* Upsample */
117 if( Fs_Hz_out == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 1 */
118 /* Special case: directly use 2x upsampler */
119 S->resampler_function = USE_silk_resampler_private_up2_HQ_wrapper;
120 } else {
121 /* Default resampler */
122 S->resampler_function = USE_silk_resampler_private_IIR_FIR;
123 up2x = 1;
124 }
125 } else if ( Fs_Hz_out < Fs_Hz_in ) {
126 /* Downsample */
127 S->resampler_function = USE_silk_resampler_private_down_FIR;
128 if( silk_MUL( Fs_Hz_out, 4 ) == silk_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 4 */
129 S->FIR_Fracs = 3;
130 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
131 S->Coefs = silk_Resampler_3_4_COEFS;
132 } else if( silk_MUL( Fs_Hz_out, 3 ) == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 3 */
133 S->FIR_Fracs = 2;
134 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
135 S->Coefs = silk_Resampler_2_3_COEFS;
136 } else if( silk_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 2 */
137 S->FIR_Fracs = 1;
138 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR1;
139 S->Coefs = silk_Resampler_1_2_COEFS;
140 } else if( silk_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 3 */
141 S->FIR_Fracs = 1;
142 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
143 S->Coefs = silk_Resampler_1_3_COEFS;
144 } else if( silk_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 4 */
145 S->FIR_Fracs = 1;
146 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
147 S->Coefs = silk_Resampler_1_4_COEFS;
148 } else if( silk_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 6 */
149 S->FIR_Fracs = 1;
150 S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
151 S->Coefs = silk_Resampler_1_6_COEFS;
152 } else {
153 /* None available */
154 silk_assert( 0 );
155 return -1;
156 }
157 } else {
158 /* Input and output sampling rates are equal: copy */
159 S->resampler_function = USE_silk_resampler_copy;
160 }
161
162 /* Ratio of input/output samples */
163 S->invRatio_Q16 = silk_LSHIFT32( silk_DIV32( silk_LSHIFT32( Fs_Hz_in, 14 + up2x ), Fs_Hz_out ), 2 );
164 /* Make sure the ratio is rounded up */
165 while( silk_SMULWW( S->invRatio_Q16, Fs_Hz_out ) < silk_LSHIFT32( Fs_Hz_in, up2x ) ) {
166 S->invRatio_Q16++;
167 }
168
169 return 0;
170}
171
172/* Resampler: convert from one sampling rate to another */
173/* Input and output sampling rate are at most 48000 Hz */
174opus_int silk_resampler(
175 silk_resampler_state_struct *S, /* I/O Resampler state */
176 opus_int16 out[], /* O Output signal */
177 const opus_int16 in[], /* I Input signal */
178 opus_int32 inLen /* I Number of input samples */
179)
180{
181 opus_int nSamples;
182
183 /* Need at least 1 ms of input data */
184 silk_assert( inLen >= S->Fs_in_kHz );
185 /* Delay can't exceed the 1 ms of buffering */
186 silk_assert( S->inputDelay <= S->Fs_in_kHz );
187
188 nSamples = S->Fs_in_kHz - S->inputDelay;
189
190 /* Copy to delay buffer */
191 silk_memcpy( &S->delayBuf[ S->inputDelay ], in, nSamples * sizeof( opus_int16 ) );
192
193 switch( S->resampler_function ) {
194 case USE_silk_resampler_private_up2_HQ_wrapper:
195 silk_resampler_private_up2_HQ_wrapper( S, out, S->delayBuf, S->Fs_in_kHz );
196 silk_resampler_private_up2_HQ_wrapper( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
197 break;
198 case USE_silk_resampler_private_IIR_FIR:
199 silk_resampler_private_IIR_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
200 silk_resampler_private_IIR_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
201 break;
202 case USE_silk_resampler_private_down_FIR:
203 silk_resampler_private_down_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
204 silk_resampler_private_down_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
205 break;
206 default:
207 silk_memcpy( out, S->delayBuf, S->Fs_in_kHz * sizeof( opus_int16 ) );
208 silk_memcpy( &out[ S->Fs_out_kHz ], &in[ nSamples ], ( inLen - S->Fs_in_kHz ) * sizeof( opus_int16 ) );
209 }
210
211 /* Copy to delay buffer */
212 silk_memcpy( S->delayBuf, &in[ inLen - S->inputDelay ], S->inputDelay * sizeof( opus_int16 ) );
213
214 return 0;
215}
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private.h b/lib/rbcodec/codecs/libopus/silk/resampler_private.h
new file mode 100644
index 0000000000..45d342c78d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private.h
@@ -0,0 +1,88 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_RESAMPLER_PRIVATE_H
29#define SILK_RESAMPLER_PRIVATE_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include "SigProc_FIX.h"
36#include "resampler_structs.h"
37#include "resampler_rom.h"
38
39/* Number of input samples to process in the inner loop */
40#define RESAMPLER_MAX_BATCH_SIZE_MS 10
41#define RESAMPLER_MAX_FS_KHZ 48
42#define RESAMPLER_MAX_BATCH_SIZE_IN ( RESAMPLER_MAX_BATCH_SIZE_MS * RESAMPLER_MAX_FS_KHZ )
43
44/* Description: Hybrid IIR/FIR polyphase implementation of resampling */
45void silk_resampler_private_IIR_FIR(
46 void *SS, /* I/O Resampler state */
47 opus_int16 out[], /* O Output signal */
48 const opus_int16 in[], /* I Input signal */
49 opus_int32 inLen /* I Number of input samples */
50);
51
52/* Description: Hybrid IIR/FIR polyphase implementation of resampling */
53void silk_resampler_private_down_FIR(
54 void *SS, /* I/O Resampler state */
55 opus_int16 out[], /* O Output signal */
56 const opus_int16 in[], /* I Input signal */
57 opus_int32 inLen /* I Number of input samples */
58);
59
60/* Upsample by a factor 2, high quality */
61void silk_resampler_private_up2_HQ_wrapper(
62 void *SS, /* I/O Resampler state (unused) */
63 opus_int16 *out, /* O Output signal [ 2 * len ] */
64 const opus_int16 *in, /* I Input signal [ len ] */
65 opus_int32 len /* I Number of input samples */
66);
67
68/* Upsample by a factor 2, high quality */
69void silk_resampler_private_up2_HQ(
70 opus_int32 *S, /* I/O Resampler state [ 6 ] */
71 opus_int16 *out, /* O Output signal [ 2 * len ] */
72 const opus_int16 *in, /* I Input signal [ len ] */
73 opus_int32 len /* I Number of input samples */
74);
75
76/* Second order AR filter */
77void silk_resampler_private_AR2(
78 opus_int32 S[], /* I/O State vector [ 2 ] */
79 opus_int32 out_Q8[], /* O Output signal */
80 const opus_int16 in[], /* I Input signal */
81 const opus_int16 A_Q14[], /* I AR coefficients, Q14 */
82 opus_int32 len /* I Signal length */
83);
84
85#ifdef __cplusplus
86}
87#endif
88#endif /* SILK_RESAMPLER_PRIVATE_H */
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private_AR2.c b/lib/rbcodec/codecs/libopus/silk/resampler_private_AR2.c
new file mode 100644
index 0000000000..2ec7625e7e
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private_AR2.c
@@ -0,0 +1,55 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33#include "resampler_private.h"
34
35/* Second order AR filter with single delay elements */
36void silk_resampler_private_AR2(
37 opus_int32 S[], /* I/O State vector [ 2 ] */
38 opus_int32 out_Q8[], /* O Output signal */
39 const opus_int16 in[], /* I Input signal */
40 const opus_int16 A_Q14[], /* I AR coefficients, Q14 */
41 opus_int32 len /* I Signal length */
42)
43{
44 opus_int32 k;
45 opus_int32 out32;
46
47 for( k = 0; k < len; k++ ) {
48 out32 = silk_ADD_LSHIFT32( S[ 0 ], (opus_int32)in[ k ], 8 );
49 out_Q8[ k ] = out32;
50 out32 = silk_LSHIFT( out32, 2 );
51 S[ 0 ] = silk_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] );
52 S[ 1 ] = silk_SMULWB( out32, A_Q14[ 1 ] );
53 }
54}
55
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c b/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c
new file mode 100644
index 0000000000..105be35f16
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c
@@ -0,0 +1,103 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33#include "resampler_private.h"
34
35static inline opus_int16 *silk_resampler_private_IIR_FIR_INTERPOL(
36 opus_int16 *out,
37 opus_int16 *buf,
38 opus_int32 max_index_Q16,
39 opus_int32 index_increment_Q16
40)
41{
42 opus_int32 index_Q16, res_Q15;
43 opus_int16 *buf_ptr;
44 opus_int32 table_index;
45
46 /* Interpolate upsampled signal and store in output array */
47 for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
48 table_index = silk_SMULWB( index_Q16 & 0xFFFF, 12 );
49 buf_ptr = &buf[ index_Q16 >> 16 ];
50
51 res_Q15 = silk_SMULBB( buf_ptr[ 0 ], silk_resampler_frac_FIR_12[ table_index ][ 0 ] );
52 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 1 ], silk_resampler_frac_FIR_12[ table_index ][ 1 ] );
53 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 2 ], silk_resampler_frac_FIR_12[ table_index ][ 2 ] );
54 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 3 ], silk_resampler_frac_FIR_12[ table_index ][ 3 ] );
55 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 4 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 3 ] );
56 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 5 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 2 ] );
57 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 6 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 1 ] );
58 res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 7 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 0 ] );
59 *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q15, 15 ) );
60 }
61 return out;
62}
63/* Upsample using a combination of allpass-based 2x upsampling and FIR interpolation */
64void silk_resampler_private_IIR_FIR(
65 void *SS, /* I/O Resampler state */
66 opus_int16 out[], /* O Output signal */
67 const opus_int16 in[], /* I Input signal */
68 opus_int32 inLen /* I Number of input samples */
69)
70{
71 silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
72 opus_int32 nSamplesIn;
73 opus_int32 max_index_Q16, index_increment_Q16;
74 opus_int16 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_12 ];
75
76 /* Copy buffered samples to start of buffer */
77 silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
78
79 /* Iterate over blocks of frameSizeIn input samples */
80 index_increment_Q16 = S->invRatio_Q16;
81 while( 1 ) {
82 nSamplesIn = silk_min( inLen, S->batchSize );
83
84 /* Upsample 2x */
85 silk_resampler_private_up2_HQ( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_12 ], in, nSamplesIn );
86
87 max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 + 1 ); /* + 1 because 2x upsampling */
88 out = silk_resampler_private_IIR_FIR_INTERPOL( out, buf, max_index_Q16, index_increment_Q16 );
89 in += nSamplesIn;
90 inLen -= nSamplesIn;
91
92 if( inLen > 0 ) {
93 /* More iterations to do; copy last part of filtered signal to beginning of buffer */
94 silk_memcpy( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
95 } else {
96 break;
97 }
98 }
99
100 /* Copy last part of filtered signal to the state for the next call */
101 silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
102}
103
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private_down_FIR.c b/lib/rbcodec/codecs/libopus/silk/resampler_private_down_FIR.c
new file mode 100644
index 0000000000..5d4cb1f072
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private_down_FIR.c
@@ -0,0 +1,189 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33#include "resampler_private.h"
34
35static inline opus_int16 *silk_resampler_private_down_FIR_INTERPOL(
36 opus_int16 *out,
37 opus_int32 *buf,
38 const opus_int16 *FIR_Coefs,
39 opus_int FIR_Order,
40 opus_int FIR_Fracs,
41 opus_int32 max_index_Q16,
42 opus_int32 index_increment_Q16
43)
44{
45 opus_int32 index_Q16, res_Q6;
46 opus_int32 *buf_ptr;
47 opus_int32 interpol_ind;
48 const opus_int16 *interpol_ptr;
49
50 switch( FIR_Order ) {
51 case RESAMPLER_DOWN_ORDER_FIR0:
52 for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
53 /* Integer part gives pointer to buffered input */
54 buf_ptr = buf + silk_RSHIFT( index_Q16, 16 );
55
56 /* Fractional part gives interpolation coefficients */
57 interpol_ind = silk_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs );
58
59 /* Inner product */
60 interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * interpol_ind ];
61 res_Q6 = silk_SMULWB( buf_ptr[ 0 ], interpol_ptr[ 0 ] );
62 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] );
63 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] );
64 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] );
65 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] );
66 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] );
67 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 6 ], interpol_ptr[ 6 ] );
68 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 7 ], interpol_ptr[ 7 ] );
69 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 8 ], interpol_ptr[ 8 ] );
70 interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * ( FIR_Fracs - 1 - interpol_ind ) ];
71 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 17 ], interpol_ptr[ 0 ] );
72 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 16 ], interpol_ptr[ 1 ] );
73 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 15 ], interpol_ptr[ 2 ] );
74 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 14 ], interpol_ptr[ 3 ] );
75 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 13 ], interpol_ptr[ 4 ] );
76 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 12 ], interpol_ptr[ 5 ] );
77 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 6 ] );
78 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 7 ] );
79 res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 9 ], interpol_ptr[ 8 ] );
80
81 /* Scale down, saturate and store in output array */
82 *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) );
83 }
84 break;
85 case RESAMPLER_DOWN_ORDER_FIR1:
86 for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
87 /* Integer part gives pointer to buffered input */
88 buf_ptr = buf + silk_RSHIFT( index_Q16, 16 );
89
90 /* Inner product */
91 res_Q6 = silk_SMULWB( silk_ADD32( buf_ptr[ 0 ], buf_ptr[ 23 ] ), FIR_Coefs[ 0 ] );
92 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 1 ], buf_ptr[ 22 ] ), FIR_Coefs[ 1 ] );
93 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 2 ], buf_ptr[ 21 ] ), FIR_Coefs[ 2 ] );
94 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 3 ], buf_ptr[ 20 ] ), FIR_Coefs[ 3 ] );
95 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 4 ], buf_ptr[ 19 ] ), FIR_Coefs[ 4 ] );
96 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 5 ], buf_ptr[ 18 ] ), FIR_Coefs[ 5 ] );
97 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 6 ], buf_ptr[ 17 ] ), FIR_Coefs[ 6 ] );
98 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 7 ], buf_ptr[ 16 ] ), FIR_Coefs[ 7 ] );
99 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 8 ], buf_ptr[ 15 ] ), FIR_Coefs[ 8 ] );
100 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 9 ], buf_ptr[ 14 ] ), FIR_Coefs[ 9 ] );
101 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 10 ], buf_ptr[ 13 ] ), FIR_Coefs[ 10 ] );
102 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 11 ], buf_ptr[ 12 ] ), FIR_Coefs[ 11 ] );
103
104 /* Scale down, saturate and store in output array */
105 *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) );
106 }
107 break;
108 case RESAMPLER_DOWN_ORDER_FIR2:
109 for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
110 /* Integer part gives pointer to buffered input */
111 buf_ptr = buf + silk_RSHIFT( index_Q16, 16 );
112
113 /* Inner product */
114 res_Q6 = silk_SMULWB( silk_ADD32( buf_ptr[ 0 ], buf_ptr[ 35 ] ), FIR_Coefs[ 0 ] );
115 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 1 ], buf_ptr[ 34 ] ), FIR_Coefs[ 1 ] );
116 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 2 ], buf_ptr[ 33 ] ), FIR_Coefs[ 2 ] );
117 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 3 ], buf_ptr[ 32 ] ), FIR_Coefs[ 3 ] );
118 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 4 ], buf_ptr[ 31 ] ), FIR_Coefs[ 4 ] );
119 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 5 ], buf_ptr[ 30 ] ), FIR_Coefs[ 5 ] );
120 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 6 ], buf_ptr[ 29 ] ), FIR_Coefs[ 6 ] );
121 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 7 ], buf_ptr[ 28 ] ), FIR_Coefs[ 7 ] );
122 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 8 ], buf_ptr[ 27 ] ), FIR_Coefs[ 8 ] );
123 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 9 ], buf_ptr[ 26 ] ), FIR_Coefs[ 9 ] );
124 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 10 ], buf_ptr[ 25 ] ), FIR_Coefs[ 10 ] );
125 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 11 ], buf_ptr[ 24 ] ), FIR_Coefs[ 11 ] );
126 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 12 ], buf_ptr[ 23 ] ), FIR_Coefs[ 12 ] );
127 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 13 ], buf_ptr[ 22 ] ), FIR_Coefs[ 13 ] );
128 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 14 ], buf_ptr[ 21 ] ), FIR_Coefs[ 14 ] );
129 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 15 ], buf_ptr[ 20 ] ), FIR_Coefs[ 15 ] );
130 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 16 ], buf_ptr[ 19 ] ), FIR_Coefs[ 16 ] );
131 res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 17 ], buf_ptr[ 18 ] ), FIR_Coefs[ 17 ] );
132
133 /* Scale down, saturate and store in output array */
134 *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) );
135 }
136 break;
137 default:
138 silk_assert( 0 );
139 }
140 return out;
141}
142
143/* Resample with a 2nd order AR filter followed by FIR interpolation */
144void silk_resampler_private_down_FIR(
145 void *SS, /* I/O Resampler state */
146 opus_int16 out[], /* O Output signal */
147 const opus_int16 in[], /* I Input signal */
148 opus_int32 inLen /* I Number of input samples */
149)
150{
151 silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
152 opus_int32 nSamplesIn;
153 opus_int32 max_index_Q16, index_increment_Q16;
154 opus_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + SILK_RESAMPLER_MAX_FIR_ORDER ];
155 const opus_int16 *FIR_Coefs;
156
157 /* Copy buffered samples to start of buffer */
158 silk_memcpy( buf, S->sFIR, S->FIR_Order * sizeof( opus_int32 ) );
159
160 FIR_Coefs = &S->Coefs[ 2 ];
161
162 /* Iterate over blocks of frameSizeIn input samples */
163 index_increment_Q16 = S->invRatio_Q16;
164 while( 1 ) {
165 nSamplesIn = silk_min( inLen, S->batchSize );
166
167 /* Second-order AR filter (output in Q8) */
168 silk_resampler_private_AR2( S->sIIR, &buf[ S->FIR_Order ], in, S->Coefs, nSamplesIn );
169
170 max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 );
171
172 /* Interpolate filtered signal */
173 out = silk_resampler_private_down_FIR_INTERPOL( out, buf, FIR_Coefs, S->FIR_Order,
174 S->FIR_Fracs, max_index_Q16, index_increment_Q16 );
175
176 in += nSamplesIn;
177 inLen -= nSamplesIn;
178
179 if( inLen > 1 ) {
180 /* More iterations to do; copy last part of filtered signal to beginning of buffer */
181 silk_memcpy( buf, &buf[ nSamplesIn ], S->FIR_Order * sizeof( opus_int32 ) );
182 } else {
183 break;
184 }
185 }
186
187 /* Copy last part of filtered signal to the state for the next call */
188 silk_memcpy( S->sFIR, &buf[ nSamplesIn ], S->FIR_Order * sizeof( opus_int32 ) );
189}
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private_up2_HQ.c b/lib/rbcodec/codecs/libopus/silk/resampler_private_up2_HQ.c
new file mode 100644
index 0000000000..6479a154da
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private_up2_HQ.c
@@ -0,0 +1,113 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33#include "resampler_private.h"
34
35/* Upsample by a factor 2, high quality */
36/* Uses 2nd order allpass filters for the 2x upsampling, followed by a */
37/* notch filter just above Nyquist. */
38void silk_resampler_private_up2_HQ(
39 opus_int32 *S, /* I/O Resampler state [ 6 ] */
40 opus_int16 *out, /* O Output signal [ 2 * len ] */
41 const opus_int16 *in, /* I Input signal [ len ] */
42 opus_int32 len /* I Number of input samples */
43)
44{
45 opus_int32 k;
46 opus_int32 in32, out32_1, out32_2, Y, X;
47
48 silk_assert( silk_resampler_up2_hq_0[ 0 ] > 0 );
49 silk_assert( silk_resampler_up2_hq_0[ 1 ] > 0 );
50 silk_assert( silk_resampler_up2_hq_0[ 2 ] < 0 );
51 silk_assert( silk_resampler_up2_hq_1[ 0 ] > 0 );
52 silk_assert( silk_resampler_up2_hq_1[ 1 ] > 0 );
53 silk_assert( silk_resampler_up2_hq_1[ 2 ] < 0 );
54
55 /* Internal variables and state are in Q10 format */
56 for( k = 0; k < len; k++ ) {
57 /* Convert to Q10 */
58 in32 = silk_LSHIFT( (opus_int32)in[ k ], 10 );
59
60 /* First all-pass section for even output sample */
61 Y = silk_SUB32( in32, S[ 0 ] );
62 X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 0 ] );
63 out32_1 = silk_ADD32( S[ 0 ], X );
64 S[ 0 ] = silk_ADD32( in32, X );
65
66 /* Second all-pass section for even output sample */
67 Y = silk_SUB32( out32_1, S[ 1 ] );
68 X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 1 ] );
69 out32_2 = silk_ADD32( S[ 1 ], X );
70 S[ 1 ] = silk_ADD32( out32_1, X );
71
72 /* Third all-pass section for even output sample */
73 Y = silk_SUB32( out32_2, S[ 2 ] );
74 X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_0[ 2 ] );
75 out32_1 = silk_ADD32( S[ 2 ], X );
76 S[ 2 ] = silk_ADD32( out32_2, X );
77
78 /* Apply gain in Q15, convert back to int16 and store to output */
79 out[ 2 * k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
80
81 /* First all-pass section for odd output sample */
82 Y = silk_SUB32( in32, S[ 3 ] );
83 X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 0 ] );
84 out32_1 = silk_ADD32( S[ 3 ], X );
85 S[ 3 ] = silk_ADD32( in32, X );
86
87 /* Second all-pass section for odd output sample */
88 Y = silk_SUB32( out32_1, S[ 4 ] );
89 X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 1 ] );
90 out32_2 = silk_ADD32( S[ 4 ], X );
91 S[ 4 ] = silk_ADD32( out32_1, X );
92
93 /* Third all-pass section for odd output sample */
94 Y = silk_SUB32( out32_2, S[ 5 ] );
95 X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_1[ 2 ] );
96 out32_1 = silk_ADD32( S[ 5 ], X );
97 S[ 5 ] = silk_ADD32( out32_2, X );
98
99 /* Apply gain in Q15, convert back to int16 and store to output */
100 out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
101 }
102}
103
104void silk_resampler_private_up2_HQ_wrapper(
105 void *SS, /* I/O Resampler state (unused) */
106 opus_int16 *out, /* O Output signal [ 2 * len ] */
107 const opus_int16 *in, /* I Input signal [ len ] */
108 opus_int32 len /* I Number of input samples */
109)
110{
111 silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
112 silk_resampler_private_up2_HQ( S->sIIR, out, in, len );
113}
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_rom.c b/lib/rbcodec/codecs/libopus/silk/resampler_rom.c
new file mode 100644
index 0000000000..bbbd6d1690
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_rom.c
@@ -0,0 +1,96 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/* Filter coefficients for IIR/FIR polyphase resampling *
33 * Total size: 179 Words (358 Bytes) */
34
35#include "resampler_private.h"
36
37/* Matlab code for the notch filter coefficients: */
38/* B = [1, 0.147, 1]; A = [1, 0.107, 0.89]; G = 0.93; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]) */
39/* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */
40/* const opus_int16 silk_resampler_up2_hq_notch[ 4 ] = { 9634, -7012, 7209, 30474 }; */
41
42/* Tables with IIR and FIR coefficients for fractional downsamplers (123 Words) */
43silk_DWORD_ALIGN const opus_int16 silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ] = {
44 -20694, -13867,
45 -49, 64, 17, -157, 353, -496, 163, 11047, 22205,
46 -39, 6, 91, -170, 186, 23, -896, 6336, 19928,
47 -19, -36, 102, -89, -24, 328, -951, 2568, 15909,
48};
49
50silk_DWORD_ALIGN const opus_int16 silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ] = {
51 -14457, -14019,
52 64, 128, -122, 36, 310, -768, 584, 9267, 17733,
53 12, 128, 18, -142, 288, -117, -865, 4123, 14459,
54};
55
56silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR1 / 2 ] = {
57 616, -14323,
58 -10, 39, 58, -46, -84, 120, 184, -315, -541, 1284, 5380, 9024,
59};
60
61silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = {
62 16102, -15162,
63 -13, 0, 20, 26, 5, -31, -43, -4, 65, 90, 7, -157, -248, -44, 593, 1583, 2612, 3271,
64};
65
66silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_4_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = {
67 22500, -15099,
68 3, -14, -20, -15, 2, 25, 37, 25, -16, -71, -107, -79, 50, 292, 623, 982, 1288, 1464,
69};
70
71silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_6_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = {
72 27540, -15257,
73 17, 12, 8, 1, -10, -22, -30, -32, -22, 3, 44, 100, 168, 243, 317, 381, 429, 455,
74};
75
76silk_DWORD_ALIGN const opus_int16 silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = {
77 -2797, -6507,
78 4697, 10739,
79 1567, 8276,
80};
81
82/* Table with interplation fractions of 1/24, 3/24, 5/24, ... , 23/24 : 23/24 (46 Words) */
83silk_DWORD_ALIGN const opus_int16 silk_resampler_frac_FIR_12[ 12 ][ RESAMPLER_ORDER_FIR_12 / 2 ] = {
84 { 189, -600, 617, 30567 },
85 { 117, -159, -1070, 29704 },
86 { 52, 221, -2392, 28276 },
87 { -4, 529, -3350, 26341 },
88 { -48, 758, -3956, 23973 },
89 { -80, 905, -4235, 21254 },
90 { -99, 972, -4222, 18278 },
91 { -107, 967, -3957, 15143 },
92 { -103, 896, -3487, 11950 },
93 { -91, 773, -2865, 8798 },
94 { -71, 611, -2143, 5784 },
95 { -46, 425, -1375, 2996 },
96};
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_rom.h b/lib/rbcodec/codecs/libopus/silk/resampler_rom.h
new file mode 100644
index 0000000000..473b24a2b5
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_rom.h
@@ -0,0 +1,68 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_FIX_RESAMPLER_ROM_H
29#define SILK_FIX_RESAMPLER_ROM_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#endif
35
36#include "typedef.h"
37#include "resampler_structs.h"
38
39#define RESAMPLER_DOWN_ORDER_FIR0 18
40#define RESAMPLER_DOWN_ORDER_FIR1 24
41#define RESAMPLER_DOWN_ORDER_FIR2 36
42#define RESAMPLER_ORDER_FIR_12 8
43
44/* Tables for 2x downsampler */
45static const opus_int16 silk_resampler_down2_0 = 9872;
46static const opus_int16 silk_resampler_down2_1 = 39809 - 65536;
47
48/* Tables for 2x upsampler, high quality */
49static const opus_int16 silk_resampler_up2_hq_0[ 3 ] = { 1746, 14986, 39083 - 65536 };
50static const opus_int16 silk_resampler_up2_hq_1[ 3 ] = { 6854, 25769, 55542 - 65536 };
51
52/* Tables with IIR and FIR coefficients for fractional downsamplers */
53extern const opus_int16 silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ];
54extern const opus_int16 silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ];
55extern const opus_int16 silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR1 / 2 ];
56extern const opus_int16 silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ];
57extern const opus_int16 silk_Resampler_1_4_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ];
58extern const opus_int16 silk_Resampler_1_6_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ];
59extern const opus_int16 silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ];
60
61/* Table with interplation fractions of 1/24, 3/24, ..., 23/24 */
62extern const opus_int16 silk_resampler_frac_FIR_12[ 12 ][ RESAMPLER_ORDER_FIR_12 / 2 ];
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif /* SILK_FIX_RESAMPLER_ROM_H */
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_structs.h b/lib/rbcodec/codecs/libopus/silk/resampler_structs.h
new file mode 100644
index 0000000000..4c28bd0a2f
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_structs.h
@@ -0,0 +1,57 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_RESAMPLER_STRUCTS_H
29#define SILK_RESAMPLER_STRUCTS_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#define SILK_RESAMPLER_MAX_FIR_ORDER 36
36#define SILK_RESAMPLER_MAX_IIR_ORDER 6
37
38typedef struct _silk_resampler_state_struct{
39 opus_int32 sIIR[ SILK_RESAMPLER_MAX_IIR_ORDER ]; /* this must be the first element of this struct */
40 opus_int32 sFIR[ SILK_RESAMPLER_MAX_FIR_ORDER ];
41 opus_int16 delayBuf[ 48 ];
42 opus_int resampler_function;
43 opus_int batchSize;
44 opus_int32 invRatio_Q16;
45 opus_int FIR_Order;
46 opus_int FIR_Fracs;
47 opus_int Fs_in_kHz;
48 opus_int Fs_out_kHz;
49 opus_int inputDelay;
50 const opus_int16 *Coefs;
51} silk_resampler_state_struct;
52
53#ifdef __cplusplus
54}
55#endif
56#endif /* SILK_RESAMPLER_STRUCTS_H */
57
diff --git a/lib/rbcodec/codecs/libopus/silk/shell_coder.c b/lib/rbcodec/codecs/libopus/silk/shell_coder.c
new file mode 100644
index 0000000000..1cc77fd88e
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/shell_coder.c
@@ -0,0 +1,151 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* shell coder; pulse-subframe length is hardcoded */
35
36static inline void combine_pulses(
37 opus_int *out, /* O combined pulses vector [len] */
38 const opus_int *in, /* I input vector [2 * len] */
39 const opus_int len /* I number of OUTPUT samples */
40)
41{
42 opus_int k;
43 for( k = 0; k < len; k++ ) {
44 out[ k ] = in[ 2 * k ] + in[ 2 * k + 1 ];
45 }
46}
47
48static inline void encode_split(
49 ec_enc *psRangeEnc, /* I/O compressor data structure */
50 const opus_int p_child1, /* I pulse amplitude of first child subframe */
51 const opus_int p, /* I pulse amplitude of current subframe */
52 const opus_uint8 *shell_table /* I table of shell cdfs */
53)
54{
55 if( p > 0 ) {
56 ec_enc_icdf( psRangeEnc, p_child1, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 );
57 }
58}
59
60static inline void decode_split(
61 opus_int *p_child1, /* O pulse amplitude of first child subframe */
62 opus_int *p_child2, /* O pulse amplitude of second child subframe */
63 ec_dec *psRangeDec, /* I/O Compressor data structure */
64 const opus_int p, /* I pulse amplitude of current subframe */
65 const opus_uint8 *shell_table /* I table of shell cdfs */
66)
67{
68 if( p > 0 ) {
69 p_child1[ 0 ] = ec_dec_icdf( psRangeDec, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 );
70 p_child2[ 0 ] = p - p_child1[ 0 ];
71 } else {
72 p_child1[ 0 ] = 0;
73 p_child2[ 0 ] = 0;
74 }
75}
76
77/* Shell encoder, operates on one shell code frame of 16 pulses */
78void silk_shell_encoder(
79 ec_enc *psRangeEnc, /* I/O compressor data structure */
80 const opus_int *pulses0 /* I data: nonnegative pulse amplitudes */
81)
82{
83 opus_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];
84
85 /* this function operates on one shell code frame of 16 pulses */
86 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
87
88 /* tree representation per pulse-subframe */
89 combine_pulses( pulses1, pulses0, 8 );
90 combine_pulses( pulses2, pulses1, 4 );
91 combine_pulses( pulses3, pulses2, 2 );
92 combine_pulses( pulses4, pulses3, 1 );
93
94 encode_split( psRangeEnc, pulses3[ 0 ], pulses4[ 0 ], silk_shell_code_table3 );
95
96 encode_split( psRangeEnc, pulses2[ 0 ], pulses3[ 0 ], silk_shell_code_table2 );
97
98 encode_split( psRangeEnc, pulses1[ 0 ], pulses2[ 0 ], silk_shell_code_table1 );
99 encode_split( psRangeEnc, pulses0[ 0 ], pulses1[ 0 ], silk_shell_code_table0 );
100 encode_split( psRangeEnc, pulses0[ 2 ], pulses1[ 1 ], silk_shell_code_table0 );
101
102 encode_split( psRangeEnc, pulses1[ 2 ], pulses2[ 1 ], silk_shell_code_table1 );
103 encode_split( psRangeEnc, pulses0[ 4 ], pulses1[ 2 ], silk_shell_code_table0 );
104 encode_split( psRangeEnc, pulses0[ 6 ], pulses1[ 3 ], silk_shell_code_table0 );
105
106 encode_split( psRangeEnc, pulses2[ 2 ], pulses3[ 1 ], silk_shell_code_table2 );
107
108 encode_split( psRangeEnc, pulses1[ 4 ], pulses2[ 2 ], silk_shell_code_table1 );
109 encode_split( psRangeEnc, pulses0[ 8 ], pulses1[ 4 ], silk_shell_code_table0 );
110 encode_split( psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], silk_shell_code_table0 );
111
112 encode_split( psRangeEnc, pulses1[ 6 ], pulses2[ 3 ], silk_shell_code_table1 );
113 encode_split( psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], silk_shell_code_table0 );
114 encode_split( psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], silk_shell_code_table0 );
115}
116
117
118/* Shell decoder, operates on one shell code frame of 16 pulses */
119void silk_shell_decoder(
120 opus_int *pulses0, /* O data: nonnegative pulse amplitudes */
121 ec_dec *psRangeDec, /* I/O Compressor data structure */
122 const opus_int pulses4 /* I number of pulses per pulse-subframe */
123)
124{
125 opus_int pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ];
126
127 /* this function operates on one shell code frame of 16 pulses */
128 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
129
130 decode_split( &pulses3[ 0 ], &pulses3[ 1 ], psRangeDec, pulses4, silk_shell_code_table3 );
131
132 decode_split( &pulses2[ 0 ], &pulses2[ 1 ], psRangeDec, pulses3[ 0 ], silk_shell_code_table2 );
133
134 decode_split( &pulses1[ 0 ], &pulses1[ 1 ], psRangeDec, pulses2[ 0 ], silk_shell_code_table1 );
135 decode_split( &pulses0[ 0 ], &pulses0[ 1 ], psRangeDec, pulses1[ 0 ], silk_shell_code_table0 );
136 decode_split( &pulses0[ 2 ], &pulses0[ 3 ], psRangeDec, pulses1[ 1 ], silk_shell_code_table0 );
137
138 decode_split( &pulses1[ 2 ], &pulses1[ 3 ], psRangeDec, pulses2[ 1 ], silk_shell_code_table1 );
139 decode_split( &pulses0[ 4 ], &pulses0[ 5 ], psRangeDec, pulses1[ 2 ], silk_shell_code_table0 );
140 decode_split( &pulses0[ 6 ], &pulses0[ 7 ], psRangeDec, pulses1[ 3 ], silk_shell_code_table0 );
141
142 decode_split( &pulses2[ 2 ], &pulses2[ 3 ], psRangeDec, pulses3[ 1 ], silk_shell_code_table2 );
143
144 decode_split( &pulses1[ 4 ], &pulses1[ 5 ], psRangeDec, pulses2[ 2 ], silk_shell_code_table1 );
145 decode_split( &pulses0[ 8 ], &pulses0[ 9 ], psRangeDec, pulses1[ 4 ], silk_shell_code_table0 );
146 decode_split( &pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], silk_shell_code_table0 );
147
148 decode_split( &pulses1[ 6 ], &pulses1[ 7 ], psRangeDec, pulses2[ 3 ], silk_shell_code_table1 );
149 decode_split( &pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], silk_shell_code_table0 );
150 decode_split( &pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], silk_shell_code_table0 );
151}
diff --git a/lib/rbcodec/codecs/libopus/silk/sort.c b/lib/rbcodec/codecs/libopus/silk/sort.c
new file mode 100644
index 0000000000..f9886b45b2
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/sort.c
@@ -0,0 +1,154 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32/* Insertion sort (fast for already almost sorted arrays): */
33/* Best case: O(n) for an already sorted array */
34/* Worst case: O(n^2) for an inversely sorted array */
35/* */
36/* Shell short: http://en.wikipedia.org/wiki/Shell_sort */
37
38#include "SigProc_FIX.h"
39
40void silk_insertion_sort_increasing(
41 opus_int32 *a, /* I/O Unsorted / Sorted vector */
42 opus_int *idx, /* O Index vector for the sorted elements */
43 const opus_int L, /* I Vector length */
44 const opus_int K /* I Number of correctly sorted positions */
45)
46{
47 opus_int32 value;
48 opus_int i, j;
49
50 /* Safety checks */
51 silk_assert( K > 0 );
52 silk_assert( L > 0 );
53 silk_assert( L >= K );
54
55 /* Write start indices in index vector */
56 for( i = 0; i < K; i++ ) {
57 idx[ i ] = i;
58 }
59
60 /* Sort vector elements by value, increasing order */
61 for( i = 1; i < K; i++ ) {
62 value = a[ i ];
63 for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
64 a[ j + 1 ] = a[ j ]; /* Shift value */
65 idx[ j + 1 ] = idx[ j ]; /* Shift index */
66 }
67 a[ j + 1 ] = value; /* Write value */
68 idx[ j + 1 ] = i; /* Write index */
69 }
70
71 /* If less than L values are asked for, check the remaining values, */
72 /* but only spend CPU to ensure that the K first values are correct */
73 for( i = K; i < L; i++ ) {
74 value = a[ i ];
75 if( value < a[ K - 1 ] ) {
76 for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
77 a[ j + 1 ] = a[ j ]; /* Shift value */
78 idx[ j + 1 ] = idx[ j ]; /* Shift index */
79 }
80 a[ j + 1 ] = value; /* Write value */
81 idx[ j + 1 ] = i; /* Write index */
82 }
83 }
84}
85
86#ifdef FIXED_POINT
87/* This function is only used by the fixed-point build */
88void silk_insertion_sort_decreasing_int16(
89 opus_int16 *a, /* I/O Unsorted / Sorted vector */
90 opus_int *idx, /* O Index vector for the sorted elements */
91 const opus_int L, /* I Vector length */
92 const opus_int K /* I Number of correctly sorted positions */
93)
94{
95 opus_int i, j;
96 opus_int value;
97
98 /* Safety checks */
99 silk_assert( K > 0 );
100 silk_assert( L > 0 );
101 silk_assert( L >= K );
102
103 /* Write start indices in index vector */
104 for( i = 0; i < K; i++ ) {
105 idx[ i ] = i;
106 }
107
108 /* Sort vector elements by value, decreasing order */
109 for( i = 1; i < K; i++ ) {
110 value = a[ i ];
111 for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {
112 a[ j + 1 ] = a[ j ]; /* Shift value */
113 idx[ j + 1 ] = idx[ j ]; /* Shift index */
114 }
115 a[ j + 1 ] = value; /* Write value */
116 idx[ j + 1 ] = i; /* Write index */
117 }
118
119 /* If less than L values are asked for, check the remaining values, */
120 /* but only spend CPU to ensure that the K first values are correct */
121 for( i = K; i < L; i++ ) {
122 value = a[ i ];
123 if( value > a[ K - 1 ] ) {
124 for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {
125 a[ j + 1 ] = a[ j ]; /* Shift value */
126 idx[ j + 1 ] = idx[ j ]; /* Shift index */
127 }
128 a[ j + 1 ] = value; /* Write value */
129 idx[ j + 1 ] = i; /* Write index */
130 }
131 }
132}
133#endif
134
135void silk_insertion_sort_increasing_all_values_int16(
136 opus_int16 *a, /* I/O Unsorted / Sorted vector */
137 const opus_int L /* I Vector length */
138)
139{
140 opus_int value;
141 opus_int i, j;
142
143 /* Safety checks */
144 silk_assert( L > 0 );
145
146 /* Sort vector elements by value, increasing order */
147 for( i = 1; i < L; i++ ) {
148 value = a[ i ];
149 for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
150 a[ j + 1 ] = a[ j ]; /* Shift value */
151 }
152 a[ j + 1 ] = value; /* Write value */
153 }
154}
diff --git a/lib/rbcodec/codecs/libopus/silk/stereo_MS_to_LR.c b/lib/rbcodec/codecs/libopus/silk/stereo_MS_to_LR.c
new file mode 100644
index 0000000000..3705b59686
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/stereo_MS_to_LR.c
@@ -0,0 +1,85 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Convert adaptive Mid/Side representation to Left/Right stereo signal */
35void silk_stereo_MS_to_LR(
36 stereo_dec_state *state, /* I/O State */
37 opus_int16 x1[], /* I/O Left input signal, becomes mid signal */
38 opus_int16 x2[], /* I/O Right input signal, becomes side signal */
39 const opus_int32 pred_Q13[], /* I Predictors */
40 opus_int fs_kHz, /* I Samples rate (kHz) */
41 opus_int frame_length /* I Number of samples */
42)
43{
44 opus_int n, denom_Q16, delta0_Q13, delta1_Q13;
45 opus_int32 sum, diff, pred0_Q13, pred1_Q13;
46
47 /* Buffering */
48 silk_memcpy( x1, state->sMid, 2 * sizeof( opus_int16 ) );
49 silk_memcpy( x2, state->sSide, 2 * sizeof( opus_int16 ) );
50 silk_memcpy( state->sMid, &x1[ frame_length ], 2 * sizeof( opus_int16 ) );
51 silk_memcpy( state->sSide, &x2[ frame_length ], 2 * sizeof( opus_int16 ) );
52
53 /* Interpolate predictors and add prediction to side channel */
54 pred0_Q13 = state->pred_prev_Q13[ 0 ];
55 pred1_Q13 = state->pred_prev_Q13[ 1 ];
56 denom_Q16 = silk_DIV32_16( (opus_int32)1 << 16, STEREO_INTERP_LEN_MS * fs_kHz );
57 delta0_Q13 = silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 0 ] - state->pred_prev_Q13[ 0 ], denom_Q16 ), 16 );
58 delta1_Q13 = silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 1 ] - state->pred_prev_Q13[ 1 ], denom_Q16 ), 16 );
59 for( n = 0; n < STEREO_INTERP_LEN_MS * fs_kHz; n++ ) {
60 pred0_Q13 += delta0_Q13;
61 pred1_Q13 += delta1_Q13;
62 sum = silk_LSHIFT( silk_ADD_LSHIFT( x1[ n ] + x1[ n + 2 ], x1[ n + 1 ], 1 ), 9 ); /* Q11 */
63 sum = silk_SMLAWB( silk_LSHIFT( (opus_int32)x2[ n + 1 ], 8 ), sum, pred0_Q13 ); /* Q8 */
64 sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)x1[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */
65 x2[ n + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) );
66 }
67 pred0_Q13 = pred_Q13[ 0 ];
68 pred1_Q13 = pred_Q13[ 1 ];
69 for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) {
70 sum = silk_LSHIFT( silk_ADD_LSHIFT( x1[ n ] + x1[ n + 2 ], x1[ n + 1 ], 1 ), 9 ); /* Q11 */
71 sum = silk_SMLAWB( silk_LSHIFT( (opus_int32)x2[ n + 1 ], 8 ), sum, pred0_Q13 ); /* Q8 */
72 sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)x1[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */
73 x2[ n + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) );
74 }
75 state->pred_prev_Q13[ 0 ] = pred_Q13[ 0 ];
76 state->pred_prev_Q13[ 1 ] = pred_Q13[ 1 ];
77
78 /* Convert to left/right signals */
79 for( n = 0; n < frame_length; n++ ) {
80 sum = x1[ n + 1 ] + (opus_int32)x2[ n + 1 ];
81 diff = x1[ n + 1 ] - (opus_int32)x2[ n + 1 ];
82 x1[ n + 1 ] = (opus_int16)silk_SAT16( sum );
83 x2[ n + 1 ] = (opus_int16)silk_SAT16( diff );
84 }
85}
diff --git a/lib/rbcodec/codecs/libopus/silk/stereo_decode_pred.c b/lib/rbcodec/codecs/libopus/silk/stereo_decode_pred.c
new file mode 100644
index 0000000000..8614cb59fb
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/stereo_decode_pred.c
@@ -0,0 +1,73 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "main.h"
33
34/* Decode mid/side predictors */
35void silk_stereo_decode_pred(
36 ec_dec *psRangeDec, /* I/O Compressor data structure */
37 opus_int32 pred_Q13[] /* O Predictors */
38)
39{
40 opus_int n, ix[ 2 ][ 3 ];
41 opus_int32 low_Q13, step_Q13;
42
43 /* Entropy decoding */
44 n = ec_dec_icdf( psRangeDec, silk_stereo_pred_joint_iCDF, 8 );
45 ix[ 0 ][ 2 ] = silk_DIV32_16( n, 5 );
46 ix[ 1 ][ 2 ] = n - 5 * ix[ 0 ][ 2 ];
47 for( n = 0; n < 2; n++ ) {
48 ix[ n ][ 0 ] = ec_dec_icdf( psRangeDec, silk_uniform3_iCDF, 8 );
49 ix[ n ][ 1 ] = ec_dec_icdf( psRangeDec, silk_uniform5_iCDF, 8 );
50 }
51
52 /* Dequantize */
53 for( n = 0; n < 2; n++ ) {
54 ix[ n ][ 0 ] += 3 * ix[ n ][ 2 ];
55 low_Q13 = silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] ];
56 step_Q13 = silk_SMULWB( silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] + 1 ] - low_Q13,
57 SILK_FIX_CONST( 0.5 / STEREO_QUANT_SUB_STEPS, 16 ) );
58 pred_Q13[ n ] = silk_SMLABB( low_Q13, step_Q13, 2 * ix[ n ][ 1 ] + 1 );
59 }
60
61 /* Subtract second from first predictor (helps when actually applying these) */
62 pred_Q13[ 0 ] -= pred_Q13[ 1 ];
63}
64
65/* Decode mid-only flag */
66void silk_stereo_decode_mid_only(
67 ec_dec *psRangeDec, /* I/O Compressor data structure */
68 opus_int *decode_only_mid /* O Flag that only mid channel has been coded */
69)
70{
71 /* Decode flag that only mid channel is coded */
72 *decode_only_mid = ec_dec_icdf( psRangeDec, silk_stereo_only_code_mid_iCDF, 8 );
73}
diff --git a/lib/rbcodec/codecs/libopus/silk/structs.h b/lib/rbcodec/codecs/libopus/silk/structs.h
new file mode 100644
index 0000000000..5d37f6605d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/structs.h
@@ -0,0 +1,324 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_STRUCTS_H
29#define SILK_STRUCTS_H
30
31#include "typedef.h"
32#include "SigProc_FIX.h"
33#include "define.h"
34#include "entenc.h"
35#include "entdec.h"
36
37#ifdef __cplusplus
38extern "C"
39{
40#endif
41
42/************************************/
43/* Noise shaping quantization state */
44/************************************/
45typedef struct {
46 opus_int16 xq[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */
47 opus_int32 sLTP_shp_Q14[ 2 * MAX_FRAME_LENGTH ];
48 opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ];
49 opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
50 opus_int32 sLF_AR_shp_Q14;
51 opus_int lagPrev;
52 opus_int sLTP_buf_idx;
53 opus_int sLTP_shp_buf_idx;
54 opus_int32 rand_seed;
55 opus_int32 prev_gain_Q16;
56 opus_int rewhite_flag;
57} silk_nsq_state;
58
59/********************************/
60/* VAD state */
61/********************************/
62typedef struct {
63 opus_int32 AnaState[ 2 ]; /* Analysis filterbank state: 0-8 kHz */
64 opus_int32 AnaState1[ 2 ]; /* Analysis filterbank state: 0-4 kHz */
65 opus_int32 AnaState2[ 2 ]; /* Analysis filterbank state: 0-2 kHz */
66 opus_int32 XnrgSubfr[ VAD_N_BANDS ]; /* Subframe energies */
67 opus_int32 NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band */
68 opus_int16 HPstate; /* State of differentiator in the lowest band */
69 opus_int32 NL[ VAD_N_BANDS ]; /* Noise energy level in each band */
70 opus_int32 inv_NL[ VAD_N_BANDS ]; /* Inverse noise energy level in each band */
71 opus_int32 NoiseLevelBias[ VAD_N_BANDS ]; /* Noise level estimator bias/offset */
72 opus_int32 counter; /* Frame counter used in the initial phase */
73} silk_VAD_state;
74
75/* Variable cut-off low-pass filter state */
76typedef struct {
77 opus_int32 In_LP_State[ 2 ]; /* Low pass filter state */
78 opus_int32 transition_frame_no; /* Counter which is mapped to a cut-off frequency */
79 opus_int mode; /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */
80} silk_LP_state;
81
82/* Structure containing NLSF codebook */
83typedef struct {
84 const opus_int16 nVectors;
85 const opus_int16 order;
86 const opus_int16 quantStepSize_Q16;
87 const opus_int16 invQuantStepSize_Q6;
88 const opus_uint8 *CB1_NLSF_Q8;
89 const opus_uint8 *CB1_iCDF;
90 const opus_uint8 *pred_Q8;
91 const opus_uint8 *ec_sel;
92 const opus_uint8 *ec_iCDF;
93 const opus_uint8 *ec_Rates_Q5;
94 const opus_int16 *deltaMin_Q15;
95} silk_NLSF_CB_struct;
96
97typedef struct {
98 opus_int16 pred_prev_Q13[ 2 ];
99 opus_int16 sMid[ 2 ];
100 opus_int16 sSide[ 2 ];
101 opus_int32 mid_side_amp_Q0[ 4 ];
102 opus_int16 smth_width_Q14;
103 opus_int16 width_prev_Q14;
104 opus_int16 silent_side_len;
105 opus_int8 predIx[ MAX_FRAMES_PER_PACKET ][ 2 ][ 3 ];
106 opus_int8 mid_only_flags[ MAX_FRAMES_PER_PACKET ];
107} stereo_enc_state;
108
109typedef struct {
110 opus_int16 pred_prev_Q13[ 2 ];
111 opus_int16 sMid[ 2 ];
112 opus_int16 sSide[ 2 ];
113} stereo_dec_state;
114
115typedef struct {
116 opus_int8 GainsIndices[ MAX_NB_SUBFR ];
117 opus_int8 LTPIndex[ MAX_NB_SUBFR ];
118 opus_int8 NLSFIndices[ MAX_LPC_ORDER + 1 ];
119 opus_int16 lagIndex;
120 opus_int8 contourIndex;
121 opus_int8 signalType;
122 opus_int8 quantOffsetType;
123 opus_int8 NLSFInterpCoef_Q2;
124 opus_int8 PERIndex;
125 opus_int8 LTP_scaleIndex;
126 opus_int8 Seed;
127} SideInfoIndices;
128
129/********************************/
130/* Encoder state */
131/********************************/
132typedef struct {
133 opus_int32 In_HP_State[ 2 ]; /* High pass filter state */
134 opus_int32 variable_HP_smth1_Q15; /* State of first smoother */
135 opus_int32 variable_HP_smth2_Q15; /* State of second smoother */
136 silk_LP_state sLP; /* Low pass filter state */
137 silk_VAD_state sVAD; /* Voice activity detector state */
138 silk_nsq_state sNSQ; /* Noise Shape Quantizer State */
139 opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */
140 opus_int speech_activity_Q8; /* Speech activity */
141 opus_int allow_bandwidth_switch; /* Flag indicating that switching of internal bandwidth is allowed */
142 opus_int8 LBRRprevLastGainIndex;
143 opus_int8 prevSignalType;
144 opus_int prevLag;
145 opus_int pitch_LPC_win_length;
146 opus_int max_pitch_lag; /* Highest possible pitch lag (samples) */
147 opus_int32 API_fs_Hz; /* API sampling frequency (Hz) */
148 opus_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */
149 opus_int maxInternal_fs_Hz; /* Maximum internal sampling frequency (Hz) */
150 opus_int minInternal_fs_Hz; /* Minimum internal sampling frequency (Hz) */
151 opus_int desiredInternal_fs_Hz; /* Soft request for internal sampling frequency (Hz) */
152 opus_int fs_kHz; /* Internal sampling frequency (kHz) */
153 opus_int nb_subfr; /* Number of 5 ms subframes in a frame */
154 opus_int frame_length; /* Frame length (samples) */
155 opus_int subfr_length; /* Subframe length (samples) */
156 opus_int ltp_mem_length; /* Length of LTP memory */
157 opus_int la_pitch; /* Look-ahead for pitch analysis (samples) */
158 opus_int la_shape; /* Look-ahead for noise shape analysis (samples) */
159 opus_int shapeWinLength; /* Window length for noise shape analysis (samples) */
160 opus_int32 TargetRate_bps; /* Target bitrate (bps) */
161 opus_int PacketSize_ms; /* Number of milliseconds to put in each packet */
162 opus_int PacketLoss_perc; /* Packet loss rate measured by farend */
163 opus_int32 frameCounter;
164 opus_int Complexity; /* Complexity setting */
165 opus_int nStatesDelayedDecision; /* Number of states in delayed decision quantization */
166 opus_int useInterpolatedNLSFs; /* Flag for using NLSF interpolation */
167 opus_int shapingLPCOrder; /* Filter order for noise shaping filters */
168 opus_int predictLPCOrder; /* Filter order for prediction filters */
169 opus_int pitchEstimationComplexity; /* Complexity level for pitch estimator */
170 opus_int pitchEstimationLPCOrder; /* Whitening filter order for pitch estimator */
171 opus_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */
172 opus_int LTPQuantLowComplexity; /* Flag for low complexity LTP quantization */
173 opus_int mu_LTP_Q9; /* Rate-distortion tradeoff in LTP quantization */
174 opus_int NLSF_MSVQ_Survivors; /* Number of survivors in NLSF MSVQ */
175 opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation, pitch prediction */
176 opus_int controlled_since_last_payload; /* Flag for ensuring codec_control only runs once per packet */
177 opus_int warping_Q16; /* Warping parameter for warped noise shaping */
178 opus_int useCBR; /* Flag to enable constant bitrate */
179 opus_int prefillFlag; /* Flag to indicate that only buffers are prefilled, no coding */
180 const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
181 const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
182 const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
183 opus_int input_quality_bands_Q15[ VAD_N_BANDS ];
184 opus_int input_tilt_Q15;
185 opus_int SNR_dB_Q7; /* Quality setting */
186
187 opus_int8 VAD_flags[ MAX_FRAMES_PER_PACKET ];
188 opus_int8 LBRR_flag;
189 opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ];
190
191 SideInfoIndices indices;
192 opus_int8 pulses[ MAX_FRAME_LENGTH ];
193
194 /* Input/output buffering */
195 opus_int16 inputBuf[ MAX_FRAME_LENGTH + 2 ]; /* Buffer containing input signal */
196 opus_int inputBufIx;
197 opus_int nFramesPerPacket;
198 opus_int nFramesEncoded; /* Number of frames analyzed in current packet */
199
200 opus_int nChannelsAPI;
201 opus_int nChannelsInternal;
202 opus_int channelNb;
203
204 /* Parameters For LTP scaling Control */
205 opus_int frames_since_onset;
206
207 /* Specifically for entropy coding */
208 opus_int ec_prevSignalType;
209 opus_int16 ec_prevLagIndex;
210
211 silk_resampler_state_struct resampler_state;
212
213 /* DTX */
214 opus_int useDTX; /* Flag to enable DTX */
215 opus_int inDTX; /* Flag to signal DTX period */
216 opus_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */
217
218 /* Inband Low Bitrate Redundancy (LBRR) data */
219 opus_int useInBandFEC; /* Saves the API setting for query */
220 opus_int LBRR_enabled; /* Depends on useInBandFRC, bitrate and packet loss rate */
221 opus_int LBRR_GainIncreases; /* Gains increment for coding LBRR frames */
222 SideInfoIndices indices_LBRR[ MAX_FRAMES_PER_PACKET ];
223 opus_int8 pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ];
224} silk_encoder_state;
225
226
227/* Struct for Packet Loss Concealment */
228typedef struct {
229 opus_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */
230 opus_int16 LTPCoef_Q14[ LTP_ORDER ]; /* LTP coeficients to use for voiced concealment */
231 opus_int16 prevLPC_Q12[ MAX_LPC_ORDER ];
232 opus_int last_frame_lost; /* Was previous frame lost */
233 opus_int32 rand_seed; /* Seed for unvoiced signal generation */
234 opus_int16 randScale_Q14; /* Scaling of unvoiced random signal */
235 opus_int32 conc_energy;
236 opus_int conc_energy_shift;
237 opus_int16 prevLTP_scale_Q14;
238 opus_int32 prevGain_Q16[ 2 ];
239 opus_int fs_kHz;
240 opus_int nb_subfr;
241 opus_int subfr_length;
242} silk_PLC_struct;
243
244/* Struct for CNG */
245typedef struct {
246 opus_int32 CNG_exc_buf_Q14[ MAX_FRAME_LENGTH ];
247 opus_int16 CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];
248 opus_int32 CNG_synth_state[ MAX_LPC_ORDER ];
249 opus_int32 CNG_smth_Gain_Q16;
250 opus_int32 rand_seed;
251 opus_int fs_kHz;
252} silk_CNG_struct;
253
254/********************************/
255/* Decoder state */
256/********************************/
257typedef struct {
258 opus_int32 prev_gain_Q16;
259 opus_int32 exc_Q14[ MAX_FRAME_LENGTH ];
260 opus_int32 sLPC_Q14_buf[ MAX_LPC_ORDER ];
261 opus_int16 outBuf[ MAX_FRAME_LENGTH + 2 * MAX_SUB_FRAME_LENGTH ]; /* Buffer for output signal */
262 opus_int lagPrev; /* Previous Lag */
263 opus_int8 LastGainIndex; /* Previous gain index */
264 opus_int fs_kHz; /* Sampling frequency in kHz */
265 opus_int32 fs_API_hz; /* API sample frequency (Hz) */
266 opus_int nb_subfr; /* Number of 5 ms subframes in a frame */
267 opus_int frame_length; /* Frame length (samples) */
268 opus_int subfr_length; /* Subframe length (samples) */
269 opus_int ltp_mem_length; /* Length of LTP memory */
270 opus_int LPC_order; /* LPC order */
271 opus_int16 prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */
272 opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation */
273 const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
274 const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
275
276 /* For buffering payload in case of more frames per packet */
277 opus_int nFramesDecoded;
278 opus_int nFramesPerPacket;
279
280 /* Specifically for entropy coding */
281 opus_int ec_prevSignalType;
282 opus_int16 ec_prevLagIndex;
283
284 opus_int VAD_flags[ MAX_FRAMES_PER_PACKET ];
285 opus_int LBRR_flag;
286 opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ];
287
288 silk_resampler_state_struct resampler_state;
289
290 const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
291
292 /* Quantization indices */
293 SideInfoIndices indices;
294
295 /* CNG state */
296 silk_CNG_struct sCNG;
297
298 /* Stuff used for PLC */
299 opus_int lossCnt;
300 opus_int prevSignalType;
301
302 silk_PLC_struct sPLC;
303
304} silk_decoder_state;
305
306/************************/
307/* Decoder control */
308/************************/
309typedef struct {
310 /* Prediction and coding parameters */
311 opus_int pitchL[ MAX_NB_SUBFR ];
312 opus_int32 Gains_Q16[ MAX_NB_SUBFR ];
313 /* Holds interpolated and final coefficients, 4-byte aligned */
314 silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
315 opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
316 opus_int LTP_scale_Q14;
317} silk_decoder_control;
318
319
320#ifdef __cplusplus
321}
322#endif
323
324#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c b/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c
new file mode 100644
index 0000000000..53f70fd8de
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c
@@ -0,0 +1,85 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "SigProc_FIX.h"
33
34/* Compute number of bits to right shift the sum of squares of a vector */
35/* of int16s to make it fit in an int32 */
36void silk_sum_sqr_shift(
37 opus_int32 *energy, /* O Energy of x, after shifting to the right */
38 opus_int *shift, /* O Number of bits right shift applied to energy */
39 const opus_int16 *x, /* I Input vector */
40 opus_int len /* I Length of input vector */
41)
42{
43 opus_int i, shft;
44 opus_int32 nrg_tmp, nrg;
45
46 nrg = 0;
47 shft = 0;
48 len--;
49 for( i = 0; i < len; i += 2 ) {
50 nrg = silk_SMLABB_ovflw( nrg, x[ i ], x[ i ] );
51 nrg = silk_SMLABB_ovflw( nrg, x[ i + 1 ], x[ i + 1 ] );
52 if( nrg < 0 ) {
53 /* Scale down */
54 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
55 shft = 2;
56 break;
57 }
58 }
59 for( ; i < len; i += 2 ) {
60 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
61 nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] );
62 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, (opus_uint32)nrg_tmp, shft );
63 if( nrg < 0 ) {
64 /* Scale down */
65 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
66 shft += 2;
67 }
68 }
69 if( i == len ) {
70 /* One sample left to process */
71 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
72 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
73 }
74
75 /* Make sure to have at least one extra leading zero (two leading zeros in total) */
76 if( nrg & 0xC0000000 ) {
77 nrg = silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
78 shft += 2;
79 }
80
81 /* Output arguments */
82 *shift = shft;
83 *energy = nrg;
84}
85
diff --git a/lib/rbcodec/codecs/libopus/silk/table_LSF_cos.c b/lib/rbcodec/codecs/libopus/silk/table_LSF_cos.c
new file mode 100644
index 0000000000..b58e3f4728
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/table_LSF_cos.c
@@ -0,0 +1,70 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34/* Cosine approximation table for LSF conversion */
35/* Q12 values (even) */
36const opus_int16 silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ] = {
37 8192, 8190, 8182, 8170,
38 8152, 8130, 8104, 8072,
39 8034, 7994, 7946, 7896,
40 7840, 7778, 7714, 7644,
41 7568, 7490, 7406, 7318,
42 7226, 7128, 7026, 6922,
43 6812, 6698, 6580, 6458,
44 6332, 6204, 6070, 5934,
45 5792, 5648, 5502, 5352,
46 5198, 5040, 4880, 4718,
47 4552, 4382, 4212, 4038,
48 3862, 3684, 3502, 3320,
49 3136, 2948, 2760, 2570,
50 2378, 2186, 1990, 1794,
51 1598, 1400, 1202, 1002,
52 802, 602, 402, 202,
53 0, -202, -402, -602,
54 -802, -1002, -1202, -1400,
55 -1598, -1794, -1990, -2186,
56 -2378, -2570, -2760, -2948,
57 -3136, -3320, -3502, -3684,
58 -3862, -4038, -4212, -4382,
59 -4552, -4718, -4880, -5040,
60 -5198, -5352, -5502, -5648,
61 -5792, -5934, -6070, -6204,
62 -6332, -6458, -6580, -6698,
63 -6812, -6922, -7026, -7128,
64 -7226, -7318, -7406, -7490,
65 -7568, -7644, -7714, -7778,
66 -7840, -7896, -7946, -7994,
67 -8034, -8072, -8104, -8130,
68 -8152, -8170, -8182, -8190,
69 -8192
70};
diff --git a/lib/rbcodec/codecs/libopus/silk/tables.h b/lib/rbcodec/codecs/libopus/silk/tables.h
new file mode 100644
index 0000000000..072b7929d5
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables.h
@@ -0,0 +1,120 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_TABLES_H
29#define SILK_TABLES_H
30
31#include "define.h"
32#include "structs.h"
33
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
39/* Entropy coding tables (with size in bytes indicated) */
40extern const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ]; /* 24 */
41extern const opus_uint8 silk_delta_gain_iCDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ]; /* 41 */
42
43extern const opus_uint8 silk_pitch_lag_iCDF[ 2 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) ];/* 32 */
44extern const opus_uint8 silk_pitch_delta_iCDF[ 21 ]; /* 21 */
45extern const opus_uint8 silk_pitch_contour_iCDF[ 34 ]; /* 34 */
46extern const opus_uint8 silk_pitch_contour_NB_iCDF[ 11 ]; /* 11 */
47extern const opus_uint8 silk_pitch_contour_10_ms_iCDF[ 12 ]; /* 12 */
48extern const opus_uint8 silk_pitch_contour_10_ms_NB_iCDF[ 3 ]; /* 3 */
49
50extern const opus_uint8 silk_pulses_per_block_iCDF[ N_RATE_LEVELS ][ MAX_PULSES + 2 ]; /* 180 */
51extern const opus_uint8 silk_pulses_per_block_BITS_Q5[ N_RATE_LEVELS - 1 ][ MAX_PULSES + 2 ]; /* 162 */
52
53extern const opus_uint8 silk_rate_levels_iCDF[ 2 ][ N_RATE_LEVELS - 1 ]; /* 18 */
54extern const opus_uint8 silk_rate_levels_BITS_Q5[ 2 ][ N_RATE_LEVELS - 1 ]; /* 18 */
55
56extern const opus_uint8 silk_max_pulses_table[ 4 ]; /* 4 */
57
58extern const opus_uint8 silk_shell_code_table0[ 152 ]; /* 152 */
59extern const opus_uint8 silk_shell_code_table1[ 152 ]; /* 152 */
60extern const opus_uint8 silk_shell_code_table2[ 152 ]; /* 152 */
61extern const opus_uint8 silk_shell_code_table3[ 152 ]; /* 152 */
62extern const opus_uint8 silk_shell_code_table_offsets[ MAX_PULSES + 1 ]; /* 17 */
63
64extern const opus_uint8 silk_lsb_iCDF[ 2 ]; /* 2 */
65
66extern const opus_uint8 silk_sign_iCDF[ 42 ]; /* 42 */
67
68extern const opus_uint8 silk_uniform3_iCDF[ 3 ]; /* 3 */
69extern const opus_uint8 silk_uniform4_iCDF[ 4 ]; /* 4 */
70extern const opus_uint8 silk_uniform5_iCDF[ 5 ]; /* 5 */
71extern const opus_uint8 silk_uniform6_iCDF[ 6 ]; /* 6 */
72extern const opus_uint8 silk_uniform8_iCDF[ 8 ]; /* 8 */
73
74extern const opus_uint8 silk_NLSF_EXT_iCDF[ 7 ]; /* 7 */
75
76extern const opus_uint8 silk_LTP_per_index_iCDF[ 3 ]; /* 3 */
77extern const opus_uint8 * const silk_LTP_gain_iCDF_ptrs[ NB_LTP_CBKS ]; /* 3 */
78extern const opus_uint8 * const silk_LTP_gain_BITS_Q5_ptrs[ NB_LTP_CBKS ]; /* 3 */
79extern const opus_int16 silk_LTP_gain_middle_avg_RD_Q14;
80extern const opus_int8 * const silk_LTP_vq_ptrs_Q7[ NB_LTP_CBKS ]; /* 168 */
81extern const opus_int8 silk_LTP_vq_sizes[ NB_LTP_CBKS ]; /* 3 */
82
83extern const opus_uint8 silk_LTPscale_iCDF[ 3 ]; /* 4 */
84extern const opus_int16 silk_LTPScales_table_Q14[ 3 ]; /* 6 */
85
86extern const opus_uint8 silk_type_offset_VAD_iCDF[ 4 ]; /* 4 */
87extern const opus_uint8 silk_type_offset_no_VAD_iCDF[ 2 ]; /* 2 */
88
89extern const opus_int16 silk_stereo_pred_quant_Q13[ STEREO_QUANT_TAB_SIZE ]; /* 32 */
90extern const opus_uint8 silk_stereo_pred_joint_iCDF[ 25 ]; /* 25 */
91extern const opus_uint8 silk_stereo_only_code_mid_iCDF[ 2 ]; /* 2 */
92
93extern const opus_uint8 * const silk_LBRR_flags_iCDF_ptr[ 2 ]; /* 10 */
94
95extern const opus_uint8 silk_NLSF_interpolation_factor_iCDF[ 5 ]; /* 5 */
96
97extern const silk_NLSF_CB_struct silk_NLSF_CB_WB; /* 1040 */
98extern const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB; /* 728 */
99
100/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
101extern const opus_int32 silk_TargetRate_table_NB[ TARGET_RATE_TAB_SZ ]; /* 32 */
102extern const opus_int32 silk_TargetRate_table_MB[ TARGET_RATE_TAB_SZ ]; /* 32 */
103extern const opus_int32 silk_TargetRate_table_WB[ TARGET_RATE_TAB_SZ ]; /* 32 */
104extern const opus_int16 silk_SNR_table_Q1[ TARGET_RATE_TAB_SZ ]; /* 32 */
105
106/* Quantization offsets */
107extern const opus_int16 silk_Quantization_Offsets_Q10[ 2 ][ 2 ]; /* 8 */
108
109/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
110extern const opus_int32 silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ]; /* 60 */
111extern const opus_int32 silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ]; /* 60 */
112
113/* Rom table with cosine values */
114extern const opus_int16 silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ]; /* 258 */
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_LTP.c b/lib/rbcodec/codecs/libopus/silk/tables_LTP.c
new file mode 100644
index 0000000000..6deb9bc556
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_LTP.c
@@ -0,0 +1,272 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34const opus_uint8 silk_LTP_per_index_iCDF[3] = {
35 179, 99, 0
36};
37
38static const opus_uint8 silk_LTP_gain_iCDF_0[8] = {
39 71, 56, 43, 30, 21, 12, 6, 0
40};
41
42static const opus_uint8 silk_LTP_gain_iCDF_1[16] = {
43 199, 165, 144, 124, 109, 96, 84, 71,
44 61, 51, 42, 32, 23, 15, 8, 0
45};
46
47static const opus_uint8 silk_LTP_gain_iCDF_2[32] = {
48 241, 225, 211, 199, 187, 175, 164, 153,
49 142, 132, 123, 114, 105, 96, 88, 80,
50 72, 64, 57, 50, 44, 38, 33, 29,
51 24, 20, 16, 12, 9, 5, 2, 0
52};
53
54const opus_int16 silk_LTP_gain_middle_avg_RD_Q14 = 12304;
55
56static const opus_uint8 silk_LTP_gain_BITS_Q5_0[8] = {
57 15, 131, 138, 138, 155, 155, 173, 173
58};
59
60static const opus_uint8 silk_LTP_gain_BITS_Q5_1[16] = {
61 69, 93, 115, 118, 131, 138, 141, 138,
62 150, 150, 155, 150, 155, 160, 166, 160
63};
64
65static const opus_uint8 silk_LTP_gain_BITS_Q5_2[32] = {
66 131, 128, 134, 141, 141, 141, 145, 145,
67 145, 150, 155, 155, 155, 155, 160, 160,
68 160, 160, 166, 166, 173, 173, 182, 192,
69 182, 192, 192, 192, 205, 192, 205, 224
70};
71
72const opus_uint8 * const silk_LTP_gain_iCDF_ptrs[NB_LTP_CBKS] = {
73 silk_LTP_gain_iCDF_0,
74 silk_LTP_gain_iCDF_1,
75 silk_LTP_gain_iCDF_2
76};
77
78const opus_uint8 * const silk_LTP_gain_BITS_Q5_ptrs[NB_LTP_CBKS] = {
79 silk_LTP_gain_BITS_Q5_0,
80 silk_LTP_gain_BITS_Q5_1,
81 silk_LTP_gain_BITS_Q5_2
82};
83
84static const opus_int8 silk_LTP_gain_vq_0[8][5] =
85{
86{
87 4, 6, 24, 7, 5
88},
89{
90 0, 0, 2, 0, 0
91},
92{
93 12, 28, 41, 13, -4
94},
95{
96 -9, 15, 42, 25, 14
97},
98{
99 1, -2, 62, 41, -9
100},
101{
102 -10, 37, 65, -4, 3
103},
104{
105 -6, 4, 66, 7, -8
106},
107{
108 16, 14, 38, -3, 33
109}
110};
111
112static const opus_int8 silk_LTP_gain_vq_1[16][5] =
113{
114{
115 13, 22, 39, 23, 12
116},
117{
118 -1, 36, 64, 27, -6
119},
120{
121 -7, 10, 55, 43, 17
122},
123{
124 1, 1, 8, 1, 1
125},
126{
127 6, -11, 74, 53, -9
128},
129{
130 -12, 55, 76, -12, 8
131},
132{
133 -3, 3, 93, 27, -4
134},
135{
136 26, 39, 59, 3, -8
137},
138{
139 2, 0, 77, 11, 9
140},
141{
142 -8, 22, 44, -6, 7
143},
144{
145 40, 9, 26, 3, 9
146},
147{
148 -7, 20, 101, -7, 4
149},
150{
151 3, -8, 42, 26, 0
152},
153{
154 -15, 33, 68, 2, 23
155},
156{
157 -2, 55, 46, -2, 15
158},
159{
160 3, -1, 21, 16, 41
161}
162};
163
164static const opus_int8 silk_LTP_gain_vq_2[32][5] =
165{
166{
167 -6, 27, 61, 39, 5
168},
169{
170 -11, 42, 88, 4, 1
171},
172{
173 -2, 60, 65, 6, -4
174},
175{
176 -1, -5, 73, 56, 1
177},
178{
179 -9, 19, 94, 29, -9
180},
181{
182 0, 12, 99, 6, 4
183},
184{
185 8, -19, 102, 46, -13
186},
187{
188 3, 2, 13, 3, 2
189},
190{
191 9, -21, 84, 72, -18
192},
193{
194 -11, 46, 104, -22, 8
195},
196{
197 18, 38, 48, 23, 0
198},
199{
200 -16, 70, 83, -21, 11
201},
202{
203 5, -11, 117, 22, -8
204},
205{
206 -6, 23, 117, -12, 3
207},
208{
209 3, -8, 95, 28, 4
210},
211{
212 -10, 15, 77, 60, -15
213},
214{
215 -1, 4, 124, 2, -4
216},
217{
218 3, 38, 84, 24, -25
219},
220{
221 2, 13, 42, 13, 31
222},
223{
224 21, -4, 56, 46, -1
225},
226{
227 -1, 35, 79, -13, 19
228},
229{
230 -7, 65, 88, -9, -14
231},
232{
233 20, 4, 81, 49, -29
234},
235{
236 20, 0, 75, 3, -17
237},
238{
239 5, -9, 44, 92, -8
240},
241{
242 1, -3, 22, 69, 31
243},
244{
245 -6, 95, 41, -12, 5
246},
247{
248 39, 67, 16, -4, 1
249},
250{
251 0, -6, 120, 55, -36
252},
253{
254 -13, 44, 122, 4, -24
255},
256{
257 81, 5, 11, 3, 7
258},
259{
260 2, 0, 9, 10, 88
261}
262};
263
264const opus_int8 * const silk_LTP_vq_ptrs_Q7[NB_LTP_CBKS] = {
265 (opus_int8 *)&silk_LTP_gain_vq_0[0][0],
266 (opus_int8 *)&silk_LTP_gain_vq_1[0][0],
267 (opus_int8 *)&silk_LTP_gain_vq_2[0][0]
268};
269
270const opus_int8 silk_LTP_vq_sizes[NB_LTP_CBKS] = {
271 8, 16, 32
272};
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_NB_MB.c b/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_NB_MB.c
new file mode 100644
index 0000000000..201a89d110
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_NB_MB.c
@@ -0,0 +1,159 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34static const opus_uint8 silk_NLSF_CB1_NB_MB_Q8[ 320 ] = {
35 12, 35, 60, 83, 108, 132, 157, 180,
36 206, 228, 15, 32, 55, 77, 101, 125,
37 151, 175, 201, 225, 19, 42, 66, 89,
38 114, 137, 162, 184, 209, 230, 12, 25,
39 50, 72, 97, 120, 147, 172, 200, 223,
40 26, 44, 69, 90, 114, 135, 159, 180,
41 205, 225, 13, 22, 53, 80, 106, 130,
42 156, 180, 205, 228, 15, 25, 44, 64,
43 90, 115, 142, 168, 196, 222, 19, 24,
44 62, 82, 100, 120, 145, 168, 190, 214,
45 22, 31, 50, 79, 103, 120, 151, 170,
46 203, 227, 21, 29, 45, 65, 106, 124,
47 150, 171, 196, 224, 30, 49, 75, 97,
48 121, 142, 165, 186, 209, 229, 19, 25,
49 52, 70, 93, 116, 143, 166, 192, 219,
50 26, 34, 62, 75, 97, 118, 145, 167,
51 194, 217, 25, 33, 56, 70, 91, 113,
52 143, 165, 196, 223, 21, 34, 51, 72,
53 97, 117, 145, 171, 196, 222, 20, 29,
54 50, 67, 90, 117, 144, 168, 197, 221,
55 22, 31, 48, 66, 95, 117, 146, 168,
56 196, 222, 24, 33, 51, 77, 116, 134,
57 158, 180, 200, 224, 21, 28, 70, 87,
58 106, 124, 149, 170, 194, 217, 26, 33,
59 53, 64, 83, 117, 152, 173, 204, 225,
60 27, 34, 65, 95, 108, 129, 155, 174,
61 210, 225, 20, 26, 72, 99, 113, 131,
62 154, 176, 200, 219, 34, 43, 61, 78,
63 93, 114, 155, 177, 205, 229, 23, 29,
64 54, 97, 124, 138, 163, 179, 209, 229,
65 30, 38, 56, 89, 118, 129, 158, 178,
66 200, 231, 21, 29, 49, 63, 85, 111,
67 142, 163, 193, 222, 27, 48, 77, 103,
68 133, 158, 179, 196, 215, 232, 29, 47,
69 74, 99, 124, 151, 176, 198, 220, 237,
70 33, 42, 61, 76, 93, 121, 155, 174,
71 207, 225, 29, 53, 87, 112, 136, 154,
72 170, 188, 208, 227, 24, 30, 52, 84,
73 131, 150, 166, 186, 203, 229, 37, 48,
74 64, 84, 104, 118, 156, 177, 201, 230
75};
76
77static const opus_uint8 silk_NLSF_CB1_iCDF_NB_MB[ 64 ] = {
78 212, 178, 148, 129, 108, 96, 85, 82,
79 79, 77, 61, 59, 57, 56, 51, 49,
80 48, 45, 42, 41, 40, 38, 36, 34,
81 31, 30, 21, 12, 10, 3, 1, 0,
82 255, 245, 244, 236, 233, 225, 217, 203,
83 190, 176, 175, 161, 149, 136, 125, 114,
84 102, 91, 81, 71, 60, 52, 43, 35,
85 28, 20, 19, 18, 12, 11, 5, 0
86};
87
88static const opus_uint8 silk_NLSF_CB2_SELECT_NB_MB[ 160 ] = {
89 16, 0, 0, 0, 0, 99, 66, 36,
90 36, 34, 36, 34, 34, 34, 34, 83,
91 69, 36, 52, 34, 116, 102, 70, 68,
92 68, 176, 102, 68, 68, 34, 65, 85,
93 68, 84, 36, 116, 141, 152, 139, 170,
94 132, 187, 184, 216, 137, 132, 249, 168,
95 185, 139, 104, 102, 100, 68, 68, 178,
96 218, 185, 185, 170, 244, 216, 187, 187,
97 170, 244, 187, 187, 219, 138, 103, 155,
98 184, 185, 137, 116, 183, 155, 152, 136,
99 132, 217, 184, 184, 170, 164, 217, 171,
100 155, 139, 244, 169, 184, 185, 170, 164,
101 216, 223, 218, 138, 214, 143, 188, 218,
102 168, 244, 141, 136, 155, 170, 168, 138,
103 220, 219, 139, 164, 219, 202, 216, 137,
104 168, 186, 246, 185, 139, 116, 185, 219,
105 185, 138, 100, 100, 134, 100, 102, 34,
106 68, 68, 100, 68, 168, 203, 221, 218,
107 168, 167, 154, 136, 104, 70, 164, 246,
108 171, 137, 139, 137, 155, 218, 219, 139
109};
110
111static const opus_uint8 silk_NLSF_CB2_iCDF_NB_MB[ 72 ] = {
112 255, 254, 253, 238, 14, 3, 2, 1,
113 0, 255, 254, 252, 218, 35, 3, 2,
114 1, 0, 255, 254, 250, 208, 59, 4,
115 2, 1, 0, 255, 254, 246, 194, 71,
116 10, 2, 1, 0, 255, 252, 236, 183,
117 82, 8, 2, 1, 0, 255, 252, 235,
118 180, 90, 17, 2, 1, 0, 255, 248,
119 224, 171, 97, 30, 4, 1, 0, 255,
120 254, 236, 173, 95, 37, 7, 1, 0
121};
122
123static const opus_uint8 silk_NLSF_CB2_BITS_NB_MB_Q5[ 72 ] = {
124 255, 255, 255, 131, 6, 145, 255, 255,
125 255, 255, 255, 236, 93, 15, 96, 255,
126 255, 255, 255, 255, 194, 83, 25, 71,
127 221, 255, 255, 255, 255, 162, 73, 34,
128 66, 162, 255, 255, 255, 210, 126, 73,
129 43, 57, 173, 255, 255, 255, 201, 125,
130 71, 48, 58, 130, 255, 255, 255, 166,
131 110, 73, 57, 62, 104, 210, 255, 255,
132 251, 123, 65, 55, 68, 100, 171, 255
133};
134
135static const opus_uint8 silk_NLSF_PRED_NB_MB_Q8[ 18 ] = {
136 179, 138, 140, 148, 151, 149, 153, 151,
137 163, 116, 67, 82, 59, 92, 72, 100,
138 89, 92
139};
140
141static const opus_int16 silk_NLSF_DELTA_MIN_NB_MB_Q15[ 11 ] = {
142 250, 3, 6, 3, 3, 3, 4, 3,
143 3, 3, 461
144};
145
146const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB =
147{
148 32,
149 10,
150 SILK_FIX_CONST( 0.18, 16 ),
151 SILK_FIX_CONST( 1.0 / 0.18, 6 ),
152 silk_NLSF_CB1_NB_MB_Q8,
153 silk_NLSF_CB1_iCDF_NB_MB,
154 silk_NLSF_PRED_NB_MB_Q8,
155 silk_NLSF_CB2_SELECT_NB_MB,
156 silk_NLSF_CB2_iCDF_NB_MB,
157 silk_NLSF_CB2_BITS_NB_MB_Q5,
158 silk_NLSF_DELTA_MIN_NB_MB_Q15,
159};
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_WB.c b/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_WB.c
new file mode 100644
index 0000000000..0d9286f39d
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_NLSF_CB_WB.c
@@ -0,0 +1,198 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34static const opus_uint8 silk_NLSF_CB1_WB_Q8[ 512 ] = {
35 7, 23, 38, 54, 69, 85, 100, 116,
36 131, 147, 162, 178, 193, 208, 223, 239,
37 13, 25, 41, 55, 69, 83, 98, 112,
38 127, 142, 157, 171, 187, 203, 220, 236,
39 15, 21, 34, 51, 61, 78, 92, 106,
40 126, 136, 152, 167, 185, 205, 225, 240,
41 10, 21, 36, 50, 63, 79, 95, 110,
42 126, 141, 157, 173, 189, 205, 221, 237,
43 17, 20, 37, 51, 59, 78, 89, 107,
44 123, 134, 150, 164, 184, 205, 224, 240,
45 10, 15, 32, 51, 67, 81, 96, 112,
46 129, 142, 158, 173, 189, 204, 220, 236,
47 8, 21, 37, 51, 65, 79, 98, 113,
48 126, 138, 155, 168, 179, 192, 209, 218,
49 12, 15, 34, 55, 63, 78, 87, 108,
50 118, 131, 148, 167, 185, 203, 219, 236,
51 16, 19, 32, 36, 56, 79, 91, 108,
52 118, 136, 154, 171, 186, 204, 220, 237,
53 11, 28, 43, 58, 74, 89, 105, 120,
54 135, 150, 165, 180, 196, 211, 226, 241,
55 6, 16, 33, 46, 60, 75, 92, 107,
56 123, 137, 156, 169, 185, 199, 214, 225,
57 11, 19, 30, 44, 57, 74, 89, 105,
58 121, 135, 152, 169, 186, 202, 218, 234,
59 12, 19, 29, 46, 57, 71, 88, 100,
60 120, 132, 148, 165, 182, 199, 216, 233,
61 17, 23, 35, 46, 56, 77, 92, 106,
62 123, 134, 152, 167, 185, 204, 222, 237,
63 14, 17, 45, 53, 63, 75, 89, 107,
64 115, 132, 151, 171, 188, 206, 221, 240,
65 9, 16, 29, 40, 56, 71, 88, 103,
66 119, 137, 154, 171, 189, 205, 222, 237,
67 16, 19, 36, 48, 57, 76, 87, 105,
68 118, 132, 150, 167, 185, 202, 218, 236,
69 12, 17, 29, 54, 71, 81, 94, 104,
70 126, 136, 149, 164, 182, 201, 221, 237,
71 15, 28, 47, 62, 79, 97, 115, 129,
72 142, 155, 168, 180, 194, 208, 223, 238,
73 8, 14, 30, 45, 62, 78, 94, 111,
74 127, 143, 159, 175, 192, 207, 223, 239,
75 17, 30, 49, 62, 79, 92, 107, 119,
76 132, 145, 160, 174, 190, 204, 220, 235,
77 14, 19, 36, 45, 61, 76, 91, 108,
78 121, 138, 154, 172, 189, 205, 222, 238,
79 12, 18, 31, 45, 60, 76, 91, 107,
80 123, 138, 154, 171, 187, 204, 221, 236,
81 13, 17, 31, 43, 53, 70, 83, 103,
82 114, 131, 149, 167, 185, 203, 220, 237,
83 17, 22, 35, 42, 58, 78, 93, 110,
84 125, 139, 155, 170, 188, 206, 224, 240,
85 8, 15, 34, 50, 67, 83, 99, 115,
86 131, 146, 162, 178, 193, 209, 224, 239,
87 13, 16, 41, 66, 73, 86, 95, 111,
88 128, 137, 150, 163, 183, 206, 225, 241,
89 17, 25, 37, 52, 63, 75, 92, 102,
90 119, 132, 144, 160, 175, 191, 212, 231,
91 19, 31, 49, 65, 83, 100, 117, 133,
92 147, 161, 174, 187, 200, 213, 227, 242,
93 18, 31, 52, 68, 88, 103, 117, 126,
94 138, 149, 163, 177, 192, 207, 223, 239,
95 16, 29, 47, 61, 76, 90, 106, 119,
96 133, 147, 161, 176, 193, 209, 224, 240,
97 15, 21, 35, 50, 61, 73, 86, 97,
98 110, 119, 129, 141, 175, 198, 218, 237
99};
100
101static const opus_uint8 silk_NLSF_CB1_iCDF_WB[ 64 ] = {
102 225, 204, 201, 184, 183, 175, 158, 154,
103 153, 135, 119, 115, 113, 110, 109, 99,
104 98, 95, 79, 68, 52, 50, 48, 45,
105 43, 32, 31, 27, 18, 10, 3, 0,
106 255, 251, 235, 230, 212, 201, 196, 182,
107 167, 166, 163, 151, 138, 124, 110, 104,
108 90, 78, 76, 70, 69, 57, 45, 34,
109 24, 21, 11, 6, 5, 4, 3, 0
110};
111
112static const opus_uint8 silk_NLSF_CB2_SELECT_WB[ 256 ] = {
113 0, 0, 0, 0, 0, 0, 0, 1,
114 100, 102, 102, 68, 68, 36, 34, 96,
115 164, 107, 158, 185, 180, 185, 139, 102,
116 64, 66, 36, 34, 34, 0, 1, 32,
117 208, 139, 141, 191, 152, 185, 155, 104,
118 96, 171, 104, 166, 102, 102, 102, 132,
119 1, 0, 0, 0, 0, 16, 16, 0,
120 80, 109, 78, 107, 185, 139, 103, 101,
121 208, 212, 141, 139, 173, 153, 123, 103,
122 36, 0, 0, 0, 0, 0, 0, 1,
123 48, 0, 0, 0, 0, 0, 0, 32,
124 68, 135, 123, 119, 119, 103, 69, 98,
125 68, 103, 120, 118, 118, 102, 71, 98,
126 134, 136, 157, 184, 182, 153, 139, 134,
127 208, 168, 248, 75, 189, 143, 121, 107,
128 32, 49, 34, 34, 34, 0, 17, 2,
129 210, 235, 139, 123, 185, 137, 105, 134,
130 98, 135, 104, 182, 100, 183, 171, 134,
131 100, 70, 68, 70, 66, 66, 34, 131,
132 64, 166, 102, 68, 36, 2, 1, 0,
133 134, 166, 102, 68, 34, 34, 66, 132,
134 212, 246, 158, 139, 107, 107, 87, 102,
135 100, 219, 125, 122, 137, 118, 103, 132,
136 114, 135, 137, 105, 171, 106, 50, 34,
137 164, 214, 141, 143, 185, 151, 121, 103,
138 192, 34, 0, 0, 0, 0, 0, 1,
139 208, 109, 74, 187, 134, 249, 159, 137,
140 102, 110, 154, 118, 87, 101, 119, 101,
141 0, 2, 0, 36, 36, 66, 68, 35,
142 96, 164, 102, 100, 36, 0, 2, 33,
143 167, 138, 174, 102, 100, 84, 2, 2,
144 100, 107, 120, 119, 36, 197, 24, 0
145};
146
147static const opus_uint8 silk_NLSF_CB2_iCDF_WB[ 72 ] = {
148 255, 254, 253, 244, 12, 3, 2, 1,
149 0, 255, 254, 252, 224, 38, 3, 2,
150 1, 0, 255, 254, 251, 209, 57, 4,
151 2, 1, 0, 255, 254, 244, 195, 69,
152 4, 2, 1, 0, 255, 251, 232, 184,
153 84, 7, 2, 1, 0, 255, 254, 240,
154 186, 86, 14, 2, 1, 0, 255, 254,
155 239, 178, 91, 30, 5, 1, 0, 255,
156 248, 227, 177, 100, 19, 2, 1, 0
157};
158
159static const opus_uint8 silk_NLSF_CB2_BITS_WB_Q5[ 72 ] = {
160 255, 255, 255, 156, 4, 154, 255, 255,
161 255, 255, 255, 227, 102, 15, 92, 255,
162 255, 255, 255, 255, 213, 83, 24, 72,
163 236, 255, 255, 255, 255, 150, 76, 33,
164 63, 214, 255, 255, 255, 190, 121, 77,
165 43, 55, 185, 255, 255, 255, 245, 137,
166 71, 43, 59, 139, 255, 255, 255, 255,
167 131, 66, 50, 66, 107, 194, 255, 255,
168 166, 116, 76, 55, 53, 125, 255, 255
169};
170
171static const opus_uint8 silk_NLSF_PRED_WB_Q8[ 30 ] = {
172 175, 148, 160, 176, 178, 173, 174, 164,
173 177, 174, 196, 182, 198, 192, 182, 68,
174 62, 66, 60, 72, 117, 85, 90, 118,
175 136, 151, 142, 160, 142, 155
176};
177
178static const opus_int16 silk_NLSF_DELTA_MIN_WB_Q15[ 17 ] = {
179 100, 3, 40, 3, 3, 3, 5, 14,
180 14, 10, 11, 3, 8, 9, 7, 3,
181 347
182};
183
184const silk_NLSF_CB_struct silk_NLSF_CB_WB =
185{
186 32,
187 16,
188 SILK_FIX_CONST( 0.15, 16 ),
189 SILK_FIX_CONST( 1.0 / 0.15, 6 ),
190 silk_NLSF_CB1_WB_Q8,
191 silk_NLSF_CB1_iCDF_WB,
192 silk_NLSF_PRED_WB_Q8,
193 silk_NLSF_CB2_SELECT_WB,
194 silk_NLSF_CB2_iCDF_WB,
195 silk_NLSF_CB2_BITS_WB_Q5,
196 silk_NLSF_DELTA_MIN_WB_Q15,
197};
198
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_gain.c b/lib/rbcodec/codecs/libopus/silk/tables_gain.c
new file mode 100644
index 0000000000..fe6f912b10
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_gain.c
@@ -0,0 +1,63 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
39const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ] =
40{
41{
42 224, 112, 44, 15, 3, 2, 1, 0
43},
44{
45 254, 237, 192, 132, 70, 23, 4, 0
46},
47{
48 255, 252, 226, 155, 61, 11, 2, 0
49}
50};
51
52const opus_uint8 silk_delta_gain_iCDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ] = {
53 250, 245, 234, 203, 71, 50, 42, 38,
54 35, 33, 31, 29, 28, 27, 26, 25,
55 24, 23, 22, 21, 20, 19, 18, 17,
56 16, 15, 14, 13, 12, 11, 10, 9,
57 8, 7, 6, 5, 4, 3, 2, 1,
58 0
59};
60
61#ifdef __cplusplus
62}
63#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_other.c b/lib/rbcodec/codecs/libopus/silk/tables_other.c
new file mode 100644
index 0000000000..5119ebd39f
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_other.c
@@ -0,0 +1,138 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "structs.h"
33#include "define.h"
34#include "tables.h"
35
36#ifdef __cplusplus
37extern "C"
38{
39#endif
40
41/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
42const opus_int32 silk_TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = {
43 0, 8000, 9400, 11500, 13500, 17500, 25000, MAX_TARGET_RATE_BPS
44};
45const opus_int32 silk_TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = {
46 0, 9000, 12000, 14500, 18500, 24500, 35500, MAX_TARGET_RATE_BPS
47};
48const opus_int32 silk_TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = {
49 0, 10500, 14000, 17000, 21500, 28500, 42000, MAX_TARGET_RATE_BPS
50};
51const opus_int16 silk_SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = {
52 18, 29, 38, 40, 46, 52, 62, 84
53};
54
55/* Tables for stereo predictor coding */
56const opus_int16 silk_stereo_pred_quant_Q13[ STEREO_QUANT_TAB_SIZE ] = {
57 -13732, -10050, -8266, -7526, -6500, -5000, -2950, -820,
58 820, 2950, 5000, 6500, 7526, 8266, 10050, 13732
59};
60const opus_uint8 silk_stereo_pred_joint_iCDF[ 25 ] = {
61 249, 247, 246, 245, 244,
62 234, 210, 202, 201, 200,
63 197, 174, 82, 59, 56,
64 55, 54, 46, 22, 12,
65 11, 10, 9, 7, 0
66};
67const opus_uint8 silk_stereo_only_code_mid_iCDF[ 2 ] = { 64, 0 };
68
69/* Tables for LBRR flags */
70static const opus_uint8 silk_LBRR_flags_2_iCDF[ 3 ] = { 203, 150, 0 };
71static const opus_uint8 silk_LBRR_flags_3_iCDF[ 7 ] = { 215, 195, 166, 125, 110, 82, 0 };
72const opus_uint8 * const silk_LBRR_flags_iCDF_ptr[ 2 ] = {
73 silk_LBRR_flags_2_iCDF,
74 silk_LBRR_flags_3_iCDF
75};
76
77/* Table for LSB coding */
78const opus_uint8 silk_lsb_iCDF[ 2 ] = { 120, 0 };
79
80/* Tables for LTPScale */
81const opus_uint8 silk_LTPscale_iCDF[ 3 ] = { 128, 64, 0 };
82
83/* Tables for signal type and offset coding */
84const opus_uint8 silk_type_offset_VAD_iCDF[ 4 ] = {
85 232, 158, 10, 0
86};
87const opus_uint8 silk_type_offset_no_VAD_iCDF[ 2 ] = {
88 230, 0
89};
90
91/* Tables for NLSF interpolation factor */
92const opus_uint8 silk_NLSF_interpolation_factor_iCDF[ 5 ] = { 243, 221, 192, 181, 0 };
93
94/* Quantization offsets */
95const opus_int16 silk_Quantization_Offsets_Q10[ 2 ][ 2 ] = {
96 { OFFSET_UVL_Q10, OFFSET_UVH_Q10 }, { OFFSET_VL_Q10, OFFSET_VH_Q10 }
97};
98
99/* Table for LTPScale */
100const opus_int16 silk_LTPScales_table_Q14[ 3 ] = { 15565, 12288, 8192 };
101
102/* Uniform entropy tables */
103const opus_uint8 silk_uniform3_iCDF[ 3 ] = { 171, 85, 0 };
104const opus_uint8 silk_uniform4_iCDF[ 4 ] = { 192, 128, 64, 0 };
105const opus_uint8 silk_uniform5_iCDF[ 5 ] = { 205, 154, 102, 51, 0 };
106const opus_uint8 silk_uniform6_iCDF[ 6 ] = { 213, 171, 128, 85, 43, 0 };
107const opus_uint8 silk_uniform8_iCDF[ 8 ] = { 224, 192, 160, 128, 96, 64, 32, 0 };
108
109const opus_uint8 silk_NLSF_EXT_iCDF[ 7 ] = { 100, 40, 16, 7, 3, 1, 0 };
110
111/* Elliptic/Cauer filters designed with 0.1 dB passband ripple,
112 80 dB minimum stopband attenuation, and
113 [0.95 : 0.15 : 0.35] normalized cut off frequencies. */
114
115/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
116const opus_int32 silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ] =
117{
118{ 250767114, 501534038, 250767114 },
119{ 209867381, 419732057, 209867381 },
120{ 170987846, 341967853, 170987846 },
121{ 131531482, 263046905, 131531482 },
122{ 89306658, 178584282, 89306658 }
123};
124
125/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
126const opus_int32 silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ] =
127{
128{ 506393414, 239854379 },
129{ 411067935, 169683996 },
130{ 306733530, 116694253 },
131{ 185807084, 77959395 },
132{ 35497197, 57401098 }
133};
134
135#ifdef __cplusplus
136}
137#endif
138
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_pitch_lag.c b/lib/rbcodec/codecs/libopus/silk/tables_pitch_lag.c
new file mode 100644
index 0000000000..e795a23cd0
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_pitch_lag.c
@@ -0,0 +1,69 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34const opus_uint8 silk_pitch_lag_iCDF[ 2 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) ] = {
35 253, 250, 244, 233, 212, 182, 150, 131,
36 120, 110, 98, 85, 72, 60, 49, 40,
37 32, 25, 19, 15, 13, 11, 9, 8,
38 7, 6, 5, 4, 3, 2, 1, 0
39};
40
41const opus_uint8 silk_pitch_delta_iCDF[21] = {
42 210, 208, 206, 203, 199, 193, 183, 168,
43 142, 104, 74, 52, 37, 27, 20, 14,
44 10, 6, 4, 2, 0
45};
46
47const opus_uint8 silk_pitch_contour_iCDF[34] = {
48 223, 201, 183, 167, 152, 138, 124, 111,
49 98, 88, 79, 70, 62, 56, 50, 44,
50 39, 35, 31, 27, 24, 21, 18, 16,
51 14, 12, 10, 8, 6, 4, 3, 2,
52 1, 0
53};
54
55const opus_uint8 silk_pitch_contour_NB_iCDF[11] = {
56 188, 176, 155, 138, 119, 97, 67, 43,
57 26, 10, 0
58};
59
60const opus_uint8 silk_pitch_contour_10_ms_iCDF[12] = {
61 165, 119, 80, 61, 47, 35, 27, 20,
62 14, 9, 4, 0
63};
64
65const opus_uint8 silk_pitch_contour_10_ms_NB_iCDF[3] = {
66 113, 63, 0
67};
68
69
diff --git a/lib/rbcodec/codecs/libopus/silk/tables_pulses_per_block.c b/lib/rbcodec/codecs/libopus/silk/tables_pulses_per_block.c
new file mode 100644
index 0000000000..0c9b18be6c
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/tables_pulses_per_block.c
@@ -0,0 +1,264 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "opus_config.h"
30#endif
31
32#include "tables.h"
33
34const opus_uint8 silk_max_pulses_table[ 4 ] = {
35 8, 10, 12, 16
36};
37
38const opus_uint8 silk_pulses_per_block_iCDF[ 10 ][ 18 ] = {
39{
40 125, 51, 26, 18, 15, 12, 11, 10,
41 9, 8, 7, 6, 5, 4, 3, 2,
42 1, 0
43},
44{
45 198, 105, 45, 22, 15, 12, 11, 10,
46 9, 8, 7, 6, 5, 4, 3, 2,
47 1, 0
48},
49{
50 213, 162, 116, 83, 59, 43, 32, 24,
51 18, 15, 12, 9, 7, 6, 5, 3,
52 2, 0
53},
54{
55 239, 187, 116, 59, 28, 16, 11, 10,
56 9, 8, 7, 6, 5, 4, 3, 2,
57 1, 0
58},
59{
60 250, 229, 188, 135, 86, 51, 30, 19,
61 13, 10, 8, 6, 5, 4, 3, 2,
62 1, 0
63},
64{
65 249, 235, 213, 185, 156, 128, 103, 83,
66 66, 53, 42, 33, 26, 21, 17, 13,
67 10, 0
68},
69{
70 254, 249, 235, 206, 164, 118, 77, 46,
71 27, 16, 10, 7, 5, 4, 3, 2,
72 1, 0
73},
74{
75 255, 253, 249, 239, 220, 191, 156, 119,
76 85, 57, 37, 23, 15, 10, 6, 4,
77 2, 0
78},
79{
80 255, 253, 251, 246, 237, 223, 203, 179,
81 152, 124, 98, 75, 55, 40, 29, 21,
82 15, 0
83},
84{
85 255, 254, 253, 247, 220, 162, 106, 67,
86 42, 28, 18, 12, 9, 6, 4, 3,
87 2, 0
88}
89};
90
91const opus_uint8 silk_pulses_per_block_BITS_Q5[ 9 ][ 18 ] = {
92{
93 31, 57, 107, 160, 205, 205, 255, 255,
94 255, 255, 255, 255, 255, 255, 255, 255,
95 255, 255
96},
97{
98 69, 47, 67, 111, 166, 205, 255, 255,
99 255, 255, 255, 255, 255, 255, 255, 255,
100 255, 255
101},
102{
103 82, 74, 79, 95, 109, 128, 145, 160,
104 173, 205, 205, 205, 224, 255, 255, 224,
105 255, 224
106},
107{
108 125, 74, 59, 69, 97, 141, 182, 255,
109 255, 255, 255, 255, 255, 255, 255, 255,
110 255, 255
111},
112{
113 173, 115, 85, 73, 76, 92, 115, 145,
114 173, 205, 224, 224, 255, 255, 255, 255,
115 255, 255
116},
117{
118 166, 134, 113, 102, 101, 102, 107, 118,
119 125, 138, 145, 155, 166, 182, 192, 192,
120 205, 150
121},
122{
123 224, 182, 134, 101, 83, 79, 85, 97,
124 120, 145, 173, 205, 224, 255, 255, 255,
125 255, 255
126},
127{
128 255, 224, 192, 150, 120, 101, 92, 89,
129 93, 102, 118, 134, 160, 182, 192, 224,
130 224, 224
131},
132{
133 255, 224, 224, 182, 155, 134, 118, 109,
134 104, 102, 106, 111, 118, 131, 145, 160,
135 173, 131
136}
137};
138
139const opus_uint8 silk_rate_levels_iCDF[ 2 ][ 9 ] =
140{
141{
142 241, 190, 178, 132, 87, 74, 41, 14,
143 0
144},
145{
146 223, 193, 157, 140, 106, 57, 39, 18,
147 0
148}
149};
150
151const opus_uint8 silk_rate_levels_BITS_Q5[ 2 ][ 9 ] =
152{
153{
154 131, 74, 141, 79, 80, 138, 95, 104,
155 134
156},
157{
158 95, 99, 91, 125, 93, 76, 123, 115,
159 123
160}
161};
162
163const opus_uint8 silk_shell_code_table0[ 152 ] = {
164 128, 0, 214, 42, 0, 235, 128, 21,
165 0, 244, 184, 72, 11, 0, 248, 214,
166 128, 42, 7, 0, 248, 225, 170, 80,
167 25, 5, 0, 251, 236, 198, 126, 54,
168 18, 3, 0, 250, 238, 211, 159, 82,
169 35, 15, 5, 0, 250, 231, 203, 168,
170 128, 88, 53, 25, 6, 0, 252, 238,
171 216, 185, 148, 108, 71, 40, 18, 4,
172 0, 253, 243, 225, 199, 166, 128, 90,
173 57, 31, 13, 3, 0, 254, 246, 233,
174 212, 183, 147, 109, 73, 44, 23, 10,
175 2, 0, 255, 250, 240, 223, 198, 166,
176 128, 90, 58, 33, 16, 6, 1, 0,
177 255, 251, 244, 231, 210, 181, 146, 110,
178 75, 46, 25, 12, 5, 1, 0, 255,
179 253, 248, 238, 221, 196, 164, 128, 92,
180 60, 35, 18, 8, 3, 1, 0, 255,
181 253, 249, 242, 229, 208, 180, 146, 110,
182 76, 48, 27, 14, 7, 3, 1, 0
183};
184
185const opus_uint8 silk_shell_code_table1[ 152 ] = {
186 129, 0, 207, 50, 0, 236, 129, 20,
187 0, 245, 185, 72, 10, 0, 249, 213,
188 129, 42, 6, 0, 250, 226, 169, 87,
189 27, 4, 0, 251, 233, 194, 130, 62,
190 20, 4, 0, 250, 236, 207, 160, 99,
191 47, 17, 3, 0, 255, 240, 217, 182,
192 131, 81, 41, 11, 1, 0, 255, 254,
193 233, 201, 159, 107, 61, 20, 2, 1,
194 0, 255, 249, 233, 206, 170, 128, 86,
195 50, 23, 7, 1, 0, 255, 250, 238,
196 217, 186, 148, 108, 70, 39, 18, 6,
197 1, 0, 255, 252, 243, 226, 200, 166,
198 128, 90, 56, 30, 13, 4, 1, 0,
199 255, 252, 245, 231, 209, 180, 146, 110,
200 76, 47, 25, 11, 4, 1, 0, 255,
201 253, 248, 237, 219, 194, 163, 128, 93,
202 62, 37, 19, 8, 3, 1, 0, 255,
203 254, 250, 241, 226, 205, 177, 145, 111,
204 79, 51, 30, 15, 6, 2, 1, 0
205};
206
207const opus_uint8 silk_shell_code_table2[ 152 ] = {
208 129, 0, 203, 54, 0, 234, 129, 23,
209 0, 245, 184, 73, 10, 0, 250, 215,
210 129, 41, 5, 0, 252, 232, 173, 86,
211 24, 3, 0, 253, 240, 200, 129, 56,
212 15, 2, 0, 253, 244, 217, 164, 94,
213 38, 10, 1, 0, 253, 245, 226, 189,
214 132, 71, 27, 7, 1, 0, 253, 246,
215 231, 203, 159, 105, 56, 23, 6, 1,
216 0, 255, 248, 235, 213, 179, 133, 85,
217 47, 19, 5, 1, 0, 255, 254, 243,
218 221, 194, 159, 117, 70, 37, 12, 2,
219 1, 0, 255, 254, 248, 234, 208, 171,
220 128, 85, 48, 22, 8, 2, 1, 0,
221 255, 254, 250, 240, 220, 189, 149, 107,
222 67, 36, 16, 6, 2, 1, 0, 255,
223 254, 251, 243, 227, 201, 166, 128, 90,
224 55, 29, 13, 5, 2, 1, 0, 255,
225 254, 252, 246, 234, 213, 183, 147, 109,
226 73, 43, 22, 10, 4, 2, 1, 0
227};
228
229const opus_uint8 silk_shell_code_table3[ 152 ] = {
230 130, 0, 200, 58, 0, 231, 130, 26,
231 0, 244, 184, 76, 12, 0, 249, 214,
232 130, 43, 6, 0, 252, 232, 173, 87,
233 24, 3, 0, 253, 241, 203, 131, 56,
234 14, 2, 0, 254, 246, 221, 167, 94,
235 35, 8, 1, 0, 254, 249, 232, 193,
236 130, 65, 23, 5, 1, 0, 255, 251,
237 239, 211, 162, 99, 45, 15, 4, 1,
238 0, 255, 251, 243, 223, 186, 131, 74,
239 33, 11, 3, 1, 0, 255, 252, 245,
240 230, 202, 158, 105, 57, 24, 8, 2,
241 1, 0, 255, 253, 247, 235, 214, 179,
242 132, 84, 44, 19, 7, 2, 1, 0,
243 255, 254, 250, 240, 223, 196, 159, 112,
244 69, 36, 15, 6, 2, 1, 0, 255,
245 254, 253, 245, 231, 209, 176, 136, 93,
246 55, 27, 11, 3, 2, 1, 0, 255,
247 254, 253, 252, 239, 221, 194, 158, 117,
248 76, 42, 18, 4, 3, 2, 1, 0
249};
250
251const opus_uint8 silk_shell_code_table_offsets[ 17 ] = {
252 0, 0, 2, 5, 9, 14, 20, 27,
253 35, 44, 54, 65, 77, 90, 104, 119,
254 135
255};
256
257const opus_uint8 silk_sign_iCDF[ 42 ] = {
258 254, 49, 67, 77, 82, 93, 99,
259 198, 11, 18, 24, 31, 36, 45,
260 255, 46, 66, 78, 87, 94, 104,
261 208, 14, 21, 32, 42, 51, 66,
262 255, 94, 104, 109, 112, 115, 118,
263 248, 53, 69, 80, 88, 95, 102
264};
diff --git a/lib/rbcodec/codecs/libopus/silk/typedef.h b/lib/rbcodec/codecs/libopus/silk/typedef.h
new file mode 100644
index 0000000000..da98123701
--- /dev/null
+++ b/lib/rbcodec/codecs/libopus/silk/typedef.h
@@ -0,0 +1,77 @@
1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_TYPEDEF_H
29#define SILK_TYPEDEF_H
30
31#include "opus_types.h"
32
33#ifndef FIXED_POINT
34# include <float.h>
35# define silk_float float
36# define silk_float_MAX FLT_MAX
37#endif
38
39#define silk_int64_MAX ((opus_int64)0x7FFFFFFFFFFFFFFFLL) /* 2^63 - 1 */
40#define silk_int64_MIN ((opus_int64)0x8000000000000000LL) /* -2^63 */
41#define silk_int32_MAX 0x7FFFFFFF /* 2^31 - 1 = 2147483647 */
42#define silk_int32_MIN ((opus_int32)0x80000000) /* -2^31 = -2147483648 */
43#define silk_int16_MAX 0x7FFF /* 2^15 - 1 = 32767 */
44#define silk_int16_MIN ((opus_int16)0x8000) /* -2^15 = -32768 */
45#define silk_int8_MAX 0x7F /* 2^7 - 1 = 127 */
46#define silk_int8_MIN ((opus_int8)0x80) /* -2^7 = -128 */
47#define silk_uint8_MAX 0xFF /* 2^8 - 1 = 255 */
48
49#define silk_TRUE 1
50#define silk_FALSE 0
51
52/* assertions */
53#if (defined _WIN32 && !defined _WINCE && !defined(__GNUC__) && !defined(NO_ASSERTS))
54# ifndef silk_assert
55# include <crtdbg.h> /* ASSERTE() */
56# define silk_assert(COND) _ASSERTE(COND)
57# endif
58#else
59# ifdef ENABLE_ASSERTIONS
60# include <stdio.h>
61# include <stdlib.h>
62#define silk_fatal(str) _silk_fatal(str, __FILE__, __LINE__);
63#ifdef __GNUC__
64__attribute__((noreturn))
65#endif
66static inline void _silk_fatal(const char *str, const char *file, int line)
67{
68 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
69 abort();
70}
71# define silk_assert(COND) {if (!(COND)) {silk_fatal("assertion failed: " #COND);}}
72# else
73# define silk_assert(COND)
74# endif
75#endif
76
77#endif /* SILK_TYPEDEF_H */