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