1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/SigProc_FIX.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,594 @@ 1.4 +/*********************************************************************** 1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved. 1.6 +Redistribution and use in source and binary forms, with or without 1.7 +modification, are permitted provided that the following conditions 1.8 +are met: 1.9 +- Redistributions of source code must retain the above copyright notice, 1.10 +this list of conditions and the following disclaimer. 1.11 +- Redistributions in binary form must reproduce the above copyright 1.12 +notice, this list of conditions and the following disclaimer in the 1.13 +documentation and/or other materials provided with the distribution. 1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the 1.15 +names of specific contributors, may be used to endorse or promote 1.16 +products derived from this software without specific prior written 1.17 +permission. 1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.28 +POSSIBILITY OF SUCH DAMAGE. 1.29 +***********************************************************************/ 1.30 + 1.31 +#ifndef SILK_SIGPROC_FIX_H 1.32 +#define SILK_SIGPROC_FIX_H 1.33 + 1.34 +#ifdef __cplusplus 1.35 +extern "C" 1.36 +{ 1.37 +#endif 1.38 + 1.39 +/*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */ 1.40 + 1.41 +#define SILK_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */ 1.42 + 1.43 +#include <string.h> /* for memset(), memcpy(), memmove() */ 1.44 +#include "typedef.h" 1.45 +#include "resampler_structs.h" 1.46 +#include "macros.h" 1.47 + 1.48 + 1.49 +/********************************************************************/ 1.50 +/* SIGNAL PROCESSING FUNCTIONS */ 1.51 +/********************************************************************/ 1.52 + 1.53 +/*! 1.54 + * Initialize/reset the resampler state for a given pair of input/output sampling rates 1.55 +*/ 1.56 +opus_int silk_resampler_init( 1.57 + silk_resampler_state_struct *S, /* I/O Resampler state */ 1.58 + opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */ 1.59 + opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */ 1.60 + opus_int forEnc /* I If 1: encoder; if 0: decoder */ 1.61 +); 1.62 + 1.63 +/*! 1.64 + * Resampler: convert from one sampling rate to another 1.65 + */ 1.66 +opus_int silk_resampler( 1.67 + silk_resampler_state_struct *S, /* I/O Resampler state */ 1.68 + opus_int16 out[], /* O Output signal */ 1.69 + const opus_int16 in[], /* I Input signal */ 1.70 + opus_int32 inLen /* I Number of input samples */ 1.71 +); 1.72 + 1.73 +/*! 1.74 +* Downsample 2x, mediocre quality 1.75 +*/ 1.76 +void silk_resampler_down2( 1.77 + opus_int32 *S, /* I/O State vector [ 2 ] */ 1.78 + opus_int16 *out, /* O Output signal [ len ] */ 1.79 + const opus_int16 *in, /* I Input signal [ floor(len/2) ] */ 1.80 + opus_int32 inLen /* I Number of input samples */ 1.81 +); 1.82 + 1.83 +/*! 1.84 + * Downsample by a factor 2/3, low quality 1.85 +*/ 1.86 +void silk_resampler_down2_3( 1.87 + opus_int32 *S, /* I/O State vector [ 6 ] */ 1.88 + opus_int16 *out, /* O Output signal [ floor(2*inLen/3) ] */ 1.89 + const opus_int16 *in, /* I Input signal [ inLen ] */ 1.90 + opus_int32 inLen /* I Number of input samples */ 1.91 +); 1.92 + 1.93 +/*! 1.94 + * second order ARMA filter; 1.95 + * slower than biquad() but uses more precise coefficients 1.96 + * can handle (slowly) varying coefficients 1.97 + */ 1.98 +void silk_biquad_alt( 1.99 + const opus_int16 *in, /* I input signal */ 1.100 + const opus_int32 *B_Q28, /* I MA coefficients [3] */ 1.101 + const opus_int32 *A_Q28, /* I AR coefficients [2] */ 1.102 + opus_int32 *S, /* I/O State vector [2] */ 1.103 + opus_int16 *out, /* O output signal */ 1.104 + const opus_int32 len, /* I signal length (must be even) */ 1.105 + opus_int stride /* I Operate on interleaved signal if > 1 */ 1.106 +); 1.107 + 1.108 +/* Variable order MA prediction error filter. */ 1.109 +void silk_LPC_analysis_filter( 1.110 + opus_int16 *out, /* O Output signal */ 1.111 + const opus_int16 *in, /* I Input signal */ 1.112 + const opus_int16 *B, /* I MA prediction coefficients, Q12 [order] */ 1.113 + const opus_int32 len, /* I Signal length */ 1.114 + const opus_int32 d /* I Filter order */ 1.115 +); 1.116 + 1.117 +/* Chirp (bandwidth expand) LP AR filter */ 1.118 +void silk_bwexpander( 1.119 + opus_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */ 1.120 + const opus_int d, /* I Length of ar */ 1.121 + opus_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */ 1.122 +); 1.123 + 1.124 +/* Chirp (bandwidth expand) LP AR filter */ 1.125 +void silk_bwexpander_32( 1.126 + opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */ 1.127 + const opus_int d, /* I Length of ar */ 1.128 + opus_int32 chirp_Q16 /* I Chirp factor in Q16 */ 1.129 +); 1.130 + 1.131 +/* Compute inverse of LPC prediction gain, and */ 1.132 +/* test if LPC coefficients are stable (all poles within unit circle) */ 1.133 +opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse prediction gain in energy domain, Q30 */ 1.134 + const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ 1.135 + const opus_int order /* I Prediction order */ 1.136 +); 1.137 + 1.138 +/* For input in Q24 domain */ 1.139 +opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse prediction gain in energy domain, Q30 */ 1.140 + const opus_int32 *A_Q24, /* I Prediction coefficients [order] */ 1.141 + const opus_int order /* I Prediction order */ 1.142 +); 1.143 + 1.144 +/* Split signal in two decimated bands using first-order allpass filters */ 1.145 +void silk_ana_filt_bank_1( 1.146 + const opus_int16 *in, /* I Input signal [N] */ 1.147 + opus_int32 *S, /* I/O State vector [2] */ 1.148 + opus_int16 *outL, /* O Low band [N/2] */ 1.149 + opus_int16 *outH, /* O High band [N/2] */ 1.150 + const opus_int32 N /* I Number of input samples */ 1.151 +); 1.152 + 1.153 +/********************************************************************/ 1.154 +/* SCALAR FUNCTIONS */ 1.155 +/********************************************************************/ 1.156 + 1.157 +/* Approximation of 128 * log2() (exact inverse of approx 2^() below) */ 1.158 +/* Convert input to a log scale */ 1.159 +opus_int32 silk_lin2log( 1.160 + const opus_int32 inLin /* I input in linear scale */ 1.161 +); 1.162 + 1.163 +/* Approximation of a sigmoid function */ 1.164 +opus_int silk_sigm_Q15( 1.165 + opus_int in_Q5 /* I */ 1.166 +); 1.167 + 1.168 +/* Approximation of 2^() (exact inverse of approx log2() above) */ 1.169 +/* Convert input to a linear scale */ 1.170 +opus_int32 silk_log2lin( 1.171 + const opus_int32 inLog_Q7 /* I input on log scale */ 1.172 +); 1.173 + 1.174 +/* Compute number of bits to right shift the sum of squares of a vector */ 1.175 +/* of int16s to make it fit in an int32 */ 1.176 +void silk_sum_sqr_shift( 1.177 + opus_int32 *energy, /* O Energy of x, after shifting to the right */ 1.178 + opus_int *shift, /* O Number of bits right shift applied to energy */ 1.179 + const opus_int16 *x, /* I Input vector */ 1.180 + opus_int len /* I Length of input vector */ 1.181 +); 1.182 + 1.183 +/* Calculates the reflection coefficients from the correlation sequence */ 1.184 +/* Faster than schur64(), but much less accurate. */ 1.185 +/* uses SMLAWB(), requiring armv5E and higher. */ 1.186 +opus_int32 silk_schur( /* O Returns residual energy */ 1.187 + opus_int16 *rc_Q15, /* O reflection coefficients [order] Q15 */ 1.188 + const opus_int32 *c, /* I correlations [order+1] */ 1.189 + const opus_int32 order /* I prediction order */ 1.190 +); 1.191 + 1.192 +/* Calculates the reflection coefficients from the correlation sequence */ 1.193 +/* Slower than schur(), but more accurate. */ 1.194 +/* Uses SMULL(), available on armv4 */ 1.195 +opus_int32 silk_schur64( /* O returns residual energy */ 1.196 + opus_int32 rc_Q16[], /* O Reflection coefficients [order] Q16 */ 1.197 + const opus_int32 c[], /* I Correlations [order+1] */ 1.198 + opus_int32 order /* I Prediction order */ 1.199 +); 1.200 + 1.201 +/* Step up function, converts reflection coefficients to prediction coefficients */ 1.202 +void silk_k2a( 1.203 + opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */ 1.204 + const opus_int16 *rc_Q15, /* I Reflection coefficients [order] Q15 */ 1.205 + const opus_int32 order /* I Prediction order */ 1.206 +); 1.207 + 1.208 +/* Step up function, converts reflection coefficients to prediction coefficients */ 1.209 +void silk_k2a_Q16( 1.210 + opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */ 1.211 + const opus_int32 *rc_Q16, /* I Reflection coefficients [order] Q16 */ 1.212 + const opus_int32 order /* I Prediction order */ 1.213 +); 1.214 + 1.215 +/* Apply sine window to signal vector. */ 1.216 +/* Window types: */ 1.217 +/* 1 -> sine window from 0 to pi/2 */ 1.218 +/* 2 -> sine window from pi/2 to pi */ 1.219 +/* every other sample of window is linearly interpolated, for speed */ 1.220 +void silk_apply_sine_window( 1.221 + opus_int16 px_win[], /* O Pointer to windowed signal */ 1.222 + const opus_int16 px[], /* I Pointer to input signal */ 1.223 + const opus_int win_type, /* I Selects a window type */ 1.224 + const opus_int length /* I Window length, multiple of 4 */ 1.225 +); 1.226 + 1.227 +/* Compute autocorrelation */ 1.228 +void silk_autocorr( 1.229 + opus_int32 *results, /* O Result (length correlationCount) */ 1.230 + opus_int *scale, /* O Scaling of the correlation vector */ 1.231 + const opus_int16 *inputData, /* I Input data to correlate */ 1.232 + const opus_int inputDataSize, /* I Length of input */ 1.233 + const opus_int correlationCount, /* I Number of correlation taps to compute */ 1.234 + int arch /* I Run-time architecture */ 1.235 +); 1.236 + 1.237 +void silk_decode_pitch( 1.238 + opus_int16 lagIndex, /* I */ 1.239 + opus_int8 contourIndex, /* O */ 1.240 + opus_int pitch_lags[], /* O 4 pitch values */ 1.241 + const opus_int Fs_kHz, /* I sampling frequency (kHz) */ 1.242 + const opus_int nb_subfr /* I number of sub frames */ 1.243 +); 1.244 + 1.245 +opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ 1.246 + const opus_int16 *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ 1.247 + opus_int *pitch_out, /* O 4 pitch lag values */ 1.248 + opus_int16 *lagIndex, /* O Lag Index */ 1.249 + opus_int8 *contourIndex, /* O Pitch contour Index */ 1.250 + opus_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ 1.251 + opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ 1.252 + const opus_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ 1.253 + const opus_int search_thres2_Q13, /* I Final threshold for lag candidates 0 - 1 */ 1.254 + const opus_int Fs_kHz, /* I Sample frequency (kHz) */ 1.255 + const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ 1.256 + const opus_int nb_subfr, /* I number of 5 ms subframes */ 1.257 + int arch /* I Run-time architecture */ 1.258 +); 1.259 + 1.260 +/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */ 1.261 +/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */ 1.262 +void silk_A2NLSF( 1.263 + opus_int16 *NLSF, /* O Normalized Line Spectral Frequencies in Q15 (0..2^15-1) [d] */ 1.264 + opus_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */ 1.265 + const opus_int d /* I Filter order (must be even) */ 1.266 +); 1.267 + 1.268 +/* compute whitening filter coefficients from normalized line spectral frequencies */ 1.269 +void silk_NLSF2A( 1.270 + opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ 1.271 + const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ 1.272 + const opus_int d /* I filter order (should be even) */ 1.273 +); 1.274 + 1.275 +void silk_insertion_sort_increasing( 1.276 + opus_int32 *a, /* I/O Unsorted / Sorted vector */ 1.277 + opus_int *idx, /* O Index vector for the sorted elements */ 1.278 + const opus_int L, /* I Vector length */ 1.279 + const opus_int K /* I Number of correctly sorted positions */ 1.280 +); 1.281 + 1.282 +void silk_insertion_sort_decreasing_int16( 1.283 + opus_int16 *a, /* I/O Unsorted / Sorted vector */ 1.284 + opus_int *idx, /* O Index vector for the sorted elements */ 1.285 + const opus_int L, /* I Vector length */ 1.286 + const opus_int K /* I Number of correctly sorted positions */ 1.287 +); 1.288 + 1.289 +void silk_insertion_sort_increasing_all_values_int16( 1.290 + opus_int16 *a, /* I/O Unsorted / Sorted vector */ 1.291 + const opus_int L /* I Vector length */ 1.292 +); 1.293 + 1.294 +/* NLSF stabilizer, for a single input data vector */ 1.295 +void silk_NLSF_stabilize( 1.296 + opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */ 1.297 + const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */ 1.298 + const opus_int L /* I Number of NLSF parameters in the input vector */ 1.299 +); 1.300 + 1.301 +/* Laroia low complexity NLSF weights */ 1.302 +void silk_NLSF_VQ_weights_laroia( 1.303 + opus_int16 *pNLSFW_Q_OUT, /* O Pointer to input vector weights [D] */ 1.304 + const opus_int16 *pNLSF_Q15, /* I Pointer to input vector [D] */ 1.305 + const opus_int D /* I Input vector dimension (even) */ 1.306 +); 1.307 + 1.308 +/* Compute reflection coefficients from input signal */ 1.309 +void silk_burg_modified( 1.310 + opus_int32 *res_nrg, /* O Residual energy */ 1.311 + opus_int *res_nrg_Q, /* O Residual energy Q value */ 1.312 + opus_int32 A_Q16[], /* O Prediction coefficients (length order) */ 1.313 + const opus_int16 x[], /* I Input signal, length: nb_subfr * ( D + subfr_length ) */ 1.314 + const opus_int32 minInvGain_Q30, /* I Inverse of max prediction gain */ 1.315 + const opus_int subfr_length, /* I Input signal subframe length (incl. D preceding samples) */ 1.316 + const opus_int nb_subfr, /* I Number of subframes stacked in x */ 1.317 + const opus_int D, /* I Order */ 1.318 + int arch /* I Run-time architecture */ 1.319 +); 1.320 + 1.321 +/* Copy and multiply a vector by a constant */ 1.322 +void silk_scale_copy_vector16( 1.323 + opus_int16 *data_out, 1.324 + const opus_int16 *data_in, 1.325 + opus_int32 gain_Q16, /* I Gain in Q16 */ 1.326 + const opus_int dataSize /* I Length */ 1.327 +); 1.328 + 1.329 +/* Some for the LTP related function requires Q26 to work.*/ 1.330 +void silk_scale_vector32_Q26_lshift_18( 1.331 + opus_int32 *data1, /* I/O Q0/Q18 */ 1.332 + opus_int32 gain_Q26, /* I Q26 */ 1.333 + opus_int dataSize /* I length */ 1.334 +); 1.335 + 1.336 +/********************************************************************/ 1.337 +/* INLINE ARM MATH */ 1.338 +/********************************************************************/ 1.339 + 1.340 +/* return sum( inVec1[i] * inVec2[i] ) */ 1.341 +opus_int32 silk_inner_prod_aligned( 1.342 + const opus_int16 *const inVec1, /* I input vector 1 */ 1.343 + const opus_int16 *const inVec2, /* I input vector 2 */ 1.344 + const opus_int len /* I vector lengths */ 1.345 +); 1.346 + 1.347 +opus_int32 silk_inner_prod_aligned_scale( 1.348 + const opus_int16 *const inVec1, /* I input vector 1 */ 1.349 + const opus_int16 *const inVec2, /* I input vector 2 */ 1.350 + const opus_int scale, /* I number of bits to shift */ 1.351 + const opus_int len /* I vector lengths */ 1.352 +); 1.353 + 1.354 +opus_int64 silk_inner_prod16_aligned_64( 1.355 + const opus_int16 *inVec1, /* I input vector 1 */ 1.356 + const opus_int16 *inVec2, /* I input vector 2 */ 1.357 + const opus_int len /* I vector lengths */ 1.358 +); 1.359 + 1.360 +/********************************************************************/ 1.361 +/* MACROS */ 1.362 +/********************************************************************/ 1.363 + 1.364 +/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating 1.365 + left. Output is 32bit int. 1.366 + Note: contemporary compilers recognize the C expression below and 1.367 + compile it into a 'ror' instruction if available. No need for OPUS_INLINE ASM! */ 1.368 +static OPUS_INLINE opus_int32 silk_ROR32( opus_int32 a32, opus_int rot ) 1.369 +{ 1.370 + opus_uint32 x = (opus_uint32) a32; 1.371 + opus_uint32 r = (opus_uint32) rot; 1.372 + opus_uint32 m = (opus_uint32) -rot; 1.373 + if( rot == 0 ) { 1.374 + return a32; 1.375 + } else if( rot < 0 ) { 1.376 + return (opus_int32) ((x << m) | (x >> (32 - m))); 1.377 + } else { 1.378 + return (opus_int32) ((x << (32 - r)) | (x >> r)); 1.379 + } 1.380 +} 1.381 + 1.382 +/* Allocate opus_int16 aligned to 4-byte memory address */ 1.383 +#if EMBEDDED_ARM 1.384 +#define silk_DWORD_ALIGN __attribute__((aligned(4))) 1.385 +#else 1.386 +#define silk_DWORD_ALIGN 1.387 +#endif 1.388 + 1.389 +/* Useful Macros that can be adjusted to other platforms */ 1.390 +#define silk_memcpy(dest, src, size) memcpy((dest), (src), (size)) 1.391 +#define silk_memset(dest, src, size) memset((dest), (src), (size)) 1.392 +#define silk_memmove(dest, src, size) memmove((dest), (src), (size)) 1.393 + 1.394 +/* Fixed point macros */ 1.395 + 1.396 +/* (a32 * b32) output have to be 32bit int */ 1.397 +#define silk_MUL(a32, b32) ((a32) * (b32)) 1.398 + 1.399 +/* (a32 * b32) output have to be 32bit uint */ 1.400 +#define silk_MUL_uint(a32, b32) silk_MUL(a32, b32) 1.401 + 1.402 +/* a32 + (b32 * c32) output have to be 32bit int */ 1.403 +#define silk_MLA(a32, b32, c32) silk_ADD32((a32),((b32) * (c32))) 1.404 + 1.405 +/* a32 + (b32 * c32) output have to be 32bit uint */ 1.406 +#define silk_MLA_uint(a32, b32, c32) silk_MLA(a32, b32, c32) 1.407 + 1.408 +/* ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */ 1.409 +#define silk_SMULTT(a32, b32) (((a32) >> 16) * ((b32) >> 16)) 1.410 + 1.411 +/* a32 + ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */ 1.412 +#define silk_SMLATT(a32, b32, c32) silk_ADD32((a32),((b32) >> 16) * ((c32) >> 16)) 1.413 + 1.414 +#define silk_SMLALBB(a64, b16, c16) silk_ADD64((a64),(opus_int64)((opus_int32)(b16) * (opus_int32)(c16))) 1.415 + 1.416 +/* (a32 * b32) */ 1.417 +#define silk_SMULL(a32, b32) ((opus_int64)(a32) * /*(opus_int64)*/(b32)) 1.418 + 1.419 +/* Adds two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour 1.420 + (just standard two's complement implementation-specific behaviour) */ 1.421 +#define silk_ADD32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) + (opus_uint32)(b))) 1.422 +/* Subtractss two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour 1.423 + (just standard two's complement implementation-specific behaviour) */ 1.424 +#define silk_SUB32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) - (opus_uint32)(b))) 1.425 + 1.426 +/* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */ 1.427 +#define silk_MLA_ovflw(a32, b32, c32) silk_ADD32_ovflw((a32), (opus_uint32)(b32) * (opus_uint32)(c32)) 1.428 +#define silk_SMLABB_ovflw(a32, b32, c32) (silk_ADD32_ovflw((a32) , ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32)))) 1.429 + 1.430 +#define silk_DIV32_16(a32, b16) ((opus_int32)((a32) / (b16))) 1.431 +#define silk_DIV32(a32, b32) ((opus_int32)((a32) / (b32))) 1.432 + 1.433 +/* These macros enables checking for overflow in silk_API_Debug.h*/ 1.434 +#define silk_ADD16(a, b) ((a) + (b)) 1.435 +#define silk_ADD32(a, b) ((a) + (b)) 1.436 +#define silk_ADD64(a, b) ((a) + (b)) 1.437 + 1.438 +#define silk_SUB16(a, b) ((a) - (b)) 1.439 +#define silk_SUB32(a, b) ((a) - (b)) 1.440 +#define silk_SUB64(a, b) ((a) - (b)) 1.441 + 1.442 +#define silk_SAT8(a) ((a) > silk_int8_MAX ? silk_int8_MAX : \ 1.443 + ((a) < silk_int8_MIN ? silk_int8_MIN : (a))) 1.444 +#define silk_SAT16(a) ((a) > silk_int16_MAX ? silk_int16_MAX : \ 1.445 + ((a) < silk_int16_MIN ? silk_int16_MIN : (a))) 1.446 +#define silk_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : \ 1.447 + ((a) < silk_int32_MIN ? silk_int32_MIN : (a))) 1.448 + 1.449 +#define silk_CHECK_FIT8(a) (a) 1.450 +#define silk_CHECK_FIT16(a) (a) 1.451 +#define silk_CHECK_FIT32(a) (a) 1.452 + 1.453 +#define silk_ADD_SAT16(a, b) (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a), (b) ) ) 1.454 +#define silk_ADD_SAT64(a, b) ((((a) + (b)) & 0x8000000000000000LL) == 0 ? \ 1.455 + ((((a) & (b)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a)+(b)) : \ 1.456 + ((((a) | (b)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a)+(b)) ) 1.457 + 1.458 +#define silk_SUB_SAT16(a, b) (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a), (b) ) ) 1.459 +#define silk_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL) == 0 ? \ 1.460 + (( (a) & ((b)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a)-(b)) : \ 1.461 + ((((a)^0x8000000000000000LL) & (b) & 0x8000000000000000LL) ? silk_int64_MAX : (a)-(b)) ) 1.462 + 1.463 +/* Saturation for positive input values */ 1.464 +#define silk_POS_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : (a)) 1.465 + 1.466 +/* Add with saturation for positive input values */ 1.467 +#define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b))) 1.468 +#define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b))) 1.469 +#define silk_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))) 1.470 +#define silk_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b))) 1.471 + 1.472 +#define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift))) /* shift >= 0, shift < 8 */ 1.473 +#define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shift))) /* shift >= 0, shift < 16 */ 1.474 +#define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shift))) /* shift >= 0, shift < 32 */ 1.475 +#define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shift))) /* shift >= 0, shift < 64 */ 1.476 +#define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift) /* shift >= 0, shift < 32 */ 1.477 + 1.478 +#define silk_RSHIFT8(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 8 */ 1.479 +#define silk_RSHIFT16(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 16 */ 1.480 +#define silk_RSHIFT32(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 32 */ 1.481 +#define silk_RSHIFT64(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 64 */ 1.482 +#define silk_RSHIFT(a, shift) silk_RSHIFT32(a, shift) /* shift >= 0, shift < 32 */ 1.483 + 1.484 +/* saturates before shifting */ 1.485 +#define silk_LSHIFT_SAT32(a, shift) (silk_LSHIFT32( silk_LIMIT( (a), silk_RSHIFT32( silk_int32_MIN, (shift) ), \ 1.486 + silk_RSHIFT32( silk_int32_MAX, (shift) ) ), (shift) )) 1.487 + 1.488 +#define silk_LSHIFT_ovflw(a, shift) ((opus_int32)((opus_uint32)(a) << (shift))) /* shift >= 0, allowed to overflow */ 1.489 +#define silk_LSHIFT_uint(a, shift) ((a) << (shift)) /* shift >= 0 */ 1.490 +#define silk_RSHIFT_uint(a, shift) ((a) >> (shift)) /* shift >= 0 */ 1.491 + 1.492 +#define silk_ADD_LSHIFT(a, b, shift) ((a) + silk_LSHIFT((b), (shift))) /* shift >= 0 */ 1.493 +#define silk_ADD_LSHIFT32(a, b, shift) silk_ADD32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */ 1.494 +#define silk_ADD_LSHIFT_uint(a, b, shift) ((a) + silk_LSHIFT_uint((b), (shift))) /* shift >= 0 */ 1.495 +#define silk_ADD_RSHIFT(a, b, shift) ((a) + silk_RSHIFT((b), (shift))) /* shift >= 0 */ 1.496 +#define silk_ADD_RSHIFT32(a, b, shift) silk_ADD32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */ 1.497 +#define silk_ADD_RSHIFT_uint(a, b, shift) ((a) + silk_RSHIFT_uint((b), (shift))) /* shift >= 0 */ 1.498 +#define silk_SUB_LSHIFT32(a, b, shift) silk_SUB32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */ 1.499 +#define silk_SUB_RSHIFT32(a, b, shift) silk_SUB32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */ 1.500 + 1.501 +/* Requires that shift > 0 */ 1.502 +#define silk_RSHIFT_ROUND(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1) 1.503 +#define silk_RSHIFT_ROUND64(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1) 1.504 + 1.505 +/* Number of rightshift required to fit the multiplication */ 1.506 +#define silk_NSHIFT_MUL_32_32(a, b) ( -(31- (32-silk_CLZ32(silk_abs(a)) + (32-silk_CLZ32(silk_abs(b))))) ) 1.507 +#define silk_NSHIFT_MUL_16_16(a, b) ( -(15- (16-silk_CLZ16(silk_abs(a)) + (16-silk_CLZ16(silk_abs(b))))) ) 1.508 + 1.509 + 1.510 +#define silk_min(a, b) (((a) < (b)) ? (a) : (b)) 1.511 +#define silk_max(a, b) (((a) > (b)) ? (a) : (b)) 1.512 + 1.513 +/* Macro to convert floating-point constants to fixed-point */ 1.514 +#define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5)) 1.515 + 1.516 +/* silk_min() versions with typecast in the function call */ 1.517 +static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) 1.518 +{ 1.519 + return (((a) < (b)) ? (a) : (b)); 1.520 +} 1.521 +static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) 1.522 +{ 1.523 + return (((a) < (b)) ? (a) : (b)); 1.524 +} 1.525 +static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) 1.526 +{ 1.527 + return (((a) < (b)) ? (a) : (b)); 1.528 +} 1.529 +static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) 1.530 +{ 1.531 + return (((a) < (b)) ? (a) : (b)); 1.532 +} 1.533 + 1.534 +/* silk_min() versions with typecast in the function call */ 1.535 +static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) 1.536 +{ 1.537 + return (((a) > (b)) ? (a) : (b)); 1.538 +} 1.539 +static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) 1.540 +{ 1.541 + return (((a) > (b)) ? (a) : (b)); 1.542 +} 1.543 +static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) 1.544 +{ 1.545 + return (((a) > (b)) ? (a) : (b)); 1.546 +} 1.547 +static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) 1.548 +{ 1.549 + return (((a) > (b)) ? (a) : (b)); 1.550 +} 1.551 + 1.552 +#define silk_LIMIT( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ 1.553 + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))) 1.554 + 1.555 +#define silk_LIMIT_int silk_LIMIT 1.556 +#define silk_LIMIT_16 silk_LIMIT 1.557 +#define silk_LIMIT_32 silk_LIMIT 1.558 + 1.559 +#define silk_abs(a) (((a) > 0) ? (a) : -(a)) /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */ 1.560 +#define silk_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))) - ((a) >> (8 * sizeof(a) - 1))) 1.561 +#define silk_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31)) 1.562 +#define silk_abs_int64(a) (((a) > 0) ? (a) : -(a)) 1.563 + 1.564 +#define silk_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )) 1.565 + 1.566 +/* PSEUDO-RANDOM GENERATOR */ 1.567 +/* Make sure to store the result as the seed for the next call (also in between */ 1.568 +/* frames), otherwise result won't be random at all. When only using some of the */ 1.569 +/* bits, take the most significant bits by right-shifting. */ 1.570 +#define silk_RAND(seed) (silk_MLA_ovflw(907633515, (seed), 196314165)) 1.571 + 1.572 +/* Add some multiplication functions that can be easily mapped to ARM. */ 1.573 + 1.574 +/* silk_SMMUL: Signed top word multiply. 1.575 + ARMv6 2 instruction cycles. 1.576 + ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.(except xM)*/ 1.577 +/*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/ 1.578 +/* the following seems faster on x86 */ 1.579 +#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL((a32), (b32)), 32) 1.580 + 1.581 +#include "Inlines.h" 1.582 +#include "MacroCount.h" 1.583 +#include "MacroDebug.h" 1.584 + 1.585 +#ifdef OPUS_ARM_INLINE_ASM 1.586 +#include "arm/SigProc_FIX_armv4.h" 1.587 +#endif 1.588 + 1.589 +#ifdef OPUS_ARM_INLINE_EDSP 1.590 +#include "arm/SigProc_FIX_armv5e.h" 1.591 +#endif 1.592 + 1.593 +#ifdef __cplusplus 1.594 +} 1.595 +#endif 1.596 + 1.597 +#endif /* SILK_SIGPROC_FIX_H */