SILK update with LBRR and some bugfixes
[opus.git] / src_FIX / SKP_Silk_HP_variable_cutoff_FIX.c
index b695a5a..bfc310b 100644 (file)
@@ -1,5 +1,5 @@
 /***********************************************************************\r
-Copyright (c) 2006-2010, Skype Limited. All rights reserved. \r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
 Redistribution and use in source and binary forms, with or without \r
 modification, (subject to the limitations in the disclaimer below) \r
 are permitted provided that the following conditions are met:\r
@@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ***********************************************************************/\r
 \r
 #include "SKP_Silk_main_FIX.h"\r
+#include "SKP_Silk_tuning_parameters.h"\r
 \r
 #if HIGH_PASS_INPUT\r
 \r
@@ -48,7 +49,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
     /*********************************************/\r
     /* Estimate Low End of Pitch Frequency Range */\r
     /*********************************************/\r
-    if( psEnc->sCmn.prev_sigtype == SIG_TYPE_VOICED ) {\r
+    if( psEnc->sCmn.prevSignalType == TYPE_VOICED ) {\r
         /* difference, in log domain */\r
         pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEnc->sCmn.fs_kHz, 1000 ), 16 ), psEnc->sCmn.prevLag );\r
         pitch_freq_log_Q7 = SKP_Silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); //0x70\r
@@ -57,7 +58,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
         quality_Q15 = psEncCtrl->input_quality_bands_Q15[ 0 ];\r
         pitch_freq_log_Q7 = SKP_SUB32( pitch_freq_log_Q7, SKP_SMULWB( SKP_SMULWB( SKP_LSHIFT( quality_Q15, 2 ), quality_Q15 ), \r
             pitch_freq_log_Q7 - SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7 ) );\r
-        pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( 19661 - quality_Q15, 9 ) ); // 19661_Q15 = 0.6_Q0\r
+        pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( SKP_FIX_CONST( 0.6, 15 ) - quality_Q15, 9 ) );\r
 \r
         //delta_freq = pitch_freq_log - psEnc->variable_HP_smth1;\r
         delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEnc->variable_HP_smth1_Q15, 8 );\r
@@ -67,21 +68,22 @@ void SKP_Silk_HP_variable_cutoff_FIX(
         }\r
 \r
         /* limit delta, to reduce impact of outliers */\r
-        delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -VARIABLE_HP_MAX_DELTA_FREQ_Q7, VARIABLE_HP_MAX_DELTA_FREQ_Q7 );\r
+        delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );\r
 \r
         /* update smoother */\r
         psEnc->variable_HP_smth1_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth1_Q15, \r
-            SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), VARIABLE_HP_SMTH_COEF1_Q16 );\r
+            SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );\r
     }\r
     /* second smoother */\r
     psEnc->variable_HP_smth2_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth2_Q15, \r
-        psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, VARIABLE_HP_SMTH_COEF2_Q16 );\r
+        psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF2, 16 ) );\r
 \r
     /* convert from log scale to Hertz */\r
-    psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) ); //pow( 2.0, psEnc->variable_HP_smth2 );\r
+    psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) );\r
 \r
     /* limit frequency range */\r
-    psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, VARIABLE_HP_MIN_FREQ_Q0, VARIABLE_HP_MAX_FREQ_Q0 );\r
+    psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, \r
+        SKP_FIX_CONST( VARIABLE_HP_MIN_FREQ, 0 ), SKP_FIX_CONST( VARIABLE_HP_MAX_FREQ, 0 ) );\r
 \r
     /********************************/\r
     /* Compute Filter Coefficients  */\r
@@ -94,7 +96,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
     SKP_assert( Fc_Q19 >=  3704 );\r
     SKP_assert( Fc_Q19 <= 27787 );\r
 \r
-    r_Q28 = ( 1 << 28 ) - SKP_MUL( 471, Fc_Q19 ); // 471_Q9 = 0.92_Q0, range: 255347779 to 266690872, 27-28 bits\r
+    r_Q28 = SKP_FIX_CONST( 1.0, 28 ) - SKP_MUL( SKP_FIX_CONST( 0.92, 9 ), Fc_Q19 );\r
     SKP_assert( r_Q28 >= 255347779 );\r
     SKP_assert( r_Q28 <= 266690872 );\r
 \r
@@ -106,7 +108,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
     \r
     // -r * ( 2 - Fc * Fc );\r
     r_Q22  = SKP_RSHIFT( r_Q28, 6 );\r
-    A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - ( 2 << 22 ) );\r
+    A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - SKP_FIX_CONST( 2.0,  22 ) );\r
     A_Q28[ 1 ] = SKP_SMULWW( r_Q22, r_Q22 );\r
 \r
     /********************************/\r