Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /*********************************************************************** |
michael@0 | 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
michael@0 | 3 | Redistribution and use in source and binary forms, with or without |
michael@0 | 4 | modification, are permitted provided that the following conditions |
michael@0 | 5 | are met: |
michael@0 | 6 | - Redistributions of source code must retain the above copyright notice, |
michael@0 | 7 | this list of conditions and the following disclaimer. |
michael@0 | 8 | - Redistributions in binary form must reproduce the above copyright |
michael@0 | 9 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 10 | documentation and/or other materials provided with the distribution. |
michael@0 | 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
michael@0 | 12 | names of specific contributors, may be used to endorse or promote |
michael@0 | 13 | products derived from this software without specific prior written |
michael@0 | 14 | permission. |
michael@0 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
michael@0 | 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
michael@0 | 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
michael@0 | 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
michael@0 | 25 | POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 26 | ***********************************************************************/ |
michael@0 | 27 | |
michael@0 | 28 | #ifndef SILK_SIGPROC_FLP_H |
michael@0 | 29 | #define SILK_SIGPROC_FLP_H |
michael@0 | 30 | |
michael@0 | 31 | #include "SigProc_FIX.h" |
michael@0 | 32 | #include "float_cast.h" |
michael@0 | 33 | #include <math.h> |
michael@0 | 34 | |
michael@0 | 35 | #ifdef __cplusplus |
michael@0 | 36 | extern "C" |
michael@0 | 37 | { |
michael@0 | 38 | #endif |
michael@0 | 39 | |
michael@0 | 40 | /********************************************************************/ |
michael@0 | 41 | /* SIGNAL PROCESSING FUNCTIONS */ |
michael@0 | 42 | /********************************************************************/ |
michael@0 | 43 | |
michael@0 | 44 | /* Chirp (bw expand) LP AR filter */ |
michael@0 | 45 | void silk_bwexpander_FLP( |
michael@0 | 46 | silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */ |
michael@0 | 47 | const opus_int d, /* I length of ar */ |
michael@0 | 48 | const silk_float chirp /* I chirp factor (typically in range (0..1) ) */ |
michael@0 | 49 | ); |
michael@0 | 50 | |
michael@0 | 51 | /* compute inverse of LPC prediction gain, and */ |
michael@0 | 52 | /* test if LPC coefficients are stable (all poles within unit circle) */ |
michael@0 | 53 | /* this code is based on silk_FLP_a2k() */ |
michael@0 | 54 | silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */ |
michael@0 | 55 | const silk_float *A, /* I prediction coefficients [order] */ |
michael@0 | 56 | opus_int32 order /* I prediction order */ |
michael@0 | 57 | ); |
michael@0 | 58 | |
michael@0 | 59 | silk_float silk_schur_FLP( /* O returns residual energy */ |
michael@0 | 60 | silk_float refl_coef[], /* O reflection coefficients (length order) */ |
michael@0 | 61 | const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */ |
michael@0 | 62 | opus_int order /* I order */ |
michael@0 | 63 | ); |
michael@0 | 64 | |
michael@0 | 65 | void silk_k2a_FLP( |
michael@0 | 66 | silk_float *A, /* O prediction coefficients [order] */ |
michael@0 | 67 | const silk_float *rc, /* I reflection coefficients [order] */ |
michael@0 | 68 | opus_int32 order /* I prediction order */ |
michael@0 | 69 | ); |
michael@0 | 70 | |
michael@0 | 71 | /* Solve the normal equations using the Levinson-Durbin recursion */ |
michael@0 | 72 | silk_float silk_levinsondurbin_FLP( /* O prediction error energy */ |
michael@0 | 73 | silk_float A[], /* O prediction coefficients [order] */ |
michael@0 | 74 | const silk_float corr[], /* I input auto-correlations [order + 1] */ |
michael@0 | 75 | const opus_int order /* I prediction order */ |
michael@0 | 76 | ); |
michael@0 | 77 | |
michael@0 | 78 | /* compute autocorrelation */ |
michael@0 | 79 | void silk_autocorrelation_FLP( |
michael@0 | 80 | silk_float *results, /* O result (length correlationCount) */ |
michael@0 | 81 | const silk_float *inputData, /* I input data to correlate */ |
michael@0 | 82 | opus_int inputDataSize, /* I length of input */ |
michael@0 | 83 | opus_int correlationCount /* I number of correlation taps to compute */ |
michael@0 | 84 | ); |
michael@0 | 85 | |
michael@0 | 86 | opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */ |
michael@0 | 87 | const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ |
michael@0 | 88 | opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */ |
michael@0 | 89 | opus_int16 *lagIndex, /* O Lag Index */ |
michael@0 | 90 | opus_int8 *contourIndex, /* O Pitch contour Index */ |
michael@0 | 91 | silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */ |
michael@0 | 92 | opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ |
michael@0 | 93 | const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */ |
michael@0 | 94 | const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */ |
michael@0 | 95 | const opus_int Fs_kHz, /* I sample frequency (kHz) */ |
michael@0 | 96 | const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ |
michael@0 | 97 | const opus_int nb_subfr, /* I Number of 5 ms subframes */ |
michael@0 | 98 | int arch /* I Run-time architecture */ |
michael@0 | 99 | ); |
michael@0 | 100 | |
michael@0 | 101 | void silk_insertion_sort_decreasing_FLP( |
michael@0 | 102 | silk_float *a, /* I/O Unsorted / Sorted vector */ |
michael@0 | 103 | opus_int *idx, /* O Index vector for the sorted elements */ |
michael@0 | 104 | const opus_int L, /* I Vector length */ |
michael@0 | 105 | const opus_int K /* I Number of correctly sorted positions */ |
michael@0 | 106 | ); |
michael@0 | 107 | |
michael@0 | 108 | /* Compute reflection coefficients from input signal */ |
michael@0 | 109 | silk_float silk_burg_modified_FLP( /* O returns residual energy */ |
michael@0 | 110 | silk_float A[], /* O prediction coefficients (length order) */ |
michael@0 | 111 | const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ |
michael@0 | 112 | const silk_float minInvGain, /* I minimum inverse prediction gain */ |
michael@0 | 113 | const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */ |
michael@0 | 114 | const opus_int nb_subfr, /* I number of subframes stacked in x */ |
michael@0 | 115 | const opus_int D /* I order */ |
michael@0 | 116 | ); |
michael@0 | 117 | |
michael@0 | 118 | /* multiply a vector by a constant */ |
michael@0 | 119 | void silk_scale_vector_FLP( |
michael@0 | 120 | silk_float *data1, |
michael@0 | 121 | silk_float gain, |
michael@0 | 122 | opus_int dataSize |
michael@0 | 123 | ); |
michael@0 | 124 | |
michael@0 | 125 | /* copy and multiply a vector by a constant */ |
michael@0 | 126 | void silk_scale_copy_vector_FLP( |
michael@0 | 127 | silk_float *data_out, |
michael@0 | 128 | const silk_float *data_in, |
michael@0 | 129 | silk_float gain, |
michael@0 | 130 | opus_int dataSize |
michael@0 | 131 | ); |
michael@0 | 132 | |
michael@0 | 133 | /* inner product of two silk_float arrays, with result as double */ |
michael@0 | 134 | double silk_inner_product_FLP( |
michael@0 | 135 | const silk_float *data1, |
michael@0 | 136 | const silk_float *data2, |
michael@0 | 137 | opus_int dataSize |
michael@0 | 138 | ); |
michael@0 | 139 | |
michael@0 | 140 | /* sum of squares of a silk_float array, with result as double */ |
michael@0 | 141 | double silk_energy_FLP( |
michael@0 | 142 | const silk_float *data, |
michael@0 | 143 | opus_int dataSize |
michael@0 | 144 | ); |
michael@0 | 145 | |
michael@0 | 146 | /********************************************************************/ |
michael@0 | 147 | /* MACROS */ |
michael@0 | 148 | /********************************************************************/ |
michael@0 | 149 | |
michael@0 | 150 | #define PI (3.1415926536f) |
michael@0 | 151 | |
michael@0 | 152 | #define silk_min_float( a, b ) (((a) < (b)) ? (a) : (b)) |
michael@0 | 153 | #define silk_max_float( a, b ) (((a) > (b)) ? (a) : (b)) |
michael@0 | 154 | #define silk_abs_float( a ) ((silk_float)fabs(a)) |
michael@0 | 155 | |
michael@0 | 156 | /* sigmoid function */ |
michael@0 | 157 | static OPUS_INLINE silk_float silk_sigmoid( silk_float x ) |
michael@0 | 158 | { |
michael@0 | 159 | return (silk_float)(1.0 / (1.0 + exp(-x))); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | /* floating-point to integer conversion (rounding) */ |
michael@0 | 163 | static OPUS_INLINE opus_int32 silk_float2int( silk_float x ) |
michael@0 | 164 | { |
michael@0 | 165 | return (opus_int32)float2int( x ); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | /* floating-point to integer conversion (rounding) */ |
michael@0 | 169 | static OPUS_INLINE void silk_float2short_array( |
michael@0 | 170 | opus_int16 *out, |
michael@0 | 171 | const silk_float *in, |
michael@0 | 172 | opus_int32 length |
michael@0 | 173 | ) |
michael@0 | 174 | { |
michael@0 | 175 | opus_int32 k; |
michael@0 | 176 | for( k = length - 1; k >= 0; k-- ) { |
michael@0 | 177 | out[k] = silk_SAT16( (opus_int32)float2int( in[k] ) ); |
michael@0 | 178 | } |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | /* integer to floating-point conversion */ |
michael@0 | 182 | static OPUS_INLINE void silk_short2float_array( |
michael@0 | 183 | silk_float *out, |
michael@0 | 184 | const opus_int16 *in, |
michael@0 | 185 | opus_int32 length |
michael@0 | 186 | ) |
michael@0 | 187 | { |
michael@0 | 188 | opus_int32 k; |
michael@0 | 189 | for( k = length - 1; k >= 0; k-- ) { |
michael@0 | 190 | out[k] = (silk_float)in[k]; |
michael@0 | 191 | } |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | /* using log2() helps the fixed-point conversion */ |
michael@0 | 195 | static OPUS_INLINE silk_float silk_log2( double x ) |
michael@0 | 196 | { |
michael@0 | 197 | return ( silk_float )( 3.32192809488736 * log10( x ) ); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | #ifdef __cplusplus |
michael@0 | 201 | } |
michael@0 | 202 | #endif |
michael@0 | 203 | |
michael@0 | 204 | #endif /* SILK_SIGPROC_FLP_H */ |