From 485d64dfdf4145bf45929c697cdb2b3eed9c91c1 Mon Sep 17 00:00:00 2001 From: Koen Vos <koen.vos@skype.net> Date: Mon, 14 Feb 2011 14:21:57 -0500 Subject: [PATCH] SILK update with LBRR and some bugfixes --- Makefile.am | 13 +- interface/SKP_Silk_SDK_API.h | 22 +- interface/SKP_Silk_control.h | 16 +- interface/SKP_Silk_errors.h | 6 +- interface/SKP_Silk_typedef.h | 2 +- interface/SKP_debug.h | 2 +- src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c | 2 +- src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c | 2 +- src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c | 20 +- src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c | 40 +- .../SKP_Silk_NLSF_VQ_rate_distortion_FIX.c | 4 +- src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c | 10 +- src_FIX/SKP_Silk_control_codec_FIX.c | 106 ++---- src_FIX/SKP_Silk_corrMatrix_FIX.c | 2 +- src_FIX/SKP_Silk_encode_frame_FIX.c | 353 ++++++------------ src_FIX/SKP_Silk_find_LPC_FIX.c | 10 +- src_FIX/SKP_Silk_find_LTP_FIX.c | 2 +- src_FIX/SKP_Silk_find_pitch_lags_FIX.c | 23 +- src_FIX/SKP_Silk_find_pred_coefs_FIX.c | 322 +--------------- src_FIX/SKP_Silk_init_encoder_FIX.c | 6 +- src_FIX/SKP_Silk_main_FIX.h | 20 +- src_FIX/SKP_Silk_noise_shape_analysis_FIX.c | 30 +- src_FIX/SKP_Silk_prefilter_FIX.c | 8 +- src_FIX/SKP_Silk_process_NLSFs_FIX.c | 20 +- src_FIX/SKP_Silk_process_gains_FIX.c | 16 +- .../SKP_Silk_regularize_correlations_FIX.c | 2 +- src_FIX/SKP_Silk_residual_energy16_FIX.c | 2 +- src_FIX/SKP_Silk_residual_energy_FIX.c | 6 +- src_FIX/SKP_Silk_solve_LS_FIX.c | 2 +- src_FIX/SKP_Silk_structs_FIX.h | 11 +- src_FIX/SKP_Silk_warped_autocorrelation_FIX.c | 2 +- src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c | 2 +- src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c | 26 +- src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c | 2 +- src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c | 21 +- src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c | 10 +- src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c | 24 +- .../SKP_Silk_NLSF_VQ_rate_distortion_FLP.c | 2 +- src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c | 2 +- src_FLP/SKP_Silk_apply_sine_window_FLP.c | 2 +- src_FLP/SKP_Silk_assembler_FLP.h | 2 +- src_FLP/SKP_Silk_control_codec_FLP.c | 105 ++---- src_FLP/SKP_Silk_corrMatrix_FLP.c | 2 +- src_FLP/SKP_Silk_encode_frame_FLP.c | 316 ++++++---------- src_FLP/SKP_Silk_find_LPC_FLP.c | 6 +- src_FLP/SKP_Silk_find_LTP_FLP.c | 2 +- src_FLP/SKP_Silk_find_pitch_lags_FLP.c | 19 +- src_FLP/SKP_Silk_find_pred_coefs_FLP.c | 18 +- src_FLP/SKP_Silk_init_encoder_FLP.c | 6 +- src_FLP/SKP_Silk_main_FLP.h | 29 +- src_FLP/SKP_Silk_noise_shape_analysis_FLP.c | 24 +- src_FLP/SKP_Silk_prefilter_FLP.c | 8 +- src_FLP/SKP_Silk_process_NLSFs_FLP.c | 12 +- src_FLP/SKP_Silk_process_gains_FLP.c | 16 +- .../SKP_Silk_regularize_correlations_FLP.c | 2 +- src_FLP/SKP_Silk_residual_energy_FLP.c | 2 +- src_FLP/SKP_Silk_solve_LS_FLP.c | 2 +- src_FLP/SKP_Silk_structs_FLP.h | 9 +- src_FLP/SKP_Silk_warped_autocorrelation_FLP.c | 2 +- src_FLP/SKP_Silk_wrappers_FLP.c | 53 +-- src_FLP/src_FLP.vcxproj | 1 - src_FLP/src_FLP.vcxproj.filters | 3 - src_SigProc_FIX/SKP_Silk_A2NLSF.c | 2 +- src_SigProc_FIX/SKP_Silk_Inlines.h | 2 +- .../SKP_Silk_LPC_analysis_filter.c | 79 ++++ src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c | 2 +- src_SigProc_FIX/SKP_Silk_LPC_stabilize.c | 2 +- .../SKP_Silk_LPC_synthesis_filter.c | 2 +- .../SKP_Silk_LPC_synthesis_order16.c | 2 +- src_SigProc_FIX/SKP_Silk_LSF_cos_table.c | 2 +- src_SigProc_FIX/SKP_Silk_MA.c | 167 --------- src_SigProc_FIX/SKP_Silk_MacroCount.h | 27 ++ src_SigProc_FIX/SKP_Silk_MacroDebug.h | 27 ++ src_SigProc_FIX/SKP_Silk_NLSF2A.c | 2 +- .../SKP_Silk_NLSF_VQ_weights_laroia.c | 2 +- src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c | 2 +- src_SigProc_FIX/SKP_Silk_SigProc_FIX.h | 67 ++-- src_SigProc_FIX/SKP_Silk_allpass_int.c | 2 +- src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c | 2 +- src_SigProc_FIX/SKP_Silk_apply_sine_window.c | 2 +- src_SigProc_FIX/SKP_Silk_array_maxabs.c | 2 +- src_SigProc_FIX/SKP_Silk_autocorr.c | 2 +- src_SigProc_FIX/SKP_Silk_biquad_alt.c | 2 +- src_SigProc_FIX/SKP_Silk_burg_modified.c | 2 +- src_SigProc_FIX/SKP_Silk_bwexpander.c | 2 +- src_SigProc_FIX/SKP_Silk_bwexpander_32.c | 2 +- .../SKP_Silk_common_pitch_est_defines.h | 89 ----- src_SigProc_FIX/SKP_Silk_debug.c | 175 +++++++++ src_SigProc_FIX/SKP_Silk_decode_pitch.c | 6 +- src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c | 2 +- src_SigProc_FIX/SKP_Silk_k2a.c | 2 +- src_SigProc_FIX/SKP_Silk_k2a_Q16.c | 2 +- src_SigProc_FIX/SKP_Silk_lin2log.c | 2 +- src_SigProc_FIX/SKP_Silk_log2lin.c | 2 +- src_SigProc_FIX/SKP_Silk_lowpass_int.c | 2 +- src_SigProc_FIX/SKP_Silk_lowpass_short.c | 2 +- src_SigProc_FIX/SKP_Silk_macros.h | 2 +- .../SKP_Silk_pitch_analysis_core.c | 42 +-- src_SigProc_FIX/SKP_Silk_pitch_est_defines.h | 4 +- src_SigProc_FIX/SKP_Silk_pitch_est_tables.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_down2.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_down2_3.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_down3.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_private.h | 2 +- .../SKP_Silk_resampler_private_AR2.c | 2 +- .../SKP_Silk_resampler_private_ARMA4.c | 2 +- .../SKP_Silk_resampler_private_IIR_FIR.c | 2 +- .../SKP_Silk_resampler_private_copy.c | 2 +- .../SKP_Silk_resampler_private_down4.c | 2 +- .../SKP_Silk_resampler_private_down_FIR.c | 2 +- .../SKP_Silk_resampler_private_up2_HQ.c | 2 +- .../SKP_Silk_resampler_private_up4.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_rom.c | 2 +- src_SigProc_FIX/SKP_Silk_resampler_rom.h | 2 +- src_SigProc_FIX/SKP_Silk_resampler_structs.h | 2 +- src_SigProc_FIX/SKP_Silk_resampler_up2.c | 2 +- .../SKP_Silk_scale_copy_vector16.c | 2 +- src_SigProc_FIX/SKP_Silk_scale_vector.c | 2 +- src_SigProc_FIX/SKP_Silk_schur.c | 2 +- src_SigProc_FIX/SKP_Silk_schur64.c | 2 +- src_SigProc_FIX/SKP_Silk_sigm_Q15.c | 2 +- src_SigProc_FIX/SKP_Silk_sort.c | 2 +- src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c | 2 +- src_SigProc_FIX/src_SigProc_FIX.vcxproj | 3 +- .../src_SigProc_FIX.vcxproj.filters | 9 +- .../SKP_Silk_LPC_inv_pred_gain_FLP.c | 2 +- .../SKP_Silk_NLSF_VQ_weights_laroia_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_SigProc_FLP.h | 57 +-- src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c | 68 ---- .../SKP_Silk_autocorrelation_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c | 2 +- .../SKP_Silk_decimate2_coarse_FLP.c | 72 ---- .../SKP_Silk_decimate2_coarsest_FLP.c | 70 ---- src_SigProc_FLP/SKP_Silk_energy_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_inner_product_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_k2a_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c | 2 +- .../SKP_Silk_pitch_analysis_core_FLP.c | 93 ++--- .../SKP_Silk_scale_copy_vector_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_schur_FLP.c | 2 +- src_SigProc_FLP/SKP_Silk_sort_FLP.c | 2 +- src_SigProc_FLP/src_SigProc_FLP.vcxproj | 3 - .../src_SigProc_FLP.vcxproj.filters | 9 - src_common/SKP_Silk_CNG.c | 6 +- .../SKP_Silk_LBRR_embed.c | 64 ++-- src_common/SKP_Silk_LP_variable_cutoff.c | 10 +- src_common/SKP_Silk_NLSF2A_stable.c | 2 +- src_common/SKP_Silk_NLSF_MSVQ_decode.c | 41 +- src_common/SKP_Silk_NSQ.c | 88 +++-- src_common/SKP_Silk_NSQ_del_dec.c | 169 ++++----- src_common/SKP_Silk_PLC.c | 6 +- src_common/SKP_Silk_PLC.h | 2 +- src_common/SKP_Silk_VAD.c | 2 +- src_common/SKP_Silk_VQ_WMat_EC.c | 6 +- src_common/SKP_Silk_code_signs.c | 12 +- src_common/SKP_Silk_control_audio_bandwidth.c | 2 +- src_common/SKP_Silk_create_init_destroy.c | 2 +- src_common/SKP_Silk_dec_API.c | 150 ++------ src_common/SKP_Silk_decode_core.c | 40 +- src_common/SKP_Silk_decode_frame.c | 114 ++++-- src_common/SKP_Silk_decode_indices.c | 202 +++++----- src_common/SKP_Silk_decode_parameters.c | 57 +-- src_common/SKP_Silk_decode_pulses.c | 24 +- src_common/SKP_Silk_decoder_set_fs.c | 4 +- src_common/SKP_Silk_define.h | 30 +- src_common/SKP_Silk_enc_API.c | 21 +- src_common/SKP_Silk_encode_indices.c | 106 ++++-- src_common/SKP_Silk_encode_pulses.c | 46 +-- src_common/SKP_Silk_gain_quant.c | 10 +- src_common/SKP_Silk_interpolate.c | 2 +- src_common/SKP_Silk_main.h | 124 +++--- src_common/SKP_Silk_pulses_to_bytes.c | 82 ---- src_common/SKP_Silk_quant_LTP_gains.c | 14 +- ...lk_setup_complexity.h => SKP_Silk_setup.h} | 35 +- src_common/SKP_Silk_shell_coder.c | 2 +- src_common/SKP_Silk_structs.h | 164 +++----- src_common/SKP_Silk_tables.h | 22 +- src_common/SKP_Silk_tables_LTP.c | 2 +- src_common/SKP_Silk_tables_NLSF_CB.h | 2 +- src_common/SKP_Silk_tables_NLSF_CB0_10.c | 3 +- src_common/SKP_Silk_tables_NLSF_CB0_16.c | 3 +- src_common/SKP_Silk_tables_NLSF_CB1_10.c | 3 +- src_common/SKP_Silk_tables_NLSF_CB1_16.c | 3 +- src_common/SKP_Silk_tables_gain.c | 2 +- src_common/SKP_Silk_tables_other.c | 72 ++-- src_common/SKP_Silk_tables_pitch_lag.c | 2 +- src_common/SKP_Silk_tables_pulses_per_block.c | 2 +- src_common/SKP_Silk_tuning_parameters.h | 12 +- src_common/src_common.vcxproj | 4 +- src_common/src_common.vcxproj.filters | 10 +- test/Decoder.c | 14 +- test/Encoder.c | 2 +- test/signalCompare.c | 2 +- 196 files changed, 1812 insertions(+), 2996 deletions(-) create mode 100644 src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c delete mode 100644 src_SigProc_FIX/SKP_Silk_MA.c delete mode 100644 src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h create mode 100644 src_SigProc_FIX/SKP_Silk_debug.c delete mode 100644 src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c delete mode 100644 src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c delete mode 100644 src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c rename src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c => src_common/SKP_Silk_LBRR_embed.c (53%) delete mode 100644 src_common/SKP_Silk_pulses_to_bytes.c rename src_common/{SKP_Silk_setup_complexity.h => SKP_Silk_setup.h} (82%) diff --git a/Makefile.am b/Makefile.am index 6556ee8c4..b2ce42cfc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,13 +40,13 @@ src_common/SKP_Silk_encode_indices.c \ src_common/SKP_Silk_encode_pulses.c \ src_common/SKP_Silk_gain_quant.c \ src_common/SKP_Silk_interpolate.c \ +src_common/SKP_Silk_LBRR_embed.c \ src_common/SKP_Silk_LP_variable_cutoff.c \ src_common/SKP_Silk_NLSF2A_stable.c \ src_common/SKP_Silk_NLSF_MSVQ_decode.c \ src_common/SKP_Silk_NSQ.c \ src_common/SKP_Silk_NSQ_del_dec.c \ src_common/SKP_Silk_PLC.c \ -src_common/SKP_Silk_pulses_to_bytes.c \ src_common/SKP_Silk_shell_coder.c \ src_common/SKP_Silk_tables_gain.c \ src_common/SKP_Silk_tables_LTP.c \ @@ -78,7 +78,6 @@ src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c \ src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c \ src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c \ src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c \ -src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c \ src_FLP/SKP_Silk_noise_shape_analysis_FLP.c \ src_FLP/SKP_Silk_prefilter_FLP.c \ src_FLP/SKP_Silk_process_gains_FLP.c \ @@ -98,6 +97,7 @@ src_SigProc_FIX/SKP_Silk_biquad_alt.c \ src_SigProc_FIX/SKP_Silk_burg_modified.c \ src_SigProc_FIX/SKP_Silk_bwexpander_32.c \ src_SigProc_FIX/SKP_Silk_bwexpander.c \ +src_SigProc_FIX/SKP_Silk_debug.c \ src_SigProc_FIX/SKP_Silk_decode_pitch.c \ src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c \ src_SigProc_FIX/SKP_Silk_k2a.c \ @@ -106,12 +106,12 @@ src_SigProc_FIX/SKP_Silk_lin2log.c \ src_SigProc_FIX/SKP_Silk_log2lin.c \ src_SigProc_FIX/SKP_Silk_lowpass_int.c \ src_SigProc_FIX/SKP_Silk_lowpass_short.c \ +src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c \ src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c \ src_SigProc_FIX/SKP_Silk_LPC_stabilize.c \ src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c \ src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c \ src_SigProc_FIX/SKP_Silk_LSF_cos_table.c \ -src_SigProc_FIX/SKP_Silk_MA.c \ src_SigProc_FIX/SKP_Silk_NLSF2A.c \ src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c \ src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c \ @@ -138,17 +138,15 @@ src_SigProc_FIX/SKP_Silk_schur.c \ src_SigProc_FIX/SKP_Silk_sigm_Q15.c \ src_SigProc_FIX/SKP_Silk_sort.c \ src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c \ -src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c \ src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c \ src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c \ src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c \ -src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c \ -src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c \ src_SigProc_FLP/SKP_Silk_energy_FLP.c \ src_SigProc_FLP/SKP_Silk_inner_product_FLP.c \ src_SigProc_FLP/SKP_Silk_k2a_FLP.c \ src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c \ src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c \ +src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c \ src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c \ src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c \ src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c \ @@ -172,13 +170,12 @@ src_common/SKP_Silk_structs.h \ src_common/SKP_Silk_tables.h \ src_common/SKP_Silk_tables_NLSF_CB.h \ src_common/SKP_Silk_tuning_parameters.h \ -src_common/SKP_Silk_setup_complexity.h \ +src_common/SKP_Silk_setup.h \ src_FIX/SKP_Silk_main_FIX.h \ src_FIX/SKP_Silk_structs_FIX.h \ src_FLP/SKP_Silk_assembler_FLP.h \ src_FLP/SKP_Silk_main_FLP.h \ src_FLP/SKP_Silk_structs_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 \ src_SigProc_FIX/SKP_Silk_MacroDebug.h \ diff --git a/interface/SKP_Silk_SDK_API.h b/interface/SKP_Silk_SDK_API.h index f8d981dad..ed4fcc4bd 100644 --- a/interface/SKP_Silk_SDK_API.h +++ b/interface/SKP_Silk_SDK_API.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -43,11 +43,9 @@ extern "C" /* Struct for TOC (Table of Contents) */ typedef struct { - SKP_int framesInPacket; /* Number of 20 ms frames in packet */ - SKP_int fs_kHz; /* Sampling frequency in packet */ - SKP_int inbandLBRR; /* Does packet contain LBRR information */ - SKP_int corrupt; /* Packet is corrupt */ - SKP_int signalTypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */ + SKP_int VADFlag; /* Voice activity for packet */ + SKP_int VADFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Voice activity for each frame in packet */ + SKP_int inbandFECFlag; /* Flag indicating if packet contains in-band FEC */ } SKP_Silk_TOC_struct; /****************************************/ @@ -113,7 +111,8 @@ SKP_int SKP_Silk_SDK_InitDecoder( /* O: Returns error co SKP_int SKP_Silk_SDK_Decode( /* O: Returns error code */ void* decState, /* I/O: State */ SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */ - SKP_int lostFlag, /* I: 0: no loss, 1 loss */ + SKP_int lostFlag, /* I: 0: no loss, 1 loss, 2 decode fec */ + SKP_int newPacketFlag, /* I: Indicates first decoder call for this packet */ 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 */ @@ -134,10 +133,11 @@ void SKP_Silk_SDK_search_for_LBRR( /**************************************/ /* Get table of contents for a packet */ /**************************************/ -void SKP_Silk_SDK_get_TOC( - ec_dec *psRangeDec, /* I/O Compressor data structure */ - const SKP_int16 nBytesIn, /* I: Number of input bytes */ - SKP_Silk_TOC_struct *Silk_TOC /* O: Table of contents */ +SKP_int SKP_Silk_SDK_get_TOC( + const SKP_uint8 *payload, /* I Payload data */ + const SKP_int nBytesIn, /* I: Number of input bytes */ + const SKP_int nFramesPerPayload, /* I: Number of SILK frames per payload */ + SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */ ); #ifdef __cplusplus diff --git a/interface/SKP_Silk_control.h b/interface/SKP_Silk_control.h index 2b7c6ebd1..0e283fb5a 100644 --- a/interface/SKP_Silk_control.h +++ b/interface/SKP_Silk_control.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -42,10 +42,10 @@ typedef struct { /* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */ SKP_int32 API_sampleRate; - /* I: Maximum internal sampling rate in Hertz; 8000/12000/16000/24000 */ + /* I: Maximum internal sampling rate in Hertz; 8000/12000/16000 */ SKP_int32 maxInternalSampleRate; - /* I: Minimum internal sampling rate in Hertz; 8000/12000/16000/24000 */ + /* I: Minimum internal sampling rate in Hertz; 8000/12000/16000 */ SKP_int32 minInternalSampleRate; /* I: Number of samples per packet in milliseconds; 10/20/40/60 */ @@ -69,7 +69,7 @@ typedef struct { /* I: Flag to use constant bitrate */ SKP_int useCBR; - /* O: Internal sampling rate used, in Hertz; 8000/12000/16000/24000 */ + /* O: Internal sampling rate used, in Hertz; 8000/12000/16000 */ SKP_int32 internalSampleRate; } SKP_SILK_SDK_EncControlStruct; @@ -83,7 +83,7 @@ typedef struct { /* I: Number of samples per packet in milliseconds; 10/20/40/60 */ SKP_int payloadSize_ms; - /* I: Internal sampling rate used, in Hertz; 8000/12000/16000/24000 */ + /* I: Internal sampling rate used, in Hertz; 8000/12000/16000 */ SKP_int32 internalSampleRate; /* O: Number of samples per frame */ @@ -91,12 +91,6 @@ typedef struct { /* O: Frames per payload 1, 2, 3 */ SKP_int framesPerPayload; - - /* O: Flag to indicate that the decoder has remaining payloads internally */ - SKP_int moreInternalDecoderFrames; - - /* O: Distance between main payload and redundant payload in packets */ - SKP_int inBandFECOffset; } SKP_SILK_SDK_DecControlStruct; #ifdef __cplusplus diff --git a/interface/SKP_Silk_errors.h b/interface/SKP_Silk_errors.h index cb3079eac..c751d9beb 100644 --- a/interface/SKP_Silk_errors.h +++ b/interface/SKP_Silk_errors.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -45,10 +45,10 @@ extern "C" /* Input length is not a multiple of 10 ms, or length is longer than the packet length */ #define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -101 -/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */ +/* Sampling frequency not 8000, 12000 or 16000 Hertz */ #define SKP_SILK_ENC_FS_NOT_SUPPORTED -102 -/* Packet size not 20, 40, 60, 80 or 100 ms */ +/* Packet size not 10, 20, 40, or 60 ms */ #define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -103 /* Allocated payload buffer too short */ diff --git a/interface/SKP_Silk_typedef.h b/interface/SKP_Silk_typedef.h index 7cb661a49..f2c1f6f2c 100644 --- a/interface/SKP_Silk_typedef.h +++ b/interface/SKP_Silk_typedef.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/interface/SKP_debug.h b/interface/SKP_debug.h index f6e37cf04..84952098a 100644 --- a/interface/SKP_debug.h +++ b/interface/SKP_debug.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c b/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c index c238687e7..bfc310b64 100644 --- a/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c +++ b/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c b/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c index 1d90a97c2..4e21d65e2 100644 --- a/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c +++ b/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c b/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c index c7baece03..090e003c0 100644 --- a/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c +++ b/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -41,7 +41,7 @@ void SKP_Silk_LTP_scale_ctrl_FIX( SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control FIX */ ) { - SKP_int round_loss, frames_per_packet; + SKP_int round_loss; SKP_int g_out_Q5, g_limit_Q15, thrld1_Q15, thrld2_Q15; /* 1st order high-pass filter */ @@ -55,27 +55,25 @@ void SKP_Silk_LTP_scale_ctrl_FIX( g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) ); /* Default is minimum scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 0; + psEnc->sCmn.indices.LTP_scaleIndex = 0; /* Round the loss measure to whole pct */ round_loss = ( SKP_int )psEnc->sCmn.PacketLoss_perc; - /* Only scale if first frame in packet 0% */ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + /* Only scale if first frame in packet */ + if( psEnc->sCmn.nFramesAnalyzed == 0 ) { - frames_per_packet = SKP_DIV32_16( psEnc->sCmn.PacketSize_ms, SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) ); - - round_loss += frames_per_packet - 1; + round_loss += psEnc->sCmn.nFramesPerPacket - 1; thrld1_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss, NB_THRESHOLDS - 1 ) ]; thrld2_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ]; if( g_limit_Q15 > thrld1_Q15 ) { /* Maximum scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 2; + psEnc->sCmn.indices.LTP_scaleIndex = 2; } else if( g_limit_Q15 > thrld2_Q15 ) { /* Medium scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 1; + psEnc->sCmn.indices.LTP_scaleIndex = 1; } } - psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ]; + psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ]; } diff --git a/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c b/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c index 2e926bb47..81a5edd44 100644 --- a/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c +++ b/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* NLSF vector encoder */ /***********************/ void SKP_Silk_NLSF_MSVQ_encode_FIX( - SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ SKP_int *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const SKP_int *pNLSF_q_Q15_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ @@ -53,13 +53,15 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( SKP_int32 pRate_Q5[ MAX_NLSF_MSVQ_SURVIVORS ]; SKP_int32 pRate_new_Q5[ MAX_NLSF_MSVQ_SURVIVORS ]; SKP_int pTempIndices[ MAX_NLSF_MSVQ_SURVIVORS ]; - SKP_int pPath[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; - SKP_int pPath_new[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; - SKP_int pRes_Q15[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; - SKP_int pRes_new_Q15[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; - - const SKP_int *pConstInt; - SKP_int *pInt; + SKP_int8 pPath[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int8 pPath_new[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int16 pRes_Q15[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; + SKP_int16 pRes_new_Q15[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; + + const SKP_int16 *pConstInt16; + SKP_int16 *pInt16; + const SKP_int8 *pConstInt8; + SKP_int8 *pInt8; const SKP_int8 *pCB_element; const SKP_Silk_NLSF_CBS *pCurrentCBStage; @@ -140,35 +142,35 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( } /* Subtract new contribution from the previous residual vector for each of 'cur_survivors' */ - pConstInt = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ]; + pConstInt16 = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ]; pCB_element = &pCurrentCBStage->CB_NLSF_Q8[ SKP_SMULBB( cb_index, LPC_order ) ]; - pInt = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ]; + pInt16 = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ]; for( i = 0; i < LPC_order; i++ ) { - pInt[ i ] = pConstInt[ i ] - SKP_LSHIFT16( ( SKP_int )pCB_element[ i ], 7 ); + pInt16[ i ] = pConstInt16[ i ] - SKP_LSHIFT16( ( SKP_int16 )pCB_element[ i ], 7 ); } /* Update accumulated rate for stage 1 to the current */ pRate_new_Q5[ k ] = pRate_Q5[ input_index ] + SKP_LSHIFT32( ( SKP_int32 )pCurrentCBStage->Rates_Q4[ cb_index ], 1 ); /* Copy paths from previous matrix, starting with the best path */ - pConstInt = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ]; - pInt = &pPath_new[ SKP_SMULBB( k, psNLSF_CB->nStages ) ]; + pConstInt8 = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ]; + pInt8 = &pPath_new[ SKP_SMULBB( k, psNLSF_CB->nStages ) ]; for( i = 0; i < s; i++ ) { - pInt[ i ] = pConstInt[ i ]; + pInt8[ i ] = pConstInt8[ i ]; } /* Write the current stage indices for the 'cur_survivors' to the best path matrix */ - pInt[ s ] = cb_index; + pInt8[ s ] = (SKP_int8)cb_index; } if( s < psNLSF_CB->nStages - 1 ) { /* Copy NLSF residual matrix for next stage */ - SKP_memcpy( pRes_Q15, pRes_new_Q15, SKP_SMULBB( cur_survivors, LPC_order ) * sizeof( SKP_int ) ); + SKP_memcpy( pRes_Q15, pRes_new_Q15, SKP_SMULBB( cur_survivors, LPC_order ) * sizeof( SKP_int16 ) ); /* Copy rate vector for next stage */ SKP_memcpy( pRate_Q5, pRate_new_Q5, cur_survivors * sizeof( SKP_int32 ) ); /* Copy best path matrix for next stage */ - SKP_memcpy( pPath, pPath_new, SKP_SMULBB( cur_survivors, psNLSF_CB->nStages ) * sizeof( SKP_int ) ); + SKP_memcpy( pPath, pPath_new, SKP_SMULBB( cur_survivors, psNLSF_CB->nStages ) * sizeof( SKP_int8) ); } prev_survivors = cur_survivors; @@ -215,7 +217,7 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( #endif /* Copy best path to output argument */ - SKP_memcpy( NLSFIndices, &pPath_new[ SKP_SMULBB( bestIndex, psNLSF_CB->nStages ) ], psNLSF_CB->nStages * sizeof( SKP_int ) ); + SKP_memcpy( NLSFIndices, &pPath_new[ SKP_SMULBB( bestIndex, psNLSF_CB->nStages ) ], psNLSF_CB->nStages * sizeof( SKP_int8 ) ); /* Decode and stabilize the best survivor */ SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order ); diff --git a/src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c b/src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c index e5bb81de1..0caf4a56a 100644 --- a/src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c +++ b/src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void SKP_Silk_NLSF_VQ_rate_distortion_FIX( SKP_int32 *pRD_Q20, /* O Rate-distortion values [psNLSF_CBS->nVectors*N] */ const SKP_Silk_NLSF_CBS *psNLSF_CBS, /* I NLSF codebook stage struct */ - const SKP_int *in_Q15, /* I Input vectors to be quantized */ + const SKP_int16 *in_Q15, /* I Input vectors to be quantized */ const SKP_int *w_Q6, /* I Weight vector */ const SKP_int32 *rate_acc_Q5, /* I Accumulated rates from previous stage */ const SKP_int mu_Q15, /* I Weight between weighted error and rate */ diff --git a/src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c b/src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c index e1f5283ee..4c448f90b 100644 --- a/src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c +++ b/src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */ void SKP_Silk_NLSF_VQ_sum_error_FIX( SKP_int32 *err_Q20, /* O Weighted quantization errors [N*K] */ - const SKP_int *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */ - const SKP_int *w_Q6, /* I Weighting vectors [N*LPC_order] */ + const SKP_int16 *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */ + const SKP_int *w_Q6, /* I Weighting vectors [LPC_order] */ const SKP_int8 *pCB_Q8, /* I Codebook vectors [K*LPC_order] */ const SKP_int N, /* I Number of input vectors */ const SKP_int K, /* I Number of codebook vectors */ @@ -62,11 +62,11 @@ void SKP_Silk_NLSF_VQ_sum_error_FIX( Wtmp_Q6 = Wcpy_Q6[ SKP_RSHIFT( m, 1 ) ]; /* Compute weighted squared quantization error for index m */ - diff_Q15 = in_Q15[ m ] - SKP_LSHIFT16( ( SKP_int )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ] + diff_Q15 = in_Q15[ m ] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ] sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 ); /* Compute weighted squared quantization error for index m + 1 */ - diff_Q15 = in_Q15[m + 1] - SKP_LSHIFT16( ( SKP_int )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ] + diff_Q15 = in_Q15[m + 1] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ] sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 ); } SKP_assert( sum_error >= 0 ); diff --git a/src_FIX/SKP_Silk_control_codec_FIX.c b/src_FIX/SKP_Silk_control_codec_FIX.c index e62e0422f..016c88ebd 100644 --- a/src_FIX/SKP_Silk_control_codec_FIX.c +++ b/src_FIX/SKP_Silk_control_codec_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "SKP_Silk_main_FIX.h" -#include "SKP_Silk_setup_complexity.h" +#include "SKP_Silk_setup.h" /* ToDo: Move the functions belowto common to be able to use them in FLP control codec also */ SKP_INLINE SKP_int SKP_Silk_setup_resamplers( @@ -42,11 +42,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( SKP_INLINE SKP_int SKP_Silk_setup_rate( SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ - SKP_int TargetRate_bps /* I */ -); - -SKP_INLINE SKP_int SKP_Silk_setup_LBRR( - SKP_Silk_encoder_state_FIX *psEnc /* I/O */ + SKP_int32 TargetRate_bps /* I */ ); /* Control encoder SNR */ @@ -106,7 +102,7 @@ SKP_int SKP_Silk_control_encoder_FIX( /********************************************/ /* Set LBRR usage */ /********************************************/ - ret += SKP_Silk_setup_LBRR( psEnc ); + ret += SKP_Silk_setup_LBRR( &psEnc->sCmn ); psEnc->sCmn.controlled_since_last_payload = 1; @@ -182,7 +178,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; } if( PacketSize_ms == 10 ) { - /* Only allowed when the payload buffer is empty */ + psEnc->sCmn.nFramesPerPacket = 1; 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 ); if( psEnc->sCmn.fs_kHz == 8 ) { @@ -191,6 +187,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF; } } else { + psEnc->sCmn.nFramesPerPacket = SKP_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS ); psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); if( psEnc->sCmn.fs_kHz == 8 ) { @@ -200,21 +197,18 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( } } psEnc->sCmn.PacketSize_ms = PacketSize_ms; - psEnc->sCmn.LBRR_nBytes = 0; } /* 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->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); + 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->sCmn.sNSQ, 0, sizeof( SKP_Silk_nsq_state ) ); + SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) ); + SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, sizeof( psEnc->sPred.prev_NLSFq_Q15 ) ); #if SWITCH_TRANSITION_FILTERING - SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) ); if( psEnc->sCmn.sLP.mode == 1 ) { /* Begin transition phase */ psEnc->sCmn.sLP.transition_frame_no = 1; @@ -223,20 +217,17 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( psEnc->sCmn.sLP.transition_frame_no = 0; } #endif - psEnc->sCmn.LBRR_nBytes = 0; psEnc->sCmn.inputBufIx = 0; - psEnc->sCmn.nFramesInPayloadBuf = 0; - psEnc->sCmn.nBytesInPayloadBuf = 0; + psEnc->sCmn.nFramesAnalyzed = 0; psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */ /* Initialize non-zero parameters */ - psEnc->sCmn.prevLag = 100; - psEnc->sCmn.first_frame_after_reset = 1; - psEnc->sPrefilt.lagPrev = 100; - psEnc->sShape.LastGainIndex = 1; - psEnc->sNSQ.lagPrev = 100; - psEnc->sNSQ.prev_inv_gain_Q16 = 65536; - psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; + psEnc->sCmn.prevLag = 100; + psEnc->sCmn.first_frame_after_reset = 1; + psEnc->sPrefilt.lagPrev = 100; + psEnc->sShape.LastGainIndex = 10; + psEnc->sCmn.sNSQ.lagPrev = 100; + psEnc->sCmn.sNSQ.prev_inv_gain_Q16 = 65536; psEnc->sCmn.fs_kHz = fs_kHz; if( psEnc->sCmn.fs_kHz == 8 ) { @@ -297,7 +288,6 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( /* unsupported sampling rate */ SKP_assert( 0 ); } - psEnc->sCmn.fs_kHz_changed = 1; } /* Check that settings are valid */ @@ -308,12 +298,12 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( SKP_INLINE SKP_int SKP_Silk_setup_rate( SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ - SKP_int TargetRate_bps /* I */ + SKP_int32 TargetRate_bps /* I */ ) { SKP_int k, ret = SKP_SILK_NO_ERROR; SKP_int32 frac_Q6; - const SKP_uint16 *rateTable; + const SKP_int32 *rateTable; /* Set bitrate/coding quality */ if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) { @@ -335,7 +325,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_rate( } for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { /* Find bitrate interval in table and interpolate */ - if( TargetRate_bps < rateTable[ k ] ) { + if( TargetRate_bps <= rateTable[ k ] ) { frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), rateTable[ k ] - rateTable[ k - 1 ] ); psEnc->SNR_dB_Q7 = SKP_LSHIFT( SNR_table_Q1[ k - 1 ], 6 ) + SKP_MUL( frac_Q6, SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] ); @@ -345,55 +335,3 @@ SKP_INLINE SKP_int SKP_Silk_setup_rate( } return( ret ); } - -SKP_INLINE SKP_int SKP_Silk_setup_LBRR( - SKP_Silk_encoder_state_FIX *psEnc /* I/O */ -) -{ - SKP_int ret = SKP_SILK_NO_ERROR; - -#if USE_LBRR - SKP_int32 LBRRRate_thres_bps; - - if( psEnc->sCmn.useInBandFEC < 0 || psEnc->sCmn.useInBandFEC > 1 ) { - ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; - } - - psEnc->sCmn.LBRR_enabled = psEnc->sCmn.useInBandFEC; - if( psEnc->sCmn.fs_kHz == 8 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000; - } else { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS; - } - - if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) { - /* Set gain increase / rate reduction for LBRR usage */ - /* Coarsely tuned with PESQ for now. */ - /* Linear regression coefs G = 8 - 0.5 * loss */ - /* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */ - psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 ); - - /* Set main stream rate compensation */ - if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { - /* Tuned to give approx same mean / weighted bitrate as no inband FEC */ - psEnc->inBandFEC_SNR_comp_Q8 = SKP_FIX_CONST( 6.0f, 8 ) - SKP_LSHIFT( psEnc->sCmn.LBRR_GainIncreases, 7 ); - } else { - psEnc->inBandFEC_SNR_comp_Q8 = 0; - psEnc->sCmn.LBRR_enabled = 0; - } - } else { - psEnc->inBandFEC_SNR_comp_Q8 = 0; - psEnc->sCmn.LBRR_enabled = 0; - } -#else - if( psEnc->sCmn.LBRR_enabled != 0 ) { - ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; - psEnc->sCmn.LBRR_enabled = 0; - } -#endif - return ret; -} diff --git a/src_FIX/SKP_Silk_corrMatrix_FIX.c b/src_FIX/SKP_Silk_corrMatrix_FIX.c index 2370a550c..1ac1b1954 100644 --- a/src_FIX/SKP_Silk_corrMatrix_FIX.c +++ b/src_FIX/SKP_Silk_corrMatrix_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_encode_frame_FIX.c b/src_FIX/SKP_Silk_encode_frame_FIX.c index 348f4d29b..46adc819f 100644 --- a/src_FIX/SKP_Silk_encode_frame_FIX.c +++ b/src_FIX/SKP_Silk_encode_frame_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -34,21 +34,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SKP_int SKP_Silk_encode_frame_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ SKP_int32 *pnBytesOut, /* O Number of payload bytes */ - ec_enc *psRangeEnc, /* I/O compressor data structure */ - const SKP_int16 *pIn /* I Input speech frame */ + ec_enc *psRangeEnc /* I/O compressor data structure */ ) { SKP_Silk_encoder_control_FIX sEncCtrl; - SKP_int i, nBytes, ret = 0; + SKP_int i, nBits, SNR_dB_Q7, ret = 0; + SKP_uint8 flags; SKP_int16 *x_frame, *res_pitch_frame; SKP_int16 xfw[ MAX_FRAME_LENGTH ]; - SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ]; SKP_int16 res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; - SKP_int frame_terminator, SNR_dB_Q7; TIC(ENCODE_FRAME) - sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3; + if( psEnc->sCmn.nFramesAnalyzed == 0 ) { + /* Create space at start of payload for VAD and FEC flags */ + SKP_uint8 iCDF[ 2 ] = { 0, 0 }; + iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 ); + ec_enc_icdf( psRangeEnc, 0, iCDF, 8 ); + + /* Encode any LBRR data from previous packet */ + SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc ); + + /* Reduce coding SNR depending on how many bits used by LBRR */ + nBits = ec_tell( psRangeEnc ); + psEnc->inBandFEC_SNR_comp_Q7 = SKP_DIV32_16( SKP_SMULBB( SKP_FIX_CONST( 6.0f, 7 ), nBits ), + SKP_SMULBB( psEnc->sCmn.nFramesPerPacket, psEnc->sCmn.frame_length ) ); + + /* Reset LBRR flags */ + SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) ); + } + + psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; + /**************************************************************/ /* Setup Input Pointers, and insert frame in input buffer */ /*************************************************************/ @@ -62,14 +79,14 @@ TIC(ENCODE_FRAME) TIC(VAD) ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, &SNR_dB_Q7, sEncCtrl.input_quality_bands_Q15, &sEncCtrl.input_tilt_Q15, - pIn, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz ); + psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz ); TOC(VAD) /**************************************************/ /* Convert speech activity into VAD and DTX flags */ /**************************************************/ if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) { - sEncCtrl.sCmn.signalType = TYPE_NO_VOICE_ACTIVITY; + psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; psEnc->sCmn.noSpeechCounter++; if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) { psEnc->sCmn.inDTX = 1; @@ -78,10 +95,12 @@ TOC(VAD) psEnc->sCmn.noSpeechCounter = 0; psEnc->sCmn.inDTX = 0; } + psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 0; } else { - psEnc->sCmn.noSpeechCounter = 0; - psEnc->sCmn.inDTX = 0; - sEncCtrl.sCmn.signalType = TYPE_UNVOICED; + psEnc->sCmn.noSpeechCounter = 0; + psEnc->sCmn.inDTX = 0; + psEnc->sCmn.indices.signalType = TYPE_UNVOICED; + psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1; } /*******************************************/ @@ -90,17 +109,15 @@ TOC(VAD) TIC(HP_IN) #if HIGH_PASS_INPUT /* Variable high-pass filter */ - SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, pIn_HP, pIn ); + SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf ); #else - SKP_memcpy( pIn_HP, pIn, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); #endif TOC(HP_IN) #if SWITCH_TRANSITION_FILTERING /* Ensure smooth bandwidth transitions */ - SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP, psEnc->sCmn.frame_length ); -#else - SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.frame_length ); #endif /*****************************************/ @@ -138,15 +155,11 @@ TIC(PROCESS_GAINS) SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl ); TOC(PROCESS_GAINS) - psEnc->sCmn.quantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.quantOffsetType; - psEnc->sCmn.signalType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.signalType; - /****************************************/ /* Low Bitrate Redundant Encoding */ /****************************************/ - psEnc->sCmn.LBRR_nBytes = MAX_ARITHM_BYTES; TIC(LBRR) - //SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, psEnc->sCmn.LBRR_payload, &psEnc->sCmn.LBRR_nBytes, xfw ); + SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw ); TOC(LBRR) /*****************************************/ @@ -154,34 +167,41 @@ TOC(LBRR) /*****************************************/ TIC(NSQ) if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { - SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, - psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, + SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses, sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, - sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, - sEncCtrl.LTP_scale_Q14 ); + sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 ); } else { - SKP_Silk_NSQ( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, - psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, + SKP_Silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses, sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, - sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, - sEncCtrl.LTP_scale_Q14 ); + sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 ); } TOC(NSQ) - /****************************************/ - /* Initialize range coder */ - /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - psEnc->sCmn.nBytesInPayloadBuf = 0; - } - /****************************************/ /* Encode Parameters */ /****************************************/ TIC(ENCODE_PARAMS) - SKP_Silk_encode_indices( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc ); + SKP_Silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesAnalyzed, 0 ); TOC(ENCODE_PARAMS) + /****************************************/ + /* Encode Excitation Signal */ + /****************************************/ +TIC(ENCODE_PULSES) + SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, + psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); +TOC(ENCODE_PULSES) + + /****************************************/ + /* Simulate network buffer delay caused */ + /* by exceeding TargetRate */ + /****************************************/ + nBits = ec_tell( psRangeEnc ); + psEnc->BufferedInChannel_ms += SKP_DIV32( SKP_SMULBB( 1000, nBits - psEnc->sCmn.prev_nBits ), psEnc->sCmn.TargetRate_bps ); + psEnc->BufferedInChannel_ms -= psEnc->sCmn.PacketSize_ms; + psEnc->BufferedInChannel_ms = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 ); + psEnc->sCmn.prev_nBits = nBits; + /****************************************/ /* Update Buffers and State */ /****************************************/ @@ -190,56 +210,36 @@ TOC(ENCODE_PARAMS) ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) ); /* Parameters needed for next frame */ - psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; - psEnc->sCmn.prevSignalType = sEncCtrl.sCmn.signalType; + psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; + psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; psEnc->sCmn.first_frame_after_reset = 0; - psEnc->sCmn.nFramesInPayloadBuf++; + psEnc->sCmn.nFramesAnalyzed++; /****************************************/ - /* Finalize payload and copy to output */ + /* Finalize payload */ /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) { - - /* Check if FEC information should be added */ - //frame_terminator = psEnc->sCmn.usage; - frame_terminator = SKP_SILK_NO_LBRR; - - /* Add the frame termination info to stream */ - ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_LBRR_Present_iCDF, 8 ); - - /* Code excitation signal */ - for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ], - &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); + if( psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) { + /* Insert VAD flags and FEC flag at beginning of bitstream */ + flags = 0; + for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) { + flags |= psEnc->sCmn.VAD_flags[i]; + flags = SKP_LSHIFT( flags, 1 ); } + flags |= psEnc->sCmn.LBRR_flag; + ret = ec_enc_patch_initial_bits( psRangeEnc, flags, psEnc->sCmn.nFramesPerPacket + 1 ); + SKP_assert( ret == 0 ); - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); - *pnBytesOut = nBytes; + /* Payload size */ + nBits = ec_tell( psRangeEnc ); + *pnBytesOut = SKP_RSHIFT( nBits + 7, 3 ); /* Reset the number of frames in payload buffer */ - psEnc->sCmn.nFramesInPayloadBuf = 0; + psEnc->sCmn.nFramesAnalyzed = 0; + psEnc->sCmn.prev_nBits = 0; } else { /* No payload this time */ *pnBytesOut = 0; - - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); - - /* Take into account the q signal that isn't in the bitstream yet */ - nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, - &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ] ); } - - /* Simulate number of ms buffered in channel because of exceeding TargetRate */ - SKP_assert( ( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) == - SKP_SAT32( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) ); - SKP_assert( psEnc->sCmn.TargetRate_bps > 0 ); - psEnc->BufferedInChannel_ms += SKP_DIV32( 8 * 1000 * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ), psEnc->sCmn.TargetRate_bps ); - psEnc->BufferedInChannel_ms -= SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ); - psEnc->BufferedInChannel_ms = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 ); - psEnc->sCmn.nBytesInPayloadBuf = nBytes; - TOC(ENCODE_FRAME) #ifdef SAVE_ALL_INTERNAL_DATA @@ -248,7 +248,7 @@ 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( pitchL.dat, sEncCtrl.sCmn.pitchL, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.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; } @@ -270,190 +270,81 @@ TOC(ENCODE_FRAME) tmp[ i ] = (SKP_float)sEncCtrl.Gains_Q16[ i ] / 65536.0f; } DEBUG_STORE_DATA( gains.dat, tmp, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( gains_indices.dat, &sEncCtrl.sCmn.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); - DEBUG_STORE_DATA( nBytes.dat, &nBytes, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( gains_indices.dat, &psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( nBits.dat, &nBits, sizeof( SKP_int ) ); tmp[ 0 ] = (SKP_float)sEncCtrl.current_SNR_dB_Q7 / 128.0f; DEBUG_STORE_DATA( current_SNR_db.dat, tmp, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( quantOffsetType.dat, &sEncCtrl.sCmn.quantOffsetType, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( quantOffsetType.dat, &psEnc->sCmn.indices.quantOffsetType, sizeof( SKP_int ) ); tmp[ 0 ] = (SKP_float)psEnc->speech_activity_Q8 / 256.0f; DEBUG_STORE_DATA( speech_activity.dat, tmp, sizeof( SKP_float ) ); for( i = 0; i < VAD_N_BANDS; i++ ) { tmp[ i ] = (SKP_float)sEncCtrl.input_quality_bands_Q15[ i ] / 32768.0f; } DEBUG_STORE_DATA( input_quality_bands.dat, tmp, VAD_N_BANDS * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( signalType.dat, &sEncCtrl.sCmn.signalType, sizeof( SKP_int ) ); - DEBUG_STORE_DATA( ratelevel.dat, &sEncCtrl.sCmn.RateLevelIndex, sizeof( SKP_int ) ); - DEBUG_STORE_DATA( lag_index.dat, &sEncCtrl.sCmn.lagIndex, sizeof( SKP_int ) ); - DEBUG_STORE_DATA( contour_index.dat, &sEncCtrl.sCmn.contourIndex, sizeof( SKP_int ) ); - DEBUG_STORE_DATA( per_index.dat, &sEncCtrl.sCmn.PERIndex, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( signalType.dat, &psEnc->sCmn.indices.signalType, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( ratelevel.dat, &psEnc->sCmn.indices.RateLevelIndex, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( lag_index.dat, &psEnc->sCmn.indices.lagIndex, sizeof( SKP_int16 ) ); + DEBUG_STORE_DATA( contour_index.dat, &psEnc->sCmn.indices.contourIndex, sizeof( SKP_int8 ) ); + DEBUG_STORE_DATA( per_index.dat, &psEnc->sCmn.indices.PERIndex, sizeof( SKP_int ) ); } #endif return( ret ); } -#if 0 //tmp -/* Low BitRate Redundancy encoding functionality. Reuse all parameters but encode residual with lower bitrate */ +/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */ void SKP_Silk_LBRR_encode_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */ - SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk encoder control struct */ - SKP_uint8 *pCode, /* O Pointer to payload */ - SKP_int16 *pnBytesOut, /* I/O Pointer to number of payload bytes */ - SKP_int16 xfw[] /* I Input signal */ + SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ + SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ + const SKP_int16 xfw[] /* I Input signal */ ) { - SKP_int i, TempGainsIndices[ MAX_NB_SUBFR ], frame_terminator; - SKP_int nBytes, nFramesInPayloadBuf; SKP_int32 TempGains_Q16[ MAX_NB_SUBFR ]; - SKP_int typeOffset, LTP_scaleIndex, Rate_only_parameters = 0; + SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesAnalyzed ]; + SKP_Silk_nsq_state sNSQ_LBRR; /*******************************************/ /* Control use of inband LBRR */ /*******************************************/ - psEnc->sCmn.LBRR_usage = SKP_SILK_NO_LBRR; - if( psEnc->sCmn.LBRR_enabled ) { - /* Control LBRR */ - /* Usage Control based on sensitivity and packet loss caracteristics */ - if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { - psEnc->sCmn.LBRR_usage = SKP_SILK_LBRR; - } - } + if( psEnc->sCmn.LBRR_enabled && psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) { + psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1; + + /* Copy noise shaping quantizer state and quantization indices from regular encoding */ + SKP_memcpy( &sNSQ_LBRR, &psEnc->sCmn.sNSQ, sizeof( SKP_Silk_nsq_state ) ); + SKP_memcpy( psIndices_LBRR, &psEnc->sCmn.indices, sizeof( SideInfoIndices ) ); - if( psEnc->sCmn.LBRR_enabled ) { /* Save original gains */ - SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, MAX_NB_SUBFR * sizeof( SKP_int ) ); - SKP_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, MAX_NB_SUBFR * sizeof( SKP_int32 ) ); - - typeOffset = psEnc->sCmn.typeOffsetPrev; // Temp save as cannot be overwritten - LTP_scaleIndex = psEncCtrl->sCmn.LTP_scaleIndex; - - /* Set max rate where quant signal is encoded */ - if( psEnc->sCmn.fs_kHz == 8 ) { - Rate_only_parameters = 13500; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - Rate_only_parameters = 15500; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - Rate_only_parameters = 17500; - } else { - SKP_assert( 0 ); - } + SKP_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, psEnc->sCmn.nb_subfr * sizeof( SKP_int32 ) ); - if( psEnc->sCmn.Complexity >= 4 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) { - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - /* First frame in packet; copy everything */ - SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) ); - - psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; - /* Increase Gains to get target LBRR rate */ - psEncCtrl->sCmn.GainsIndices[ 0 ] = psEncCtrl->sCmn.GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases; - psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT_int( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 ); - } - /* Decode to get gains in sync with decoder */ - /* Overwrite unquantized gains with quantized gains */ - SKP_Silk_gains_dequant( psEncCtrl->Gains_Q16, psEncCtrl->sCmn.GainsIndices, - &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, psEnc->sCmn.nb_subfr ); - - /*****************************************/ - /* Noise shaping quantization */ - /*****************************************/ - if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { - SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, - psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, - psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, - psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 ); - } else { - SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, - psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, - psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, - psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 ); - } - } else { - SKP_memset( psEnc->sCmn.q_LBRR, 0, psEnc->sCmn.frame_length * sizeof( SKP_int8 ) ); - psEncCtrl->sCmn.LTP_scaleIndex = 0; - } - /****************************************/ - /* Initialize arithmetic coder */ - /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES ); - - SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR ); - psEnc->sCmn.nBytesInPayloadBuf = 0; - } + if( psEnc->sCmn.nFramesAnalyzed == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed - 1 ] == 0 ) { + /* First frame in packet or previous frame not LBRR coded */ + psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; - /****************************************/ - /* Encode Parameters */ - /****************************************/ - SKP_Silk_encode_indices( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR ); - - /****************************************/ - /* Encode Parameters */ - /****************************************/ - if( psEnc->sCmn.sRC_LBRR.error ) { - /* Encoder returned error: clear payload buffer */ - nFramesInPayloadBuf = 0; - } else { - nFramesInPayloadBuf = psEnc->sCmn.nFramesInPayloadBuf + 1; + /* Increase Gains to get target LBRR rate */ + psIndices_LBRR->GainsIndices[ 0 ] = psIndices_LBRR->GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases; + psIndices_LBRR->GainsIndices[ 0 ] = SKP_min_int( psIndices_LBRR->GainsIndices[ 0 ], N_LEVELS_QGAIN - 1 ); } - /****************************************/ - /* Finalize payload and copy to output */ - /****************************************/ - if( SKP_SMULBB( nFramesInPayloadBuf, SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) ) >= psEnc->sCmn.PacketSize_ms ) { - - /* Check if FEC information should be added */ - frame_terminator = SKP_SILK_LAST_FRAME; - - /* Add the frame termination info to stream */ - ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_LBRR_Present_iCDF, 8 ); - - /*********************************************/ - /* Encode quantization indices of excitation */ - /*********************************************/ - for( i = 0; i < nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ], - &psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); - } - - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc_LBRR ) + 7, 3 ); - - /* Check that there is enough space in external output buffer and move data */ - if( *pnBytesOut >= nBytes ) { - SKP_int bits_in_stream, mask; - bits_in_stream = ec_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state ); - ec_enc_done( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state ); - - /* Fill up any remaining bits in the last byte with 1s */ - if( bits_in_stream & 7 ) { - mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 ); - if( nBytes - 1 < *pnBytesOut ) { - psEnc->sCmn.sRC_LBRR.range_enc_celt_state.buf->buf[ nBytes - 1 ] |= mask; - } - } - SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) ); - - *pnBytesOut = nBytes; - } else { - /* Not enough space: payload will be discarded */ - *pnBytesOut = 0; - SKP_assert( 0 ); - } + /* Decode to get gains in sync with decoder */ + /* Overwrite unquantized gains with quantized gains */ + SKP_Silk_gains_dequant( psEncCtrl->Gains_Q16, psIndices_LBRR->GainsIndices, + &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr ); + + /*****************************************/ + /* Noise shaping quantization */ + /*****************************************/ + if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { + SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw, + psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesAnalyzed ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, + psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, + psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 ); } else { - /* No payload this time */ - *pnBytesOut = 0; - - /* Encode that more frames follows */ - frame_terminator = SKP_SILK_MORE_FRAMES; - ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_LBRR_Present_iCDF, 8 ); + SKP_Silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw, + psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesAnalyzed ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, + psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, + psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 ); } /* Restore original Gains */ - SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); - SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof( SKP_int32 ) ); - - /* Restore LTP scale index and typeoffset */ - psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex; - psEnc->sCmn.typeOffsetPrev = typeOffset; + SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof( SKP_int32 ) ); } } -#endif diff --git a/src_FIX/SKP_Silk_find_LPC_FIX.c b/src_FIX/SKP_Silk_find_LPC_FIX.c index 450ec1e58..8b0a96c02 100644 --- a/src_FIX/SKP_Silk_find_LPC_FIX.c +++ b/src_FIX/SKP_Silk_find_LPC_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Finds LPC vector from correlations, and converts to NLSF */ void SKP_Silk_find_LPC_FIX( SKP_int NLSF_Q15[], /* O NLSFs */ - SKP_int *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */ + SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */ const SKP_int prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */ const SKP_int useInterpolatedNLSFs, /* I Flag */ const SKP_int LPC_order, /* I LPC order */ @@ -43,7 +43,6 @@ void SKP_Silk_find_LPC_FIX( SKP_int k; SKP_int32 a_Q16[ MAX_LPC_ORDER ]; SKP_int isInterpLower, shift; - SKP_int16 S[ MAX_LPC_ORDER ]; SKP_int32 res_nrg0, res_nrg1; SKP_int rshift0, rshift1; @@ -96,8 +95,7 @@ void SKP_Silk_find_LPC_FIX( SKP_Silk_NLSF2A_stable( a_tmp_Q12, NLSF0_Q15, LPC_order ); /* Calculate residual energy with NLSF interpolation */ - SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) ); - SKP_Silk_LPC_analysis_filter( x, a_tmp_Q12, S, LPC_res, 2 * subfr_length, LPC_order ); + SKP_Silk_LPC_analysis_filter( LPC_res, x, a_tmp_Q12, 2 * subfr_length, LPC_order ); SKP_Silk_sum_sqr_shift( &res_nrg0, &rshift0, LPC_res + LPC_order, subfr_length - LPC_order ); SKP_Silk_sum_sqr_shift( &res_nrg1, &rshift1, LPC_res + LPC_order + subfr_length, subfr_length - LPC_order ); @@ -138,7 +136,7 @@ void SKP_Silk_find_LPC_FIX( /* Interpolation has lower residual energy */ res_nrg = res_nrg_interp; res_nrg_Q = res_nrg_interp_Q; - *interpIndex = k; + *interpIndex = (SKP_int8)k; } res_nrg_2nd = res_nrg_interp; res_nrg_2nd_Q = res_nrg_interp_Q; diff --git a/src_FIX/SKP_Silk_find_LTP_FIX.c b/src_FIX/SKP_Silk_find_LTP_FIX.c index cddc29a41..014cd0858 100644 --- a/src_FIX/SKP_Silk_find_LTP_FIX.c +++ b/src_FIX/SKP_Silk_find_LTP_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_find_pitch_lags_FIX.c b/src_FIX/SKP_Silk_find_pitch_lags_FIX.c index 12f62a028..2a66f528a 100644 --- a/src_FIX/SKP_Silk_find_pitch_lags_FIX.c +++ b/src_FIX/SKP_Silk_find_pitch_lags_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -44,7 +44,6 @@ void SKP_Silk_find_pitch_lags_FIX( SKP_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ]; SKP_int16 rc_Q15[ MAX_FIND_PITCH_LPC_ORDER ]; SKP_int32 A_Q24[ MAX_FIND_PITCH_LPC_ORDER ]; - SKP_int32 FiltState[ MAX_FIND_PITCH_LPC_ORDER ]; SKP_int16 A_Q12[ MAX_FIND_PITCH_LPC_ORDER ]; /******************************************/ @@ -104,11 +103,9 @@ void SKP_Silk_find_pitch_lags_FIX( /*****************************************/ /* LPC analysis filtering */ /*****************************************/ - SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind will complain otherwise */ - SKP_Silk_MA_Prediction( x_buf, A_Q12, FiltState, res, buf_len, psEnc->sCmn.pitchEstimationLPCOrder ); - SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) ); + SKP_Silk_LPC_analysis_filter( res, x_buf, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder ); - if( psEncCtrl->sCmn.signalType != TYPE_NO_VOICE_ACTIVITY ) { + if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY ) { /* Threshold for pitch estimator */ thrhld_Q15 = SKP_FIX_CONST( 0.6, 15 ); thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder ); @@ -120,18 +117,18 @@ void SKP_Silk_find_pitch_lags_FIX( /*****************************************/ /* Call pitch estimator */ /*****************************************/ - if( SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, - &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16, + if( SKP_Silk_pitch_analysis_core( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex, &psEnc->sCmn.indices.contourIndex, + &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16, ( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr ) == 0 ) { - psEncCtrl->sCmn.signalType = TYPE_VOICED; + psEnc->sCmn.indices.signalType = TYPE_VOICED; } else { - psEncCtrl->sCmn.signalType = TYPE_UNVOICED; + psEnc->sCmn.indices.signalType = TYPE_UNVOICED; } } else { - SKP_memset( psEncCtrl->sCmn.pitchL, 0, sizeof( psEncCtrl->sCmn.pitchL ) ); - psEncCtrl->sCmn.lagIndex = 0; - psEncCtrl->sCmn.contourIndex = 0; + SKP_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) ); + psEnc->sCmn.indices.lagIndex = 0; + psEnc->sCmn.indices.contourIndex = 0; psEnc->LTPCorr_Q15 = 0; } } diff --git a/src_FIX/SKP_Silk_find_pred_coefs_FIX.c b/src_FIX/SKP_Silk_find_pred_coefs_FIX.c index efe2dfb8b..5f3dcdc5d 100644 --- a/src_FIX/SKP_Silk_find_pred_coefs_FIX.c +++ b/src_FIX/SKP_Silk_find_pred_coefs_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -27,48 +27,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main_FIX.h" -#ifdef SAVE_ALL_INTERNAL_DATA -#include <math.h> - -void SKP_Silk_LTP_ana_core( - SKP_float r_LPC[], /* I LPC residual */ - SKP_float r_LTP[], /* O LTP residual */ - const SKP_int pitchL[], /* I pitch lags */ - const SKP_float LTPCoef[], /* I LTP Coeficients */ - SKP_int subfr_length, /* I smpls in one sub frame */ - SKP_int LTP_mem_length /* I Length of LTP state of input */ -); - -void SKP_Silk_LPC_analysis_filter_FLP( - SKP_float r_LPC[], /* O LPC residual signal */ - const SKP_float PredCoef[], /* I LPC coeficicnts */ - const SKP_float s[], /* I Input Signal */ - SKP_int length, /* I length of signal */ - SKP_int Order /* I LPC order */ -); - -double SKP_Silk_energy_FLP( - const SKP_float *data, - SKP_int dataSize -); - -/* integer to floating-point conversion */ -SKP_INLINE void SKP_short2float_array( - 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 ) ); } - -#endif - 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 */ @@ -85,12 +43,6 @@ void SKP_Silk_find_pred_coefs_FIX( SKP_int32 tmp, min_gain_Q16; SKP_int LTP_corrs_rshift[ MAX_NB_SUBFR ]; -#ifdef SAVE_ALL_INTERNAL_DATA - SKP_int16 uq_PredCoef_Q12[ MAX_NB_SUBFR >> 1 ][ MAX_LPC_ORDER ]; - SKP_float uq_PredCoef[ MAX_NB_SUBFR >> 1 ][ MAX_LPC_ORDER ]; - SKP_float uq_LTPCoef[ MAX_NB_SUBFR * LTP_ORDER ]; -#endif - /* weighting for weighted least squares */ min_gain_Q16 = SKP_int32_MAX >> 6; for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { @@ -114,26 +66,19 @@ void SKP_Silk_find_pred_coefs_FIX( local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] ); } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /**********/ /* VOICED */ /**********/ - SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.pitchL[ 0 ] + LTP_ORDER / 2 ); + SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); /* LTP analysis */ SKP_Silk_find_LTP_FIX( psEncCtrl->LTPCoef_Q14, WLTP, &psEncCtrl->LTPredCodGain_Q7, - res_pitch, psEncCtrl->sCmn.pitchL, Wght_Q15, psEnc->sCmn.subfr_length, + res_pitch, psEncCtrl->pitchL, Wght_Q15, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length, LTP_corrs_rshift ); -#ifdef SAVE_ALL_INTERNAL_DATA - /* Save unquantized LTP coefficients */ - for( i = 0; i < LTP_ORDER * psEnc->sCmn.nb_subfr; i++ ) { - uq_LTPCoef[ i ] = (SKP_float)psEncCtrl->LTPCoef_Q14[ i ] / 16384.0f; - } -#endif - /* Quantize LTP gain parameters */ - SKP_Silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, + SKP_Silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr); /* Control LTP scaling */ @@ -141,7 +86,7 @@ void SKP_Silk_find_pred_coefs_FIX( /* Create LTP residual */ SKP_Silk_LTP_analysis_filter_FIX( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder, - psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); + psEncCtrl->LTPCoef_Q14, psEncCtrl->pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); } else { /************/ @@ -163,37 +108,11 @@ void SKP_Silk_find_pred_coefs_FIX( /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */ TIC(FIND_LPC) - SKP_Silk_find_LPC_FIX( NLSF_Q15, &psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq_Q15, + SKP_Silk_find_LPC_FIX( NLSF_Q15, &psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq_Q15, psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder, LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder, psEnc->sCmn.nb_subfr ); TOC(FIND_LPC) -#ifdef SAVE_ALL_INTERNAL_DATA /* Save unquantized LPC's */ - if( psEnc->sCmn.useInterpolatedNLSFs == 0 ) { - /* Convert back to filter representation */ - SKP_Silk_NLSF2A_stable( uq_PredCoef_Q12[ 0 ], NLSF_Q15, psEnc->sCmn.predictLPCOrder ); - SKP_memcpy( uq_PredCoef_Q12[ 1 ], uq_PredCoef_Q12[ 0 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_int16 ) ); - } else { /* i.e. if( psEnc->useInterpolatedLSFs != 0 ) */ - SKP_int iNLSF_Q15[ MAX_LPC_ORDER ]; - - /* Update interpolated LSF0 coefficients taking quantization of LSF1 coefficients into account */ - SKP_Silk_interpolate( iNLSF_Q15, psEnc->sPred.prev_NLSFq_Q15, NLSF_Q15, - psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder ); - - /* Convert back to filter representation */ - SKP_Silk_NLSF2A_stable( uq_PredCoef_Q12[ 0 ], iNLSF_Q15, psEnc->sCmn.predictLPCOrder ); - - /* Convert back to filter representation */ - SKP_Silk_NLSF2A_stable( uq_PredCoef_Q12[ 1 ], NLSF_Q15, psEnc->sCmn.predictLPCOrder ); - } - - /* Convert to FLP */ - for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) { - uq_PredCoef[ 0 ][ i ] = (SKP_float)uq_PredCoef_Q12[ 0 ][ i ] / 4096.0f; - uq_PredCoef[ 1 ][ i ] = (SKP_float)uq_PredCoef_Q12[ 1 ][ i ] / 4096.0f; - } -#endif - /* Quantize LSFs */ TIC(PROCESS_LSFS) SKP_Silk_process_NLSFs_FIX( psEnc, psEncCtrl, NLSF_Q15 ); @@ -205,231 +124,4 @@ void SKP_Silk_find_pred_coefs_FIX( /* Copy to prediction struct for use in next frame for fluctuation reduction */ SKP_memcpy( psEnc->sPred.prev_NLSFq_Q15, NLSF_Q15, psEnc->sCmn.predictLPCOrder * sizeof( SKP_int ) ); - -#ifdef SAVE_ALL_INTERNAL_DATA - { - SKP_int j, k; - SKP_float in_nrg, *in_ptr; - SKP_float LPC_res_nrg, qLPC_res_nrg, LTP_res_nrg, qLTP_res_nrg; - SKP_float LPC_predCodGain, QLPC_predCodGain, QLTP_predCodGain, LTPredCodGain, predCodGain; - SKP_float LPC_res[ MAX_FRAME_LENGTH << 1 ], LTP_res[ MAX_FRAME_LENGTH ]; - SKP_float SF_resNrg[ MAX_NB_SUBFR ]; - - SKP_float x_flp[ 2 * MAX_FRAME_LENGTH ]; - SKP_float Wght[ MAX_NB_SUBFR ]; - SKP_float PredCoef[ 2 ][ MAX_LPC_ORDER ]; - SKP_float LTPCoef[ MAX_NB_SUBFR * LTP_ORDER ]; - - /* Convert various FIX data to FLP */ - SKP_short2float_array( x_flp, psEnc->x_buf, psEnc->sCmn.ltp_mem_length + psEnc->sCmn.frame_length ); - for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { - Wght[ k ] = ( (SKP_float)Wght_Q15[ k ] / 32768.0f ); - } - for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) { - PredCoef[ 0 ][ i ] = (SKP_float)psEncCtrl->PredCoef_Q12[ 0 ][ i ] / 4096.0f; - PredCoef[ 1 ][ i ] = (SKP_float)psEncCtrl->PredCoef_Q12[ 1 ][ i ] / 4096.0f; - } - for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) { - LTPCoef[ i ] = (SKP_float)psEncCtrl->LTPCoef_Q14[ i ] / 16384.0f; - } - - /* Weighted input energy */ - in_ptr = &x_flp[ psEnc->sCmn.ltp_mem_length ]; - DEBUG_STORE_DATA( x_flp.dat, x_flp, psEnc->sCmn.frame_length * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( in_ptr.dat, in_ptr, psEnc->sCmn.frame_length * sizeof( SKP_float ) ); - in_nrg = 0.0f; - for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { - in_nrg += (SKP_float)SKP_Silk_energy_FLP( in_ptr, psEnc->sCmn.subfr_length ) * Wght[ k ]; - in_ptr += psEnc->sCmn.subfr_length; - } - - if( psEnc->sCmn.useInterpolatedNLSFs == 0 ) { - SKP_memcpy( PredCoef[ 0 ], PredCoef[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); - } - - DEBUG_STORE_DATA( uq_PredCoef.dat, uq_PredCoef[0], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( PredCoef.dat, PredCoef[0], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); - - LPC_res_nrg = 0.0f; - LTP_res_nrg = 0.0f; - qLPC_res_nrg = 0.0f; - qLTP_res_nrg = 0.0f; - for( j = 0; j < psEnc->sCmn.nb_subfr; j += 2 ) { - /* Calculate LPC residual with unquantized LPC */ - SKP_Silk_LPC_analysis_filter_FLP( LPC_res, uq_PredCoef[ j >> 1 ], x_flp + j * psEnc->sCmn.subfr_length, - ( psEnc->sCmn.ltp_mem_length + ( psEnc->sCmn.subfr_length << 1 ) ), psEnc->sCmn.predictLPCOrder ); - - /* Weighted energy */ - in_ptr = &LPC_res[ psEnc->sCmn.ltp_mem_length ]; - for( k = 0; k < 2; k++ ) { - LPC_res_nrg += (SKP_float)SKP_Silk_energy_FLP( in_ptr, psEnc->sCmn.subfr_length ) * Wght[ j + k ]; - in_ptr += psEnc->sCmn.subfr_length; - } - - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - /* Calculate LTP residual with unquantized LTP and unquantized LPC */ - SKP_Silk_LTP_ana_core( LPC_res, LTP_res, &psEncCtrl->sCmn.pitchL[ j ], - &uq_LTPCoef[ j * LTP_ORDER ], psEnc->sCmn.subfr_length, psEnc->sCmn.ltp_mem_length ); - - /* Weighted energy */ - in_ptr = LTP_res; - for( k = 0; k < 2; k++ ) { - LTP_res_nrg += (SKP_float)SKP_Silk_energy_FLP( in_ptr, psEnc->sCmn.subfr_length ) * Wght[ j + k ]; - in_ptr += psEnc->sCmn.subfr_length; - } - } - - /* Calculate LPC residual with quantized LPC */ - SKP_Silk_LPC_analysis_filter_FLP( LPC_res, PredCoef[ j >> 1 ], x_flp + j * psEnc->sCmn.subfr_length, - ( psEnc->sCmn.ltp_mem_length + ( psEnc->sCmn.subfr_length << 1 ) ), psEnc->sCmn.predictLPCOrder ); - - /* Weighted energy */ - in_ptr = &LPC_res[ psEnc->sCmn.ltp_mem_length ]; - for( k = 0; k < 2; k++ ) { - SF_resNrg[ k + j ] = (SKP_float)SKP_Silk_energy_FLP( in_ptr, psEnc->sCmn.subfr_length ); - qLPC_res_nrg += SF_resNrg[ k + j ] * Wght[ j + k ]; - in_ptr += psEnc->sCmn.subfr_length; - } - - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - /* Calculate LTP residual with unquantized LTP and unquantized LPC */ - SKP_Silk_LTP_ana_core( LPC_res, LTP_res, &psEncCtrl->sCmn.pitchL[ j ], - <PCoef[ j * LTP_ORDER ], psEnc->sCmn.subfr_length, psEnc->sCmn.ltp_mem_length ); - - /* Weighted energy */ - in_ptr = LTP_res; - for( k = 0; k < 2; k++ ) { - SF_resNrg[ k + j ] = (SKP_float)SKP_Silk_energy_FLP( in_ptr, psEnc->sCmn.subfr_length ); - qLTP_res_nrg += SF_resNrg[ k + j ] * Wght[ j + k ]; - in_ptr += psEnc->sCmn.subfr_length; - } - } else { - SKP_memcpy( LTP_res, &LPC_res[ psEnc->sCmn.ltp_mem_length ], ( psEnc->sCmn.subfr_length << 1 ) * sizeof( SKP_float ) ); - } - /* Save residual */ - DEBUG_STORE_DATA( LPC_res.dat, &LPC_res[ psEnc->sCmn.ltp_mem_length ], ( psEnc->sCmn.subfr_length << 1 ) * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( res.dat, LTP_res, ( psEnc->sCmn.subfr_length << 1 ) * sizeof( SKP_float ) ); - } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - LPC_predCodGain = 3.0f * SKP_Silk_log2( in_nrg / LPC_res_nrg ); - QLPC_predCodGain = 3.0f * SKP_Silk_log2( in_nrg / qLPC_res_nrg ); - LTPredCodGain = 3.0f * SKP_Silk_log2( LPC_res_nrg / LTP_res_nrg ); - QLTP_predCodGain = 3.0f * SKP_Silk_log2( qLPC_res_nrg / qLTP_res_nrg ); - } else { - LPC_predCodGain = 3.0f * SKP_Silk_log2( in_nrg / LPC_res_nrg ); - QLPC_predCodGain = 3.0f * SKP_Silk_log2( in_nrg / qLPC_res_nrg ); - LTPredCodGain = 0.0f; - QLTP_predCodGain = 0.0f; - } - predCodGain = QLPC_predCodGain + QLTP_predCodGain; - - DEBUG_STORE_DATA( LTPredCodGain.dat, <PredCodGain, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( QLTP_predCodGain.dat, &QLTP_predCodGain, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( LPC_predCodGain.dat, &LPC_predCodGain, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( QLPC_predCodGain.dat, &QLPC_predCodGain, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( predCodGain.dat, &predCodGain, sizeof( SKP_float ) ); - DEBUG_STORE_DATA( ResNrg.dat, SF_resNrg, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); - } -#endif -} - -#ifdef SAVE_ALL_INTERNAL_DATA -/****************************************************/ -/* LTP analysis filter. Filters two subframes */ -/****************************************************/ -void SKP_Silk_LTP_ana_core( - SKP_float r_LPC[], /* I LPC residual */ - SKP_float r_LTP[], /* O LTP residual */ - const SKP_int pitchL[], /* I pitch lags */ - const SKP_float LTPCoef[], /* I LTP Coeficients */ - SKP_int subfr_length, /* I smpls in one sub frame */ - SKP_int LTP_mem_length /* I Length of LTP state of input */ -) -{ - SKP_int k, i; - SKP_float LTP_pred; - const SKP_float *r, *b_ptr, *lag_ptr; - - r = &r_LPC[ LTP_mem_length ]; - b_ptr = LTPCoef; - for( k = 0; k < (MAX_NB_SUBFR >> 1); k++ ) { - lag_ptr = r - pitchL[k]; - /* LTP analysis FIR filter */ - for( i = 0; i < subfr_length; i++ ) { - /* long-term prediction */ - LTP_pred = lag_ptr[LTP_ORDER/2] * b_ptr[0]; - LTP_pred += lag_ptr[LTP_ORDER/2 - 1] * b_ptr[1]; - LTP_pred += lag_ptr[LTP_ORDER/2 - 2] * b_ptr[2]; - LTP_pred += lag_ptr[LTP_ORDER/2 - 3] * b_ptr[3]; - LTP_pred += lag_ptr[LTP_ORDER/2 - 4] * b_ptr[4]; - - /* subtract prediction */ - r_LTP[i] = r[i] - LTP_pred; - lag_ptr++; - } - r += subfr_length; - r_LTP += subfr_length; - b_ptr += LTP_ORDER; - } -} - -/*******************************************/ -/* LPC analysis filter */ -/* NB! State is kept internally and the */ -/* filter always starts with zero state */ -/* first Order output samples are not set */ -/*******************************************/ -void SKP_Silk_LPC_analysis_filter_FLP( - SKP_float r_LPC[], /* O LPC residual signal */ - const SKP_float PredCoef[], /* I LPC coeficicnts */ - const SKP_float s[], /* I Input Signal */ - SKP_int length, /* I length of signal */ - SKP_int Order /* I LPC order */ -) -{ - SKP_int i, j; - SKP_float LPC_pred; - const SKP_float *s_ptr; - - for ( i = Order; i < length; i++ ) { - s_ptr = &s[i - 1]; - - LPC_pred = 0; - /* short-term prediction */ - for( j = 0; j < Order; j++ ) { - LPC_pred += s_ptr[ -j ] * PredCoef[ j ]; - } - - /* prediction error */ - r_LPC[ i ] = s_ptr[ 1 ] - LPC_pred; - } -} - -/* sum of squares of a SKP_float array, with result as double */ -double SKP_Silk_energy_FLP( - const SKP_float *data, - SKP_int dataSize -) -{ - SKP_int i, dataSize4; - double result; - - /* 4x unrolled loop */ - result = 0.0f; - dataSize4 = dataSize & 0xFFFC; - for( i = 0; i < dataSize4; i += 4 ) { - result += data[ i + 0 ] * data[ i + 0 ] + - data[ i + 1 ] * data[ i + 1 ] + - data[ i + 2 ] * data[ i + 2 ] + - data[ i + 3 ] * data[ i + 3 ]; - } - - /* add any remaining products */ - for( ; i < dataSize; i++ ) { - result += data[ i ] * data[ i ]; - } - - SKP_assert( result >= 0.0 ); - return result; } -#endif diff --git a/src_FIX/SKP_Silk_init_encoder_FIX.c b/src_FIX/SKP_Silk_init_encoder_FIX.c index 01bfc5e06..d57d15b47 100644 --- a/src_FIX/SKP_Silk_init_encoder_FIX.c +++ b/src_FIX/SKP_Silk_init_encoder_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -48,9 +48,5 @@ SKP_int SKP_Silk_init_encoder_FIX( /* Initialize Silk VAD */ ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD ); - /* Initialize NSQ */ - psEnc->sNSQ.prev_inv_gain_Q16 = 65536; - psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; - return( ret ); } diff --git a/src_FIX/SKP_Silk_main_FIX.h b/src_FIX/SKP_Silk_main_FIX.h index 382443e2e..64c5b8b89 100644 --- a/src_FIX/SKP_Silk_main_FIX.h +++ b/src_FIX/SKP_Silk_main_FIX.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -57,19 +57,15 @@ void SKP_Silk_HP_variable_cutoff_FIX( /* Encoder main function */ SKP_int SKP_Silk_encode_frame_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - SKP_int32 *pnBytesOut, /* I/O Pointer to number of payload bytes; */ - /* input: max length; output: used */ - ec_enc *psRangeEnc, /* I/O compressor data structure */ - const SKP_int16 *pIn /* I Pointer to input speech frame */ + SKP_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */ + ec_enc *psRangeEnc /* I/O compressor data structure */ ); /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ void SKP_Silk_LBRR_encode_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ - SKP_uint8 *pCode, /* O Pointer to payload */ - SKP_int32 *pnBytesOut, /* I/O Pointer to number of payload bytes */ - SKP_int16 xfw[] /* I Input signal */ + const SKP_int16 xfw[] /* I Input signal */ ); /* Initializes the Silk encoder state */ @@ -145,7 +141,7 @@ void SKP_Silk_find_pred_coefs_FIX( /* LPC analysis */ void SKP_Silk_find_LPC_FIX( SKP_int NLSF_Q15[], /* O NLSFs */ - SKP_int *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */ + SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */ const SKP_int prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */ const SKP_int useInterpolatedNLSFs, /* I Flag */ const SKP_int LPC_order, /* I LPC order */ @@ -204,7 +200,7 @@ void SKP_Silk_process_NLSFs_FIX( /* NLSF vector encoder */ void SKP_Silk_NLSF_MSVQ_encode_FIX( - SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ SKP_int *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const SKP_int *pNLSF_q_Q15_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ @@ -220,7 +216,7 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( void SKP_Silk_NLSF_VQ_rate_distortion_FIX( SKP_int32 *pRD_Q20, /* O Rate-distortion values [psNLSF_CBS->nVectors*N] */ const SKP_Silk_NLSF_CBS *psNLSF_CBS, /* I NLSF codebook stage struct */ - const SKP_int *in_Q15, /* I Input vectors to be quantized */ + const SKP_int16 *in_Q15, /* I Input vectors to be quantized */ const SKP_int *w_Q6, /* I Weight vector */ const SKP_int32 *rate_acc_Q5, /* I Accumulated rates from previous stage */ const SKP_int mu_Q15, /* I Weight between weighted error and rate */ @@ -231,7 +227,7 @@ void SKP_Silk_NLSF_VQ_rate_distortion_FIX( /* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */ void SKP_Silk_NLSF_VQ_sum_error_FIX( SKP_int32 *err_Q20, /* O Weighted quantization errors [N*K] */ - const SKP_int *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */ + const SKP_int16 *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */ const SKP_int *w_Q6, /* I Weighting vectors [N*LPC_order] */ const SKP_int8 *pCB_Q9, /* I Codebook vectors [K*LPC_order] */ const SKP_int N, /* I Number of input vectors */ diff --git a/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c b/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c index 151348677..649161d8f 100644 --- a/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c +++ b/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -151,9 +151,8 @@ void SKP_Silk_noise_shape_analysis_FIX( SKP_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; SKP_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ]; SKP_int16 x_windowed[ SHAPE_LPC_WIN_MAX ]; - const SKP_int16 *x_ptr, *pitch_res_ptr; - SKP_int32 sqrt_nrg[ MAX_NB_SUBFR ], Qnrg_vec[ MAX_NB_SUBFR ]; + const SKP_int16 *x_ptr, *pitch_res_ptr; /* Point to start of first LPC analysis block */ x_ptr = x - psEnc->sCmn.la_shape; @@ -162,13 +161,10 @@ void SKP_Silk_noise_shape_analysis_FIX( /* CONTROL SNR */ /****************/ /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */ - psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULWB( SKP_LSHIFT( ( SKP_int32 )psEnc->BufferedInChannel_ms, 7 ), - SKP_FIX_CONST( 0.1, 16 ) ); + psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULBB( psEnc->BufferedInChannel_ms, SKP_FIX_CONST( 0.1, 7 ) ); - /* Reduce SNR_dB if inband FEC used */ - if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) { - psEncCtrl->current_SNR_dB_Q7 -= SKP_RSHIFT( psEnc->inBandFEC_SNR_comp_Q8, 1 ); - } + /* Reduce SNR_dB because of any inband FEC used */ + psEncCtrl->current_SNR_dB_Q7 -= psEnc->inBandFEC_SNR_comp_Q7; /****************/ /* GAIN CONTROL */ @@ -191,7 +187,7 @@ void SKP_Silk_noise_shape_analysis_FIX( SKP_SMULWB( SKP_FIX_CONST( 1.0, 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) ); // Q12 } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Reduce gains for periodic signals */ SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( HARM_SNR_INCR_dB, 8 ), psEnc->LTPCorr_Q15 ); } else { @@ -205,9 +201,9 @@ void SKP_Silk_noise_shape_analysis_FIX( /* SPARSENESS PROCESSING */ /*************************/ /* Set quantizer offset */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Initally set to 0; may be overruled in process_gains(..) */ - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; psEncCtrl->sparseness_Q8 = 0; } else { /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ @@ -232,9 +228,9 @@ void SKP_Silk_noise_shape_analysis_FIX( /* Set quantization offset depending on sparseness measure */ if( psEncCtrl->sparseness_Q8 > SKP_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) { - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; } else { - psEncCtrl->sCmn.quantOffsetType = 1; + psEnc->sCmn.indices.quantOffsetType = 1; } /* Increase coding SNR for sparse signals */ @@ -383,12 +379,12 @@ void SKP_Silk_noise_shape_analysis_FIX( SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEncCtrl->input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) ); #endif strength_Q16 = SKP_RSHIFT( SKP_MUL( strength_Q16, psEnc->speech_activity_Q8 ), 8 ); - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */ /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/ SKP_int fs_kHz_inv = SKP_DIV32_16( SKP_FIX_CONST( 0.2, 14 ), psEnc->sCmn.fs_kHz ); for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { - b_Q14 = fs_kHz_inv + SKP_DIV32_16( SKP_FIX_CONST( 3.0, 14 ), psEncCtrl->sCmn.pitchL[ k ] ); + b_Q14 = fs_kHz_inv + SKP_DIV32_16( SKP_FIX_CONST( 3.0, 14 ), psEncCtrl->pitchL[ k ] ); /* Pack two coefficients in one int32 */ psEncCtrl->LF_shp_Q14[ k ] = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 ); psEncCtrl->LF_shp_Q14[ k ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) ); @@ -420,7 +416,7 @@ void SKP_Silk_noise_shape_analysis_FIX( HarmBoost_Q16 = SKP_SMLAWB( HarmBoost_Q16, SKP_FIX_CONST( 1.0, 16 ) - SKP_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SKP_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) ); - if( USE_HARM_SHAPING && psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* More harmonic noise shaping for high bitrates or noisy input */ HarmShapeGain_Q16 = SKP_SMLAWB( SKP_FIX_CONST( HARMONIC_SHAPING, 16 ), SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULWB( SKP_FIX_CONST( 1.0, 18 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ), diff --git a/src_FIX/SKP_Silk_prefilter_FIX.c b/src_FIX/SKP_Silk_prefilter_FIX.c index 994bac261..58be293f5 100644 --- a/src_FIX/SKP_Silk_prefilter_FIX.c +++ b/src_FIX/SKP_Silk_prefilter_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -106,8 +106,8 @@ void SKP_Silk_prefilter_FIX( lag = P->lagPrev; for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Update Variables that change per sub frame */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - lag = psEncCtrl->sCmn.pitchL[ k ]; + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { + lag = psEncCtrl->pitchL[ k ]; } /* Noise shape parameters */ @@ -144,7 +144,7 @@ void SKP_Silk_prefilter_FIX( pxw += psEnc->sCmn.subfr_length; } - P->lagPrev = psEncCtrl->sCmn.pitchL[ MAX_NB_SUBFR - 1 ]; + P->lagPrev = psEncCtrl->pitchL[ MAX_NB_SUBFR - 1 ]; } /* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal */ diff --git a/src_FIX/SKP_Silk_process_NLSFs_FIX.c b/src_FIX/SKP_Silk_process_NLSFs_FIX.c index 9e41e7573..09e7ba75b 100644 --- a/src_FIX/SKP_Silk_process_NLSFs_FIX.c +++ b/src_FIX/SKP_Silk_process_NLSFs_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -53,7 +53,7 @@ void SKP_Silk_process_NLSFs_FIX( /***********************/ /* Calculate mu values */ /***********************/ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* NLSF_mu = 0.002f - 0.001f * psEnc->speech_activity; */ /* NLSF_mu_fluc_red = 0.1f - 0.05f * psEnc->speech_activity; */ NLSF_mu_Q15 = SKP_SMLAWB( 66, -8388, psEnc->speech_activity_Q8 ); @@ -72,25 +72,21 @@ void SKP_Silk_process_NLSFs_FIX( NLSF_mu_Q15 = SKP_max( NLSF_mu_Q15, 1 ); /* Calculate NLSF weights */ - TIC(NLSF_weights_FIX) SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW_Q6, pNLSF_Q15, psEnc->sCmn.predictLPCOrder ); - TOC(NLSF_weights_FIX) /* Update NLSF weights for interpolated NLSFs */ - doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEncCtrl->sCmn.NLSFInterpCoef_Q2 < ( 1 << 2 ) ); + doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEnc->sCmn.indices.NLSFInterpCoef_Q2 < ( 1 << 2 ) ); if( doInterpolate ) { /* Calculate the interpolated NLSF vector for the first half */ SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, - psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder ); + psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder ); /* Calculate first half NLSF weights for the interpolated NLSFs */ - TIC(NLSF_weights_FIX) SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW0_temp_Q6, pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder ); - TOC(NLSF_weights_FIX) /* Update NLSF weights with contribution from first half */ - i_sqr_Q15 = SKP_LSHIFT( SKP_SMULBB( psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->sCmn.NLSFInterpCoef_Q2 ), 11 ); + i_sqr_Q15 = SKP_LSHIFT( SKP_SMULBB( psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sCmn.indices.NLSFInterpCoef_Q2 ), 11 ); for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) { pNLSFW_Q6[ i ] = SKP_SMLAWB( SKP_RSHIFT( pNLSFW_Q6[ i ], 1 ), pNLSFW0_temp_Q6[ i ], i_sqr_Q15 ); SKP_assert( pNLSFW_Q6[ i ] <= SKP_int16_MAX ); @@ -99,11 +95,11 @@ void SKP_Silk_process_NLSFs_FIX( } /* Set pointer to the NLSF codebook for the current signal type and LPC order */ - psNLSF_CB = psEnc->sCmn.psNLSF_CB[ 1 - ( psEncCtrl->sCmn.signalType >> 1 ) ]; + psNLSF_CB = psEnc->sCmn.psNLSF_CB[ 1 - ( psEnc->sCmn.indices.signalType >> 1 ) ]; /* Quantize NLSF parameters given the trained NLSF codebooks */ TIC(MSVQ_encode_FIX) - SKP_Silk_NLSF_MSVQ_encode_FIX( psEncCtrl->sCmn.NLSFIndices, pNLSF_Q15, psNLSF_CB, + SKP_Silk_NLSF_MSVQ_encode_FIX( psEnc->sCmn.indices.NLSFIndices, pNLSF_Q15, psNLSF_CB, psEnc->sPred.prev_NLSFq_Q15, pNLSFW_Q6, NLSF_mu_Q15, NLSF_mu_fluc_red_Q16, psEnc->sCmn.NLSF_MSVQ_Survivors, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.first_frame_after_reset ); TOC(MSVQ_encode_FIX) @@ -114,7 +110,7 @@ void SKP_Silk_process_NLSFs_FIX( if( doInterpolate ) { /* Calculate the interpolated, quantized LSF vector for the first half */ SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, - psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder ); + psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder ); /* Convert back to LPC coefficients */ SKP_Silk_NLSF2A_stable( psEncCtrl->PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder ); diff --git a/src_FIX/SKP_Silk_process_gains_FIX.c b/src_FIX/SKP_Silk_process_gains_FIX.c index 23ea9ccfb..dfa0980ac 100644 --- a/src_FIX/SKP_Silk_process_gains_FIX.c +++ b/src_FIX/SKP_Silk_process_gains_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -39,7 +39,7 @@ void SKP_Silk_process_gains_FIX( SKP_int32 s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10; /* Gain reduction when LTP coding gain is high */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /*s = -0.5f * SKP_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */ s_Q16 = -SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SKP_FIX_CONST( 12.0, 7 ), 4 ) ); for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { @@ -83,19 +83,19 @@ void SKP_Silk_process_gains_FIX( } /* Noise shaping quantization */ - SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, psEncCtrl->Gains_Q16, - &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, psEnc->sCmn.nb_subfr ); + SKP_Silk_gains_quant( psEnc->sCmn.indices.GainsIndices, psEncCtrl->Gains_Q16, + &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr ); /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) { - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; } else { - psEncCtrl->sCmn.quantOffsetType = 1; + psEnc->sCmn.indices.quantOffsetType = 1; } } /* Quantizer boundary adjustment */ - quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrl->sCmn.signalType >> 1 ][ psEncCtrl->sCmn.quantOffsetType ]; + quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEnc->sCmn.indices.signalType >> 1 ][ psEnc->sCmn.indices.quantOffsetType ]; psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( LAMBDA_OFFSET, 10 ) + SKP_SMULBB( SKP_FIX_CONST( LAMBDA_DELAYED_DECISIONS, 10 ), psEnc->sCmn.nStatesDelayedDecision ) + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_SPEECH_ACT, 18 ), psEnc->speech_activity_Q8 ) diff --git a/src_FIX/SKP_Silk_regularize_correlations_FIX.c b/src_FIX/SKP_Silk_regularize_correlations_FIX.c index fa2e8cd58..f30f631cf 100644 --- a/src_FIX/SKP_Silk_regularize_correlations_FIX.c +++ b/src_FIX/SKP_Silk_regularize_correlations_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_residual_energy16_FIX.c b/src_FIX/SKP_Silk_residual_energy16_FIX.c index 223ad1463..b559ce61a 100644 --- a/src_FIX/SKP_Silk_residual_energy16_FIX.c +++ b/src_FIX/SKP_Silk_residual_energy16_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_residual_energy_FIX.c b/src_FIX/SKP_Silk_residual_energy_FIX.c index 6d538ecbf..2fb531ca8 100644 --- a/src_FIX/SKP_Silk_residual_energy_FIX.c +++ b/src_FIX/SKP_Silk_residual_energy_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -43,7 +43,6 @@ void SKP_Silk_residual_energy_FIX( SKP_int offset, i, j, rshift, lz1, lz2; SKP_int16 *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; const SKP_int16 *x_ptr; - SKP_int16 S[ MAX_LPC_ORDER ]; SKP_int32 tmp32; x_ptr = x; @@ -52,8 +51,7 @@ void SKP_Silk_residual_energy_FIX( /* Filter input to create the LPC residual for each frame half, and measure subframe energies */ for( i = 0; i < nb_subfr >> 1; i++ ) { /* Calculate half frame LPC residual signal including preceeding samples */ - SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) ); - SKP_Silk_LPC_analysis_filter( x_ptr, a_Q12[ i ], S, LPC_res, ( MAX_NB_SUBFR >> 1 ) * offset, LPC_order ); + SKP_Silk_LPC_analysis_filter( LPC_res, x_ptr, a_Q12[ i ], ( MAX_NB_SUBFR >> 1 ) * offset, LPC_order ); /* Point to first subframe of the just calculated LPC residual signal */ LPC_res_ptr = LPC_res + LPC_order; diff --git a/src_FIX/SKP_Silk_solve_LS_FIX.c b/src_FIX/SKP_Silk_solve_LS_FIX.c index f61e9fbcf..256841855 100644 --- a/src_FIX/SKP_Silk_solve_LS_FIX.c +++ b/src_FIX/SKP_Silk_solve_LS_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FIX/SKP_Silk_structs_FIX.h b/src_FIX/SKP_Silk_structs_FIX.h index f422d93b9..0cc048914 100644 --- a/src_FIX/SKP_Silk_structs_FIX.h +++ b/src_FIX/SKP_Silk_structs_FIX.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -41,7 +41,7 @@ extern "C" /* Noise shaping analysis state */ /********************************/ typedef struct { - SKP_int LastGainIndex; + SKP_int8 LastGainIndex; SKP_int32 HarmBoost_smth_Q16; SKP_int32 HarmShapeGain_smth_Q16; SKP_int32 Tilt_smth_Q16; @@ -85,8 +85,6 @@ typedef struct { SKP_Silk_shape_state_FIX sShape; /* Shape state */ SKP_Silk_prefilter_state_FIX sPrefilt; /* Prefilter State */ SKP_Silk_predict_state_FIX sPred; /* Prediction state */ - SKP_Silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ - SKP_Silk_nsq_state sNSQ_LBRR; /* Noise Shape Quantizer State ( for low bitrate redundancy ) */ /* Buffer for find pitch and noise shape analysis */ SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; @@ -99,7 +97,7 @@ typedef struct { SKP_int prevLTPredCodGain_Q7; SKP_int HPLTPredCodGain_Q7; - SKP_int32 inBandFEC_SNR_comp_Q8; /* Compensation to SNR_dB when using inband FEC Voiced */ + SKP_int32 inBandFEC_SNR_comp_Q7; /* Compensation to SNR_dB when using inband FEC Voiced */ } SKP_Silk_encoder_state_FIX; @@ -107,13 +105,12 @@ typedef struct { /* Encoder control FIX */ /************************/ typedef struct { - SKP_Silk_encoder_control sCmn; /* Common struct, shared with floating-point code */ - /* Prediction and coding parameters */ SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; SKP_int LTP_scale_Q14; + SKP_int pitchL[ MAX_NB_SUBFR ]; /* Noise shaping parameters */ /* Testing */ diff --git a/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c b/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c index b9dabed73..380104ff7 100644 --- a/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c +++ b/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c b/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c index 4d3fdfa09..dcac37be6 100644 --- a/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c +++ b/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c b/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c index ae400b5fb..b340f5592 100644 --- a/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c +++ b/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -43,11 +43,11 @@ void SKP_Silk_LPC_analysis_filter16_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 16; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 16; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ @@ -81,11 +81,11 @@ void SKP_Silk_LPC_analysis_filter14_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 14; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 14; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ @@ -117,11 +117,11 @@ void SKP_Silk_LPC_analysis_filter12_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 12; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 12; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ @@ -151,11 +151,11 @@ void SKP_Silk_LPC_analysis_filter10_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 10; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 10; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ @@ -183,11 +183,11 @@ void SKP_Silk_LPC_analysis_filter8_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 8; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 8; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ @@ -213,11 +213,11 @@ void SKP_Silk_LPC_analysis_filter6_FLP( const SKP_int length /* I Length of input signal */ ) { - SKP_int ix = 6; + SKP_int ix; SKP_float LPC_pred; const SKP_float *s_ptr; - for ( ; ix < length; ix++) { + for ( ix = 6; ix < length; ix++) { s_ptr = &s[ix - 1]; /* short-term prediction */ diff --git a/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c b/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c index 1b565c743..b27b08d44 100644 --- a/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c +++ b/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c b/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c index 5039d54d4..b94d2fe4e 100644 --- a/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c +++ b/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main_FLP.h" #define NB_THRESHOLDS 11 + /* Table containing trained thresholds for LTP scaling */ static const SKP_float LTPScaleThresholds[ NB_THRESHOLDS ] = { @@ -41,7 +42,7 @@ void SKP_Silk_LTP_scale_ctrl_FLP( SKP_Silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ ) { - SKP_int round_loss, frames_per_packet; + SKP_int round_loss; SKP_float g_out, g_limit, thrld1, thrld2; /* 1st order high-pass filter */ @@ -57,28 +58,26 @@ void SKP_Silk_LTP_scale_ctrl_FLP( /* Default is minimum scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 0; + psEnc->sCmn.indices.LTP_scaleIndex = 0; /* Round the loss measure to whole pct */ round_loss = ( SKP_int )( psEnc->sCmn.PacketLoss_perc ); round_loss = SKP_max( 0, round_loss ); - /* Only scale if first frame in packet 0% */ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ){ + /* Only scale if first frame in packet */ + if( psEnc->sCmn.nFramesAnalyzed == 0 ){ - frames_per_packet = psEnc->sCmn.PacketSize_ms / ( SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr ); - - round_loss += ( frames_per_packet - 1 ); + round_loss += psEnc->sCmn.nFramesPerPacket - 1; thrld1 = LTPScaleThresholds[ SKP_min_int( round_loss, NB_THRESHOLDS - 1 ) ]; thrld2 = LTPScaleThresholds[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ]; if( g_limit > thrld1 ) { /* High Scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 2; + psEnc->sCmn.indices.LTP_scaleIndex = 2; } else if( g_limit > thrld2 ) { /* Middle Scaling */ - psEncCtrl->sCmn.LTP_scaleIndex = 1; + psEnc->sCmn.indices.LTP_scaleIndex = 1; } } - psEncCtrl->LTP_scale = ( SKP_float)SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ] / 16384.0f; + psEncCtrl->LTP_scale = ( SKP_float)SKP_Silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ] / 16384.0f; } diff --git a/src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c b/src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c index 977472361..652537143 100644 --- a/src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c +++ b/src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void SKP_Silk_NLSF_MSVQ_decode_FLP( SKP_float *pNLSF, /* O Decoded output vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I NLSF codebook struct */ - const SKP_int *NLSFIndices, /* I NLSF indices [ nStages ] */ + const SKP_int8 *NLSFIndices, /* I NLSF indices [ nStages ] */ const SKP_int LPC_order /* I LPC order used */ ) { @@ -43,7 +43,7 @@ void SKP_Silk_NLSF_MSVQ_decode_FLP( SKP_assert( 0 <= NLSFIndices[ 0 ] && NLSFIndices[ 0 ] < psNLSF_CB->CBStages[ 0 ].nVectors ); /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q8[ SKP_MUL( NLSFIndices[ 0 ], LPC_order ) ]; + pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q8[ SKP_SMULBB( (SKP_int)NLSFIndices[ 0 ], LPC_order ) ]; /* Initialize with the codebook vector from stage 0 */ for( i = 0; i < LPC_order; i++ ) { @@ -56,7 +56,7 @@ void SKP_Silk_NLSF_MSVQ_decode_FLP( if( LPC_order == 16 ) { /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ SKP_LSHIFT( NLSFIndices[ s ], 4 ) ]; + pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ 16 * (SKP_int)NLSFIndices[ s ] ]; /* Add the codebook vector from the current stage */ pNLSF[ 0 ] += ( SKP_float )pCB_element[ 0 ]; @@ -77,7 +77,7 @@ void SKP_Silk_NLSF_MSVQ_decode_FLP( pNLSF[ 15 ] += ( SKP_float )pCB_element[ 15 ]; } else { /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ NLSFIndices[ s ] * LPC_order ]; + pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ (SKP_int)NLSFIndices[ s ] * LPC_order ]; /* Add the codebook vector from the current stage */ for( i = 0; i < LPC_order; i++ ) { diff --git a/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c b/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c index 585bf7770..416a1cedc 100644 --- a/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c +++ b/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* NLSF vector encoder */ /***********************/ void SKP_Silk_NLSF_MSVQ_encode_FLP( - SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ SKP_float *pNLSF, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const SKP_float *pNLSF_q_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ @@ -53,15 +53,15 @@ void SKP_Silk_NLSF_MSVQ_encode_FLP( SKP_float pRate[ MAX_NLSF_MSVQ_SURVIVORS ]; SKP_float pRate_new[ MAX_NLSF_MSVQ_SURVIVORS ]; SKP_int pTempIndices[ MAX_NLSF_MSVQ_SURVIVORS ]; - SKP_int pPath[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; - SKP_int pPath_new[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int8 pPath[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int8 pPath_new[ MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ]; SKP_float pRes_Q8[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; SKP_float pRes_Q8_new[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; const SKP_float *pConstFloat; SKP_float *pFloat; - const SKP_int *pConstInt; - SKP_int *pInt; + const SKP_int8 *pConstInt8; + SKP_int8 *pInt8; const SKP_int8 *pCB_element; const SKP_Silk_NLSF_CBS *pCurrentCBStage; @@ -150,13 +150,13 @@ void SKP_Silk_NLSF_MSVQ_encode_FLP( pRate_new[ k ] = pRate[ input_index ] + 0.0625f * ( SKP_float )pCurrentCBStage->Rates_Q4[ cb_index ]; /* Copy paths from previous matrix, starting with the best path */ - pConstInt = &pPath[ input_index * psNLSF_CB->nStages ]; - pInt = &pPath_new[ k * psNLSF_CB->nStages ]; + pConstInt8 = &pPath[ input_index * psNLSF_CB->nStages ]; + pInt8 = &pPath_new[ k * psNLSF_CB->nStages ]; for( i = 0; i < s; i++ ) { - pInt[ i ] = pConstInt[ i ]; + pInt8[ i ] = pConstInt8[ i ]; } /* Write the current stage indices for the 'cur_survivors' to the best path matrix */ - pInt[ s ] = cb_index; + pInt8[ s ] = (SKP_int8)cb_index; } if( s < psNLSF_CB->nStages - 1 ) { @@ -167,7 +167,7 @@ void SKP_Silk_NLSF_MSVQ_encode_FLP( SKP_memcpy( pRate, pRate_new, cur_survivors * sizeof( SKP_float ) ); /* Copy best path matrix for next stage */ - SKP_memcpy( pPath, pPath_new, cur_survivors * psNLSF_CB->nStages * sizeof( SKP_int ) ); + SKP_memcpy( pPath, pPath_new, cur_survivors * psNLSF_CB->nStages * sizeof( SKP_int8) ); } prev_survivors = cur_survivors; @@ -213,7 +213,7 @@ void SKP_Silk_NLSF_MSVQ_encode_FLP( #endif /* Copy best path to output argument */ - SKP_memcpy( NLSFIndices, &pPath_new[ bestIndex * psNLSF_CB->nStages ], psNLSF_CB->nStages * sizeof( SKP_int ) ); + SKP_memcpy( NLSFIndices, &pPath_new[ bestIndex * psNLSF_CB->nStages ], psNLSF_CB->nStages * sizeof( SKP_int8 ) ); /* Decode and stabilize the best survivor */ SKP_Silk_NLSF_MSVQ_decode_FLP( pNLSF, psNLSF_CB, NLSFIndices, LPC_order ); diff --git a/src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c b/src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c index 5b92da14f..c45b683bc 100644 --- a/src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c +++ b/src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c b/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c index 78db9b7f1..6e4df1628 100644 --- a/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c +++ b/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_apply_sine_window_FLP.c b/src_FLP/SKP_Silk_apply_sine_window_FLP.c index 17e8f1c55..1db6b1473 100644 --- a/src_FLP/SKP_Silk_apply_sine_window_FLP.c +++ b/src_FLP/SKP_Silk_apply_sine_window_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_assembler_FLP.h b/src_FLP/SKP_Silk_assembler_FLP.h index d949c6767..e4129ad3e 100644 --- a/src_FLP/SKP_Silk_assembler_FLP.h +++ b/src_FLP/SKP_Silk_assembler_FLP.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_control_codec_FLP.c b/src_FLP/SKP_Silk_control_codec_FLP.c index 45440d646..028729c1b 100644 --- a/src_FLP/SKP_Silk_control_codec_FLP.c +++ b/src_FLP/SKP_Silk_control_codec_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "SKP_Silk_main_FLP.h" -#include "SKP_Silk_setup_complexity.h" +#include "SKP_Silk_setup.h" SKP_INLINE SKP_int SKP_Silk_setup_resamplers( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ @@ -41,11 +41,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( SKP_INLINE SKP_int SKP_Silk_setup_rate( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ - SKP_int TargetRate_bps /* I Target max bitrate */ -); - -SKP_INLINE SKP_int SKP_Silk_setup_LBRR( - SKP_Silk_encoder_state_FLP *psEnc /* I/O Pointer to Silk encoder state FLP */ + SKP_int32 TargetRate_bps /* I Target max bitrate */ ); /* Control encoder */ @@ -105,7 +101,7 @@ SKP_int SKP_Silk_control_encoder_FLP( /********************************************/ /* Set LBRR usage */ /********************************************/ - ret += SKP_Silk_setup_LBRR( psEnc ); + ret += SKP_Silk_setup_LBRR( &psEnc->sCmn ); psEnc->sCmn.controlled_since_last_payload = 1; @@ -186,6 +182,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( } if( PacketSize_ms == 10 ) { /* Only allowed when the payload buffer is empty */ + psEnc->sCmn.nFramesPerPacket = 1; 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 ); if( psEnc->sCmn.fs_kHz == 8 ) { @@ -194,6 +191,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF; } } else { + psEnc->sCmn.nFramesPerPacket = SKP_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS ); psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); if( psEnc->sCmn.fs_kHz == 8 ) { @@ -203,21 +201,18 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( } } psEnc->sCmn.PacketSize_ms = PacketSize_ms; - psEnc->sCmn.LBRR_nBytes = 0; } /* 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_FLP ) ); - SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FLP ) ); - SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) ); - SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FLP ) ); - 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->sPred.prev_NLSFq, 0, MAX_LPC_ORDER * sizeof( SKP_float ) ); + SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FLP ) ); + SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FLP ) ); + SKP_memset( &psEnc->sCmn.sNSQ, 0, sizeof( SKP_Silk_nsq_state ) ); + SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FLP ) ); + SKP_memset( psEnc->sPred.prev_NLSFq, 0, sizeof( psEnc->sPred.prev_NLSFq ) ); #if SWITCH_TRANSITION_FILTERING - SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) ); if( psEnc->sCmn.sLP.mode == 1 ) { /* Begin transition phase */ psEnc->sCmn.sLP.transition_frame_no = 1; @@ -226,20 +221,17 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( psEnc->sCmn.sLP.transition_frame_no = 0; } #endif - psEnc->sCmn.LBRR_nBytes = 0; psEnc->sCmn.inputBufIx = 0; - psEnc->sCmn.nFramesInPayloadBuf = 0; - psEnc->sCmn.nBytesInPayloadBuf = 0; + psEnc->sCmn.nFramesAnalyzed = 0; psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */ /* Initialize non-zero parameters */ - psEnc->sCmn.prevLag = 100; - psEnc->sCmn.first_frame_after_reset = 1; - psEnc->sPrefilt.lagPrev = 100; - psEnc->sShape.LastGainIndex = 1; - psEnc->sNSQ.lagPrev = 100; - psEnc->sNSQ.prev_inv_gain_Q16 = 65536; - psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; + psEnc->sCmn.prevLag = 100; + psEnc->sCmn.first_frame_after_reset = 1; + psEnc->sPrefilt.lagPrev = 100; + psEnc->sShape.LastGainIndex = 10; + psEnc->sCmn.sNSQ.lagPrev = 100; + psEnc->sCmn.sNSQ.prev_inv_gain_Q16 = 65536; psEnc->sCmn.fs_kHz = fs_kHz; if( psEnc->sCmn.fs_kHz == 8 ) { @@ -300,7 +292,6 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( /* unsupported sampling rate */ SKP_assert( 0 ); } - psEnc->sCmn.fs_kHz_changed = 1; } /* Check that settings are valid */ @@ -311,12 +302,12 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs( SKP_INLINE SKP_int SKP_Silk_setup_rate( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ - SKP_int TargetRate_bps /* I Target max bitrate */ + SKP_int32 TargetRate_bps /* I Target max bitrate */ ) { SKP_int k, ret = SKP_SILK_NO_ERROR; SKP_float frac; - const SKP_uint16 *rateTable; + const SKP_int32 *rateTable; /* Set bitrate/coding quality */ if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) { @@ -338,7 +329,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_rate( } for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { /* Find bitrate interval in table and interpolate */ - if( TargetRate_bps < rateTable[ k ] ) { + if( TargetRate_bps <= rateTable[ k ] ) { frac = (SKP_float)( TargetRate_bps - rateTable[ k - 1 ] ) / (SKP_float)( rateTable[ k ] - rateTable[ k - 1 ] ); psEnc->SNR_dB = 0.5f * ( SNR_table_Q1[ k - 1 ] + frac * ( SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] ) ); @@ -348,55 +339,3 @@ SKP_INLINE SKP_int SKP_Silk_setup_rate( } return( ret ); } - -SKP_INLINE SKP_int SKP_Silk_setup_LBRR( - SKP_Silk_encoder_state_FLP *psEnc /* I/O Pointer to Silk encoder state FLP */ -) -{ - SKP_int ret = SKP_SILK_NO_ERROR; - -#if USE_LBRR - SKP_int32 LBRRRate_thres_bps; - - if( psEnc->sCmn.useInBandFEC < 0 || psEnc->sCmn.useInBandFEC > 1 ) { - ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; - } - - psEnc->sCmn.LBRR_enabled = psEnc->sCmn.useInBandFEC; - if( psEnc->sCmn.fs_kHz == 8 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000; - } else { - LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS; - } - - if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) { - /* Set gain increase / rate reduction for LBRR usage */ - /* Coarsely tuned with PESQ for now. */ - /* Linear regression coefs G = 8 - 0.5 * loss */ - /* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */ - psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 ); - - /* Set main stream rate compensation */ - if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { - /* Tuned to give approx same mean / weighted bitrate as no inband FEC */ - psEnc->inBandFEC_SNR_comp = 6.0f - 0.5f * psEnc->sCmn.LBRR_GainIncreases; - } else { - psEnc->inBandFEC_SNR_comp = 0; - psEnc->sCmn.LBRR_enabled = 0; - } - } else { - psEnc->inBandFEC_SNR_comp = 0; - psEnc->sCmn.LBRR_enabled = 0; - } -#else - if( psEnc->sCmn.LBRR_enabled != 0 ) { - ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; - psEnc->sCmn.LBRR_enabled = 0; - } -#endif - return ret; -} diff --git a/src_FLP/SKP_Silk_corrMatrix_FLP.c b/src_FLP/SKP_Silk_corrMatrix_FLP.c index 996e20de1..0fdaabd05 100644 --- a/src_FLP/SKP_Silk_corrMatrix_FLP.c +++ b/src_FLP/SKP_Silk_corrMatrix_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_encode_frame_FLP.c b/src_FLP/SKP_Silk_encode_frame_FLP.c index b2a903752..b87def7ad 100644 --- a/src_FLP/SKP_Silk_encode_frame_FLP.c +++ b/src_FLP/SKP_Silk_encode_frame_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -34,22 +34,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SKP_int SKP_Silk_encode_frame_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ SKP_int32 *pnBytesOut, /* O Number of payload bytes */ - ec_enc *psRangeEnc, /* I/O compressor data structure */ - const SKP_int16 *pIn /* I Input speech frame */ + ec_enc *psRangeEnc /* I/O compressor data structure */ ) { SKP_Silk_encoder_control_FLP sEncCtrl; - SKP_int k, i, nBytes, ret = 0; + SKP_int i, nBits, ret = 0; + SKP_uint8 flags; SKP_float *x_frame, *res_pitch_frame; - SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ]; - SKP_int16 pIn_HP_LP[ MAX_FRAME_LENGTH ]; - SKP_float xfw[ MAX_FRAME_LENGTH ]; + SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ]; + SKP_float xfw[ MAX_FRAME_LENGTH ]; SKP_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; - SKP_int frame_terminator; TIC(ENCODE_FRAME) - sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3; + if( psEnc->sCmn.nFramesAnalyzed == 0 ) { + /* Create space at start of payload for VAD and FEC flags */ + SKP_uint8 iCDF[ 2 ] = { 0, 0 }; + iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 ); + ec_enc_icdf( psRangeEnc, 0, iCDF, 8 ); + + /* Encode any LBRR data from previous packet */ + SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc ); + + /* Reduce coding SNR depending on how many bits used by LBRR */ + nBits = ec_tell( psRangeEnc ); + psEnc->inBandFEC_SNR_comp = ( 6.0f * nBits ) / + ( psEnc->sCmn.nFramesPerPacket * psEnc->sCmn.frame_length ); + + /* Reset LBRR flags */ + SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) ); + } + + psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; + /**************************************************************/ /* Setup Input Pointers, and insert frame in input buffer */ /*************************************************************/ @@ -61,14 +78,14 @@ TIC(ENCODE_FRAME) /* Voice Activity Detection */ /****************************/ TIC(VAD) - SKP_Silk_VAD_FLP( psEnc, &sEncCtrl, pIn ); + SKP_Silk_VAD_FLP( psEnc, &sEncCtrl, psEnc->sCmn.inputBuf ); TOC(VAD) /**************************************************/ /* Convert speech activity into VAD and DTX flags */ /**************************************************/ if( psEnc->speech_activity < SPEECH_ACTIVITY_DTX_THRES ) { - sEncCtrl.sCmn.signalType = TYPE_NO_VOICE_ACTIVITY; + psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; psEnc->sCmn.noSpeechCounter++; if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) { psEnc->sCmn.inDTX = 1; @@ -77,10 +94,12 @@ TOC(VAD) psEnc->sCmn.noSpeechCounter = 0; psEnc->sCmn.inDTX = 0; } + psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 0; } else { psEnc->sCmn.noSpeechCounter = 0; psEnc->sCmn.inDTX = 0; - sEncCtrl.sCmn.signalType = TYPE_UNVOICED; + psEnc->sCmn.indices.signalType = TYPE_UNVOICED; + psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1; } /*******************************************/ @@ -89,27 +108,25 @@ TOC(VAD) TIC(HP_IN) #if HIGH_PASS_INPUT /* Variable high-pass filter */ - SKP_Silk_HP_variable_cutoff_FLP( psEnc, &sEncCtrl, pIn_HP, pIn ); + SKP_Silk_HP_variable_cutoff_FLP( psEnc, &sEncCtrl, pIn_HP, psEnc->sCmn.inputBuf ); #else - SKP_memcpy( pIn_HP, pIn, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + SKP_memcpy( pIn_HP, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); #endif TOC(HP_IN) #if SWITCH_TRANSITION_FILTERING /* Ensure smooth bandwidth transitions */ - SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, pIn_HP_LP, pIn_HP, psEnc->sCmn.frame_length ); -#else - SKP_memcpy( pIn_HP_LP, pIn_HP, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, pIn_HP, psEnc->sCmn.frame_length ); #endif /*******************************************/ /* Copy new frame to front of input buffer */ /*******************************************/ - SKP_short2float_array( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP_LP, psEnc->sCmn.frame_length ); + SKP_short2float_array( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP, psEnc->sCmn.frame_length ); /* Add tiny signal to avoid high CPU load from denormalized floating point numbers */ - for( k = 0; k < 8; k++ ) { - x_frame[ LA_SHAPE_MS * psEnc->sCmn.fs_kHz + k * ( psEnc->sCmn.frame_length >> 3 ) ] += ( 1 - ( k & 2 ) ) * 1e-6f; + for( i = 0; i < 8; i++ ) { + x_frame[ LA_SHAPE_MS * psEnc->sCmn.fs_kHz + i * ( psEnc->sCmn.frame_length >> 3 ) ] += ( 1 - ( i & 2 ) ) * 1e-6f; } /*****************************************/ @@ -147,38 +164,45 @@ TIC(PROCESS_GAINS) SKP_Silk_process_gains_FLP( psEnc, &sEncCtrl ); TOC(PROCESS_GAINS) - psEnc->sCmn.quantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.quantOffsetType; - psEnc->sCmn.signalType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.signalType; - /****************************************/ /* Low Bitrate Redundant Encoding */ /****************************************/ - psEnc->sCmn.LBRR_nBytes = MAX_ARITHM_BYTES; TIC(LBRR) - //SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, psEnc->sCmn.LBRR_payload, &psEnc->sCmn.LBRR_nBytes, xfw ); + SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, xfw ); TOC(LBRR) /*****************************************/ /* Noise shaping quantization */ /*****************************************/ TIC(NSQ) - SKP_Silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, xfw, &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * MAX_FRAME_LENGTH ], 0 ); + SKP_Silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, xfw ); TOC(NSQ) - /****************************************/ - /* Initialize range coder */ - /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - psEnc->sCmn.nBytesInPayloadBuf = 0; - } - /****************************************/ /* Encode Parameters */ /****************************************/ TIC(ENCODE_PARAMS) - SKP_Silk_encode_indices( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc ); + SKP_Silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesAnalyzed, 0 ); TOC(ENCODE_PARAMS) + /****************************************/ + /* Encode Excitation Signal */ + /****************************************/ +TIC(ENCODE_PULSES) + SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, + psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); +TOC(ENCODE_PULSES) + + /****************************************/ + /* Simulate network buffer delay caused */ + /* by exceeding TargetRate */ + /****************************************/ + nBits = ec_tell( psRangeEnc ); + psEnc->BufferedInChannel_ms += 1000.0f * ( nBits - psEnc->sCmn.prev_nBits ) / psEnc->sCmn.TargetRate_bps; + psEnc->BufferedInChannel_ms -= psEnc->sCmn.nb_subfr * SUB_FRAME_LENGTH_MS; + psEnc->BufferedInChannel_ms = SKP_LIMIT_float( psEnc->BufferedInChannel_ms, 0.0f, 100.0f ); + psEnc->sCmn.prev_nBits = nBits; + /****************************************/ /* Update Buffers and State */ /****************************************/ @@ -187,65 +211,49 @@ TOC(ENCODE_PARAMS) ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_float ) ); /* Parameters needed for next frame */ - psEnc->sCmn.prevSignalType = sEncCtrl.sCmn.signalType; - psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; + psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; + psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; psEnc->sCmn.first_frame_after_reset = 0; - psEnc->sCmn.nFramesInPayloadBuf++; + psEnc->sCmn.nFramesAnalyzed++; /****************************************/ - /* Finalize payload and copy to output */ + /* Finalize payload */ /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) { - - /* Check if FEC information should be added */ - //frame_terminator = psEnc->sCmn.LBRR_usage; - frame_terminator = SKP_SILK_NO_LBRR; - - /* Add the frame termination info to stream */ - ec_enc_icdf( psRangeEnc, frame_terminator, SKP_Silk_LBRR_Present_iCDF, 8 ); - - /* Code excitation signal */ - for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ], - &psEnc->sCmn.q[ i * MAX_FRAME_LENGTH ], psEnc->sCmn.frame_length ); + if( psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) { + /* Insert VAD flags and FEC flag at beginning of bitstream */ + flags = 0; + for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) { + flags |= psEnc->sCmn.VAD_flags[i]; + flags = SKP_LSHIFT( flags, 1 ); } + flags |= psEnc->sCmn.LBRR_flag; + ret = ec_enc_patch_initial_bits( psRangeEnc, flags, psEnc->sCmn.nFramesPerPacket + 1 ); + SKP_assert( ret == 0 ); - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); - *pnBytesOut = nBytes; + /* Payload size */ + nBits = ec_tell( psRangeEnc ); + *pnBytesOut = SKP_RSHIFT( nBits + 7, 3 ); /* Reset the number of frames in payload buffer */ - psEnc->sCmn.nFramesInPayloadBuf = 0; + psEnc->sCmn.nFramesAnalyzed = 0; + psEnc->sCmn.prev_nBits = 0; } else { /* No payload this time */ *pnBytesOut = 0; - - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); - - /* Take into account the q signal that isn't in the bitstream yet */ - nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, - &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * MAX_FRAME_LENGTH ] ); } - - /* Simulate number of ms buffered in channel because of exceeding TargetRate */ - psEnc->BufferedInChannel_ms += ( 8.0f * 1000.0f * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ) ) / psEnc->sCmn.TargetRate_bps; - psEnc->BufferedInChannel_ms -= SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ); - psEnc->BufferedInChannel_ms = SKP_LIMIT_float( psEnc->BufferedInChannel_ms, 0.0f, 100.0f ); - psEnc->sCmn.nBytesInPayloadBuf = nBytes; - TOC(ENCODE_FRAME) + #ifdef SAVE_ALL_INTERNAL_DATA //DEBUG_STORE_DATA( xf.dat, pIn_HP_LP, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); //DEBUG_STORE_DATA( xfw.dat, xfw, psEnc->sCmn.frame_length * sizeof( SKP_float ) ); - DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.sCmn.pitchL, MAX_NB_SUBFR * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.pitchL, MAX_NB_SUBFR * sizeof( SKP_int ) ); DEBUG_STORE_DATA( pitchG_quantized.dat, sEncCtrl.LTPCoef, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( SKP_float ) ); DEBUG_STORE_DATA( pitch_freq_low_Hz.dat, &sEncCtrl.pitch_freq_low_Hz, sizeof( SKP_float ) ); DEBUG_STORE_DATA( LTPcorr.dat, &psEnc->LTPCorr, sizeof( SKP_float ) ); DEBUG_STORE_DATA( tilt.dat, &sEncCtrl.input_tilt, sizeof( SKP_float ) ); DEBUG_STORE_DATA( gains.dat, sEncCtrl.Gains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); DEBUG_STORE_DATA( gains_indices.dat, &sEncCtrl.sCmn.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); - DEBUG_STORE_DATA( nBytes.dat, &nBytes, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( nBits.dat, &nBits, sizeof( SKP_int ) ); DEBUG_STORE_DATA( current_SNR_db.dat, &sEncCtrl.current_SNR_dB, sizeof( SKP_float ) ); DEBUG_STORE_DATA( quantOffsetType.dat, &sEncCtrl.sCmn.quantOffsetType, sizeof( SKP_int ) ); DEBUG_STORE_DATA( speech_activity.dat, &psEnc->speech_activity, sizeof( SKP_float ) ); @@ -257,165 +265,63 @@ TOC(ENCODE_FRAME) DEBUG_STORE_DATA( per_index.dat, &sEncCtrl.sCmn.PERIndex, sizeof( SKP_int ) ); DEBUG_STORE_DATA( PredCoef.dat, &sEncCtrl.PredCoef[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); DEBUG_STORE_DATA( ltp_scale_idx.dat, &sEncCtrl.sCmn.LTP_scaleIndex, sizeof( SKP_int ) ); -// DEBUG_STORE_DATA( xq.dat, psEnc->sNSQ.xqBuf, psEnc->sCmn.frame_length * sizeof( SKP_float ) ); +// DEBUG_STORE_DATA( xq.dat, psEnc->sCmn.sNSQ.xqBuf, psEnc->sCmn.frame_length * sizeof( SKP_float ) ); #endif return( ret ); } -#if 0 -/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ +/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */ void SKP_Silk_LBRR_encode_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - SKP_uint8 *pCode, /* O Payload */ - SKP_int16 *pnBytesOut, /* I/O Payload bytes; in: max; out: used */ const SKP_float xfw[] /* I Input signal */ ) { + SKP_int k; SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; - SKP_int i, k, TempGainsIndices[ MAX_NB_SUBFR ], frame_terminator; - SKP_int nBytes, nFramesInPayloadBuf; SKP_float TempGains[ MAX_NB_SUBFR ]; - SKP_int typeOffset, LTP_scaleIndex, Rate_only_parameters = 0; - ec_byte_buffer range_enc_celt_buf; + SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesAnalyzed ]; + SKP_Silk_nsq_state sNSQ_LBRR; /*******************************************/ /* Control use of inband LBRR */ /*******************************************/ - psEnc->sCmn.LBRR_usage = SKP_SILK_NO_LBRR; - if( psEnc->sCmn.LBRR_enabled ) { - /* Control LBRR based on sensitivity and packet loss caracteristics */ - if( psEnc->speech_activity > LBRR_SPEECH_ACTIVITY_THRES && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { - psEnc->sCmn.LBRR_usage = SKP_SILK_LBRR; - } + if( psEnc->sCmn.LBRR_enabled && psEnc->speech_activity > LBRR_SPEECH_ACTIVITY_THRES ) { + psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1; + + /* Copy noise shaping quantizer state and quantization indices from regular encoding */ + SKP_memcpy( &sNSQ_LBRR, &psEnc->sCmn.sNSQ, sizeof( SKP_Silk_nsq_state ) ); + SKP_memcpy( psIndices_LBRR, &psEnc->sCmn.indices, sizeof( SideInfoIndices ) ); /* Save original gains */ - SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, MAX_NB_SUBFR * sizeof( SKP_int ) ); - SKP_memcpy( TempGains, psEncCtrl->Gains, MAX_NB_SUBFR * sizeof( SKP_float ) ); - - typeOffset = psEnc->sCmn.typeOffsetPrev; // Temp save as cannot be overwritten - LTP_scaleIndex = psEncCtrl->sCmn.LTP_scaleIndex; - - /* Set max rate where quant signal is encoded */ - if( psEnc->sCmn.fs_kHz == 8 ) { - Rate_only_parameters = 13500; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - Rate_only_parameters = 15500; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - Rate_only_parameters = 17500; - } else { - SKP_assert( 0 ); - } + SKP_memcpy( TempGains, psEncCtrl->Gains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); - if( psEnc->sCmn.Complexity >= 4 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) { - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - /* First frame in packet copy everything */ - SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) ); - psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; - /* Increase Gains to get target LBRR rate */ - psEncCtrl->sCmn.GainsIndices[ 0 ] += psEnc->sCmn.LBRR_GainIncreases; - psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT_int( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 ); - } - /* Decode to get gains in sync with decoder */ - SKP_Silk_gains_dequant( Gains_Q16, psEncCtrl->sCmn.GainsIndices, - &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, psEnc->sCmn.nb_subfr ); - - /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ - for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { - psEncCtrl->Gains[ k ] = Gains_Q16[ k ] / 65536.0f; - } - - /*****************************************/ - /* Noise shaping quantization */ - /*****************************************/ - SKP_Silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, xfw, &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * MAX_FRAME_LENGTH ], 1 ); - } else { - SKP_memset( &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * MAX_FRAME_LENGTH ], 0, psEnc->sCmn.frame_length * sizeof( SKP_int8 ) ); - psEncCtrl->sCmn.LTP_scaleIndex = 0; - } - /****************************************/ - /* Initialize arithmetic coder */ - /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES ); - - SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR ); - psEnc->sCmn.nBytesInPayloadBuf = 0; - } - /****************************************/ - /* Encode Parameters */ - /****************************************/ - SKP_Silk_encode_indices( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR ); + if( psEnc->sCmn.nFramesAnalyzed == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed - 1 ] == 0 ) { + /* First frame in packet or previous frame not LBRR coded */ + psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; - if( psEnc->sCmn.sRC_LBRR.error ) { - /* Encoder returned error: Clear payload buffer */ - nFramesInPayloadBuf = 0; - } else { - nFramesInPayloadBuf = psEnc->sCmn.nFramesInPayloadBuf + 1; + /* Increase Gains to get target LBRR rate */ + psIndices_LBRR->GainsIndices[ 0 ] += psEnc->sCmn.LBRR_GainIncreases; + psIndices_LBRR->GainsIndices[ 0 ] = SKP_min_int( psIndices_LBRR->GainsIndices[ 0 ], N_LEVELS_QGAIN - 1 ); } - /****************************************/ - /* Finalize payload and copy to output */ - /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) { - - /* Check if FEC information should be added */ - 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 ); - - /*********************************************/ - /* Encode quantization indices of excitation */ - /*********************************************/ - for( i = 0; i < nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ], - &psEnc->sCmn.q_LBRR[ i * MAX_FRAME_LENGTH ], psEnc->sCmn.frame_length ); - } - - /* Payload length so far */ - nBytes = SKP_RSHIFT( ec_tell( psRangeEnc_LBRR ) + 7, 3 ); - - /* Check that there is enough space in external output buffer and move data */ - if( *pnBytesOut >= nBytes ) { - SKP_int bits_in_stream, mask; - bits_in_stream = ec_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state ); - ec_enc_done( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state ); - - /* Fill up any remaining bits in the last byte with 1s */ - if( bits_in_stream & 7 ) { - mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 ); - if( nBytes - 1 < *pnBytesOut ) { - psEnc->sCmn.sRC_LBRR.range_enc_celt_state.buf->buf[ nBytes - 1 ] |= mask; - } - } - SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) ); - - *pnBytesOut = nBytes; - } else { - /* Not enough space: payload will be discarded */ - *pnBytesOut = 0; - SKP_assert( 0 ); - } - } else { - /* No payload this time */ - *pnBytesOut = 0; - - /* 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 ); + /* Decode to get gains in sync with decoder */ + SKP_Silk_gains_dequant( Gains_Q16, psIndices_LBRR->GainsIndices, + &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr ); + + /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + psEncCtrl->Gains[ k ] = Gains_Q16[ k ] / 65536.0f; } + /*****************************************/ + /* Noise shaping quantization */ + /*****************************************/ + SKP_Silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, psIndices_LBRR, &sNSQ_LBRR, + psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesAnalyzed ], xfw ); + /* Restore original Gains */ - SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); - SKP_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); - - /* Restore LTP scale index and typeoffset */ - psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex; - psEnc->sCmn.typeOffsetPrev = typeOffset; + SKP_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) ); } } -#endif diff --git a/src_FLP/SKP_Silk_find_LPC_FLP.c b/src_FLP/SKP_Silk_find_LPC_FLP.c index e5ffa7e47..8f6be16ac 100644 --- a/src_FLP/SKP_Silk_find_LPC_FLP.c +++ b/src_FLP/SKP_Silk_find_LPC_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void SKP_Silk_find_LPC_FLP( SKP_float NLSF[], /* O NLSFs */ - SKP_int *interpIndex, /* O NLSF interp. index for NLSF interp. */ + SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */ const SKP_float prev_NLSFq[], /* I Previous NLSFs, for NLSF interpolation */ const SKP_int useInterpNLSFs, /* I Flag */ const SKP_int LPC_order, /* I LPC order */ @@ -82,7 +82,7 @@ void SKP_Silk_find_LPC_FLP( if( res_nrg_interp < res_nrg ) { /* Interpolation has lower residual energy */ res_nrg = res_nrg_interp; - *interpIndex = k; + *interpIndex = (SKP_int8)k; } else if( res_nrg_interp > res_nrg_2nd ) { /* No reason to continue iterating - residual energies will continue to climb */ break; diff --git a/src_FLP/SKP_Silk_find_LTP_FLP.c b/src_FLP/SKP_Silk_find_LTP_FLP.c index 155105f88..1238498d2 100644 --- a/src_FLP/SKP_Silk_find_LTP_FLP.c +++ b/src_FLP/SKP_Silk_find_LTP_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_find_pitch_lags_FLP.c b/src_FLP/SKP_Silk_find_pitch_lags_FLP.c index 01e83486f..f35899d5a 100644 --- a/src_FLP/SKP_Silk_find_pitch_lags_FLP.c +++ b/src_FLP/SKP_Silk_find_pitch_lags_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -99,9 +99,8 @@ void SKP_Silk_find_pitch_lags_FLP( /* LPC analysis filtering */ /*****************************************/ SKP_Silk_LPC_analysis_filter_FLP( res, A, x_buf, buf_len, psEnc->sCmn.pitchEstimationLPCOrder ); - SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_float ) ); - if( psEncCtrl->sCmn.signalType != TYPE_NO_VOICE_ACTIVITY ) { + if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY ) { /* Threshold for pitch estimator */ thrhld = 0.6f; thrhld -= 0.004f * psEnc->sCmn.pitchEstimationLPCOrder; @@ -112,18 +111,18 @@ void SKP_Silk_find_pitch_lags_FLP( /*****************************************/ /* Call Pitch estimator */ /*****************************************/ - if( SKP_Silk_pitch_analysis_core_FLP( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, - &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16 / 65536.0f, + if( SKP_Silk_pitch_analysis_core_FLP( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex, + &psEnc->sCmn.indices.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16 / 65536.0f, thrhld, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr ) == 0 ) { - psEncCtrl->sCmn.signalType = TYPE_VOICED; + psEnc->sCmn.indices.signalType = TYPE_VOICED; } else { - psEncCtrl->sCmn.signalType = TYPE_UNVOICED; + psEnc->sCmn.indices.signalType = TYPE_UNVOICED; } } else { - SKP_memset( psEncCtrl->sCmn.pitchL, 0, sizeof( psEncCtrl->sCmn.pitchL ) ); - psEncCtrl->sCmn.lagIndex = 0; - psEncCtrl->sCmn.contourIndex = 0; + SKP_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) ); + psEnc->sCmn.indices.lagIndex = 0; + psEnc->sCmn.indices.contourIndex = 0; psEnc->LTPCorr = 0; } } diff --git a/src_FLP/SKP_Silk_find_pred_coefs_FLP.c b/src_FLP/SKP_Silk_find_pred_coefs_FLP.c index c408e811a..5ef9a216c 100644 --- a/src_FLP/SKP_Silk_find_pred_coefs_FLP.c +++ b/src_FLP/SKP_Silk_find_pred_coefs_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -42,7 +42,6 @@ void SKP_Silk_find_pred_coefs_FLP( const SKP_float *x_ptr; SKP_float *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ]; - /* Weighting for weighted least squares */ for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { SKP_assert( psEncCtrl->Gains[ i ] > 0.0f ); @@ -50,16 +49,15 @@ void SKP_Silk_find_pred_coefs_FLP( Wght[ i ] = invGains[ i ] * invGains[ i ]; } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /**********/ /* VOICED */ /**********/ - SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.pitchL[ 0 ] + LTP_ORDER / 2 ); + SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); /* LTP analysis */ SKP_Silk_find_LTP_FLP( psEncCtrl->LTPCoef, WLTP, &psEncCtrl->LTPredCodGain, res_pitch, - psEncCtrl->sCmn.pitchL, Wght, psEnc->sCmn.subfr_length, - psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length ); + psEncCtrl->pitchL, Wght, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length ); #ifdef SAVE_ALL_INTERNAL_DATA DEBUG_STORE_DATA( ltp_gains.dat, psEncCtrl->LTPCoef, sizeof( psEncCtrl->LTPCoef ) ); @@ -67,7 +65,7 @@ void SKP_Silk_find_pred_coefs_FLP( #endif /* Quantize LTP gain parameters */ - SKP_Silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, + SKP_Silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity , psEnc->sCmn.nb_subfr ); /* Control LTP scaling */ @@ -75,7 +73,7 @@ void SKP_Silk_find_pred_coefs_FLP( /* Create LTP residual */ SKP_Silk_LTP_analysis_filter_FLP( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder, - psEncCtrl->LTPCoef, psEncCtrl->sCmn.pitchL, invGains, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); + psEncCtrl->LTPCoef, psEncCtrl->pitchL, invGains, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); } else { /************/ @@ -96,13 +94,15 @@ void SKP_Silk_find_pred_coefs_FLP( } /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */ - SKP_Silk_find_LPC_FLP( NLSF, &psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq, + SKP_Silk_find_LPC_FLP( NLSF, &psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq, psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder, LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder, psEnc->sCmn.nb_subfr ); /* Quantize LSFs */ +TIC(LSF_quant); SKP_Silk_process_NLSFs_FLP( psEnc, psEncCtrl, NLSF ); +TOC(LSF_quant); /* Calculate residual energy using quantized LPC coefficients */ SKP_Silk_residual_energy_FLP( psEncCtrl->ResNrg, LPC_in_pre, psEncCtrl->PredCoef, psEncCtrl->Gains, diff --git a/src_FLP/SKP_Silk_init_encoder_FLP.c b/src_FLP/SKP_Silk_init_encoder_FLP.c index d3e60b81f..4b9ffdffa 100644 --- a/src_FLP/SKP_Silk_init_encoder_FLP.c +++ b/src_FLP/SKP_Silk_init_encoder_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -50,9 +50,5 @@ SKP_int SKP_Silk_init_encoder_FLP( /* Initialize Silk VAD */ ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD ); - /* Initialize NSQ */ - psEnc->sNSQ.prev_inv_gain_Q16 = 65536; - psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; - return( ret ); } diff --git a/src_FLP/SKP_Silk_main_FLP.h b/src_FLP/SKP_Silk_main_FLP.h index d91af2083..d40642172 100644 --- a/src_FLP/SKP_Silk_main_FLP.h +++ b/src_FLP/SKP_Silk_main_FLP.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -59,18 +59,14 @@ void SKP_Silk_HP_variable_cutoff_FLP( /* Encoder main function */ SKP_int SKP_Silk_encode_frame_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ - SKP_int32 *pnBytesOut, /* I/O Number of payload bytes; */ - /* input: max length; output: used */ - ec_enc *psRangeEnc, /* I/O compressor data structure */ - const SKP_int16 *pIn /* I Input speech frame */ + SKP_int32 *pnBytesOut, /* O Number of payload bytes; */ + ec_enc *psRangeEnc /* I/O compressor data structure */ ); /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ void SKP_Silk_LBRR_encode_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - SKP_uint8 *pCode, /* O Payload */ - SKP_int32 *pnBytesOut, /* I/O Payload bytes; in: max; out: used */ const SKP_float xfw[] /* I Input signal */ ); @@ -146,7 +142,7 @@ void SKP_Silk_find_pred_coefs_FLP( /* LPC analysis */ void SKP_Silk_find_LPC_FLP( SKP_float NLSF[], /* O NLSFs */ - SKP_int *interpIndex, /* O NLSF interp. index for NLSF interp. */ + SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */ const SKP_float prev_NLSFq[], /* I Previous NLSFs, for NLSF interpolation */ const SKP_int useInterpNLSFs, /* I Flag */ const SKP_int LPC_order, /* I LPC order */ @@ -203,10 +199,10 @@ void SKP_Silk_LPC_analysis_filter_FLP( /* LTP tap quantizer */ void SKP_Silk_quant_LTP_gains_FLP( SKP_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */ - SKP_int cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ - SKP_int *periodicity_index, /* O Periodicity index */ + SKP_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ + SKP_int8 *periodicity_index, /* O Periodicity index */ const SKP_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */ - const SKP_int mu_Q10, /* I Mu value (R/D tradeoff) */ + const SKP_int mu_Q10, /* I Mu value (R/D tradeoff) */ const SKP_int lowComplexity, /* I Flag for low complexity */ const SKP_int nb_subfr /* I number of subframes */ ); @@ -223,7 +219,7 @@ void SKP_Silk_process_NLSFs_FLP( /* NLSF vector encoder */ void SKP_Silk_NLSF_MSVQ_encode_FLP( - SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ SKP_float *pNLSF, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const SKP_float *pNLSF_q_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ @@ -262,7 +258,7 @@ void SKP_Silk_NLSF_VQ_sum_error_FLP( void SKP_Silk_NLSF_MSVQ_decode_FLP( SKP_float *pNLSF, /* O Decoded output vector [ LPC_ORDER ] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I NLSF codebook struct */ - const SKP_int *NLSFIndices, /* I NLSF indices [ nStages ] */ + const SKP_int8 *NLSFIndices, /* I NLSF indices [ nStages ] */ const SKP_int LPC_order /* I LPC order used */ ); @@ -387,9 +383,10 @@ SKP_int SKP_Silk_VAD_FLP( void SKP_Silk_NSQ_wrapper_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - const SKP_float x[], /* I Prefiltered input signal */ - SKP_int8 q[], /* O Quantized pulse signal */ - const SKP_int useLBRR /* I LBRR flag */ + SideInfoIndices *psIndices, /* I/O Quantization indices */ + SKP_Silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */ + SKP_int8 pulses[], /* O Quantized pulse signal */ + const SKP_float x[] /* I Prefiltered input signal */ ); /* using log2() helps the fixed-point conversion */ diff --git a/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c b/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c index 57e09f788..17a991e6f 100644 --- a/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c +++ b/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -144,10 +144,8 @@ void SKP_Silk_noise_shape_analysis_FLP( /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */ psEncCtrl->current_SNR_dB = psEnc->SNR_dB - 0.1f * psEnc->BufferedInChannel_ms; - /* Reduce SNR_dB if inband FEC used */ - if( psEnc->speech_activity > LBRR_SPEECH_ACTIVITY_THRES ) { - psEncCtrl->current_SNR_dB -= psEnc->inBandFEC_SNR_comp; - } + /* Reduce SNR_dB because of any inband FEC used */ + psEncCtrl->current_SNR_dB -= psEnc->inBandFEC_SNR_comp; /****************/ /* GAIN CONTROL */ @@ -165,7 +163,7 @@ void SKP_Silk_noise_shape_analysis_FLP( SNR_adj_dB -= BG_SNR_DECR_dB * psEncCtrl->coding_quality * ( 0.5f + 0.5f * psEncCtrl->input_quality ) * b * b; } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Reduce gains for periodic signals */ SNR_adj_dB += HARM_SNR_INCR_dB * psEnc->LTPCorr; } else { @@ -177,9 +175,9 @@ void SKP_Silk_noise_shape_analysis_FLP( /* SPARSENESS PROCESSING */ /*************************/ /* Set quantizer offset */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Initally set to 0; may be overruled in process_gains(..) */ - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; psEncCtrl->sparseness = 0.0f; } else { /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ @@ -200,9 +198,9 @@ void SKP_Silk_noise_shape_analysis_FLP( /* Set quantization offset depending on sparseness measure */ if( psEncCtrl->sparseness > SPARSENESS_THRESHOLD_QNT_OFFSET ) { - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; } else { - psEncCtrl->sCmn.quantOffsetType = 1; + psEnc->sCmn.indices.quantOffsetType = 1; } /* Increase coding SNR for sparse signals */ @@ -311,11 +309,11 @@ void SKP_Silk_noise_shape_analysis_FLP( /* Less low frequency shaping for noisy inputs */ strength = LOW_FREQ_SHAPING * ( 1.0f + LOW_QUALITY_LOW_FREQ_SHAPING_DECR * ( psEncCtrl->input_quality_bands[ 0 ] - 1.0f ) ); strength *= psEnc->speech_activity; - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */ /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/ for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { - b = 0.2f / psEnc->sCmn.fs_kHz + 3.0f / psEncCtrl->sCmn.pitchL[ k ]; + b = 0.2f / psEnc->sCmn.fs_kHz + 3.0f / psEncCtrl->pitchL[ k ]; psEncCtrl->LF_MA_shp[ k ] = -1.0f + b; psEncCtrl->LF_AR_shp[ k ] = 1.0f - b - b * strength; } @@ -341,7 +339,7 @@ void SKP_Silk_noise_shape_analysis_FLP( /* More harmonic boost for noisy input signals */ HarmBoost += LOW_INPUT_QUALITY_HARMONIC_BOOST * ( 1.0f - psEncCtrl->input_quality ); - if( USE_HARM_SHAPING && psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /* Harmonic noise shaping */ HarmShapeGain = HARMONIC_SHAPING; diff --git a/src_FLP/SKP_Silk_prefilter_FLP.c b/src_FLP/SKP_Silk_prefilter_FLP.c index d8b0f66fd..c3a23d15e 100644 --- a/src_FLP/SKP_Silk_prefilter_FLP.c +++ b/src_FLP/SKP_Silk_prefilter_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -110,8 +110,8 @@ void SKP_Silk_prefilter_FLP( lag = P->lagPrev; for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Update Variables that change per sub frame */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - lag = psEncCtrl->sCmn.pitchL[ k ]; + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { + lag = psEncCtrl->pitchL[ k ]; } /* Noise shape parameters */ @@ -143,7 +143,7 @@ void SKP_Silk_prefilter_FLP( px += psEnc->sCmn.subfr_length; pxw += psEnc->sCmn.subfr_length; } - P->lagPrev = psEncCtrl->sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; + P->lagPrev = psEncCtrl->pitchL[ psEnc->sCmn.nb_subfr - 1 ]; } /* diff --git a/src_FLP/SKP_Silk_process_NLSFs_FLP.c b/src_FLP/SKP_Silk_process_NLSFs_FLP.c index e21ac88de..0f13a47d6 100644 --- a/src_FLP/SKP_Silk_process_NLSFs_FLP.c +++ b/src_FLP/SKP_Silk_process_NLSFs_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -48,7 +48,7 @@ void SKP_Silk_process_NLSFs_FLP( /***********************/ /* Calculate mu values */ /***********************/ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { NLSF_mu = 0.002f - 0.001f * psEnc->speech_activity; NLSF_mu_fluc_red = 0.1f - 0.05f * psEnc->speech_activity; } else { @@ -60,11 +60,11 @@ void SKP_Silk_process_NLSFs_FLP( SKP_Silk_NLSF_VQ_weights_laroia_FLP( pNLSFW, pNLSF, psEnc->sCmn.predictLPCOrder ); /* Update NLSF weights for interpolated NLSFs */ - doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEncCtrl->sCmn.NLSFInterpCoef_Q2 < ( 1 << 2 ) ); + doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEnc->sCmn.indices.NLSFInterpCoef_Q2 < ( 1 << 2 ) ); if( doInterpolate ) { /* Calculate the interpolated NLSF vector for the first half */ - NLSF_interpolation_factor = 0.25f * psEncCtrl->sCmn.NLSFInterpCoef_Q2; + NLSF_interpolation_factor = 0.25f * psEnc->sCmn.indices.NLSFInterpCoef_Q2; SKP_Silk_interpolate_wrapper_FLP( pNLSF0_temp, psEnc->sPred.prev_NLSFq, pNLSF, NLSF_interpolation_factor, psEnc->sCmn.predictLPCOrder ); @@ -79,10 +79,10 @@ void SKP_Silk_process_NLSFs_FLP( } /* Set pointer to the NLSF codebook for the current signal type and LPC order */ - psNLSF_CB = psEnc->sCmn.psNLSF_CB[ 1 - (psEncCtrl->sCmn.signalType >> 1) ]; + psNLSF_CB = psEnc->sCmn.psNLSF_CB[ 1 - ( psEnc->sCmn.indices.signalType >> 1 ) ]; /* Quantize NLSF parameters given the trained NLSF codebooks */ - SKP_Silk_NLSF_MSVQ_encode_FLP( psEncCtrl->sCmn.NLSFIndices, pNLSF, psNLSF_CB, psEnc->sPred.prev_NLSFq, pNLSFW, NLSF_mu, + SKP_Silk_NLSF_MSVQ_encode_FLP( psEnc->sCmn.indices.NLSFIndices, pNLSF, psNLSF_CB, psEnc->sPred.prev_NLSFq, pNLSFW, NLSF_mu, NLSF_mu_fluc_red, psEnc->sCmn.NLSF_MSVQ_Survivors, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.first_frame_after_reset ); /* Convert quantized NLSFs back to LPC coefficients */ diff --git a/src_FLP/SKP_Silk_process_gains_FLP.c b/src_FLP/SKP_Silk_process_gains_FLP.c index e49e9ba68..9a0d46276 100644 --- a/src_FLP/SKP_Silk_process_gains_FLP.c +++ b/src_FLP/SKP_Silk_process_gains_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -40,7 +40,7 @@ void SKP_Silk_process_gains_FLP( SKP_float s, InvMaxSqrVal, gain, quant_offset; /* Gain reduction when LTP coding gain is high */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { s = 1.0f - 0.5f * SKP_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->Gains[ k ] *= s; @@ -63,8 +63,8 @@ void SKP_Silk_process_gains_FLP( } /* Noise shaping quantization */ - SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, pGains_Q16, - &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, psEnc->sCmn.nb_subfr ); + SKP_Silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, + &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr ); /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { @@ -72,16 +72,16 @@ void SKP_Silk_process_gains_FLP( } /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */ - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { if( psEncCtrl->LTPredCodGain + psEncCtrl->input_tilt > 1.0f ) { - psEncCtrl->sCmn.quantOffsetType = 0; + psEnc->sCmn.indices.quantOffsetType = 0; } else { - psEncCtrl->sCmn.quantOffsetType = 1; + psEnc->sCmn.indices.quantOffsetType = 1; } } /* Quantizer boundary adjustment */ - quant_offset = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrl->sCmn.signalType >> 1 ][ psEncCtrl->sCmn.quantOffsetType ] / 1024.0f; + quant_offset = SKP_Silk_Quantization_Offsets_Q10[ psEnc->sCmn.indices.signalType >> 1 ][ psEnc->sCmn.indices.quantOffsetType ] / 1024.0f; psEncCtrl->Lambda = LAMBDA_OFFSET + LAMBDA_DELAYED_DECISIONS * psEnc->sCmn.nStatesDelayedDecision + LAMBDA_SPEECH_ACT * psEnc->speech_activity diff --git a/src_FLP/SKP_Silk_regularize_correlations_FLP.c b/src_FLP/SKP_Silk_regularize_correlations_FLP.c index 14eadb7d7..3acb944dc 100644 --- a/src_FLP/SKP_Silk_regularize_correlations_FLP.c +++ b/src_FLP/SKP_Silk_regularize_correlations_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_residual_energy_FLP.c b/src_FLP/SKP_Silk_residual_energy_FLP.c index f7a734ce0..1d11b4ec9 100644 --- a/src_FLP/SKP_Silk_residual_energy_FLP.c +++ b/src_FLP/SKP_Silk_residual_energy_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_solve_LS_FLP.c b/src_FLP/SKP_Silk_solve_LS_FLP.c index 6e52b3778..e6c02c4dd 100644 --- a/src_FLP/SKP_Silk_solve_LS_FLP.c +++ b/src_FLP/SKP_Silk_solve_LS_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_structs_FLP.h b/src_FLP/SKP_Silk_structs_FLP.h index b2dd92684..5a950e0ca 100644 --- a/src_FLP/SKP_Silk_structs_FLP.h +++ b/src_FLP/SKP_Silk_structs_FLP.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -40,7 +40,7 @@ extern "C" /* Noise shaping analysis state */ /********************************/ typedef struct { - SKP_int LastGainIndex; + SKP_int8 LastGainIndex; SKP_float HarmBoost_smth; SKP_float HarmShapeGain_smth; SKP_float Tilt_smth; @@ -82,8 +82,6 @@ typedef struct { SKP_Silk_shape_state_FLP sShape; /* Noise shaping state */ SKP_Silk_prefilter_state_FLP sPrefilt; /* Prefilter State */ SKP_Silk_predict_state_FLP sPred; /* Prediction State */ - SKP_Silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ - SKP_Silk_nsq_state sNSQ_LBRR; /* Noise Shape Quantizer State ( for low bitrate redundancy )*/ /* 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 */ @@ -104,13 +102,12 @@ typedef struct { /* Encoder control FLP */ /************************/ typedef struct { - SKP_Silk_encoder_control sCmn; /* Common struct, shared with fixed-point code */ - /* Prediction and coding parameters */ SKP_float Gains[MAX_NB_SUBFR]; SKP_float PredCoef[ 2 ][ MAX_LPC_ORDER ]; /* holds interpolated and final coefficients */ SKP_float LTPCoef[LTP_ORDER * MAX_NB_SUBFR]; SKP_float LTP_scale; + SKP_int pitchL[ MAX_NB_SUBFR ]; /* Noise shaping parameters */ SKP_float AR1[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; diff --git a/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c b/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c index 5ed5dc8a9..355d7e49c 100644 --- a/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c +++ b/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_FLP/SKP_Silk_wrappers_FLP.c b/src_FLP/SKP_Silk_wrappers_FLP.c index 83ac58cd0..0af68130a 100644 --- a/src_FLP/SKP_Silk_wrappers_FLP.c +++ b/src_FLP/SKP_Silk_wrappers_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -155,13 +155,13 @@ SKP_int SKP_Silk_VAD_FLP( void SKP_Silk_NSQ_wrapper_FLP( SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - const SKP_float x[], /* I Prefiltered input signal */ - SKP_int8 q[], /* O Quantized pulse signal */ - const SKP_int useLBRR /* I LBRR flag */ + SideInfoIndices *psIndices, /* I/O Quantization indices */ + SKP_Silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */ + SKP_int8 pulses[], /* O Quantized pulse signal */ + const SKP_float x[] /* I Prefiltered input signal */ ) { SKP_int i, j; - SKP_float tmp_float; SKP_int16 x_16[ MAX_FRAME_LENGTH ]; SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; @@ -169,7 +169,6 @@ void SKP_Silk_NSQ_wrapper_FLP( SKP_int LTP_scale_Q14; /* Noise shaping parameters */ - /* Testing */ SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */ SKP_int Lambda_Q10; @@ -204,16 +203,12 @@ void SKP_Silk_NSQ_wrapper_FLP( } for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { - tmp_float = SKP_LIMIT( ( psEncCtrl->Gains[ i ] * 65536.0f ), 2147483000.0f, -2147483000.0f ); - Gains_Q16[ i ] = SKP_float2int( tmp_float ); - if( psEncCtrl->Gains[ i ] > 0.0f ) { - SKP_assert( tmp_float >= 0.0f ); - SKP_assert( Gains_Q16[ i ] >= 0 ); - } + Gains_Q16[ i ] = SKP_float2int( psEncCtrl->Gains[ i ] * 65536.0f ); + SKP_assert( Gains_Q16[ i ] > 0 ); } - if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) { - LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ]; + if( psIndices->signalType == TYPE_VOICED ) { + LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ]; } else { LTP_scale_Q14 = 0; } @@ -222,26 +217,12 @@ void SKP_Silk_NSQ_wrapper_FLP( SKP_float2short_array( x_16, x, psEnc->sCmn.frame_length ); /* Call NSQ */ - if( useLBRR ) { - if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { - SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, - x_16, q, psEncCtrl->sCmn.NLSFInterpCoef_Q2, PredCoef_Q12[ 0 ], LTPCoef_Q14, AR2_Q13, - HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, Lambda_Q10, LTP_scale_Q14 ); - } else { - SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, - x_16, q, psEncCtrl->sCmn.NLSFInterpCoef_Q2, PredCoef_Q12[ 0 ], LTPCoef_Q14, AR2_Q13, - HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, Lambda_Q10, LTP_scale_Q14 ); - } + if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { + SKP_Silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x_16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, + AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14 ); } else { - if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { - SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ, - x_16, q, psEncCtrl->sCmn.NLSFInterpCoef_Q2, PredCoef_Q12[ 0 ], LTPCoef_Q14, AR2_Q13, - HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, Lambda_Q10, LTP_scale_Q14 ); - } else { - SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ, - x_16, q, psEncCtrl->sCmn.NLSFInterpCoef_Q2, PredCoef_Q12[ 0 ], LTPCoef_Q14, AR2_Q13, - HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, Lambda_Q10, LTP_scale_Q14 ); - } + SKP_Silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x_16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, + AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14 ); } } @@ -250,10 +231,10 @@ void SKP_Silk_NSQ_wrapper_FLP( /***********************************************/ void SKP_Silk_quant_LTP_gains_FLP( SKP_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */ - SKP_int cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ - SKP_int *periodicity_index, /* O Periodicity index */ + SKP_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ + SKP_int8 *periodicity_index, /* O Periodicity index */ const SKP_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */ - const SKP_int mu_Q10, /* I Mu value (R/D tradeoff) */ + const SKP_int mu_Q10, /* I Mu value (R/D tradeoff) */ const SKP_int lowComplexity, /* I Flag for low complexity */ const SKP_int nb_subfr /* I number of subframes */ ) diff --git a/src_FLP/src_FLP.vcxproj b/src_FLP/src_FLP.vcxproj index 97d8035c3..8e28b7e87 100644 --- a/src_FLP/src_FLP.vcxproj +++ b/src_FLP/src_FLP.vcxproj @@ -96,7 +96,6 @@ <ClCompile Include="SKP_Silk_NLSF_MSVQ_encode_FLP.c" /> <ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion_FLP.c" /> <ClCompile Include="SKP_Silk_NLSF_VQ_sum_error_FLP.c" /> - <ClCompile Include="SKP_Silk_NLSF_VQ_weights_laroia_FLP.c" /> <ClCompile Include="SKP_Silk_noise_shape_analysis_FLP.c" /> <ClCompile Include="SKP_Silk_prefilter_FLP.c" /> <ClCompile Include="SKP_Silk_process_gains_FLP.c" /> diff --git a/src_FLP/src_FLP.vcxproj.filters b/src_FLP/src_FLP.vcxproj.filters index eb30f7f18..781af9331 100644 --- a/src_FLP/src_FLP.vcxproj.filters +++ b/src_FLP/src_FLP.vcxproj.filters @@ -80,9 +80,6 @@ <ClCompile Include="SKP_Silk_NLSF_VQ_sum_error_FLP.c"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="SKP_Silk_NLSF_VQ_weights_laroia_FLP.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="SKP_Silk_noise_shape_analysis_FLP.c"> <Filter>Source Files</Filter> </ClCompile> diff --git a/src_SigProc_FIX/SKP_Silk_A2NLSF.c b/src_SigProc_FIX/SKP_Silk_A2NLSF.c index d098ae1ca..e2e0e29fb 100644 --- a/src_SigProc_FIX/SKP_Silk_A2NLSF.c +++ b/src_SigProc_FIX/SKP_Silk_A2NLSF.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_Inlines.h b/src_SigProc_FIX/SKP_Silk_Inlines.h index 6eb0bb1a7..88a2046b0 100644 --- a/src_SigProc_FIX/SKP_Silk_Inlines.h +++ b/src_SigProc_FIX/SKP_Silk_Inlines.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c b/src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c new file mode 100644 index 000000000..6029ae606 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c @@ -0,0 +1,79 @@ +/*********************************************************************** +Copyright (c) 2006-2011, 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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FIX.h" + +/*******************************************/ +/* LPC analysis filter */ +/* NB! State is kept internally and the */ +/* filter always starts with zero state */ +/* first Order output samples are not set */ +/*******************************************/ + +void SKP_Silk_LPC_analysis_filter( + SKP_int16 *out, /* O: Output signal */ + const SKP_int16 *in, /* I: Input signal */ + const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */ + const SKP_int32 len, /* I: Signal length */ + const SKP_int32 d /* I: Filter order */ +) +{ + SKP_int ix, j; + SKP_int32 out32_Q12, out32; + const SKP_int16 *in_ptr; + + SKP_assert( d >= 6 ); + SKP_assert( (d & 1) == 0 ); + SKP_assert( d <= len ); + + for ( ix = d; ix < len; ix++) { + in_ptr = &in[ ix - 1 ]; + + out32_Q12 = SKP_SMULBB( in_ptr[ 0 ], B[ 0 ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -1 ], B[ 1 ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -2 ], B[ 2 ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -3 ], B[ 3 ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -4 ], B[ 4 ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -5 ], B[ 5 ] ); + for( j = 6; j < d; j += 2 ) { + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -j ], B[ j ] ); + out32_Q12 = SKP_SMLABB( out32_Q12, in_ptr[ -j - 1 ], B[ j + 1 ] ); + } + + /* Subtract prediction */ + out32_Q12 = SKP_SUB32( SKP_LSHIFT( (SKP_int32)in_ptr[ 1 ], 12 ), out32_Q12 ); + + /* Scale to Q0 */ + out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 ); + + /* Saturate output */ + out[ ix ] = ( SKP_int16 )SKP_SAT16( out32 ); + } + + /* Set first LPC d samples to zero instead of undefined */ + SKP_memset( out, 0, d * sizeof( SKP_int16 ) ); +} diff --git a/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c b/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c index d274fb420..06aaa1985 100644 --- a/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c b/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c index e1dc7dbcf..3dd58470e 100644 --- a/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c index c7916f359..e5f8d24ab 100644 --- a/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c index 2b9c6a476..82d8afd9c 100644 --- a/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_LSF_cos_table.c b/src_SigProc_FIX/SKP_Silk_LSF_cos_table.c index 099324ffa..1fc87a7af 100644 --- a/src_SigProc_FIX/SKP_Silk_LSF_cos_table.c +++ b/src_SigProc_FIX/SKP_Silk_LSF_cos_table.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_MA.c b/src_SigProc_FIX/SKP_Silk_MA.c deleted file mode 100644 index 3470a92f6..000000000 --- a/src_SigProc_FIX/SKP_Silk_MA.c +++ /dev/null @@ -1,167 +0,0 @@ -/*********************************************************************** -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. -***********************************************************************/ - -/* * - * SKP_Silk_MA.c * - * * - * Variable order MA filter * - * * - * Copyright 2006 (c), Skype Limited * - * Date: 060221 * - * */ -#include "SKP_Silk_SigProc_FIX.h" - -/* Variable order MA filter */ -void SKP_Silk_MA( - const SKP_int16 *in, /* I: input signal */ - const SKP_int16 *B, /* I: MA coefficients, Q13 [order+1] */ - SKP_int32 *S, /* I/O: state vector [order] */ - SKP_int16 *out, /* O: output signal */ - const SKP_int32 len, /* I: signal length */ - const SKP_int32 order /* I: filter order */ -) -{ - SKP_int k, d, in16; - SKP_int32 out32; - - for( k = 0; k < len; k++ ) { - in16 = in[ k ]; - out32 = SKP_SMLABB( S[ 0 ], in16, B[ 0 ] ); - out32 = SKP_RSHIFT_ROUND( out32, 13 ); - - for( d = 1; d < order; d++ ) { - S[ d - 1 ] = SKP_SMLABB( S[ d ], in16, B[ d ] ); - } - S[ order - 1 ] = SKP_SMULBB( in16, B[ order ] ); - - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); - } -} -/* Variable order MA prediction error filter */ -void SKP_Silk_MA_Prediction( - const SKP_int16 *in, /* I: Input signal */ - const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */ - SKP_int32 *S, /* I/O: State vector [order] */ - SKP_int16 *out, /* O: Output signal */ - const SKP_int32 len, /* I: Signal length */ - const SKP_int32 order /* I: Filter order */ -) -{ - SKP_int k, d, in16; - SKP_int32 out32; - - for( k = 0; k < len; k++ ) { - in16 = in[ k ]; - out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ]; - out32 = SKP_RSHIFT_ROUND( out32, 12 ); - - for( d = 0; d < order - 1; d++ ) { - S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B[ d ] ); - } - S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] ); - - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); - } -} - -void SKP_Silk_MA_Prediction_Q13( - const SKP_int16 *in, /* I: input signal */ - const SKP_int16 *B, /* I: MA prediction coefficients, Q13 [order] */ - SKP_int32 *S, /* I/O: state vector [order] */ - SKP_int16 *out, /* O: output signal */ - SKP_int32 len, /* I: signal length */ - SKP_int32 order /* I: filter order */ -) -{ - SKP_int k, d, in16; - SKP_int32 out32; - for( k = 0; k < len; k++ ) { - in16 = in[ k ]; - out32 = SKP_LSHIFT( in16, 13 ) - S[ 0 ]; - out32 = SKP_RSHIFT_ROUND( out32, 13 ); - - for( d = 0; d < order - 1; d++ ) { - S[ d ] = SKP_SMLABB( S[ d + 1 ], in16, B[ d ] ); - } - S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] ); - - /* Limit */ - out[ k ] = ( SKP_int16 )SKP_SAT16( out32 ); - } -} - -void SKP_Silk_LPC_analysis_filter( - const SKP_int16 *in, /* I: Input signal */ - const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */ - SKP_int16 *S, /* I/O: State vector [order] */ - SKP_int16 *out, /* O: Output signal */ - const SKP_int32 len, /* I: Signal length */ - const SKP_int32 Order /* I: Filter order */ -) -{ - SKP_int k, j, idx, Order_half = SKP_RSHIFT( Order, 1 ); - SKP_int32 out32_Q12, out32; - SKP_int16 SA, SB; - /* Order must be even */ - SKP_assert( 2 * Order_half == Order ); - - /* S[] values are in Q0 */ - for( k = 0; k < len; k++ ) { - SA = S[ 0 ]; - out32_Q12 = 0; - for( j = 0; j < ( Order_half - 1 ); j++ ) { - idx = SKP_SMULBB( 2, j ) + 1; - /* Multiply-add two prediction coefficients for each loop */ - SB = S[ idx ]; - S[ idx ] = SA; - out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ idx - 1 ] ); - out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ idx ] ); - SA = S[ idx + 1 ]; - S[ idx + 1 ] = SB; - } - - /* Unrolled loop: epilog */ - SB = S[ Order - 1 ]; - S[ Order - 1 ] = SA; - out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ Order - 2 ] ); - out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ Order - 1 ] ); - - /* Subtract prediction */ - out32_Q12 = SKP_SUB_SAT32( SKP_LSHIFT( (SKP_int32)in[ k ], 12 ), out32_Q12 ); - - /* Scale to Q0 */ - out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 ); - - /* Saturate output */ - out[ k ] = ( SKP_int16 )SKP_SAT16( out32 ); - - /* Move input line */ - S[ 0 ] = in[ k ]; - } -} diff --git a/src_SigProc_FIX/SKP_Silk_MacroCount.h b/src_SigProc_FIX/SKP_Silk_MacroCount.h index 93fbe4d11..be9f0d037 100644 --- a/src_SigProc_FIX/SKP_Silk_MacroCount.h +++ b/src_SigProc_FIX/SKP_Silk_MacroCount.h @@ -1,3 +1,30 @@ +/*********************************************************************** +Copyright (c) 2006-2011, 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 _SIGPROCFIX_API_MACROCOUNT_H_ #define _SIGPROCFIX_API_MACROCOUNT_H_ #include <stdio.h> diff --git a/src_SigProc_FIX/SKP_Silk_MacroDebug.h b/src_SigProc_FIX/SKP_Silk_MacroDebug.h index 29b27831c..cabbc2a7d 100644 --- a/src_SigProc_FIX/SKP_Silk_MacroDebug.h +++ b/src_SigProc_FIX/SKP_Silk_MacroDebug.h @@ -1,3 +1,30 @@ +/*********************************************************************** +Copyright (c) 2006-2011, 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 _SIGPROCFIX_API_DEBUG_H_ #define _SIGPROCFIX_API_DEBUG_H_ diff --git a/src_SigProc_FIX/SKP_Silk_NLSF2A.c b/src_SigProc_FIX/SKP_Silk_NLSF2A.c index fc477a585..05e3c1126 100644 --- a/src_SigProc_FIX/SKP_Silk_NLSF2A.c +++ b/src_SigProc_FIX/SKP_Silk_NLSF2A.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c b/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c index 532775e72..b6e44bc84 100644 --- a/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c +++ b/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c b/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c index 9c595d997..90975f6ab 100644 --- a/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c +++ b/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h b/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h index 372f2b800..eeff5808b 100644 --- a/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h +++ b/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -37,7 +37,7 @@ extern "C" //#define SKP_MACRO_COUNT /* Used to enable WMOPS counting */ #define SKP_Silk_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */ -#define SKP_Silk_MAX_CORRELATION_LENGTH 640 /* max input length to the correlation */ +#define SKP_Silk_MAX_CORRELATION_LENGTH 640 /* max input length to the correlation */ #include "SKP_Silk_typedef.h" #include <string.h> #include <stdlib.h> /* for abs() */ @@ -55,7 +55,7 @@ extern "C" * Initialize/reset the resampler state for a given pair of input/output sampling rates */ SKP_int SKP_Silk_resampler_init( - SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */ + SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */ SKP_int32 Fs_Hz_in, /* I: Input sampling rate (Hz) */ SKP_int32 Fs_Hz_out /* I: Output sampling rate (Hz) */ ); @@ -65,14 +65,14 @@ SKP_int SKP_Silk_resampler_init( * Clear the states of all resampling filters, without resetting sampling rate ratio */ SKP_int SKP_Silk_resampler_clear( - SKP_Silk_resampler_state_struct *S /* I/O: Resampler state */ + SKP_Silk_resampler_state_struct *S /* I/O: Resampler state */ ); /*! * Resampler: convert from one sampling rate to another */ SKP_int SKP_Silk_resampler( - SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */ + SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */ SKP_int16 out[], /* O: Output signal */ const SKP_int16 in[], /* I: Input signal */ SKP_int32 inLen /* I: Number of input samples */ @@ -176,15 +176,6 @@ void SKP_Silk_MA_Prediction( const SKP_int32 order /* I: Filter order */ ); -void SKP_Silk_MA_Prediction_Q13( - const SKP_int16 *in, /* I: input signal */ - const SKP_int16 *B, /* I: MA prediction coefficients, Q13 [order] */ - SKP_int32 *S, /* I/O: state vector [order] */ - SKP_int16 *out, /* O: output signal */ - SKP_int32 len, /* I: signal length */ - SKP_int32 order /* I: filter order */ -); - /*! * 16th order AR filter for LPC synthesis, coefficients are in Q12 */ @@ -200,10 +191,9 @@ void SKP_Silk_LPC_synthesis_order16( /* variable order MA prediction error filter. */ /* Inverse filter of SKP_Silk_LPC_synthesis_filter */ void SKP_Silk_LPC_analysis_filter( + SKP_int16 *out, /* O: Output signal */ const SKP_int16 *in, /* I: Input signal */ const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */ - SKP_int16 *S, /* I/O: State vector [order] */ - SKP_int16 *out, /* O: Output signal */ const SKP_int32 len, /* I: Signal length */ const SKP_int32 Order /* I: Filter order */ ); @@ -346,25 +336,25 @@ void SKP_Silk_autocorr( #define SKP_Silk_PE_MAX_COMPLEX 2 void SKP_Silk_decode_pitch( - SKP_int lagIndex, /* I */ - SKP_int contourIndex, /* O */ + SKP_int16 lagIndex, /* I */ + SKP_int8 contourIndex, /* O */ SKP_int pitch_lags[], /* O 4 pitch values */ const SKP_int Fs_kHz, /* I sampling frequency (kHz) */ const SKP_int nb_subfr /* I number of sub frames */ ); -SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ - const SKP_int16 *signal, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ - SKP_int *pitch_out, /* O 4 pitch lag values */ - SKP_int *lagIndex, /* O Lag Index */ - SKP_int *contourIndex, /* O Pitch contour Index */ - SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ - SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ - const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ - const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */ - const SKP_int Fs_kHz, /* I Sample frequency (kHz) */ - const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ - const SKP_int nb_subfr /* I number of 5 ms subframes */ +SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ + const SKP_int16 *signal, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ + SKP_int *pitch_out, /* O 4 pitch lag values */ + SKP_int16 *lagIndex, /* O Lag Index */ + SKP_int8 *contourIndex, /* O Pitch contour Index */ + SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ + SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ + const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ + const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */ + const SKP_int Fs_kHz, /* I Sample frequency (kHz) */ + const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ + const SKP_int nb_subfr /* I number of 5 ms subframes */ ); /* parameter defining the size and accuracy of the piecewise linear */ @@ -375,14 +365,14 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv extern const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ]; void SKP_Silk_LPC_fit( - SKP_int16 *a_QQ, /* O stabilized LPC vector, Q(24-rshift) [L] */ - SKP_int32 *a_Q24, /* I LPC vector [L] */ - const SKP_int QQ, /* I Q domain of output LPC vector */ - const SKP_int L /* I Number of LPC parameters in the input vector */ + SKP_int16 *a_QQ, /* O stabilized LPC vector, Q(24-rshift) [L] */ + SKP_int32 *a_Q24, /* I LPC vector [L] */ + const SKP_int QQ, /* I Q domain of output LPC vector */ + const SKP_int L /* I Number of LPC parameters in the input vector */ ); -/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */ -/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */ +/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */ +/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */ void SKP_Silk_A2NLSF( SKP_int *NLSF, /* O Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */ SKP_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */ @@ -549,7 +539,7 @@ SKP_INLINE SKP_int32 SKP_ROR32( SKP_int32 a32, SKP_int rot ) /* Useful Macros that can be adjusted to other platforms */ #define SKP_memcpy(a, b, c) memcpy((a), (b), (c)) /* Dest, Src, ByteCount */ #define SKP_memset(a, b, c) memset((a), (b), (c)) /* Dest, value, ByteCount */ -#define SKP_memmove(a, b, c) memmove((a), (b), (c)) /* Dest, Src, ByteCount */ +#define SKP_memmove(a, b, c) memmove((a), (b), (c)) /* Dest, Src, ByteCount */ /* fixed point macros */ // (a32 * b32) output have to be 32bit int @@ -732,8 +722,7 @@ SKP_INLINE SKP_int64 SKP_max_64(SKP_int64 a, SKP_int64 b) /* PSEUDO-RANDOM GENERATOR */ /* Make sure to store the result as the seed for the next call (also in between */ /* frames), otherwise result won't be random at all. When only using some of the */ -/* bits, take the most significant bits by right-shifting. Do not just mask off */ -/* the lowest bits. */ +/* bits, take the most significant bits by right-shifting. */ #define SKP_RAND(seed) (SKP_MLA_ovflw(907633515, (seed), 196314165)) // Add some multiplication functions that can be easily mapped to ARM. diff --git a/src_SigProc_FIX/SKP_Silk_allpass_int.c b/src_SigProc_FIX/SKP_Silk_allpass_int.c index 8f1560699..bc2f7cea2 100644 --- a/src_SigProc_FIX/SKP_Silk_allpass_int.c +++ b/src_SigProc_FIX/SKP_Silk_allpass_int.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c b/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c index d948a625e..04cbe0774 100644 --- a/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c +++ b/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_apply_sine_window.c b/src_SigProc_FIX/SKP_Silk_apply_sine_window.c index 54876285d..87d71f898 100644 --- a/src_SigProc_FIX/SKP_Silk_apply_sine_window.c +++ b/src_SigProc_FIX/SKP_Silk_apply_sine_window.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_array_maxabs.c b/src_SigProc_FIX/SKP_Silk_array_maxabs.c index e5ace4653..90b58b2ae 100644 --- a/src_SigProc_FIX/SKP_Silk_array_maxabs.c +++ b/src_SigProc_FIX/SKP_Silk_array_maxabs.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_autocorr.c b/src_SigProc_FIX/SKP_Silk_autocorr.c index 0cf8c0bbf..f7862b894 100644 --- a/src_SigProc_FIX/SKP_Silk_autocorr.c +++ b/src_SigProc_FIX/SKP_Silk_autocorr.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_biquad_alt.c b/src_SigProc_FIX/SKP_Silk_biquad_alt.c index 4f114299f..f7ffc33d1 100644 --- a/src_SigProc_FIX/SKP_Silk_biquad_alt.c +++ b/src_SigProc_FIX/SKP_Silk_biquad_alt.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_burg_modified.c b/src_SigProc_FIX/SKP_Silk_burg_modified.c index 3faebd4c1..235184ff1 100644 --- a/src_SigProc_FIX/SKP_Silk_burg_modified.c +++ b/src_SigProc_FIX/SKP_Silk_burg_modified.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_bwexpander.c b/src_SigProc_FIX/SKP_Silk_bwexpander.c index d2f5aa66f..9cdc64a0a 100644 --- a/src_SigProc_FIX/SKP_Silk_bwexpander.c +++ b/src_SigProc_FIX/SKP_Silk_bwexpander.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_bwexpander_32.c b/src_SigProc_FIX/SKP_Silk_bwexpander_32.c index e4a4e986d..f5f5e907a 100644 --- a/src_SigProc_FIX/SKP_Silk_bwexpander_32.c +++ b/src_SigProc_FIX/SKP_Silk_bwexpander_32.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h b/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h deleted file mode 100644 index cf0a456df..000000000 --- a/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h +++ /dev/null @@ -1,89 +0,0 @@ -/*********************************************************************** -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_COMMON_PE_DEFINES_H -#define SKP_SILK_COMMON_PE_DEFINES_H - -#include "SKP_Silk_SigProc_FIX.h" - -/************************************************************/ -/* Definitions For Fix pitch estimator */ -/************************************************************/ - -#define PE_MAX_FS_KHZ 24 /* Maximum sampling frequency used */ - -#define PE_MAX_NB_SUBFR 4 -#define PE_SUBFR_LENGTH_MS 5 /* 5 ms */ - -#define PE_LTP_MEM_LENGTH_MS (4 * PE_SUBFR_LENGTH_MS) - -#define PE_MAX_FRAME_LENGTH_MS (PE_LTP_MEM_LENGTH_MS + PE_MAX_NB_SUBFR * PE_SUBFR_LENGTH_MS) -#define PE_MAX_FRAME_LENGTH (PE_MAX_FRAME_LENGTH_MS * PE_MAX_FS_KHZ) -#define PE_MAX_FRAME_LENGTH_ST_1 (PE_MAX_FRAME_LENGTH >> 2) -#define PE_MAX_FRAME_LENGTH_ST_2 (PE_MAX_FRAME_LENGTH >> 1) -#define PE_MAX_SF_FRAME_LENGTH (PE_SUB_FRAME * PE_MAX_FS_KHZ) - -#define PE_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */ -#define PE_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */ -#define PE_MAX_LAG (PE_MAX_LAG_MS * PE_MAX_FS_KHZ) -#define PE_MIN_LAG (PE_MIN_LAG_MS * PE_MAX_FS_KHZ) - -#define PE_D_SRCH_LENGTH 24 - -#define PE_MAX_DECIMATE_STATE_LENGTH 7 - -#define PE_NB_STAGE3_LAGS 5 - -#define PE_NB_CBKS_STAGE2 3 -#define PE_NB_CBKS_STAGE2_EXT 11 - -#define PE_CB_mn2 1 -#define PE_CB_mx2 2 - -#define PE_NB_CBKS_STAGE3_MAX 34 -#define PE_NB_CBKS_STAGE3_MID 24 -#define PE_NB_CBKS_STAGE3_MIN 16 - -#define PE_NB_CBKS_STAGE3_10MS 12 -#define PE_NB_CBKS_STAGE2_10MS 3 - -#define PE_SHORTLAG_BIAS 0.2f /* for logarithmic weighting */ -#define PE_PREVLAG_BIAS 0.2f /* for logarithmic weighting */ -#define PE_FLATCONTOUR_BIAS 0.05f - -extern const SKP_int8 SKP_Silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ]; -extern const SKP_int8 SKP_Silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ]; -extern const SKP_int8 SKP_Silk_Lag_range_stage3[ SKP_Silk_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ]; -extern const SKP_int8 SKP_Silk_nb_cbk_searchs_stage3[ SKP_Silk_PE_MAX_COMPLEX + 1 ]; - -/* Tables added for 10 ms frames */ -extern const SKP_int8 SKP_Silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ 3 ]; -extern const SKP_int8 SKP_Silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 12 ]; -extern const SKP_int8 SKP_Silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ]; - -#endif - diff --git a/src_SigProc_FIX/SKP_Silk_debug.c b/src_SigProc_FIX/SKP_Silk_debug.c new file mode 100644 index 000000000..2e3f691e9 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_debug.c @@ -0,0 +1,175 @@ +/*********************************************************************** +Copyright (c) 2006-2011, 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. +***********************************************************************/ + +/* * + * SKP_debug.c * + * * + * This contains code to help debugging * + * * + * Copyright 2009 (c), Skype Limited * + * Date: 090629 * + * */ + +#include "SKP_debug.h" +#include "../src_SigProc_FIX/SKP_Silk_SigProc_FIX.h" + +#ifdef _WIN32 + +#if (defined(_WIN32) || defined(_WINCE)) +#include <windows.h> /* timer */ +#else // Linux or Mac +#include <sys/time.h> +#endif + +unsigned long GetHighResolutionTime(void) /* O: time in usec*/ +{ + /* Returns a time counter in microsec */ + /* the resolution is platform dependent */ + /* but is typically 1.62 us resolution */ + LARGE_INTEGER lpPerformanceCount; + LARGE_INTEGER lpFrequency; + QueryPerformanceCounter(&lpPerformanceCount); + QueryPerformanceFrequency(&lpFrequency); + return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart); +} +#else // Linux or Mac +unsigned long GetHighResolutionTime(void) /* O: time in usec*/ +{ + struct timeval tv; + gettimeofday(&tv, 0); + return((tv.tv_sec*1000000)+(tv.tv_usec)); +} +#endif + +#if SKP_TIC_TOC + +int SKP_Timer_nTimers = 0; +int SKP_Timer_depth_ctr = 0; +char SKP_Timer_tags[SKP_NUM_TIMERS_MAX][SKP_NUM_TIMERS_MAX_TAG_LEN]; +#ifdef WIN32 +LARGE_INTEGER SKP_Timer_start[SKP_NUM_TIMERS_MAX]; +#else +unsigned long SKP_Timer_start[SKP_NUM_TIMERS_MAX]; +#endif +unsigned int SKP_Timer_cnt[SKP_NUM_TIMERS_MAX]; +SKP_int64 SKP_Timer_min[SKP_NUM_TIMERS_MAX]; +SKP_int64 SKP_Timer_sum[SKP_NUM_TIMERS_MAX]; +SKP_int64 SKP_Timer_max[SKP_NUM_TIMERS_MAX]; +SKP_int64 SKP_Timer_depth[SKP_NUM_TIMERS_MAX]; + +#ifdef WIN32 +void SKP_TimerSave(char *file_name) +{ + if( SKP_Timer_nTimers > 0 ) + { + int k; + FILE *fp; + LARGE_INTEGER lpFrequency; + LARGE_INTEGER lpPerformanceCount1, lpPerformanceCount2; + int del = 0x7FFFFFFF; + double avg, sum_avg; + /* estimate overhead of calling performance counters */ + for( k = 0; k < 1000; k++ ) { + QueryPerformanceCounter(&lpPerformanceCount1); + QueryPerformanceCounter(&lpPerformanceCount2); + lpPerformanceCount2.QuadPart -= lpPerformanceCount1.QuadPart; + if( (int)lpPerformanceCount2.LowPart < del ) + del = lpPerformanceCount2.LowPart; + } + QueryPerformanceFrequency(&lpFrequency); + /* print results to file */ + sum_avg = 0.0f; + for( k = 0; k < SKP_Timer_nTimers; k++ ) { + if (SKP_Timer_depth[k] == 0) { + sum_avg += (1e6 * SKP_Timer_sum[k] / SKP_Timer_cnt[k] - del) / lpFrequency.QuadPart * SKP_Timer_cnt[k]; + } + } + fp = fopen(file_name, "w"); + fprintf(fp, " min avg %% max count\n"); + for( k = 0; k < SKP_Timer_nTimers; k++ ) { + if (SKP_Timer_depth[k] == 0) { + fprintf(fp, "%-28s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 1) { + fprintf(fp, " %-27s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 2) { + fprintf(fp, " %-26s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 3) { + fprintf(fp, " %-25s", SKP_Timer_tags[k]); + } else { + fprintf(fp, " %-24s", SKP_Timer_tags[k]); + } + avg = (1e6 * SKP_Timer_sum[k] / SKP_Timer_cnt[k] - del) / lpFrequency.QuadPart; + fprintf(fp, "%8.2f", (1e6 * (SKP_max_64(SKP_Timer_min[k] - del, 0))) / lpFrequency.QuadPart); + fprintf(fp, "%12.2f %6.2f", avg, 100.0 * avg / sum_avg * SKP_Timer_cnt[k]); + fprintf(fp, "%12.2f", (1e6 * (SKP_max_64(SKP_Timer_max[k] - del, 0))) / lpFrequency.QuadPart); + fprintf(fp, "%10d\n", SKP_Timer_cnt[k]); + } + fprintf(fp, " microseconds\n"); + fclose(fp); + } +} +#else +void SKP_TimerSave(char *file_name) +{ + if( SKP_Timer_nTimers > 0 ) + { + int k; + FILE *fp; + /* print results to file */ + fp = fopen(file_name, "w"); + fprintf(fp, " min avg max count\n"); + for( k = 0; k < SKP_Timer_nTimers; k++ ) + { + if (SKP_Timer_depth[k] == 0) { + fprintf(fp, "%-28s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 1) { + fprintf(fp, " %-27s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 2) { + fprintf(fp, " %-26s", SKP_Timer_tags[k]); + } else if (SKP_Timer_depth[k] == 3) { + fprintf(fp, " %-25s", SKP_Timer_tags[k]); + } else { + fprintf(fp, " %-24s", SKP_Timer_tags[k]); + } + fprintf(fp, "%d ", SKP_Timer_min[k]); + fprintf(fp, "%f ", (double)SKP_Timer_sum[k] / (double)SKP_Timer_cnt[k]); + fprintf(fp, "%d ", SKP_Timer_max[k]); + fprintf(fp, "%10d\n", SKP_Timer_cnt[k]); + } + fprintf(fp, " microseconds\n"); + fclose(fp); + } +} +#endif + +#endif /* SKP_TIC_TOC */ + +#if SKP_DEBUG +FILE *SKP_debug_store_fp[ SKP_NUM_STORES_MAX ]; +int SKP_debug_store_count = 0; +#endif /* SKP_DEBUG */ + diff --git a/src_SigProc_FIX/SKP_Silk_decode_pitch.c b/src_SigProc_FIX/SKP_Silk_decode_pitch.c index d3eb40724..540229b70 100644 --- a/src_SigProc_FIX/SKP_Silk_decode_pitch.c +++ b/src_SigProc_FIX/SKP_Silk_decode_pitch.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -32,8 +32,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_pitch_est_defines.h" void SKP_Silk_decode_pitch( - SKP_int lagIndex, /* I */ - SKP_int contourIndex, /* O */ + SKP_int16 lagIndex, /* I */ + SKP_int8 contourIndex, /* O */ SKP_int pitch_lags[], /* O pitch values */ const SKP_int Fs_kHz, /* I sampling frequency (kHz) */ const SKP_int nb_subfr /* I number of sub frames */ diff --git a/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c b/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c index 318f0a573..5469a2714 100644 --- a/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c +++ b/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_k2a.c b/src_SigProc_FIX/SKP_Silk_k2a.c index 19e88070a..0cb5482a6 100644 --- a/src_SigProc_FIX/SKP_Silk_k2a.c +++ b/src_SigProc_FIX/SKP_Silk_k2a.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_k2a_Q16.c b/src_SigProc_FIX/SKP_Silk_k2a_Q16.c index f12d1f281..c59719de6 100644 --- a/src_SigProc_FIX/SKP_Silk_k2a_Q16.c +++ b/src_SigProc_FIX/SKP_Silk_k2a_Q16.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_lin2log.c b/src_SigProc_FIX/SKP_Silk_lin2log.c index 6b3e7ed63..31cb05bff 100644 --- a/src_SigProc_FIX/SKP_Silk_lin2log.c +++ b/src_SigProc_FIX/SKP_Silk_lin2log.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_log2lin.c b/src_SigProc_FIX/SKP_Silk_log2lin.c index b06ce303f..258627cf3 100644 --- a/src_SigProc_FIX/SKP_Silk_log2lin.c +++ b/src_SigProc_FIX/SKP_Silk_log2lin.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_lowpass_int.c b/src_SigProc_FIX/SKP_Silk_lowpass_int.c index fbe9bda99..ac254551c 100644 --- a/src_SigProc_FIX/SKP_Silk_lowpass_int.c +++ b/src_SigProc_FIX/SKP_Silk_lowpass_int.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_lowpass_short.c b/src_SigProc_FIX/SKP_Silk_lowpass_short.c index f8bfcf6a8..058822d57 100644 --- a/src_SigProc_FIX/SKP_Silk_lowpass_short.c +++ b/src_SigProc_FIX/SKP_Silk_lowpass_short.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_macros.h b/src_SigProc_FIX/SKP_Silk_macros.h index 7ec277fca..406781edb 100644 --- a/src_SigProc_FIX/SKP_Silk_macros.h +++ b/src_SigProc_FIX/SKP_Silk_macros.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c b/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c index baa8a3387..bf0589138 100644 --- a/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c +++ b/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -64,25 +64,25 @@ SKP_int32 SKP_FIX_P_Ana_find_scaling( /*************************************************************/ /* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ /*************************************************************/ -SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ - const SKP_int16 *signal, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ - SKP_int *pitch_out, /* O 4 pitch lag values */ - SKP_int *lagIndex, /* O Lag Index */ - SKP_int *contourIndex, /* O Pitch contour Index */ - SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ - SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ - const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ - const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */ - const SKP_int Fs_kHz, /* I Sample frequency (kHz) */ - const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ - const SKP_int nb_subfr /* I number of 5 ms subframes */ +SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ + const SKP_int16 *signal, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ + SKP_int *pitch_out, /* O 4 pitch lag values */ + SKP_int16 *lagIndex, /* O Lag Index */ + SKP_int8 *contourIndex, /* O Pitch contour Index */ + SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ + SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ + const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ + const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */ + const SKP_int Fs_kHz, /* I Sample frequency (kHz) */ + const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ + const SKP_int nb_subfr /* I number of 5 ms subframes */ ) { SKP_int16 signal_8kHz[ PE_MAX_FRAME_LENGTH_ST_2 ]; SKP_int16 signal_4kHz[ PE_MAX_FRAME_LENGTH_ST_1 ]; + SKP_int32 filt_state[ 6 ]; SKP_int32 scratch_mem[ 3 * PE_MAX_FRAME_LENGTH ]; SKP_int16 *input_signal_ptr; - SKP_int32 filt_state[ PE_MAX_DECIMATE_STATE_LENGTH ]; SKP_int i, k, d, j; SKP_int16 C[ PE_MAX_NB_SUBFR ][ ( PE_MAX_LAG >> 1 ) + 5 ]; const SKP_int16 *target_ptr, *basis_ptr; @@ -133,13 +133,13 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 u SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) ); SKP_Silk_resampler_down2( filt_state, signal_8kHz, signal, frame_length ); } else if ( Fs_kHz == 12 ) { - SKP_int32 R23[ 6 ]; - SKP_memset( R23, 0, 6 * sizeof( SKP_int32 ) ); - SKP_Silk_resampler_down2_3( R23, signal_8kHz, signal, frame_length ); + SKP_memset( filt_state, 0, 6 * sizeof( SKP_int32 ) ); + SKP_Silk_resampler_down2_3( filt_state, signal_8kHz, signal, frame_length ); } else { SKP_assert( Fs_kHz == 8 ); SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_int16) ); } + /* Decimate again to 4 kHz */ SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );/* Set state to zero */ SKP_Silk_resampler_down2( filt_state, signal_4kHz, signal_8kHz, frame_length_8kHz ); @@ -557,8 +557,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 u for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag_new + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); } - *lagIndex = lag_new - min_lag; - *contourIndex = CBimax; + *lagIndex = (SKP_int16)( lag_new - min_lag); + *contourIndex = (SKP_int8)CBimax; } else { /* Save Lags and correlation */ CCmax = SKP_max( CCmax, 0 ); @@ -566,8 +566,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 u for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); } - *lagIndex = lag - min_lag_8kHz; - *contourIndex = CBimax; + *lagIndex = (SKP_int16)( lag - min_lag_8kHz ); + *contourIndex = (SKP_int8)CBimax; } SKP_assert( *lagIndex >= 0 ); /* return as voiced */ diff --git a/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h b/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h index c2b20b733..1960eabf9 100644 --- a/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h +++ b/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -54,8 +54,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PE_D_SRCH_LENGTH 24 -#define PE_MAX_DECIMATE_STATE_LENGTH 7 - #define PE_NB_STAGE3_LAGS 5 #define PE_NB_CBKS_STAGE2 3 diff --git a/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c b/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c index 5d9f68d74..f513b8d86 100644 --- a/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c +++ b/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler.c b/src_SigProc_FIX/SKP_Silk_resampler.c index 4ee313a3b..980f81fef 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler.c +++ b/src_SigProc_FIX/SKP_Silk_resampler.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down2.c b/src_SigProc_FIX/SKP_Silk_resampler_down2.c index 36e1d9bf5..f9f6c339a 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_down2.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_down2.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c b/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c index 9c4d64426..120f296d9 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down3.c b/src_SigProc_FIX/SKP_Silk_resampler_down3.c index 661673920..70c86f669 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_down3.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_down3.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private.h b/src_SigProc_FIX/SKP_Silk_resampler_private.h index bb8d4d84b..0402b484a 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private.h +++ b/src_SigProc_FIX/SKP_Silk_resampler_private.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c b/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c index 01b50b557..5cc673ad5 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c b/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c index 590fd61df..922c57539 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c b/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c index e80ce1ca6..df9a031dc 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c b/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c index 2c151e7f6..7c5b03197 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c b/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c index 6fb1506a6..0d327c728 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c b/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c index 687b7fd20..d8e06d932 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c b/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c index 2aa1d8a0b..afb4a12f0 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c b/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c index 89be2f28c..9c63d400e 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_rom.c b/src_SigProc_FIX/SKP_Silk_resampler_rom.c index 3d7dbe2aa..5a220c538 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_rom.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_rom.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_rom.h b/src_SigProc_FIX/SKP_Silk_resampler_rom.h index dca280a33..e08f83ab9 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_rom.h +++ b/src_SigProc_FIX/SKP_Silk_resampler_rom.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_structs.h b/src_SigProc_FIX/SKP_Silk_resampler_structs.h index e4a09c941..e4513e3e0 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_structs.h +++ b/src_SigProc_FIX/SKP_Silk_resampler_structs.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_resampler_up2.c b/src_SigProc_FIX/SKP_Silk_resampler_up2.c index 835e11309..718b2740d 100644 --- a/src_SigProc_FIX/SKP_Silk_resampler_up2.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_up2.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c b/src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c index 56057723c..2fa4bf621 100644 --- a/src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c +++ b/src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_scale_vector.c b/src_SigProc_FIX/SKP_Silk_scale_vector.c index 22e1429e9..a3615e7a6 100644 --- a/src_SigProc_FIX/SKP_Silk_scale_vector.c +++ b/src_SigProc_FIX/SKP_Silk_scale_vector.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_schur.c b/src_SigProc_FIX/SKP_Silk_schur.c index 4f2209fb6..6815612b2 100644 --- a/src_SigProc_FIX/SKP_Silk_schur.c +++ b/src_SigProc_FIX/SKP_Silk_schur.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_schur64.c b/src_SigProc_FIX/SKP_Silk_schur64.c index 154f45de6..891b59a51 100644 --- a/src_SigProc_FIX/SKP_Silk_schur64.c +++ b/src_SigProc_FIX/SKP_Silk_schur64.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_sigm_Q15.c b/src_SigProc_FIX/SKP_Silk_sigm_Q15.c index 95c056343..5b4168c16 100644 --- a/src_SigProc_FIX/SKP_Silk_sigm_Q15.c +++ b/src_SigProc_FIX/SKP_Silk_sigm_Q15.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_sort.c b/src_SigProc_FIX/SKP_Silk_sort.c index add67a652..76595b91b 100644 --- a/src_SigProc_FIX/SKP_Silk_sort.c +++ b/src_SigProc_FIX/SKP_Silk_sort.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c b/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c index fcfdc529b..a7cd69154 100644 --- a/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c +++ b/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FIX/src_SigProc_FIX.vcxproj b/src_SigProc_FIX/src_SigProc_FIX.vcxproj index 72e526cf7..e34ce9793 100644 --- a/src_SigProc_FIX/src_SigProc_FIX.vcxproj +++ b/src_SigProc_FIX/src_SigProc_FIX.vcxproj @@ -74,6 +74,7 @@ <None Include="ReadMe.txt" /> </ItemGroup> <ItemGroup> + <ClInclude Include="..\interface\SKP_debug.h" /> <ClInclude Include="SKP_Silk_pitch_est_defines.h" /> <ClInclude Include="SKP_Silk_Inlines.h" /> <ClInclude Include="SKP_Silk_MacroCount.h" /> @@ -109,7 +110,7 @@ <ClCompile Include="SKP_Silk_LPC_synthesis_filter.c" /> <ClCompile Include="SKP_Silk_LPC_synthesis_order16.c" /> <ClCompile Include="SKP_Silk_LSF_cos_table.c" /> - <ClCompile Include="SKP_Silk_MA.c" /> + <ClCompile Include="SKP_Silk_LPC_analysis_filter.c" /> <ClCompile Include="SKP_Silk_NLSF2A.c" /> <ClCompile Include="SKP_Silk_NLSF_stabilize.c" /> <ClCompile Include="SKP_Silk_NLSF_VQ_weights_laroia.c" /> diff --git a/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters b/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters index 6531f7031..2801eb364 100644 --- a/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters +++ b/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters @@ -45,6 +45,9 @@ <ClInclude Include="SKP_Silk_pitch_est_defines.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\interface\SKP_debug.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="SKP_Silk_A2NLSF.c"> @@ -116,9 +119,6 @@ <ClCompile Include="SKP_Silk_LSF_cos_table.c"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="SKP_Silk_MA.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="SKP_Silk_NLSF_stabilize.c"> <Filter>Source Files</Filter> </ClCompile> @@ -200,5 +200,8 @@ <ClCompile Include="SKP_Silk_debug.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="SKP_Silk_LPC_analysis_filter.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c b/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c index 976f9fda8..4b2f2f2b4 100644 --- a/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c b/src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c index 82a94fd9d..f5828571d 100644 --- a/src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h b/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h index 74dcc000f..115de3a0c 100644 --- a/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h +++ b/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define _SKP_SILK_SIGPROC_FLP_H_ #include "SKP_Silk_SigProc_FIX.h" +#include "float_cast.h" #include <math.h> #ifdef __cplusplus @@ -41,33 +42,6 @@ extern "C" /* SIGNAL PROCESSING FUNCTIONS */ /********************************************************************/ -/* first-order allpass filter */ -void SKP_Silk_allpass_int_FLP( - const SKP_float *in, /* I: input signal [len] */ - SKP_float *S, /* I/O: state [1] */ - SKP_float A, /* I: coefficient (0 <= A < 1) */ - SKP_float *out, /* O: output signal [len] */ - const SKP_int32 len /* I: number of samples */ -); - -/* downsample by a factor 2, coarser */ -void SKP_Silk_decimate2_coarse_FLP( - const SKP_float *in, /* I: signal [2*len] */ - SKP_float *S, /* I/O: state vector [2] */ - SKP_float *out, /* O: decimated signal [len] */ - SKP_float *scratch, /* I: scratch memory [3*len] */ - const SKP_int32 len /* I: number of OUTPUT samples */ -); - -/* downsample by a factor 2, coarsest */ -void SKP_Silk_decimate2_coarsest_FLP( - const SKP_float *in, /* I: signal [2*len] */ - SKP_float *S, /* I/O: state vector [2] */ - SKP_float *out, /* O: decimated signal [len] */ - SKP_float *scratch, /* I: scratch memory [3*len] */ - const SKP_int32 len /* I: number of OUTPUT samples */ -); - /* Chirp (bw expand) LP AR filter */ void SKP_Silk_bwexpander_FLP( SKP_float *ar, /* io AR filter to be expanded (without leading 1) */ @@ -117,10 +91,10 @@ void SKP_Silk_autocorrelation_FLP( #define SigProc_PE_MAX_COMPLEX 2 SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unvoiced */ - const SKP_float *signal, /* I signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ + const SKP_float *signal, /* I signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ SKP_int *pitch_out, /* O 4 pitch lag values */ - SKP_int *lagIndex, /* O lag Index */ - SKP_int *contourIndex, /* O pitch contour Index */ + SKP_int16 *lagIndex, /* O lag Index */ + SKP_int8 *contourIndex, /* O pitch contour Index */ SKP_float *LTPCorr, /* I/O normalized correlation; input: value from previous frame */ SKP_int prevLag, /* I last lag of previous frame; set to zero is unvoiced */ const SKP_float search_thres1, /* I first stage threshold for lag candidates 0 - 1 */ @@ -208,6 +182,18 @@ SKP_INLINE SKP_float SKP_sigmoid(SKP_float x) return (SKP_float)(1.0 / (1.0 + exp(-x))); } +/* floating-point to integer conversion (rounding) */ +#if 1 +/* use implementation in float_cast.h */ +#define SKP_float2int(x) float2int(x) +#else +SKP_INLINE SKP_int32 SKP_float2int(SKP_float x) +{ + double y = x; + return (SKP_int32)( ( y > 0 ) ? y + 0.5 : y - 0.5 ); +} +#endif + /* floating-point to integer conversion (rounding) */ SKP_INLINE void SKP_float2short_array( SKP_int16 *out, @@ -217,17 +203,10 @@ SKP_INLINE void SKP_float2short_array( { SKP_int32 k; for (k = length-1; k >= 0; k--) { - double x = in[k]; - out[k] = (SKP_int16)SKP_SAT16( ( x > 0 ) ? x + 0.5 : x - 0.5 ); + out[k] = (SKP_int16)SKP_SAT16( float2int( in[k] ) ); } } -/* floating-point to integer conversion (rounding) */ -SKP_INLINE SKP_int32 SKP_float2int(double x) -{ - return (SKP_int32)( ( x > 0 ) ? x + 0.5 : x - 0.5 ); -} - /* integer to floating-point conversion */ SKP_INLINE void SKP_short2float_array( SKP_float *out, diff --git a/src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c b/src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c deleted file mode 100644 index 210780b81..000000000 --- a/src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c +++ /dev/null @@ -1,68 +0,0 @@ -/*********************************************************************** -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. -***********************************************************************/ - -/* * - * SKP_Silk_allpass_int.c * - * * - * First-order allpass filter with * * - * transfer function: * - * * - * A + Z^(-1) * - * H(z) = ------------ * - * 1 + A*Z^(-1) * - * * - * Implemented using minimum multiplier filter design. * - * * - * Reference: http://www.univ.trieste.it/~ramponi/teaching/ * - * DSP/materiale/Ch6(2).pdf * - * * - * Copyright 2007 (c), Skype Limited * - * Date: 070525 * - * */ -#include "SKP_Silk_SigProc_FLP.h" - -/* first-order allpass filter */ -void SKP_Silk_allpass_int_FLP( - const SKP_float *in, /* I: input signal [len] */ - SKP_float *S, /* I/O: state [1] */ - SKP_float A, /* I: coefficient (0 <= A < 1) */ - SKP_float *out, /* O: output signal [len] */ - const SKP_int32 len /* I: number of samples */ -) -{ - SKP_float Y2, X2, S0; - SKP_int32 k; - - S0 = S[ 0 ]; - for ( k = len-1; k >= 0; k-- ) { - Y2 = *in - S0; - X2 = Y2 * A; - (*out++) = S0 + X2; - S0 = (*in++) + X2; - } - S[ 0 ] = S0; -} diff --git a/src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c b/src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c index d1fde2ed1..2fa56b494 100644 --- a/src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c b/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c index bb11f13dc..5b44c7243 100644 --- a/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c b/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c index 3f6be99da..3cf18090e 100644 --- a/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c b/src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c deleted file mode 100644 index 4dffbc80a..000000000 --- a/src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c +++ /dev/null @@ -1,72 +0,0 @@ -/*********************************************************************** -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. -***********************************************************************/ - -/* * - * SKP_Silk_decimate2_coarse.c * - * * - * downsample by a factor 2, coarser * - * * - * Copyright 2006 (c), Camino Networks * - * Date: 060221 * - * */ -#include "SKP_Silk_SigProc_FLP.h" - -/* coefficients for coarser 2-fold resampling */ -static SKP_float A20c_FLP[ 2 ] = {0.064666748046875f, 0.508514404296875f}; -static SKP_float A21c_FLP[ 2 ] = {0.245666503906250f, 0.819732666015625f}; - -/* downsample by a factor 2, coarser */ -void SKP_Silk_decimate2_coarse_FLP( - const SKP_float *in, /* I: 16 kHz signal [2*len] */ - SKP_float *S, /* I/O: state vector [4] */ - SKP_float *out, /* O: 8 kHz signal [len] */ - SKP_float *scratch, /* I: scratch memory [3*len] */ - const SKP_int32 len /* I: number of OUTPUT samples */ -) -{ - SKP_int32 k; - - /* de-interleave allpass inputs */ - for ( k = 0; k < len; k++) { - scratch[ k ] = in[ 2 * k ]; - scratch[ k + len ] = in[ 2 * k + 1 ]; - } - - /* allpass filters */ - SKP_Silk_allpass_int_FLP( scratch, S + 0, A21c_FLP[ 0 ], scratch + 2 * len, len ); - SKP_Silk_allpass_int_FLP( scratch + 2 * len, S + 1, A21c_FLP[ 1 ], scratch, len ); - - SKP_Silk_allpass_int_FLP( scratch + len, S + 2, A20c_FLP[ 0 ], scratch + 2 * len, len ); - SKP_Silk_allpass_int_FLP( scratch + 2 * len, S + 3, A20c_FLP[ 1 ], scratch + len, len ); - - /* add two allpass outputs */ - for ( k = 0; k < len; k++ ) { - out[ k ] = 0.5f * ( scratch[ k ] + scratch[ k + len ] ); - } -} - - diff --git a/src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c b/src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c deleted file mode 100644 index 55bc75cd1..000000000 --- a/src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c +++ /dev/null @@ -1,70 +0,0 @@ -/*********************************************************************** -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. -***********************************************************************/ - -/* * - * SKP_Silk_decimate2_coarsest.c * - * * - * downsample by a factor 2, coarsest * - * * - * Copyright 2006 (c), Camino Networks * - * Date: 060221 * - * */ -#include "SKP_Silk_SigProc_FLP.h" - -/* coefficients for coarsest 2-fold resampling */ -/* note that these differ from the interpolator with the same filter orders! */ -static float A20cst_FLP[ 1 ] = {0.289001464843750f}; -static float A21cst_FLP[ 1 ] = {0.780487060546875f}; - -/* downsample by a factor 2, coarsest */ -void SKP_Silk_decimate2_coarsest_FLP( - const SKP_float *in, /* I: 16 kHz signal [2*len] */ - SKP_float *S, /* I/O: state vector [2] */ - SKP_float *out, /* O: 8 kHz signal [len] */ - SKP_float *scratch, /* I: scratch memory [3*len] */ - const SKP_int32 len /* I: number of OUTPUT samples */ -) -{ - SKP_int32 k; - - /* de-interleave allpass inputs */ - for ( k = 0; k < len; k++ ) { - scratch[ k ] = in[ 2 * k + 0 ]; - scratch[ k + len ] = in[ 2 * k + 1 ]; - } - - /* allpass filters */ - SKP_Silk_allpass_int_FLP( scratch, S + 0, A21cst_FLP[ 0 ], scratch + 2 * len, len ); - SKP_Silk_allpass_int_FLP( scratch + len, S + 1, A20cst_FLP[ 0 ], scratch, len ); - - /* add two allpass outputs */ - for ( k = 0; k < len; k++ ) { - out[ k ] = 0.5f * ( scratch[ k ] + scratch[ k + 2 * len ] ); - } -} - - diff --git a/src_SigProc_FLP/SKP_Silk_energy_FLP.c b/src_SigProc_FLP/SKP_Silk_energy_FLP.c index 6e2726f8d..579364d29 100644 --- a/src_SigProc_FLP/SKP_Silk_energy_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_energy_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c b/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c index 29e2da7c7..05f5233a1 100644 --- a/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_k2a_FLP.c b/src_SigProc_FLP/SKP_Silk_k2a_FLP.c index 4bbd9d75f..d6d4b1655 100644 --- a/src_SigProc_FLP/SKP_Silk_k2a_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_k2a_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c b/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c index 924ae5966..6b09f02d4 100644 --- a/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c b/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c index d58efab1c..244754c34 100644 --- a/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -71,8 +71,8 @@ static void SKP_P_Ana_calc_energy_st3( SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unvoiced */ const SKP_float *signal, /* I signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ SKP_int *pitch_out, /* O 4 pitch lag values */ - SKP_int *lagIndex, /* O lag Index */ - SKP_int *contourIndex, /* O pitch contour Index */ + SKP_int16 *lagIndex, /* O lag Index */ + SKP_int8 *contourIndex, /* O pitch contour Index */ SKP_float *LTPCorr, /* I/O normalized correlation; input: value from previous frame */ SKP_int prevLag, /* I last lag of previous frame; set to zero is unvoiced */ const SKP_float search_thres1, /* I first stage threshold for lag candidates 0 - 1 */ @@ -82,11 +82,12 @@ SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unv const SKP_int nb_subfr /* I number of 5 ms subframes */ ) { - SKP_float signal_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ]; - SKP_float signal_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ]; - SKP_float scratch_mem[ PE_MAX_FRAME_LENGTH * 3 ]; - SKP_float filt_state[ PE_MAX_DECIMATE_STATE_LENGTH ]; SKP_int i, k, d, j; + SKP_float signal_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ]; + SKP_float signal_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ]; + SKP_int16 signal_8_FIX[ PE_MAX_FRAME_LENGTH_MS * 8 ]; + SKP_int16 signal_4_FIX[ PE_MAX_FRAME_LENGTH_MS * 4 ]; + SKP_int32 filt_state[ 6 ]; SKP_float threshold, contour_bias; SKP_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ]; SKP_float CC[ PE_NB_CBKS_STAGE2_EXT ]; @@ -136,47 +137,29 @@ SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unv SKP_memset(C, 0, sizeof(SKP_float) * nb_subfr * ((PE_MAX_LAG >> 1) + 5)); /* Resample from input sampled at Fs_kHz to 8 kHz */ - if( Fs_kHz == 12 ) { - SKP_int16 signal_12[ 12 * PE_MAX_FRAME_LENGTH_MS ]; - SKP_int16 signal_8[ 8 * PE_MAX_FRAME_LENGTH_MS ]; - SKP_int32 R23[ 6 ]; - + if( Fs_kHz == 16 ) { + /* Resample to 16 -> 8 khz */ + SKP_int16 signal_16_FIX[ 16 * PE_MAX_FRAME_LENGTH_MS ]; + SKP_float2short_array( signal_16_FIX, signal, frame_length ); + SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) ); + SKP_Silk_resampler_down2( filt_state, signal_8_FIX, signal_16_FIX, frame_length ); + SKP_short2float_array( signal_8kHz, signal_8_FIX, frame_length_8kHz ); + } else if( Fs_kHz == 12 ) { /* Resample to 12 -> 8 khz */ - SKP_memset( R23, 0, 6 * sizeof( SKP_int32 ) ); - SKP_float2short_array( signal_12, signal, frame_length ); - SKP_Silk_resampler_down2_3( R23, signal_8, signal_12, frame_length ); - SKP_short2float_array( signal_8kHz, signal_8, frame_length_8kHz ); - } else if( Fs_kHz == 16 ) { - if( complexity == SigProc_PE_MAX_COMPLEX ) { - SKP_assert( 4 <= PE_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 4 * sizeof(SKP_float) ); - - SKP_Silk_decimate2_coarse_FLP( signal, filt_state, signal_8kHz, - scratch_mem, frame_length_8kHz ); - } else { - SKP_assert( 2 <= PE_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 2 * sizeof(SKP_float) ); - - SKP_Silk_decimate2_coarsest_FLP( signal, filt_state, signal_8kHz, - scratch_mem, frame_length_8kHz ); - } + SKP_int16 signal_12_FIX[ 12 * PE_MAX_FRAME_LENGTH_MS ]; + SKP_float2short_array( signal_12_FIX, signal, frame_length ); + SKP_memset( filt_state, 0, 6 * sizeof( SKP_int32 ) ); + SKP_Silk_resampler_down2_3( filt_state, signal_8_FIX, signal_12_FIX, frame_length ); + SKP_short2float_array( signal_8kHz, signal_8_FIX, frame_length_8kHz ); } else { SKP_assert( Fs_kHz == 8 ); - SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_float) ); + SKP_float2short_array( signal_8_FIX, signal, frame_length_8kHz ); } - /* Decimate again to 4 kHz. Set mem to zero */ - if( complexity == SigProc_PE_MAX_COMPLEX ) { - SKP_assert( 4 <= PE_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 4 * sizeof(SKP_float) ); - SKP_Silk_decimate2_coarse_FLP( signal_8kHz, filt_state, - signal_4kHz, scratch_mem, frame_length_4kHz ); - } else { - SKP_assert( 2 <= PE_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 2 * sizeof(SKP_float) ); - SKP_Silk_decimate2_coarsest_FLP( signal_8kHz, filt_state, - signal_4kHz, scratch_mem, frame_length_4kHz ); - } + /* Decimate again to 4 kHz */ + SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) ); + SKP_Silk_resampler_down2( filt_state, signal_4_FIX, signal_8_FIX, frame_length_8kHz ); + SKP_short2float_array( signal_4kHz, signal_4_FIX, frame_length_4kHz ); /* Low-pass filter */ for( i = frame_length_4kHz - 1; i > 0; i-- ) { @@ -303,22 +286,16 @@ SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unv *********************************************************************************/ SKP_memset( C, 0, PE_MAX_NB_SUBFR*((PE_MAX_LAG >> 1) + 5) * sizeof(SKP_float)); // Is this needed? - target_ptr = &signal_8kHz[ PE_LTP_MEM_LENGTH_MS * 8 ]; + if( Fs_kHz == 8 ) { + target_ptr = &signal[ PE_LTP_MEM_LENGTH_MS * 8 ]; + } else { + target_ptr = &signal_8kHz[ PE_LTP_MEM_LENGTH_MS * 8 ]; + } for( k = 0; k < nb_subfr; k++ ) { - - /* Check that we are within range of the array */ - SKP_assert( target_ptr >= signal_8kHz ); - SKP_assert( target_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz ); - energy_tmp = SKP_Silk_energy_FLP( target_ptr, sf_length_8kHz ); for( j = 0; j < length_d_comp; j++ ) { d = d_comp[ j ]; basis_ptr = target_ptr - d; - - /* Check that we are within range of the array */ - SKP_assert( basis_ptr >= signal_8kHz ); - SKP_assert( basis_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz ); - cross_corr = SKP_Silk_inner_product_FLP( basis_ptr, target_ptr, sf_length_8kHz ); energy = SKP_Silk_energy_FLP( basis_ptr, sf_length_8kHz ); if (cross_corr > 0.0f) { @@ -490,8 +467,8 @@ SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unv for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag_new + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); } - *lagIndex = lag_new - min_lag; - *contourIndex = CBimax; + *lagIndex = (SKP_int16)( lag_new - min_lag ); + *contourIndex = (SKP_int8)CBimax; } else { /* Save Lags and correlation */ SKP_assert( CCmax >= 0.0f ); @@ -499,8 +476,8 @@ SKP_int SKP_Silk_pitch_analysis_core_FLP( /* O voicing estimate: 0 voiced, 1 unv for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); } - *lagIndex = lag - min_lag; - *contourIndex = CBimax; + *lagIndex = (SKP_int16)( lag - min_lag ); + *contourIndex = (SKP_int8)CBimax; } SKP_assert( *lagIndex >= 0 ); /* return as voiced */ diff --git a/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c b/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c index 5cc24f35e..94274fd63 100644 --- a/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c b/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c index 559d89c81..69b47e67c 100644 --- a/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_schur_FLP.c b/src_SigProc_FLP/SKP_Silk_schur_FLP.c index 7b45d0d65..a6dd24cab 100644 --- a/src_SigProc_FLP/SKP_Silk_schur_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_schur_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/SKP_Silk_sort_FLP.c b/src_SigProc_FLP/SKP_Silk_sort_FLP.c index 2c809b275..fa592de2b 100644 --- a/src_SigProc_FLP/SKP_Silk_sort_FLP.c +++ b/src_SigProc_FLP/SKP_Silk_sort_FLP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_SigProc_FLP/src_SigProc_FLP.vcxproj b/src_SigProc_FLP/src_SigProc_FLP.vcxproj index 9a11f3741..c4e9004aa 100644 --- a/src_SigProc_FLP/src_SigProc_FLP.vcxproj +++ b/src_SigProc_FLP/src_SigProc_FLP.vcxproj @@ -77,12 +77,9 @@ <ClInclude Include="SKP_Silk_SigProc_FLP.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="SKP_Silk_allpass_int_FLP.c" /> <ClCompile Include="SKP_Silk_autocorrelation_FLP.c" /> <ClCompile Include="SKP_Silk_burg_modified_FLP.c" /> <ClCompile Include="SKP_Silk_bwexpander_FLP.c" /> - <ClCompile Include="SKP_Silk_decimate2_coarsest_FLP.c" /> - <ClCompile Include="SKP_Silk_decimate2_coarse_FLP.c" /> <ClCompile Include="SKP_Silk_energy_FLP.c" /> <ClCompile Include="SKP_Silk_inner_product_FLP.c" /> <ClCompile Include="SKP_Silk_k2a_FLP.c" /> diff --git a/src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters b/src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters index b25f49a65..4bc333487 100644 --- a/src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters +++ b/src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters @@ -23,9 +23,6 @@ </ClInclude> </ItemGroup> <ItemGroup> - <ClCompile Include="SKP_Silk_allpass_int_FLP.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="SKP_Silk_autocorrelation_FLP.c"> <Filter>Source Files</Filter> </ClCompile> @@ -35,12 +32,6 @@ <ClCompile Include="SKP_Silk_bwexpander_FLP.c"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="SKP_Silk_decimate2_coarse_FLP.c"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="SKP_Silk_decimate2_coarsest_FLP.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="SKP_Silk_energy_FLP.c"> <Filter>Source Files</Filter> </ClCompile> diff --git a/src_common/SKP_Silk_CNG.c b/src_common/SKP_Silk_CNG.c index 1b41962b9..41128ef20 100644 --- a/src_common/SKP_Silk_CNG.c +++ b/src_common/SKP_Silk_CNG.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -92,7 +92,7 @@ void SKP_Silk_CNG( psCNG->fs_kHz = psDec->fs_kHz; } - if( psDec->lossCnt == 0 && psDec->vadFlag == NO_VOICE_ACTIVITY ) { + if( psDec->lossCnt == 0 && psDec->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) { /* Update CNG parameters */ /* Smoothing of LSF's */ @@ -119,7 +119,7 @@ void SKP_Silk_CNG( } /* Add CNG when packet is lost and / or when low speech activity */ - if( psDec->lossCnt ) {//|| psDec->vadFlag == NO_VOICE_ACTIVITY ) { + if( psDec->lossCnt ) { /* Generate CNG excitation */ SKP_Silk_CNG_exc( CNG_sig, psCNG->CNG_exc_buf_Q10, diff --git a/src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c b/src_common/SKP_Silk_LBRR_embed.c similarity index 53% rename from src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c rename to src_common/SKP_Silk_LBRR_embed.c index 192758f31..c5080d15d 100644 --- a/src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c +++ b/src_common/SKP_Silk_LBRR_embed.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -25,45 +25,35 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -#include "SKP_Silk_SigProc_FLP.h" +#include "SKP_Silk_main.h" -/* -R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP -Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech, -Signal Processing, pp. 641-644, 1991. -*/ - -#define MIN_NDELTA ( 1e-6f / PI ) - -/* Laroia low complexity NLSF weights */ -void SKP_Silk_NLSF_VQ_weights_laroia_FLP( - SKP_float *pXW, /* 0: Pointer to input vector weights [D x 1] */ - const SKP_float *pX, /* I: Pointer to input vector [D x 1] */ - const SKP_int D /* I: Input vector dimension */ +/*******************************************/ +/* Encode LBRR side info and excitation */ +/*******************************************/ +void SKP_Silk_LBRR_embed( + SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ + ec_enc *psRangeEnc /* I/O Compressor data structure */ ) { - SKP_int k; - SKP_float tmp1, tmp2; - - /* Safety checks */ - SKP_assert( D > 0 ); - SKP_assert( ( D & 1 ) == 0 ); - - /* First value */ - tmp1 = 1.0f / SKP_max_float( pX[ 0 ], MIN_NDELTA ); - tmp2 = 1.0f / SKP_max_float( pX[ 1 ] - pX[ 0 ], MIN_NDELTA ); - pXW[ 0 ] = tmp1 + tmp2; - - /* Main loop */ - for( k = 1; k < D - 1; k += 2 ) { - tmp1 = 1.0f / SKP_max_float( pX[ k + 1 ] - pX[ k ], MIN_NDELTA ); - pXW[ k ] = tmp1 + tmp2; + SKP_int i; + SKP_int32 LBRR_symbol; + + /* Encode LBRR flags */ + LBRR_symbol = 0; + for( i = 0; i < psEncC->nFramesPerPacket; i++ ) { + LBRR_symbol |= SKP_LSHIFT( psEncC->LBRR_flags[ i ], i ); + } + psEncC->LBRR_flag = LBRR_symbol > 0 ? 1 : 0; + if( LBRR_symbol && psEncC->nFramesPerPacket > 1 ) { + ec_enc_icdf( psRangeEnc, LBRR_symbol - 1, SKP_Silk_LBRR_flags_iCDF_ptr[ psEncC->nFramesPerPacket - 2 ], 8 ); + } - tmp2 = 1.0f / SKP_max_float( pX[ k + 2 ] - pX[ k + 1 ], MIN_NDELTA ); - pXW[ k + 1 ] = tmp1 + tmp2; + /* Code indices and excitation signals */ + for( i = 0; i < psEncC->nFramesPerPacket; i++ ) { + if( psEncC->LBRR_flags[ i ] ) { + SKP_Silk_encode_indices( psEncC, psRangeEnc, i, 1 ); + SKP_Silk_encode_pulses( psRangeEnc, psEncC->indices_LBRR[i].signalType, + psEncC->indices_LBRR[i].quantOffsetType, psEncC->pulses_LBRR[ i ], psEncC->frame_length ); + } } - - /* Last value */ - tmp1 = 1.0f / SKP_max_float( 1.0f - pX[ D - 1 ], MIN_NDELTA ); - pXW[ D - 1 ] = tmp1 + tmp2; } diff --git a/src_common/SKP_Silk_LP_variable_cutoff.c b/src_common/SKP_Silk_LP_variable_cutoff.c index 3f40356ac..82183ddef 100644 --- a/src_common/SKP_Silk_LP_variable_cutoff.c +++ b/src_common/SKP_Silk_LP_variable_cutoff.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -114,8 +114,7 @@ SKP_INLINE void SKP_Silk_LP_interpolate_filter_taps( /* Deactivate by setting psEncC->transition_frame_no = 0; */ void SKP_Silk_LP_variable_cutoff( SKP_Silk_LP_state *psLP, /* I/O LP filter state */ - SKP_int16 *out, /* O Low-pass filtered output signal */ - const SKP_int16 *in, /* I Input signal */ + SKP_int16 *signal, /* I/O Low-pass filtered output signal */ const SKP_int frame_length /* I Frame length */ ) { @@ -185,10 +184,7 @@ void SKP_Silk_LP_variable_cutoff( if( psLP->transition_frame_no > 0 ) { /* ARMA low-pass filtering */ SKP_assert( TRANSITION_NB == 3 && TRANSITION_NA == 2 ); - SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psLP->In_LP_State, out, frame_length ); - } else { - /* Instead of using the filter, copy input directly to output */ - SKP_memcpy( out, in, frame_length * sizeof( SKP_int16 ) ); + SKP_Silk_biquad_alt( signal, B_Q28, A_Q28, psLP->In_LP_State, signal, frame_length ); } } #endif diff --git a/src_common/SKP_Silk_NLSF2A_stable.c b/src_common/SKP_Silk_NLSF2A_stable.c index db06ab320..7f79df766 100644 --- a/src_common/SKP_Silk_NLSF2A_stable.c +++ b/src_common/SKP_Silk_NLSF2A_stable.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_NLSF_MSVQ_decode.c b/src_common/SKP_Silk_NLSF_MSVQ_decode.c index 5655e497d..3cd0a3e73 100644 --- a/src_common/SKP_Silk_NLSF_MSVQ_decode.c +++ b/src_common/SKP_Silk_NLSF_MSVQ_decode.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -31,33 +31,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void SKP_Silk_NLSF_MSVQ_decode( SKP_int *pNLSF_Q15, /* O Pointer to decoded output vector [LPC_ORDER x 1] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Pointer to NLSF codebook struct */ - const SKP_int *NLSFIndices, /* I Pointer to NLSF indices [nStages x 1] */ + const SKP_int8 *NLSFIndices, /* I Pointer to NLSF indices [nStages x 1] */ const SKP_int LPC_order /* I LPC order used */ ) { const SKP_int8 *pCB_element; - SKP_int s; - SKP_int i; + SKP_int i, s; SKP_int pNLSF_Q8[ MAX_LPC_ORDER ]; - /* Check that each index is within valid range */ + /* Check that index is within valid range */ SKP_assert( 0 <= NLSFIndices[ 0 ] && NLSFIndices[ 0 ] < psNLSF_CB->CBStages[ 0 ].nVectors ); /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q8[ SKP_MUL( NLSFIndices[ 0 ], LPC_order ) ]; + pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q8[ SKP_SMULBB( (SKP_int16)NLSFIndices[ 0 ], LPC_order ) ]; /* Initialize with the codebook vector from stage 0 */ for( i = 0; i < LPC_order; i++ ) { pNLSF_Q8[ i ] = ( SKP_int )pCB_element[ i ]; } - for( s = 1; s < psNLSF_CB->nStages; s++ ) { - /* Check that each index is within valid range */ - SKP_assert( 0 <= NLSFIndices[ s ] && NLSFIndices[ s ] < psNLSF_CB->CBStages[ s ].nVectors ); + if( LPC_order == 16 ) { + for( s = 1; s < psNLSF_CB->nStages; s++ ) { + /* Check that each index is within valid range */ + SKP_assert( 0 <= NLSFIndices[ s ] && NLSFIndices[ s ] < psNLSF_CB->CBStages[ s ].nVectors ); - if( LPC_order == 16 ) { /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ SKP_LSHIFT( NLSFIndices[ s ], 4 ) ]; + pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ 16 * (SKP_int16)NLSFIndices[ s ] ]; /* Add the codebook vector from the current stage */ pNLSF_Q8[ 0 ] += ( SKP_int )pCB_element[ 0 ]; @@ -76,14 +75,24 @@ void SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q8[ 13 ] += ( SKP_int )pCB_element[ 13 ]; pNLSF_Q8[ 14 ] += ( SKP_int )pCB_element[ 14 ]; pNLSF_Q8[ 15 ] += ( SKP_int )pCB_element[ 15 ]; - } else { + } + } else { + SKP_assert( LPC_order == 10 ); + for( s = 1; s < psNLSF_CB->nStages; s++ ) { /* Point to the first vector element */ - pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ SKP_SMULBB( NLSFIndices[ s ], LPC_order ) ]; + pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ SKP_SMULBB( (SKP_int16)NLSFIndices[ s ], LPC_order ) ]; /* Add the codebook vector from the current stage */ - for( i = 0; i < LPC_order; i++ ) { - pNLSF_Q8[ i ] += ( SKP_int )pCB_element[ i ]; - } + pNLSF_Q8[ 0 ] += ( SKP_int )pCB_element[ 0 ]; + pNLSF_Q8[ 1 ] += ( SKP_int )pCB_element[ 1 ]; + pNLSF_Q8[ 2 ] += ( SKP_int )pCB_element[ 2 ]; + pNLSF_Q8[ 3 ] += ( SKP_int )pCB_element[ 3 ]; + pNLSF_Q8[ 4 ] += ( SKP_int )pCB_element[ 4 ]; + pNLSF_Q8[ 5 ] += ( SKP_int )pCB_element[ 5 ]; + pNLSF_Q8[ 6 ] += ( SKP_int )pCB_element[ 6 ]; + pNLSF_Q8[ 7 ] += ( SKP_int )pCB_element[ 7 ]; + pNLSF_Q8[ 8 ] += ( SKP_int )pCB_element[ 8 ]; + pNLSF_Q8[ 9 ] += ( SKP_int )pCB_element[ 9 ]; } } diff --git a/src_common/SKP_Silk_NSQ.c b/src_common/SKP_Silk_NSQ.c index 2c3b54418..8eea9014b 100644 --- a/src_common/SKP_Silk_NSQ.c +++ b/src_common/SKP_Silk_NSQ.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -28,13 +28,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" SKP_INLINE void SKP_Silk_nsq_scale_states( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ - const SKP_int16 x[], /* I input in Q0 */ - SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ - const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */ - SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ - SKP_int subfr, /* I subframe number */ + const SKP_Silk_encoder_state *psEncC, /* I Encoder State */ + SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + const SKP_int16 x[], /* I input in Q0 */ + SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ + const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */ + SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ + SKP_int subfr, /* I subframe number */ const SKP_int LTP_scale_Q14, /* I */ const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ const SKP_int pitchL[ MAX_NB_SUBFR ] /* I */ @@ -44,7 +44,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ SKP_int signalType, /* I Signal type */ const SKP_int32 x_sc_Q10[], /* I */ - SKP_int8 q[], /* O */ + SKP_int8 pulses[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -63,19 +63,19 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( ); void SKP_Silk_NSQ( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ + const SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ const SKP_int16 x[], /* I prefiltered input signal */ - SKP_int8 q[], /* O quantized qulse signal */ - const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ + SKP_int8 pulses[], /* O quantized qulse signal */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefficients */ - const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ - const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefficients */ + const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ + const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I */ const SKP_int Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ) @@ -87,19 +87,18 @@ void SKP_Silk_NSQ( SKP_int16 sLTP[ 2 * MAX_FRAME_LENGTH ]; SKP_int32 HarmShapeFIRPacked_Q14; SKP_int offset_Q10; - SKP_int32 FiltState[ MAX_LPC_ORDER ]; SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / MAX_NB_SUBFR ]; - NSQ->rand_seed = psEncCtrlC->Seed; + NSQ->rand_seed = psIndices->Seed; /* Set unvoiced lag to the previous one, overwrite later for voiced */ lag = NSQ->lagPrev; SKP_assert( NSQ->prev_inv_gain_Q16 != 0 ); - offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->signalType >> 1 ][ psEncCtrlC->quantOffsetType ]; + offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ psIndices->quantOffsetType ]; - if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) { + if( psIndices->NLSFInterpCoef_Q2 == 4 ) { LSF_interpolation_flag = 0; } else { LSF_interpolation_flag = 1; @@ -120,9 +119,9 @@ void SKP_Silk_NSQ( HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 ); NSQ->rewhite_flag = 0; - if( psEncCtrlC->signalType == TYPE_VOICED ) { + if( psIndices->signalType == TYPE_VOICED ) { /* Voiced */ - lag = psEncCtrlC->pitchL[ k ]; + lag = pitchL[ k ]; /* Re-whitening */ if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) { @@ -130,28 +129,27 @@ void SKP_Silk_NSQ( start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; SKP_assert( start_idx > 0 ); - SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) ); - SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ], - A_Q12, FiltState, &sLTP[ start_idx ], psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder ); + SKP_Silk_LPC_analysis_filter( &sLTP[ start_idx ], &NSQ->xq[ start_idx + k * psEncC->subfr_length ], + A_Q12, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder ); NSQ->rewhite_flag = 1; NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; } } - SKP_Silk_nsq_scale_states( psEncC, NSQ, x, x_sc_Q10, sLTP, sLTP_Q16, k, LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL ); + SKP_Silk_nsq_scale_states( psEncC, NSQ, x, x_sc_Q10, sLTP, sLTP_Q16, k, LTP_scale_Q14, Gains_Q16, pitchL ); - SKP_Silk_noise_shape_quantizer( NSQ, psEncCtrlC->signalType, x_sc_Q10, q, pxq, sLTP_Q16, A_Q12, B_Q14, + SKP_Silk_noise_shape_quantizer( NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q16, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder ); - x += psEncC->subfr_length; - q += psEncC->subfr_length; - pxq += psEncC->subfr_length; + x += psEncC->subfr_length; + pulses += psEncC->subfr_length; + pxq += psEncC->subfr_length; } /* Update lagPrev for next frame */ - NSQ->lagPrev = psEncCtrlC->pitchL[ psEncC->nb_subfr - 1 ]; + NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; /* Save quantized speech and noise shaping signals */ SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int16 ) ); @@ -159,7 +157,7 @@ void SKP_Silk_NSQ( #ifdef SAVE_ALL_INTERNAL_DATA DEBUG_STORE_DATA( xq.dat, &pxq[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) ); - DEBUG_STORE_DATA( q.dat, &q[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int8 ) ); + DEBUG_STORE_DATA( q.dat, &pulses[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int8 ) ); DEBUG_STORE_DATA( sLTP_Q16.dat, &sLTP_Q16[ psEncC->ltp_mem_length ], psEncC->frame_length * sizeof( SKP_int32 ) ); #endif } @@ -171,7 +169,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ SKP_int signalType, /* I Signal type */ const SKP_int32 x_sc_Q10[], /* I */ - SKP_int8 q[], /* O */ + SKP_int8 pulses[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -317,7 +315,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( q_Q10 = SKP_LSHIFT( q_Q0, 10 ); } } - q[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */ + pulses[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */ /* Excitation */ exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 ); @@ -342,7 +340,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( NSQ->sLTP_buf_idx++; /* Make dither dependent on quantized signal */ - NSQ->rand_seed += q[ i ]; + NSQ->rand_seed += pulses[ i ]; } /* Update LPC synth buffer */ @@ -350,13 +348,13 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( } SKP_INLINE void SKP_Silk_nsq_scale_states( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ - const SKP_int16 x[], /* I input in Q0 */ - SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ - const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */ - SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ - SKP_int subfr, /* I subframe number */ + const SKP_Silk_encoder_state *psEncC, /* I Encoder State */ + SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + const SKP_int16 x[], /* I input in Q0 */ + SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ + const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */ + SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ + SKP_int subfr, /* I subframe number */ const SKP_int LTP_scale_Q14, /* I */ const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ const SKP_int pitchL[ MAX_NB_SUBFR ] /* I */ diff --git a/src_common/SKP_Silk_NSQ_del_dec.c b/src_common/SKP_Silk_NSQ_del_dec.c index dc50e73af..eba6f7c68 100644 --- a/src_common/SKP_Silk_NSQ_del_dec.c +++ b/src_common/SKP_Silk_NSQ_del_dec.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -28,14 +28,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" typedef struct { + SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + NSQ_LPC_BUF_LENGTH ]; SKP_int32 RandState[ DECISION_DELAY ]; SKP_int32 Q_Q10[ DECISION_DELAY ]; SKP_int32 Xq_Q10[ DECISION_DELAY ]; SKP_int32 Pred_Q16[ DECISION_DELAY ]; SKP_int32 Shape_Q10[ DECISION_DELAY ]; - SKP_int32 Gain_Q16[ DECISION_DELAY ]; SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; - SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + NSQ_LPC_BUF_LENGTH ]; SKP_int32 LF_AR_Q12; SKP_int32 Seed; SKP_int32 SeedInit; @@ -51,24 +50,18 @@ typedef struct { SKP_int32 LPC_exc_Q16; } NSQ_sample_struct; -SKP_INLINE void SKP_Silk_copy_del_dec_state( - NSQ_del_dec_struct *DD_dst, /* I Dst del dec state */ - NSQ_del_dec_struct *DD_src, /* I Src del dec state */ - SKP_int LPC_state_idx /* I Index to LPC buffer */ -); - SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - const SKP_int16 x[], /* I Input in Q0 */ - SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ - const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ - SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ - SKP_int subfr, /* I Subframe number */ - SKP_int nStatesDelayedDecision, /* I Number of del dec states */ - SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */ - const SKP_int LTP_scale_Q14, /* I LTP state scaling */ + const SKP_Silk_encoder_state *psEncC, /* I Encoder State */ + SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ + const SKP_int16 x[], /* I Input in Q0 */ + SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ + const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ + SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ + SKP_int subfr, /* I Subframe number */ + SKP_int nStatesDelayedDecision, /* I Number of del dec states */ + SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */ + const SKP_int LTP_scale_Q14, /* I LTP state scaling */ const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ const SKP_int pitchL[ MAX_NB_SUBFR ] /* I Pitch lag */ ); @@ -81,9 +74,10 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ SKP_int signalType, /* I Signal type */ const SKP_int32 x_Q10[], /* I */ - SKP_int8 q[], /* O */ + SKP_int8 pulses[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP filter state */ + SKP_int32 delayedGain_Q16[], /* I/O Gain delay buffer */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ const SKP_int16 b_Q14[], /* I Long term prediction coefs */ const SKP_int16 AR_shp_Q13[], /* I Noise shaping coefs */ @@ -105,19 +99,19 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( ); void SKP_Silk_NSQ_del_dec( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ + const SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ const SKP_int16 x[], /* I Prefiltered input signal */ - SKP_int8 q[], /* O Quantized pulse signal */ - const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ + SKP_int8 pulses[], /* O Quantized pulse signal */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I LT prediction coefs */ - const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ - const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I LT prediction coefs */ + const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ + const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I */ const SKP_int Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ) @@ -130,8 +124,9 @@ void SKP_Silk_NSQ_del_dec( SKP_int16 sLTP[ 2 * MAX_FRAME_LENGTH ]; SKP_int32 HarmShapeFIRPacked_Q14; SKP_int offset_Q10; - SKP_int32 FiltState[ MAX_LPC_ORDER ], RDmin_Q10; + SKP_int32 RDmin_Q10; SKP_int32 x_sc_Q10[ MAX_SUB_FRAME_LENGTH ]; + SKP_int32 delayedGain_Q16[ DECISION_DELAY ]; NSQ_del_dec_struct psDelDec[ MAX_DEL_DEC_STATES ]; NSQ_del_dec_struct *psDD; @@ -144,7 +139,7 @@ void SKP_Silk_NSQ_del_dec( SKP_memset( psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof( NSQ_del_dec_struct ) ); for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) { psDD = &psDelDec[ k ]; - psDD->Seed = ( k + psEncCtrlC->Seed ) & 3; + psDD->Seed = ( k + psIndices->Seed ) & 3; psDD->SeedInit = psDD->Seed; psDD->RD_Q10 = 0; psDD->LF_AR_Q12 = NSQ->sLF_AR_shp_Q12; @@ -153,15 +148,15 @@ void SKP_Silk_NSQ_del_dec( SKP_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) ); } - offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->signalType >> 1 ][ psEncCtrlC->quantOffsetType ]; + offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ psIndices->quantOffsetType ]; smpl_buf_idx = 0; /* index of oldest samples */ decisionDelay = SKP_min_int( DECISION_DELAY, psEncC->subfr_length ); /* For voiced frames limit the decision delay to lower than the pitch lag */ - if( psEncCtrlC->signalType == TYPE_VOICED ) { + if( psIndices->signalType == TYPE_VOICED ) { for( k = 0; k < psEncC->nb_subfr; k++ ) { - decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 ); + decisionDelay = SKP_min_int( decisionDelay, pitchL[ k ] - LTP_ORDER / 2 - 1 ); } } else { if( lag > 0 ) { @@ -169,7 +164,7 @@ void SKP_Silk_NSQ_del_dec( } } - if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) { + if( psIndices->NLSFInterpCoef_Q2 == 4 ) { LSF_interpolation_flag = 0; } else { LSF_interpolation_flag = 1; @@ -191,9 +186,9 @@ void SKP_Silk_NSQ_del_dec( HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 ); NSQ->rewhite_flag = 0; - if( psEncCtrlC->signalType == TYPE_VOICED ) { + if( psIndices->signalType == TYPE_VOICED ) { /* Voiced */ - lag = psEncCtrlC->pitchL[ k ]; + lag = pitchL[ k ]; /* Re-whitening */ if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) { @@ -220,9 +215,9 @@ void SKP_Silk_NSQ_del_dec( last_smple_idx = smpl_buf_idx + decisionDelay; for( i = 0; i < decisionDelay; i++ ) { last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; - q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); + pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( - SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) ); + SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], Gains_Q16[ 1 ] ), 10 ) ); NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ]; } @@ -233,9 +228,8 @@ void SKP_Silk_NSQ_del_dec( start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; SKP_assert( start_idx > 0 ); - SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) ); - SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ], - A_Q12, FiltState, &sLTP[ start_idx ], psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder ); + SKP_Silk_LPC_analysis_filter( &sLTP[ start_idx ], &NSQ->xq[ start_idx + k * psEncC->subfr_length ], + A_Q12, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder ); NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; NSQ->rewhite_flag = 1; @@ -243,16 +237,16 @@ void SKP_Silk_NSQ_del_dec( } SKP_Silk_nsq_del_dec_scale_states( psEncC, NSQ, psDelDec, x, x_sc_Q10, sLTP, sLTP_Q16, k, - psEncC->nStatesDelayedDecision, smpl_buf_idx, LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL ); + psEncC->nStatesDelayedDecision, smpl_buf_idx, LTP_scale_Q14, Gains_Q16, pitchL ); - SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->signalType, x_sc_Q10, q, pxq, sLTP_Q16, - A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], - Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, - psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay ); + SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q16, + delayedGain_Q16, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], + Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, + psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay ); - x += psEncC->subfr_length; - q += psEncC->subfr_length; - pxq += psEncC->subfr_length; + x += psEncC->subfr_length; + pulses += psEncC->subfr_length; + pxq += psEncC->subfr_length; } /* Find winner */ @@ -267,13 +261,13 @@ void SKP_Silk_NSQ_del_dec( /* Copy final part of signals from winner state to output and long-term filter states */ psDD = &psDelDec[ Winner_ind ]; - psEncCtrlC->Seed = psDD->SeedInit; + psIndices->Seed = psDD->SeedInit; last_smple_idx = smpl_buf_idx + decisionDelay; for( i = 0; i < decisionDelay; i++ ) { last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; - q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); + pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( - SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) ); + SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], Gains_Q16[ psEncC->nb_subfr - 1 ] ), 10 ) ); NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ]; sLTP_Q16[ NSQ->sLTP_buf_idx - decisionDelay + i ] = psDD->Pred_Q16[ last_smple_idx ]; } @@ -282,7 +276,7 @@ void SKP_Silk_NSQ_del_dec( /* Update states */ NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12; - NSQ->lagPrev = psEncCtrlC->pitchL[ psEncC->nb_subfr - 1 ]; + NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; /* Save quantized speech and noise shaping signals */ SKP_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int16 ) ); @@ -290,7 +284,7 @@ void SKP_Silk_NSQ_del_dec( #ifdef SAVE_ALL_INTERNAL_DATA DEBUG_STORE_DATA( xq.dat, &pxq[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) ); - DEBUG_STORE_DATA( q.dat, &q[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int8 ) ); + DEBUG_STORE_DATA( q.dat, &pulses[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int8 ) ); DEBUG_STORE_DATA( sLTP_Q16.dat, &sLTP_Q16[ psEncC->ltp_mem_length ], psEncC->frame_length * sizeof( SKP_int32 ) ); #endif } @@ -303,9 +297,10 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ SKP_int signalType, /* I Signal type */ const SKP_int32 x_Q10[], /* I */ - SKP_int8 q[], /* O */ + SKP_int8 pulses[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP filter state */ + SKP_int32 delayedGain_Q16[], /* I/O Gain delay buffer */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ const SKP_int16 b_Q14[], /* I Long term prediction coefs */ const SKP_int16 AR_shp_Q13[], /* I Noise shaping coefs */ @@ -470,13 +465,13 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( if( rd1_Q10 < rd2_Q10 ) { psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 ); psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 ); - psSS[ 0 ].Q_Q10 = q1_Q10; - psSS[ 1 ].Q_Q10 = q2_Q10; + psSS[ 0 ].Q_Q10 = q1_Q10; + psSS[ 1 ].Q_Q10 = q2_Q10; } else { psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 ); psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 ); - psSS[ 0 ].Q_Q10 = q2_Q10; - psSS[ 1 ].Q_Q10 = q1_Q10; + psSS[ 0 ].Q_Q10 = q2_Q10; + psSS[ 1 ].Q_Q10 = q1_Q10; } /* Update states for best quantization */ @@ -557,16 +552,17 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( /* Replace a state if best from second set outperforms worst in first set */ if( RDmin_Q10 < RDmax_Q10 ) { - SKP_Silk_copy_del_dec_state( &psDelDec[ RDmax_ind ], &psDelDec[ RDmin_ind ], i ); + SKP_memcpy( ((SKP_int32 *)&psDelDec[ RDmax_ind ]) + i, + ((SKP_int32 *)&psDelDec[ RDmin_ind ]) + i, sizeof( NSQ_del_dec_struct ) - i * sizeof( SKP_int32) ); SKP_memcpy( &psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof( NSQ_sample_struct ) ); } /* Write samples from winner to output and long-term filter states */ psDD = &psDelDec[ Winner_ind ]; if( subfr > 0 || i >= decisionDelay ) { - q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); + pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( - SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) ); + SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], delayedGain_Q16[ last_smple_idx ] ), 10 ) ); NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ]; sLTP_Q16[ NSQ->sLTP_buf_idx - decisionDelay ] = psDD->Pred_Q16[ last_smple_idx ]; } @@ -586,8 +582,8 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( psDD->Seed = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 ); psDD->RandState[ *smpl_buf_idx ] = psDD->Seed; psDD->RD_Q10 = psSS->RD_Q10; - psDD->Gain_Q16[ *smpl_buf_idx ] = Gain_Q16; } + delayedGain_Q16[ *smpl_buf_idx ] = Gain_Q16; } /* Update LPC states */ for( k = 0; k < nStatesDelayedDecision; k++ ) { @@ -597,17 +593,17 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( } SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - const SKP_int16 x[], /* I Input in Q0 */ - SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ - const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ - SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ - SKP_int subfr, /* I Subframe number */ - SKP_int nStatesDelayedDecision, /* I Number of del dec states */ - SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */ - const SKP_int LTP_scale_Q14, /* I LTP state scaling */ + const SKP_Silk_encoder_state *psEncC, /* I Encoder State */ + SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ + const SKP_int16 x[], /* I Input in Q0 */ + SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ + const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ + SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */ + SKP_int subfr, /* I Subframe number */ + SKP_int nStatesDelayedDecision, /* I Number of del dec states */ + SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */ + const SKP_int LTP_scale_Q14, /* I LTP state scaling */ const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ const SKP_int pitchL[ MAX_NB_SUBFR ] /* I Pitch lag */ ) @@ -678,22 +674,3 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( SKP_assert( inv_gain_Q16 != 0 ); NSQ->prev_inv_gain_Q16 = inv_gain_Q16; } - -SKP_INLINE void SKP_Silk_copy_del_dec_state( - NSQ_del_dec_struct *DD_dst, /* I Dst del dec state */ - NSQ_del_dec_struct *DD_src, /* I Src del dec state */ - SKP_int LPC_state_idx /* I Index to LPC buffer */ -) -{ - SKP_memcpy( DD_dst->RandState, DD_src->RandState, sizeof( DD_src->RandState ) ); - SKP_memcpy( DD_dst->Q_Q10, DD_src->Q_Q10, sizeof( DD_src->Q_Q10 ) ); - SKP_memcpy( DD_dst->Pred_Q16, DD_src->Pred_Q16, sizeof( DD_src->Pred_Q16 ) ); - SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, sizeof( DD_src->Shape_Q10 ) ); - SKP_memcpy( DD_dst->Xq_Q10, DD_src->Xq_Q10, sizeof( DD_src->Xq_Q10 ) ); - SKP_memcpy( DD_dst->sAR2_Q14, DD_src->sAR2_Q14, sizeof( DD_src->sAR2_Q14 ) ); - SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) ); - DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12; - DD_dst->Seed = DD_src->Seed; - DD_dst->SeedInit = DD_src->SeedInit; - DD_dst->RD_Q10 = DD_src->RD_Q10; -} diff --git a/src_common/SKP_Silk_PLC.c b/src_common/SKP_Silk_PLC.c index a9f7a8d21..a99ebf8de 100644 --- a/src_common/SKP_Silk_PLC.c +++ b/src_common/SKP_Silk_PLC.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -86,9 +86,9 @@ void SKP_Silk_PLC_update( psPLC = &psDec->sPLC; /* Update parameters used in case of packet loss */ - psDec->prevSignalType = psDecCtrl->signalType; + psDec->prevSignalType = psDec->indices.signalType; LTP_Gain_Q14 = 0; - if( psDecCtrl->signalType == TYPE_VOICED ) { + if( psDec->indices.signalType == TYPE_VOICED ) { /* Find the parameters for the last subframe which contains a pitch pulse */ for( j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; j++ ) { if( j == psDec->nb_subfr ){ diff --git a/src_common/SKP_Silk_PLC.h b/src_common/SKP_Silk_PLC.h index 015a5fa80..d23f994af 100644 --- a/src_common/SKP_Silk_PLC.h +++ b/src_common/SKP_Silk_PLC.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_VAD.c b/src_common/SKP_Silk_VAD.c index 703b2fc42..96ca24bf1 100644 --- a/src_common/SKP_Silk_VAD.c +++ b/src_common/SKP_Silk_VAD.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_VQ_WMat_EC.c b/src_common/SKP_Silk_VQ_WMat_EC.c index 4d7ba854d..1bcd91c23 100644 --- a/src_common/SKP_Silk_VQ_WMat_EC.c +++ b/src_common/SKP_Silk_VQ_WMat_EC.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Entropy constrained matrix-weighted VQ, hard-coded to 5-element vectors, for a single input data vector */ void SKP_Silk_VQ_WMat_EC( - SKP_int *ind, /* O index of best codebook vector */ + SKP_int8 *ind, /* O index of best codebook vector */ SKP_int32 *rate_dist_Q14, /* O best weighted quantization error + mu * rate*/ const SKP_int16 *in_Q14, /* I input vector to be quantized */ const SKP_int32 *W_Q18, /* I weighting matrix */ @@ -98,7 +98,7 @@ void SKP_Silk_VQ_WMat_EC( /* find best */ if( sum1_Q14 < *rate_dist_Q14 ) { *rate_dist_Q14 = sum1_Q14; - *ind = k; + *ind = (SKP_int8)k; } /* Go to next cbk vector */ diff --git a/src_common/SKP_Silk_code_signs.c b/src_common/SKP_Silk_code_signs.c index 70f6a0aaa..ee15f9815 100644 --- a/src_common/SKP_Silk_code_signs.c +++ b/src_common/SKP_Silk_code_signs.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -36,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Encodes signs of excitation */ void SKP_Silk_encode_signs( ec_enc *psRangeEnc, /* I/O Compressor data structure */ - const SKP_int8 q[], /* I pulse signal */ + const SKP_int8 pulses[], /* I pulse signal */ SKP_int length, /* I length of input */ const SKP_int signalType, /* I Signal type */ const SKP_int quantOffsetType, /* I Quantization offset type */ @@ -49,7 +49,7 @@ void SKP_Silk_encode_signs( const SKP_uint8 *icdf_ptr; icdf[ 1 ] = 0; - q_ptr = q; + q_ptr = pulses; i = SKP_SMULBB( 6, SKP_ADD_LSHIFT( quantOffsetType, signalType, 1 ) ); icdf_ptr = &SKP_Silk_sign_iCDF[ i ]; length = SKP_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH ); @@ -70,7 +70,7 @@ void SKP_Silk_encode_signs( /* Decodes signs of excitation */ void SKP_Silk_decode_signs( ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_int q[], /* I/O pulse signal */ + SKP_int pulses[], /* I/O pulse signal */ SKP_int length, /* I length of input */ const SKP_int signalType, /* I Signal type */ const SKP_int quantOffsetType, /* I Quantization offset type */ @@ -83,7 +83,7 @@ void SKP_Silk_decode_signs( const SKP_uint8 *icdf_ptr; icdf[ 1 ] = 0; - q_ptr = q; + q_ptr = pulses; i = SKP_SMULBB( 6, SKP_ADD_LSHIFT( quantOffsetType, signalType, 1 ) ); icdf_ptr = &SKP_Silk_sign_iCDF[ i ]; length = SKP_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH ); @@ -94,7 +94,7 @@ void SKP_Silk_decode_signs( for( j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++ ) { if( q_ptr[ j ] > 0 ) { /* attach sign */ -#if 1 +#if 0 /* conditional implementation */ if( ec_dec_icdf( psRangeDec, icdf, 8 ) == 0 ) { q_ptr[ j ] = -q_ptr[ j ]; diff --git a/src_common/SKP_Silk_control_audio_bandwidth.c b/src_common/SKP_Silk_control_audio_bandwidth.c index 3b8d502cb..6b728da61 100644 --- a/src_common/SKP_Silk_control_audio_bandwidth.c +++ b/src_common/SKP_Silk_control_audio_bandwidth.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_create_init_destroy.c b/src_common/SKP_Silk_create_init_destroy.c index 93cdaf730..0a1e02a4b 100644 --- a/src_common/SKP_Silk_create_init_destroy.c +++ b/src_common/SKP_Silk_create_init_destroy.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_dec_API.c b/src_common/SKP_Silk_dec_API.c index 6fb82424b..a071813e1 100644 --- a/src_common/SKP_Silk_dec_API.c +++ b/src_common/SKP_Silk_dec_API.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -60,14 +60,15 @@ SKP_int SKP_Silk_SDK_InitDecoder( SKP_int SKP_Silk_SDK_Decode( void* decState, /* I/O: State */ SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */ - SKP_int lostFlag, /* I: 0: no loss, 1 loss */ + SKP_int lostFlag, /* I: 0: no loss, 1 loss, 2 decode fec */ + SKP_int newPacketFlag, /* I: Indicates first decoder call for this packet */ 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 /* O: Number of samples decoded */ ) { - SKP_int ret = SKP_SILK_NO_ERROR, used_bytes, prev_fs_kHz; + SKP_int ret = SKP_SILK_NO_ERROR, prev_fs_kHz; SKP_Silk_decoder_state *psDec; psDec = (SKP_Silk_decoder_state *)decState; @@ -75,35 +76,27 @@ SKP_int SKP_Silk_SDK_Decode( /**********************************/ /* Test if first frame in payload */ /**********************************/ - if( psDec->moreInternalDecoderFrames == 0 ) { + if( newPacketFlag ) { /* First Frame in Payload */ psDec->nFramesDecoded = 0; /* Used to count frames in packet */ } - if( psDec->moreInternalDecoderFrames == 0 && /* First frame in packet */ - lostFlag == 0 && /* Not packet loss */ - nBytesIn > MAX_ARITHM_BYTES ) { /* Too long payload */ - /* Avoid trying to decode a too large packet */ - lostFlag = 1; - return SKP_SILK_DEC_PAYLOAD_TOO_LARGE; - } - /* Save previous sample frequency */ prev_fs_kHz = psDec->fs_kHz; if( psDec->nFramesDecoded == 0 ) { SKP_int fs_kHz_dec; if( decControl->payloadSize_ms == 10 ) { - psDec->nFramesInPacket = 1; + psDec->nFramesPerPacket = 1; psDec->nb_subfr = 2; } else if( decControl->payloadSize_ms == 20 ) { - psDec->nFramesInPacket = 1; + psDec->nFramesPerPacket = 1; psDec->nb_subfr = 4; } else if( decControl->payloadSize_ms == 40 ) { - psDec->nFramesInPacket = 2; + psDec->nFramesPerPacket = 2; psDec->nb_subfr = 4; } else if( decControl->payloadSize_ms == 60 ) { - psDec->nFramesInPacket = 3; + psDec->nFramesPerPacket = 3; psDec->nb_subfr = 4; } else { SKP_assert( 0 ); @@ -118,28 +111,8 @@ SKP_int SKP_Silk_SDK_Decode( } /* Call decoder for one frame */ - ret += SKP_Silk_decode_frame( psDec, psRangeDec, samplesOut, nSamplesOut, nBytesIn, lostFlag, &used_bytes ); + ret += SKP_Silk_decode_frame( psDec, psRangeDec, samplesOut, nSamplesOut, nBytesIn, lostFlag ); - if( used_bytes ) { /* Only Call if not a packet loss */ - psDec->moreInternalDecoderFrames = psDec->nFramesInPacket - psDec->nFramesDecoded; - if( psDec->nBytesLeft <= 0 || psDec->moreInternalDecoderFrames <= 0 ) { - /* Last frame in Payload */ - - /* Track inband FEC usage */ - if( psDec->vadFlag == VOICE_ACTIVITY ) { - if( psDec->FrameTermination == SKP_SILK_NO_LBRR ) { - psDec->no_FEC_counter++; - if( psDec->no_FEC_counter > NO_LBRR_THRES ) { - psDec->inband_FEC_offset = 0; - } - } else if( psDec->FrameTermination == SKP_SILK_LBRR ) { - psDec->inband_FEC_offset = 1; /* FEC info with 1 packet delay */ - psDec->no_FEC_counter = 0; - } - } - } - } - if( decControl->API_sampleRate > MAX_API_FS_KHZ * 1000 || decControl->API_sampleRate < 8000 ) { ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY; return( ret ); @@ -169,99 +142,38 @@ SKP_int SKP_Silk_SDK_Decode( /* Copy all parameters that are needed out of internal structure to the control stucture */ decControl->frameSize = ( SKP_int )*nSamplesOut; - decControl->framesPerPayload = ( SKP_int )psDec->nFramesInPacket; - decControl->inBandFECOffset = ( SKP_int )psDec->inband_FEC_offset; - decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames; + decControl->framesPerPayload = ( SKP_int )psDec->nFramesPerPacket; return ret; } -#if 0 -/* Function to find LBRR information in a packet */ -void SKP_Silk_SDK_search_for_LBRR( - const SKP_uint8 *inData, /* I: Encoded input vector */ - const SKP_int16 nBytesIn, /* I: Number of input Bytes */ - SKP_int lost_offset, /* I: Offset from lost packet */ - SKP_uint8 *LBRRData, /* O: LBRR payload */ - SKP_int16 *nLBRRBytes /* O: Number of LBRR Bytes */ +/* Getting table of contents for a packet */ +SKP_int SKP_Silk_SDK_get_TOC( + const SKP_uint8 *payload, /* I Payload data */ + const SKP_int nBytesIn, /* I: Number of input bytes */ + const SKP_int nFramesPerPayload, /* I: Number of SILK frames per payload */ + SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */ ) { - SKP_int ret = SKP_SILK_NO_ERROR; - SKP_Silk_decoder_state sDec; // Local decoder state to avoid interfering with running decoder */ - SKP_Silk_decoder_control sDecCtrl; - SKP_int i, TempQ[ MAX_FRAME_LENGTH ]; + SKP_int i, flags, ret = SKP_SILK_NO_ERROR; - if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) { - /* No useful FEC in this packet */ - *nLBRRBytes = 0; - return; + if( nBytesIn < 1 ) { + return -1; } - - sDec.nFramesDecoded = 0; - sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */ - SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); - - /* Decode all parameter indices for the whole packet*/ - SKP_Silk_decode_indices( &sDec, psRangeDec ); - - /* Is there usable LBRR in this packet */ - *nLBRRBytes = 0; - if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) { - /* The wanted FEC is present in the packet */ - for( i = 0; i < sDec.nFramesInPacket; i++ ) { - SKP_Silk_decode_parameters( &sDec, &sDecCtrl, psRangeDec, TempQ, 0 ); - - if( sDec.nBytesLeft <= 0 || sDec.sRC.error ) { - /* Corrupt stream */ - LBRRData = NULL; - *nLBRRBytes = 0; - break; - } else { - sDec.nFramesDecoded++; - } - } - - if( LBRRData != NULL ) { - /* The wanted FEC is present in the packet */ - *nLBRRBytes = sDec.nBytesLeft; - SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) ); - } + if( nFramesPerPayload < 0 || nFramesPerPayload > 3 ) { + return -1; } -} -#endif -/* Getting type of content for a packet */ -void SKP_Silk_SDK_get_TOC( - ec_dec *psRangeDec, /* I/O Compressor data structure */ - const SKP_int16 nBytesIn, /* I: Number of input bytes */ - SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */ -) -{ - SKP_Silk_decoder_state sDec; // Local Decoder state to avoid interfering with running decoder */ - SKP_int i, ret = SKP_SILK_NO_ERROR; + SKP_memset( Silk_TOC, 0, sizeof( Silk_TOC ) ); - sDec.nFramesDecoded = 0; - sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */ + flags = SKP_RSHIFT( payload[ 0 ], 7 - nFramesPerPayload ) & ( SKP_LSHIFT( 1, nFramesPerPayload + 1 ) - 1 ); - /* Decode all parameter indices for the whole packet*/ - SKP_Silk_decode_indices( &sDec, psRangeDec ); - - if( psRangeDec->error ) { - /* Corrupt packet */ - SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) ); - Silk_TOC->corrupt = 1; - } else { - Silk_TOC->corrupt = 0; - Silk_TOC->framesInPacket = sDec.nFramesInPacket; - Silk_TOC->fs_kHz = sDec.fs_kHz; - if( sDec.FrameTermination == SKP_SILK_LBRR ) { - Silk_TOC->inbandLBRR = 1; - } else { - Silk_TOC->inbandLBRR = 0; - } - /* Copy data */ - for( i = 0; i < sDec.nFramesInPacket; i++ ) { - Silk_TOC->signalTypeFlags[ i ] = sDec.signalType[ i ]; - } + Silk_TOC->inbandFECFlag = flags & 1; + for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) { + flags = SKP_RSHIFT( flags, 1 ); + Silk_TOC->VADFlags[ i ] = flags & 1; + Silk_TOC->VADFlag |= flags & 1; } + + return ret; } diff --git a/src_common/SKP_Silk_decode_core.c b/src_common/SKP_Silk_decode_core.c index cfe9451bf..67767c30b 100644 --- a/src_common/SKP_Silk_decode_core.c +++ b/src_common/SKP_Silk_decode_core.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -34,43 +34,42 @@ void SKP_Silk_decode_core( SKP_Silk_decoder_state *psDec, /* I/O Decoder state */ SKP_Silk_decoder_control *psDecCtrl, /* I Decoder control */ SKP_int16 xq[], /* O Decoded speech */ - const SKP_int q[ MAX_FRAME_LENGTH ] /* I Pulse signal */ + const SKP_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */ ) { SKP_int i, j, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType; SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ]; SKP_int16 sLTP[ MAX_FRAME_LENGTH ]; SKP_int32 LTP_pred_Q14, LPC_pred_Q10, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10, dither; - SKP_int32 *pred_lag_ptr, *pexc_Q10; + SKP_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10; + SKP_int32 res_Q10[ MAX_SUB_FRAME_LENGTH ]; SKP_int32 vec_Q10[ MAX_SUB_FRAME_LENGTH ]; - SKP_int32 FiltState[ MAX_LPC_ORDER ]; SKP_assert( psDec->prev_inv_gain_Q16 != 0 ); - offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDecCtrl->signalType >> 1 ][ psDecCtrl->quantOffsetType ]; + offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ][ psDec->indices.quantOffsetType ]; - if( psDecCtrl->NLSFInterpCoef_Q2 < 1 << 2 ) { + if( psDec->indices.NLSFInterpCoef_Q2 < 1 << 2 ) { NLSF_interpolation_flag = 1; } else { NLSF_interpolation_flag = 0; } /* Decode excitation */ - rand_seed = psDecCtrl->Seed; + rand_seed = psDec->indices.Seed; for( i = 0; i < psDec->frame_length; i++ ) { rand_seed = SKP_RAND( rand_seed ); /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */ dither = SKP_RSHIFT( rand_seed, 31 ); - psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )q[ i ], 10 ) + offset_Q10; + psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )pulses[ i ], 10 ) + offset_Q10; psDec->exc_Q10[ i ] = ( psDec->exc_Q10[ i ] ^ dither ) - dither; - rand_seed += q[ i ]; + rand_seed += pulses[ i ]; } #ifdef SAVE_ALL_INTERNAL_DATA DEBUG_STORE_DATA( dec_q.dat, q, psDec->frame_length * sizeof( SKP_int ) ); - DEBUG_STORE_DATA( dec_exc_Q10.dat, psDec->exc_Q10, psDec->frame_length * sizeof( SKP_int32 )); #endif pexc_Q10 = psDec->exc_Q10; @@ -78,13 +77,14 @@ void SKP_Silk_decode_core( sLTP_buf_idx = psDec->ltp_mem_length; /* Loop over subframes */ for( k = 0; k < psDec->nb_subfr; k++ ) { + pres_Q10 = res_Q10; A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ]; /* Preload LPC coeficients to array on stack. Gives small performance gain */ SKP_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( SKP_int16 ) ); B_Q14 = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ]; Gain_Q16 = psDecCtrl->Gains_Q16[ k ]; - signalType = psDecCtrl->signalType; + signalType = psDec->indices.signalType; inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gain_Q16, 1 ), 32 ); inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX ); @@ -106,7 +106,7 @@ void SKP_Silk_decode_core( /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */ if( psDec->lossCnt && psDec->prevSignalType == TYPE_VOICED && - psDecCtrl->signalType != TYPE_VOICED && k < MAX_NB_SUBFR/2 ) { + psDec->indices.signalType != TYPE_VOICED && k < MAX_NB_SUBFR/2 ) { SKP_memset( B_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) ); B_Q14[ LTP_ORDER/2 ] = SKP_FIX_CONST( 0.25, 14 ); @@ -125,9 +125,8 @@ void SKP_Silk_decode_core( start_idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2; SKP_assert( start_idx > 0 ); - SKP_memset( FiltState, 0, psDec->LPC_order * sizeof( SKP_int32 ) ); - SKP_Silk_MA_Prediction( &psDec->outBuf[ start_idx + k * psDec->subfr_length ], - A_Q12, FiltState, &sLTP[ start_idx ], psDec->ltp_mem_length - start_idx, psDec->LPC_order ); + SKP_Silk_LPC_analysis_filter( &sLTP[ start_idx ], &psDec->outBuf[ start_idx + k * psDec->subfr_length ], + A_Q12, psDec->ltp_mem_length - start_idx, psDec->LPC_order ); /* After rewhitening the LTP state is unscaled */ inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 ); @@ -162,16 +161,19 @@ void SKP_Silk_decode_core( pred_lag_ptr++; /* Generate LPC residual */ - pexc_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) ); + pres_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) ); /* Update states */ - psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( pexc_Q10[ i ], 6 ); + psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( pres_Q10[ i ], 6 ); sLTP_buf_idx++; } + } else { + pres_Q10 = pexc_Q10; } #ifdef SAVE_ALL_INTERNAL_DATA - DEBUG_STORE_DATA( dec_res_Q10.dat, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( dec_exc_Q10.dat, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( dec_res_Q10.dat, pres_Q10, psDec->subfr_length * sizeof( SKP_int32 ) ); #endif for( i = 0; i < psDec->subfr_length; i++ ) { @@ -191,7 +193,7 @@ void SKP_Silk_decode_core( } /* Add prediction to LPC residual */ - vec_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], LPC_pred_Q10 ); + vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 ); /* Update states */ psDec->sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 ); diff --git a/src_common/SKP_Silk_decode_frame.c b/src_common/SKP_Silk_decode_frame.c index 101d962a9..b457b3207 100644 --- a/src_common/SKP_Silk_decode_frame.c +++ b/src_common/SKP_Silk_decode_frame.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -28,6 +28,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" #include "SKP_Silk_PLC.h" +#define DECODE_NORMAL 0 +#define PACKET_LOST 1 +#define DECODE_LBRR 2 + /****************/ /* Decode frame */ /****************/ @@ -37,15 +41,16 @@ SKP_int SKP_Silk_decode_frame( SKP_int16 pOut[], /* O Pointer to output speech frame */ SKP_int32 *pN, /* O Pointer to size of output frame */ const SKP_int nBytes, /* I Payload length */ - SKP_int action, /* I Action from Jitter Buffer */ - SKP_int *decBytes /* O Used bytes to decode this frame */ + SKP_int lostFlag /* I 0: no loss, 1 loss, 2 decode fec */ ) { SKP_Silk_decoder_control sDecCtrl; - SKP_int L, fs_Khz_old, nb_subfr_old, mv_len, ret = 0; - SKP_int Pulses[ MAX_FRAME_LENGTH ]; + SKP_int i, L, mv_len, ret = 0; + SKP_int8 flags; + SKP_int32 LBRR_symbol; + SKP_int pulses[ MAX_FRAME_LENGTH ]; -TIC(decode_frame) +TIC(DECODE_FRAME) L = psDec->frame_length; sDecCtrl.LTP_scale_Q14 = 0; @@ -54,29 +59,78 @@ TIC(decode_frame) SKP_assert( L > 0 && L <= MAX_FRAME_LENGTH ); /********************************************/ - /* Decode Frame if packet is not lost */ + /* Decode Frame if packet is not lost */ /********************************************/ - *decBytes = 0; - if( action == 0 ) { - /********************************************/ - /* Initialize arithmetic coder */ - /********************************************/ - fs_Khz_old = psDec->fs_kHz; - nb_subfr_old = psDec->nb_subfr; - if( psDec->nFramesDecoded == 0 ) { - SKP_Silk_decode_indices( psDec, psRangeDec ); + if( lostFlag != PACKET_LOST && psDec->nFramesDecoded == 0 ) { + /* First decoder call for this payload */ + /* Decode VAD flags and LBRR flag */ + SKP_uint8 iCDF[ 2 ] = { 128, 0 }; + flags = SKP_RSHIFT( psRangeDec->buf[ 0 ], 7 - psDec->nFramesPerPacket ) & + ( SKP_LSHIFT( 1, psDec->nFramesPerPacket + 1 ) - 1 ); + psDec->LBRR_flag = flags & 1; + for( i = psDec->nFramesPerPacket - 1; i >= 0 ; i-- ) { + flags = SKP_RSHIFT( flags, 1 ); + psDec->VAD_flags[ i ] = flags & 1; + } + for( i = 0; i < psDec->nFramesPerPacket + 1; i++ ) { + ec_dec_icdf( psRangeDec, iCDF, 8 ); + } + + /* Decode LBRR flags */ + SKP_memset( psDec->LBRR_flags, 0, sizeof( psDec->LBRR_flags ) ); + if( psDec->LBRR_flag ) { + if( psDec->nFramesPerPacket == 1 ) { + psDec->LBRR_flags[ 0 ] = 1; + } else { + LBRR_symbol = ec_dec_icdf( psRangeDec, SKP_Silk_LBRR_flags_iCDF_ptr[ psDec->nFramesPerPacket - 2 ], 8 ) + 1; + for( i = 0; i < psDec->nFramesPerPacket; i++ ) { + psDec->LBRR_flags[ i ] = SKP_RSHIFT( LBRR_symbol, i ) & 1; + } + } } + if( lostFlag == DECODE_NORMAL ) { + /* Regular decoding: skip all LBRR data */ + for( i = 0; i < psDec->nFramesPerPacket; i++ ) { + if( psDec->LBRR_flags[ i ] ) { + SKP_Silk_decode_indices( psDec, psRangeDec, i, 1 ); + SKP_Silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType, + psDec->indices.quantOffsetType, psDec->frame_length ); + } + } + } + + } + + if( lostFlag == DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 0 ) { + /* Treat absent LBRR data as lost frame */ + lostFlag = PACKET_LOST; + psDec->nFramesDecoded++; + } + + if( lostFlag != PACKET_LOST ) { + /*********************************************/ + /* Decode quantization indices of side info */ + /*********************************************/ +TIC(decode_indices) + SKP_Silk_decode_indices( psDec, psRangeDec, psDec->nFramesDecoded, lostFlag ); +TOC(decode_indices) + + /*********************************************/ + /* Decode quantization indices of excitation */ + /*********************************************/ +TIC(decode_pulses) + SKP_Silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType, + psDec->indices.quantOffsetType, psDec->frame_length ); +TOC(decode_pulses) + /********************************************/ /* Decode parameters and pulse signal */ /********************************************/ TIC(decode_params) - SKP_Silk_decode_parameters( psDec, &sDecCtrl, psRangeDec, Pulses ); + SKP_Silk_decode_parameters( psDec, &sDecCtrl ); TOC(decode_params) - *decBytes = psRangeDec->storage - psDec->nBytesLeft; - psDec->nFramesDecoded++; - /* Update length. Sampling frequency may have changed */ L = psDec->frame_length; @@ -84,27 +138,24 @@ TOC(decode_params) /* Run inverse NSQ */ /********************************************************/ TIC(decode_core) - SKP_Silk_decode_core( psDec, &sDecCtrl, pOut, Pulses ); + SKP_Silk_decode_core( psDec, &sDecCtrl, pOut, pulses ); TOC(decode_core) /********************************************************/ /* Update PLC state */ /********************************************************/ - SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action ); + SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, 0 ); psDec->lossCnt = 0; - psDec->prevSignalType = sDecCtrl.signalType; + psDec->prevSignalType = psDec->indices.signalType; + SKP_assert( psDec->prevSignalType >= 0 && psDec->prevSignalType <= 2 ); /* A frame has been decoded without errors */ psDec->first_frame_after_reset = 0; - } - - /*************************************************************/ - /* Generate Concealment frame if packet is lost, or corrupt */ - /*************************************************************/ - if( action == 1 ) { + psDec->nFramesDecoded++; + } else { /* Handle packet loss by extrapolation */ - SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action ); + SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, 1 ); } /*************************/ @@ -140,7 +191,8 @@ TOC(HP_out) /********************************************/ *pN = ( SKP_int16 )L; -TOC(decode_frame) +TOC(DECODE_FRAME) return ret; } + \ No newline at end of file diff --git a/src_common/SKP_Silk_decode_indices.c b/src_common/SKP_Silk_decode_indices.c index b324a70c6..95f7ebf28 100644 --- a/src_common/SKP_Silk_decode_indices.c +++ b/src_common/SKP_Silk_decode_indices.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -30,125 +30,119 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Decode indices from payload */ void SKP_Silk_decode_indices( SKP_Silk_decoder_state *psDec, /* I/O State */ - ec_dec *psRangeDec /* I/O Compressor data structure */ + ec_dec *psRangeDec, /* I/O Compressor data structure */ + SKP_int FrameIndex, /* I Frame number */ + SKP_int decode_LBRR /* I Flag indicating LBRR data is being decoded */ ) { - SKP_int i, k, Ix, FrameIndex; - SKP_int signalType, quantOffsetType, nBytesUsed; - SKP_int decode_absolute_lagIndex, delta_lagIndex, prev_lagIndex = 0; + SKP_int i, k, Ix, condCoding; + SKP_int decode_absolute_lagIndex, delta_lagIndex; const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL; - for( FrameIndex = 0; FrameIndex < psDec->nFramesInPacket; FrameIndex++ ) { - /*******************************************/ - /* Decode signal type and quantizer offset */ - /*******************************************/ - if( FrameIndex == 0 ) { - /* first frame in packet: independent coding */ - Ix = ec_dec_icdf( psRangeDec, SKP_Silk_type_offset_iCDF, 8 ); - } else { - /* conditional coding */ - Ix = ec_dec_icdf( psRangeDec, SKP_Silk_type_offset_joint_iCDF[ psDec->typeOffsetPrev ], 8 ); - } - signalType = SKP_RSHIFT( Ix, 1 ); - quantOffsetType = Ix & 1; - psDec->typeOffsetPrev = Ix; + if( FrameIndex > 0 && ( decode_LBRR == 0 || psDec->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) { + condCoding = 1; + } else { + condCoding = 0; + } - /****************/ - /* Decode gains */ - /****************/ - /* first subframe */ - if( FrameIndex == 0 ) { - /* first frame in packet: independent coding, in two stages: MSB bits followed by 3 LSBs */ - psDec->GainsIndices[ FrameIndex ][ 0 ] = SKP_LSHIFT( ec_dec_icdf( psRangeDec, SKP_Silk_gain_iCDF[ signalType ], 8 ), 3 ); - psDec->GainsIndices[ FrameIndex ][ 0 ] += ec_dec_icdf( psRangeDec, SKP_Silk_uniform8_iCDF, 8 ); - } else { - /* conditional coding */ - psDec->GainsIndices[ FrameIndex ][ 0 ] = ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 ); - } + /*******************************************/ + /* Decode signal type and quantizer offset */ + /*******************************************/ + if( decode_LBRR || psDec->VAD_flags[ FrameIndex ] ) { + Ix = ec_dec_icdf( psRangeDec, SKP_Silk_type_offset_VAD_iCDF, 8 ) + 2; + } else { + Ix = ec_dec_icdf( psRangeDec, SKP_Silk_type_offset_no_VAD_iCDF, 8 ); + } + psDec->indices.signalType = (SKP_int8)SKP_RSHIFT( Ix, 1 ); + psDec->indices.quantOffsetType = (SKP_int8)( Ix & 1 ); - /* remaining subframes */ - for( i = 1; i < psDec->nb_subfr; i++ ) { - psDec->GainsIndices[ FrameIndex ][ i ] = ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 ); - } + /****************/ + /* Decode gains */ + /****************/ + /* first subframe */ + if( condCoding ) { + /* conditional coding */ + psDec->indices.GainsIndices[ 0 ] = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 ); + } else { + /* independent coding, in two stages: MSB bits followed by 3 LSBs */ + psDec->indices.GainsIndices[ 0 ] = (SKP_int8)SKP_LSHIFT( ec_dec_icdf( psRangeDec, SKP_Silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 ); + psDec->indices.GainsIndices[ 0 ] += (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_uniform8_iCDF, 8 ); + } + + /* remaining subframes */ + for( i = 1; i < psDec->nb_subfr; i++ ) { + psDec->indices.GainsIndices[ i ] = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 ); + } - /**********************/ - /* Decode LSF Indices */ - /**********************/ - /* Set pointer to LSF VQ CB for the current signal type */ - psNLSF_CB = psDec->psNLSF_CB[ 1 - (signalType >> 1) ]; + /**********************/ + /* Decode LSF Indices */ + /**********************/ + /* Set pointer to LSF VQ CB for the current signal type */ + psNLSF_CB = psDec->psNLSF_CB[ 1 - ( psDec->indices.signalType >> 1 ) ]; - /* Range decoding of the NLSF path */ - for( i = 0; i < psNLSF_CB->nStages; i++ ) { - psDec->NLSFIndices[ FrameIndex ][ i ] = ec_dec_icdf( psRangeDec, psNLSF_CB->StartPtr[ i ], 8 ); - } + /* Range decoding of the NLSF path */ + for( i = 0; i < psNLSF_CB->nStages; i++ ) { + psDec->indices.NLSFIndices[ i ] = (SKP_int8)ec_dec_icdf( psRangeDec, psNLSF_CB->StartPtr[ i ], 8 ); + } - /***********************************/ - /* Decode LSF interpolation factor */ - /***********************************/ - if( psDec->nb_subfr == MAX_NB_SUBFR ) { - psDec->NLSFInterpCoef_Q2[ FrameIndex ] = ec_dec_icdf( psRangeDec, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 ); - } else { - psDec->NLSFInterpCoef_Q2[ FrameIndex ] = 4; - } + /***********************************/ + /* Decode LSF interpolation factor */ + /***********************************/ + if( psDec->nb_subfr == MAX_NB_SUBFR ) { + psDec->indices.NLSFInterpCoef_Q2 = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 ); + } else { + psDec->indices.NLSFInterpCoef_Q2 = 4; + } - if( signalType == TYPE_VOICED ) { - /*********************/ - /* Decode pitch lags */ - /*********************/ - /* Get lag index */ - decode_absolute_lagIndex = 1; - if( FrameIndex > 0 && psDec->signalType[ FrameIndex - 1 ] == TYPE_VOICED ) { - /* Decode Delta index */ - delta_lagIndex = ec_dec_icdf( psRangeDec, SKP_Silk_pitch_delta_iCDF, 8 ); - if( delta_lagIndex > 0 ) { - delta_lagIndex = delta_lagIndex - 9; - psDec->lagIndex[ FrameIndex ] = prev_lagIndex + delta_lagIndex; - decode_absolute_lagIndex = 0; - } - } - if( decode_absolute_lagIndex ) { - /* Absolute decoding */ - psDec->lagIndex[ FrameIndex ] = ec_dec_icdf( psRangeDec, SKP_Silk_pitch_lag_iCDF, 8 ) * SKP_RSHIFT( psDec->fs_kHz, 1 ); - psDec->lagIndex[ FrameIndex ] += ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 ); + if( psDec->indices.signalType == TYPE_VOICED ) + { + /*********************/ + /* Decode pitch lags */ + /*********************/ + /* Get lag index */ + decode_absolute_lagIndex = 1; + if( condCoding && psDec->ec_prevSignalType == TYPE_VOICED ) { + /* Decode Delta index */ + delta_lagIndex = (SKP_int16)ec_dec_icdf( psRangeDec, SKP_Silk_pitch_delta_iCDF, 8 ); + if( delta_lagIndex > 0 ) { + delta_lagIndex = delta_lagIndex - 9; + psDec->indices.lagIndex = (SKP_int16)( psDec->ec_prevLagIndex + delta_lagIndex ); + decode_absolute_lagIndex = 0; } - prev_lagIndex = psDec->lagIndex[ FrameIndex ]; + } + if( decode_absolute_lagIndex ) { + /* Absolute decoding */ + psDec->indices.lagIndex = (SKP_int16)ec_dec_icdf( psRangeDec, SKP_Silk_pitch_lag_iCDF, 8 ) * SKP_RSHIFT( psDec->fs_kHz, 1 ); + psDec->indices.lagIndex += (SKP_int16)ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 ); + } + psDec->ec_prevLagIndex = psDec->indices.lagIndex; - /* Get countour index */ - psDec->contourIndex[ FrameIndex ] = ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 ); + /* Get countour index */ + psDec->indices.contourIndex = (SKP_int8)ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 ); - /********************/ - /* Decode LTP gains */ - /********************/ - /* Decode PERIndex value */ - psDec->PERIndex[ FrameIndex ] = ec_dec_icdf( psRangeDec, SKP_Silk_LTP_per_index_iCDF, 8 ); - - for( k = 0; k < psDec->nb_subfr; k++ ) { - psDec->LTPIndex[ FrameIndex ][ k ] = ec_dec_icdf( psRangeDec, SKP_Silk_LTP_gain_iCDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], 8 ); - } + /********************/ + /* Decode LTP gains */ + /********************/ + /* Decode PERIndex value */ + psDec->indices.PERIndex = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_LTP_per_index_iCDF, 8 ); - /**********************/ - /* Decode LTP scaling */ - /**********************/ - psDec->LTP_scaleIndex[ FrameIndex ] = ec_dec_icdf( psRangeDec, SKP_Silk_LTPscale_iCDF, 8 ); + for( k = 0; k < psDec->nb_subfr; k++ ) { + psDec->indices.LTPIndex[ k ] = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8 ); } - /***************/ - /* Decode seed */ - /***************/ - psDec->Seed[ FrameIndex ] = ec_dec_icdf( psRangeDec, SKP_Silk_Seed_iCDF, 8 ); - - psDec->signalType[ FrameIndex ] = signalType; - psDec->quantOffsetType[ FrameIndex ] = quantOffsetType; + /**********************/ + /* Decode LTP scaling */ + /**********************/ + if( !condCoding ) { + psDec->indices.LTP_scaleIndex = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_LTPscale_iCDF, 8 ); + } else { + psDec->indices.LTP_scaleIndex = 0; + } } + psDec->ec_prevSignalType = psDec->indices.signalType; - /**************************************/ - /* Decode Frame termination indicator */ - /**************************************/ - psDec->FrameTermination = ec_dec_icdf( psRangeDec, SKP_Silk_LBRR_Present_iCDF, 8 ); - - /****************************************/ - /* Get number of bytes used so far */ - /****************************************/ - nBytesUsed = SKP_RSHIFT( ec_tell( psRangeDec ) + 7, 3 ); - psDec->nBytesLeft = psRangeDec->storage - nBytesUsed; + /***************/ + /* Decode seed */ + /***************/ + psDec->indices.Seed = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_uniform4_iCDF, 8 ); } diff --git a/src_common/SKP_Silk_decode_parameters.c b/src_common/SKP_Silk_decode_parameters.c index d5e64500f..08157da45 100644 --- a/src_common/SKP_Silk_decode_parameters.c +++ b/src_common/SKP_Silk_decode_parameters.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -30,34 +30,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Decode parameters from payload */ void SKP_Silk_decode_parameters( SKP_Silk_decoder_state *psDec, /* I/O State */ - SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */ - ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_int q[ MAX_FRAME_LENGTH ] /* O Excitation signal */ + SKP_Silk_decoder_control *psDecCtrl /* I/O Decoder control */ ) { - SKP_int i, k, Ix, nBytesUsed; + SKP_int i, k, Ix; SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ]; const SKP_int8 *cbk_ptr_Q7; const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL; - psDecCtrl->signalType = psDec->signalType[ psDec->nFramesDecoded ]; - psDecCtrl->quantOffsetType = psDec->quantOffsetType[ psDec->nFramesDecoded ]; - psDec->vadFlag = psDecCtrl->signalType > 0 ? 1 : 0; - psDecCtrl->NLSFInterpCoef_Q2 = psDec->NLSFInterpCoef_Q2[ psDec->nFramesDecoded ]; - psDecCtrl->Seed = psDec->Seed[ psDec->nFramesDecoded ]; - /* Dequant Gains */ - SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->GainsIndices[ psDec->nFramesDecoded ], + SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices, &psDec->LastGainIndex, psDec->nFramesDecoded, psDec->nb_subfr ); /****************/ /* Decode NLSFs */ /****************/ /* Set pointer to NLSF VQ CB for the current signal type */ - psNLSF_CB = psDec->psNLSF_CB[ 1 - (psDecCtrl->signalType >> 1) ]; + psNLSF_CB = psDec->psNLSF_CB[ 1 - (psDec->indices.signalType >> 1) ]; /* From the NLSF path, decode an NLSF vector */ - SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, psDec->NLSFIndices[ psDec->nFramesDecoded ], psDec->LPC_order ); + SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, psDec->indices.NLSFIndices, psDec->LPC_order ); /* Convert NLSF parameters to AR prediction filter coefficients */ SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order ); @@ -65,14 +57,14 @@ void SKP_Silk_decode_parameters( /* If just reset, e.g., because internal Fs changed, do not allow interpolation */ /* improves the case of packet loss in the first frame after a switch */ if( psDec->first_frame_after_reset == 1 ) { - psDecCtrl->NLSFInterpCoef_Q2 = 4; + psDec->indices.NLSFInterpCoef_Q2 = 4; } - if( psDecCtrl->NLSFInterpCoef_Q2 < 4 ) { + if( psDec->indices.NLSFInterpCoef_Q2 < 4 ) { /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */ /* the previous NLSF1, and the current NLSF1 */ for( i = 0; i < psDec->LPC_order; i++ ) { - pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + SKP_RSHIFT( SKP_MUL( psDecCtrl->NLSFInterpCoef_Q2, + pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + SKP_RSHIFT( SKP_MUL( psDec->indices.NLSFInterpCoef_Q2, pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ), 2 ); } @@ -92,25 +84,19 @@ void SKP_Silk_decode_parameters( SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); } - if( psDecCtrl->signalType == TYPE_VOICED ) { + if( psDec->indices.signalType == TYPE_VOICED ) { /*********************/ /* Decode pitch lags */ /*********************/ /* Decode pitch values */ - SKP_Silk_decode_pitch( psDec->lagIndex[ psDec->nFramesDecoded ], psDec->contourIndex[ psDec->nFramesDecoded ], - psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr ); - - /********************/ - /* Decode LTP gains */ - /********************/ - psDecCtrl->PERIndex = psDec->PERIndex[ psDec->nFramesDecoded ]; + SKP_Silk_decode_pitch( psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr ); /* Decode Codebook Index */ - cbk_ptr_Q7 = SKP_Silk_LTP_vq_ptrs_Q7[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */ + cbk_ptr_Q7 = SKP_Silk_LTP_vq_ptrs_Q7[ psDec->indices.PERIndex ]; /* set pointer to start of codebook */ for( k = 0; k < psDec->nb_subfr; k++ ) { - Ix = psDec->LTPIndex[ psDec->nFramesDecoded ][ k ]; + Ix = psDec->indices.LTPIndex[ k ]; for( i = 0; i < LTP_ORDER; i++ ) { psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = SKP_LSHIFT( cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7 ); } @@ -119,25 +105,12 @@ void SKP_Silk_decode_parameters( /**********************/ /* Decode LTP scaling */ /**********************/ - Ix = psDec->LTP_scaleIndex[ psDec->nFramesDecoded ]; + Ix = psDec->indices.LTP_scaleIndex; psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ]; } else { SKP_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( SKP_int ) ); SKP_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof( SKP_int16 ) ); - psDecCtrl->PERIndex = 0; + psDec->indices.PERIndex = 0; psDecCtrl->LTP_scale_Q14 = 0; } - - /*********************************************/ - /* Decode quantization indices of excitation */ - /*********************************************/ -TIC(decode_pulses) - SKP_Silk_decode_pulses( psRangeDec, psDecCtrl, q, psDec->frame_length ); -TOC(decode_pulses) - - /****************************************/ - /* get number of bytes used so far */ - /****************************************/ - nBytesUsed = SKP_RSHIFT( ec_tell( psRangeDec ) + 7, 3 ); - psDec->nBytesLeft = psRangeDec->storage - nBytesUsed; } diff --git a/src_common/SKP_Silk_decode_pulses.c b/src_common/SKP_Silk_decode_pulses.c index c0a865505..2a92790f7 100644 --- a/src_common/SKP_Silk_decode_pulses.c +++ b/src_common/SKP_Silk_decode_pulses.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -32,12 +32,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /*********************************************/ void SKP_Silk_decode_pulses( ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */ - SKP_int q[], /* O Excitation signal */ - const SKP_int frame_length /* I Frame length (preliminary) */ + SKP_int pulses[], /* O Excitation signal */ + const SKP_int signalType, /* I Sigtype */ + const SKP_int quantOffsetType, /* I quantOffsetType */ + const SKP_int frame_length /* I Frame length */ ) { - SKP_int i, j, k, iter, abs_q, nLS; + SKP_int i, j, k, iter, abs_q, nLS, RateLevelIndex; SKP_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ]; SKP_int *pulses_ptr; const SKP_uint8 *cdf_ptr; @@ -45,7 +46,7 @@ void SKP_Silk_decode_pulses( /*********************/ /* Decode rate level */ /*********************/ - psDecCtrl->RateLevelIndex = ec_dec_icdf( psRangeDec, SKP_Silk_rate_levels_iCDF[ psDecCtrl->signalType >> 1 ], 8 ); + RateLevelIndex = ec_dec_icdf( psRangeDec, SKP_Silk_rate_levels_iCDF[ signalType >> 1 ], 8 ); /* Calculate number of shell blocks */ SKP_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); @@ -58,7 +59,7 @@ void SKP_Silk_decode_pulses( /***************************************************/ /* Sum-Weighted-Pulses Decoding */ /***************************************************/ - cdf_ptr = SKP_Silk_pulses_per_block_iCDF[ psDecCtrl->RateLevelIndex ]; + cdf_ptr = SKP_Silk_pulses_per_block_iCDF[ RateLevelIndex ]; for( i = 0; i < iter; i++ ) { nLshifts[ i ] = 0; sum_pulses[ i ] = ec_dec_icdf( psRangeDec, cdf_ptr, 8 ); @@ -75,9 +76,9 @@ void SKP_Silk_decode_pulses( /***************************************************/ for( i = 0; i < iter; i++ ) { if( sum_pulses[ i ] > 0 ) { - SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] ); + SKP_Silk_shell_decoder( &pulses[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] ); } else { - SKP_memset( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) ); + SKP_memset( &pulses[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) ); } } @@ -87,7 +88,7 @@ void SKP_Silk_decode_pulses( for( i = 0; i < iter; i++ ) { if( nLshifts[ i ] > 0 ) { nLS = nLshifts[ i ]; - pulses_ptr = &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ]; + pulses_ptr = &pulses[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ]; for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { abs_q = pulses_ptr[ k ]; for( j = 0; j < nLS; j++ ) { @@ -102,6 +103,5 @@ void SKP_Silk_decode_pulses( /****************************************/ /* Decode and add signs to pulse signal */ /****************************************/ - SKP_Silk_decode_signs( psRangeDec, q, frame_length, psDecCtrl->signalType, - psDecCtrl->quantOffsetType, sum_pulses ); + SKP_Silk_decode_signs( psRangeDec, pulses, frame_length, signalType, quantOffsetType, sum_pulses ); } diff --git a/src_common/SKP_Silk_decoder_set_fs.c b/src_common/SKP_Silk_decoder_set_fs.c index b8df6811f..c12e629b0 100644 --- a/src_common/SKP_Silk_decoder_set_fs.c +++ b/src_common/SKP_Silk_decoder_set_fs.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -72,7 +72,7 @@ void SKP_Silk_decoder_set_fs( SKP_memset( psDec->prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); psDec->lagPrev = 100; - psDec->LastGainIndex = 1; + psDec->LastGainIndex = 10; psDec->prevSignalType = TYPE_NO_VOICE_ACTIVITY; psDec->first_frame_after_reset = 1; diff --git a/src_common/SKP_Silk_define.h b/src_common/SKP_Silk_define.h index becd4613e..58f3ae4f5 100644 --- a/src_common/SKP_Silk_define.h +++ b/src_common/SKP_Silk_define.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -48,7 +48,7 @@ extern "C" /* Limits on bitrate */ #define MIN_TARGET_RATE_BPS 5000 -#define MAX_TARGET_RATE_BPS SKP_uint16_MAX +#define MAX_TARGET_RATE_BPS 80000 /* Compensation in bitrate calculations for 10 ms modes */ #define REDUCE_BITRATE_10_MS_BPS 2200 @@ -68,21 +68,10 @@ extern "C" #define NO_SPEECH_FRAMES_BEFORE_DTX 5 /* eq 100 ms */ #define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */ -#define USE_LBRR 0 - -/* Amount of concecutive no FEC packets before telling JB */ -#define NO_LBRR_THRES 10 - -/* Maximum delay between real packet and LBRR packet */ -#define MAX_LBRR_DELAY 2 -#define LBRR_IDX_MASK 1 - -#define INBAND_FEC_MIN_RATE_BPS 18000 /* Dont use inband FEC below this total target rate */ -#define LBRR_LOSS_THRES 2 /* Start adding LBRR at this loss rate (needs tuning) */ - -/* Frame termination indicator defines */ -#define SKP_SILK_NO_LBRR 0 -#define SKP_SILK_LBRR 1 +/* LBRR thresholds */ +#define LBRR_NB_MIN_RATE_BPS 9000 +#define LBRR_MB_MIN_RATE_BPS 12000 +#define LBRR_WB_MIN_RATE_BPS 15000 /* Activate bandwidth transition filtering for mode switching */ #define SWITCH_TRANSITION_FILTERING 1 @@ -99,10 +88,6 @@ extern "C" #define TYPE_UNVOICED 1 #define TYPE_VOICED 2 -/* VAD Types used by silk */ -#define NO_VOICE_ACTIVITY 0 -#define VOICE_ACTIVITY 1 - /* Number of subframes */ #define MAX_NB_SUBFR 4 @@ -132,9 +117,6 @@ extern "C" /* Maximum length of LPC window used in noise shape analysis */ #define SHAPE_LPC_WIN_MAX ( 15 * MAX_FS_KHZ ) -/* Max number of bytes in payload output buffer (may contain multiple frames) */ -#define MAX_ARITHM_BYTES 1024 - /* dB level of lowest gain quantization level */ #define MIN_QGAIN_DB 2 /* dB level of highest gain quantization level */ diff --git a/src_common/SKP_Silk_enc_API.c b/src_common/SKP_Silk_enc_API.c index 946bb55e3..1c7b59cb9 100644 --- a/src_common/SKP_Silk_enc_API.c +++ b/src_common/SKP_Silk_enc_API.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -130,7 +130,7 @@ SKP_int SKP_Silk_SDK_Encode( { SKP_int max_internal_fs_kHz, min_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, ret = SKP_SILK_NO_ERROR; SKP_int nSamplesToBuffer, Complexity, input_10ms, nSamplesFromInput = 0; - SKP_int32 TargetRate_bps, API_fs_Hz, MaxBytesOut; + SKP_int32 TargetRate_bps, API_fs_Hz; SKP_Silk_encoder_state_Fxx *psEnc = ( SKP_Silk_encoder_state_Fxx* )encState; SKP_assert( encControl != NULL ); @@ -205,7 +205,6 @@ SKP_int SKP_Silk_SDK_Encode( } /* Input buffering/resampling and encoding */ - MaxBytesOut = 0; /* return 0 output bytes if no encoder called */ while( 1 ) { nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx; if( API_fs_Hz == SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ) { @@ -228,19 +227,8 @@ SKP_int SKP_Silk_SDK_Encode( SKP_assert( psEnc->sCmn.inputBufIx == psEnc->sCmn.frame_length ); /* Enough data in input buffer, so encode */ - if( MaxBytesOut == 0 ) { - /* No payload obtained so far */ - MaxBytesOut = *nBytesOut; - if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, &MaxBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) { - SKP_assert( 0 ); - } - } else { - /* outData already contains a payload */ - if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, nBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) { - SKP_assert( 0 ); - } - /* Check that no second payload was created */ - SKP_assert( *nBytesOut == 0 ); + if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, nBytesOut, psRangeEnc ) ) != 0 ) { + SKP_assert( 0 ); } psEnc->sCmn.inputBufIx = 0; psEnc->sCmn.controlled_since_last_payload = 0; @@ -253,7 +241,6 @@ SKP_int SKP_Silk_SDK_Encode( } } - *nBytesOut = MaxBytesOut; if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) { /* DTX */ *nBytesOut = 0; diff --git a/src_common/SKP_Silk_encode_indices.c b/src_common/SKP_Silk_encode_indices.c index a122a90b1..ebeb3bfe4 100644 --- a/src_common/SKP_Silk_encode_indices.c +++ b/src_common/SKP_Silk_encode_indices.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -32,13 +32,27 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /*******************************************/ void SKP_Silk_encode_indices( SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ - SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */ - ec_enc *psRangeEnc /* I/O Compressor data structure */ + ec_enc *psRangeEnc, /* I/O Compressor data structure */ + SKP_int FrameIndex, /* I Frame number */ + SKP_int encode_LBRR /* I Flag indicating LBRR data is being encoded */ ) { - SKP_int i, k, typeOffset; + SKP_int i, k, condCoding, typeOffset; SKP_int encode_absolute_lagIndex, delta_lagIndex; const SKP_Silk_NLSF_CB_struct *psNLSF_CB; + const SideInfoIndices *psIndices; + + if( FrameIndex > 0 && ( encode_LBRR == 0 || psEncC->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) { + condCoding = 1; + } else { + condCoding = 0; + } + + if( encode_LBRR ) { + psIndices = &psEncC->indices_LBRR[ FrameIndex ]; + } else { + psIndices = &psEncC->indices; + } #ifdef SAVE_ALL_INTERNAL_DATA SKP_int nBytes_lagIndex, nBytes_contourIndex, nBytes_LTP; @@ -48,15 +62,14 @@ void SKP_Silk_encode_indices( /*******************************************/ /* Encode signal type and quantizer offset */ /*******************************************/ - typeOffset = 2 * psEncCtrlC->signalType + psEncCtrlC->quantOffsetType; - if( psEncC->nFramesInPayloadBuf == 0 ) { - /* first frame in packet: independent coding */ - ec_enc_icdf( psRangeEnc, typeOffset, SKP_Silk_type_offset_iCDF, 8 ); + typeOffset = 2 * psIndices->signalType + psIndices->quantOffsetType; + SKP_assert( typeOffset >= 0 && typeOffset < 6 ); + SKP_assert( encode_LBRR == 0 || typeOffset >= 2 ); + if( encode_LBRR || typeOffset >= 2 ) { + ec_enc_icdf( psRangeEnc, typeOffset - 2, SKP_Silk_type_offset_VAD_iCDF, 8 ); } else { - /* conditional coding */ - ec_enc_icdf( psRangeEnc, typeOffset, SKP_Silk_type_offset_joint_iCDF[ psEncC->typeOffsetPrev ], 8 ); + ec_enc_icdf( psRangeEnc, typeOffset, SKP_Silk_type_offset_no_VAD_iCDF, 8 ); } - psEncC->typeOffsetPrev = typeOffset; /****************/ /* Encode gains */ @@ -65,18 +78,21 @@ void SKP_Silk_encode_indices( nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); #endif /* first subframe */ - if( psEncC->nFramesInPayloadBuf == 0 ) { - /* first frame in packet: independent coding, in two stages: MSB bits followed by 3 LSBs */ - ec_enc_icdf( psRangeEnc, SKP_RSHIFT( psEncCtrlC->GainsIndices[ 0 ], 3 ), SKP_Silk_gain_iCDF[ psEncCtrlC->signalType ], 8 ); - ec_enc_icdf( psRangeEnc, psEncCtrlC->GainsIndices[ 0 ] & 7, SKP_Silk_uniform8_iCDF, 8 ); - } else { + if( condCoding ) { /* conditional coding */ - ec_enc_icdf( psRangeEnc, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_iCDF, 8 ); + SKP_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ], SKP_Silk_delta_gain_iCDF, 8 ); + } else { + /* independent coding, in two stages: MSB bits followed by 3 LSBs */ + SKP_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < N_LEVELS_QGAIN ); + ec_enc_icdf( psRangeEnc, SKP_RSHIFT( psIndices->GainsIndices[ 0 ], 3 ), SKP_Silk_gain_iCDF[ psIndices->signalType ], 8 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ] & 7, SKP_Silk_uniform8_iCDF, 8 ); } /* remaining subframes */ for( i = 1; i < psEncC->nb_subfr; i++ ) { - ec_enc_icdf( psRangeEnc, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_iCDF, 8 ); + SKP_assert( psIndices->GainsIndices[ i ] >= 0 && psIndices->GainsIndices[ i ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ i ], SKP_Silk_delta_gain_iCDF, 8 ); } #ifdef SAVE_ALL_INTERNAL_DATA @@ -92,15 +108,17 @@ void SKP_Silk_encode_indices( nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); #endif /* Range encoding of the NLSF path */ - psNLSF_CB = psEncC->psNLSF_CB[ 1 - (psEncCtrlC->signalType>>1) ]; + psNLSF_CB = psEncC->psNLSF_CB[ 1 - ( psIndices->signalType >> 1 ) ]; for( i = 0; i < psNLSF_CB->nStages; i++ ) { - ec_enc_icdf( psRangeEnc, psEncCtrlC->NLSFIndices[ i ], psNLSF_CB->StartPtr[ i ], 8 ); + SKP_assert( 0 <= psIndices->NLSFIndices[ i ] && psIndices->NLSFIndices[ i ] < psNLSF_CB->CBStages[ i ].nVectors ); + ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i ], psNLSF_CB->StartPtr[ i ], 8 ); } if( psEncC->nb_subfr == MAX_NB_SUBFR ) { /* Encode NLSF interpolation factor */ - SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) ); - ec_enc_icdf( psRangeEnc, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 ); + SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psIndices->NLSFInterpCoef_Q2 == ( 1 << 2 ) ); + SKP_assert( psIndices->NLSFInterpCoef_Q2 >= 0 && psIndices->NLSFInterpCoef_Q2 < 5 ); + ec_enc_icdf( psRangeEnc, psIndices->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 ); } #ifdef SAVE_ALL_INTERNAL_DATA @@ -110,7 +128,8 @@ void SKP_Silk_encode_indices( DEBUG_STORE_DATA( nBytes_LSF.dat, &nBytes_after, sizeof( SKP_int ) ); #endif - if( psEncCtrlC->signalType == TYPE_VOICED ) { + if( psIndices->signalType == TYPE_VOICED ) + { /*********************/ /* Encode pitch lags */ /*********************/ @@ -119,29 +138,29 @@ void SKP_Silk_encode_indices( #endif /* lag index */ encode_absolute_lagIndex = 1; - if( psEncC->nFramesInPayloadBuf > 0 && psEncC->prevSignalType == TYPE_VOICED ) { + if( condCoding && psEncC->ec_prevSignalType == TYPE_VOICED ) { /* Delta Encoding */ - delta_lagIndex = psEncCtrlC->lagIndex - psEncC->prev_lagIndex; + delta_lagIndex = psIndices->lagIndex - psEncC->ec_prevLagIndex; if( delta_lagIndex < -8 || delta_lagIndex > 11 ) { delta_lagIndex = 0; } else { delta_lagIndex = delta_lagIndex + 9; encode_absolute_lagIndex = 0; /* Only use delta */ } - SKP_assert( delta_lagIndex < 21 ); + SKP_assert( delta_lagIndex >= 0 && delta_lagIndex < 21 ); ec_enc_icdf( psRangeEnc, delta_lagIndex, SKP_Silk_pitch_delta_iCDF, 8 ); } if( encode_absolute_lagIndex ) { /* Absolute encoding */ SKP_int32 pitch_high_bits, pitch_low_bits; - pitch_high_bits = SKP_DIV32_16( psEncCtrlC->lagIndex, SKP_RSHIFT( psEncC->fs_kHz, 1 ) ); - pitch_low_bits = psEncCtrlC->lagIndex - SKP_SMULBB( pitch_high_bits, SKP_RSHIFT( psEncC->fs_kHz, 1 ) ); + pitch_high_bits = SKP_DIV32_16( psIndices->lagIndex, SKP_RSHIFT( psEncC->fs_kHz, 1 ) ); + pitch_low_bits = psIndices->lagIndex - SKP_SMULBB( pitch_high_bits, SKP_RSHIFT( psEncC->fs_kHz, 1 ) ); SKP_assert( pitch_low_bits < psEncC->fs_kHz / 2 ); SKP_assert( pitch_high_bits < 32 ); ec_enc_icdf( psRangeEnc, pitch_high_bits, SKP_Silk_pitch_lag_iCDF, 8 ); ec_enc_icdf( psRangeEnc, pitch_low_bits, psEncC->pitch_lag_low_bits_iCDF, 8 ); } - psEncC->prev_lagIndex = psEncCtrlC->lagIndex; + psEncC->ec_prevLagIndex = psIndices->lagIndex; #ifdef SAVE_ALL_INTERNAL_DATA nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); @@ -152,11 +171,12 @@ void SKP_Silk_encode_indices( nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); #endif /* Countour index */ - SKP_assert( ( psEncCtrlC->contourIndex < 34 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 4 ) || - ( psEncCtrlC->contourIndex < 11 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 4 ) || - ( psEncCtrlC->contourIndex < 12 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 2 ) || - ( psEncCtrlC->contourIndex < 3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2 ) ); - ec_enc_icdf( psRangeEnc, psEncCtrlC->contourIndex, psEncC->pitch_contour_iCDF, 8 ); + SKP_assert( psIndices->contourIndex >= 0 ); + SKP_assert( ( psIndices->contourIndex < 34 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 4 ) || + ( psIndices->contourIndex < 11 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 4 ) || + ( psIndices->contourIndex < 12 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 2 ) || + ( psIndices->contourIndex < 3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2 ) ); + ec_enc_icdf( psRangeEnc, psIndices->contourIndex, psEncC->pitch_contour_iCDF, 8 ); #ifdef SAVE_ALL_INTERNAL_DATA nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); nBytes_contourIndex = nBytes_after - nBytes_before; // bytes just added @@ -170,17 +190,24 @@ void SKP_Silk_encode_indices( #endif /* PERIndex value */ - ec_enc_icdf( psRangeEnc, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_iCDF, 8 ); + SKP_assert( psIndices->PERIndex >= 0 && psIndices->PERIndex < 3 ); + ec_enc_icdf( psRangeEnc, psIndices->PERIndex, SKP_Silk_LTP_per_index_iCDF, 8 ); /* Codebook Indices */ for( k = 0; k < psEncC->nb_subfr; k++ ) { - ec_enc_icdf( psRangeEnc, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_iCDF_ptrs[ psEncCtrlC->PERIndex ], 8 ); + SKP_assert( psIndices->LTPIndex[ k ] >= 0 && psIndices->LTPIndex[ k ] < ( 8 << psIndices->PERIndex ) ); + ec_enc_icdf( psRangeEnc, psIndices->LTPIndex[ k ], SKP_Silk_LTP_gain_iCDF_ptrs[ psIndices->PERIndex ], 8 ); } /**********************/ /* Encode LTP scaling */ /**********************/ - ec_enc_icdf( psRangeEnc, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_iCDF, 8 ); + if( !condCoding ) { + SKP_assert( psIndices->LTP_scaleIndex >= 0 && psIndices->LTP_scaleIndex < 3 ); + ec_enc_icdf( psRangeEnc, psIndices->LTP_scaleIndex, SKP_Silk_LTPscale_iCDF, 8 ); + } + SKP_assert( !condCoding || psIndices->LTP_scaleIndex == 0 ); + #ifdef SAVE_ALL_INTERNAL_DATA nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); nBytes_LTP = nBytes_after - nBytes_before; // bytes just added @@ -198,6 +225,8 @@ void SKP_Silk_encode_indices( DEBUG_STORE_DATA( nBytes_LTP.dat, &nBytes_LTP, sizeof( SKP_int ) ); #endif + psEncC->ec_prevSignalType = psIndices->signalType; + #ifdef SAVE_ALL_INTERNAL_DATA nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); #endif @@ -205,5 +234,6 @@ void SKP_Silk_encode_indices( /***************/ /* Encode seed */ /***************/ - ec_enc_icdf( psRangeEnc, psEncCtrlC->Seed, SKP_Silk_Seed_iCDF, 8 ); + SKP_assert( psIndices->Seed >= 0 && psIndices->Seed < 4 ); + ec_enc_icdf( psRangeEnc, psIndices->Seed, SKP_Silk_uniform4_iCDF, 8 ); } diff --git a/src_common/SKP_Silk_encode_pulses.c b/src_common/SKP_Silk_encode_pulses.c index 5dcda3070..6fff9b95d 100644 --- a/src_common/SKP_Silk_encode_pulses.c +++ b/src_common/SKP_Silk_encode_pulses.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -27,24 +27,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" -/* Tables generated with pyramid_combinations_generalized_tree.m */ -/* Pyramid L1 norm */ -static const float PVQ_W_SIGNS_BITS[ 32 ] = -{ - 0.0000f, 5.0000f, 9.0000f, 12.4179f, 15.4263f, 18.1210f, 20.5637f, 22.7972f, - 24.8536f, 26.7576f, 28.5290f, 30.1838f, 31.7353f, 33.1949f, 34.5719f, 35.8747f, - 37.1102f, 38.2847f, 39.4034f, 40.4712f, 41.4922f, 42.4702f, 43.4083f, 44.3097f, - 45.1769f, 46.0123f, 46.8181f, 47.5961f, 48.3483f, 49.0762f, 49.7813f, 50.4648f -}; - -static const float PVQ_WO_SIGNS_BITS[ 32 ] = -{ - 0.0000f, 4.0000f, 7.0875f, 9.6724f, 11.9204f, 13.9204f, 15.7277f, 17.3798f, - 18.9033f, 20.3184f, 21.6403f, 22.8813f, 24.0512f, 25.1582f, 26.2088f, 27.2088f, - 28.1630f, 29.0755f, 29.9500f, 30.7895f, 31.5969f, 32.3745f, 33.1245f, 33.8489f, - 34.5493f, 35.2274f, 35.8845f, 36.5219f, 37.1408f, 37.7423f, 38.3273f, 38.8966f -}; - /*********************************************/ /* Encode quantization indices of excitation */ /*********************************************/ @@ -74,7 +56,7 @@ void SKP_Silk_encode_pulses( ec_enc *psRangeEnc, /* I/O compressor data structure */ const SKP_int signalType, /* I Sigtype */ const SKP_int quantOffsetType, /* I quantOffsetType */ - SKP_int8 q[], /* I quantization indices */ + SKP_int8 pulses[], /* I quantization indices */ const SKP_int frame_length /* I Frame length */ ) { @@ -100,15 +82,15 @@ void SKP_Silk_encode_pulses( if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ){ SKP_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */ iter++; - SKP_memset( &q[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof(SKP_int8)); + SKP_memset( &pulses[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof(SKP_int8)); } /* Take the absolute value of the pulses */ for( i = 0; i < iter * SHELL_CODEC_FRAME_LENGTH; i+=4 ) { - abs_pulses[i+0] = ( SKP_int )SKP_abs( q[ i + 0 ] ); - abs_pulses[i+1] = ( SKP_int )SKP_abs( q[ i + 1 ] ); - abs_pulses[i+2] = ( SKP_int )SKP_abs( q[ i + 2 ] ); - abs_pulses[i+3] = ( SKP_int )SKP_abs( q[ i + 3 ] ); + abs_pulses[i+0] = ( SKP_int )SKP_abs( pulses[ i + 0 ] ); + abs_pulses[i+1] = ( SKP_int )SKP_abs( pulses[ i + 1 ] ); + abs_pulses[i+2] = ( SKP_int )SKP_abs( pulses[ i + 2 ] ); + abs_pulses[i+3] = ( SKP_int )SKP_abs( pulses[ i + 3 ] ); } /* Calc sum pulses per shell code frame */ @@ -119,21 +101,15 @@ void SKP_Silk_encode_pulses( while( 1 ) { /* 1+1 -> 2 */ scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, SKP_Silk_max_pulses_table[ 0 ], 8 ); - /* 2+2 -> 4 */ scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 1 ], 4 ); - /* 4+4 -> 8 */ scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 2 ], 2 ); - /* 8+8 -> 16 */ - sum_pulses[ i ] = pulses_comb[ 0 ] + pulses_comb[ 1 ]; - if( sum_pulses[ i ] > SKP_Silk_max_pulses_table[ 3 ] ) { - scale_down++; - } + scale_down += combine_and_check( &sum_pulses[ i ], pulses_comb, SKP_Silk_max_pulses_table[ 3 ], 1 ); if( scale_down ) { - /* We need to down scale the quantization signal */ + /* We need to downscale the quantization signal */ nRshifts[ i ]++; for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { abs_pulses_ptr[ k ] = SKP_RSHIFT( abs_pulses_ptr[ k ], 1 ); @@ -198,7 +174,7 @@ void SKP_Silk_encode_pulses( /****************/ for( i = 0; i < iter; i++ ) { if( nRshifts[ i ] > 0 ) { - pulses_ptr = &q[ i * SHELL_CODEC_FRAME_LENGTH ]; + pulses_ptr = &pulses[ i * SHELL_CODEC_FRAME_LENGTH ]; nLS = nRshifts[ i ] - 1; for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] ); @@ -216,6 +192,6 @@ void SKP_Silk_encode_pulses( /****************/ /* Encode signs */ /****************/ - SKP_Silk_encode_signs( psRangeEnc, q, frame_length, signalType, quantOffsetType, sum_pulses ); + SKP_Silk_encode_signs( psRangeEnc, pulses, frame_length, signalType, quantOffsetType, sum_pulses ); #endif } diff --git a/src_common/SKP_Silk_gain_quant.c b/src_common/SKP_Silk_gain_quant.c index 4c89dd84e..101ecbd61 100644 --- a/src_common/SKP_Silk_gain_quant.c +++ b/src_common/SKP_Silk_gain_quant.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -33,9 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Gain scalar quantization with hysteresis, uniform on log scale */ void SKP_Silk_gains_quant( - SKP_int ind[ MAX_NB_SUBFR ], /* O gain indices */ + SKP_int8 ind[ MAX_NB_SUBFR ], /* O gain indices */ SKP_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (quantized out) */ - SKP_int *prev_ind, /* I/O last index in previous frame */ + SKP_int8 *prev_ind, /* I/O last index in previous frame */ const SKP_int conditional, /* I first gain is delta coded if 1 */ const SKP_int nb_subfr /* I number of subframes */ ) @@ -88,8 +88,8 @@ void SKP_Silk_gains_quant( /* Gains scalar dequantization, uniform on log scale */ void SKP_Silk_gains_dequant( SKP_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */ - const SKP_int ind[ MAX_NB_SUBFR ], /* I gain indices */ - SKP_int *prev_ind, /* I/O last index in previous frame */ + const SKP_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */ + SKP_int8 *prev_ind, /* I/O last index in previous frame */ const SKP_int conditional, /* I first gain is delta coded if 1 */ const SKP_int nb_subfr /* I number of subframes */ ) diff --git a/src_common/SKP_Silk_interpolate.c b/src_common/SKP_Silk_interpolate.c index b12778f9f..f3adcbeda 100644 --- a/src_common/SKP_Silk_interpolate.c +++ b/src_common/SKP_Silk_interpolate.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_main.h b/src_common/SKP_Silk_main.h index 0b9011ce7..9f12506f9 100644 --- a/src_common/SKP_Silk_main.h +++ b/src_common/SKP_Silk_main.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -52,7 +52,7 @@ extern "C" /* Encodes signs of excitation */ void SKP_Silk_encode_signs( ec_enc *psRangeEnc, /* I/O Compressor data structure */ - const SKP_int8 q[], /* I pulse signal */ + const SKP_int8 pulses[], /* I pulse signal */ SKP_int length, /* I length of input */ const SKP_int signalType, /* I Signal type */ const SKP_int quantOffsetType, /* I Quantization offset type */ @@ -62,7 +62,7 @@ void SKP_Silk_encode_signs( /* Decodes signs of excitation */ void SKP_Silk_decode_signs( ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_int q[], /* I/O pulse signal */ + SKP_int pulses[], /* I/O pulse signal */ SKP_int length, /* I length of input */ const SKP_int signalType, /* I Signal type */ const SKP_int quantOffsetType, /* I Quantization offset type */ @@ -84,7 +84,7 @@ void SKP_Silk_encode_pulses( ec_enc *psRangeEnc, /* I/O compressor data structure */ const SKP_int signalType, /* I Signal type */ const SKP_int quantOffsetType, /* I quantOffsetType */ - SKP_int8 q[], /* I quantization indices */ + SKP_int8 pulses[], /* I quantization indices */ const SKP_int frame_length /* I Frame length */ ); @@ -103,9 +103,9 @@ void SKP_Silk_shell_decoder( /* Gain scalar quantization with hysteresis, uniform on log scale */ void SKP_Silk_gains_quant( - SKP_int ind[ MAX_NB_SUBFR ], /* O gain indices */ + SKP_int8 ind[ MAX_NB_SUBFR ], /* O gain indices */ SKP_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (quantized out) */ - SKP_int *prev_ind, /* I/O last index in previous frame */ + SKP_int8 *prev_ind, /* I/O last index in previous frame */ const SKP_int conditional, /* I first gain is delta coded if 1 */ const SKP_int nb_subfr /* I number of subframes */ ); @@ -113,8 +113,8 @@ void SKP_Silk_gains_quant( /* Gains scalar dequantization, uniform on log scale */ void SKP_Silk_gains_dequant( SKP_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */ - const SKP_int ind[ MAX_NB_SUBFR ], /* I gain indices */ - SKP_int *prev_ind, /* I/O last index in previous frame */ + const SKP_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */ + SKP_int8 *prev_ind, /* I/O last index in previous frame */ const SKP_int conditional, /* I first gain is delta coded if 1 */ const SKP_int nb_subfr /* I number of subframes */ ); @@ -138,8 +138,8 @@ void SKP_Silk_interpolate( /* LTP tap quantizer */ void SKP_Silk_quant_LTP_gains( SKP_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (un)quantized LTP gains */ - SKP_int cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ - SKP_int *periodicity_index, /* O Periodicity Index */ + SKP_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ + SKP_int8 *periodicity_index, /* O Periodicity Index */ const SKP_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error Weights in Q18 */ SKP_int mu_Q9, /* I Mu value (R/D tradeoff) */ SKP_int lowComplexity, /* I Flag for low complexity */ @@ -148,7 +148,7 @@ void SKP_Silk_quant_LTP_gains( /* Entropy constrained matrix-weighted VQ, for a single input data vector */ void SKP_Silk_VQ_WMat_EC( - SKP_int *ind, /* O index of best codebook vector */ + SKP_int8 *ind, /* O index of best codebook vector */ SKP_int32 *rate_dist_Q14, /* O best weighted quantization error + mu * rate*/ const SKP_int16 *in_Q14, /* I input vector to be quantized */ const SKP_int32 *W_Q18, /* I weighting matrix */ @@ -162,38 +162,38 @@ void SKP_Silk_VQ_WMat_EC( /* Noise shaping quantization (NSQ)*/ /***********************************/ void SKP_Silk_NSQ( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ + const SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ const SKP_int16 x[], /* I prefiltered input signal */ - SKP_int8 q[], /* O quantized qulse signal */ - const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ + SKP_int8 pulses[], /* O quantized qulse signal */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefficients */ - const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ - const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefficients */ + const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ + const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I */ const SKP_int Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ); /* Noise shaping using delayed decision */ void SKP_Silk_NSQ_del_dec( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ + const SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ const SKP_int16 x[], /* I Prefiltered input signal */ - SKP_int8 q[], /* O Quantized pulse signal */ - const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ + SKP_int8 pulses[], /* O Quantized pulse signal */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I LT prediction coefs */ - const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ - const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I LT prediction coefs */ + const SKP_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */ + const SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const SKP_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I */ const SKP_int Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ); @@ -230,12 +230,17 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Return v /* Start by setting transition_frame_no = 1; */ void SKP_Silk_LP_variable_cutoff( SKP_Silk_LP_state *psLP, /* I/O LP filter state */ - SKP_int16 *out, /* O Low-pass filtered output signal */ - const SKP_int16 *in, /* I Input signal */ + SKP_int16 *signal, /* I/O Low-pass filtered output signal */ const SKP_int frame_length /* I Frame length */ ); #endif +/* Encode LBRR side info and excitation */ +void SKP_Silk_LBRR_embed( + SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ + ec_enc *psRangeEnc /* I/O Compressor data structure */ +); + /****************************************************/ /* Decoder Functions */ /****************************************************/ @@ -266,22 +271,27 @@ SKP_int SKP_Silk_decode_frame( SKP_int16 pOut[], /* O Pointer to output speech frame */ SKP_int32 *pN, /* O Pointer to size of output frame */ const SKP_int nBytes, /* I Payload length */ - SKP_int action, /* I Action from Jitter Buffer */ - SKP_int *decBytes /* O Used bytes to decode this frame */ + SKP_int lostFlag /* I 0: no loss, 1 loss, 2 decode fec */ +); + +/* Decode LBRR side info and excitation */ +void SKP_Silk_LBRR_extract( + SKP_Silk_decoder_state *psDec, /* I/O State */ + ec_dec *psRangeDec /* I/O Compressor data structure */ ); /* Decode indices from payload v4 Bitstream */ void SKP_Silk_decode_indices( SKP_Silk_decoder_state *psDec, /* I/O State */ - ec_dec *psRangeDec /* I/O Compressor data structure */ + ec_dec *psRangeDec, /* I/O Compressor data structure */ + SKP_int FrameIndex, /* I Frame number */ + SKP_int decode_LBRR /* I Flag indicating LBRR data is being decoded */ ); /* Decode parameters from payload v4 Bitstream */ void SKP_Silk_decode_parameters( SKP_Silk_decoder_state *psDec, /* I/O State */ - SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */ - ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_int q[ MAX_FRAME_LENGTH ] /* O Excitation signal */ + SKP_Silk_decoder_control *psDecCtrl /* I/O Decoder control */ ); /* Core decoder. Performs inverse NSQ operation LTP + LPC */ @@ -289,27 +299,24 @@ void SKP_Silk_decode_core( SKP_Silk_decoder_state *psDec, /* I/O Decoder state */ SKP_Silk_decoder_control *psDecCtrl, /* I Decoder control */ SKP_int16 xq[], /* O Decoded speech */ - const SKP_int q[ MAX_FRAME_LENGTH ] /* I Pulse signal */ + const SKP_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */ ); /* NLSF vector decoder */ void SKP_Silk_NLSF_MSVQ_decode( SKP_int *pNLSF_Q15, /* O Pointer to decoded output [LPC_ORDER x 1] */ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Pointer to NLSF codebook struct */ - const SKP_int *NLSFIndices, /* I Pointer to NLSF indices [nStages x 1] */ + const SKP_int8 *NLSFIndices, /* I Pointer to NLSF indices [nStages x 1] */ const SKP_int LPC_order /* I LPC order */ ); -/**********************/ -/* Arithmetic coding */ -/*********************/ - /* Decode quantization indices of excitation (Shell coding) */ void SKP_Silk_decode_pulses( - ec_dec *psRangeDec, /* I/O Compressor data structure */ - SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */ - SKP_int q[], /* O Excitation signal */ - const SKP_int frame_length /* I Frame length (preliminary) */ + ec_dec *psRangeDec, /* I/O Compressor data structure */ + SKP_int pulses[], /* O Excitation signal */ + const SKP_int signalType, /* I Sigtype */ + const SKP_int quantOffsetType, /* I quantOffsetType */ + const SKP_int frame_length /* I Frame length */ ); /******************/ @@ -332,22 +339,9 @@ void SKP_Silk_CNG( /* Encoding of various parameters */ void SKP_Silk_encode_indices( SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ - SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */ - ec_enc *psRangeEnc /* I/O Compressor data structure */ -); - -/* Extract lowest layer encoding */ -void SKP_Silk_get_low_layer_internal( - const SKP_uint8 *indata, /* I: Encoded input vector */ - const SKP_int16 nBytesIn, /* I: Number of input Bytes */ - SKP_uint8 *Layer0data, /* O: Layer0 payload */ - SKP_int32 *nLayer0Bytes /* O: Number of FEC Bytes */ -); - -/* Predict number of bytes used to encode q */ -SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes used to encode q */ - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State*/ - SKP_int8 q[] /* I Pulse signal */ + ec_enc *psRangeEnc, /* I/O Compressor data structure */ + SKP_int FrameIndex, /* I Frame number */ + SKP_int encode_LBRR /* I Flag indicating LBRR data is being encoded */ ); #ifdef __cplusplus diff --git a/src_common/SKP_Silk_pulses_to_bytes.c b/src_common/SKP_Silk_pulses_to_bytes.c deleted file mode 100644 index 0129ea1c0..000000000 --- a/src_common/SKP_Silk_pulses_to_bytes.c +++ /dev/null @@ -1,82 +0,0 @@ -/*********************************************************************** -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. -***********************************************************************/ - -/* - * File Name: SKP_Silk_pulses_to_bytes.c - */ - -#include <stdlib.h> -#include "SKP_Silk_main.h" - -/* nBytes = sum_over_shell_blocks( POLY_FIT_0 + POLY_FIT_1 * sum_abs_val + POLY_FIT_2 * sum_abs_val^2 ) */ -#define POLY_FIT_0_Q15 12520 -#define POLY_FIT_1_Q15 15862 -#define POLY_FIT_2_Q20 -9222 - -/* Predict number of bytes used to encode q */ -SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes used to encode q */ - SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */ - SKP_int8 q[] /* I Pulse signal */ -) -{ - SKP_int i, j, iter; - SKP_int8 *q_ptr; - SKP_int32 sum_abs_val, nBytes, acc_nBytes; - - /* Take the absolute value of the pulses */ - iter = psEncC->frame_length / SHELL_CODEC_FRAME_LENGTH; - - /* Calculate rate as a nonlinaer mapping of sum abs value of each Shell block */ - q_ptr = q; - acc_nBytes = 0; - for( j = 0; j < iter; j++ ) { - sum_abs_val = 0; - for(i = 0; i < SHELL_CODEC_FRAME_LENGTH; i+=4){ - sum_abs_val += (SKP_int32)SKP_abs( q_ptr[ i + 0 ] ); - sum_abs_val += (SKP_int32)SKP_abs( q_ptr[ i + 1 ] ); - sum_abs_val += (SKP_int32)SKP_abs( q_ptr[ i + 2 ] ); - sum_abs_val += (SKP_int32)SKP_abs( q_ptr[ i + 3 ] ); - } - /* Calculate nBytes used for thi sshell frame */ - nBytes = SKP_SMULWB( SKP_SMULBB( sum_abs_val, sum_abs_val ), POLY_FIT_2_Q20 ); // Q4 - nBytes = SKP_LSHIFT_SAT32( nBytes, 11 ); // Q15 - nBytes += SKP_SMULBB( sum_abs_val, POLY_FIT_1_Q15 ); // Q15 - nBytes += POLY_FIT_0_Q15; // Q15 - -#ifdef SAVE_ALL_INTERNAL_DATA - DEBUG_STORE_DATA( sum_abs_val.dat, &sum_abs_val, sizeof( SKP_int32 ) ); -#endif - acc_nBytes += nBytes; - - q_ptr += SHELL_CODEC_FRAME_LENGTH; /* update pointer */ - } - - acc_nBytes = SKP_RSHIFT_ROUND( acc_nBytes, 15 ); // Q0 - acc_nBytes = SKP_SAT16( acc_nBytes ); // just to be sure // Q0 - - return (SKP_int)acc_nBytes; -} diff --git a/src_common/SKP_Silk_quant_LTP_gains.c b/src_common/SKP_Silk_quant_LTP_gains.c index 87ae33982..506cded1a 100644 --- a/src_common/SKP_Silk_quant_LTP_gains.c +++ b/src_common/SKP_Silk_quant_LTP_gains.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -29,22 +29,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void SKP_Silk_quant_LTP_gains( SKP_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (un)quantized LTP gains */ - SKP_int cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ - SKP_int *periodicity_index, /* O Periodicity Index */ + SKP_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ + SKP_int8 *periodicity_index, /* O Periodicity Index */ const SKP_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error Weights in Q18 */ SKP_int mu_Q9, /* I Mu value (R/D tradeoff) */ SKP_int lowComplexity, /* I Flag for low complexity */ const SKP_int nb_subfr /* I number of subframes */ ) { - SKP_int j, k, temp_idx[ MAX_NB_SUBFR ], cbk_size; + SKP_int j, k, cbk_size; + SKP_int8 temp_idx[ MAX_NB_SUBFR ]; const SKP_uint8 *cl_ptr_Q5; const SKP_int8 *cbk_ptr_Q7; const SKP_int16 *b_Q14_ptr; const SKP_int32 *W_Q18_ptr; SKP_int32 rate_dist_Q14_subfr, rate_dist_Q14, min_rate_dist_Q14; - TIC(quant_LTP) /***************************************************/ @@ -86,8 +86,8 @@ TIC(quant_LTP) if( rate_dist_Q14 < min_rate_dist_Q14 ) { min_rate_dist_Q14 = rate_dist_Q14; - SKP_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( SKP_int ) ); - *periodicity_index = k; + *periodicity_index = (SKP_int8)k; + SKP_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( SKP_int8 ) ); } /* Break early in low-complexity mode if rate distortion is below threshold */ diff --git a/src_common/SKP_Silk_setup_complexity.h b/src_common/SKP_Silk_setup.h similarity index 82% rename from src_common/SKP_Silk_setup_complexity.h rename to src_common/SKP_Silk_setup.h index bc6534fa4..d1233cd16 100644 --- a/src_common/SKP_Silk_setup_complexity.h +++ b/src_common/SKP_Silk_setup.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -98,7 +98,6 @@ SKP_INLINE SKP_int SKP_Silk_setup_complexity( /* Do not allow higher pitch estimation LPC order than predict LPC order */ psEncC->pitchEstimationLPCOrder = SKP_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder ); psEncC->shapeWinLength = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 * psEncC->la_shape; - psEncC->Complexity = Complexity; SKP_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); SKP_assert( psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); @@ -110,3 +109,35 @@ SKP_INLINE SKP_int SKP_Silk_setup_complexity( return( ret ); } + +SKP_INLINE SKP_int SKP_Silk_setup_LBRR( + SKP_Silk_encoder_state *psEncC /* I/O */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + SKP_int32 LBRRRate_thres_bps; + + if( psEncC->useInBandFEC < 0 || psEncC->useInBandFEC > 1 ) { + ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; + } + + if( psEncC->fs_kHz == 8 ) { + LBRRRate_thres_bps = LBRR_NB_MIN_RATE_BPS; + } else if( psEncC->fs_kHz == 12 ) { + LBRRRate_thres_bps = LBRR_MB_MIN_RATE_BPS; + } else if( psEncC->fs_kHz == 16 ) { + LBRRRate_thres_bps = LBRR_WB_MIN_RATE_BPS; + } else { + SKP_assert( 0 ); + } + + LBRRRate_thres_bps = SKP_RSHIFT( SKP_SMULBB( LBRRRate_thres_bps, 7 - psEncC->PacketLoss_perc ), 2 ); + if( psEncC->useInBandFEC && psEncC->TargetRate_bps >= LBRRRate_thres_bps && psEncC->PacketLoss_perc > 0 ) { + /* Set gain increase / rate reduction for LBRR usage */ + psEncC->LBRR_GainIncreases = SKP_max_int( 6 - SKP_SMULWB( psEncC->PacketLoss_perc, SKP_FIX_CONST( 0.4, 16 ) ), 2 ); + psEncC->LBRR_enabled = 1; + } else { + psEncC->LBRR_enabled = 0; + } + return ret; +} diff --git a/src_common/SKP_Silk_shell_coder.c b/src_common/SKP_Silk_shell_coder.c index 73166ad08..930204b44 100644 --- a/src_common/SKP_Silk_shell_coder.c +++ b/src_common/SKP_Silk_shell_coder.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_structs.h b/src_common/SKP_Silk_structs.h index bb9dad476..0321c21b5 100644 --- a/src_common/SKP_Silk_structs.h +++ b/src_common/SKP_Silk_structs.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -39,14 +39,13 @@ extern "C" { #endif - /************************************/ /* Noise shaping quantization state */ /************************************/ typedef struct { SKP_int16 xq[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */ SKP_int32 sLTP_shp_Q10[ 2 * MAX_FRAME_LENGTH ]; - SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + NSQ_LPC_BUF_LENGTH ]; + SKP_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ]; SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; SKP_int32 sLF_AR_shp_Q12; SKP_int lagPrev; @@ -55,7 +54,7 @@ typedef struct { SKP_int32 rand_seed; SKP_int32 prev_inv_gain_Q16; SKP_int rewhite_flag; -} SKP_Silk_nsq_state; /* FIX*/ +} SKP_Silk_nsq_state; /********************************/ /* VAD state */ @@ -73,22 +72,6 @@ typedef struct { SKP_int32 counter; /* Frame counter used in the initial phase */ } SKP_Silk_VAD_state; -/*******************************/ -/* Range encoder/decoder state */ -/*******************************/ -#if 0 -typedef struct { - SKP_int32 bufferLength; - SKP_int32 bufferIx; - SKP_uint32 base_Q32; - SKP_uint32 range_Q16; - SKP_int32 error; - SKP_uint8 buffer[ MAX_ARITHM_BYTES ]; /* Buffer containing payload */ - /* The CELT entropy decoder */ - ec_dec range_dec_celt_state; -} SKP_Silk_range_coder_state; -#endif - #if SWITCH_TRANSITION_FILTERING /* Variable cut-off low-pass filter state */ typedef struct { @@ -113,11 +96,24 @@ typedef struct { const SKP_Silk_NLSF_CBS *CBStages; const SKP_int *NDeltaMin_Q15; - /* Fields for arithmetic (de)coding */ - const SKP_uint8 *CDF; + /* Fields for range (de)coding */ const SKP_uint8 * const *StartPtr; } SKP_Silk_NLSF_CB_struct; +typedef struct { + SKP_int8 GainsIndices[ MAX_NB_SUBFR ]; + SKP_int8 LTPIndex[ MAX_NB_SUBFR ]; + SKP_int8 NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int16 lagIndex; + SKP_int8 contourIndex; + SKP_int8 signalType; + SKP_int8 quantOffsetType; + SKP_int8 NLSFInterpCoef_Q2; + SKP_int8 PERIndex; + SKP_int8 LTP_scaleIndex; + SKP_int8 Seed; +} SideInfoIndices; + /********************************/ /* Encoder state */ /********************************/ @@ -126,21 +122,18 @@ typedef struct { SKP_int32 In_HP_State[ 2 ]; /* High pass filter state */ #endif #if SWITCH_TRANSITION_FILTERING - SKP_Silk_LP_state sLP; /* Low pass filter state */ + SKP_Silk_LP_state sLP; /* Low pass filter state */ #endif SKP_Silk_VAD_state sVAD; /* Voice activity detector state */ - - SKP_int LBRRprevLastGainIndex; - SKP_int prevSignalType; - SKP_int typeOffsetPrev; /* Previous signal type and quantization offset */ + SKP_Silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ + SKP_int8 LBRRprevLastGainIndex; + SKP_int8 prevSignalType; SKP_int prevLag; - SKP_int prev_lagIndex; SKP_int32 API_fs_Hz; /* API sampling frequency (Hz) */ SKP_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */ SKP_int maxInternal_fs_kHz; /* Maximum internal sampling frequency (kHz) */ SKP_int minInternal_fs_kHz; /* Minimum internal sampling frequency (kHz) */ SKP_int fs_kHz; /* Internal sampling frequency (kHz) */ - SKP_int fs_kHz_changed; /* Did we switch yet? */ SKP_int nb_subfr; /* Number of 5 ms subframes in a frame */ SKP_int frame_length; /* Frame length (samples) */ SKP_int subfr_length; /* Subframe length (samples) */ @@ -167,70 +160,52 @@ typedef struct { SKP_int controlled_since_last_payload; /* Flag for ensuring codec_control only runs once per packet */ SKP_int warping_Q16; /* Warping parameter for warped noise shaping */ SKP_int useCBR; /* Flag to enable constant bitrate */ + SKP_int prev_nBits; /* Use to track bits used by each frame in packet */ const SKP_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */ const SKP_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ + const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ + + SKP_int8 VAD_flags[ MAX_FRAMES_PER_PACKET ]; + SKP_int8 LBRR_flag; + SKP_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; + + SideInfoIndices indices; + SKP_int8 pulses[ MAX_FRAME_LENGTH ]; /* Input/output buffering */ - SKP_int16 inputBuf[ MAX_FRAME_LENGTH ]; /* buffer containin input signal */ + SKP_int16 inputBuf[ MAX_FRAME_LENGTH ]; /* buffer containing input signal */ SKP_int inputBufIx; - SKP_int nFramesInPayloadBuf; /* number of frames sitting in outputBuf */ - SKP_int nBytesInPayloadBuf; /* number of bytes sitting in outputBuf */ + SKP_int nFramesPerPacket; + SKP_int nFramesAnalyzed; /* Number of frames analyzed in current packet */ /* Parameters For LTP scaling Control */ SKP_int frames_since_onset; - const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ - - /* Inband Low Bitrate Redundancy (LBRR) data */ - SKP_int useInBandFEC; /* Saves the API setting for query */ - SKP_int LBRR_enabled; - SKP_int LBRR_GainIncreases; /* Number of shifts to Gains to get LBRR rate Voiced frames */ + /* Specifically for entropy coding */ + SKP_int ec_prevSignalType; + SKP_int16 ec_prevLagIndex; /* Bitrate control */ SKP_int32 bitrateDiff; /* Accumulated diff. between the target bitrate and the switch bitrates */ SKP_int32 bitrate_threshold_up; /* Threshold for switching to a higher internal sample frequency */ SKP_int32 bitrate_threshold_down; /* Threshold for switching to a lower internal sample frequency */ - SKP_Silk_resampler_state_struct resampler_state; + SKP_Silk_resampler_state_struct resampler_state; /* DTX */ - SKP_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */ SKP_int useDTX; /* Flag to enable DTX */ SKP_int inDTX; /* Flag to signal DTX period */ - SKP_int LBRR_nBytes; + SKP_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */ - /* Buffers */ - SKP_int8 q[ MAX_FRAME_LENGTH * MAX_FRAMES_PER_PACKET ]; /* pulse signal buffer */ - SKP_int8 q_LBRR[ MAX_FRAME_LENGTH * MAX_FRAMES_PER_PACKET ]; /* pulse signal buffer */ - SKP_int quantOffsetType[ MAX_FRAMES_PER_PACKET ]; - SKP_int signalType[ MAX_FRAMES_PER_PACKET ]; + /* Inband Low Bitrate Redundancy (LBRR) data */ + SKP_int useInBandFEC; /* Saves the API setting for query */ + SKP_int LBRR_enabled; /* Depends on useInBandFRC, bitrate and packet loss rate */ + SKP_int LBRR_GainIncreases; /* Number of shifts to Gains to get LBRR rate Voiced frames */ + SideInfoIndices indices_LBRR[ MAX_FRAMES_PER_PACKET ]; + SKP_int8 pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ]; } SKP_Silk_encoder_state; -/************************/ -/* Encoder control */ -/************************/ -typedef struct { - /* Quantization indices */ - SKP_int lagIndex; - SKP_int contourIndex; - SKP_int PERIndex; - SKP_int LTPIndex[ MAX_NB_SUBFR ]; - SKP_int NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ]; /* NLSF path of quantized LSF vector */ - SKP_int NLSFInterpCoef_Q2; - SKP_int GainsIndices[ MAX_NB_SUBFR ]; - SKP_int32 Seed; - SKP_int LTP_scaleIndex; - SKP_int RateLevelIndex; - SKP_int quantOffsetType; - SKP_int signalType; - - /* Prediction and coding parameters */ - SKP_int pitchL[ MAX_NB_SUBFR ]; - - SKP_int LBRR_usage; /* Low bitrate redundancy usage */ -} SKP_Silk_encoder_control; - /* Struct for Packet Loss Concealment */ typedef struct { SKP_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */ @@ -260,16 +235,13 @@ typedef struct { /* Decoder state */ /********************************/ typedef struct { - //SKP_Silk_range_coder_state sRC; /* Range coder state */ SKP_int32 prev_inv_gain_Q16; SKP_int32 sLTP_Q16[ 2 * MAX_FRAME_LENGTH ]; - SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + MAX_LPC_ORDER ]; + SKP_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + MAX_LPC_ORDER ]; SKP_int32 exc_Q10[ MAX_FRAME_LENGTH ]; SKP_int16 outBuf[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for output signal */ SKP_int lagPrev; /* Previous Lag */ - SKP_int LastGainIndex; /* Previous gain index */ - SKP_int LastGainIndex_EnhLayer; /* Previous gain index */ - SKP_int typeOffsetPrev; /* Previous signal type and quantization offset */ + SKP_int8 LastGainIndex; /* Previous gain index */ SKP_int32 HPState[ DEC_HP_ORDER ]; /* HP filter state */ const SKP_int32 *HP_A; /* HP filter AR coefficients */ const SKP_int32 *HP_B; /* HP filter MA coefficients */ @@ -286,34 +258,24 @@ typedef struct { const SKP_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ /* For buffering payload in case of more frames per packet */ - SKP_int nBytesLeft; SKP_int nFramesDecoded; - SKP_int nFramesInPacket; - SKP_int moreInternalDecoderFrames; - SKP_int FrameTermination; + SKP_int nFramesPerPacket; + + /* Specifically for entropy coding */ + SKP_int ec_prevSignalType; + SKP_int16 ec_prevLagIndex; + + SKP_int VAD_flags[ MAX_FRAMES_PER_PACKET ]; + SKP_int LBRR_flag; + SKP_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; - SKP_Silk_resampler_state_struct resampler_state; + SKP_Silk_resampler_state_struct resampler_state; const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ - SKP_int signalType[ MAX_FRAMES_PER_PACKET ]; - SKP_int quantOffsetType[ MAX_FRAMES_PER_PACKET ]; - SKP_int GainsIndices[ MAX_FRAMES_PER_PACKET ][ MAX_NB_SUBFR ]; - SKP_int GainsIndices_EnhLayer[ MAX_FRAMES_PER_PACKET ][ MAX_NB_SUBFR ]; - SKP_int NLSFIndices[ MAX_FRAMES_PER_PACKET ][ NLSF_MSVQ_MAX_CB_STAGES ]; - SKP_int NLSFInterpCoef_Q2[ MAX_FRAMES_PER_PACKET ]; - SKP_int lagIndex[ MAX_FRAMES_PER_PACKET ]; - SKP_int contourIndex[ MAX_FRAMES_PER_PACKET ]; - SKP_int PERIndex[ MAX_FRAMES_PER_PACKET ]; - SKP_int LTPIndex[ MAX_FRAMES_PER_PACKET ][ MAX_NB_SUBFR ]; - SKP_int LTP_scaleIndex[ MAX_FRAMES_PER_PACKET ]; - SKP_int Seed[ MAX_FRAMES_PER_PACKET ]; + /* Quantization indices */ + SideInfoIndices indices; - /* Parameters used to investigate if inband FEC is used */ - SKP_int vadFlag; - SKP_int no_FEC_counter; /* Counts number of frames wo inband FEC */ - SKP_int inband_FEC_offset; /* 0: no FEC, 1: FEC with 1 packet offset, 2: FEC w 2 packets offset */ - /* CNG state */ SKP_Silk_CNG_struct sCNG; @@ -332,18 +294,10 @@ typedef struct { /* prediction and coding parameters */ SKP_int pitchL[ MAX_NB_SUBFR ]; SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; - SKP_int32 Seed; /* holds interpolated and final coefficients, 4-byte aligned */ SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; SKP_int LTP_scale_Q14; - - /* quantization indices */ - SKP_int PERIndex; - SKP_int RateLevelIndex; - SKP_int quantOffsetType; - SKP_int signalType; - SKP_int NLSFInterpCoef_Q2; } SKP_Silk_decoder_control; #ifdef __cplusplus diff --git a/src_common/SKP_Silk_tables.h b/src_common/SKP_Silk_tables.h index e85214c57..5c510e0ed 100644 --- a/src_common/SKP_Silk_tables.h +++ b/src_common/SKP_Silk_tables.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -82,8 +82,10 @@ extern const SKP_int8 SKP_Silk_LTP_vq_sizes[ NB_LTP_CBKS ]; extern const SKP_uint8 SKP_Silk_LTPscale_iCDF[ 3 ]; /* 4 */ extern const SKP_int16 SKP_Silk_LTPScales_table_Q14[ 3 ]; -const SKP_uint8 SKP_Silk_type_offset_iCDF[6]; /* 6 */ -const SKP_uint8 SKP_Silk_type_offset_joint_iCDF[6][6]; /* 36 */ +extern const SKP_uint8 SKP_Silk_type_offset_VAD_iCDF[4]; /* 4 */ +extern const SKP_uint8 SKP_Silk_type_offset_no_VAD_iCDF[2]; /* 2 */ + +extern const SKP_uint8 * const SKP_Silk_LBRR_flags_iCDF_ptr[2]; /* 10 */ extern const SKP_uint8 SKP_Silk_NLSF_interpolation_factor_iCDF[ 5 ]; /* 5 */ @@ -92,10 +94,10 @@ extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16, SKP_Silk_NLSF_CB1_16; extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10, SKP_Silk_NLSF_CB1_10; /* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */ -extern const SKP_uint16 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ]; -extern const SKP_uint16 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ]; -extern const SKP_uint16 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ]; -extern const SKP_uint16 SNR_table_Q1[ TARGET_RATE_TAB_SZ ]; +extern const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ]; +extern const SKP_int32 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ]; +extern const SKP_int32 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ]; +extern const SKP_int16 SNR_table_Q1[ TARGET_RATE_TAB_SZ ]; /* Decoder high-pass filter coefficients */ extern const SKP_int32 SKP_Silk_Dec_A_HP_16[ DEC_HP_ORDER ]; /* 2 */ @@ -105,12 +107,6 @@ extern const SKP_int32 SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ]; extern const SKP_int32 SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ]; /* 2 */ extern const SKP_int32 SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ]; /* 3 */ -/* Table for frame termination indication */ -extern const SKP_uint8 SKP_Silk_LBRR_Present_iCDF[ 2 ]; - -/* Table for random seed */ -extern const SKP_uint8 SKP_Silk_Seed_iCDF[ 4 ]; - /* Quantization offsets */ extern const SKP_int16 SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ]; diff --git a/src_common/SKP_Silk_tables_LTP.c b/src_common/SKP_Silk_tables_LTP.c index 2433d7c8b..78d9c447c 100644 --- a/src_common/SKP_Silk_tables_LTP.c +++ b/src_common/SKP_Silk_tables_LTP.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_tables_NLSF_CB.h b/src_common/SKP_Silk_tables_NLSF_CB.h index 06f8a75ea..216b72a08 100644 --- a/src_common/SKP_Silk_tables_NLSF_CB.h +++ b/src_common/SKP_Silk_tables_NLSF_CB.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_tables_NLSF_CB0_10.c b/src_common/SKP_Silk_tables_NLSF_CB0_10.c index 905d72c34..44b705817 100644 --- a/src_common/SKP_Silk_tables_NLSF_CB0_10.c +++ b/src_common/SKP_Silk_tables_NLSF_CB0_10.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -921,7 +921,6 @@ const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10 = NLSF_MSVQ_CB0_10_STAGES, SKP_Silk_NLSF_CB0_10_Stage_info, SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min_Q15, - SKP_Silk_NLSF_MSVQ_CB0_10_CDF, SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr }; diff --git a/src_common/SKP_Silk_tables_NLSF_CB0_16.c b/src_common/SKP_Silk_tables_NLSF_CB0_16.c index 43c544937..e61e1f140 100644 --- a/src_common/SKP_Silk_tables_NLSF_CB0_16.c +++ b/src_common/SKP_Silk_tables_NLSF_CB0_16.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -937,7 +937,6 @@ const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16 = NLSF_MSVQ_CB0_16_STAGES, SKP_Silk_NLSF_CB0_16_Stage_info, SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min_Q15, - SKP_Silk_NLSF_MSVQ_CB0_16_CDF, SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr }; diff --git a/src_common/SKP_Silk_tables_NLSF_CB1_10.c b/src_common/SKP_Silk_tables_NLSF_CB1_10.c index a239e92f8..19a5325e8 100644 --- a/src_common/SKP_Silk_tables_NLSF_CB1_10.c +++ b/src_common/SKP_Silk_tables_NLSF_CB1_10.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -609,7 +609,6 @@ const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_10 = NLSF_MSVQ_CB1_10_STAGES, SKP_Silk_NLSF_CB1_10_Stage_info, SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min_Q15, - SKP_Silk_NLSF_MSVQ_CB1_10_CDF, SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr }; diff --git a/src_common/SKP_Silk_tables_NLSF_CB1_16.c b/src_common/SKP_Silk_tables_NLSF_CB1_16.c index aff908468..911158eaa 100644 --- a/src_common/SKP_Silk_tables_NLSF_CB1_16.c +++ b/src_common/SKP_Silk_tables_NLSF_CB1_16.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -673,7 +673,6 @@ const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_16 = NLSF_MSVQ_CB1_16_STAGES, SKP_Silk_NLSF_CB1_16_Stage_info, SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min_Q15, - SKP_Silk_NLSF_MSVQ_CB1_16_CDF, SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr }; diff --git a/src_common/SKP_Silk_tables_gain.c b/src_common/SKP_Silk_tables_gain.c index f7e26e4bb..c3953df8f 100644 --- a/src_common/SKP_Silk_tables_gain.c +++ b/src_common/SKP_Silk_tables_gain.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_tables_other.c b/src_common/SKP_Silk_tables_other.c index 489ce3171..422429dc3 100644 --- a/src_common/SKP_Silk_tables_other.c +++ b/src_common/SKP_Silk_tables_other.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -35,17 +35,17 @@ extern "C" #endif /* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */ -const SKP_uint16 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = { - 0, 8000, 9000, 11000, 13000, 16000, 21000, MAX_TARGET_RATE_BPS +const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = { + 0, 8000, 9000, 11000, 13000, 17500, 25000, MAX_TARGET_RATE_BPS }; -const SKP_uint16 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = { - 0, 10000, 12000, 14000, 17000, 21000, 27000, MAX_TARGET_RATE_BPS +const SKP_int32 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = { + 0, 10000, 12000, 14000, 17000, 23000, 33500, MAX_TARGET_RATE_BPS }; -const SKP_uint16 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = { - 0, 11000, 14000, 17000, 21000, 26000, 35000, MAX_TARGET_RATE_BPS +const SKP_int32 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = { + 0, 11000, 14000, 17000, 21000, 27500, 41500, MAX_TARGET_RATE_BPS }; -const SKP_uint16 SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = { - 19, 31, 35, 39, 44, 49, 55, 60 +const SKP_int16 SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = { + 19, 31, 35, 39, 44, 50, 60, 80 }; /* Decoder high-pass filter coefficients, -6 dB @ 50 Hz, 0.05 dB ripple */ @@ -58,63 +58,43 @@ const SKP_int32 SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ] = { 261993005, -5239860 const SKP_int32 SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ] = {-517610668, 249913410}; /* second order AR coefs, Q28 */ const SKP_int32 SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ] = { 258905997, -517811995, 258905997}; /* second order MA coefs, Q28 */ +/* tables for LBRR flags */ +const SKP_uint8 SKP_Silk_LBRR_flags_2_iCDF[ 3 ] = { 203, 150, 0 }; +const SKP_uint8 SKP_Silk_LBRR_flags_3_iCDF[ 7 ] = { 215, 195, 166, 125, 110, 82, 0 }; +const SKP_uint8 * const SKP_Silk_LBRR_flags_iCDF_ptr[2] = { + SKP_Silk_LBRR_flags_2_iCDF, + SKP_Silk_LBRR_flags_3_iCDF +}; + /* table for LSB coding */ -const SKP_uint8 SKP_Silk_lsb_iCDF[ 2 ] = { 100, 0 }; +const SKP_uint8 SKP_Silk_lsb_iCDF[ 2 ] = { 120, 0 }; /* tables for LTPScale */ const SKP_uint8 SKP_Silk_LTPscale_iCDF[ 3 ] = { 128, 64, 0 }; -/* tables for VAD flag */ -const SKP_uint8 SKP_Silk_vadflag_iCDF[ 2 ] = { 100, 0 }; - /* tables for signal type and offset coding */ -const SKP_uint8 SKP_Silk_type_offset_iCDF[6] = { - 253, 222, 202, 138, 7, 0 +const SKP_uint8 SKP_Silk_type_offset_VAD_iCDF[4] = { + 232, 158, 10, 0 }; -const SKP_uint8 SKP_Silk_type_offset_joint_iCDF[6][6] = -{ -{ - 67, 34, 8, 5, 4, 0 -}, -{ - 156, 42, 16, 11, 10, 0 -}, -{ - 154, 140, 55, 29, 15, 0 -}, -{ - 169, 156, 109, 23, 18, 0 -}, -{ - 156, 150, 136, 129, 68, 0 -}, -{ - 195, 187, 169, 147, 141, 0 -} +const SKP_uint8 SKP_Silk_type_offset_no_VAD_iCDF[2] = { + 230, 0 }; - /* tables for NLSF interpolation factor */ const SKP_uint8 SKP_Silk_NLSF_interpolation_factor_iCDF[ 5 ] = { 243, 221, 192, 181, 0 }; -/* Table for frame termination indication */ -const SKP_uint8 SKP_Silk_LBRR_Present_iCDF[ 2 ] = { 100, 0 }; - -/* Table for random seed */ -const SKP_uint8 SKP_Silk_Seed_iCDF[ 4 ] = { 192, 128, 64, 0 }; - /* Quantization offsets */ const SKP_int16 SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ] = { { OFFSET_UVL_Q10, OFFSET_UVH_Q10 }, { OFFSET_VL_Q10, OFFSET_VH_Q10 } }; /* Table for LTPScale */ -const SKP_int16 SKP_Silk_LTPScales_table_Q14[ 3 ] = { 15565, 11469, 8192 }; +const SKP_int16 SKP_Silk_LTPScales_table_Q14[ 3 ] = { 15565, 12288, 8192 }; /* Uniform entropy tables */ -const SKP_uint8 SKP_Silk_uniform4_iCDF[ 4 ] = { 192, 128, 64, 0 }; -const SKP_uint8 SKP_Silk_uniform6_iCDF[ 6 ] = { 213, 171, 128, 85, 43, 0 }; -const SKP_uint8 SKP_Silk_uniform8_iCDF[ 8 ] = { 224, 192, 160, 128, 96, 64, 32, 0 }; +const SKP_uint8 SKP_Silk_uniform4_iCDF[ 4 ] = { 192, 128, 64, 0 }; +const SKP_uint8 SKP_Silk_uniform6_iCDF[ 6 ] = { 213, 171, 128, 85, 43, 0 }; +const SKP_uint8 SKP_Silk_uniform8_iCDF[ 8 ] = { 224, 192, 160, 128, 96, 64, 32, 0 }; #if SWITCH_TRANSITION_FILTERING /* Elliptic/Cauer filters designed with 0.1 dB passband ripple, diff --git a/src_common/SKP_Silk_tables_pitch_lag.c b/src_common/SKP_Silk_tables_pitch_lag.c index 78ec04e9e..b4638df4d 100644 --- a/src_common/SKP_Silk_tables_pitch_lag.c +++ b/src_common/SKP_Silk_tables_pitch_lag.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_tables_pulses_per_block.c b/src_common/SKP_Silk_tables_pulses_per_block.c index a4a0b41aa..74f55fcd0 100644 --- a/src_common/SKP_Silk_tables_pulses_per_block.c +++ b/src_common/SKP_Silk_tables_pulses_per_block.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/src_common/SKP_Silk_tuning_parameters.h b/src_common/SKP_Silk_tuning_parameters.h index 89598d437..c823534f2 100644 --- a/src_common/SKP_Silk_tuning_parameters.h +++ b/src_common/SKP_Silk_tuning_parameters.h @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -80,13 +80,11 @@ extern "C" /* Various */ /***********/ -/* Required speech activity for counting frame as active */ -#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES 0.7f +/* VAD threshold */ +#define SPEECH_ACTIVITY_DTX_THRES 0.2f -#define SPEECH_ACTIVITY_DTX_THRES 0.1f - -/* Speech Activity LBRR enable threshold (needs tuning) */ -#define LBRR_SPEECH_ACTIVITY_THRES 0.5f +/* Speech Activity LBRR enable threshold */ +#define LBRR_SPEECH_ACTIVITY_THRES 0.3f /*************************/ /* Perceptual parameters */ diff --git a/src_common/src_common.vcxproj b/src_common/src_common.vcxproj index 6a4ee5381..985c0ab5a 100644 --- a/src_common/src_common.vcxproj +++ b/src_common/src_common.vcxproj @@ -77,7 +77,7 @@ <ClInclude Include="SKP_Silk_define.h" /> <ClInclude Include="SKP_Silk_main.h" /> <ClInclude Include="SKP_Silk_PLC.h" /> - <ClInclude Include="SKP_Silk_setup_complexity.h" /> + <ClInclude Include="SKP_Silk_setup.h" /> <ClInclude Include="SKP_Silk_structs.h" /> <ClInclude Include="SKP_Silk_tables.h" /> <ClInclude Include="SKP_Silk_tables_NLSF_CB.h" /> @@ -100,13 +100,13 @@ <ClCompile Include="SKP_Silk_enc_API.c" /> <ClCompile Include="SKP_Silk_gain_quant.c" /> <ClCompile Include="SKP_Silk_interpolate.c" /> + <ClCompile Include="SKP_Silk_LBRR_embed.c" /> <ClCompile Include="SKP_Silk_LP_variable_cutoff.c" /> <ClCompile Include="SKP_Silk_NLSF2A_stable.c" /> <ClCompile Include="SKP_Silk_NLSF_MSVQ_decode.c" /> <ClCompile Include="SKP_Silk_NSQ.c" /> <ClCompile Include="SKP_Silk_NSQ_del_dec.c" /> <ClCompile Include="SKP_Silk_PLC.c" /> - <ClCompile Include="SKP_Silk_pulses_to_bytes.c" /> <ClCompile Include="SKP_Silk_quant_LTP_gains.c" /> <ClCompile Include="SKP_Silk_shell_coder.c" /> <ClCompile Include="SKP_Silk_tables_gain.c" /> diff --git a/src_common/src_common.vcxproj.filters b/src_common/src_common.vcxproj.filters index 2f26aeda1..7c9b57c38 100644 --- a/src_common/src_common.vcxproj.filters +++ b/src_common/src_common.vcxproj.filters @@ -36,10 +36,10 @@ <ClInclude Include="SKP_Silk_tuning_parameters.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="SKP_Silk_setup_complexity.h"> + <ClInclude Include="SKP_Silk_tables_NLSF_CB.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="SKP_Silk_tables_NLSF_CB.h"> + <ClInclude Include="SKP_Silk_setup.h"> <Filter>Header Files</Filter> </ClInclude> </ItemGroup> @@ -101,9 +101,6 @@ <ClCompile Include="SKP_Silk_PLC.c"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="SKP_Silk_pulses_to_bytes.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="SKP_Silk_shell_coder.c"> <Filter>Source Files</Filter> </ClCompile> @@ -152,5 +149,8 @@ <ClCompile Include="SKP_Silk_encode_indices.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="SKP_Silk_LBRR_embed.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/test/Decoder.c b/test/Decoder.c index 356c3e776..5fc8c2e43 100644 --- a/test/Decoder.c +++ b/test/Decoder.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: @@ -269,7 +269,7 @@ int main( int argc, char* argv[] ) frames = 0; do { /* Decode 20 ms */ - ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len ); + ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, frames == 0, &range_dec_celt_state, nBytes, outPtr, &len ); if( ret ) { printf( "\nSKP_Silk_SDK_Decode returned %d", ret ); } @@ -288,12 +288,12 @@ int main( int argc, char* argv[] ) frames = 0; } /* Until last 20 ms frame of packet has been decoded */ - } while( DecControl.moreInternalDecoderFrames ); + } while( frames < DecControl.framesPerPayload ); } else { /* Loss: Decode enough frames to cover one packet duration */ for( i = 0; i < DecControl.framesPerPayload; i++ ) { /* Generate 20 ms */ - ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len ); + ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, i == 0, &range_dec_celt_state, nBytes, outPtr, &len ); if( ret ) { printf( "\nSKP_Silk_Decode returned %d", ret ); } @@ -366,7 +366,7 @@ int main( int argc, char* argv[] ) frames = 0; do { /* Decode 20 ms */ - ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len ); + ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, frames == 0, &range_dec_celt_state, nBytes, outPtr, &len ); if( ret ) { printf( "\nSKP_Silk_SDK_Decode returned %d", ret ); } @@ -381,13 +381,13 @@ int main( int argc, char* argv[] ) frames = 0; } /* Until last 20 ms frame of packet has been decoded */ - } while( DecControl.moreInternalDecoderFrames ); + } while( frames < DecControl.framesPerPayload ); } else { /* Loss: Decode enough frames to cover one packet duration */ /* Generate 20 ms */ for( i = 0; i < DecControl.framesPerPayload; i++ ) { - ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len ); + ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, i == 0, &range_dec_celt_state, nBytes, outPtr, &len ); if( ret ) { printf( "\nSKP_Silk_Decode returned %d", ret ); } diff --git a/test/Encoder.c b/test/Encoder.c index 105960f68..3e06a478b 100644 --- a/test/Encoder.c +++ b/test/Encoder.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: diff --git a/test/signalCompare.c b/test/signalCompare.c index f6025d914..dbca147e5 100644 --- a/test/signalCompare.c +++ b/test/signalCompare.c @@ -1,5 +1,5 @@ /*********************************************************************** -Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Copyright (c) 2006-2011, 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: -- GitLab