annotate src/opus-1.3/silk/SigProc_FIX.h @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifndef SILK_SIGPROC_FIX_H
cannam@154 29 #define SILK_SIGPROC_FIX_H
cannam@154 30
cannam@154 31 #ifdef __cplusplus
cannam@154 32 extern "C"
cannam@154 33 {
cannam@154 34 #endif
cannam@154 35
cannam@154 36 /*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */
cannam@154 37
cannam@154 38 #define SILK_MAX_ORDER_LPC 24 /* max order of the LPC analysis in schur() and k2a() */
cannam@154 39
cannam@154 40 #include <string.h> /* for memset(), memcpy(), memmove() */
cannam@154 41 #include "typedef.h"
cannam@154 42 #include "resampler_structs.h"
cannam@154 43 #include "macros.h"
cannam@154 44 #include "cpu_support.h"
cannam@154 45
cannam@154 46 #if defined(OPUS_X86_MAY_HAVE_SSE4_1)
cannam@154 47 #include "x86/SigProc_FIX_sse.h"
cannam@154 48 #endif
cannam@154 49
cannam@154 50 #if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
cannam@154 51 #include "arm/biquad_alt_arm.h"
cannam@154 52 #include "arm/LPC_inv_pred_gain_arm.h"
cannam@154 53 #endif
cannam@154 54
cannam@154 55 /********************************************************************/
cannam@154 56 /* SIGNAL PROCESSING FUNCTIONS */
cannam@154 57 /********************************************************************/
cannam@154 58
cannam@154 59 /*!
cannam@154 60 * Initialize/reset the resampler state for a given pair of input/output sampling rates
cannam@154 61 */
cannam@154 62 opus_int silk_resampler_init(
cannam@154 63 silk_resampler_state_struct *S, /* I/O Resampler state */
cannam@154 64 opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
cannam@154 65 opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
cannam@154 66 opus_int forEnc /* I If 1: encoder; if 0: decoder */
cannam@154 67 );
cannam@154 68
cannam@154 69 /*!
cannam@154 70 * Resampler: convert from one sampling rate to another
cannam@154 71 */
cannam@154 72 opus_int silk_resampler(
cannam@154 73 silk_resampler_state_struct *S, /* I/O Resampler state */
cannam@154 74 opus_int16 out[], /* O Output signal */
cannam@154 75 const opus_int16 in[], /* I Input signal */
cannam@154 76 opus_int32 inLen /* I Number of input samples */
cannam@154 77 );
cannam@154 78
cannam@154 79 /*!
cannam@154 80 * Downsample 2x, mediocre quality
cannam@154 81 */
cannam@154 82 void silk_resampler_down2(
cannam@154 83 opus_int32 *S, /* I/O State vector [ 2 ] */
cannam@154 84 opus_int16 *out, /* O Output signal [ len ] */
cannam@154 85 const opus_int16 *in, /* I Input signal [ floor(len/2) ] */
cannam@154 86 opus_int32 inLen /* I Number of input samples */
cannam@154 87 );
cannam@154 88
cannam@154 89 /*!
cannam@154 90 * Downsample by a factor 2/3, low quality
cannam@154 91 */
cannam@154 92 void silk_resampler_down2_3(
cannam@154 93 opus_int32 *S, /* I/O State vector [ 6 ] */
cannam@154 94 opus_int16 *out, /* O Output signal [ floor(2*inLen/3) ] */
cannam@154 95 const opus_int16 *in, /* I Input signal [ inLen ] */
cannam@154 96 opus_int32 inLen /* I Number of input samples */
cannam@154 97 );
cannam@154 98
cannam@154 99 /*!
cannam@154 100 * second order ARMA filter;
cannam@154 101 * slower than biquad() but uses more precise coefficients
cannam@154 102 * can handle (slowly) varying coefficients
cannam@154 103 */
cannam@154 104 void silk_biquad_alt_stride1(
cannam@154 105 const opus_int16 *in, /* I input signal */
cannam@154 106 const opus_int32 *B_Q28, /* I MA coefficients [3] */
cannam@154 107 const opus_int32 *A_Q28, /* I AR coefficients [2] */
cannam@154 108 opus_int32 *S, /* I/O State vector [2] */
cannam@154 109 opus_int16 *out, /* O output signal */
cannam@154 110 const opus_int32 len /* I signal length (must be even) */
cannam@154 111 );
cannam@154 112
cannam@154 113 void silk_biquad_alt_stride2_c(
cannam@154 114 const opus_int16 *in, /* I input signal */
cannam@154 115 const opus_int32 *B_Q28, /* I MA coefficients [3] */
cannam@154 116 const opus_int32 *A_Q28, /* I AR coefficients [2] */
cannam@154 117 opus_int32 *S, /* I/O State vector [4] */
cannam@154 118 opus_int16 *out, /* O output signal */
cannam@154 119 const opus_int32 len /* I signal length (must be even) */
cannam@154 120 );
cannam@154 121
cannam@154 122 /* Variable order MA prediction error filter. */
cannam@154 123 void silk_LPC_analysis_filter(
cannam@154 124 opus_int16 *out, /* O Output signal */
cannam@154 125 const opus_int16 *in, /* I Input signal */
cannam@154 126 const opus_int16 *B, /* I MA prediction coefficients, Q12 [order] */
cannam@154 127 const opus_int32 len, /* I Signal length */
cannam@154 128 const opus_int32 d, /* I Filter order */
cannam@154 129 int arch /* I Run-time architecture */
cannam@154 130 );
cannam@154 131
cannam@154 132 /* Chirp (bandwidth expand) LP AR filter */
cannam@154 133 void silk_bwexpander(
cannam@154 134 opus_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */
cannam@154 135 const opus_int d, /* I Length of ar */
cannam@154 136 opus_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */
cannam@154 137 );
cannam@154 138
cannam@154 139 /* Chirp (bandwidth expand) LP AR filter */
cannam@154 140 void silk_bwexpander_32(
cannam@154 141 opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */
cannam@154 142 const opus_int d, /* I Length of ar */
cannam@154 143 opus_int32 chirp_Q16 /* I Chirp factor in Q16 */
cannam@154 144 );
cannam@154 145
cannam@154 146 /* Compute inverse of LPC prediction gain, and */
cannam@154 147 /* test if LPC coefficients are stable (all poles within unit circle) */
cannam@154 148 opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse prediction gain in energy domain, Q30 */
cannam@154 149 const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */
cannam@154 150 const opus_int order /* I Prediction order */
cannam@154 151 );
cannam@154 152
cannam@154 153 /* Split signal in two decimated bands using first-order allpass filters */
cannam@154 154 void silk_ana_filt_bank_1(
cannam@154 155 const opus_int16 *in, /* I Input signal [N] */
cannam@154 156 opus_int32 *S, /* I/O State vector [2] */
cannam@154 157 opus_int16 *outL, /* O Low band [N/2] */
cannam@154 158 opus_int16 *outH, /* O High band [N/2] */
cannam@154 159 const opus_int32 N /* I Number of input samples */
cannam@154 160 );
cannam@154 161
cannam@154 162 #if !defined(OVERRIDE_silk_biquad_alt_stride2)
cannam@154 163 #define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((void)(arch), silk_biquad_alt_stride2_c(in, B_Q28, A_Q28, S, out, len))
cannam@154 164 #endif
cannam@154 165
cannam@154 166 #if !defined(OVERRIDE_silk_LPC_inverse_pred_gain)
cannam@154 167 #define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((void)(arch), silk_LPC_inverse_pred_gain_c(A_Q12, order))
cannam@154 168 #endif
cannam@154 169
cannam@154 170 /********************************************************************/
cannam@154 171 /* SCALAR FUNCTIONS */
cannam@154 172 /********************************************************************/
cannam@154 173
cannam@154 174 /* Approximation of 128 * log2() (exact inverse of approx 2^() below) */
cannam@154 175 /* Convert input to a log scale */
cannam@154 176 opus_int32 silk_lin2log(
cannam@154 177 const opus_int32 inLin /* I input in linear scale */
cannam@154 178 );
cannam@154 179
cannam@154 180 /* Approximation of a sigmoid function */
cannam@154 181 opus_int silk_sigm_Q15(
cannam@154 182 opus_int in_Q5 /* I */
cannam@154 183 );
cannam@154 184
cannam@154 185 /* Approximation of 2^() (exact inverse of approx log2() above) */
cannam@154 186 /* Convert input to a linear scale */
cannam@154 187 opus_int32 silk_log2lin(
cannam@154 188 const opus_int32 inLog_Q7 /* I input on log scale */
cannam@154 189 );
cannam@154 190
cannam@154 191 /* Compute number of bits to right shift the sum of squares of a vector */
cannam@154 192 /* of int16s to make it fit in an int32 */
cannam@154 193 void silk_sum_sqr_shift(
cannam@154 194 opus_int32 *energy, /* O Energy of x, after shifting to the right */
cannam@154 195 opus_int *shift, /* O Number of bits right shift applied to energy */
cannam@154 196 const opus_int16 *x, /* I Input vector */
cannam@154 197 opus_int len /* I Length of input vector */
cannam@154 198 );
cannam@154 199
cannam@154 200 /* Calculates the reflection coefficients from the correlation sequence */
cannam@154 201 /* Faster than schur64(), but much less accurate. */
cannam@154 202 /* uses SMLAWB(), requiring armv5E and higher. */
cannam@154 203 opus_int32 silk_schur( /* O Returns residual energy */
cannam@154 204 opus_int16 *rc_Q15, /* O reflection coefficients [order] Q15 */
cannam@154 205 const opus_int32 *c, /* I correlations [order+1] */
cannam@154 206 const opus_int32 order /* I prediction order */
cannam@154 207 );
cannam@154 208
cannam@154 209 /* Calculates the reflection coefficients from the correlation sequence */
cannam@154 210 /* Slower than schur(), but more accurate. */
cannam@154 211 /* Uses SMULL(), available on armv4 */
cannam@154 212 opus_int32 silk_schur64( /* O returns residual energy */
cannam@154 213 opus_int32 rc_Q16[], /* O Reflection coefficients [order] Q16 */
cannam@154 214 const opus_int32 c[], /* I Correlations [order+1] */
cannam@154 215 opus_int32 order /* I Prediction order */
cannam@154 216 );
cannam@154 217
cannam@154 218 /* Step up function, converts reflection coefficients to prediction coefficients */
cannam@154 219 void silk_k2a(
cannam@154 220 opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */
cannam@154 221 const opus_int16 *rc_Q15, /* I Reflection coefficients [order] Q15 */
cannam@154 222 const opus_int32 order /* I Prediction order */
cannam@154 223 );
cannam@154 224
cannam@154 225 /* Step up function, converts reflection coefficients to prediction coefficients */
cannam@154 226 void silk_k2a_Q16(
cannam@154 227 opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */
cannam@154 228 const opus_int32 *rc_Q16, /* I Reflection coefficients [order] Q16 */
cannam@154 229 const opus_int32 order /* I Prediction order */
cannam@154 230 );
cannam@154 231
cannam@154 232 /* Apply sine window to signal vector. */
cannam@154 233 /* Window types: */
cannam@154 234 /* 1 -> sine window from 0 to pi/2 */
cannam@154 235 /* 2 -> sine window from pi/2 to pi */
cannam@154 236 /* every other sample of window is linearly interpolated, for speed */
cannam@154 237 void silk_apply_sine_window(
cannam@154 238 opus_int16 px_win[], /* O Pointer to windowed signal */
cannam@154 239 const opus_int16 px[], /* I Pointer to input signal */
cannam@154 240 const opus_int win_type, /* I Selects a window type */
cannam@154 241 const opus_int length /* I Window length, multiple of 4 */
cannam@154 242 );
cannam@154 243
cannam@154 244 /* Compute autocorrelation */
cannam@154 245 void silk_autocorr(
cannam@154 246 opus_int32 *results, /* O Result (length correlationCount) */
cannam@154 247 opus_int *scale, /* O Scaling of the correlation vector */
cannam@154 248 const opus_int16 *inputData, /* I Input data to correlate */
cannam@154 249 const opus_int inputDataSize, /* I Length of input */
cannam@154 250 const opus_int correlationCount, /* I Number of correlation taps to compute */
cannam@154 251 int arch /* I Run-time architecture */
cannam@154 252 );
cannam@154 253
cannam@154 254 void silk_decode_pitch(
cannam@154 255 opus_int16 lagIndex, /* I */
cannam@154 256 opus_int8 contourIndex, /* O */
cannam@154 257 opus_int pitch_lags[], /* O 4 pitch values */
cannam@154 258 const opus_int Fs_kHz, /* I sampling frequency (kHz) */
cannam@154 259 const opus_int nb_subfr /* I number of sub frames */
cannam@154 260 );
cannam@154 261
cannam@154 262 opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */
cannam@154 263 const opus_int16 *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
cannam@154 264 opus_int *pitch_out, /* O 4 pitch lag values */
cannam@154 265 opus_int16 *lagIndex, /* O Lag Index */
cannam@154 266 opus_int8 *contourIndex, /* O Pitch contour Index */
cannam@154 267 opus_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */
cannam@154 268 opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
cannam@154 269 const opus_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */
cannam@154 270 const opus_int search_thres2_Q13, /* I Final threshold for lag candidates 0 - 1 */
cannam@154 271 const opus_int Fs_kHz, /* I Sample frequency (kHz) */
cannam@154 272 const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
cannam@154 273 const opus_int nb_subfr, /* I number of 5 ms subframes */
cannam@154 274 int arch /* I Run-time architecture */
cannam@154 275 );
cannam@154 276
cannam@154 277 /* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */
cannam@154 278 /* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */
cannam@154 279 void silk_A2NLSF(
cannam@154 280 opus_int16 *NLSF, /* O Normalized Line Spectral Frequencies in Q15 (0..2^15-1) [d] */
cannam@154 281 opus_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */
cannam@154 282 const opus_int d /* I Filter order (must be even) */
cannam@154 283 );
cannam@154 284
cannam@154 285 /* compute whitening filter coefficients from normalized line spectral frequencies */
cannam@154 286 void silk_NLSF2A(
cannam@154 287 opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
cannam@154 288 const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */
cannam@154 289 const opus_int d, /* I filter order (should be even) */
cannam@154 290 int arch /* I Run-time architecture */
cannam@154 291 );
cannam@154 292
cannam@154 293 /* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around */
cannam@154 294 void silk_LPC_fit(
cannam@154 295 opus_int16 *a_QOUT, /* O Output signal */
cannam@154 296 opus_int32 *a_QIN, /* I/O Input signal */
cannam@154 297 const opus_int QOUT, /* I Input Q domain */
cannam@154 298 const opus_int QIN, /* I Input Q domain */
cannam@154 299 const opus_int d /* I Filter order */
cannam@154 300 );
cannam@154 301
cannam@154 302 void silk_insertion_sort_increasing(
cannam@154 303 opus_int32 *a, /* I/O Unsorted / Sorted vector */
cannam@154 304 opus_int *idx, /* O Index vector for the sorted elements */
cannam@154 305 const opus_int L, /* I Vector length */
cannam@154 306 const opus_int K /* I Number of correctly sorted positions */
cannam@154 307 );
cannam@154 308
cannam@154 309 void silk_insertion_sort_decreasing_int16(
cannam@154 310 opus_int16 *a, /* I/O Unsorted / Sorted vector */
cannam@154 311 opus_int *idx, /* O Index vector for the sorted elements */
cannam@154 312 const opus_int L, /* I Vector length */
cannam@154 313 const opus_int K /* I Number of correctly sorted positions */
cannam@154 314 );
cannam@154 315
cannam@154 316 void silk_insertion_sort_increasing_all_values_int16(
cannam@154 317 opus_int16 *a, /* I/O Unsorted / Sorted vector */
cannam@154 318 const opus_int L /* I Vector length */
cannam@154 319 );
cannam@154 320
cannam@154 321 /* NLSF stabilizer, for a single input data vector */
cannam@154 322 void silk_NLSF_stabilize(
cannam@154 323 opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */
cannam@154 324 const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */
cannam@154 325 const opus_int L /* I Number of NLSF parameters in the input vector */
cannam@154 326 );
cannam@154 327
cannam@154 328 /* Laroia low complexity NLSF weights */
cannam@154 329 void silk_NLSF_VQ_weights_laroia(
cannam@154 330 opus_int16 *pNLSFW_Q_OUT, /* O Pointer to input vector weights [D] */
cannam@154 331 const opus_int16 *pNLSF_Q15, /* I Pointer to input vector [D] */
cannam@154 332 const opus_int D /* I Input vector dimension (even) */
cannam@154 333 );
cannam@154 334
cannam@154 335 /* Compute reflection coefficients from input signal */
cannam@154 336 void silk_burg_modified_c(
cannam@154 337 opus_int32 *res_nrg, /* O Residual energy */
cannam@154 338 opus_int *res_nrg_Q, /* O Residual energy Q value */
cannam@154 339 opus_int32 A_Q16[], /* O Prediction coefficients (length order) */
cannam@154 340 const opus_int16 x[], /* I Input signal, length: nb_subfr * ( D + subfr_length ) */
cannam@154 341 const opus_int32 minInvGain_Q30, /* I Inverse of max prediction gain */
cannam@154 342 const opus_int subfr_length, /* I Input signal subframe length (incl. D preceding samples) */
cannam@154 343 const opus_int nb_subfr, /* I Number of subframes stacked in x */
cannam@154 344 const opus_int D, /* I Order */
cannam@154 345 int arch /* I Run-time architecture */
cannam@154 346 );
cannam@154 347
cannam@154 348 /* Copy and multiply a vector by a constant */
cannam@154 349 void silk_scale_copy_vector16(
cannam@154 350 opus_int16 *data_out,
cannam@154 351 const opus_int16 *data_in,
cannam@154 352 opus_int32 gain_Q16, /* I Gain in Q16 */
cannam@154 353 const opus_int dataSize /* I Length */
cannam@154 354 );
cannam@154 355
cannam@154 356 /* Some for the LTP related function requires Q26 to work.*/
cannam@154 357 void silk_scale_vector32_Q26_lshift_18(
cannam@154 358 opus_int32 *data1, /* I/O Q0/Q18 */
cannam@154 359 opus_int32 gain_Q26, /* I Q26 */
cannam@154 360 opus_int dataSize /* I length */
cannam@154 361 );
cannam@154 362
cannam@154 363 /********************************************************************/
cannam@154 364 /* INLINE ARM MATH */
cannam@154 365 /********************************************************************/
cannam@154 366
cannam@154 367 /* return sum( inVec1[i] * inVec2[i] ) */
cannam@154 368
cannam@154 369 opus_int32 silk_inner_prod_aligned(
cannam@154 370 const opus_int16 *const inVec1, /* I input vector 1 */
cannam@154 371 const opus_int16 *const inVec2, /* I input vector 2 */
cannam@154 372 const opus_int len, /* I vector lengths */
cannam@154 373 int arch /* I Run-time architecture */
cannam@154 374 );
cannam@154 375
cannam@154 376
cannam@154 377 opus_int32 silk_inner_prod_aligned_scale(
cannam@154 378 const opus_int16 *const inVec1, /* I input vector 1 */
cannam@154 379 const opus_int16 *const inVec2, /* I input vector 2 */
cannam@154 380 const opus_int scale, /* I number of bits to shift */
cannam@154 381 const opus_int len /* I vector lengths */
cannam@154 382 );
cannam@154 383
cannam@154 384 opus_int64 silk_inner_prod16_aligned_64_c(
cannam@154 385 const opus_int16 *inVec1, /* I input vector 1 */
cannam@154 386 const opus_int16 *inVec2, /* I input vector 2 */
cannam@154 387 const opus_int len /* I vector lengths */
cannam@154 388 );
cannam@154 389
cannam@154 390 /********************************************************************/
cannam@154 391 /* MACROS */
cannam@154 392 /********************************************************************/
cannam@154 393
cannam@154 394 /* Rotate a32 right by 'rot' bits. Negative rot values result in rotating
cannam@154 395 left. Output is 32bit int.
cannam@154 396 Note: contemporary compilers recognize the C expression below and
cannam@154 397 compile it into a 'ror' instruction if available. No need for OPUS_INLINE ASM! */
cannam@154 398 static OPUS_INLINE opus_int32 silk_ROR32( opus_int32 a32, opus_int rot )
cannam@154 399 {
cannam@154 400 opus_uint32 x = (opus_uint32) a32;
cannam@154 401 opus_uint32 r = (opus_uint32) rot;
cannam@154 402 opus_uint32 m = (opus_uint32) -rot;
cannam@154 403 if( rot == 0 ) {
cannam@154 404 return a32;
cannam@154 405 } else if( rot < 0 ) {
cannam@154 406 return (opus_int32) ((x << m) | (x >> (32 - m)));
cannam@154 407 } else {
cannam@154 408 return (opus_int32) ((x << (32 - r)) | (x >> r));
cannam@154 409 }
cannam@154 410 }
cannam@154 411
cannam@154 412 /* Allocate opus_int16 aligned to 4-byte memory address */
cannam@154 413 #if EMBEDDED_ARM
cannam@154 414 #define silk_DWORD_ALIGN __attribute__((aligned(4)))
cannam@154 415 #else
cannam@154 416 #define silk_DWORD_ALIGN
cannam@154 417 #endif
cannam@154 418
cannam@154 419 /* Useful Macros that can be adjusted to other platforms */
cannam@154 420 #define silk_memcpy(dest, src, size) memcpy((dest), (src), (size))
cannam@154 421 #define silk_memset(dest, src, size) memset((dest), (src), (size))
cannam@154 422 #define silk_memmove(dest, src, size) memmove((dest), (src), (size))
cannam@154 423
cannam@154 424 /* Fixed point macros */
cannam@154 425
cannam@154 426 /* (a32 * b32) output have to be 32bit int */
cannam@154 427 #define silk_MUL(a32, b32) ((a32) * (b32))
cannam@154 428
cannam@154 429 /* (a32 * b32) output have to be 32bit uint */
cannam@154 430 #define silk_MUL_uint(a32, b32) silk_MUL(a32, b32)
cannam@154 431
cannam@154 432 /* a32 + (b32 * c32) output have to be 32bit int */
cannam@154 433 #define silk_MLA(a32, b32, c32) silk_ADD32((a32),((b32) * (c32)))
cannam@154 434
cannam@154 435 /* a32 + (b32 * c32) output have to be 32bit uint */
cannam@154 436 #define silk_MLA_uint(a32, b32, c32) silk_MLA(a32, b32, c32)
cannam@154 437
cannam@154 438 /* ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */
cannam@154 439 #define silk_SMULTT(a32, b32) (((a32) >> 16) * ((b32) >> 16))
cannam@154 440
cannam@154 441 /* a32 + ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int */
cannam@154 442 #define silk_SMLATT(a32, b32, c32) silk_ADD32((a32),((b32) >> 16) * ((c32) >> 16))
cannam@154 443
cannam@154 444 #define silk_SMLALBB(a64, b16, c16) silk_ADD64((a64),(opus_int64)((opus_int32)(b16) * (opus_int32)(c16)))
cannam@154 445
cannam@154 446 /* (a32 * b32) */
cannam@154 447 #define silk_SMULL(a32, b32) ((opus_int64)(a32) * /*(opus_int64)*/(b32))
cannam@154 448
cannam@154 449 /* Adds two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour
cannam@154 450 (just standard two's complement implementation-specific behaviour) */
cannam@154 451 #define silk_ADD32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) + (opus_uint32)(b)))
cannam@154 452 /* Subtractss two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour
cannam@154 453 (just standard two's complement implementation-specific behaviour) */
cannam@154 454 #define silk_SUB32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) - (opus_uint32)(b)))
cannam@154 455
cannam@154 456 /* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */
cannam@154 457 #define silk_MLA_ovflw(a32, b32, c32) silk_ADD32_ovflw((a32), (opus_uint32)(b32) * (opus_uint32)(c32))
cannam@154 458 #define silk_SMLABB_ovflw(a32, b32, c32) (silk_ADD32_ovflw((a32) , ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32))))
cannam@154 459
cannam@154 460 #define silk_DIV32_16(a32, b16) ((opus_int32)((a32) / (b16)))
cannam@154 461 #define silk_DIV32(a32, b32) ((opus_int32)((a32) / (b32)))
cannam@154 462
cannam@154 463 /* These macros enables checking for overflow in silk_API_Debug.h*/
cannam@154 464 #define silk_ADD16(a, b) ((a) + (b))
cannam@154 465 #define silk_ADD32(a, b) ((a) + (b))
cannam@154 466 #define silk_ADD64(a, b) ((a) + (b))
cannam@154 467
cannam@154 468 #define silk_SUB16(a, b) ((a) - (b))
cannam@154 469 #define silk_SUB32(a, b) ((a) - (b))
cannam@154 470 #define silk_SUB64(a, b) ((a) - (b))
cannam@154 471
cannam@154 472 #define silk_SAT8(a) ((a) > silk_int8_MAX ? silk_int8_MAX : \
cannam@154 473 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)))
cannam@154 474 #define silk_SAT16(a) ((a) > silk_int16_MAX ? silk_int16_MAX : \
cannam@154 475 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)))
cannam@154 476 #define silk_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : \
cannam@154 477 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)))
cannam@154 478
cannam@154 479 #define silk_CHECK_FIT8(a) (a)
cannam@154 480 #define silk_CHECK_FIT16(a) (a)
cannam@154 481 #define silk_CHECK_FIT32(a) (a)
cannam@154 482
cannam@154 483 #define silk_ADD_SAT16(a, b) (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a), (b) ) )
cannam@154 484 #define silk_ADD_SAT64(a, b) ((((a) + (b)) & 0x8000000000000000LL) == 0 ? \
cannam@154 485 ((((a) & (b)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a)+(b)) : \
cannam@154 486 ((((a) | (b)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a)+(b)) )
cannam@154 487
cannam@154 488 #define silk_SUB_SAT16(a, b) (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a), (b) ) )
cannam@154 489 #define silk_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL) == 0 ? \
cannam@154 490 (( (a) & ((b)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a)-(b)) : \
cannam@154 491 ((((a)^0x8000000000000000LL) & (b) & 0x8000000000000000LL) ? silk_int64_MAX : (a)-(b)) )
cannam@154 492
cannam@154 493 /* Saturation for positive input values */
cannam@154 494 #define silk_POS_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_MAX : (a))
cannam@154 495
cannam@154 496 /* Add with saturation for positive input values */
cannam@154 497 #define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)))
cannam@154 498 #define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)))
cannam@154 499 #define silk_ADD_POS_SAT32(a, b) ((((opus_uint32)(a)+(opus_uint32)(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)))
cannam@154 500
cannam@154 501 #define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift))) /* shift >= 0, shift < 8 */
cannam@154 502 #define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shift))) /* shift >= 0, shift < 16 */
cannam@154 503 #define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shift))) /* shift >= 0, shift < 32 */
cannam@154 504 #define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shift))) /* shift >= 0, shift < 64 */
cannam@154 505 #define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift) /* shift >= 0, shift < 32 */
cannam@154 506
cannam@154 507 #define silk_RSHIFT8(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 8 */
cannam@154 508 #define silk_RSHIFT16(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 16 */
cannam@154 509 #define silk_RSHIFT32(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 32 */
cannam@154 510 #define silk_RSHIFT64(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 64 */
cannam@154 511 #define silk_RSHIFT(a, shift) silk_RSHIFT32(a, shift) /* shift >= 0, shift < 32 */
cannam@154 512
cannam@154 513 /* saturates before shifting */
cannam@154 514 #define silk_LSHIFT_SAT32(a, shift) (silk_LSHIFT32( silk_LIMIT( (a), silk_RSHIFT32( silk_int32_MIN, (shift) ), \
cannam@154 515 silk_RSHIFT32( silk_int32_MAX, (shift) ) ), (shift) ))
cannam@154 516
cannam@154 517 #define silk_LSHIFT_ovflw(a, shift) ((opus_int32)((opus_uint32)(a) << (shift))) /* shift >= 0, allowed to overflow */
cannam@154 518 #define silk_LSHIFT_uint(a, shift) ((a) << (shift)) /* shift >= 0 */
cannam@154 519 #define silk_RSHIFT_uint(a, shift) ((a) >> (shift)) /* shift >= 0 */
cannam@154 520
cannam@154 521 #define silk_ADD_LSHIFT(a, b, shift) ((a) + silk_LSHIFT((b), (shift))) /* shift >= 0 */
cannam@154 522 #define silk_ADD_LSHIFT32(a, b, shift) silk_ADD32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */
cannam@154 523 #define silk_ADD_LSHIFT_uint(a, b, shift) ((a) + silk_LSHIFT_uint((b), (shift))) /* shift >= 0 */
cannam@154 524 #define silk_ADD_RSHIFT(a, b, shift) ((a) + silk_RSHIFT((b), (shift))) /* shift >= 0 */
cannam@154 525 #define silk_ADD_RSHIFT32(a, b, shift) silk_ADD32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */
cannam@154 526 #define silk_ADD_RSHIFT_uint(a, b, shift) ((a) + silk_RSHIFT_uint((b), (shift))) /* shift >= 0 */
cannam@154 527 #define silk_SUB_LSHIFT32(a, b, shift) silk_SUB32((a), silk_LSHIFT32((b), (shift))) /* shift >= 0 */
cannam@154 528 #define silk_SUB_RSHIFT32(a, b, shift) silk_SUB32((a), silk_RSHIFT32((b), (shift))) /* shift >= 0 */
cannam@154 529
cannam@154 530 /* Requires that shift > 0 */
cannam@154 531 #define silk_RSHIFT_ROUND(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
cannam@154 532 #define silk_RSHIFT_ROUND64(a, shift) ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
cannam@154 533
cannam@154 534 /* Number of rightshift required to fit the multiplication */
cannam@154 535 #define silk_NSHIFT_MUL_32_32(a, b) ( -(31- (32-silk_CLZ32(silk_abs(a)) + (32-silk_CLZ32(silk_abs(b))))) )
cannam@154 536 #define silk_NSHIFT_MUL_16_16(a, b) ( -(15- (16-silk_CLZ16(silk_abs(a)) + (16-silk_CLZ16(silk_abs(b))))) )
cannam@154 537
cannam@154 538
cannam@154 539 #define silk_min(a, b) (((a) < (b)) ? (a) : (b))
cannam@154 540 #define silk_max(a, b) (((a) > (b)) ? (a) : (b))
cannam@154 541
cannam@154 542 /* Macro to convert floating-point constants to fixed-point */
cannam@154 543 #define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5))
cannam@154 544
cannam@154 545 /* silk_min() versions with typecast in the function call */
cannam@154 546 static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
cannam@154 547 {
cannam@154 548 return (((a) < (b)) ? (a) : (b));
cannam@154 549 }
cannam@154 550 static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
cannam@154 551 {
cannam@154 552 return (((a) < (b)) ? (a) : (b));
cannam@154 553 }
cannam@154 554 static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
cannam@154 555 {
cannam@154 556 return (((a) < (b)) ? (a) : (b));
cannam@154 557 }
cannam@154 558 static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
cannam@154 559 {
cannam@154 560 return (((a) < (b)) ? (a) : (b));
cannam@154 561 }
cannam@154 562
cannam@154 563 /* silk_min() versions with typecast in the function call */
cannam@154 564 static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
cannam@154 565 {
cannam@154 566 return (((a) > (b)) ? (a) : (b));
cannam@154 567 }
cannam@154 568 static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
cannam@154 569 {
cannam@154 570 return (((a) > (b)) ? (a) : (b));
cannam@154 571 }
cannam@154 572 static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
cannam@154 573 {
cannam@154 574 return (((a) > (b)) ? (a) : (b));
cannam@154 575 }
cannam@154 576 static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
cannam@154 577 {
cannam@154 578 return (((a) > (b)) ? (a) : (b));
cannam@154 579 }
cannam@154 580
cannam@154 581 #define silk_LIMIT( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
cannam@154 582 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))))
cannam@154 583
cannam@154 584 #define silk_LIMIT_int silk_LIMIT
cannam@154 585 #define silk_LIMIT_16 silk_LIMIT
cannam@154 586 #define silk_LIMIT_32 silk_LIMIT
cannam@154 587
cannam@154 588 #define silk_abs(a) (((a) > 0) ? (a) : -(a)) /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
cannam@154 589 #define silk_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))) - ((a) >> (8 * sizeof(a) - 1)))
cannam@154 590 #define silk_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31))
cannam@154 591 #define silk_abs_int64(a) (((a) > 0) ? (a) : -(a))
cannam@154 592
cannam@154 593 #define silk_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ))
cannam@154 594
cannam@154 595 /* PSEUDO-RANDOM GENERATOR */
cannam@154 596 /* Make sure to store the result as the seed for the next call (also in between */
cannam@154 597 /* frames), otherwise result won't be random at all. When only using some of the */
cannam@154 598 /* bits, take the most significant bits by right-shifting. */
cannam@154 599 #define RAND_MULTIPLIER 196314165
cannam@154 600 #define RAND_INCREMENT 907633515
cannam@154 601 #define silk_RAND(seed) (silk_MLA_ovflw((RAND_INCREMENT), (seed), (RAND_MULTIPLIER)))
cannam@154 602
cannam@154 603 /* Add some multiplication functions that can be easily mapped to ARM. */
cannam@154 604
cannam@154 605 /* silk_SMMUL: Signed top word multiply.
cannam@154 606 ARMv6 2 instruction cycles.
cannam@154 607 ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.(except xM)*/
cannam@154 608 /*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/
cannam@154 609 /* the following seems faster on x86 */
cannam@154 610 #define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL((a32), (b32)), 32)
cannam@154 611
cannam@154 612 #if !defined(OPUS_X86_MAY_HAVE_SSE4_1)
cannam@154 613 #define silk_burg_modified(res_nrg, res_nrg_Q, A_Q16, x, minInvGain_Q30, subfr_length, nb_subfr, D, arch) \
cannam@154 614 ((void)(arch), silk_burg_modified_c(res_nrg, res_nrg_Q, A_Q16, x, minInvGain_Q30, subfr_length, nb_subfr, D, arch))
cannam@154 615
cannam@154 616 #define silk_inner_prod16_aligned_64(inVec1, inVec2, len, arch) \
cannam@154 617 ((void)(arch),silk_inner_prod16_aligned_64_c(inVec1, inVec2, len))
cannam@154 618 #endif
cannam@154 619
cannam@154 620 #include "Inlines.h"
cannam@154 621 #include "MacroCount.h"
cannam@154 622 #include "MacroDebug.h"
cannam@154 623
cannam@154 624 #ifdef OPUS_ARM_INLINE_ASM
cannam@154 625 #include "arm/SigProc_FIX_armv4.h"
cannam@154 626 #endif
cannam@154 627
cannam@154 628 #ifdef OPUS_ARM_INLINE_EDSP
cannam@154 629 #include "arm/SigProc_FIX_armv5e.h"
cannam@154 630 #endif
cannam@154 631
cannam@154 632 #if defined(MIPSr1_ASM)
cannam@154 633 #include "mips/sigproc_fix_mipsr1.h"
cannam@154 634 #endif
cannam@154 635
cannam@154 636
cannam@154 637 #ifdef __cplusplus
cannam@154 638 }
cannam@154 639 #endif
cannam@154 640
cannam@154 641 #endif /* SILK_SIGPROC_FIX_H */