Commit 606cc10f authored by Koen Vos's avatar Koen Vos Committed by Jean-Marc Valin
Browse files

Big SILK update

parent 446b7f3f
......@@ -6,18 +6,23 @@ AM_CPPFLAGS = $(AM_CFLAGS)
INCLUDES = -I$(top_srcdir)/src_FLP -I$(top_srcdir)/src_SigProc_FIX -I$(top_srcdir)/src_SigProc_FLP -I$(top_srcdir)/src_common -I$(top_srcdir)/interface -I$(top_srcdir)/../celt/libcelt
EXTRA_DIST = Silk_FLP.sln \
Silk_FLP.sln \
src_FIX/Silk_FIX.vcproj \
src_FLP/Silk_FLP.vcproj \
src_common/Silk_Common.vcproj \
src_common/Silk_CommonFLP.vcproj \
src_FIX/src_FIX.vcxproj \
src_FIX/src_FIX.vcxproj.filters \
src_FLP/src_FLP.vcxproj \
src_FLP/src_FLP.vcxproj.filters \
src_common/src_common.vcxproj \
src_common/src_common.vcxproj.filters \
test/Encoder.c \
test/Enc_SDK.vcproj \
test/Decoder.c \
test/Dec_SDK.vcproj \
test/signalCompare.c \
test/SignalCompare.vcproj \
src_SigProc_FLP/SigProc_FLP.vcproj \
src_SigProc_FIX/SigProc_FIX.vcproj
src_SigProc_FLP/src_SigProc_FLP.vcxproj \
src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters \
src_SigProc_FIX/src_SigProc_FIX.vcxproj \
src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters \
test_silk_dec/test_silk_dec.vcxproj \
test_silk_dec/test_silk_dec.vcxproj.filters \
test_silk_enc/test_silk_enc.vcxproj \
test_silk_enc/test_silk_enc.vcxproj.filters
lib_LTLIBRARIES = libSKP_SILK_SDK.la
libSKP_SILK_SDK_la_SOURCES = src_common/SKP_Silk_CNG.c \
......@@ -56,9 +61,10 @@ src_common/SKP_Silk_tables_other.c \
src_common/SKP_Silk_tables_pitch_lag.c \
src_common/SKP_Silk_tables_pulses_per_block.c \
src_common/SKP_Silk_tables_sign.c \
src_common/SKP_Silk_tables_type_offset.c \
src_common/SKP_Silk_VAD.c \
src_common/SKP_Silk_control_audio_bandwidth.c \
src_common/SKP_Silk_quant_LTP_gains.c \
src_common/SKP_Silk_VQ_WMat_EC.c \
src_FLP/SKP_Silk_apply_sine_window_FLP.c \
src_FLP/SKP_Silk_control_codec_FLP.c \
src_FLP/SKP_Silk_corrMatrix_FLP.c \
......@@ -81,16 +87,9 @@ src_FLP/SKP_Silk_noise_shape_analysis_FLP.c \
src_FLP/SKP_Silk_prefilter_FLP.c \
src_FLP/SKP_Silk_process_gains_FLP.c \
src_FLP/SKP_Silk_process_NLSFs_FLP.c \
src_FLP/SKP_Silk_quant_LTP_gains_FLP.c \
src_FLP/SKP_Silk_regularize_correlations_FLP.c \
src_FLP/SKP_Silk_residual_energy_FLP.c \
src_FLP/SKP_Silk_solve_LS_FLP.c \
src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c \
src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c \
src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c \
src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c \
src_FLP/SKP_Silk_tables_other_FLP.c \
src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c \
src_FLP/SKP_Silk_warped_autocorrelation_FLP.c \
src_FLP/SKP_Silk_wrappers_FLP.c \
src_SigProc_FIX/SKP_Silk_A2NLSF.c \
......@@ -177,21 +176,14 @@ src_common/SKP_Silk_perceptual_parameters.h \
src_common/SKP_Silk_PLC.h \
src_common/SKP_Silk_structs.h \
src_common/SKP_Silk_tables.h \
src_common/SKP_Silk_tables_NLSF_CB0_10.h \
src_common/SKP_Silk_tables_NLSF_CB0_16.h \
src_common/SKP_Silk_tables_NLSF_CB1_10.h \
src_common/SKP_Silk_tables_NLSF_CB1_16.h \
src_common/SKP_Silk_tables_NLSF_CB.h \
src_common/SKP_Silk_tuning_parameters.h \
src_common/SKP_Silk_setup_complexity.h \
src_FIX/SKP_Silk_define_FIX.h \
src_FIX/SKP_Silk_main_FIX.h \
src_FIX/SKP_Silk_perceptual_parameters_FIX.h \
src_FIX/SKP_Silk_structs_FIX.h \
src_FLP/SKP_Silk_assembler_FLP.h \
src_FLP/SKP_Silk_define_FLP.h \
src_FLP/SKP_Silk_main_FLP.h \
src_FLP/SKP_Silk_structs_FLP.h \
src_FLP/SKP_Silk_tables_FLP.h \
src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h \
src_SigProc_FIX/SKP_Silk_Inlines.h \
src_SigProc_FIX/SKP_Silk_MacroCount.h \
......@@ -202,19 +194,18 @@ src_SigProc_FIX/SKP_Silk_resampler_private.h \
src_SigProc_FIX/SKP_Silk_resampler_rom.h \
src_SigProc_FIX/SKP_Silk_resampler_structs.h \
src_SigProc_FIX/SKP_Silk_SigProc_FIX.h \
src_SigProc_FLP/SKP_Silk_pitch_est_defines_FLP.h \
src_SigProc_FLP/SKP_Silk_SigProc_FLP.h
bin_PROGRAMS = Encoder Decoder signalCompare
Encoder_SOURCES = test/Encoder.c test/SKP_debug.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
Encoder_SOURCES = test/Encoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
Encoder_LDADD = $(lib_LTLIBRARIES)
Encoder_LDFLAGS = $(LIBS)
Decoder_SOURCES = test/Decoder.c test/SKP_debug.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
Decoder_SOURCES = test/Decoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
Decoder_LDADD = $(lib_LTLIBRARIES)
Decoder_LDFLAGS = $(LIBS)
signalCompare_SOURCES = test/signalCompare.c test/SKP_debug.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
signalCompare_SOURCES = test/signalCompare.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
signalCompare_LDADD = $(lib_LTLIBRARIES)
signalCompare_LDFLAGS = $(LIBS)
......
......@@ -118,7 +118,7 @@ SKP_int SKP_Silk_SDK_Decode( /* O: Returns error co
ec_dec *psRangeDec, /* I/O Compressor data structure */
const SKP_int nBytesIn, /* I: Number of input bytes */
SKP_int16 *samplesOut, /* O: Decoded output speech vector */
SKP_int32 *nSamplesOut /* I/O: Number of samples (vector/decoded) */
SKP_int32 *nSamplesOut /* O: Number of samples decoded */
);
/***************************************************************/
......
......@@ -254,24 +254,50 @@ extern SKP_int64 SKP_Timer_depth[SKP_NUM_TIMERS_MAX];
/************************************/
/* opens an empty file if this file has not yet been open, then writes to the file and closes it */
/* if file has been open previously it is opened again and the fwrite is appending, finally it is closed */
#define SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES) { static SKP_int32 init = 0;FILE *fp;if (init == 0) {init = 1;fp = fopen(#FILE_NAME, "wb");}else {fp = fopen(#FILE_NAME, "ab+");} fwrite((DATA_PTR), (N_BYTES), 1, fp);fclose(fp);}
#define SAVE_DATA( FILE_NAME, DATA_PTR, N_BYTES ) { \
static SKP_int32 init = 0; \
FILE *fp; \
if (init == 0) { \
init = 1; \
fp = fopen(#FILE_NAME, "wb"); \
} else { \
fp = fopen(#FILE_NAME, "ab+"); \
} \
fwrite((DATA_PTR), (N_BYTES), 1, fp); \
fclose(fp); \
}
/* Example: DEBUG_STORE_DATA(testfile.pcm, &RIN[0], 160*sizeof(SKP_int16)); */
#if 0
/* Ensure that everything is written to files when an assert breaks */
#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES)
#define DEBUG_STORE_CLOSE_FILES
#else
#define SKP_NUM_STORES_MAX 100
extern FILE *SKP_debug_store_fp[ SKP_NUM_STORES_MAX ];
extern int SKP_debug_store_count;
/* Faster way of storing the data */
#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) { \
static SKP_int32 init = 0; \
static FILE *fp; \
if (init == 0) \
{ \
init = 1; \
fp = fopen(#FILE_NAME, "wb"); \
} \
fwrite((DATA_PTR), (N_BYTES), 1, fp); \
#define DEBUG_STORE_DATA( FILE_NAME, DATA_PTR, N_BYTES ) { \
static SKP_int init = 0, cnt = 0; \
static FILE **fp; \
if (init == 0) { \
init = 1; \
cnt = SKP_debug_store_count++; \
SKP_debug_store_fp[ cnt ] = fopen(#FILE_NAME, "wb"); \
} \
fwrite((DATA_PTR), (N_BYTES), 1, SKP_debug_store_fp[ cnt ]); \
}
/* Call this at the end of main() */
#define DEBUG_STORE_CLOSE_FILES { \
SKP_int i; \
for( i = 0; i < SKP_debug_store_count; i++ ) { \
fclose( SKP_debug_store_fp[ i ] ); \
} \
}
#endif
......@@ -283,6 +309,7 @@ extern SKP_int64 SKP_Timer_depth[SKP_NUM_TIMERS_MAX];
/* define macros as empty strings */
#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES)
#define SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES)
#define DEBUG_STORE_CLOSE_FILES
#endif /* SKP_DEBUG */
......
......@@ -34,11 +34,6 @@ SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
SKP_int fs_kHz /* I */
);
SKP_INLINE SKP_int SKP_Silk_setup_packetsize(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int PacketSize_ms /* I */
);
SKP_INLINE SKP_int SKP_Silk_setup_fs(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int fs_kHz, /* I */
......@@ -141,40 +136,6 @@ void SKP_Silk_LBRR_ctrl_FIX(
}
}
SKP_INLINE SKP_int SKP_Silk_setup_packetsize(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int PacketSize_ms /* I */
)
{
SKP_int ret = SKP_SILK_NO_ERROR;
if( ( PacketSize_ms != 10 ) &&
( PacketSize_ms != 20 ) &&
( PacketSize_ms != 40 ) &&
( PacketSize_ms != 60 ) ) {
ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
} else {
if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) {
if( PacketSize_ms == 10 ) {
/* Only allowed when the payload buffer is empty */
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
psEnc->sCmn.PacketSize_ms = PacketSize_ms;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, psEnc->sCmn.fs_kHz );
/* Packet length changes. Reset LBRR buffer */
SKP_Silk_LBRR_reset( &psEnc->sCmn );
} else{
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;
psEnc->sCmn.PacketSize_ms = PacketSize_ms;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, psEnc->sCmn.fs_kHz );
/* Packet length changes. Reset LBRR buffer */
SKP_Silk_LBRR_reset( &psEnc->sCmn );
}
}
psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );
}
return(ret);
}
SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int fs_kHz /* I */
......@@ -235,16 +196,37 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
{
SKP_int ret = SKP_SILK_NO_ERROR;
/* Set packet size */
if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) {
if( ( PacketSize_ms != 10 ) &&
( PacketSize_ms != 20 ) &&
( PacketSize_ms != 40 ) &&
( PacketSize_ms != 60 ) ) {
ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
}
if( PacketSize_ms == 10 ) {
/* Only allowed when the payload buffer is empty */
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
} else {
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
}
/* Packet length changes. Reset LBRR buffer */
SKP_Silk_LBRR_reset( &psEnc->sCmn );
psEnc->sCmn.PacketSize_ms = PacketSize_ms;
}
/* Set internal sampling frequency */
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
#if SWITCH_TRANSITION_FILTERING
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
if( psEnc->sCmn.sLP.mode == 1 ) {
......@@ -278,46 +260,68 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;
psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;
if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;
} else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
} else {
/* Unsupported number of frames */
SKP_assert( 0 );
}
} else {
psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;
psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
} else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
} else {
/* Unsupported number of frames */
SKP_assert( 0 );
}
}
psEnc->sCmn.subfr_length = SKP_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz );
psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz;
psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );
psEnc->sCmn.ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz );
psEnc->sCmn.la_pitch = SKP_SMULBB( LA_PITCH_MS, fs_kHz );
psEnc->sPred.min_pitch_lag = SKP_SMULBB( 3, fs_kHz );
psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
} else {
} else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
} else {
/* Unsupported number of frames */
SKP_assert( 0 );
}
if( psEnc->sCmn.fs_kHz == 24 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 8 );
psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX;
psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS;
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 10 );
psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX;
psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform12_iCDF;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 8 );
psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS;
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 10 );
psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform8_iCDF;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 8 );
psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 10 );
psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;
} else if( psEnc->sCmn.fs_kHz == 8 ) {
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 10 );
psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = 0;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;
} else {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 8 );
psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = 0;
/* unsupported sampling rate */
SKP_assert( 0 );
}
psEnc->sCmn.fs_kHz_changed = 1;
}
/********************************************/
/* Set packet size */
/********************************************/
ret += SKP_Silk_setup_packetsize( psEnc, PacketSize_ms );
/* Check that settings are valid */
SKP_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length );
......@@ -329,9 +333,9 @@ SKP_INLINE SKP_int SKP_Silk_setup_rate(
SKP_int TargetRate_bps /* I */
)
{
SKP_int k, ret = 0;
SKP_int k, ret = SKP_SILK_NO_ERROR;
SKP_int32 frac_Q6;
const SKP_int32 *rateTable;
const SKP_uint16 *rateTable;
/* Set bitrate/coding quality */
if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {
......
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, (subject to the limitations in the disclaimer below)
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Skype Limited, nor the names of specific
contributors, may be used to endorse or promote products derived from
this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#ifndef SKP_SILK_DEFINE_FIX_H
#define SKP_SILK_DEFINE_FIX_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Head room for correlations */
#define LTP_CORRS_HEAD_ROOM 2
#define LPC_CORRS_HEAD_ROOM 10
#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES_Q8 179 // 179.2_Q8 = 0.7f required speech activity for counting frame as active
/* DTX settings */
#define SPEECH_ACTIVITY_DTX_THRES_Q8 26 // 25.60_Q8 = 0.1f
#define LBRR_SPEECH_ACTIVITY_THRES_Q8 128
/* level of noise floor for whitening filter LPC analysis in pitch analysis */
#define FIND_PITCH_WHITE_NOISE_FRACTION_Q16 66
/* bandwdith expansion for whitening filter in pitch analysis */
#define FIND_PITCH_BANDWITH_EXPANSION_Q16 64881
/* Threshold used by pitch estimator for early escape */
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_HC_MODE 45875 // 0.7
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_MC_MODE 49152 // 0.75
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_LC_MODE 52429 // 0.8
/* Regualarization factor for correlation matrix. Equivalent to adding noise at -50 dB */
#define FIND_LTP_COND_FAC_Q31 21475
#define FIND_LPC_COND_FAC_Q32 257698 // 6e-5
/* Find Pred Coef defines */
#define INACTIVE_BWExp_Q16 64225 // 0.98
#define ACTIVE_BWExp_Q16 65470 // 0.999
#define LTP_DAMPING_Q16 66
#define LTP_SMOOTHING_Q26 6710886
/* LTP quantization settings */
#define MU_LTP_QUANT_NB_Q8 8
#define MU_LTP_QUANT_MB_Q8 6
#define MU_LTP_QUANT_WB_Q8 5
#define MU_LTP_QUANT_SWB_Q8 4
/***********************/
/* High pass filtering */
/***********************/
/* Smoothing parameters for low end of pitch frequency range estimation */
#define VARIABLE_HP_SMTH_COEF1_Q16 6554 // 0.1
#define VARIABLE_HP_SMTH_COEF2_Q16 983 // 0.015
/* Min and max values for low end of pitch frequency range estimation */
#define VARIABLE_HP_MIN_FREQ_Q0 80
#define VARIABLE_HP_MAX_FREQ_Q0 150
/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */
#define VARIABLE_HP_MAX_DELTA_FREQ_Q7 51 // 0.4 in Q7
#ifdef __cplusplus
}
#endif
#endif
......@@ -46,7 +46,6 @@ SKP_int SKP_Silk_encode_frame_FIX(
SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ];
SKP_int16 res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
SKP_int LBRR_idx, frame_terminator, SNR_dB_Q7;
const SKP_uint16 *FrameTermination_CDF;
/* Low bitrate redundancy parameters */
SKP_uint8 LBRRpayload[ MAX_ARITHM_BYTES ];
......@@ -115,7 +114,7 @@ TOC(PREFILTER)
/* Find linear prediction coefficients (LPC + LTP) */
/***************************************************/
TIC(FIND_PRED_COEF)
SKP_Silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch );
SKP_Silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame );
TOC(FIND_PRED_COEF)
/****************************************/
......@@ -133,7 +132,7 @@ TOC(PROCESS_GAINS)
/****************************************/
nBytesLBRR = MAX_ARITHM_BYTES;
TIC(LBRR)
SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
//SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
TOC(LBRR)
/*****************************************/
......@@ -186,7 +185,6 @@ TOC(NSQ)
/****************************************/
TIC(ENCODE_PARAMS)
SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc );
FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;
TOC(ENCODE_PARAMS)
/****************************************/
......@@ -220,8 +218,7 @@ TOC(ENCODE_PARAMS)
frame_terminator = SKP_SILK_NO_LBRR;
/* Add the frame termination info to stream */
ec_encode_bin( psRangeEnc, FrameTermination_CDF[ frame_terminator ],
FrameTermination_CDF[ frame_terminator + 1 ], 16 );
ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_FrameTermination_iCDF, 8 );
/* Code excitation signal */
for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) {
......@@ -316,7 +313,6 @@ TOC(ENCODE_FRAME)
int i;
DEBUG_STORE_DATA( xf.dat, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
DEBUG_STORE_DATA( xfw.dat, xfw, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
// DEBUG_STORE_DATA( q.dat, &psEnc->sCmn.q[ ( psEnc->sCmn.nFramesInPayloadBuf - 1)*psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length * sizeof( SKP_int8 ) );
DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.sCmn.pitchL, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) );
for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {
tmp[ i ] = (SKP_float)sEncCtrl.LTPCoef_Q14[ i ] / 16384.0f;
......@@ -471,8 +467,7 @@ void SKP_Silk_LBRR_encode_FIX(
frame_terminator = SKP_SILK_LAST_FRAME;
/* Add the frame termination info to stream */
ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ],
FrameTermination_CDF[ frame_terminator + 1 ], 16 );
ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_FrameTermination_iCDF, 8 );
/*********************************************/
/* Encode quantization indices of excitation */
......@@ -512,8 +507,7 @@ void SKP_Silk_LBRR_encode_FIX(
/* Encode that more frames follows */
frame_terminator = SKP_SILK_MORE_FRAMES;
ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ],
FrameTermination_CDF[ frame_terminator + 1 ], 16 );
ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_FrameTermination_iCDF, 8 );
}
/* Restore original Gains */
......
......@@ -82,7 +82,7 @@ void SKP_Silk_find_pitch_lags_FIX(
SKP_Silk_autocorr( auto_corr, &scale, Wsig, psPredSt->pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 );
/* Add white noise, as fraction of energy */
auto_corr[ 0 ] = SKP_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );
auto_corr[ 0 ] = SKP_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) ) + 1;
/* Calculate the reflection coefficients using schur */
res_nrg = SKP_Silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
......
......@@ -54,10 +54,16 @@ double SKP_Silk_energy_FLP(
/* integer to floating-point conversion */
SKP_INLINE void SKP_short2float_array(
SKP_float *out,
const SKP_int16 *in,
SKP_int32 length
);
SKP_float *out,
const SKP_int16 *in,
SKP_int32 length
)
{
SKP_int32 k;
for (k = length-1; k >= 0; k--) {
out[k] = (SKP_float)in[k];
}
}
SKP_INLINE SKP_float SKP_Silk_log2( double x ) { return ( SKP_float )( 3.32192809488736 * log10( x ) ); }
......@@ -66,7 +72,8 @@ SKP_INLINE SKP_float SKP_Silk_log2( double x ) { return ( SKP_float )( 3.3219280
void SKP_Silk_find_pred_coefs_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
const SKP_int16 res_pitch[] /* I Residual from pitch analysis */
const SKP_int16 res_pitch[], /* I Residual from pitch analysis */
const SKP_int16 x[] /* I Speech signal */
)
{
SKP_int i;
......@@ -126,8 +133,8 @@ void SKP_Silk_find_pred_coefs_FIX(
#endif
/* Quantize LTP gain parameters */
SKP_Silk_quant_LTP_gains_FIX( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex,
WLTP, psEnc->mu_LTP_Q8, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr);
SKP_Silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex,
WLTP, psEnc->sCmn.mu_LTP_Q10, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr);
/* Control LTP scaling */
SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl );
......@@ -141,7 +148,7 @@ void SKP_Silk_find_pred_coefs_FIX(
/* UNVOICED */
/************/
/* Create signal with prepended subframes, scaled by inverse gains */
x_ptr = psEnc->x_buf + psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder;
x_ptr = x - psEnc->sCmn.predictLPCOrder;
x_pre_ptr = LPC_in_pre;
for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
SKP_Silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ],
......