ref: be75f1d0fe8611e73c80e487410f7355adfdd122
parent: e790b37d86aa439d6207a9695e810c0b17ef9c97
author: Koen Vos <koen.vos@skype.net>
date: Wed May 25 13:18:02 EDT 2011
Fixes a crash on fixed-point stereo voice and some valgrind uninitialized errors
--- a/silk/fixed/silk_noise_shape_analysis_FIX.c
+++ b/silk/fixed/silk_noise_shape_analysis_FIX.c
@@ -308,7 +308,11 @@
if( psEnc->sCmn.warping_Q16 > 0 ) {
/* Adjust gain for warping */
gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder );
+ SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
+ if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
+ psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;
+ }
}
/* Bandwidth expansion for synthesis filter shaping */
--- a/silk/fixed/silk_structs_FIX.h
+++ b/silk/fixed/silk_structs_FIX.h
@@ -65,17 +65,17 @@
/* Encoder state FIX */
/********************************/
typedef struct {
- silk_encoder_state sCmn; /* Common struct, shared with floating-point code */
- silk_shape_state_FIX sShape; /* Shape state */
- silk_prefilter_state_FIX sPrefilt; /* Prefilter State */
+ silk_encoder_state sCmn; /* Common struct, shared with floating-point code */
+ silk_shape_state_FIX sShape; /* Shape state */
+ silk_prefilter_state_FIX sPrefilt; /* Prefilter State */
/* Buffer for find pitch and noise shape analysis */
- SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
- SKP_int LTPCorr_Q15; /* Normalized correlation from pitch lag estimator */
-
+ SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */
+ SKP_int LTPCorr_Q15; /* Normalized correlation from pitch lag estimator */
+
/* Parameters For LTP scaling Control */
- SKP_int prevLTPredCodGain_Q7;
- SKP_int HPLTPredCodGain_Q7;
+ SKP_int prevLTPredCodGain_Q7;
+ SKP_int HPLTPredCodGain_Q7;
} silk_encoder_state_FIX;
/************************/
@@ -115,13 +115,13 @@
/* Encoder Super Struct */
/************************/
typedef struct {
- silk_encoder_state_FIX state_Fxx[ ENCODER_NUM_CHANNELS ];
- stereo_enc_state sStereo;
- SKP_int32 nBitsExceeded;
- SKP_int nChannelsAPI;
- SKP_int nChannelsInternal;
- SKP_int timeSinceSwitchAllowed_ms;
- SKP_int allowBandwidthSwitch;
+ silk_encoder_state_FIX state_Fxx[ ENCODER_NUM_CHANNELS ];
+ stereo_enc_state sStereo;
+ SKP_int32 nBitsExceeded;
+ SKP_int nChannelsAPI;
+ SKP_int nChannelsInternal;
+ SKP_int timeSinceSwitchAllowed_ms;
+ SKP_int allowBandwidthSwitch;
} silk_encoder;
--- a/silk/float/silk_LPC_analysis_filter_FLP.c
+++ b/silk/float/silk_LPC_analysis_filter_FLP.c
@@ -28,12 +28,12 @@
#include <stdlib.h>
#include "silk_main_FLP.h"
-/*******************************************/
-/* LPC analysis filter */
-/* NB! State is kept internally and the */
-/* filter always starts with zero state */
-/* first Order output samples are not set */
-/*******************************************/
+/************************************************/
+/* LPC analysis filter */
+/* NB! State is kept internally and the */
+/* filter always starts with zero state */
+/* first Order output samples are set to zero */
+/************************************************/
/* 16th order LPC analysis filter, does not write first 16 samples */
void silk_LPC_analysis_filter16_FLP(
@@ -233,12 +233,12 @@
}
}
-/*******************************************/
-/* LPC analysis filter */
-/* NB! State is kept internally and the */
-/* filter always starts with zero state */
-/* first Order output samples are not set */
-/*******************************************/
+/************************************************/
+/* LPC analysis filter */
+/* NB! State is kept internally and the */
+/* filter always starts with zero state */
+/* first Order output samples are set to zero */
+/************************************************/
void silk_LPC_analysis_filter_FLP(
SKP_float r_LPC[], /* O LPC residual signal */
@@ -279,5 +279,8 @@
SKP_assert( 0 );
break;
}
+
+ /* Set first Order output samples to zero */
+ SKP_memset( r_LPC, 0, Order * sizeof( SKP_float ) );
}
--- a/silk/float/silk_structs_FLP.h
+++ b/silk/float/silk_structs_FLP.h
@@ -65,17 +65,17 @@
/* Encoder state FLP */
/********************************/
typedef struct {
- silk_encoder_state sCmn; /* Common struct, shared with fixed-point code */
- silk_shape_state_FLP sShape; /* Noise shaping state */
- silk_prefilter_state_FLP sPrefilt; /* Prefilter State */
+ silk_encoder_state sCmn; /* Common struct, shared with fixed-point code */
+ silk_shape_state_FLP sShape; /* Noise shaping state */
+ silk_prefilter_state_FLP sPrefilt; /* Prefilter State */
/* Buffer for find pitch and noise shape analysis */
- SKP_float x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */
- SKP_float LTPCorr; /* Normalized correlation from pitch lag estimator */
+ SKP_float x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */
+ SKP_float LTPCorr; /* Normalized correlation from pitch lag estimator */
/* Parameters for LTP scaling control */
- SKP_float prevLTPredCodGain;
- SKP_float HPLTPredCodGain;
+ SKP_float prevLTPredCodGain;
+ SKP_float HPLTPredCodGain;
} silk_encoder_state_FLP;
/************************/
@@ -113,13 +113,13 @@
/* Encoder Super Struct */
/************************/
typedef struct {
- silk_encoder_state_FLP state_Fxx[ ENCODER_NUM_CHANNELS ];
- stereo_enc_state sStereo;
- SKP_int32 nBitsExceeded;
- SKP_int nChannelsAPI;
- SKP_int nChannelsInternal;
- SKP_int timeSinceSwitchAllowed_ms;
- SKP_int allowBandwidthSwitch;
+ silk_encoder_state_FLP state_Fxx[ ENCODER_NUM_CHANNELS ];
+ stereo_enc_state sStereo;
+ SKP_int32 nBitsExceeded;
+ SKP_int nChannelsAPI;
+ SKP_int nChannelsInternal;
+ SKP_int timeSinceSwitchAllowed_ms;
+ SKP_int allowBandwidthSwitch;
} silk_encoder;
#ifdef __cplusplus
--- a/silk/silk_HP_variable_cutoff.c
+++ b/silk/silk_HP_variable_cutoff.c
@@ -25,6 +25,9 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#ifdef FIXED_POINT
#include "silk_main_FIX.h"
#else
@@ -44,32 +47,41 @@
SKP_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7;
silk_encoder_state *psEncC1 = &state_Fxx[ 0 ].sCmn;
- /*********************************************/
- /* Estimate Low End of Pitch Frequency Range */
- /*********************************************/
- if( psEncC1->prevSignalType == TYPE_VOICED ) {
- /* difference, in log domain */
- pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEncC1->fs_kHz, 1000 ), 16 ), psEncC1->prevLag );
- pitch_freq_log_Q7 = silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 );
+ if( psEncC1->HP_cutoff_Hz == 0 ) {
+ /* Adaptive cutoff frequency: estimate low end of pitch frequency range */
+ if( psEncC1->prevSignalType == TYPE_VOICED ) {
+ /* difference, in log domain */
+ pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEncC1->fs_kHz, 1000 ), 16 ), psEncC1->prevLag );
+ pitch_freq_log_Q7 = silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 );
- /* adjustment based on quality */
- quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ];
- pitch_freq_log_Q7 = SKP_SMLAWB( pitch_freq_log_Q7, SKP_SMULWB( SKP_LSHIFT( -quality_Q15, 2 ), quality_Q15 ),
- pitch_freq_log_Q7 - ( silk_lin2log( SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 16 ) ) - ( 16 << 7 ) ) );
+ /* adjustment based on quality */
+ quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ];
+ pitch_freq_log_Q7 = SKP_SMLAWB( pitch_freq_log_Q7, SKP_SMULWB( SKP_LSHIFT( -quality_Q15, 2 ), quality_Q15 ),
+ pitch_freq_log_Q7 - ( silk_lin2log( SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 16 ) ) - ( 16 << 7 ) ) );
- /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */
- delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEncC1->variable_HP_smth1_Q15, 8 );
- if( delta_freq_Q7 < 0 ) {
- /* less smoothing for decreasing pitch frequency, to track something close to the minimum */
- delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 );
- }
+ /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */
+ delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEncC1->variable_HP_smth1_Q15, 8 );
+ if( delta_freq_Q7 < 0 ) {
+ /* less smoothing for decreasing pitch frequency, to track something close to the minimum */
+ delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 );
+ }
- /* limit delta, to reduce impact of outliers in pitch estimation */
- delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );
+ /* limit delta, to reduce impact of outliers in pitch estimation */
+ delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );
- /* update smoother */
- psEncC1->variable_HP_smth1_Q15 = SKP_SMLAWB( psEncC1->variable_HP_smth1_Q15,
- SKP_SMULBB( psEncC1->speech_activity_Q8, delta_freq_Q7 ), SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );
+ /* update smoother */
+ psEncC1->variable_HP_smth1_Q15 = SKP_SMLAWB( psEncC1->variable_HP_smth1_Q15,
+ SKP_SMULBB( psEncC1->speech_activity_Q8, delta_freq_Q7 ), SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );
+
+ /* limit frequency range */
+ psEncC1->variable_HP_smth1_Q15 = SKP_LIMIT_32( psEncC1->variable_HP_smth1_Q15,
+ SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MIN_CUTOFF_HZ ), 8 ),
+ SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MAX_CUTOFF_HZ ), 8 ) );
+ }
+ } else {
+ /* Externally-controlled cutoff frequency */
+ cutoff_Hz = SKP_LIMIT( psEncC1->HP_cutoff_Hz, 10, 500 );
+ psEncC1->variable_HP_smth1_Q15 = SKP_LSHIFT( silk_lin2log( cutoff_Hz ), 8 );
}
/* second smoother */
@@ -78,9 +90,6 @@
/* convert from log scale to Hertz */
cutoff_Hz = silk_log2lin( SKP_RSHIFT( psEncC1->variable_HP_smth2_Q15, 8 ) );
-
- /* limit frequency range */
- cutoff_Hz = SKP_LIMIT_32( cutoff_Hz, SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 0 ), SILK_FIX_CONST( VARIABLE_HP_MAX_CUTOFF_HZ, 0 ) );
/********************************/
/* Compute Filter Coefficients */
--- a/silk/silk_LPC_analysis_filter.c
+++ b/silk/silk_LPC_analysis_filter.c
@@ -31,7 +31,7 @@
/* LPC analysis filter */
/* NB! State is kept internally and the */
/* filter always starts with zero state */
-/* first Order output samples are not set */
+/* first d output samples are set to zero */
/*******************************************/
void silk_LPC_analysis_filter(
@@ -73,4 +73,7 @@
/* Saturate output */
out[ ix ] = ( SKP_int16 )SKP_SAT16( out32 );
}
+
+ /* Set first d output samples to zero */
+ SKP_memset( out, 0, d * sizeof( SKP_int16 ) );
}
--- a/silk/silk_control.h
+++ b/silk/silk_control.h
@@ -83,6 +83,9 @@
/* I: Flag to use constant bitrate */
SKP_int useCBR;
+ /* I: Cutoff frequency of input HP filter (of zero: adaptive) */
+ SKP_int HP_cutoff_Hz;
+
/* O: Internal sampling rate used, in Hertz; 8000/12000/16000 */
SKP_int32 internalSampleRate;
--- a/silk/silk_control_codec.c
+++ b/silk/silk_control_codec.c
@@ -28,8 +28,6 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-
-#include "silk_tuning_parameters.h"
#ifdef FIXED_POINT
#include "silk_main_FIX.h"
#define silk_encoder_state_Fxx silk_encoder_state_FIX
@@ -37,6 +35,7 @@
#include "silk_main_FLP.h"
#define silk_encoder_state_Fxx silk_encoder_state_FLP
#endif
+#include "silk_tuning_parameters.h"
SKP_int silk_setup_resamplers(
silk_encoder_state_Fxx *psEnc, /* I/O */
--- a/silk/silk_enc_API.c
+++ b/silk/silk_enc_API.c
@@ -25,7 +25,9 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include "silk_define.h"
#include "silk_API.h"
#include "silk_control.h"
@@ -110,6 +112,7 @@
encStatus->useInBandFEC = state_Fxx[ 0 ].sCmn.useInBandFEC;
encStatus->useDTX = state_Fxx[ 0 ].sCmn.useDTX;
encStatus->useCBR = state_Fxx[ 0 ].sCmn.useCBR;
+ encStatus->HP_cutoff_Hz = state_Fxx[ 0 ].sCmn.HP_cutoff_Hz;
encStatus->internalSampleRate = SKP_SMULBB( state_Fxx[ 0 ].sCmn.fs_kHz, 1000 );
encStatus->allowBandwidthSwitch = state_Fxx[ 0 ].sCmn.allow_bandwidth_switch;
encStatus->inWBmodeWithoutVariableLP = state_Fxx[ 0 ].sCmn.fs_kHz == 16 && state_Fxx[ 0 ].sCmn.sLP.mode == 0;
@@ -295,6 +298,7 @@
}
/* High-pass filter */
+ psEnc->state_Fxx[ 0 ].sCmn.HP_cutoff_Hz = encControl->HP_cutoff_Hz;
silk_HP_variable_cutoff( psEnc->state_Fxx, psEnc->nChannelsInternal );
/* Total target bits for packet */
--- a/silk/silk_init_encoder.c
+++ b/silk/silk_init_encoder.c
@@ -25,6 +25,9 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#ifdef FIXED_POINT
#include "silk_main_FIX.h"
#else
@@ -54,5 +57,5 @@
/* Initialize Silk VAD */
ret += silk_VAD_Init( &psEnc->sCmn.sVAD );
- return( ret );
+ return ret;
}
--- a/silk/silk_lin2log.c
+++ b/silk/silk_lin2log.c
@@ -26,7 +26,7 @@
***********************************************************************/
#include "silk_SigProc_FIX.h"
-/* Approximation of 128 * log2() (very close inverse of approx 2^() below) */
+/* Approximation of 128 * log2() (very close inverse of silk_log2lin()) */
/* Convert input to a log scale */
SKP_int32 silk_lin2log( const SKP_int32 inLin ) /* I: Input in linear scale */
{
@@ -35,6 +35,6 @@
silk_CLZ_FRAC( inLin, &lz, &frac_Q7 );
/* Piece-wise parabolic approximation */
- return( SKP_LSHIFT( 31 - lz, 7 ) + SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 ) );
+ return SKP_LSHIFT( 31 - lz, 7 ) + SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 );
}
--- a/silk/silk_structs.h
+++ b/silk/silk_structs.h
@@ -135,6 +135,7 @@
SKP_int32 In_HP_State[ 2 ]; /* High pass filter state */
SKP_int32 variable_HP_smth1_Q15; /* State of first smoother */
SKP_int32 variable_HP_smth2_Q15; /* State of second smoother */
+ SKP_int HP_cutoff_Hz; /* Fixed cutoff frequency (if zero: adaptive) */
silk_LP_state sLP; /* Low pass filter state */
silk_VAD_state sVAD; /* Voice activity detector state */
silk_nsq_state sNSQ; /* Noise Shape Quantizer State */
--- a/silk/silk_tuning_parameters.h
+++ b/silk/silk_tuning_parameters.h
@@ -75,8 +75,8 @@
#define VARIABLE_HP_MAX_DELTA_FREQ 0.4f
/* Min and max cut-off frequency values (-3 dB points) */
-#define VARIABLE_HP_MIN_CUTOFF_HZ 60.0f
-#define VARIABLE_HP_MAX_CUTOFF_HZ 100.0f
+#define VARIABLE_HP_MIN_CUTOFF_HZ 60
+#define VARIABLE_HP_MAX_CUTOFF_HZ 100
/***********/
/* Various */