cannam@154: /*********************************************************************** cannam@154: Copyright (c) 2006-2011, Skype Limited. All rights reserved. cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: - Redistributions of source code must retain the above copyright notice, cannam@154: this list of conditions and the following disclaimer. cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: - Neither the name of Internet Society, IETF or IETF Trust, nor the cannam@154: names of specific contributors, may be used to endorse or promote cannam@154: products derived from this software without specific prior written cannam@154: permission. cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" cannam@154: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE cannam@154: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE cannam@154: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE cannam@154: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR cannam@154: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF cannam@154: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS cannam@154: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN cannam@154: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) cannam@154: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE cannam@154: POSSIBILITY OF SUCH DAMAGE. cannam@154: ***********************************************************************/ cannam@154: cannam@154: #ifndef SILK_SIGPROC_FLP_H cannam@154: #define SILK_SIGPROC_FLP_H cannam@154: cannam@154: #include "SigProc_FIX.h" cannam@154: #include "float_cast.h" cannam@154: #include cannam@154: cannam@154: #ifdef __cplusplus cannam@154: extern "C" cannam@154: { cannam@154: #endif cannam@154: cannam@154: /********************************************************************/ cannam@154: /* SIGNAL PROCESSING FUNCTIONS */ cannam@154: /********************************************************************/ cannam@154: cannam@154: /* Chirp (bw expand) LP AR filter */ cannam@154: void silk_bwexpander_FLP( cannam@154: silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */ cannam@154: const opus_int d, /* I length of ar */ cannam@154: const silk_float chirp /* I chirp factor (typically in range (0..1) ) */ cannam@154: ); cannam@154: cannam@154: /* compute inverse of LPC prediction gain, and */ cannam@154: /* test if LPC coefficients are stable (all poles within unit circle) */ cannam@154: /* this code is based on silk_FLP_a2k() */ cannam@154: silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */ cannam@154: const silk_float *A, /* I prediction coefficients [order] */ cannam@154: opus_int32 order /* I prediction order */ cannam@154: ); cannam@154: cannam@154: silk_float silk_schur_FLP( /* O returns residual energy */ cannam@154: silk_float refl_coef[], /* O reflection coefficients (length order) */ cannam@154: const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */ cannam@154: opus_int order /* I order */ cannam@154: ); cannam@154: cannam@154: void silk_k2a_FLP( cannam@154: silk_float *A, /* O prediction coefficients [order] */ cannam@154: const silk_float *rc, /* I reflection coefficients [order] */ cannam@154: opus_int32 order /* I prediction order */ cannam@154: ); cannam@154: cannam@154: /* compute autocorrelation */ cannam@154: void silk_autocorrelation_FLP( cannam@154: silk_float *results, /* O result (length correlationCount) */ cannam@154: const silk_float *inputData, /* I input data to correlate */ cannam@154: opus_int inputDataSize, /* I length of input */ cannam@154: opus_int correlationCount /* I number of correlation taps to compute */ cannam@154: ); cannam@154: cannam@154: opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */ cannam@154: const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ cannam@154: opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */ cannam@154: opus_int16 *lagIndex, /* O Lag Index */ cannam@154: opus_int8 *contourIndex, /* O Pitch contour Index */ cannam@154: silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */ cannam@154: opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ cannam@154: const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */ cannam@154: const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */ cannam@154: const opus_int Fs_kHz, /* I sample frequency (kHz) */ cannam@154: const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ cannam@154: const opus_int nb_subfr, /* I Number of 5 ms subframes */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: void silk_insertion_sort_decreasing_FLP( cannam@154: silk_float *a, /* I/O Unsorted / Sorted vector */ cannam@154: opus_int *idx, /* O Index vector for the sorted elements */ cannam@154: const opus_int L, /* I Vector length */ cannam@154: const opus_int K /* I Number of correctly sorted positions */ cannam@154: ); cannam@154: cannam@154: /* Compute reflection coefficients from input signal */ cannam@154: silk_float silk_burg_modified_FLP( /* O returns residual energy */ cannam@154: silk_float A[], /* O prediction coefficients (length order) */ cannam@154: const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ cannam@154: const silk_float minInvGain, /* I minimum inverse prediction gain */ cannam@154: const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */ cannam@154: const opus_int nb_subfr, /* I number of subframes stacked in x */ cannam@154: const opus_int D /* I order */ cannam@154: ); cannam@154: cannam@154: /* multiply a vector by a constant */ cannam@154: void silk_scale_vector_FLP( cannam@154: silk_float *data1, cannam@154: silk_float gain, cannam@154: opus_int dataSize cannam@154: ); cannam@154: cannam@154: /* copy and multiply a vector by a constant */ cannam@154: void silk_scale_copy_vector_FLP( cannam@154: silk_float *data_out, cannam@154: const silk_float *data_in, cannam@154: silk_float gain, cannam@154: opus_int dataSize cannam@154: ); cannam@154: cannam@154: /* inner product of two silk_float arrays, with result as double */ cannam@154: double silk_inner_product_FLP( cannam@154: const silk_float *data1, cannam@154: const silk_float *data2, cannam@154: opus_int dataSize cannam@154: ); cannam@154: cannam@154: /* sum of squares of a silk_float array, with result as double */ cannam@154: double silk_energy_FLP( cannam@154: const silk_float *data, cannam@154: opus_int dataSize cannam@154: ); cannam@154: cannam@154: /********************************************************************/ cannam@154: /* MACROS */ cannam@154: /********************************************************************/ cannam@154: cannam@154: #define PI (3.1415926536f) cannam@154: cannam@154: #define silk_min_float( a, b ) (((a) < (b)) ? (a) : (b)) cannam@154: #define silk_max_float( a, b ) (((a) > (b)) ? (a) : (b)) cannam@154: #define silk_abs_float( a ) ((silk_float)fabs(a)) cannam@154: cannam@154: /* sigmoid function */ cannam@154: static OPUS_INLINE silk_float silk_sigmoid( silk_float x ) cannam@154: { cannam@154: return (silk_float)(1.0 / (1.0 + exp(-x))); cannam@154: } cannam@154: cannam@154: /* floating-point to integer conversion (rounding) */ cannam@154: static OPUS_INLINE opus_int32 silk_float2int( silk_float x ) cannam@154: { cannam@154: return (opus_int32)float2int( x ); cannam@154: } cannam@154: cannam@154: /* floating-point to integer conversion (rounding) */ cannam@154: static OPUS_INLINE void silk_float2short_array( cannam@154: opus_int16 *out, cannam@154: const silk_float *in, cannam@154: opus_int32 length cannam@154: ) cannam@154: { cannam@154: opus_int32 k; cannam@154: for( k = length - 1; k >= 0; k-- ) { cannam@154: out[k] = silk_SAT16( (opus_int32)float2int( in[k] ) ); cannam@154: } cannam@154: } cannam@154: cannam@154: /* integer to floating-point conversion */ cannam@154: static OPUS_INLINE void silk_short2float_array( cannam@154: silk_float *out, cannam@154: const opus_int16 *in, cannam@154: opus_int32 length cannam@154: ) cannam@154: { cannam@154: opus_int32 k; cannam@154: for( k = length - 1; k >= 0; k-- ) { cannam@154: out[k] = (silk_float)in[k]; cannam@154: } cannam@154: } cannam@154: cannam@154: /* using log2() helps the fixed-point conversion */ cannam@154: static OPUS_INLINE silk_float silk_log2( double x ) cannam@154: { cannam@154: return ( silk_float )( 3.32192809488736 * log10( x ) ); cannam@154: } cannam@154: cannam@154: #ifdef __cplusplus cannam@154: } cannam@154: #endif cannam@154: cannam@154: #endif /* SILK_SIGPROC_FLP_H */