From fd1a5db140d51e7188e5126db2edc0ab923cfa8c Mon Sep 17 00:00:00 2001 From: Koen Vos <koen.vos@skype.net> Date: Wed, 30 Jun 2010 10:41:17 -0400 Subject: [PATCH] Update SILK code using the CELT range coder --- AUTHORS | 0 ChangeLog | 0 INSTALL | 236 -- Makefile | 122 ++ Makefile.am | 172 -- NEWS | 0 README | 0 Silk_FIX.sln | 91 + Silk_FLP.sln | 99 + Silk_SDK.sln | 44 - configure.gnu | 4 - configure.in | 26 - interface/SKP_Silk_SDK_API.h | 32 +- interface/SKP_Silk_control.h | 15 +- interface/SKP_Silk_errors.h | 32 +- interface/SKP_debug.h | 293 +++ readme.txt | 2 +- src/SKP_Silk_common_pitch_est_defines.h | 76 - src/SKP_Silk_control_codec_FIX.c | 656 ------ src/SKP_Silk_dec_API.c | 343 --- src/SKP_Silk_decode_parameters.c | 243 --- src/SKP_Silk_enc_API.c | 268 --- src/SKP_Silk_encode_parameters.c | 167 -- src/SKP_Silk_find_pred_coefs_FIX.c | 148 -- src/SKP_Silk_macros.h | 122 -- src/SKP_Silk_range_coder.c | 372 ---- src/SKP_Silk_resample_1_3.c | 101 - src/SKP_Silk_resample_2_3_coarse.c | 112 - src/SKP_Silk_resample_2_3_coarsest.c | 131 -- src/SKP_Silk_resample_3_1.c | 100 - src/SKP_Silk_resample_3_4.c | 79 - src/SKP_Silk_resample_4_3.c | 77 - src/SKP_Silk_resample_rom.h | 107 - src/Silk_FIX.2008.vcproj | 837 ------- src/Silk_FIX.2010.vcxproj | 300 --- src/Silk_FIX.vcproj | 700 ------ .../SKP_Silk_HP_variable_cutoff_FIX.c | 4 +- .../SKP_Silk_LTP_analysis_filter_FIX.c | 26 +- .../SKP_Silk_LTP_scale_ctrl_FIX.c | 2 +- .../SKP_Silk_NLSF_MSVQ_encode_FIX.c | 19 + .../SKP_Silk_NLSF_VQ_rate_distortion_FIX.c | 0 .../SKP_Silk_NLSF_VQ_sum_error_FIX.c | 0 .../SKP_Silk_VQ_nearest_neighbor_FIX.c | 57 +- src_FIX/SKP_Silk_control_codec_FIX.c | 583 +++++ {src => src_FIX}/SKP_Silk_corrMatrix_FIX.c | 0 {src => src_FIX}/SKP_Silk_define_FIX.h | 5 - {src => src_FIX}/SKP_Silk_encode_frame_FIX.c | 253 ++- {src => src_FIX}/SKP_Silk_find_LPC_FIX.c | 13 +- {src => src_FIX}/SKP_Silk_find_LTP_FIX.c | 48 +- .../SKP_Silk_find_pitch_lags_FIX.c | 30 +- src_FIX/SKP_Silk_find_pred_coefs_FIX.c | 442 ++++ {src => src_FIX}/SKP_Silk_init_encoder_FIX.c | 13 +- {src => src_FIX}/SKP_Silk_main_FIX.h | 110 +- .../SKP_Silk_noise_shape_analysis_FIX.c | 185 +- src_FIX/SKP_Silk_perceptual_parameters_FIX.h | 117 + {src => src_FIX}/SKP_Silk_prefilter_FIX.c | 87 +- {src => src_FIX}/SKP_Silk_process_NLSFs_FIX.c | 0 {src => src_FIX}/SKP_Silk_process_gains_FIX.c | 15 +- .../SKP_Silk_quant_LTP_gains_FIX.c | 38 +- .../SKP_Silk_regularize_correlations_FIX.c | 0 .../SKP_Silk_residual_energy16_FIX.c | 0 .../SKP_Silk_residual_energy_FIX.c | 44 +- {src => src_FIX}/SKP_Silk_solve_LS_FIX.c | 0 {src => src_FIX}/SKP_Silk_structs_FIX.h | 66 +- src_FIX/SKP_Silk_warped_autocorrelation_FIX.c | 82 + src_FIX/Silk_FIX.vcproj | 288 +++ src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c | 103 + src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c | 206 ++ src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c | 71 + src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c | 84 + src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c | 90 + src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c | 225 ++ .../SKP_Silk_NLSF_VQ_rate_distortion_FLP.c | 57 + src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c | 132 ++ src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c | 69 + src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c | 96 + src_FLP/SKP_Silk_apply_sine_window_FLP.c | 79 + COPYING => src_FLP/SKP_Silk_assembler_FLP.h | 16 + src_FLP/SKP_Silk_control_codec_FLP.c | 578 +++++ src_FLP/SKP_Silk_corrMatrix_FLP.c | 89 + src_FLP/SKP_Silk_define_FLP.h | 103 + src_FLP/SKP_Silk_encode_frame_FLP.c | 472 ++++ src_FLP/SKP_Silk_find_LPC_FLP.c | 97 + src_FLP/SKP_Silk_find_LTP_FLP.c | 124 ++ src_FLP/SKP_Silk_find_pitch_lags_FLP.c | 112 + src_FLP/SKP_Silk_find_pred_coefs_FLP.c | 110 + src_FLP/SKP_Silk_init_encoder_FLP.c | 63 + src_FLP/SKP_Silk_main_FLP.h | 435 ++++ src_FLP/SKP_Silk_noise_shape_analysis_FLP.c | 367 ++++ src_FLP/SKP_Silk_prefilter_FLP.c | 202 ++ src_FLP/SKP_Silk_process_NLSFs_FLP.c | 106 + src_FLP/SKP_Silk_process_gains_FLP.c | 96 + src_FLP/SKP_Silk_quant_LTP_gains_FLP.c | 108 + .../SKP_Silk_regularize_correlations_FLP.c | 43 + src_FLP/SKP_Silk_residual_energy_FLP.c | 113 + src_FLP/SKP_Silk_solve_LS_FLP.c | 203 ++ src_FLP/SKP_Silk_structs_FLP.h | 176 ++ src_FLP/SKP_Silk_tables_FLP.h | 43 + src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c | 739 +++++++ src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c | 1925 +++++++++++++++++ src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c | 475 ++++ src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c | 973 +++++++++ src_FLP/SKP_Silk_tables_other_FLP.c | 36 + src_FLP/SKP_Silk_warped_autocorrelation_FLP.c | 69 + src_FLP/SKP_Silk_wrappers_FLP.c | 245 +++ src_FLP/Silk_FLP.vcproj | 328 +++ {src => src_SigProc_FIX}/SKP_Silk_A2NLSF.c | 5 +- {src => src_SigProc_FIX}/SKP_Silk_Inlines.h | 27 +- .../SKP_Silk_LPC_inv_pred_gain.c | 116 +- .../SKP_Silk_LPC_stabilize.c | 5 +- .../SKP_Silk_LPC_synthesis_filter.c | 48 +- .../SKP_Silk_LPC_synthesis_order16.c | 131 +- .../SKP_Silk_LSF_cos_table.c | 0 {src => src_SigProc_FIX}/SKP_Silk_MA.c | 119 +- src_SigProc_FIX/SKP_Silk_MacroCount.h | 692 ++++++ src_SigProc_FIX/SKP_Silk_MacroDebug.h | 532 +++++ {src => src_SigProc_FIX}/SKP_Silk_NLSF2A.c | 7 +- .../SKP_Silk_NLSF_VQ_weights_laroia.c | 0 .../SKP_Silk_NLSF_stabilize.c | 2 +- .../SKP_Silk_SigProc_FIX.h | 239 +- .../SKP_Silk_allpass_int.c | 2 +- .../SKP_Silk_ana_filt_bank_1.c | 51 +- .../SKP_Silk_apply_sine_window.c | 14 +- .../SKP_Silk_array_maxabs.c | 11 +- {src => src_SigProc_FIX}/SKP_Silk_autocorr.c | 2 +- {src => src_SigProc_FIX}/SKP_Silk_biquad.c | 2 +- .../SKP_Silk_biquad_alt.c | 0 .../SKP_Silk_burg_modified.c | 14 +- .../SKP_Silk_bwexpander.c | 0 .../SKP_Silk_bwexpander_32.c | 0 .../SKP_Silk_common_pitch_est_defines.h | 86 + src_SigProc_FIX/SKP_Silk_decode_pitch.c | 71 + .../SKP_Silk_inner_prod_aligned.c | 4 +- {src => src_SigProc_FIX}/SKP_Silk_k2a.c | 2 +- {src => src_SigProc_FIX}/SKP_Silk_k2a_Q16.c | 2 +- {src => src_SigProc_FIX}/SKP_Silk_lin2log.c | 0 {src => src_SigProc_FIX}/SKP_Silk_log2lin.c | 0 .../SKP_Silk_lowpass_int.c | 0 .../SKP_Silk_lowpass_short.c | 0 src_SigProc_FIX/SKP_Silk_macros.h | 132 ++ .../SKP_Silk_pitch_analysis_core.c | 405 ++-- .../SKP_Silk_pitch_est_defines.h | 12 +- .../SKP_Silk_pitch_est_tables.c | 38 +- src_SigProc_FIX/SKP_Silk_resampler.c | 323 +++ src_SigProc_FIX/SKP_Silk_resampler_down2.c | 79 + src_SigProc_FIX/SKP_Silk_resampler_down2_3.c | 102 + src_SigProc_FIX/SKP_Silk_resampler_down3.c | 93 + src_SigProc_FIX/SKP_Silk_resampler_private.h | 130 ++ .../SKP_Silk_resampler_private_AR2.c | 60 + .../SKP_Silk_resampler_private_ARMA4.c | 79 + .../SKP_Silk_resampler_private_IIR_FIR.c | 105 + .../SKP_Silk_resampler_private_copy.c | 33 +- .../SKP_Silk_resampler_private_down4.c | 77 + .../SKP_Silk_resampler_private_down_FIR.c | 160 ++ .../SKP_Silk_resampler_private_up2_HQ.c | 120 + .../SKP_Silk_resampler_private_up4.c | 72 +- src_SigProc_FIX/SKP_Silk_resampler_rom.c | 276 +++ src_SigProc_FIX/SKP_Silk_resampler_rom.h | 91 + src_SigProc_FIX/SKP_Silk_resampler_structs.h | 79 + .../SKP_Silk_resampler_up2.c | 66 +- .../SKP_Silk_scale_copy_vector16.c | 0 .../SKP_Silk_scale_vector.c | 19 +- {src => src_SigProc_FIX}/SKP_Silk_schur.c | 2 +- {src => src_SigProc_FIX}/SKP_Silk_schur64.c | 2 +- {src => src_SigProc_FIX}/SKP_Silk_sigm_Q15.c | 0 {src => src_SigProc_FIX}/SKP_Silk_sort.c | 100 +- .../SKP_Silk_sum_sqr_shift.c | 4 +- src_SigProc_FIX/SigProc_FIX.vcproj | 408 ++++ .../SKP_Silk_LPC_inv_pred_gain_FLP.c | 73 +- .../SKP_Silk_NLSF_VQ_weights_laroia_FLP.c | 69 + src_SigProc_FLP/SKP_Silk_SigProc_FLP.h | 249 +++ .../SKP_Silk_allpass_int_FLP.c | 65 +- .../SKP_Silk_autocorrelation_FLP.c | 48 + src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c | 154 ++ src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c | 47 + .../SKP_Silk_decimate2_coarse_FLP.c | 62 +- .../SKP_Silk_decimate2_coarsest_FLP.c | 55 +- src_SigProc_FLP/SKP_Silk_energy_FLP.c | 56 + src_SigProc_FLP/SKP_Silk_inner_product_FLP.c | 56 + .../SKP_Silk_k2a_FLP.c | 42 +- src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c | 77 + .../SKP_Silk_pitch_analysis_core_FLP.c | 672 ++++++ .../SKP_Silk_pitch_est_defines_FLP.h | 42 + .../SKP_Silk_scale_copy_vector_FLP.c | 53 + src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c | 52 + src_SigProc_FLP/SKP_Silk_schur_FLP.c | 71 + src_SigProc_FLP/SKP_Silk_sort_FLP.c | 150 ++ src_SigProc_FLP/SigProc_FLP.vcproj | 248 +++ {src => src_common}/SKP_Silk_CNG.c | 8 +- {src => src_common}/SKP_Silk_LBRR_reset.c | 0 .../SKP_Silk_LP_variable_cutoff.c | 13 +- {src => src_common}/SKP_Silk_NLSF2A_stable.c | 0 .../SKP_Silk_NLSF_MSVQ_decode.c | 0 {src => src_common}/SKP_Silk_NSQ.c | 256 ++- {src => src_common}/SKP_Silk_NSQ_del_dec.c | 232 +- {src => src_common}/SKP_Silk_PLC.c | 66 +- {src => src_common}/SKP_Silk_PLC.h | 4 +- {src => src_common}/SKP_Silk_VAD.c | 62 +- {src => src_common}/SKP_Silk_code_signs.c | 14 +- .../SKP_Silk_create_init_destroy.c | 7 +- src_common/SKP_Silk_dec_SDK_API.c | 234 ++ {src => src_common}/SKP_Silk_decode_core.c | 131 +- {src => src_common}/SKP_Silk_decode_frame.c | 55 +- .../SKP_Silk_decode_indices_v4.c | 19 +- .../SKP_Silk_decode_parameters_v4.c | 21 +- {src => src_common}/SKP_Silk_decode_pulses.c | 8 +- {src => src_common}/SKP_Silk_decoder_set_fs.c | 10 +- {src => src_common}/SKP_Silk_define.h | 111 +- .../SKP_Silk_detect_SWB_input.c | 4 +- src_common/SKP_Silk_enc_API.c | 242 +++ .../SKP_Silk_encode_parameters_v4.c | 83 +- {src => src_common}/SKP_Silk_encode_pulses.c | 41 +- {src => src_common}/SKP_Silk_gain_quant.c | 26 +- {src => src_common}/SKP_Silk_interpolate.c | 0 {src => src_common}/SKP_Silk_main.h | 105 +- .../SKP_Silk_perceptual_parameters.h | 64 +- .../SKP_Silk_pulses_to_bytes.c | 18 +- src_common/SKP_Silk_range_coder.c | 290 +++ {src => src_common}/SKP_Silk_shell_coder.c | 0 {src => src_common}/SKP_Silk_structs.h | 88 +- {src => src_common}/SKP_Silk_tables.h | 8 +- {src => src_common}/SKP_Silk_tables_LTP.c | 0 .../SKP_Silk_tables_NLSF_CB0_10.c | 2 +- .../SKP_Silk_tables_NLSF_CB0_10.h | 0 .../SKP_Silk_tables_NLSF_CB0_16.c | 2 +- .../SKP_Silk_tables_NLSF_CB0_16.h | 0 .../SKP_Silk_tables_NLSF_CB1_10.c | 2 +- .../SKP_Silk_tables_NLSF_CB1_10.h | 0 .../SKP_Silk_tables_NLSF_CB1_16.c | 2 +- .../SKP_Silk_tables_NLSF_CB1_16.h | 0 {src => src_common}/SKP_Silk_tables_gain.c | 0 {src => src_common}/SKP_Silk_tables_other.c | 7 +- .../SKP_Silk_tables_pitch_lag.c | 0 .../SKP_Silk_tables_pulses_per_block.c | 0 {src => src_common}/SKP_Silk_tables_sign.c | 121 +- .../SKP_Silk_tables_type_offset.c | 0 src_common/Silk_Common.vcproj | 360 +++ src_common/Silk_CommonFLP.vcproj | 364 ++++ test/Dec_SDK.vcproj | 10 +- test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user | 65 + test/Decoder.c | 134 +- test/Enc_SDK.vcproj | 10 +- test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user | 65 + test/Encoder.c | 200 +- test/SKP_debug.c | 169 ++ test/SignalCompare.vcproj | 4 +- .../SignalCompare.vcproj.SKYPE-KOEN.koen.user | 65 + test/signalCompare.c | 547 ++--- 248 files changed, 22296 insertions(+), 7937 deletions(-) delete mode 100644 AUTHORS delete mode 100644 ChangeLog delete mode 100644 INSTALL create mode 100644 Makefile delete mode 100644 Makefile.am delete mode 100644 NEWS delete mode 100644 README create mode 100644 Silk_FIX.sln create mode 100644 Silk_FLP.sln delete mode 100644 Silk_SDK.sln delete mode 100755 configure.gnu delete mode 100644 configure.in create mode 100644 interface/SKP_debug.h delete mode 100644 src/SKP_Silk_common_pitch_est_defines.h delete mode 100644 src/SKP_Silk_control_codec_FIX.c delete mode 100644 src/SKP_Silk_dec_API.c delete mode 100644 src/SKP_Silk_decode_parameters.c delete mode 100644 src/SKP_Silk_enc_API.c delete mode 100644 src/SKP_Silk_encode_parameters.c delete mode 100644 src/SKP_Silk_find_pred_coefs_FIX.c delete mode 100644 src/SKP_Silk_macros.h delete mode 100644 src/SKP_Silk_range_coder.c delete mode 100644 src/SKP_Silk_resample_1_3.c delete mode 100644 src/SKP_Silk_resample_2_3_coarse.c delete mode 100644 src/SKP_Silk_resample_2_3_coarsest.c delete mode 100644 src/SKP_Silk_resample_3_1.c delete mode 100644 src/SKP_Silk_resample_3_4.c delete mode 100644 src/SKP_Silk_resample_4_3.c delete mode 100644 src/SKP_Silk_resample_rom.h delete mode 100644 src/Silk_FIX.2008.vcproj delete mode 100644 src/Silk_FIX.2010.vcxproj delete mode 100644 src/Silk_FIX.vcproj rename {src => src_FIX}/SKP_Silk_HP_variable_cutoff_FIX.c (94%) rename {src => src_FIX}/SKP_Silk_LTP_analysis_filter_FIX.c (66%) rename {src => src_FIX}/SKP_Silk_LTP_scale_ctrl_FIX.c (96%) rename {src => src_FIX}/SKP_Silk_NLSF_MSVQ_encode_FIX.c (91%) rename {src => src_FIX}/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_NLSF_VQ_sum_error_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_VQ_nearest_neighbor_FIX.c (60%) create mode 100644 src_FIX/SKP_Silk_control_codec_FIX.c rename {src => src_FIX}/SKP_Silk_corrMatrix_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_define_FIX.h (90%) rename {src => src_FIX}/SKP_Silk_encode_frame_FIX.c (58%) rename {src => src_FIX}/SKP_Silk_find_LPC_FIX.c (91%) rename {src => src_FIX}/SKP_Silk_find_LTP_FIX.c (82%) rename {src => src_FIX}/SKP_Silk_find_pitch_lags_FIX.c (85%) create mode 100644 src_FIX/SKP_Silk_find_pred_coefs_FIX.c rename {src => src_FIX}/SKP_Silk_init_encoder_FIX.c (86%) rename {src => src_FIX}/SKP_Silk_main_FIX.h (72%) rename {src => src_FIX}/SKP_Silk_noise_shape_analysis_FIX.c (68%) create mode 100644 src_FIX/SKP_Silk_perceptual_parameters_FIX.h rename {src => src_FIX}/SKP_Silk_prefilter_FIX.c (68%) rename {src => src_FIX}/SKP_Silk_process_NLSFs_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_process_gains_FIX.c (92%) rename {src => src_FIX}/SKP_Silk_quant_LTP_gains_FIX.c (76%) rename {src => src_FIX}/SKP_Silk_regularize_correlations_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_residual_energy16_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_residual_energy_FIX.c (66%) rename {src => src_FIX}/SKP_Silk_solve_LS_FIX.c (100%) rename {src => src_FIX}/SKP_Silk_structs_FIX.h (72%) create mode 100644 src_FIX/SKP_Silk_warped_autocorrelation_FIX.c create mode 100644 src_FIX/Silk_FIX.vcproj create mode 100644 src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c create mode 100644 src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c create mode 100644 src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c create mode 100644 src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c create mode 100644 src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c create mode 100644 src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c create mode 100644 src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c create mode 100644 src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c create mode 100644 src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c create mode 100644 src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c create mode 100644 src_FLP/SKP_Silk_apply_sine_window_FLP.c rename COPYING => src_FLP/SKP_Silk_assembler_FLP.h (79%) create mode 100644 src_FLP/SKP_Silk_control_codec_FLP.c create mode 100644 src_FLP/SKP_Silk_corrMatrix_FLP.c create mode 100644 src_FLP/SKP_Silk_define_FLP.h create mode 100644 src_FLP/SKP_Silk_encode_frame_FLP.c create mode 100644 src_FLP/SKP_Silk_find_LPC_FLP.c create mode 100644 src_FLP/SKP_Silk_find_LTP_FLP.c create mode 100644 src_FLP/SKP_Silk_find_pitch_lags_FLP.c create mode 100644 src_FLP/SKP_Silk_find_pred_coefs_FLP.c create mode 100644 src_FLP/SKP_Silk_init_encoder_FLP.c create mode 100644 src_FLP/SKP_Silk_main_FLP.h create mode 100644 src_FLP/SKP_Silk_noise_shape_analysis_FLP.c create mode 100644 src_FLP/SKP_Silk_prefilter_FLP.c create mode 100644 src_FLP/SKP_Silk_process_NLSFs_FLP.c create mode 100644 src_FLP/SKP_Silk_process_gains_FLP.c create mode 100644 src_FLP/SKP_Silk_quant_LTP_gains_FLP.c create mode 100644 src_FLP/SKP_Silk_regularize_correlations_FLP.c create mode 100644 src_FLP/SKP_Silk_residual_energy_FLP.c create mode 100644 src_FLP/SKP_Silk_solve_LS_FLP.c create mode 100644 src_FLP/SKP_Silk_structs_FLP.h create mode 100644 src_FLP/SKP_Silk_tables_FLP.h create mode 100644 src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c create mode 100644 src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c create mode 100644 src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c create mode 100644 src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c create mode 100644 src_FLP/SKP_Silk_tables_other_FLP.c create mode 100644 src_FLP/SKP_Silk_warped_autocorrelation_FLP.c create mode 100644 src_FLP/SKP_Silk_wrappers_FLP.c create mode 100644 src_FLP/Silk_FLP.vcproj rename {src => src_SigProc_FIX}/SKP_Silk_A2NLSF.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_Inlines.h (90%) rename {src => src_SigProc_FIX}/SKP_Silk_LPC_inv_pred_gain.c (69%) rename {src => src_SigProc_FIX}/SKP_Silk_LPC_stabilize.c (94%) rename {src => src_SigProc_FIX}/SKP_Silk_LPC_synthesis_filter.c (66%) rename {src => src_SigProc_FIX}/SKP_Silk_LPC_synthesis_order16.c (55%) rename {src => src_SigProc_FIX}/SKP_Silk_LSF_cos_table.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_MA.c (57%) create mode 100644 src_SigProc_FIX/SKP_Silk_MacroCount.h create mode 100644 src_SigProc_FIX/SKP_Silk_MacroDebug.h rename {src => src_SigProc_FIX}/SKP_Silk_NLSF2A.c (93%) rename {src => src_SigProc_FIX}/SKP_Silk_NLSF_VQ_weights_laroia.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_NLSF_stabilize.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_SigProc_FIX.h (79%) rename {src => src_SigProc_FIX}/SKP_Silk_allpass_int.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_ana_filt_bank_1.c (63%) rename {src => src_SigProc_FIX}/SKP_Silk_apply_sine_window.c (89%) rename {src => src_SigProc_FIX}/SKP_Silk_array_maxabs.c (91%) rename {src => src_SigProc_FIX}/SKP_Silk_autocorr.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_biquad.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_biquad_alt.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_burg_modified.c (95%) rename {src => src_SigProc_FIX}/SKP_Silk_bwexpander.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_bwexpander_32.c (100%) create mode 100644 src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h create mode 100644 src_SigProc_FIX/SKP_Silk_decode_pitch.c rename {src => src_SigProc_FIX}/SKP_Silk_inner_prod_aligned.c (95%) rename {src => src_SigProc_FIX}/SKP_Silk_k2a.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_k2a_Q16.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_lin2log.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_log2lin.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_lowpass_int.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_lowpass_short.c (100%) create mode 100644 src_SigProc_FIX/SKP_Silk_macros.h rename {src => src_SigProc_FIX}/SKP_Silk_pitch_analysis_core.c (66%) rename {src => src_SigProc_FIX}/SKP_Silk_pitch_est_defines.h (84%) rename {src => src_SigProc_FIX}/SKP_Silk_pitch_est_tables.c (72%) create mode 100644 src_SigProc_FIX/SKP_Silk_resampler.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_down2.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_down2_3.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_down3.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private.h create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c rename src/SKP_Silk_resample_3_2_rom.c => src_SigProc_FIX/SKP_Silk_resampler_private_copy.c (66%) create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_down4.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c rename src/SKP_Silk_resample_1_2.c => src_SigProc_FIX/SKP_Silk_resampler_private_up4.c (51%) create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_rom.c create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_rom.h create mode 100644 src_SigProc_FIX/SKP_Silk_resampler_structs.h rename src/SKP_Silk_resample_2_1_coarse.c => src_SigProc_FIX/SKP_Silk_resampler_up2.c (54%) rename {src => src_SigProc_FIX}/SKP_Silk_scale_copy_vector16.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_scale_vector.c (86%) rename {src => src_SigProc_FIX}/SKP_Silk_schur.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_schur64.c (96%) rename {src => src_SigProc_FIX}/SKP_Silk_sigm_Q15.c (100%) rename {src => src_SigProc_FIX}/SKP_Silk_sort.c (65%) rename {src => src_SigProc_FIX}/SKP_Silk_sum_sqr_shift.c (97%) create mode 100644 src_SigProc_FIX/SigProc_FIX.vcproj rename src/SKP_Silk_resample_2_3.c => src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c (54%) create mode 100644 src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_SigProc_FLP.h rename src/SKP_Silk_resample_3_2.c => src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c (55%) create mode 100644 src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c rename src/SKP_Silk_resample_1_2_coarse.c => src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c (56%) rename src/SKP_Silk_resample_1_2_coarsest.c => src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c (58%) create mode 100644 src_SigProc_FLP/SKP_Silk_energy_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_inner_product_FLP.c rename src/SKP_Silk_resample_2_3_rom.c => src_SigProc_FLP/SKP_Silk_k2a_FLP.c (59%) create mode 100644 src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_pitch_est_defines_FLP.h create mode 100644 src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_schur_FLP.c create mode 100644 src_SigProc_FLP/SKP_Silk_sort_FLP.c create mode 100644 src_SigProc_FLP/SigProc_FLP.vcproj rename {src => src_common}/SKP_Silk_CNG.c (94%) rename {src => src_common}/SKP_Silk_LBRR_reset.c (100%) rename {src => src_common}/SKP_Silk_LP_variable_cutoff.c (94%) rename {src => src_common}/SKP_Silk_NLSF2A_stable.c (100%) rename {src => src_common}/SKP_Silk_NLSF_MSVQ_decode.c (100%) rename {src => src_common}/SKP_Silk_NSQ.c (66%) rename {src => src_common}/SKP_Silk_NSQ_del_dec.c (77%) rename {src => src_common}/SKP_Silk_PLC.c (86%) rename {src => src_common}/SKP_Silk_PLC.h (95%) rename {src => src_common}/SKP_Silk_VAD.c (83%) rename {src => src_common}/SKP_Silk_code_signs.c (92%) rename {src => src_common}/SKP_Silk_create_init_destroy.c (92%) create mode 100644 src_common/SKP_Silk_dec_SDK_API.c rename {src => src_common}/SKP_Silk_decode_core.c (57%) rename {src => src_common}/SKP_Silk_decode_frame.c (79%) rename {src => src_common}/SKP_Silk_decode_indices_v4.c (91%) rename {src => src_common}/SKP_Silk_decode_parameters_v4.c (89%) rename {src => src_common}/SKP_Silk_decode_pulses.c (92%) rename {src => src_common}/SKP_Silk_decoder_set_fs.c (86%) rename {src => src_common}/SKP_Silk_define.h (77%) rename {src => src_common}/SKP_Silk_detect_SWB_input.c (96%) create mode 100644 src_common/SKP_Silk_enc_API.c rename {src => src_common}/SKP_Silk_encode_parameters_v4.c (71%) rename {src => src_common}/SKP_Silk_encode_pulses.c (81%) rename {src => src_common}/SKP_Silk_gain_quant.c (71%) rename {src => src_common}/SKP_Silk_interpolate.c (100%) rename {src => src_common}/SKP_Silk_main.h (78%) rename src/SKP_Silk_perceptual_parameters_FIX.h => src_common/SKP_Silk_perceptual_parameters.h (60%) rename {src => src_common}/SKP_Silk_pulses_to_bytes.c (85%) create mode 100644 src_common/SKP_Silk_range_coder.c rename {src => src_common}/SKP_Silk_shell_coder.c (100%) rename {src => src_common}/SKP_Silk_structs.h (84%) rename {src => src_common}/SKP_Silk_tables.h (95%) rename {src => src_common}/SKP_Silk_tables_LTP.c (100%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB0_10.c (97%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB0_10.h (100%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB0_16.c (98%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB0_16.h (100%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB1_10.c (96%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB1_10.h (100%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB1_16.c (98%) rename {src => src_common}/SKP_Silk_tables_NLSF_CB1_16.h (100%) rename {src => src_common}/SKP_Silk_tables_gain.c (100%) rename {src => src_common}/SKP_Silk_tables_other.c (95%) rename {src => src_common}/SKP_Silk_tables_pitch_lag.c (100%) rename {src => src_common}/SKP_Silk_tables_pulses_per_block.c (100%) rename {src => src_common}/SKP_Silk_tables_sign.c (57%) rename {src => src_common}/SKP_Silk_tables_type_offset.c (100%) create mode 100644 src_common/Silk_Common.vcproj create mode 100644 src_common/Silk_CommonFLP.vcproj create mode 100644 test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user create mode 100644 test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user create mode 100644 test/SKP_debug.c create mode 100644 test/SignalCompare.vcproj.SKYPE-KOEN.koen.user diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index e69de29bb..000000000 diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index e69de29bb..000000000 diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 23e5f25d0..000000000 --- a/INSTALL +++ /dev/null @@ -1,236 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free -Software Foundation, Inc. - -This file is free documentation; the Free Software Foundation gives -unlimited permission to copy, distribute and modify it. - -Basic Installation -================== - -These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. (Caching is -disabled by default to prevent problems with accidental use of stale -cache files.) - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You only need -`configure.ac' if you want to change it or regenerate `configure' using -a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - -Some systems require unusual options for compilation or linking that the -`configure' script does not know about. Run `./configure --help' for -details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - -You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not support the `VPATH' -variable, you have to compile the package for one architecture at a -time in the source code directory. After you have installed the -package for one architecture, use `make distclean' before reconfiguring -for another architecture. - -Installation Names -================== - -By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - -Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - -There may be some features `configure' cannot figure out automatically, -but needs to determine by the type of machine the package will run on. -Usually, assuming the package is built to be run on the _same_ -architectures, `configure' can figure that out, but if it prints a -message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - -If you want to set default values for `configure' scripts to share, you -can create a site shell script called `config.site' that gives default -values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - -Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). Here is a another example: - - /bin/bash ./configure CONFIG_SHELL=/bin/bash - -Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent -configuration-related scripts to be executed by `/bin/bash'. - -`configure' Invocation -====================== - -`configure' recognizes the following options to control how it operates. - -`--help' -`-h' - Print a summary of the options to `configure', and exit. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d86fd264c --- /dev/null +++ b/Makefile @@ -0,0 +1,122 @@ +# +# Makefile for Silk SDK +# +# Copyright (c) 2010, Skype Limited +# All rights reserved. +# + +#Platform detection and settings + +BUILD_OS := $(shell uname | sed -e 's/^.*Darwin.*/MacOS-X/ ; s/^.*CYGWIN.*/Windows/') + +BUILD_ARCHITECTURE := $(shell uname -m | sed -e 's/i686/i386/') + +EXESUFFIX = +LIBPREFIX = lib +LIBSUFFIX = .a +OBJSUFFIX = .o + +CC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) +AR = $(TOOLCHAIN_PREFIX)ar +RANLIB = $(TOOLCHAIN_PREFIX)ranlib +CP = $(TOOLCHAIN_PREFIX)cp + +cflags-from-defines = $(addprefix -D,$(1)) +cflags-from-includes = $(addprefix -I,$(1)) +ldflags-from-ldlibdirs = $(addprefix -L,$(1)) +ldlibs-from-libs = $(addprefix -l,$(1)) + +CFLAGS += -Wall -enable-threads -O3 + +CFLAGS += $(call cflags-from-defines,$(CDEFINES)) +CFLAGS += $(call cflags-from-includes,$(CINCLUDES)) +LDFLAGS += $(call ldflags-from-ldlibdirs,$(LDLIBDIRS)) +LDLIBS += $(call ldlibs-from-libs,$(LIBS)) + +COMPILE.c.cmdline = $(CC) -c $(CFLAGS) -o $@ $< +LINK.o.cmdline = $(LINK.o) -lm $^ $(LDLIBS) -o $@$(EXESUFFIX) +ARCHIVE.cmdline = $(AR) $(ARFLAGS) $@ $^ && $(RANLIB) $@ + +%$(OBJSUFFIX):%.c + $(COMPILE.c.cmdline) + +ifneq (,$(filter FIXED_POINT, $(CDEFINES))) + +# Directives + +CINCLUDES += interface src_common src_fix src_SigProc_FIX test + +# VPATH e.g. VPATH = src:../headers +VPATH = ./ \ + interface \ + src_common \ + src_fix \ + src_SigProc_FIX \ + test + +SRCS_C = $(wildcard src_common/*.c src_fix/*.c src_SigProc_FIX/*.c ) + +else + +# Directives + +CINCLUDES += interface src_common src_fix src_SigProc_FIX src_SigProc_FLP test + +# VPATH e.g. VPATH = src:../headers +VPATH = ./ \ + interface \ + src_common \ + src_flp \ + src_SigProc_FIX \ + src_SigProc_FLP \ + test + +SRCS_C = $(wildcard src_common/*.c src_flp/*.c src_SigProc_FIX/*.c src_SigProc_FLP/*.c ) + +endif + +# Variable definitions +LIB_NAME = SKP_SILK_SDK +TARGET = $(LIBPREFIX)$(LIB_NAME)$(LIBSUFFIX) + + +OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C)) + +ENCODER_SRCS_C = test/Encoder.c test/SKP_debug.c +ENCODER_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(ENCODER_SRCS_C)) + +DECODER_SRCS_C = test/Decoder.c test/SKP_debug.c +DECODER_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(DECODER_SRCS_C)) + +SIGNALCMP_SRCS_C = test/signalCompare.c +SIGNALCMP_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SIGNALCMP_SRCS_C)) + +LIBS = \ + $(LIB_NAME) + +LDLIBDIRS = ./ + +# Rules +default: all + +all: $(TARGET) encoder decoder signalcompare + +lib: $(TARGET) + +$(TARGET): $(OBJS) + $(ARCHIVE.cmdline) + +encoder$(EXESUFFIX): $(ENCODER_OBJS) + $(LINK.o.cmdline) + +decoder$(EXESUFFIX): $(DECODER_OBJS) + $(LINK.o.cmdline) + +signalcompare$(EXESUFFIX): $(SIGNALCMP_OBJS) + $(LINK.o.cmdline) + +clean: + $(RM) $(TARGET)* $(OBJS) $(ENCODER_OBJS) $(DECODER_OBJS) \ + $(SIGNALCMP_OBJS) $(TEST_OBJS) \ + encoder$(EXESUFFIX) decoder$(EXESUFFIX) signalcompare$(EXESUFFIX) + diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 2a681e873..000000000 --- a/Makefile.am +++ /dev/null @@ -1,172 +0,0 @@ - -AM_CFLAGS = -Isrc -Iinterface -fPIC -Wall -O3 -AUTOMAKE_OPTS = gnu -NAME = libSKP_SILK_SDK -AM_CPPFLAGS = $(AM_CFLAGS) - -EXTRA_DIST = Silk_SDK.sln \ -src/Silk_FIX.vcproj \ -test/Encoder.c \ -test/Enc_SDK.vcproj \ -test/Decoder.c \ -test/Dec_SDK.vcproj \ -test/signalCompare.c \ -test/SignalCompare.vcproj - -lib_LTLIBRARIES = libSKP_SILK_SDK.la -libSKP_SILK_SDK_la_SOURCES = src/SKP_Silk_A2NLSF.c \ -src/SKP_Silk_allpass_int.c \ -src/SKP_Silk_ana_filt_bank_1.c \ -src/SKP_Silk_apply_sine_window.c \ -src/SKP_Silk_array_maxabs.c \ -src/SKP_Silk_autocorr.c \ -src/SKP_Silk_biquad_alt.c \ -src/SKP_Silk_biquad.c \ -src/SKP_Silk_burg_modified.c \ -src/SKP_Silk_bwexpander_32.c \ -src/SKP_Silk_bwexpander.c \ -src/SKP_Silk_CNG.c \ -src/SKP_Silk_code_signs.c \ -src/SKP_Silk_control_codec_FIX.c \ -src/SKP_Silk_corrMatrix_FIX.c \ -src/SKP_Silk_create_init_destroy.c \ -src/SKP_Silk_dec_API.c \ -src/SKP_Silk_decode_core.c \ -src/SKP_Silk_decode_frame.c \ -src/SKP_Silk_decode_indices_v4.c \ -src/SKP_Silk_decode_parameters.c \ -src/SKP_Silk_decode_parameters_v4.c \ -src/SKP_Silk_decode_pulses.c \ -src/SKP_Silk_decoder_set_fs.c \ -src/SKP_Silk_detect_SWB_input.c \ -src/SKP_Silk_enc_API.c \ -src/SKP_Silk_encode_frame_FIX.c \ -src/SKP_Silk_encode_parameters.c \ -src/SKP_Silk_encode_parameters_v4.c \ -src/SKP_Silk_encode_pulses.c \ -src/SKP_Silk_find_LPC_FIX.c \ -src/SKP_Silk_find_LTP_FIX.c \ -src/SKP_Silk_find_pitch_lags_FIX.c \ -src/SKP_Silk_find_pred_coefs_FIX.c \ -src/SKP_Silk_gain_quant.c \ -src/SKP_Silk_HP_variable_cutoff_FIX.c \ -src/SKP_Silk_init_encoder_FIX.c \ -src/SKP_Silk_inner_prod_aligned.c \ -src/SKP_Silk_interpolate.c \ -src/SKP_Silk_k2a.c \ -src/SKP_Silk_k2a_Q16.c \ -src/SKP_Silk_LBRR_reset.c \ -src/SKP_Silk_lin2log.c \ -src/SKP_Silk_log2lin.c \ -src/SKP_Silk_lowpass_int.c \ -src/SKP_Silk_lowpass_short.c \ -src/SKP_Silk_LPC_inv_pred_gain.c \ -src/SKP_Silk_LPC_stabilize.c \ -src/SKP_Silk_LPC_synthesis_filter.c \ -src/SKP_Silk_LPC_synthesis_order16.c \ -src/SKP_Silk_LP_variable_cutoff.c \ -src/SKP_Silk_LSF_cos_table.c \ -src/SKP_Silk_LTP_analysis_filter_FIX.c \ -src/SKP_Silk_LTP_scale_ctrl_FIX.c \ -src/SKP_Silk_MA.c \ -src/SKP_Silk_NLSF2A.c \ -src/SKP_Silk_NLSF2A_stable.c \ -src/SKP_Silk_NLSF_MSVQ_decode.c \ -src/SKP_Silk_NLSF_MSVQ_encode_FIX.c \ -src/SKP_Silk_NLSF_stabilize.c \ -src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c \ -src/SKP_Silk_NLSF_VQ_sum_error_FIX.c \ -src/SKP_Silk_NLSF_VQ_weights_laroia.c \ -src/SKP_Silk_noise_shape_analysis_FIX.c \ -src/SKP_Silk_NSQ.c \ -src/SKP_Silk_NSQ_del_dec.c \ -src/SKP_Silk_pitch_analysis_core.c \ -src/SKP_Silk_pitch_est_tables.c \ -src/SKP_Silk_PLC.c \ -src/SKP_Silk_prefilter_FIX.c \ -src/SKP_Silk_process_gains_FIX.c \ -src/SKP_Silk_process_NLSFs_FIX.c \ -src/SKP_Silk_pulses_to_bytes.c \ -src/SKP_Silk_quant_LTP_gains_FIX.c \ -src/SKP_Silk_range_coder.c \ -src/SKP_Silk_regularize_correlations_FIX.c \ -src/SKP_Silk_resample_1_2.c \ -src/SKP_Silk_resample_1_2_coarse.c \ -src/SKP_Silk_resample_1_2_coarsest.c \ -src/SKP_Silk_resample_1_3.c \ -src/SKP_Silk_resample_2_1_coarse.c \ -src/SKP_Silk_resample_2_3.c \ -src/SKP_Silk_resample_2_3_coarse.c \ -src/SKP_Silk_resample_2_3_coarsest.c \ -src/SKP_Silk_resample_2_3_rom.c \ -src/SKP_Silk_resample_3_1.c \ -src/SKP_Silk_resample_3_2.c \ -src/SKP_Silk_resample_3_2_rom.c \ -src/SKP_Silk_resample_3_4.c \ -src/SKP_Silk_resample_4_3.c \ -src/SKP_Silk_residual_energy16_FIX.c \ -src/SKP_Silk_residual_energy_FIX.c \ -src/SKP_Silk_scale_copy_vector16.c \ -src/SKP_Silk_scale_vector.c \ -src/SKP_Silk_schur64.c \ -src/SKP_Silk_schur.c \ -src/SKP_Silk_shell_coder.c \ -src/SKP_Silk_sigm_Q15.c \ -src/SKP_Silk_solve_LS_FIX.c \ -src/SKP_Silk_sort.c \ -src/SKP_Silk_sum_sqr_shift.c \ -src/SKP_Silk_tables_gain.c \ -src/SKP_Silk_tables_LTP.c \ -src/SKP_Silk_tables_NLSF_CB0_10.c \ -src/SKP_Silk_tables_NLSF_CB0_16.c \ -src/SKP_Silk_tables_NLSF_CB1_10.c \ -src/SKP_Silk_tables_NLSF_CB1_16.c \ -src/SKP_Silk_tables_other.c \ -src/SKP_Silk_tables_pitch_lag.c \ -src/SKP_Silk_tables_pulses_per_block.c \ -src/SKP_Silk_tables_sign.c \ -src/SKP_Silk_tables_type_offset.c \ -src/SKP_Silk_VAD.c \ -src/SKP_Silk_VQ_nearest_neighbor_FIX.c - - -libSKP_SILK_SDK_la_CFLAGS = $(AM_CFLAGS) -libSKP_SILK_SDK_la_LDFLAGS = $(LIBS) - -library_includedir = $(prefix)/include/silk -library_include_HEADERS = src/SKP_Silk_common_pitch_est_defines.h \ -src/SKP_Silk_define_FIX.h \ -src/SKP_Silk_define.h \ -src/SKP_Silk_Inlines.h \ -src/SKP_Silk_macros.h \ -src/SKP_Silk_main_FIX.h \ -src/SKP_Silk_main.h \ -src/SKP_Silk_perceptual_parameters_FIX.h \ -src/SKP_Silk_pitch_est_defines.h \ -src/SKP_Silk_PLC.h \ -src/SKP_Silk_resample_rom.h \ -src/SKP_Silk_SigProc_FIX.h \ -src/SKP_Silk_structs_FIX.h \ -src/SKP_Silk_structs.h \ -src/SKP_Silk_tables.h \ -src/SKP_Silk_tables_NLSF_CB0_10.h \ -src/SKP_Silk_tables_NLSF_CB0_16.h \ -src/SKP_Silk_tables_NLSF_CB1_10.h \ -src/SKP_Silk_tables_NLSF_CB1_16.h \ -interface/SKP_Silk_control.h \ -interface/SKP_Silk_errors.h \ -interface/SKP_Silk_SDK_API.h \ -interface/SKP_Silk_typedef.h - -bin_PROGRAMS = Encoder Decoder signalCompare -Encoder_SOURCES = test/Encoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h -Encoder_LDADD = $(lib_LTLIBRARIES) -Encoder_LDFLAGS = $(LIBS) - -Decoder_SOURCES = test/Decoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h -Decoder_LDADD = $(lib_LTLIBRARIES) -Decoder_LDFLAGS = $(LIBS) - -signalCompare_SOURCES = test/signalCompare.c $(top_builddir)/interface/SKP_Silk_SDK_API.h -signalCompare_LDADD = $(lib_LTLIBRARIES) -signalCompare_LDFLAGS = $(LIBS) diff --git a/NEWS b/NEWS deleted file mode 100644 index e69de29bb..000000000 diff --git a/README b/README deleted file mode 100644 index e69de29bb..000000000 diff --git a/Silk_FIX.sln b/Silk_FIX.sln new file mode 100644 index 000000000..478d196a5 --- /dev/null +++ b/Silk_FIX.sln @@ -0,0 +1,91 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dec", "test\Dec_SDK.vcproj", "{82685D7F-0589-42BD-877C-31A952D53A8E}" + ProjectSection(ProjectDependencies) = postProject + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SignalCompare", "test\SignalCompare.vcproj", "{7FE8F544-9175-40C3-A187-7F15CE9A75D8}" + ProjectSection(ProjectDependencies) = postProject + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Enc", "test\Enc_SDK.vcproj", "{6D97A8EF-5724-4D85-8BF4-C583714BBA78}" + ProjectSection(ProjectDependencies) = postProject + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_FIX", "src_FIX\Silk_FIX.vcproj", "{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" + ProjectSection(ProjectDependencies) = postProject + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SigProc_FIX", "src_SigProc_FIX\SigProc_FIX.vcproj", "{2769AFC5-8FC2-42E8-803C-528ACBA89C74}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_Common", "src_common\Silk_Common.vcproj", "{0E29E502-AB22-4147-93A1-AC91528ED758}" + ProjectSection(ProjectDependencies) = postProject + {8181D6A1-DE19-4A5C-9B96-E10A18068C93} = {8181D6A1-DE19-4A5C-9B96-E10A18068C93} + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcelt", "..\..\celt-0.8.0\libcelt\libcelt.vcproj", "{8181D6A1-DE19-4A5C-9B96-E10A18068C93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug MCD|Win32 = Debug MCD|Win32 + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug MCD|Win32.Build.0 = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.Build.0 = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.ActiveCfg = Release|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.Build.0 = Release|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug MCD|Win32.Build.0 = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.ActiveCfg = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.Build.0 = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.ActiveCfg = Release|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.Build.0 = Release|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug MCD|Win32.Build.0 = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.ActiveCfg = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.Build.0 = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.ActiveCfg = Release|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.Build.0 = Release|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug MCD|Win32.Build.0 = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.ActiveCfg = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.Build.0 = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.ActiveCfg = Release|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.Build.0 = Release|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug MCD|Win32.Build.0 = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug|Win32.ActiveCfg = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug|Win32.Build.0 = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Release|Win32.ActiveCfg = Release|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Release|Win32.Build.0 = Release|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug MCD|Win32.Build.0 = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug|Win32.ActiveCfg = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug|Win32.Build.0 = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Release|Win32.ActiveCfg = Release|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Release|Win32.Build.0 = Release|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug MCD|Win32.ActiveCfg = Debug MCD|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug MCD|Win32.Build.0 = Debug MCD|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug|Win32.ActiveCfg = Debug|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug|Win32.Build.0 = Debug|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Release|Win32.ActiveCfg = Release|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Silk_FLP.sln b/Silk_FLP.sln new file mode 100644 index 000000000..9b5118909 --- /dev/null +++ b/Silk_FLP.sln @@ -0,0 +1,99 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dec", "test\Dec_SDK.vcproj", "{82685D7F-0589-42BD-877C-31A952D53A8E}" + ProjectSection(ProjectDependencies) = postProject + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SignalCompare", "test\SignalCompare.vcproj", "{7FE8F544-9175-40C3-A187-7F15CE9A75D8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Enc", "test\Enc_SDK.vcproj", "{6D97A8EF-5724-4D85-8BF4-C583714BBA78}" + ProjectSection(ProjectDependencies) = postProject + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + {793D0EC2-8554-4674-9A97-F25DE5DBE926} = {793D0EC2-8554-4674-9A97-F25DE5DBE926} + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SigProc_FIX", "src_SigProc_FIX\SigProc_FIX.vcproj", "{2769AFC5-8FC2-42E8-803C-528ACBA89C74}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_FLP", "src_FLP\Silk_FLP.vcproj", "{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" + ProjectSection(ProjectDependencies) = postProject + {793D0EC2-8554-4674-9A97-F25DE5DBE926} = {793D0EC2-8554-4674-9A97-F25DE5DBE926} + {0E29E502-AB22-4147-93A1-AC91528ED758} = {0E29E502-AB22-4147-93A1-AC91528ED758} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SigProc_FLP", "src_SigProc_FLP\SigProc_FLP.vcproj", "{793D0EC2-8554-4674-9A97-F25DE5DBE926}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_Common", "src_common\Silk_CommonFLP.vcproj", "{0E29E502-AB22-4147-93A1-AC91528ED758}" + ProjectSection(ProjectDependencies) = postProject + {8181D6A1-DE19-4A5C-9B96-E10A18068C93} = {8181D6A1-DE19-4A5C-9B96-E10A18068C93} + {2769AFC5-8FC2-42E8-803C-528ACBA89C74} = {2769AFC5-8FC2-42E8-803C-528ACBA89C74} + {793D0EC2-8554-4674-9A97-F25DE5DBE926} = {793D0EC2-8554-4674-9A97-F25DE5DBE926} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcelt", "..\..\celt-0.8.0\libcelt\libcelt.vcproj", "{8181D6A1-DE19-4A5C-9B96-E10A18068C93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug MCD|Win32 = Debug MCD|Win32 + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug MCD|Win32.Build.0 = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.Build.0 = Debug|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.ActiveCfg = Release|Win32 + {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.Build.0 = Release|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug MCD|Win32.Build.0 = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.ActiveCfg = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.Build.0 = Debug|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.ActiveCfg = Release|Win32 + {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.Build.0 = Release|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug MCD|Win32.Build.0 = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.ActiveCfg = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.Build.0 = Debug|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.ActiveCfg = Release|Win32 + {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.Build.0 = Release|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug MCD|Win32.Build.0 = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug|Win32.ActiveCfg = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Debug|Win32.Build.0 = Debug|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Release|Win32.ActiveCfg = Release|Win32 + {2769AFC5-8FC2-42E8-803C-528ACBA89C74}.Release|Win32.Build.0 = Release|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug MCD|Win32.Build.0 = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.ActiveCfg = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.Build.0 = Debug|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.ActiveCfg = Release|Win32 + {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.Build.0 = Release|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Debug MCD|Win32.Build.0 = Debug|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Debug|Win32.ActiveCfg = Debug|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Debug|Win32.Build.0 = Debug|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Release|Win32.ActiveCfg = Release|Win32 + {793D0EC2-8554-4674-9A97-F25DE5DBE926}.Release|Win32.Build.0 = Release|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug MCD|Win32.ActiveCfg = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug MCD|Win32.Build.0 = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug|Win32.ActiveCfg = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Debug|Win32.Build.0 = Debug|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Release|Win32.ActiveCfg = Release|Win32 + {0E29E502-AB22-4147-93A1-AC91528ED758}.Release|Win32.Build.0 = Release|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug MCD|Win32.ActiveCfg = Debug MCD|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug MCD|Win32.Build.0 = Debug MCD|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug|Win32.ActiveCfg = Debug|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Debug|Win32.Build.0 = Debug|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Release|Win32.ActiveCfg = Release|Win32 + {8181D6A1-DE19-4A5C-9B96-E10A18068C93}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Silk_SDK.sln b/Silk_SDK.sln deleted file mode 100644 index ab0dd8d37..000000000 --- a/Silk_SDK.sln +++ /dev/null @@ -1,44 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_FIX", "src\Silk_FIX.vcproj", "{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dec_SDK", "test\Dec_SDK.vcproj", "{82685D7F-0589-42BD-877C-31A952D53A8E}" - ProjectSection(ProjectDependencies) = postProject - {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SignalCompare", "test\SignalCompare.vcproj", "{7FE8F544-9175-40C3-A187-7F15CE9A75D8}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Enc_SDK", "test\Enc_SDK.vcproj", "{6D97A8EF-5724-4D85-8BF4-C583714BBA78}" - ProjectSection(ProjectDependencies) = postProject - {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {56B91D01-9150-4BBF-AFA1-5B68AB991B76} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.ActiveCfg = Debug|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.Build.0 = Debug|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.ActiveCfg = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.Build.0 = Release|Win32 - {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.ActiveCfg = Debug|Win32 - {82685D7F-0589-42BD-877C-31A952D53A8E}.Debug|Win32.Build.0 = Debug|Win32 - {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.ActiveCfg = Release|Win32 - {82685D7F-0589-42BD-877C-31A952D53A8E}.Release|Win32.Build.0 = Release|Win32 - {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.ActiveCfg = Debug|Win32 - {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Debug|Win32.Build.0 = Debug|Win32 - {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.ActiveCfg = Release|Win32 - {7FE8F544-9175-40C3-A187-7F15CE9A75D8}.Release|Win32.Build.0 = Release|Win32 - {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.ActiveCfg = Debug|Win32 - {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Debug|Win32.Build.0 = Debug|Win32 - {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.ActiveCfg = Release|Win32 - {6D97A8EF-5724-4D85-8BF4-C583714BBA78}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/configure.gnu b/configure.gnu deleted file mode 100755 index c78238de4..000000000 --- a/configure.gnu +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/sh -srcpath=$(dirname $0 2>/dev/null ) || srcpath="." -$srcpath/configure "$@" --disable-shared --with-pic - diff --git a/configure.in b/configure.in deleted file mode 100644 index bd71b658a..000000000 --- a/configure.in +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.59]) -AC_INIT(libSKP_SILK_SDK, 1.0.2, brian@freeswitch.org, libSKP_SILK_SDK) -AM_INIT_AUTOMAKE(libSKP_SILK_SDK,1.0.2) - -# Checks for programs. -AC_PROG_CC -AC_PROG_LIBTOOL - -# Checks for header files. -AC_HEADER_STDC -AC_CHECK_HEADERS([float.h stdint.h stdlib.h string.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_SIZE_T - -# Checks for library functions. -AC_FUNC_MALLOC -AC_CHECK_LIB([m],[pow]) - -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT diff --git a/interface/SKP_Silk_SDK_API.h b/interface/SKP_Silk_SDK_API.h index cb31db244..e266780ac 100644 --- a/interface/SKP_Silk_SDK_API.h +++ b/interface/SKP_Silk_SDK_API.h @@ -39,7 +39,7 @@ extern "C" #define SILK_MAX_FRAMES_PER_PACKET 5 -/* Struct for TOC (Table Of Contents) */ +/* 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 */ @@ -56,14 +56,14 @@ typedef struct { /***********************************************/ /* Get size in bytes of the Silk encoder state */ /***********************************************/ -SKP_int SKP_Silk_SDK_Get_Encoder_Size( +SKP_int SKP_Silk_SDK_Get_Encoder_Size( /* O: Returns error code */ SKP_int32 *encSizeBytes /* O: Number of bytes in SILK encoder state */ ); /*************************/ /* Init or reset encoder */ /*************************/ -SKP_int SKP_Silk_SDK_InitEncoder( +SKP_int SKP_Silk_SDK_InitEncoder( /* O: Returns error code */ void *encState, /* I/O: State */ SKP_SILK_SDK_EncControlStruct *encStatus /* O: Encoder Status */ ); @@ -71,7 +71,7 @@ SKP_int SKP_Silk_SDK_InitEncoder( /***************************************/ /* Read control structure from encoder */ /***************************************/ -SKP_int SKP_Silk_SDK_QueryEncoder( +SKP_int SKP_Silk_SDK_QueryEncoder( /* O: Returns error code */ const void *encState, /* I: State */ SKP_SILK_SDK_EncControlStruct *encStatus /* O: Encoder Status */ ); @@ -79,13 +79,13 @@ SKP_int SKP_Silk_SDK_QueryEncoder( /**************************/ /* Encode frame with Silk */ /**************************/ -SKP_int SKP_Silk_SDK_Encode( +SKP_int SKP_Silk_SDK_Encode( /* O: Returns error code */ void *encState, /* I/O: State */ const SKP_SILK_SDK_EncControlStruct *encControl, /* I: Control status */ const SKP_int16 *samplesIn, /* I: Speech sample input vector */ SKP_int nSamplesIn, /* I: Number of samples in input vector */ SKP_uint8 *outData, /* O: Encoded output vector */ - SKP_int16 *nBytesOut /* I/O: Number of Bytes in outData (input: Max Bytes) */ + SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */ ); /****************************************/ @@ -95,26 +95,26 @@ SKP_int SKP_Silk_SDK_Encode( /***********************************************/ /* Get size in bytes of the Silk decoder state */ /***********************************************/ -SKP_int SKP_Silk_SDK_Get_Decoder_Size( +SKP_int SKP_Silk_SDK_Get_Decoder_Size( /* O: Returns error code */ SKP_int32 *decSizeBytes /* O: Number of bytes in SILK decoder state */ ); /*************************/ /* Init or Reset decoder */ /*************************/ -SKP_int SKP_Silk_SDK_InitDecoder( +SKP_int SKP_Silk_SDK_InitDecoder( /* O: Returns error code */ void *decState /* I/O: State */ ); /******************/ /* Decode a frame */ /******************/ -SKP_int SKP_Silk_SDK_Decode( +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 */ const SKP_uint8 *inData, /* I: Encoded input vector */ - const SKP_int nBytesIn, /* I: Number of input Bytes */ + const SKP_int nBytesIn, /* I: Number of input bytes */ SKP_int16 *samplesOut, /* O: Decoded output speech vector */ SKP_int16 *nSamplesOut /* I/O: Number of samples (vector/decoded) */ ); @@ -123,22 +123,20 @@ SKP_int SKP_Silk_SDK_Decode( /* Find Low Bit Rate Redundancy (LBRR) information in a packet */ /***************************************************************/ void SKP_Silk_SDK_search_for_LBRR( - void *decState, /* I: Decoder state, to select bitstream version only */ const SKP_uint8 *inData, /* I: Encoded input vector */ - const SKP_int16 nBytesIn, /* I: Number of input Bytes */ + 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 */ ); -/************************************/ -/* Get type of content for a packet */ -/************************************/ +/**************************************/ +/* Get table of contents for a packet */ +/**************************************/ void SKP_Silk_SDK_get_TOC( - void *decState, /* I: Decoder state, to select bitstream version only */ const SKP_uint8 *inData, /* I: Encoded input vector */ const SKP_int16 nBytesIn, /* I: Number of input bytes */ - SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */ + SKP_Silk_TOC_struct *Silk_TOC /* O: Table of contents */ ); /**************************/ diff --git a/interface/SKP_Silk_control.h b/interface/SKP_Silk_control.h index 2bd056fd2..b0fdc156a 100644 --- a/interface/SKP_Silk_control.h +++ b/interface/SKP_Silk_control.h @@ -39,8 +39,11 @@ extern "C" /* Structure for controlling encoder operation */ /***********************************************/ typedef struct { - /* I: Sampling rate in Hertz; 8000/12000/16000/24000 */ - SKP_int32 sampleRate; + /* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000 */ + SKP_int32 API_sampleRate; + + /* I: Maximum internal sampling rate in Hertz; 8000/12000/16000/24000 */ + SKP_int32 maxInternalSampleRate; /* I: Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms */ SKP_int packetSize; @@ -48,7 +51,7 @@ typedef struct { /* I: Bitrate during active speech in bits/second; internally limited */ SKP_int32 bitRate; - /* I: Uplink Packet loss in pct (0...100) */ + /* I: Uplink packet loss in percent (0-100) */ SKP_int packetLossPercentage; /* I: Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity */ @@ -57,7 +60,7 @@ typedef struct { /* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */ SKP_int useInBandFEC; - /* I: Flag to enable Discontinous Transmission; 0/1 */ + /* I: Flag to enable discontinuous transmission (DTX); 0/1 */ SKP_int useDTX; } SKP_SILK_SDK_EncControlStruct; @@ -65,8 +68,8 @@ typedef struct { /* Structure for controlling decoder operation and reading decoder status */ /**************************************************************************/ typedef struct { - /* I: Sampling rate in Hertz; 8000/12000/16000/24000 */ - SKP_int32 sampleRate; + /* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000 */ + SKP_int32 API_sampleRate; /* O: Number of samples per frame */ SKP_int frameSize; diff --git a/interface/SKP_Silk_errors.h b/interface/SKP_Silk_errors.h index 99b837cb3..475f4934a 100644 --- a/interface/SKP_Silk_errors.h +++ b/interface/SKP_Silk_errors.h @@ -36,48 +36,45 @@ extern "C" /******************/ /* Error messages */ /******************/ -#define SKP_SILK_NO_ERROR 0 +#define SKP_SILK_NO_ERROR 0 /**************************/ /* Encoder error messages */ /**************************/ -/* Input length is not a multiplum of 10 ms, - or length is longer than the packet length */ -#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -1 +/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */ +#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -1 -/* Sampling frequency not 8000, 12000, 16000 - or 24000 Hertz */ -#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2 +/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */ +#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2 /* Packet size not 20, 40, 60, 80 or 100 ms */ -#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -3 +#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -3 /* Allocated payload buffer too short */ -#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4 +#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4 /* Loss rate not between 0 and 100 percent */ -#define SKP_SILK_ENC_WRONG_LOSS_RATE -5 +#define SKP_SILK_ENC_INVALID_LOSS_RATE -5 /* Complexity setting not valid, use 0, 1 or 2 */ -#define SKP_SILK_ENC_WRONG_COMPLEXITY_SETTING -6 +#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -6 /* Inband FEC setting not valid, use 0 or 1 */ -#define SKP_SILK_ENC_WRONG_INBAND_FEC_SETTING -7 +#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -7 /* DTX setting not valid, use 0 or 1 */ -#define SKP_SILK_ENC_WRONG_DTX_SETTING -8 +#define SKP_SILK_ENC_INVALID_DTX_SETTING -8 /* Internal encoder error */ -#define SKP_SILK_ENC_INTERNAL_ERROR -9 +#define SKP_SILK_ENC_INTERNAL_ERROR -9 /**************************/ /* Decoder error messages */ /**************************/ -/* Output sampling frequency lower than internal - decoded sampling frequency */ -#define SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY -10 +/* Output sampling frequency lower than internal decoded sampling frequency */ +#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -10 /* Payload size exceeded the maximum allowed 1024 bytes */ #define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -11 @@ -85,7 +82,6 @@ extern "C" /* Payload has bit errors */ #define SKP_SILK_DEC_PAYLOAD_ERROR -12 - #ifdef __cplusplus } #endif diff --git a/interface/SKP_debug.h b/interface/SKP_debug.h new file mode 100644 index 000000000..d55ca9569 --- /dev/null +++ b/interface/SKP_debug.h @@ -0,0 +1,293 @@ +/*********************************************************************** +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_debug.h * + * * + * This contains code to help debugging * + * * + * Copyright 2009 (c), Skype Limited * + * Date: 090629 * + * */ +#ifndef _SKP_DEBUG_H_ +#define _SKP_DEBUG_H_ + +#ifdef _WIN32 +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif + +#include "SKP_Silk_typedef.h" +#include <stdio.h> /* file writing */ +#include <string.h> /* strcpy, strcmp */ + +#ifdef __cplusplus +extern "C" +{ +#endif + +unsigned long GetHighResolutionTime(); /* O: time in usec*/ + +/* make SKP_DEBUG dependent on compiler's _DEBUG */ +#if defined _WIN32 + #ifdef _DEBUG + #define SKP_DEBUG 1 + #else + #define SKP_DEBUG 0 + #endif + + /* overrule the above */ + #if 0 + // #define NO_ASSERTS + #undef SKP_DEBUG + #define SKP_DEBUG 1 + #endif +#else + #define SKP_DEBUG 0 +#endif + +/* Flag for using timers */ +#define SKP_TIC_TOC 1 + +#if SKP_TIC_TOC + +#if (defined(_WIN32) || defined(_WINCE)) +#include <windows.h> /* timer */ +#pragma warning( disable : 4996 ) // stop bitching about strcpy in TIC() +#else // Linux or Mac +#include <sys/time.h> +#endif + +/*********************************/ +/* timer functions for profiling */ +/*********************************/ +/* example: */ +/* */ +/* TIC(LPC) */ +/* do_LPC(in_vec, order, acoef); // do LPC analysis */ +/* TOC(LPC) */ +/* */ +/* and call the following just before exiting (from main) */ +/* */ +/* SKP_TimerSave("SKP_TimingData.txt"); */ +/* */ +/* results are now in SKP_TimingData.txt */ + +void SKP_TimerSave(char *file_name); + +/* max number of timers (in different locations) */ +#define SKP_NUM_TIMERS_MAX 50 +/* max length of name tags in TIC(..), TOC(..) */ +#define SKP_NUM_TIMERS_MAX_TAG_LEN 30 + +extern int SKP_Timer_nTimers; +extern int SKP_Timer_depth_ctr; +extern char SKP_Timer_tags[SKP_NUM_TIMERS_MAX][SKP_NUM_TIMERS_MAX_TAG_LEN]; +#ifdef _WIN32 +extern LARGE_INTEGER SKP_Timer_start[SKP_NUM_TIMERS_MAX]; +#else +extern unsigned long SKP_Timer_start[SKP_NUM_TIMERS_MAX]; +#endif +extern unsigned int SKP_Timer_cnt[SKP_NUM_TIMERS_MAX]; +extern SKP_int64 SKP_Timer_sum[SKP_NUM_TIMERS_MAX]; +extern SKP_int64 SKP_Timer_max[SKP_NUM_TIMERS_MAX]; +extern SKP_int64 SKP_Timer_min[SKP_NUM_TIMERS_MAX]; +extern SKP_int64 SKP_Timer_depth[SKP_NUM_TIMERS_MAX]; + +/* WARNING: TIC()/TOC can measure only up to 0.1 seconds at a time */ +#ifdef _WIN32 +#define TIC(TAG_NAME) { \ + static int init = 0; \ + static int ID = -1; \ + if( init == 0 ) \ + { \ + int k; \ + init = 1; \ + for( k = 0; k < SKP_Timer_nTimers; k++ ) { \ + if( strcmp(SKP_Timer_tags[k], #TAG_NAME) == 0 ) { \ + ID = k; \ + break; \ + } \ + } \ + if (ID == -1) { \ + ID = SKP_Timer_nTimers; \ + SKP_Timer_nTimers++; \ + SKP_Timer_depth[ID] = SKP_Timer_depth_ctr; \ + strcpy(SKP_Timer_tags[ID], #TAG_NAME); \ + SKP_Timer_cnt[ID] = 0; \ + SKP_Timer_sum[ID] = 0; \ + SKP_Timer_min[ID] = 0xFFFFFFFF; \ + SKP_Timer_max[ID] = 0; \ + } \ + } \ + SKP_Timer_depth_ctr++; \ + QueryPerformanceCounter(&SKP_Timer_start[ID]); \ +} +#else +#define TIC(TAG_NAME) { \ + static int init = 0; \ + static int ID = -1; \ + if( init == 0 ) \ + { \ + int k; \ + init = 1; \ + for( k = 0; k < SKP_Timer_nTimers; k++ ) { \ + if( strcmp(SKP_Timer_tags[k], #TAG_NAME) == 0 ) { \ + ID = k; \ + break; \ + } \ + } \ + if (ID == -1) { \ + ID = SKP_Timer_nTimers; \ + SKP_Timer_nTimers++; \ + SKP_Timer_depth[ID] = SKP_Timer_depth_ctr; \ + strcpy(SKP_Timer_tags[ID], #TAG_NAME); \ + SKP_Timer_cnt[ID] = 0; \ + SKP_Timer_sum[ID] = 0; \ + SKP_Timer_min[ID] = 0xFFFFFFFF; \ + SKP_Timer_max[ID] = 0; \ + } \ + } \ + SKP_Timer_depth_ctr++; \ + SKP_Timer_start[ID] = GetHighResolutionTime(); \ +} +#endif + +#ifdef _WIN32 +#define TOC(TAG_NAME) { \ + LARGE_INTEGER lpPerformanceCount; \ + static int init = 0; \ + static int ID = 0; \ + if( init == 0 ) \ + { \ + int k; \ + init = 1; \ + for( k = 0; k < SKP_Timer_nTimers; k++ ) { \ + if( strcmp(SKP_Timer_tags[k], #TAG_NAME) == 0 ) { \ + ID = k; \ + break; \ + } \ + } \ + } \ + QueryPerformanceCounter(&lpPerformanceCount); \ + lpPerformanceCount.QuadPart -= SKP_Timer_start[ID].QuadPart; \ + if((lpPerformanceCount.QuadPart < 100000000) && \ + (lpPerformanceCount.QuadPart >= 0)) { \ + SKP_Timer_cnt[ID]++; \ + SKP_Timer_sum[ID] += lpPerformanceCount.QuadPart; \ + if( lpPerformanceCount.QuadPart > SKP_Timer_max[ID] ) \ + SKP_Timer_max[ID] = lpPerformanceCount.QuadPart; \ + if( lpPerformanceCount.QuadPart < SKP_Timer_min[ID] ) \ + SKP_Timer_min[ID] = lpPerformanceCount.QuadPart; \ + } \ + SKP_Timer_depth_ctr--; \ +} +#else +#define TOC(TAG_NAME) { \ + unsigned long endTime; \ + static int init = 0; \ + static int ID = 0; \ + if( init == 0 ) \ + { \ + int k; \ + init = 1; \ + for( k = 0; k < SKP_Timer_nTimers; k++ ) { \ + if( strcmp(SKP_Timer_tags[k], #TAG_NAME) == 0 ) { \ + ID = k; \ + break; \ + } \ + } \ + } \ + endTime = GetHighResolutionTime(); \ + endTime -= SKP_Timer_start[ID]; \ + if((endTime < 100000000) && \ + (endTime >= 0)) { \ + SKP_Timer_cnt[ID]++; \ + SKP_Timer_sum[ID] += endTime; \ + if( endTime > SKP_Timer_max[ID] ) \ + SKP_Timer_max[ID] = endTime; \ + if( endTime < SKP_Timer_min[ID] ) \ + SKP_Timer_min[ID] = endTime; \ + } \ + SKP_Timer_depth_ctr--; \ +} +#endif + +#else /* SKP_TIC_TOC */ + +/* define macros as empty strings */ +#define TIC(TAG_NAME) +#define TOC(TAG_NAME) +#define SKP_TimerSave(FILE_NAME) + +#endif /* SKP_TIC_TOC */ + + + +#if SKP_DEBUG +/************************************/ +/* write data to file for debugging */ +/************************************/ +/* opens an empty file if this file has not yet been open, then writes to the file and closes it */ +/* if file has been open previously it is opened again and the fwrite is appending, finally it is closed */ +#define SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES) { static SKP_int32 init = 0;FILE *fp;if (init == 0) {init = 1;fp = fopen(#FILE_NAME, "wb");}else {fp = fopen(#FILE_NAME, "ab+");} fwrite((DATA_PTR), (N_BYTES), 1, fp);fclose(fp);} + +/* Example: DEBUG_STORE_DATA(testfile.pcm, &RIN[0], 160*sizeof(SKP_int16)); */ + +#if 0 +/* Ensure that everything is written to files when an assert breaks */ +#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES) +#else +/* Faster way of storing the data */ +#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) { \ + static SKP_int32 init = 0; \ + static FILE *fp; \ + if (init == 0) \ + { \ + init = 1; \ + fp = fopen(#FILE_NAME, "wb"); \ + } \ + fwrite((DATA_PTR), (N_BYTES), 1, fp); \ +} +#endif + +/* micro sec */ +#define SKP_GETTIME(void) time = (SKP_int64) GetHighResolutionTime(); + +#else /* SKP_DEBUG */ + +/* define macros as empty strings */ +#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) +#define SAVE_DATA(FILE_NAME, DATA_PTR, N_BYTES) + +#endif /* SKP_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SKP_DEBUG_H_ */ diff --git a/readme.txt b/readme.txt index 11cf53134..9c826b055 100644 --- a/readme.txt +++ b/readme.txt @@ -8,7 +8,7 @@ Date: 09/03/2010 (Format: DD/MM/YYYY) I. Description -This package contains files for compiling and testing the fixed +This package contains files for compilation and evaluation of the fixed point SILK SDK library. The following is included in this package: o Source code for the fixed point SILK SDK library diff --git a/src/SKP_Silk_common_pitch_est_defines.h b/src/SKP_Silk_common_pitch_est_defines.h deleted file mode 100644 index 2e001f428..000000000 --- a/src/SKP_Silk_common_pitch_est_defines.h +++ /dev/null @@ -1,76 +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 SIGPROC_COMMON_PITCH_EST_DEFINES_H -#define SIGPROC_COMMON_PITCH_EST_DEFINES_H - -#include "SKP_Silk_SigProc_FIX.h" - -/************************************************************/ -/* Definitions For Fix pitch estimator */ -/************************************************************/ - -#define PITCH_EST_MAX_FS_KHZ 24 /* Maximum sampling frequency used */ - -#define PITCH_EST_FRAME_LENGTH_MS 40 /* 40 ms */ - -#define PITCH_EST_MAX_FRAME_LENGTH (PITCH_EST_FRAME_LENGTH_MS * PITCH_EST_MAX_FS_KHZ) -#define PITCH_EST_MAX_FRAME_LENGTH_ST_1 (PITCH_EST_MAX_FRAME_LENGTH >> 2) -#define PITCH_EST_MAX_FRAME_LENGTH_ST_2 (PITCH_EST_MAX_FRAME_LENGTH >> 1) -#define PITCH_EST_MAX_SF_FRAME_LENGTH (PITCH_EST_SUB_FRAME * PITCH_EST_MAX_FS_KHZ) - -#define PITCH_EST_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */ -#define PITCH_EST_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */ -#define PITCH_EST_MAX_LAG (PITCH_EST_MAX_LAG_MS * PITCH_EST_MAX_FS_KHZ) -#define PITCH_EST_MIN_LAG (PITCH_EST_MIN_LAG_MS * PITCH_EST_MAX_FS_KHZ) - -#define PITCH_EST_NB_SUBFR 4 - -#define PITCH_EST_D_SRCH_LENGTH 24 - -#define PITCH_EST_MAX_DECIMATE_STATE_LENGTH 7 - -#define PITCH_EST_NB_STAGE3_LAGS 5 - -#define PITCH_EST_NB_CBKS_STAGE2 3 -#define PITCH_EST_NB_CBKS_STAGE2_EXT 11 - -#define PITCH_EST_CB_mn2 1 -#define PITCH_EST_CB_mx2 2 - -#define PITCH_EST_NB_CBKS_STAGE3_MAX 34 -#define PITCH_EST_NB_CBKS_STAGE3_MID 24 -#define PITCH_EST_NB_CBKS_STAGE3_MIN 16 - -extern const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT]; -extern const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX]; -extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ]; -extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ]; -extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ]; - -#endif - diff --git a/src/SKP_Silk_control_codec_FIX.c b/src/SKP_Silk_control_codec_FIX.c deleted file mode 100644 index e4f64429e..000000000 --- a/src/SKP_Silk_control_codec_FIX.c +++ /dev/null @@ -1,656 +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. -***********************************************************************/ - -#include "SKP_Silk_main_FIX.h" - -/* Control encoder SNR */ -SKP_int SKP_Silk_control_encoder_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */ - const SKP_int API_fs_kHz, /* I External (API) sampling rate (kHz) */ - const SKP_int PacketSize_ms, /* I Packet length (ms) */ - SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */ - const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */ - const SKP_int INBandFec_enabled, /* I Enable (1) / disable (0) inband FEC */ - const SKP_int DTX_enabled, /* I Enable / disable DTX */ - const SKP_int InputFramesize_ms, /* I Inputframe in ms */ - const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */ -) -{ - SKP_int32 LBRRRate_thres_bps; - SKP_int k, fs_kHz, ret = 0; - SKP_int32 frac_Q6; - const SKP_int32 *rateTable; - - /* State machine for the SWB/WB switching */ - fs_kHz = psEnc->sCmn.fs_kHz; - - /* Only switch during low speech activity, when no frames are sitting in the payload buffer */ - if( API_fs_kHz == 8 || fs_kHz == 0 || API_fs_kHz < fs_kHz ) { - // Switching is not possible, encoder just initialized, or internal mode higher than external - fs_kHz = API_fs_kHz; - } else { - - /* Resample all valid data in x_buf. Resampling the last part gets rid of a click, 5ms after switching */ - /* this is because the same state is used when downsampling in API.c and is then up to date */ - /* the click immidiatly after switching is most of the time still there */ - - if( psEnc->sCmn.fs_kHz == 24 ) { - /* Accumulate the difference between the target rate and limit */ - if( psEnc->sCmn.fs_kHz_changed == 0 ) { - psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - SWB2WB_BITRATE_BPS_INITIAL ); - } else { - psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - SWB2WB_BITRATE_BPS ); - } - psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 ); - - /* Check if we should switch from 24 to 16 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */ - ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || psEnc->sCmn.sSWBdetect.WB_detected == 1 ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */ - psEnc->sCmn.sLP.mode = 0; /* Switch down */ - } - - if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) && /* Transition phase complete, ready to switch */ -#else - if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || psEnc->sCmn.sSWBdetect.WB_detected == 1 ) && -#endif - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - SKP_int16 x_bufout[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 16; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - SKP_memset( psEnc->sCmn.resample24To16state, 0, sizeof( psEnc->sCmn.resample24To16state ) ); - -#if LOW_COMPLEXITY_ONLY - { - SKP_int16 scratch[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; - SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, (SKP_int16*)scratch ); - } -#else - SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); -#endif - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_bufout, 0, 320 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */ -#endif - } - } else if( psEnc->sCmn.fs_kHz == 16 ) { - - /* Check if we should switch from 16 to 24 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */ -#else - if( -#endif - ( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= WB2SWB_BITRATE_BPS && psEnc->sCmn.sSWBdetect.WB_detected == 0 ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - SKP_int16 x_bufout[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ]; - SKP_int32 resample16To24state[ 11 ]; - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 24; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - SKP_memset( resample16To24state, 0, sizeof(resample16To24state) ); - - SKP_Silk_resample_3_2( &x_bufout[ 0 ], resample16To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_bufout, 0, 480 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.mode = 1; /* Switch up */ -#endif - } else { - /* accumulate the difference between the target rate and limit */ - psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - WB2MB_BITRATE_BPS ); - psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 ); - - /* Check if we should switch from 16 to 12 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */ - ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */ - psEnc->sCmn.sLP.mode = 0; /* Switch down */ - } - - if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) && /* Transition phase complete, ready to switch */ -#else - if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) && -#endif - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 12; - - if( API_fs_kHz == 24 ) { - - /* Intermediate upsampling of x_bufFIX from 16 to 24 kHz */ - SKP_int16 x_buf24[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ]; - SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 resample16To24state[ 11 ]; - - SKP_memset( resample16To24state, 0, sizeof( resample16To24state ) ); - SKP_Silk_resample_3_2( &x_buf24[ 0 ], resample16To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - /* Update the state of the resampler used in API.c, from 24 to 12 kHz */ - SKP_memset( psEnc->sCmn.resample24To12state, 0, sizeof( psEnc->sCmn.resample24To12state ) ); - SKP_Silk_resample_1_2_coarse( &x_buf24[ 0 ], psEnc->sCmn.resample24To12state, &x_buf[ 0 ], scratch, SKP_RSHIFT( SKP_SMULBB( 3, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ), 2 ) ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - } else if( API_fs_kHz == 16 ) { - SKP_int16 x_bufout[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 4 ]; - SKP_memset( psEnc->sCmn.resample16To12state, 0, sizeof( psEnc->sCmn.resample16To12state ) ); - - SKP_Silk_resample_3_4( &x_bufout[ 0 ], psEnc->sCmn.resample16To12state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_bufout, 0, 240 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - } -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */ -#endif - } - } - } else if( psEnc->sCmn.fs_kHz == 12 ) { - - /* Check if we should switch from 12 to 16 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */ -#else - if( -#endif - ( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= MB2WB_BITRATE_BPS ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 16; - - /* Reset state of the resampler to be used */ - if( API_fs_kHz == 24 ) { - - SKP_int16 x_bufout[ 2 * 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 3 ]; - - /* Intermediate upsampling of x_bufFIX from 12 to 24 kHz */ - SKP_int16 x_buf24[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 resample12To24state[6]; - - SKP_memset( resample12To24state, 0, sizeof( resample12To24state ) ); - SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample12To24state, &x_buf24[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - SKP_memset( psEnc->sCmn.resample24To16state, 0, sizeof( psEnc->sCmn.resample24To16state ) ); - -#if LOW_COMPLEXITY_ONLY - SKP_assert( sizeof( SKP_int16 ) * ( 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ) <= sizeof( scratch ) ); - SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ), (SKP_int16*)scratch ); -#else - SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) ); -#endif - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_bufout, 0, 320 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - } -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.mode = 1; /* Switch up */ -#endif - } else { - /* accumulate the difference between the target rate and limit */ - psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - MB2NB_BITRATE_BPS ); - psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 ); - - /* Check if we should switch from 12 to 8 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */ - ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */ - psEnc->sCmn.sLP.mode = 0; /* Switch down */ - } - - if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) && -#else - if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) && -#endif - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 8; - - if( API_fs_kHz == 24 ) { - - SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - /* Intermediate upsampling of x_buf from 12 to 24 kHz */ - SKP_int16 x_buf24[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 resample12To24state[ 6 ]; - - SKP_memset( resample12To24state, 0, sizeof( resample12To24state ) ); - SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample12To24state, &x_buf24[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - /* Update the state of the resampler used in API.c, from 24 to 8 kHz */ - SKP_memset( psEnc->sCmn.resample24To8state, 0, sizeof( psEnc->sCmn.resample24To8state ) ); - SKP_Silk_resample_1_3( &x_buf[ 0 ], psEnc->sCmn.resample24To8state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_buf, 0, 160 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - } else if( API_fs_kHz == 16 ) { - /* Intermediate upsampling of x_bufFIX from 12 to 16 kHz */ - SKP_int16 x_buf16[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ]; - SKP_int32 resample12To16state[11]; - - SKP_memset( resample12To16state, 0, sizeof( resample12To16state ) ); - SKP_Silk_resample_3_2( &x_buf16[ 0 ], resample12To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_buf, 0, 160 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - } else if( API_fs_kHz == 12 ) { - SKP_int16 x_bufout[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 3 ]; - SKP_memset( psEnc->sCmn.resample12To8state, 0, sizeof( psEnc->sCmn.resample12To8state ) ); -#if LOW_COMPLEXITY_ONLY - { - SKP_int16 scratch[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; - SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample12To8state, &x_buf[ 0 ], - SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, scratch ); - } -#else - SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample12To8state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); -#endif - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_bufout, 0, 160 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - } -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */ -#endif - } - } - } else if( psEnc->sCmn.fs_kHz == 8 ) { - - /* Check if we should switch from 8 to 12 kHz */ -#if SWITCH_TRANSITION_FILTERING - if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */ -#else - if( -#endif - ( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= NB2MB_BITRATE_BPS ) && - ( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; - - SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - psEnc->sCmn.bitrateDiff = 0; - fs_kHz = 12; - - /* Reset state of the resampler to be used */ - if( API_fs_kHz == 24 ) { - SKP_int16 x_buf24[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 scratch[ 3 * 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ]; - SKP_int32 resample8To24state[ 7 ]; - - /* Intermediate upsampling of x_bufFIX from 8 to 24 kHz */ - SKP_memset( resample8To24state, 0, sizeof( resample8To24state ) ); - SKP_Silk_resample_3_1( &x_buf24[ 0 ], resample8To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - SKP_memset( psEnc->sCmn.resample24To12state, 0, sizeof( psEnc->sCmn.resample24To12state ) ); - - SKP_Silk_resample_1_2_coarse( &x_buf24[ 0 ], psEnc->sCmn.resample24To12state, &x_buf[ 0 ], scratch, SKP_RSHIFT( SKP_SMULBB( 3, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ), 1 ) ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - - } else if( API_fs_kHz == 16 ) { - SKP_int16 x_buf16[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; - SKP_int32 resample8To16state[ 6 ]; - - /* Intermediate upsampling of x_bufFIX from 8 to 16 kHz */ - SKP_memset( resample8To16state, 0, sizeof( resample8To16state ) ); - SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample8To16state, &x_buf16[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ); - - SKP_memset( psEnc->sCmn.resample16To12state, 0, sizeof( psEnc->sCmn.resample16To12state ) ); - - SKP_Silk_resample_3_4( &x_buf[ 0 ], psEnc->sCmn.resample16To12state, &x_buf16[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) ); - - /* set the first frame to zero, no performance difference was noticed though */ - SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) ); - SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) ); - } -#if SWITCH_TRANSITION_FILTERING - psEnc->sCmn.sLP.mode = 1; /* Switch up */ -#endif - } - } else { - // Internal sample frequency not supported! - SKP_assert( 0 ); - } - } - -#if SWITCH_TRANSITION_FILTERING - /* After switching up, stop transition filter during speech inactivity */ - if( ( psEnc->sCmn.sLP.mode == 1 ) && - ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && - ( psEnc->speech_activity_Q8 < 128 ) && - ( psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { - - psEnc->sCmn.sLP.transition_frame_no = 0; - - /* Reset transition filter state */ - SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); - } -#endif - - - - /* Set internal sampling frequency */ - if( psEnc->sCmn.fs_kHz != fs_kHz ) { - /* reset part of the state */ - SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) ); - SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) ); - SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) ); - SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) ); - SKP_memset( psEnc->sNSQ.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) ); - SKP_memset( psEnc->sNSQ_LBRR.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) ); - SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) ); -#if SWITCH_TRANSITION_FILTERING - SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); - if( psEnc->sCmn.sLP.mode == 1 ) { - /* Begin transition phase */ - psEnc->sCmn.sLP.transition_frame_no = 1; - } else { - /* End transition phase */ - psEnc->sCmn.sLP.transition_frame_no = 0; - } -#endif - psEnc->sCmn.inputBufIx = 0; - psEnc->sCmn.nFramesInPayloadBuf = 0; - psEnc->sCmn.nBytesInPayloadBuf = 0; - psEnc->sCmn.oldest_LBRR_idx = 0; - psEnc->sCmn.TargetRate_bps = 0; /* ensures that psEnc->SNR_dB is recomputed */ - - SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); - - /* Initialize non-zero parameters */ - psEnc->sCmn.prevLag = 100; - psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED; - 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.fs_kHz = fs_kHz; - if( psEnc->sCmn.fs_kHz == 8 ) { - psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER; - psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10; - psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10; - } else { - psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER; - psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16; - psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16; - } - psEnc->sCmn.frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz ); - psEnc->sCmn.subfr_length = SKP_DIV32_16( psEnc->sCmn.frame_length, NB_SUBFR ); - psEnc->sCmn.la_pitch = SKP_SMULBB( LA_PITCH_MS, fs_kHz ); - psEnc->sCmn.la_shape = SKP_SMULBB( LA_SHAPE_MS, fs_kHz ); - psEnc->sPred.min_pitch_lag = SKP_SMULBB( 3, fs_kHz ); - psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz ); - psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); - if( psEnc->sCmn.fs_kHz == 24 ) { - psEnc->mu_LTP_Q8 = MU_LTP_QUANT_SWB_Q8; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - psEnc->mu_LTP_Q8 = MU_LTP_QUANT_WB_Q8; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - psEnc->mu_LTP_Q8 = MU_LTP_QUANT_MB_Q8; - } else { - psEnc->mu_LTP_Q8 = MU_LTP_QUANT_NB_Q8; - } - psEnc->sCmn.fs_kHz_changed = 1; - - /* Check that settings are valid */ - SKP_assert( ( psEnc->sCmn.subfr_length * NB_SUBFR ) == psEnc->sCmn.frame_length ); - } - - /* Set encoding complexity */ - if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) { - /* Low complexity */ - psEnc->sCmn.Complexity = 0; - psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_LC_MODE; - psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_LC_MODE; - psEnc->sCmn.pitchEstimationLPCOrder = 8; - psEnc->sCmn.shapingLPCOrder = 12; - psEnc->sCmn.nStatesDelayedDecision = 1; - psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ; - psEnc->sCmn.useInterpolatedNLSFs = 0; - psEnc->sCmn.LTPQuantLowComplexity = 1; - psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE; - } else if( Complexity == 1 ) { - /* Medium complexity */ - psEnc->sCmn.Complexity = 1; - psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_MC_MODE; - psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_MC_MODE; - psEnc->sCmn.pitchEstimationLPCOrder = 12; - psEnc->sCmn.shapingLPCOrder = 16; - psEnc->sCmn.nStatesDelayedDecision = 2; - psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ_del_dec; - psEnc->sCmn.useInterpolatedNLSFs = 0; - psEnc->sCmn.LTPQuantLowComplexity = 0; - psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE; - } else if( Complexity == 2 ) { - /* High complexity */ - psEnc->sCmn.Complexity = 2; - psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_HC_MODE; - psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_HC_MODE; - psEnc->sCmn.pitchEstimationLPCOrder = 16; - psEnc->sCmn.shapingLPCOrder = 16; - psEnc->sCmn.nStatesDelayedDecision = 4; - psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ_del_dec; - psEnc->sCmn.useInterpolatedNLSFs = 1; - psEnc->sCmn.LTPQuantLowComplexity = 0; - psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS; - } else { - ret = SKP_SILK_ENC_WRONG_COMPLEXITY_SETTING; - } - - /* Dont have higher Pitch estimation LPC order than predict LPC order */ - psEnc->sCmn.pitchEstimationLPCOrder = SKP_min_int( psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.predictLPCOrder ); - - SKP_assert( psEnc->sCmn.pitchEstimationLPCOrder <= FIND_PITCH_LPC_ORDER_MAX ); - SKP_assert( psEnc->sCmn.shapingLPCOrder <= SHAPE_LPC_ORDER_MAX ); - SKP_assert( psEnc->sCmn.nStatesDelayedDecision <= DEL_DEC_STATES_MAX ); - - /* Set bitrate/coding quality */ - TargetRate_bps = SKP_min( TargetRate_bps, 100000 ); - if( psEnc->sCmn.fs_kHz == 8 ) { - TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_NB_BPS ); - } else if( psEnc->sCmn.fs_kHz == 12 ) { - TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_MB_BPS ); - } else if( psEnc->sCmn.fs_kHz == 16 ) { - TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_WB_BPS ); - } else { - TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_SWB_BPS ); - } - if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) { - psEnc->sCmn.TargetRate_bps = TargetRate_bps; - - /* if new TargetRate_bps, translate to SNR_dB value */ - if( psEnc->sCmn.fs_kHz == 8 ) { - rateTable = TargetRate_table_NB; - } else if( psEnc->sCmn.fs_kHz == 12 ) { - rateTable = TargetRate_table_MB; - } else if( psEnc->sCmn.fs_kHz == 16 ) { - rateTable = TargetRate_table_WB; - } else { - rateTable = TargetRate_table_SWB; - } - for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { - /* find bitrate interval in table and interpolate */ - 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 ] ); - break; - } - } - } - - /* Set packet size */ - if( ( PacketSize_ms != 20 ) && - ( PacketSize_ms != 40 ) && - ( PacketSize_ms != 60 ) && - ( PacketSize_ms != 80 ) && - ( PacketSize_ms != 100 ) ) { - ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; - } else { - if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) { - psEnc->sCmn.PacketSize_ms = PacketSize_ms; - - /* Packet length changes. Reset LBRR buffer */ - SKP_Silk_LBRR_reset( &psEnc->sCmn ); - } - } - - /* Set packet loss rate measured by farend */ - if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) { - ret = SKP_SILK_ENC_WRONG_LOSS_RATE; - } - psEnc->sCmn.PacketLoss_perc = PacketLoss_perc; - -#if USE_LBRR - if( INBandFec_enabled < 0 || INBandFec_enabled > 1 ) { - ret = SKP_SILK_ENC_WRONG_INBAND_FEC_SETTING; - } - - /* Only change settings if first frame in packet */ - if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - - psEnc->sCmn.LBRR_enabled = INBandFec_enabled; - 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 */ - /* Coarse 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 aprox same mean / weighted bitrate as no inband FEC */ - psEnc->inBandFEC_SNR_comp_Q8 = ( 6 << 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 - psEnc->sCmn.LBRR_enabled = 0; -#endif - - /* Set DTX mode */ - if( DTX_enabled < 0 || DTX_enabled > 1 ) { - ret = SKP_SILK_ENC_WRONG_DTX_SETTING; - } - psEnc->sCmn.useDTX = DTX_enabled; - - return ret; -} - -/* Control low bitrate redundancy usage */ -void SKP_Silk_LBRR_ctrl_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */ - SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control */ -) -{ - SKP_int LBRR_usage; - - if( psEnc->sCmn.LBRR_enabled ) { - /* Control LBRR */ - - /* Usage Control based on sensitivity and packet loss caracteristics */ - /* For now only enable adding to next for active frames. Make more complex later */ - LBRR_usage = SKP_SILK_NO_LBRR; - if( psEnc->speech_activity_Q8 > LBRR_SPEECH_ACTIVITY_THRES_Q8 && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity - //if( psEnc->PacketLoss_burst > BURST_THRES ) - // psEncCtrl->LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS2; - //} else { - LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1;//SKP_SILK_NO_LBRR - //} - } - psEncCtrl->sCmn.LBRR_usage = LBRR_usage; - } else { - psEncCtrl->sCmn.LBRR_usage = SKP_SILK_NO_LBRR; - } -} diff --git a/src/SKP_Silk_dec_API.c b/src/SKP_Silk_dec_API.c deleted file mode 100644 index 70f7d31e6..000000000 --- a/src/SKP_Silk_dec_API.c +++ /dev/null @@ -1,343 +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. -***********************************************************************/ - -#include "SKP_Silk_SDK_API.h" -#include "SKP_Silk_main_FIX.h" - -/*********************/ -/* Decoder functions */ -/*********************/ - -SKP_int SKP_Silk_SDK_Get_Decoder_Size( SKP_int32 *decSizeBytes ) -{ - SKP_int ret = 0; - - *decSizeBytes = sizeof( SKP_Silk_decoder_state ); - - return ret; -} - -/* Reset decoder state */ -SKP_int SKP_Silk_SDK_InitDecoder( - void* decState /* I/O: State */ -) -{ - SKP_int ret = 0; - SKP_Silk_decoder_state *struc; - - struc = (SKP_Silk_decoder_state *)decState; - - ret = SKP_Silk_init_decoder( struc ); - - return ret; -} - -/* Decode a frame */ -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 */ - const SKP_uint8 *inData, /* I: Encoded input vector */ - const SKP_int nBytesIn, /* I: Number of input Bytes */ - SKP_int16 *samplesOut, /* O: Decoded output speech vector */ - SKP_int16 *nSamplesOut /* I/O: Number of samples (vector/decoded) */ -) -{ - SKP_int ret = 0, used_bytes, prev_fs_kHz; - SKP_Silk_decoder_state *psDec; - - psDec = (SKP_Silk_decoder_state *)decState; - - /**********************************/ - /* Test if first frame in payload */ - /**********************************/ - if( psDec->moreInternalDecoderFrames == 0 ) { - /* 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; - ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE; - } - - /* Save previous sample frequency */ - prev_fs_kHz = psDec->fs_kHz; - - /* Call decoder for one frame */ - ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn, - lostFlag, &used_bytes ); - - if( used_bytes ) { /* Only Call if not a packet loss */ - if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) { - /* We have more frames in the Payload */ - psDec->moreInternalDecoderFrames = 1; - } else { - /* Last frame in Payload */ - psDec->moreInternalDecoderFrames = 0; - psDec->nFramesInPacket = psDec->nFramesDecoded; - - /* Track inband FEC usage */ - if( psDec->vadFlag == VOICE_ACTIVITY ) { - if( psDec->FrameTermination == SKP_SILK_LAST_FRAME ) { - psDec->no_FEC_counter++; - if( psDec->no_FEC_counter > NO_LBRR_THRES ) { - psDec->inband_FEC_offset = 0; - } - } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER1 ) { - psDec->inband_FEC_offset = 1; /* FEC info with 1 packet delay */ - psDec->no_FEC_counter = 0; - } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER2 ) { - psDec->inband_FEC_offset = 2; /* FEC info with 2 packets delay */ - psDec->no_FEC_counter = 0; - } - } - } - } - - if( psDec->fs_kHz * 1000 > decControl->sampleRate ) { - ret = SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY; - } - - /* Do any resampling if needed */ - if( psDec->fs_kHz * 1000 != decControl->sampleRate ) { - SKP_int16 samplesOut_tmp[ 2 * MAX_FRAME_LENGTH ]; - SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ]; - - /* Copy to a tmpbuffer as the resampling writes to samplesOut */ - memcpy( samplesOut_tmp, samplesOut, *nSamplesOut * sizeof( SKP_int16 ) ); - - /* Clear resampler state when switching internal sampling frequency */ - if( prev_fs_kHz != psDec->fs_kHz ) { - SKP_memset( psDec->resampleState, 0, sizeof( psDec->resampleState ) ); - } - - if( psDec->fs_kHz == 16 && decControl->sampleRate == 24000 ) { - /* Resample from 16 kHz to 24 kHz */ - SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut ); - } else if( psDec->fs_kHz == 12 && decControl->sampleRate == 24000 ) { - /* Resample from 12 kHz to 24 kHz */ - SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut ); - } else if( psDec->fs_kHz == 8 && decControl->sampleRate == 24000 ) { - /* Resample from 8 kHz to 24 kHz */ - SKP_Silk_resample_3_1( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut ); - } else if( psDec->fs_kHz == 12 && decControl->sampleRate == 16000 ) { - /* Resample from 12 kHz to 16 kHz */ - SKP_Silk_resample_4_3( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut ); - } else if( psDec->fs_kHz == 8 && decControl->sampleRate == 16000 ) { - /* Resample from 8 kHz to 16 kHz */ - SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut ); - } else if( psDec->fs_kHz == 8 && decControl->sampleRate == 12000 ) { - /* Resample from 8 kHz to 12 kHz */ - SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut ); - } - - *nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->sampleRate, psDec->fs_kHz * 1000 ); - } - - /* Copy all parameters that are needed out of internal structure to the control stucture */ - decControl->frameSize = ( SKP_int )psDec->frame_length; - decControl->framesPerPacket = ( SKP_int )psDec->nFramesInPacket; - decControl->inBandFECOffset = ( SKP_int )psDec->inband_FEC_offset; - decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames; - - return ret; -} - -/* Function to find LBRR information in a packet */ -void SKP_Silk_SDK_search_for_LBRR( - void *decState, /* I: Decoder state, to select bitstream version only */ - 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 */ -) -{ - SKP_Silk_decoder_state *psDec; - 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 ]; - - psDec = ( SKP_Silk_decoder_state * )decState; - - if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) { - /* No useful FEC in this packet */ - *nLBRRBytes = 0; - return; - } - - 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 ) ); - SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn ); - - if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */ - /* Decode all parameter indices for the whole packet*/ - SKP_Silk_decode_indices_v4( &sDec ); - - /* 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_v4( &sDec, &sDecCtrl, 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 ) ); - } - } - } else { /* Silk_v3 payload */ - while(1) { - SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 ); - - if( sDec.sRC.error ) { - /* Corrupt stream */ - *nLBRRBytes = 0; - return; - }; - - if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) { - /* The wanted FEC is present in the packet */ - *nLBRRBytes = sDec.nBytesLeft; - SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) ); - break; - } - if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) { - sDec.nFramesDecoded++; - } else { - LBRRData = NULL; - *nLBRRBytes = 0; - break; - } - } - } -} - -/* Getting type of content for a packet */ -void SKP_Silk_SDK_get_TOC( - void *decState, /* I/O: Decoder state, to select bitstream version only */ - const SKP_uint8 *inData, /* I: Encoded input vector */ - const SKP_int16 nBytesIn, /* I: Number of input bytes */ - SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */ -) -{ - SKP_Silk_decoder_state *psDec; - 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 ]; - - psDec = (SKP_Silk_decoder_state *)decState; - - sDec.nFramesDecoded = 0; - sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */ - SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn ); - - if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */ - /* Decode all parameter indices for the whole packet*/ - SKP_Silk_decode_indices_v4( &sDec ); - - if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.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_LAST_FRAME ) { - Silk_TOC->inbandLBRR = sDec.FrameTermination; - } else { - Silk_TOC->inbandLBRR = sDec.FrameTermination - 1; - } - /* Copy data */ - for( i = 0; i < sDec.nFramesInPacket; i++ ) { - Silk_TOC->vadFlags[ i ] = sDec.vadFlagBuf[ i ]; - Silk_TOC->sigtypeFlags[ i ] = sDec.sigtype[ i ]; - } - } - } else { /* Silk_v3 payload */ - Silk_TOC->corrupt = 0; - while( 1 ) { - SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 ); - - Silk_TOC->vadFlags[ sDec.nFramesDecoded ] = sDec.vadFlag; - Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype; - - if( sDec.sRC.error ) { - /* Corrupt stream */ - Silk_TOC->corrupt = 1; - break; - }; - - if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) { - sDec.nFramesDecoded++; - } else { - break; - } - } - if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES || - sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) { - /* Corrupt packet */ - SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) ); - Silk_TOC->corrupt = 1; - } else { - Silk_TOC->framesInPacket = sDec.nFramesDecoded; - Silk_TOC->fs_kHz = sDec.fs_kHz; - if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) { - Silk_TOC->inbandLBRR = sDec.FrameTermination; - } else { - Silk_TOC->inbandLBRR = sDec.FrameTermination - 1; - } - } - } -} - -/**************************/ -/* Get the version number */ -/**************************/ -/* Return a pointer to string specifying the version */ -const char *SKP_Silk_SDK_get_version() -{ - static const char version[] = "1.0.2"; - return version; -} diff --git a/src/SKP_Silk_decode_parameters.c b/src/SKP_Silk_decode_parameters.c deleted file mode 100644 index d58539591..000000000 --- a/src/SKP_Silk_decode_parameters.c +++ /dev/null @@ -1,243 +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. -***********************************************************************/ - -#include "SKP_Silk_main.h" - -/* 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 */ - SKP_int q[], /* O Excitation signal */ - const SKP_int fullDecoding /* I Flag to tell if only arithmetic decoding */ -) -{ - SKP_int i, k, Ix, fs_kHz_dec, nBytesUsed; - SKP_int Ixs[ NB_SUBFR ]; - SKP_int GainsIndices[ NB_SUBFR ]; - SKP_int NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ]; - SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ]; - const SKP_int16 *cbk_ptr_Q14; - const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL; - SKP_Silk_range_coder_state *psRC = &psDec->sRC; - - /************************/ - /* Decode sampling rate */ - /************************/ - /* only done for first frame of packet */ - if( psDec->nFramesDecoded == 0 ) { - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset ); - - /* check that sampling rate is supported */ - if( Ix < 0 || Ix > 3 ) { - psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE; - return; - } - fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ]; - SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec ); - } - - /*******************************************/ - /* Decode signal type and quantizer offset */ - /*******************************************/ - if( psDec->nFramesDecoded == 0 ) { - /* first frame in packet: independent coding */ - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset ); - } else { - /* condidtional coding */ - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], - SKP_Silk_type_offset_CDF_offset ); - } - psDecCtrl->sigtype = SKP_RSHIFT( Ix, 1 ); - psDecCtrl->QuantOffsetType = Ix & 1; - psDec->typeOffsetPrev = Ix; - - /****************/ - /* Decode gains */ - /****************/ - /* first subframe */ - if( psDec->nFramesDecoded == 0 ) { - /* first frame in packet: independent coding */ - SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_gain_CDF[ psDecCtrl->sigtype ], SKP_Silk_gain_CDF_offset ); - } else { - /* condidtional coding */ - SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset ); - } - - /* remaining subframes */ - for( i = 1; i < NB_SUBFR; i++ ) { - SKP_Silk_range_decoder( &GainsIndices[ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset ); - } - - /* Dequant Gains */ - SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, GainsIndices, &psDec->LastGainIndex, psDec->nFramesDecoded ); - /****************/ - /* Decode NLSFs */ - /****************/ - /* Set pointer to NLSF VQ CB for the current signal type */ - psNLSF_CB = psDec->psNLSF_CB[ psDecCtrl->sigtype ]; - - /* Arithmetically decode NLSF path */ - SKP_Silk_range_decoder_multi( NLSFIndices, psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages ); - - /* From the NLSF path, decode an NLSF vector */ - SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, psDec->LPC_order ); - - /************************************/ - /* Decode NLSF interpolation factor */ - /************************************/ - SKP_Silk_range_decoder( &psDecCtrl->NLSFInterpCoef_Q2, psRC, SKP_Silk_NLSF_interpolation_factor_CDF, - SKP_Silk_NLSF_interpolation_factor_offset ); - - /* 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; - } - - if( fullDecoding ) { - /* Convert NLSF parameters to AR prediction filter coefficients */ - SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order ); - - if( psDecCtrl->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, - ( pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ) ), 2 ); - } - - /* Convert NLSF parameters to AR prediction filter coefficients */ - SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order ); - } else { - /* Copy LPC coefficients for first half from second half */ - SKP_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], - psDec->LPC_order * sizeof( SKP_int16 ) ); - } - } - - SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int ) ); - - /* After a packet loss do BWE of LPC coefs */ - if( psDec->lossCnt ) { - SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); - SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); - } - - if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) { - /*********************/ - /* Decode pitch lags */ - /*********************/ - /* Get lag index */ - if( psDec->fs_kHz == 8 ) { - SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_NB_CDF, SKP_Silk_pitch_lag_NB_CDF_offset ); - } else if( psDec->fs_kHz == 12 ) { - SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_MB_CDF, SKP_Silk_pitch_lag_MB_CDF_offset ); - } else if( psDec->fs_kHz == 16 ) { - SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_WB_CDF, SKP_Silk_pitch_lag_WB_CDF_offset ); - } else { - SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset ); - } - - /* Get countour index */ - if( psDec->fs_kHz == 8 ) { - /* Less codevectors used in 8 khz mode */ - SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset ); - } else { - /* Joint for 12, 16, and 24 khz */ - SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset ); - } - - /* Decode pitch values */ - SKP_Silk_decode_pitch( Ixs[ 0 ], Ixs[ 1 ], psDecCtrl->pitchL, psDec->fs_kHz ); - - /********************/ - /* Decode LTP gains */ - /********************/ - /* Decode PERIndex value */ - SKP_Silk_range_decoder( &psDecCtrl->PERIndex, psRC, SKP_Silk_LTP_per_index_CDF, - SKP_Silk_LTP_per_index_CDF_offset ); - - /* Decode Codebook Index */ - cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; // set pointer to start of codebook - - for( k = 0; k < NB_SUBFR; k++ ) { - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDecCtrl->PERIndex ], - SKP_Silk_LTP_gain_CDF_offsets[ psDecCtrl->PERIndex ] ); - - for( i = 0; i < LTP_ORDER; i++ ) { - psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( k, LTP_ORDER ) + i ] = cbk_ptr_Q14[ SKP_SMULBB( Ix, LTP_ORDER ) + i ]; - } - } - - /**********************/ - /* Decode LTP scaling */ - /**********************/ - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset ); - psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ]; - } else { - SKP_memset( psDecCtrl->pitchL, 0, NB_SUBFR * sizeof( SKP_int ) ); - SKP_memset( psDecCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) ); - psDecCtrl->PERIndex = 0; - psDecCtrl->LTP_scale_Q14 = 0; - } - - /***************/ - /* Decode seed */ - /***************/ - SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset ); - psDecCtrl->Seed = ( SKP_int32 )Ix; - /*********************************************/ - /* Decode quantization indices of excitation */ - /*********************************************/ - SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length ); - - /*********************************************/ - /* Decode VAD flag */ - /*********************************************/ - SKP_Silk_range_decoder( &psDec->vadFlag, psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset ); - - /**************************************/ - /* Decode Frame termination indicator */ - /**************************************/ - SKP_Silk_range_decoder( &psDec->FrameTermination, psRC, SKP_Silk_FrameTermination_CDF, SKP_Silk_FrameTermination_offset ); - - /****************************************/ - /* get number of bytes used so far */ - /****************************************/ - SKP_Silk_range_coder_get_length( psRC, &nBytesUsed ); - psDec->nBytesLeft = psRC->bufferLength - nBytesUsed; - if( psDec->nBytesLeft < 0 ) { - psRC->error = RANGE_CODER_READ_BEYOND_BUFFER; - } - - /****************************************/ - /* check remaining bits in last byte */ - /****************************************/ - if( psDec->nBytesLeft == 0 ) { - SKP_Silk_range_coder_check_after_decoding( psRC ); - } -} diff --git a/src/SKP_Silk_enc_API.c b/src/SKP_Silk_enc_API.c deleted file mode 100644 index 0bf6038cf..000000000 --- a/src/SKP_Silk_enc_API.c +++ /dev/null @@ -1,268 +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. -***********************************************************************/ - - -#include "SKP_Silk_define.h" -#include "SKP_Silk_main_FIX.h" -#include "SKP_Silk_SDK_API.h" -#include "SKP_Silk_control.h" -#include "SKP_Silk_typedef.h" -#include "SKP_Silk_structs.h" -#define SKP_Silk_EncodeControlStruct SKP_SILK_SDK_EncControlStruct - -/****************************************/ -/* Encoder functions */ -/****************************************/ - -SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int *encSizeBytes ) -{ - SKP_int ret = 0; - - *encSizeBytes = sizeof( SKP_Silk_encoder_state_FIX ); - - return ret; -} - - -/***************************************/ -/* Read control structure from encoder */ -/***************************************/ -SKP_int SKP_Silk_SDK_QueryEncoder( - const void *encState, /* I: State Vector */ - SKP_Silk_EncodeControlStruct *encStatus /* O: Control Structure */ -) -{ - SKP_Silk_encoder_state_FIX *psEnc; - SKP_int ret = 0; - - psEnc = ( SKP_Silk_encoder_state_FIX* )encState; - - encStatus->sampleRate = ( unsigned short )SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ); /* convert kHz -> Hz */ - encStatus->packetSize = ( unsigned short )SKP_SMULBB( psEnc->sCmn.fs_kHz, psEnc->sCmn.PacketSize_ms ); /* convert samples -> ms */ - encStatus->bitRate = ( unsigned short )psEnc->sCmn.TargetRate_bps; - encStatus->packetLossPercentage = psEnc->sCmn.PacketLoss_perc; - encStatus->complexity = psEnc->sCmn.Complexity; - - return ret; -} - -/*************************/ -/* Init or Reset encoder */ -/*************************/ -SKP_int SKP_Silk_SDK_InitEncoder( - void *encState, /* I/O: State */ - SKP_Silk_EncodeControlStruct *encStatus /* O: Control structure */ -) -{ - SKP_Silk_encoder_state_FIX *psEnc; - SKP_int ret = 0; - - - psEnc = ( SKP_Silk_encoder_state_FIX* )encState; - - /* Reset Encoder */ - if( ret += SKP_Silk_init_encoder_FIX( psEnc ) ) { - SKP_assert( 0 ); - } - - /* Read Control structure */ - if( ret += SKP_Silk_SDK_QueryEncoder( encState, encStatus ) ) { - SKP_assert( 0 ); - } - - - return ret; -} - -/**************************/ -/* Encode frame with Silk */ -/**************************/ -SKP_int SKP_Silk_SDK_Encode( - void *encState, /* I/O: State */ - const SKP_Silk_EncodeControlStruct *encControl, /* I: Control structure */ - const SKP_int16 *samplesIn, /* I: Speech sample input vector */ - SKP_int nSamplesIn, /* I: Number of samples in input vector */ - SKP_uint8 *outData, /* O: Encoded output vector */ - SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */ -) -{ - SKP_int API_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFec, UseDTX, ret = 0; - SKP_int nSamplesToBuffer, Complexity, input_ms, nSamplesFromInput = 0; - SKP_int32 TargetRate_bps; - SKP_int16 MaxBytesOut; - SKP_Silk_encoder_state_FIX *psEnc = ( SKP_Silk_encoder_state_FIX* )encState; - - - SKP_assert( encControl != NULL ); - - /* Check sampling frequency first, to avoid divide by zero later */ - if( ( encControl->sampleRate != 8000 ) && ( encControl->sampleRate != 12000 ) && - ( encControl->sampleRate != 16000 ) && ( encControl->sampleRate != 24000 ) ) { - ret = SKP_SILK_ENC_FS_NOT_SUPPORTED; - SKP_assert( 0 ); - return( ret ); - } - - /* Set Encoder parameters from Control structure */ - API_fs_kHz = SKP_DIV32_16( ( SKP_int )encControl->sampleRate, 1000 ); /* convert Hz -> kHz */ - PacketSize_ms = SKP_DIV32_16( ( SKP_int )encControl->packetSize, API_fs_kHz ); /* convert samples -> ms */ - TargetRate_bps = ( SKP_int32 )encControl->bitRate; - PacketLoss_perc = ( SKP_int )encControl->packetLossPercentage; - UseInBandFec = ( SKP_int )encControl->useInBandFEC; - Complexity = ( SKP_int )encControl->complexity; - UseDTX = ( SKP_int )encControl->useDTX; - - /* Only accept input lengths that are multiplum of 10 ms */ - input_ms = SKP_DIV32_16( nSamplesIn, API_fs_kHz ); - if( ( input_ms % 10) != 0 || nSamplesIn < 0 ) { - ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; - SKP_assert( 0 ); - return( ret ); - } - - /* Make sure no more than one packet can be produced */ - if( nSamplesIn > SKP_SMULBB( psEnc->sCmn.PacketSize_ms, API_fs_kHz ) ) { - ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; - SKP_assert( 0 ); - return( ret ); - } - - if( ( ret = SKP_Silk_control_encoder_FIX( psEnc, API_fs_kHz, PacketSize_ms, TargetRate_bps, - PacketLoss_perc, UseInBandFec, UseDTX, input_ms, Complexity ) ) != 0 ) { - SKP_assert( 0 ); - return( ret ); - } - - /* Detect energy above 8 kHz */ - if( encControl->sampleRate == 24000 && psEnc->sCmn.sSWBdetect.SWB_detected == 0 && psEnc->sCmn.sSWBdetect.WB_detected == 0 ) { - SKP_Silk_detect_SWB_input( &psEnc->sCmn.sSWBdetect, samplesIn, ( SKP_int )nSamplesIn ); - } - - /* Input buffering/resampling and encoding */ - MaxBytesOut = 0; /* return 0 output bytes if no encoder called */ - while( 1 ) { - /* Resample/buffer */ - nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx; - if( encControl->sampleRate == SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) ) { - /* Same sample frequency - copy the data */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, nSamplesIn ); - nSamplesFromInput = nSamplesToBuffer; - SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, SKP_SMULBB( nSamplesToBuffer, sizeof( SKP_int16 ) ) ); - } else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 16 ) { - /* Resample the data from 24 kHz to 16 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_SMULWB( SKP_LSHIFT( nSamplesIn, 1 ), 21846 ) ); // 21846 = ceil(2/3)*2^15 - nSamplesFromInput = SKP_RSHIFT( SKP_SMULBB( nSamplesToBuffer, 3 ), 1 ); -#if LOW_COMPLEXITY_ONLY - { - SKP_int16 scratch[ MAX_FRAME_LENGTH + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; - SKP_assert( nSamplesFromInput <= MAX_FRAME_LENGTH ); - SKP_Silk_resample_2_3_coarse( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To16state, - samplesIn, nSamplesFromInput, scratch ); - } -#else - SKP_Silk_resample_2_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To16state, - samplesIn, nSamplesFromInput ); -#endif - } else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 12 ) { - SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ]; - /* Resample the data from 24 kHz to 12 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( nSamplesIn, 1 ) ); - nSamplesFromInput = SKP_LSHIFT16( nSamplesToBuffer, 1 ); - SKP_Silk_resample_1_2_coarse( samplesIn, psEnc->sCmn.resample24To12state, - &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], scratch, nSamplesToBuffer ); - } else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 8 ) { - /* Resample the data from 24 kHz to 8 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_DIV32_16( nSamplesIn, 3 ) ); - nSamplesFromInput = SKP_SMULBB( nSamplesToBuffer, 3 ); - SKP_Silk_resample_1_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To8state, - samplesIn, nSamplesFromInput); - } else if( encControl->sampleRate == 16000 && psEnc->sCmn.fs_kHz == 12 ) { - /* Resample the data from 16 kHz to 12 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( SKP_SMULBB( nSamplesIn, 3 ), 2 ) ); - nSamplesFromInput = SKP_SMULWB( SKP_LSHIFT16( nSamplesToBuffer, 2 ), 21846 ); // 21846 = ceil((1/3)*2^16) - SKP_Silk_resample_3_4( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample16To12state, - samplesIn, nSamplesFromInput ); - } else if( encControl->sampleRate == 16000 && psEnc->sCmn.fs_kHz == 8 ) { - SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ]; - /* Resample the data from 16 kHz to 8 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( nSamplesIn, 1 ) ); - nSamplesFromInput = SKP_LSHIFT16( nSamplesToBuffer, 1 ); - SKP_Silk_resample_1_2_coarse( samplesIn, psEnc->sCmn.resample16To8state, - &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], scratch, nSamplesToBuffer ); - } else if( encControl->sampleRate == 12000 && psEnc->sCmn.fs_kHz == 8 ) { - /* Resample the data from 12 kHz to 8 kHz */ - nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_SMULWB( SKP_LSHIFT( nSamplesIn, 1 ), 21846 ) ); - nSamplesFromInput = SKP_RSHIFT( SKP_SMULBB( nSamplesToBuffer, 3 ), 1 ); -#if LOW_COMPLEXITY_ONLY - { - SKP_int16 scratch[ MAX_FRAME_LENGTH + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; - SKP_assert( nSamplesFromInput <= MAX_FRAME_LENGTH ); - SKP_Silk_resample_2_3_coarse( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample12To8state, - samplesIn, nSamplesFromInput, scratch ); - } -#else - SKP_Silk_resample_2_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample12To8state, - samplesIn, nSamplesFromInput ); -#endif - } - samplesIn += nSamplesFromInput; - nSamplesIn -= nSamplesFromInput; - psEnc->sCmn.inputBufIx += nSamplesToBuffer; - - /* Silk encoder */ - if( 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_FIX( psEnc, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) { - SKP_assert( 0 ); - } - } else { - /* outData already contains a payload */ - if( ( ret = SKP_Silk_encode_frame_FIX( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) { - SKP_assert( 0 ); - } - /* Check that no second payload was created */ - SKP_assert( *nBytesOut == 0 ); - } - psEnc->sCmn.inputBufIx = 0; - } else { - break; - } - } - - *nBytesOut = MaxBytesOut; - if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) { - /* Dtx simulation */ - *nBytesOut = 0; - } - - - return ret; -} - diff --git a/src/SKP_Silk_encode_parameters.c b/src/SKP_Silk_encode_parameters.c deleted file mode 100644 index 4af3551f5..000000000 --- a/src/SKP_Silk_encode_parameters.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. -***********************************************************************/ - -#include "SKP_Silk_main.h" - -/*******************************************/ -/* Encode parameters to create the payload */ -/*******************************************/ -void SKP_Silk_encode_parameters( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ - SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */ - SKP_Silk_range_coder_state *psRC, /* I/O Range encoder state */ - const SKP_int *q /* I Quantization indices */ -) -{ - SKP_int i, k, typeOffset; - const SKP_Silk_NLSF_CB_struct *psNLSF_CB; - - - /************************/ - /* Encode sampling rate */ - /************************/ - /* only done for first frame in packet */ - if( psEncC->nFramesInPayloadBuf == 0 ) { - - /* Initialize arithmetic coder */ - SKP_Silk_range_enc_init( &psEncC->sRC ); - psEncC->nBytesInPayloadBuf = 0; - - /* get sampling rate index */ - for( i = 0; i < 3; i++ ) { - if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) { - break; - } - } - SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF ); - } - - /*******************************************/ - /* Encode signal type and quantizer offset */ - /*******************************************/ - typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType; - if( psEncC->nFramesInPayloadBuf == 0 ) { - /* first frame in packet: independent coding */ - SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF ); - } else { - /* condidtional coding */ - SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] ); - } - psEncC->typeOffsetPrev = typeOffset; - - /****************/ - /* Encode gains */ - /****************/ - /* first subframe */ - if( psEncC->nFramesInPayloadBuf == 0 ) { - /* first frame in packet: independent coding */ - SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] ); - } else { - /* condidtional coding */ - SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF ); - } - - /* remaining subframes */ - for( i = 1; i < NB_SUBFR; i++ ) { - SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF ); - } - - - /****************/ - /* Encode NLSFs */ - /****************/ - /* Range encoding of the NLSF path */ - psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ]; - SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages ); - - /* Encode NLSF interpolation factor */ - SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) ); - SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF ); - - - if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) { - /*********************/ - /* Encode pitch lags */ - /*********************/ - - - /* lag index */ - if( psEncC->fs_kHz == 8 ) { - SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF ); - } else if( psEncC->fs_kHz == 12 ) { - SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF ); - } else if( psEncC->fs_kHz == 16 ) { - SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF ); - } else { - SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF ); - } - - - /* countour index */ - if( psEncC->fs_kHz == 8 ) { - /* Less codevectors used in 8 khz mode */ - SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF ); - } else { - /* Joint for 12, 16, 24 khz */ - SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF ); - } - - /********************/ - /* Encode LTP gains */ - /********************/ - - /* PERIndex value */ - SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF ); - - /* Codebook Indices */ - for( k = 0; k < NB_SUBFR; k++ ) { - SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] ); - } - - /**********************/ - /* Encode LTP scaling */ - /**********************/ - SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF ); - } - - - /***************/ - /* Encode seed */ - /***************/ - SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF ); - - /*********************************************/ - /* Encode quantization indices of excitation */ - /*********************************************/ - SKP_Silk_encode_pulses( psRC, psEncCtrlC->sigtype, psEncCtrlC->QuantOffsetType, q, psEncC->frame_length ); - - - /*********************************************/ - /* Encode VAD flag */ - /*********************************************/ - SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF ); -} diff --git a/src/SKP_Silk_find_pred_coefs_FIX.c b/src/SKP_Silk_find_pred_coefs_FIX.c deleted file mode 100644 index 57b091ed9..000000000 --- a/src/SKP_Silk_find_pred_coefs_FIX.c +++ /dev/null @@ -1,148 +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. -***********************************************************************/ - -#include "SKP_Silk_main_FIX.h" - - -#define VARQ 1 // EXPERIMENTAL -#define Qx 0 // EXPERIMENTAL - -void SKP_Silk_find_pred_coefs_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */ - SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ - const SKP_int16 res_pitch[] /* I Residual from pitch analysis */ -) -{ - SKP_int i; - SKP_int32 WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ]; - SKP_int32 invGains_Q16[ NB_SUBFR ], local_gains_Qx[ NB_SUBFR ], Wght_Q15[ NB_SUBFR ]; - SKP_int NLSF_Q15[ MAX_LPC_ORDER ]; - const SKP_int16 *x_ptr; - SKP_int16 *x_pre_ptr, LPC_in_pre[ NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ]; - - SKP_int32 tmp, min_gain_Q16; -#if !VARQ - SKP_int LZ; -#endif - SKP_int LTP_corrs_rshift[ NB_SUBFR ]; - - - /* weighting for weighted least squares */ - min_gain_Q16 = SKP_int32_MAX >> 6; - for( i = 0; i < NB_SUBFR; i++ ) { - min_gain_Q16 = SKP_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] ); - } -#if !VARQ - LZ = SKP_Silk_CLZ32( min_gain_Q16 ) - 1; - LZ = SKP_LIMIT( LZ, 0, 16 ); - min_gain_Q16 = SKP_RSHIFT( min_gain_Q16, 2 ); /* Ensure that maximum invGains_Q16 is within range of a 16 bit int */ -#endif - for( i = 0; i < NB_SUBFR; i++ ) { - /* Divide to Q16 */ - SKP_assert( psEncCtrl->Gains_Q16[ i ] > 0 ); -#if VARQ - /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */ - invGains_Q16[ i ] = SKP_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 ); -#else - invGains_Q16[ i ] = SKP_DIV32( SKP_LSHIFT( min_gain_Q16, LZ ), SKP_RSHIFT( psEncCtrl->Gains_Q16[ i ], 16 - LZ ) ); -#endif - - /* Ensure Wght_Q15 a minimum value 1 */ - invGains_Q16[ i ] = SKP_max( invGains_Q16[ i ], 363 ); - - /* Square the inverted gains */ - SKP_assert( invGains_Q16[ i ] == SKP_SAT16( invGains_Q16[ i ] ) ); - tmp = SKP_SMULWB( invGains_Q16[ i ], invGains_Q16[ i ] ); - Wght_Q15[ i ] = SKP_RSHIFT( tmp, 1 ); - - /* Invert the inverted and normalized gains */ - local_gains_Qx[ i ] = SKP_DIV32( ( 1 << ( 16 + Qx ) ), invGains_Q16[ i ] ); - } - - if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { - /**********/ - /* VOICED */ - /**********/ - SKP_assert( psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.pitchL[ 0 ] + LTP_ORDER / 2 ); - - /* LTP analysis */ - SKP_Silk_find_LTP_FIX( psEncCtrl->LTPCoef_Q14, WLTP, &psEncCtrl->LTPredCodGain_Q7, res_pitch, - res_pitch + SKP_RSHIFT( psEnc->sCmn.frame_length, 1 ), psEncCtrl->sCmn.pitchL, Wght_Q15, - psEnc->sCmn.subfr_length, psEnc->sCmn.frame_length, LTP_corrs_rshift ); - - - /* Quantize LTP gain parameters */ - SKP_Silk_quant_LTP_gains_FIX( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, - WLTP, psEnc->mu_LTP_Q8, psEnc->sCmn.LTPQuantLowComplexity ); - - /* Control LTP scaling */ - SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl ); - - /* Create LTP residual */ - SKP_Silk_LTP_analysis_filter_FIX( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder, - psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, 16, psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder ); - - } else { - /************/ - /* UNVOICED */ - /************/ - /* Create signal with prepended subframes, scaled by inverse gains */ - x_ptr = psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder; - x_pre_ptr = LPC_in_pre; - for( i = 0; i < NB_SUBFR; i++ ) { - SKP_Silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ], - psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); - x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder; - x_ptr += psEnc->sCmn.subfr_length; - } - - SKP_memset( psEncCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) ); - psEncCtrl->LTPredCodGain_Q7 = 0; - } - - /* 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, - psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder, - LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); - TOC(FIND_LPC) - - - /* Quantize LSFs */ - TIC(PROCESS_LSFS) - SKP_Silk_process_NLSFs_FIX( psEnc, psEncCtrl, NLSF_Q15 ); - TOC(PROCESS_LSFS) - - /* Calculate residual energy using quantized LPC coefficients */ - SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains_Qx, Qx, - psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder ); - - /* 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 ) ); - -} - diff --git a/src/SKP_Silk_macros.h b/src/SKP_Silk_macros.h deleted file mode 100644 index c42aa76e1..000000000 --- a/src/SKP_Silk_macros.h +++ /dev/null @@ -1,122 +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_API_C_H_ -#define _SKP_SILK_API_C_H_ - -// This is an inline header file for general platform. - -// (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int -#define SKP_SMULWB(a32, b32) ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16)) - -// a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int -#define SKP_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16))) - -// (a32 * (b32 >> 16)) >> 16 -#define SKP_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16)) - -// a32 + (b32 * (c32 >> 16)) >> 16 -#define SKP_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16)) - -// (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int -#define SKP_SMULBB(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32))) - -// a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int -#define SKP_SMLABB(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32))) - -// (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16) -#define SKP_SMULBT(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16)) - -// a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16) -#define SKP_SMLABT(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16)) - -// a64 + (b32 * c32) -#define SKP_SMLAL(a64, b32, c32) (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32)))) - -// (a32 * b32) >> 16 -#define SKP_SMULWW(a32, b32) SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16)) - -// a32 + ((b32 * c32) >> 16) -#define SKP_SMLAWW(a32, b32, c32) SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16)) - -/* add/subtract with output saturated */ -#define SKP_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \ - ((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) : \ - ((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) ) - -#define SKP_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \ - (( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) : \ - ((((a)^0x80000000) & (b) & 0x80000000) ? SKP_int32_MAX : (a)-(b)) ) - -SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16) -{ - SKP_int32 out32 = 0; - if( in16 == 0 ) { - return 16; - } - /* test nibbles */ - if( in16 & 0xFF00 ) { - if( in16 & 0xF000 ) { - in16 >>= 12; - } else { - out32 += 4; - in16 >>= 8; - } - } else { - if( in16 & 0xFFF0 ) { - out32 += 8; - in16 >>= 4; - } else { - out32 += 12; - } - } - /* test bits and return */ - if( in16 & 0xC ) { - if( in16 & 0x8 ) - return out32 + 0; - else - return out32 + 1; - } else { - if( in16 & 0xE ) - return out32 + 2; - else - return out32 + 3; - } -} - -SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32) -{ - /* test highest 16 bits and convert to SKP_int16 */ - if( in32 & 0xFFFF0000 ) { - return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16)); - } else { - return SKP_Silk_CLZ16((SKP_int16)in32) + 16; - } -} - -#endif //_SKP_SILK_API_C_H_ - diff --git a/src/SKP_Silk_range_coder.c b/src/SKP_Silk_range_coder.c deleted file mode 100644 index b42fa42ec..000000000 --- a/src/SKP_Silk_range_coder.c +++ /dev/null @@ -1,372 +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. -***********************************************************************/ - -#include "SKP_Silk_main.h" - -/* Range encoder for one symbol */ -void SKP_Silk_range_encoder( - SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ - const SKP_int data, /* I uncompressed data */ - const SKP_uint16 prob[] /* I cumulative density functions */ -) -{ - SKP_uint32 low_Q16, high_Q16; - SKP_uint32 base_tmp, range_Q32; - - /* Copy structure data */ - SKP_uint32 base_Q32 = psRC->base_Q32; - SKP_uint32 range_Q16 = psRC->range_Q16; - SKP_int32 bufferIx = psRC->bufferIx; - SKP_uint8 *buffer = psRC->buffer; - - if( psRC->error ) { - return; - } - - /* Update interval */ - low_Q16 = prob[ data ]; - high_Q16 = prob[ data + 1 ]; - base_tmp = base_Q32; /* save current base, to test for carry */ - base_Q32 += SKP_MUL_uint( range_Q16, low_Q16 ); - range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 ); - - /* Check for carry */ - if( base_Q32 < base_tmp ) { - /* Propagate carry in buffer */ - SKP_int bufferIx_tmp = bufferIx; - while( ( ++buffer[ --bufferIx_tmp ] ) == 0 ); - } - - /* Check normalization */ - if( range_Q32 & 0xFF000000 ) { - /* No normalization */ - range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 ); - } else { - if( range_Q32 & 0xFFFF0000 ) { - /* Normalization of 8 bits shift */ - range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 ); - } else { - /* Normalization of 16 bits shift */ - range_Q16 = range_Q32; - /* Make sure not to write beyond buffer */ - if( bufferIx >= psRC->bufferLength ) { - psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER; - return; - } - /* Write one byte to buffer */ - buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) ); - base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 ); - } - /* Make sure not to write beyond buffer */ - if( bufferIx >= psRC->bufferLength ) { - psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER; - return; - } - /* Write one byte to buffer */ - buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) ); - base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 ); - } - - /* Copy structure data back */ - psRC->base_Q32 = base_Q32; - psRC->range_Q16 = range_Q16; - psRC->bufferIx = bufferIx; -} - -/* Range encoder for multiple symbols */ -void SKP_Silk_range_encoder_multi( - SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ - const SKP_int data[], /* I uncompressed data [nSymbols] */ - const SKP_uint16 * const prob[], /* I cumulative density functions */ - const SKP_int nSymbols /* I number of data symbols */ -) -{ - SKP_int k; - for( k = 0; k < nSymbols; k++ ) { - SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] ); - } -} - -/* Range decoder for one symbol */ -void SKP_Silk_range_decoder( - SKP_int data[], /* O uncompressed data */ - SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ - const SKP_uint16 prob[], /* I cumulative density function */ - SKP_int probIx /* I initial (middle) entry of cdf */ -) -{ - SKP_uint32 low_Q16, high_Q16; - SKP_uint32 base_tmp, range_Q32; - - /* Copy structure data */ - SKP_uint32 base_Q32 = psRC->base_Q32; - SKP_uint32 range_Q16 = psRC->range_Q16; - SKP_int32 bufferIx = psRC->bufferIx; - SKP_uint8 *buffer = &psRC->buffer[ 4 ]; - - if( psRC->error ) { - /* Set output to zero */ - *data = 0; - return; - } - - high_Q16 = prob[ probIx ]; - base_tmp = SKP_MUL_uint( range_Q16, high_Q16 ); - if( base_tmp > base_Q32 ) { - while( 1 ) { - low_Q16 = prob[ --probIx ]; - base_tmp = SKP_MUL_uint( range_Q16, low_Q16 ); - if( base_tmp <= base_Q32 ) { - break; - } - high_Q16 = low_Q16; - /* Test for out of range */ - if( high_Q16 == 0 ) { - psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE; - /* Set output to zero */ - *data = 0; - return; - } - } - } else { - while( 1 ) { - low_Q16 = high_Q16; - high_Q16 = prob[ ++probIx ]; - base_tmp = SKP_MUL_uint( range_Q16, high_Q16 ); - if( base_tmp > base_Q32 ) { - probIx--; - break; - } - /* Test for out of range */ - if( high_Q16 == 0xFFFF ) { - psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE; - /* Set output to zero */ - *data = 0; - return; - } - } - } - *data = probIx; - base_Q32 -= SKP_MUL_uint( range_Q16, low_Q16 ); - range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 ); - - /* Check normalization */ - if( range_Q32 & 0xFF000000 ) { - /* No normalization */ - range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 ); - } else { - if( range_Q32 & 0xFFFF0000 ) { - /* Normalization of 8 bits shift */ - range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 ); - /* Check for errors */ - if( SKP_RSHIFT_uint( base_Q32, 24 ) ) { - psRC->error = RANGE_CODER_NORMALIZATION_FAILED; - /* Set output to zero */ - *data = 0; - return; - } - } else { - /* Normalization of 16 bits shift */ - range_Q16 = range_Q32; - /* Check for errors */ - if( SKP_RSHIFT( base_Q32, 16 ) ) { - psRC->error = RANGE_CODER_NORMALIZATION_FAILED; - /* Set output to zero */ - *data = 0; - return; - } - /* Update base */ - base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 ); - /* Make sure not to read beyond buffer */ - if( bufferIx < psRC->bufferLength ) { - /* Read one byte from buffer */ - base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ]; - } - } - /* Update base */ - base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 ); - /* Make sure not to read beyond buffer */ - if( bufferIx < psRC->bufferLength ) { - /* Read one byte from buffer */ - base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ]; - } - } - - /* Check for zero interval length */ - if( range_Q16 == 0 ) { - psRC->error = RANGE_CODER_ZERO_INTERVAL_WIDTH; - /* Set output to zero */ - *data = 0; - return; - } - - /* Copy structure data back */ - psRC->base_Q32 = base_Q32; - psRC->range_Q16 = range_Q16; - psRC->bufferIx = bufferIx; -} - -/* Range decoder for multiple symbols */ -void SKP_Silk_range_decoder_multi( - SKP_int data[], /* O uncompressed data [nSymbols] */ - SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ - const SKP_uint16 * const prob[], /* I cumulative density functions */ - const SKP_int probStartIx[], /* I initial (middle) entries of cdfs [nSymbols] */ - const SKP_int nSymbols /* I number of data symbols */ -) -{ - SKP_int k; - for( k = 0; k < nSymbols; k++ ) { - SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] ); - } -} - -/* Initialize range encoder */ -void SKP_Silk_range_enc_init( - SKP_Silk_range_coder_state *psRC /* O compressor data structure */ -) -{ - /* Initialize structure */ - psRC->bufferLength = MAX_ARITHM_BYTES; - psRC->range_Q16 = 0x0000FFFF; - psRC->bufferIx = 0; - psRC->base_Q32 = 0; - psRC->error = 0; -} - -/* Initialize range decoder */ -void SKP_Silk_range_dec_init( - SKP_Silk_range_coder_state *psRC, /* O compressor data structure */ - const SKP_uint8 buffer[], /* I buffer for compressed data [bufferLength] */ - const SKP_int32 bufferLength /* I buffer length (in bytes) */ -) -{ - /* check input */ - if( bufferLength > MAX_ARITHM_BYTES ) { - psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG; - return; - } - /* Initialize structure */ - /* Copy to internal buffer */ - SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); - psRC->bufferLength = bufferLength; - psRC->bufferIx = 0; - psRC->base_Q32 = - SKP_LSHIFT_uint( (SKP_uint32)buffer[ 0 ], 24 ) | - SKP_LSHIFT_uint( (SKP_uint32)buffer[ 1 ], 16 ) | - SKP_LSHIFT_uint( (SKP_uint32)buffer[ 2 ], 8 ) | - (SKP_uint32)buffer[ 3 ]; - psRC->range_Q16 = 0x0000FFFF; - psRC->error = 0; -} - -/* Determine length of bitstream */ -SKP_int SKP_Silk_range_coder_get_length( /* O returns number of BITS in stream */ - const SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ - SKP_int *nBytes /* O number of BYTES in stream */ -) -{ - SKP_int nBits; - - /* Number of additional bits (1..9) required to be stored to stream */ - nBits = SKP_LSHIFT( psRC->bufferIx, 3 ) + SKP_Silk_CLZ32( psRC->range_Q16 - 1 ) - 14; - - *nBytes = SKP_RSHIFT( nBits + 7, 3 ); - - /* Return number of bits in bitstream */ - return nBits; -} - -/* Write shortest uniquely decodable stream to buffer, and determine its length */ -void SKP_Silk_range_enc_wrap_up( - SKP_Silk_range_coder_state *psRC /* I/O compressed data structure */ -) -{ - SKP_int bufferIx_tmp, bits_to_store, bits_in_stream, nBytes, mask; - SKP_uint32 base_Q24; - - /* Lower limit of interval, shifted 8 bits to the right */ - base_Q24 = SKP_RSHIFT_uint( psRC->base_Q32, 8 ); - - bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes ); - - /* Number of additional bits (1..9) required to be stored to stream */ - bits_to_store = bits_in_stream - SKP_LSHIFT( psRC->bufferIx, 3 ); - /* Round up to required resolution */ - base_Q24 += SKP_RSHIFT_uint( 0x00800000, bits_to_store - 1 ); - base_Q24 &= SKP_LSHIFT_ovflw( 0xFFFFFFFF, 24 - bits_to_store ); - - /* Check for carry */ - if( base_Q24 & 0x01000000 ) { - /* Propagate carry in buffer */ - bufferIx_tmp = psRC->bufferIx; - while( ( ++( psRC->buffer[ --bufferIx_tmp ] ) ) == 0 ); - } - - /* Store to stream, making sure not to write beyond buffer */ - if( psRC->bufferIx < psRC->bufferLength ) { - psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 16 ); - if( bits_to_store > 8 ) { - if( psRC->bufferIx < psRC->bufferLength ) { - psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 8 ); - } - } - } - - /* 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 < psRC->bufferLength ) { - psRC->buffer[ nBytes - 1 ] |= mask; - } - } -} - -/* Check that any remaining bits in the last byte are set to 1 */ -void SKP_Silk_range_coder_check_after_decoding( - SKP_Silk_range_coder_state *psRC /* I/O compressed data structure */ -) -{ - SKP_int bits_in_stream, nBytes, mask; - - bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes ); - - /* Make sure not to read beyond buffer */ - if( nBytes - 1 >= psRC->bufferLength ) { - psRC->error = RANGE_CODER_DECODER_CHECK_FAILED; - return; - } - - /* Test any remaining bits in last byte */ - if( bits_in_stream & 7 ) { - mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 ); - if( ( psRC->buffer[ nBytes - 1 ] & mask ) != mask ) { - psRC->error = RANGE_CODER_DECODER_CHECK_FAILED; - return; - } - } -} diff --git a/src/SKP_Silk_resample_1_3.c b/src/SKP_Silk_resample_1_3.c deleted file mode 100644 index 0f77412c4..000000000 --- a/src/SKP_Silk_resample_1_3.c +++ /dev/null @@ -1,101 +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_resample_1_3.c * - * * - * Downsamples by a factor 3 * - * * - * Copyright 2008 (c), Skype Limited * - * Date: 081113 * - * */ -#include "SKP_Silk_SigProc_FIX.h" - -#define OUT_SUBFR_LEN 80 - -/* Downsamples by a factor 3 */ -void SKP_Silk_resample_1_3( - SKP_int16 *out, /* O: Fs_low signal [inLen/3] */ - SKP_int32 *S, /* I/O: State vector [7] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int32 inLen /* I: Input length, must be a multiple of 3 */ -) -{ - SKP_int k, outLen, LSubFrameIn, LSubFrameOut; - SKP_int32 out_tmp, limit = 102258000; // (102258000 + 1560) * 21 * 2^(-16) = 32767.5 - SKP_int32 scratch0[ 3 * OUT_SUBFR_LEN ]; - SKP_int32 scratch10[ OUT_SUBFR_LEN ], scratch11[ OUT_SUBFR_LEN ], scratch12[ OUT_SUBFR_LEN ]; - /* coefficients for 3-fold resampling */ - const SKP_int16 A30[ 2 ] = { 1773, 17818 }; - const SKP_int16 A31[ 2 ] = { 4942, 25677 }; - const SKP_int16 A32[ 2 ] = { 11786, 29304 }; - - /* Check that input is multiple of 3 */ - SKP_assert( inLen % 3 == 0 ); - - outLen = SKP_DIV32_16( inLen, 3 ); - while( outLen > 0 ) { - LSubFrameOut = SKP_min_int( OUT_SUBFR_LEN, outLen ); - LSubFrameIn = SKP_SMULBB( 3, LSubFrameOut ); - - /* Low-pass filter, Q15 -> Q25 */ - SKP_Silk_lowpass_short( in, S, scratch0, LSubFrameIn ); - - /* De-interleave three allpass inputs */ - for( k = 0; k < LSubFrameOut; k++ ) { - scratch10[ k ] = scratch0[ 3 * k ]; - scratch11[ k ] = scratch0[ 3 * k + 1 ]; - scratch12[ k ] = scratch0[ 3 * k + 2 ]; - } - - /* Allpass filters */ - SKP_Silk_allpass_int( scratch10, S + 1, A32[ 0 ], scratch0, LSubFrameOut ); - SKP_Silk_allpass_int( scratch0, S + 2, A32[ 1 ], scratch10, LSubFrameOut ); - - SKP_Silk_allpass_int( scratch11, S + 3, A31[ 0 ], scratch0, LSubFrameOut ); - SKP_Silk_allpass_int( scratch0, S + 4, A31[ 1 ], scratch11, LSubFrameOut ); - - SKP_Silk_allpass_int( scratch12, S + 5, A30[ 0 ], scratch0, LSubFrameOut ); - SKP_Silk_allpass_int( scratch0, S + 6, A30[ 1 ], scratch12, LSubFrameOut ); - - /* Add three allpass outputs */ - for( k = 0; k < LSubFrameOut; k++ ) { - out_tmp = scratch10[ k ] + scratch11[ k ] + scratch12[ k ]; - if( out_tmp - limit > 0 ) { - out[ k ] = SKP_int16_MAX; - } else if( out_tmp + limit < 0 ) { - out[ k ] = SKP_int16_MIN; - } else { - out[ k ] = (SKP_int16) SKP_SMULWB( out_tmp + 1560, 21 ); - } - } - - in += LSubFrameIn; - out += LSubFrameOut; - outLen -= LSubFrameOut; - } -} diff --git a/src/SKP_Silk_resample_2_3_coarse.c b/src/SKP_Silk_resample_2_3_coarse.c deleted file mode 100644 index 76c597bb7..000000000 --- a/src/SKP_Silk_resample_2_3_coarse.c +++ /dev/null @@ -1,112 +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_resample_2_3_coarse.c * - * * - * Description: Linear phase FIR polyphase implementation of resampling * - * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090423 * - * */ - -#include "SKP_Silk_SigProc_FIX.h" -#include "SKP_Silk_resample_rom.h" - -/* Resamples input data with a factor 2/3 */ -void SKP_Silk_resample_2_3_coarse( - SKP_int16 *out, /* O: Output signal */ - SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */ - const SKP_int16 *in, /* I: Input signal */ - const SKP_int frameLenIn, /* I: Number of input samples */ - SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */ -) -{ - SKP_int32 n, ind, interpol_ind, tmp, index_Q16; - SKP_int16 *in_ptr; - SKP_int frameLenOut; - const SKP_int16 *interpol_ptr; - - /* Copy buffered samples to start of scratch */ - SKP_memcpy( scratch, S, ( SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) ); - - /* Then append by the input signal */ - SKP_memcpy( &scratch[ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ], in, frameLenIn * sizeof( SKP_int16 ) ); - - frameLenOut = SKP_DIV32_16( SKP_MUL( 2, frameLenIn ), 3 ); - index_Q16 = 0; - - SKP_assert( frameLenIn == ( ( frameLenOut * 3 ) / 2 ) ); - - /* Interpolate */ - for( n = frameLenOut; n > 0; n-- ) { - - /* Integer part */ - ind = SKP_RSHIFT( index_Q16, 16 ); - - /* Pointer to buffered input */ - in_ptr = scratch + ind; - - /* Fractional part */ - interpol_ind = ( SKP_SMULWB( index_Q16, SigProc_Resample_2_3_coarse_NUM_INTERPOLATORS ) & - ( SigProc_Resample_2_3_coarse_NUM_INTERPOLATORS - 1 ) ); - - /* Pointer to FIR taps */ - interpol_ptr = SigProc_Resample_2_3_coarse_INTERPOL[ interpol_ind ]; - - /* Interpolate */ - /* Hardcoded for 32 FIR taps */ - SKP_assert( SigProc_Resample_2_3_coarse_NUM_FIR_COEFS == 32 ); - tmp = (SKP_int32)interpol_ptr[ 0 ] * in_ptr[ 0 ] + (SKP_int32)interpol_ptr[ 1 ] * in_ptr[ 1 ] + - (SKP_int32)interpol_ptr[ 2 ] * in_ptr[ 2 ] + (SKP_int32)interpol_ptr[ 3 ] * in_ptr[ 3 ] + - (SKP_int32)interpol_ptr[ 4 ] * in_ptr[ 4 ] + (SKP_int32)interpol_ptr[ 5 ] * in_ptr[ 5 ] + - (SKP_int32)interpol_ptr[ 6 ] * in_ptr[ 6 ] + (SKP_int32)interpol_ptr[ 7 ] * in_ptr[ 7 ] + - (SKP_int32)interpol_ptr[ 8 ] * in_ptr[ 8 ] + (SKP_int32)interpol_ptr[ 9 ] * in_ptr[ 9 ] + - (SKP_int32)interpol_ptr[ 10 ] * in_ptr[ 10 ] + (SKP_int32)interpol_ptr[ 11 ] * in_ptr[ 11 ] + - (SKP_int32)interpol_ptr[ 12 ] * in_ptr[ 12 ] + (SKP_int32)interpol_ptr[ 13 ] * in_ptr[ 13 ] + - (SKP_int32)interpol_ptr[ 14 ] * in_ptr[ 14 ] + (SKP_int32)interpol_ptr[ 15 ] * in_ptr[ 15 ] + - (SKP_int32)interpol_ptr[ 16 ] * in_ptr[ 16 ] + (SKP_int32)interpol_ptr[ 17 ] * in_ptr[ 17 ] + - (SKP_int32)interpol_ptr[ 18 ] * in_ptr[ 18 ] + (SKP_int32)interpol_ptr[ 19 ] * in_ptr[ 19 ] + - (SKP_int32)interpol_ptr[ 20 ] * in_ptr[ 20 ] + (SKP_int32)interpol_ptr[ 21 ] * in_ptr[ 21 ] + - (SKP_int32)interpol_ptr[ 22 ] * in_ptr[ 22 ] + (SKP_int32)interpol_ptr[ 23 ] * in_ptr[ 23 ] + - (SKP_int32)interpol_ptr[ 24 ] * in_ptr[ 24 ] + (SKP_int32)interpol_ptr[ 25 ] * in_ptr[ 25 ] + - (SKP_int32)interpol_ptr[ 26 ] * in_ptr[ 26 ] + (SKP_int32)interpol_ptr[ 27 ] * in_ptr[ 27 ] + - (SKP_int32)interpol_ptr[ 28 ] * in_ptr[ 28 ] + (SKP_int32)interpol_ptr[ 29 ] * in_ptr[ 29 ]; - - /* Round, saturate and store to output array */ - *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( tmp, 15 ) ); - - /* Update index */ - index_Q16 += ( ( 1 << 16 ) + ( 1 << 15 ) ); // (3/2)_Q0; - } - - /* Move last part of input signal to the sample buffer to prepare for the next call */ - SKP_memcpy( S, &in[ frameLenIn - ( SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ) ], - ( SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) ); -} diff --git a/src/SKP_Silk_resample_2_3_coarsest.c b/src/SKP_Silk_resample_2_3_coarsest.c deleted file mode 100644 index 6a57eaa31..000000000 --- a/src/SKP_Silk_resample_2_3_coarsest.c +++ /dev/null @@ -1,131 +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_resample_2_3_coarsest.c * - * * - * Description: Linear phase FIR polyphase implementation of resampling * - * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090423 * - * */ - -#include "SKP_Silk_SigProc_FIX.h" -#include "SKP_Silk_resample_rom.h" - -/* Resamples input data with a factor 2/3 */ -void SKP_Silk_resample_2_3_coarsest( - SKP_int16 *out, /* O: Output signal */ - SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */ - const SKP_int16 *in, /* I: Input signal */ - const SKP_int frameLenIn, /* I: Number of input samples */ - SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */ -) -{ - SKP_int32 n, ind, interpol_ind, tmp, index_Q16; - SKP_int16 *in_ptr; - SKP_int frameLenOut; - const SKP_int16 *interpol_ptr; -#if ( EMBEDDED_ARM>=6 ) && defined (__GNUC__) - SKP_int32 in_val, interpol_val; -#endif - - /* Copy buffered samples to start of scratch */ - SKP_memcpy( scratch, S, ( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) ); - - /* Then append by the input signal */ - SKP_memcpy( &scratch[ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ], in, frameLenIn * sizeof( SKP_int16 ) ); - - frameLenOut = SKP_SMULWB( SKP_LSHIFT( (SKP_int32)frameLenIn, 1 ), 21846 ); // 21846_Q15 = (2/3)_Q0 rounded _up_ - index_Q16 = 0; - - SKP_assert( frameLenIn == ( ( frameLenOut * 3 ) / 2 ) ); - - /* Interpolate */ - for( n = frameLenOut; n > 0; n-- ) { - - /* Integer part */ - ind = SKP_RSHIFT( index_Q16, 16 ); - - /* Pointer to buffered input */ - in_ptr = scratch + ind; - - /* Fractional part */ - interpol_ind = ( SKP_SMULWB( index_Q16, SigProc_Resample_2_3_coarsest_NUM_INTERPOLATORS ) & - ( SigProc_Resample_2_3_coarsest_NUM_INTERPOLATORS - 1 ) ); - - /* Pointer to FIR taps */ - interpol_ptr = SigProc_Resample_2_3_coarsest_INTERPOL[ interpol_ind ]; - - /* Interpolate: Hardcoded for 10 FIR taps */ -#if ( EMBEDDED_ARM>=6 ) && defined (__GNUC__) /*It doesn't improve efficiency on iphone.*/ - /*tmp = SKP_SMUAD( *((SKP_int32 *)interpol_ptr)++, *((SKP_int32 *)in_ptr)++); - tmp = SKP_SMLAD( tmp, *((SKP_int32 *)interpol_ptr)++, *((SKP_int32 *)in_ptr)++); - tmp = SKP_SMLAD( tmp, *((SKP_int32 *)interpol_ptr), *((SKP_int32 *)in_ptr) );*/ - __asm__ __volatile__ ( "ldr %1, [%3], #4 \n\t" - "ldr %2, [%4], #4 \n\t" - "smuad %0, %1, %2 \n\t" - "ldr %1, [%3], #4 \n\t" - "ldr %2, [%4], #4 \n\t" - "smlad %0, %1, %2, %0\n\t" - "ldr %1, [%3], #4 \n\t" - "ldr %2, [%4], #4 \n\t" - "smlad %0, %1, %2, %0\n\t" - "ldr %1, [%3], #4 \n\t" - "ldr %2, [%4], #4 \n\t" - "smlad %0, %1, %2, %0\n\t" - "ldr %1, [%3] \n\t" - "ldr %2, [%4] \n\t" - "smlad %0, %1, %2, %0\n\t" - : "=r" (tmp), "=r" (interpol_val), "=r" (in_val), "=r" (interpol_ptr), "=r" (in_ptr) - : "3" (interpol_ptr), "4" (in_ptr)); -#else - SKP_assert( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS == 10 ); - tmp = SKP_SMULBB( interpol_ptr[ 0 ], in_ptr[ 0 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 1 ], in_ptr[ 1 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 2 ], in_ptr[ 2 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 3 ], in_ptr[ 3 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 4 ], in_ptr[ 4 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 5 ], in_ptr[ 5 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 6 ], in_ptr[ 6 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 7 ], in_ptr[ 7 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 8 ], in_ptr[ 8 ] ); - tmp = SKP_SMLABB( tmp, interpol_ptr[ 9 ], in_ptr[ 9 ] ); -#endif - /* Round, saturate and store to output array */ - *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( tmp, 15 ) ); - - /* Update index */ - index_Q16 += ( ( 1 << 16 ) + ( 1 << 15 ) ); // (3/2)_Q0; - } - - /* Move last part of input signal to the sample buffer to prepare for the next call */ - SKP_memcpy( S, &in[ frameLenIn - ( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ) ], - ( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) ); -} diff --git a/src/SKP_Silk_resample_3_1.c b/src/SKP_Silk_resample_3_1.c deleted file mode 100644 index 5272bb8d7..000000000 --- a/src/SKP_Silk_resample_3_1.c +++ /dev/null @@ -1,100 +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_resample_3_1.c * - * * - * Upsamples by a factor 3 * - * * - * Copyright 2008 (c), Skype Limited * - * Date: 081113 * - * */ -#include "SKP_Silk_SigProc_FIX.h" - -#define IN_SUBFR_LEN_RESAMPLE_3_1 40 - -/* Resamples by a factor 3/1 */ -void SKP_Silk_resample_3_1( - SKP_int16 *out, /* O: Fs_high signal [inLen*3] */ - SKP_int32 *S, /* I/O: State vector [7] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - const SKP_int32 inLen /* I: Input length */ -) -{ - SKP_int k, LSubFrameIn, LSubFrameOut; - SKP_int32 out_tmp, idx, inLenTmp = inLen; - SKP_int32 scratch00[ IN_SUBFR_LEN_RESAMPLE_3_1 ]; - SKP_int32 scratch0[ 3 * IN_SUBFR_LEN_RESAMPLE_3_1 ]; - SKP_int32 scratch1[ 3 * IN_SUBFR_LEN_RESAMPLE_3_1 ]; - - /* Coefficients for 3-fold resampling */ - const SKP_int16 A30[ 2 ] = { 1773, 17818 }; - const SKP_int16 A31[ 2 ] = { 4942, 25677 }; - const SKP_int16 A32[ 2 ] = { 11786, 29304 }; - - while( inLenTmp > 0 ) { - LSubFrameIn = SKP_min_int( IN_SUBFR_LEN_RESAMPLE_3_1, inLenTmp ); - LSubFrameOut = SKP_SMULBB( 3, LSubFrameIn ); - - /* Convert Q15 -> Q25 */ - for( k = 0; k < LSubFrameIn; k++ ) { - scratch00[k] = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); - } - - /* Allpass filtering */ - /* Scratch size: 2 * 3* LSubFrame * sizeof(SKP_int32) */ - SKP_Silk_allpass_int( scratch00, S + 1, A30[ 0 ], scratch1, LSubFrameIn ); - SKP_Silk_allpass_int( scratch1, S + 2, A30[ 1 ], scratch0, LSubFrameIn ); - - SKP_Silk_allpass_int( scratch00, S + 3, A31[ 0 ], scratch1, LSubFrameIn ); - SKP_Silk_allpass_int( scratch1, S + 4, A31[ 1 ], scratch0 + IN_SUBFR_LEN_RESAMPLE_3_1, LSubFrameIn ); - - SKP_Silk_allpass_int( scratch00, S + 5, A32[ 0 ], scratch1, LSubFrameIn ); - SKP_Silk_allpass_int( scratch1, S + 6, A32[ 1 ], scratch0 + 2 * IN_SUBFR_LEN_RESAMPLE_3_1, LSubFrameIn ); - - /* Interleave three allpass outputs */ - for( k = 0; k < LSubFrameIn; k++ ) { - idx = SKP_SMULBB( 3, k ); - scratch1[ idx ] = scratch0[ k ]; - scratch1[ idx + 1 ] = scratch0[ k + IN_SUBFR_LEN_RESAMPLE_3_1 ]; - scratch1[ idx + 2 ] = scratch0[ k + 2 * IN_SUBFR_LEN_RESAMPLE_3_1 ]; - } - - /* Low-pass filtering */ - SKP_Silk_lowpass_int( scratch1, S, scratch0, LSubFrameOut ); - - /* Saturate and convert to SKP_int16 */ - for( k = 0; k < LSubFrameOut; k++ ) { - out_tmp = scratch0[ k ]; - out[ k ] = (SKP_int16) SKP_SAT16( SKP_RSHIFT_ROUND( out_tmp, 10 ) ); - } - - in += LSubFrameIn; - inLenTmp -= LSubFrameIn; - out += LSubFrameOut; - } -} diff --git a/src/SKP_Silk_resample_3_4.c b/src/SKP_Silk_resample_3_4.c deleted file mode 100644 index 4b83a7a74..000000000 --- a/src/SKP_Silk_resample_3_4.c +++ /dev/null @@ -1,79 +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_resample_3_4.c * - * * - * Resamples by a factor 3/4 * - * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090408 * - * */ - -#include "SKP_Silk_SigProc_FIX.h" - -#define IN_SUBFR_LEN_RESAMPLE_3_4 80 - -/* Resamples by a factor 3/4 */ -void SKP_Silk_resample_3_4( - SKP_int16 *out, /* O: Fs_high signal [inLen*3/4] */ - SKP_int32 *S, /* I/O: State vector [7+2+6] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - SKP_int inLen /* I: Input length, must be a multiple of 4 */ -) -{ - SKP_int LSubFrameIn, LSubFrameOut; - SKP_int16 outH[ 3 * IN_SUBFR_LEN_RESAMPLE_3_4 ]; - SKP_int16 outL[ ( 3 * IN_SUBFR_LEN_RESAMPLE_3_4 ) / 2 ]; - SKP_int32 scratch[ ( 9 * IN_SUBFR_LEN_RESAMPLE_3_4 ) / 2 ]; - - /* Check that input is multiple of 4 */ - SKP_assert( inLen % 4 == 0 ); - - while( inLen > 0 ) { - LSubFrameIn = SKP_min_int( IN_SUBFR_LEN_RESAMPLE_3_4, inLen ); - LSubFrameOut = SKP_SMULWB( 49152, LSubFrameIn ); - - /* Upsample by a factor 3 */ - SKP_Silk_resample_3_1( outH, &S[ 0 ], in, LSubFrameIn ); - - /* Downsample by a factor 2 twice */ - /* Scratch size needs to be: 3 * 2 * LSubFrameOut * sizeof( SKP_int32 ) */ - /* I: state vector [2], scratch memory [3*len] */ - SKP_Silk_resample_1_2_coarsest( outH, &S[ 7 ], outL, scratch, SKP_LSHIFT( LSubFrameOut, 1 ) ); - - /* Scratch size needs to be: 3 * LSubFrameOut * sizeof( SKP_int32 ) */ - /* I: state vector [6], scratch memory [3*len] */ - SKP_Silk_resample_1_2_coarse( outL, &S[ 9 ], out, scratch, LSubFrameOut ); - - in += LSubFrameIn; - out += LSubFrameOut; - inLen -= LSubFrameIn; - } -} diff --git a/src/SKP_Silk_resample_4_3.c b/src/SKP_Silk_resample_4_3.c deleted file mode 100644 index f5c4f4d90..000000000 --- a/src/SKP_Silk_resample_4_3.c +++ /dev/null @@ -1,77 +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_resample_4_3.c * - * * - * Resamples by a factor 4/3 * - * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090407 * - * */ - -#include "SKP_Silk_SigProc_FIX.h" - -#define OUT_SUBFR_LEN 80 - -/* Resamples by a factor 4/3 */ -void SKP_Silk_resample_4_3( - SKP_int16 *out, /* O: Fs_low signal [inLen * 4/3] */ - SKP_int32 *S, /* I/O: State vector [7+4+4] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int inLen /* I: input length, must be a multiple of 3 */ -) -{ - SKP_int outLen, LSubFrameIn, LSubFrameOut; - SKP_int16 outH[ 3 * OUT_SUBFR_LEN ]; - SKP_int16 outHH[ 6 * OUT_SUBFR_LEN ]; - SKP_int32 scratch[ 9 * OUT_SUBFR_LEN / 2 ]; - - /* Check that input is multiple of 3 */ - SKP_assert( inLen % 3 == 0 ); - - outLen = SKP_DIV32_16( SKP_LSHIFT( inLen, 2 ), 3 ); - while( outLen > 0 ) { - LSubFrameOut = SKP_min_int( OUT_SUBFR_LEN, outLen ); - LSubFrameIn = SKP_SMULWB( 49152, LSubFrameOut ); - - /* Upsample two times by a factor 2 */ - /* Scratch size needs to be: 3 * LSubFrameIn * sizeof( SKP_int32 ) */ - SKP_Silk_resample_2_1_coarse( in, &S[ 0 ], outH, scratch, LSubFrameIn ); - /* Scratch size needs to be: 6 * LSubFrameIn * sizeof( SKP_int32 ) */ - SKP_Silk_resample_2_1_coarse( outH, &S[ 4 ], outHH, scratch, SKP_LSHIFT( LSubFrameIn, 1 ) ); - - /* Downsample by a factor 3 */ - SKP_Silk_resample_1_3( out, &S[ 8 ], outHH, SKP_LSHIFT( LSubFrameIn, 2 ) ); - - in += LSubFrameIn; - out += LSubFrameOut; - outLen -= LSubFrameOut; - } -} diff --git a/src/SKP_Silk_resample_rom.h b/src/SKP_Silk_resample_rom.h deleted file mode 100644 index 9a32648b7..000000000 --- a/src/SKP_Silk_resample_rom.h +++ /dev/null @@ -1,107 +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_resample_rom.h * - * * - * Description: Header file for FIR resampling of * - * 32 and 44 kHz input * - * * - * Copyright 2007 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 070807 * - * */ - -#ifndef _SKP_SILK_FIX_RESAMPLE_ROM_H_ -#define _SKP_SILK_FIX_RESAMPLE_ROM_H_ - -#include "SKP_Silk_typedef.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define SigProc_Resample_bw_1_4_NUM_INTERPOLATORS_LOG2 7 -#define SigProc_Resample_bw_1_4_NUM_INTERPOLATORS (1 << SigProc_Resample_bw_1_4_NUM_INTERPOLATORS_LOG2) -#define SigProc_Resample_bw_1_4_NUM_FIR_COEFS 6 - -extern const SKP_int16 SigProc_Resample_bw_1_4_INTERPOL[SigProc_Resample_bw_1_4_NUM_INTERPOLATORS][SigProc_Resample_bw_1_4_NUM_FIR_COEFS]; - - -#define SigProc_Resample_bw_80_441_NUM_INTERPOLATORS_LOG2 6 -#define SigProc_Resample_bw_80_441_NUM_INTERPOLATORS (1 << SigProc_Resample_bw_80_441_NUM_INTERPOLATORS_LOG2) -#define SigProc_Resample_bw_80_441_NUM_FIR_COEFS 4 - -extern const SKP_int16 SigProc_Resample_bw_80_441_INTERPOL[SigProc_Resample_bw_80_441_NUM_INTERPOLATORS][SigProc_Resample_bw_80_441_NUM_FIR_COEFS]; - -#define SigProc_Resample_2_3_coarse_NUM_INTERPOLATORS 2 -#define SigProc_Resample_2_3_coarse_NUM_FIR_COEFS 32 - -extern const SKP_int16 SigProc_Resample_2_3_coarse_INTERPOL[SigProc_Resample_2_3_coarse_NUM_INTERPOLATORS][SigProc_Resample_2_3_coarse_NUM_FIR_COEFS]; - -#define SigProc_Resample_2_3_coarsest_NUM_INTERPOLATORS 2 -#define SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS 10 - -extern const SKP_int16 SigProc_Resample_2_3_coarsest_INTERPOL[SigProc_Resample_2_3_coarsest_NUM_INTERPOLATORS][SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS]; - -#define SigProc_Resample_3_2_coarse_NUM_INTERPOLATORS 3 -#define SigProc_Resample_3_2_coarse_NUM_FIR_COEFS 8 - -extern const SKP_int16 SigProc_Resample_3_2_coarse_INTERPOL[SigProc_Resample_3_2_coarse_NUM_INTERPOLATORS][SigProc_Resample_3_2_coarse_NUM_FIR_COEFS]; - -#define SigProc_Resample_147_40_NUM_INTERPOLATORS 147 -#define SigProc_Resample_147_40_NUM_FIR_COEFS 20 - -extern const SKP_int16 SigProc_Resample_147_40_INTERPOL[SigProc_Resample_147_40_NUM_INTERPOLATORS][SigProc_Resample_147_40_NUM_FIR_COEFS]; - -#define SigProc_Resample_147_40_alt_NUM_INTERPOLATORS 147 -#define SigProc_Resample_147_40_alt_NUM_FIR_COEFS 10 - -extern const SKP_int16 SigProc_Resample_147_40_alt_INTERPOL[SigProc_Resample_147_40_alt_NUM_INTERPOLATORS][SigProc_Resample_147_40_alt_NUM_FIR_COEFS]; - -#define SigProc_Resample_147_40_coarse_NUM_INTERPOLATORS 147 -#define SigProc_Resample_147_40_coarse_NUM_FIR_COEFS 16 - -extern const SKP_int16 SigProc_Resample_147_40_coarse_INTERPOL[SigProc_Resample_147_40_coarse_NUM_INTERPOLATORS][SigProc_Resample_147_40_coarse_NUM_FIR_COEFS]; - -#define SigProc_Resample_40_147_NUM_INTERPOLATORS 40 -#define SigProc_Resample_40_147_NUM_FIR_COEFS 60 - -extern const SKP_int16 SigProc_Resample_40_147_INTERPOL[SigProc_Resample_40_147_NUM_INTERPOLATORS][SigProc_Resample_40_147_NUM_FIR_COEFS]; - -#define SigProc_Resample_40_147_coarse_NUM_INTERPOLATORS 40 -#define SigProc_Resample_40_147_coarse_NUM_FIR_COEFS 30 - -extern const SKP_int16 SigProc_Resample_40_147_coarse_INTERPOL[SigProc_Resample_40_147_coarse_NUM_INTERPOLATORS][SigProc_Resample_40_147_coarse_NUM_FIR_COEFS]; - -#ifdef __cplusplus -} -#endif - -#endif // _SKP_SILK_FIX_RESAMPLE_ROM_H_ diff --git a/src/Silk_FIX.2008.vcproj b/src/Silk_FIX.2008.vcproj deleted file mode 100644 index 536817986..000000000 --- a/src/Silk_FIX.2008.vcproj +++ /dev/null @@ -1,837 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="Silk_FIX" - ProjectGUID="{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" - RootNamespace="Silk" - Keyword="Win32Proj" - TargetFrameworkVersion="131072" - > - <Platforms> - <Platform - Name="Win32" - /> - <Platform - Name="x64" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="1" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - InlineFunctionExpansion="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB" - GeneratePreprocessedFile="0" - RuntimeLibrary="0" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - <Configuration - Name="Debug|x64" - OutputDirectory="$(PlatformName)\$(ConfigurationName)" - IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - TargetEnvironment="3" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="1" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - <Configuration - Name="Release|x64" - OutputDirectory="$(PlatformName)\$(ConfigurationName)" - IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - TargetEnvironment="3" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - InlineFunctionExpansion="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB" - GeneratePreprocessedFile="0" - RuntimeLibrary="0" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <Filter - Name="Source Files" - Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" - UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" - > - <File - RelativePath=".\SKP_Silk_A2NLSF.c" - > - </File> - <File - RelativePath=".\SKP_Silk_allpass_int.c" - > - </File> - <File - RelativePath=".\SKP_Silk_ana_filt_bank_1.c" - > - </File> - <File - RelativePath=".\SKP_Silk_apply_sine_window.c" - > - </File> - <File - RelativePath=".\SKP_Silk_array_maxabs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_autocorr.c" - > - </File> - <File - RelativePath=".\SKP_Silk_biquad.c" - > - </File> - <File - RelativePath=".\SKP_Silk_biquad_alt.c" - > - </File> - <File - RelativePath=".\SKP_Silk_burg_modified.c" - > - </File> - <File - RelativePath=".\SKP_Silk_bwexpander.c" - > - </File> - <File - RelativePath=".\SKP_Silk_bwexpander_32.c" - > - </File> - <File - RelativePath=".\SKP_Silk_CNG.c" - > - </File> - <File - RelativePath=".\SKP_Silk_code_signs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_control_codec_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_corrMatrix_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_create_init_destroy.c" - > - </File> - <File - RelativePath=".\SKP_Silk_dec_API.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_core.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_frame.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_indices_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_parameters.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_parameters_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_pulses.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decoder_set_fs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_detect_SWB_input.c" - > - </File> - <File - RelativePath=".\SKP_Silk_enc_API.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_frame_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_parameters.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_parameters_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_pulses.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_LPC_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_LTP_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_pitch_lags_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_pred_coefs_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_gain_quant.c" - > - </File> - <File - RelativePath=".\SKP_Silk_HP_variable_cutoff_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_init_encoder_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_inner_prod_aligned.c" - > - </File> - <File - RelativePath=".\SKP_Silk_interpolate.c" - > - </File> - <File - RelativePath=".\SKP_Silk_k2a.c" - > - </File> - <File - RelativePath=".\SKP_Silk_k2a_Q16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LBRR_reset.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lin2log.c" - > - </File> - <File - RelativePath=".\SKP_Silk_log2lin.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lowpass_int.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lowpass_short.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LP_variable_cutoff.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_inv_pred_gain.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_stabilize.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_synthesis_filter.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_synthesis_order16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LSF_cos_table.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LTP_analysis_filter_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LTP_scale_ctrl_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_MA.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF2A.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF2A_stable.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_MSVQ_decode.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_MSVQ_encode_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_stabilize.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_rate_distortion_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_sum_error_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_weights_laroia.c" - > - </File> - <File - RelativePath=".\SKP_Silk_noise_shape_analysis_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NSQ.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NSQ_del_dec.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_analysis_core.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_est_tables.c" - > - </File> - <File - RelativePath=".\SKP_Silk_PLC.c" - > - </File> - <File - RelativePath=".\SKP_Silk_prefilter_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_process_gains_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_process_NLSFs_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pulses_to_bytes.c" - > - </File> - <File - RelativePath=".\SKP_Silk_quant_LTP_gains_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_range_coder.c" - > - </File> - <File - RelativePath=".\SKP_Silk_regularize_correlations_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2_coarsest.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_1_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_coarsest.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_rom.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_1.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_2.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_2_rom.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_4_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_residual_energy16_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_residual_energy_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_scale_copy_vector16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_scale_vector.c" - > - </File> - <File - RelativePath=".\SKP_Silk_schur.c" - > - </File> - <File - RelativePath=".\SKP_Silk_schur64.c" - > - </File> - <File - RelativePath=".\SKP_Silk_shell_coder.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sigm_Q15.c" - > - </File> - <File - RelativePath=".\SKP_Silk_solve_LS_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sort.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sum_sqr_shift.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_gain.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_LTP.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_other.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_pitch_lag.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_pulses_per_block.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_sign.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_type_offset.c" - > - </File> - <File - RelativePath=".\SKP_Silk_VAD.c" - > - </File> - <File - RelativePath=".\SKP_Silk_VQ_nearest_neighbor_FIX.c" - > - </File> - </Filter> - <Filter - Name="Header Files" - Filter="h;hpp;hxx;hm;inl;inc;xsd" - UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" - > - <File - RelativePath="..\interface\SKP_Silk_control.h" - > - </File> - <File - RelativePath=".\SKP_Silk_define.h" - > - </File> - <File - RelativePath=".\SKP_Silk_define_FIX.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_errors.h" - > - </File> - <File - RelativePath=".\SKP_Silk_Inlines.h" - > - </File> - <File - RelativePath=".\SKP_Silk_macros.h" - > - </File> - <File - RelativePath=".\SKP_Silk_main.h" - > - </File> - <File - RelativePath=".\SKP_Silk_main_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_perceptual_parameters_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_est_defines.h" - > - </File> - <File - RelativePath=".\SKP_Silk_PLC.h" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_rom.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_SDK_API.h" - > - </File> - <File - RelativePath=".\SKP_Silk_SigProc_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_structs.h" - > - </File> - <File - RelativePath=".\SKP_Silk_structs_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_tables.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_typedef.h" - > - </File> - </Filter> - </Files> - <Globals> - </Globals> -</VisualStudioProject> diff --git a/src/Silk_FIX.2010.vcxproj b/src/Silk_FIX.2010.vcxproj deleted file mode 100644 index 8d341b50e..000000000 --- a/src/Silk_FIX.2010.vcxproj +++ /dev/null @@ -1,300 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectName>Silk_FIX</ProjectName> - <ProjectGuid>{56B91D01-9150-4BBF-AFA1-5B68AB991B76}</ProjectGuid> - <RootNamespace>Silk</RootNamespace> - <Keyword>Win32Proj</Keyword> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <CharacterSet>Unicode</CharacterSet> - <WholeProgramOptimization>true</WholeProgramOptimization> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <CharacterSet>Unicode</CharacterSet> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <CharacterSet>Unicode</CharacterSet> - <WholeProgramOptimization>true</WholeProgramOptimization> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <CharacterSet>Unicode</CharacterSet> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <ImportGroup Label="ExtensionSettings"> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup> - <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> - <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</OutDir> - <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir> - <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</OutDir> - <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir> - <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir> - <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir> - <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir> - <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <Optimization>Disabled</Optimization> - <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> - <AdditionalIncludeDirectories>../interface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MinimalRebuild>true</MinimalRebuild> - <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> - <FloatingPointModel>Fast</FloatingPointModel> - <PrecompiledHeader> - </PrecompiledHeader> - <WarningLevel>Level3</WarningLevel> - <DebugInformationFormat>EditAndContinue</DebugInformationFormat> - </ClCompile> - <PostBuildEvent> - <Command> - </Command> - </PostBuildEvent> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <Optimization>MaxSpeed</Optimization> - <InlineFunctionExpansion>Default</InlineFunctionExpansion> - <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> - <AdditionalIncludeDirectories>../interface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <PreprocessToFile>false</PreprocessToFile> - <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers> - <RuntimeLibrary>MultiThreaded</RuntimeLibrary> - <FloatingPointModel>Fast</FloatingPointModel> - <PrecompiledHeader> - </PrecompiledHeader> - <WarningLevel>Level3</WarningLevel> - <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> - </ClCompile> - <PostBuildEvent> - <Command> - </Command> - </PostBuildEvent> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Midl> - <TargetEnvironment>X64</TargetEnvironment> - </Midl> - <ClCompile> - <Optimization>Disabled</Optimization> - <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> - <AdditionalIncludeDirectories>../interface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MinimalRebuild>true</MinimalRebuild> - <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> - <FloatingPointModel>Fast</FloatingPointModel> - <PrecompiledHeader> - </PrecompiledHeader> - <WarningLevel>Level3</WarningLevel> - <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> - </ClCompile> - <PostBuildEvent> - <Command> - </Command> - </PostBuildEvent> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Midl> - <TargetEnvironment>X64</TargetEnvironment> - </Midl> - <ClCompile> - <Optimization>MaxSpeed</Optimization> - <InlineFunctionExpansion>Default</InlineFunctionExpansion> - <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> - <AdditionalIncludeDirectories>../interface;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <PreprocessToFile>false</PreprocessToFile> - <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers> - <RuntimeLibrary>MultiThreaded</RuntimeLibrary> - <FloatingPointModel>Fast</FloatingPointModel> - <PrecompiledHeader> - </PrecompiledHeader> - <WarningLevel>Level3</WarningLevel> - <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> - </ClCompile> - <PostBuildEvent> - <Command> - </Command> - </PostBuildEvent> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="SKP_Silk_A2NLSF.c" /> - <ClCompile Include="SKP_Silk_allpass_int.c" /> - <ClCompile Include="SKP_Silk_ana_filt_bank_1.c" /> - <ClCompile Include="SKP_Silk_apply_sine_window.c" /> - <ClCompile Include="SKP_Silk_array_maxabs.c" /> - <ClCompile Include="SKP_Silk_autocorr.c" /> - <ClCompile Include="SKP_Silk_biquad.c" /> - <ClCompile Include="SKP_Silk_biquad_alt.c" /> - <ClCompile Include="SKP_Silk_burg_modified.c" /> - <ClCompile Include="SKP_Silk_bwexpander.c" /> - <ClCompile Include="SKP_Silk_bwexpander_32.c" /> - <ClCompile Include="SKP_Silk_CNG.c" /> - <ClCompile Include="SKP_Silk_code_signs.c" /> - <ClCompile Include="SKP_Silk_control_codec_FIX.c" /> - <ClCompile Include="SKP_Silk_corrMatrix_FIX.c" /> - <ClCompile Include="SKP_Silk_create_init_destroy.c" /> - <ClCompile Include="SKP_Silk_dec_API.c" /> - <ClCompile Include="SKP_Silk_decode_core.c" /> - <ClCompile Include="SKP_Silk_decode_frame.c" /> - <ClCompile Include="SKP_Silk_decode_indices_v4.c" /> - <ClCompile Include="SKP_Silk_decode_parameters.c" /> - <ClCompile Include="SKP_Silk_decode_parameters_v4.c" /> - <ClCompile Include="SKP_Silk_decode_pulses.c" /> - <ClCompile Include="SKP_Silk_decoder_set_fs.c" /> - <ClCompile Include="SKP_Silk_detect_SWB_input.c" /> - <ClCompile Include="SKP_Silk_enc_API.c" /> - <ClCompile Include="SKP_Silk_encode_frame_FIX.c" /> - <ClCompile Include="SKP_Silk_encode_parameters.c" /> - <ClCompile Include="SKP_Silk_encode_parameters_v4.c" /> - <ClCompile Include="SKP_Silk_encode_pulses.c" /> - <ClCompile Include="SKP_Silk_find_LPC_FIX.c" /> - <ClCompile Include="SKP_Silk_find_LTP_FIX.c" /> - <ClCompile Include="SKP_Silk_find_pitch_lags_FIX.c" /> - <ClCompile Include="SKP_Silk_find_pred_coefs_FIX.c" /> - <ClCompile Include="SKP_Silk_gain_quant.c" /> - <ClCompile Include="SKP_Silk_HP_variable_cutoff_FIX.c" /> - <ClCompile Include="SKP_Silk_init_encoder_FIX.c" /> - <ClCompile Include="SKP_Silk_inner_prod_aligned.c" /> - <ClCompile Include="SKP_Silk_interpolate.c" /> - <ClCompile Include="SKP_Silk_k2a.c" /> - <ClCompile Include="SKP_Silk_k2a_Q16.c" /> - <ClCompile Include="SKP_Silk_LBRR_reset.c" /> - <ClCompile Include="SKP_Silk_lin2log.c" /> - <ClCompile Include="SKP_Silk_log2lin.c" /> - <ClCompile Include="SKP_Silk_lowpass_int.c" /> - <ClCompile Include="SKP_Silk_lowpass_short.c" /> - <ClCompile Include="SKP_Silk_LP_variable_cutoff.c" /> - <ClCompile Include="SKP_Silk_LPC_inv_pred_gain.c" /> - <ClCompile Include="SKP_Silk_LPC_stabilize.c" /> - <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_LTP_analysis_filter_FIX.c" /> - <ClCompile Include="SKP_Silk_LTP_scale_ctrl_FIX.c" /> - <ClCompile Include="SKP_Silk_MA.c" /> - <ClCompile Include="SKP_Silk_NLSF2A.c" /> - <ClCompile Include="SKP_Silk_NLSF2A_stable.c" /> - <ClCompile Include="SKP_Silk_NLSF_MSVQ_decode.c" /> - <ClCompile Include="SKP_Silk_NLSF_MSVQ_encode_FIX.c" /> - <ClCompile Include="SKP_Silk_NLSF_stabilize.c" /> - <ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion_FIX.c" /> - <ClCompile Include="SKP_Silk_NLSF_VQ_sum_error_FIX.c" /> - <ClCompile Include="SKP_Silk_NLSF_VQ_weights_laroia.c" /> - <ClCompile Include="SKP_Silk_noise_shape_analysis_FIX.c" /> - <ClCompile Include="SKP_Silk_NSQ.c" /> - <ClCompile Include="SKP_Silk_NSQ_del_dec.c" /> - <ClCompile Include="SKP_Silk_pitch_analysis_core.c" /> - <ClCompile Include="SKP_Silk_pitch_est_tables.c" /> - <ClCompile Include="SKP_Silk_PLC.c" /> - <ClCompile Include="SKP_Silk_prefilter_FIX.c" /> - <ClCompile Include="SKP_Silk_process_gains_FIX.c" /> - <ClCompile Include="SKP_Silk_process_NLSFs_FIX.c" /> - <ClCompile Include="SKP_Silk_pulses_to_bytes.c" /> - <ClCompile Include="SKP_Silk_quant_LTP_gains_FIX.c" /> - <ClCompile Include="SKP_Silk_range_coder.c" /> - <ClCompile Include="SKP_Silk_regularize_correlations_FIX.c" /> - <ClCompile Include="SKP_Silk_resample_1_2.c" /> - <ClCompile Include="SKP_Silk_resample_1_2_coarse.c" /> - <ClCompile Include="SKP_Silk_resample_1_2_coarsest.c" /> - <ClCompile Include="SKP_Silk_resample_1_3.c" /> - <ClCompile Include="SKP_Silk_resample_2_1_coarse.c" /> - <ClCompile Include="SKP_Silk_resample_2_3.c" /> - <ClCompile Include="SKP_Silk_resample_2_3_coarse.c" /> - <ClCompile Include="SKP_Silk_resample_2_3_coarsest.c" /> - <ClCompile Include="SKP_Silk_resample_2_3_rom.c" /> - <ClCompile Include="SKP_Silk_resample_3_1.c" /> - <ClCompile Include="SKP_Silk_resample_3_2.c" /> - <ClCompile Include="SKP_Silk_resample_3_2_rom.c" /> - <ClCompile Include="SKP_Silk_resample_3_4.c" /> - <ClCompile Include="SKP_Silk_resample_4_3.c" /> - <ClCompile Include="SKP_Silk_residual_energy16_FIX.c" /> - <ClCompile Include="SKP_Silk_residual_energy_FIX.c" /> - <ClCompile Include="SKP_Silk_scale_copy_vector16.c" /> - <ClCompile Include="SKP_Silk_scale_vector.c" /> - <ClCompile Include="SKP_Silk_schur.c" /> - <ClCompile Include="SKP_Silk_schur64.c" /> - <ClCompile Include="SKP_Silk_shell_coder.c" /> - <ClCompile Include="SKP_Silk_sigm_Q15.c" /> - <ClCompile Include="SKP_Silk_solve_LS_FIX.c" /> - <ClCompile Include="SKP_Silk_sort.c" /> - <ClCompile Include="SKP_Silk_sum_sqr_shift.c" /> - <ClCompile Include="SKP_Silk_tables_gain.c" /> - <ClCompile Include="SKP_Silk_tables_LTP.c" /> - <ClCompile Include="SKP_Silk_tables_NLSF_CB0_10.c" /> - <ClCompile Include="SKP_Silk_tables_NLSF_CB0_16.c" /> - <ClCompile Include="SKP_Silk_tables_NLSF_CB1_10.c" /> - <ClCompile Include="SKP_Silk_tables_NLSF_CB1_16.c" /> - <ClCompile Include="SKP_Silk_tables_other.c" /> - <ClCompile Include="SKP_Silk_tables_pitch_lag.c" /> - <ClCompile Include="SKP_Silk_tables_pulses_per_block.c" /> - <ClCompile Include="SKP_Silk_tables_sign.c" /> - <ClCompile Include="SKP_Silk_tables_type_offset.c" /> - <ClCompile Include="SKP_Silk_VAD.c" /> - <ClCompile Include="SKP_Silk_VQ_nearest_neighbor_FIX.c" /> - </ItemGroup> - <ItemGroup> - <ClInclude Include="..\interface\SKP_Silk_control.h" /> - <ClInclude Include="SKP_Silk_define.h" /> - <ClInclude Include="SKP_Silk_define_FIX.h" /> - <ClInclude Include="..\interface\SKP_Silk_errors.h" /> - <ClInclude Include="SKP_Silk_Inlines.h" /> - <ClInclude Include="SKP_Silk_macros.h" /> - <ClInclude Include="SKP_Silk_main.h" /> - <ClInclude Include="SKP_Silk_main_FIX.h" /> - <ClInclude Include="SKP_Silk_perceptual_parameters_FIX.h" /> - <ClInclude Include="SKP_Silk_pitch_est_defines.h" /> - <ClInclude Include="SKP_Silk_PLC.h" /> - <ClInclude Include="SKP_Silk_resample_rom.h" /> - <ClInclude Include="..\interface\SKP_Silk_SDK_API.h" /> - <ClInclude Include="SKP_Silk_SigProc_FIX.h" /> - <ClInclude Include="SKP_Silk_structs.h" /> - <ClInclude Include="SKP_Silk_structs_FIX.h" /> - <ClInclude Include="SKP_Silk_tables.h" /> - <ClInclude Include="..\interface\SKP_Silk_typedef.h" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <ImportGroup Label="ExtensionTargets"> - </ImportGroup> -</Project> \ No newline at end of file diff --git a/src/Silk_FIX.vcproj b/src/Silk_FIX.vcproj deleted file mode 100644 index 2e76109bb..000000000 --- a/src/Silk_FIX.vcproj +++ /dev/null @@ -1,700 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="8,00" - Name="Silk_FIX" - ProjectGUID="{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" - RootNamespace="Silk" - Keyword="Win32Proj" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(SolutionDir)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="1" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - OutputFile="SKP_Silk_FIX_Win32_debug.lib" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(SolutionDir)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - InlineFunctionExpansion="0" - FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="../interface" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB" - GeneratePreprocessedFile="0" - RuntimeLibrary="0" - FloatingPointModel="2" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLibrarianTool" - OutputFile="SKP_Silk_FIX_Win32_mt.lib" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCPostBuildEventTool" - CommandLine="" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <Filter - Name="Source Files" - Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" - UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" - > - <File - RelativePath=".\SKP_Silk_A2NLSF.c" - > - </File> - <File - RelativePath=".\SKP_Silk_allpass_int.c" - > - </File> - <File - RelativePath=".\SKP_Silk_ana_filt_bank_1.c" - > - </File> - <File - RelativePath=".\SKP_Silk_apply_sine_window.c" - > - </File> - <File - RelativePath=".\SKP_Silk_array_maxabs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_autocorr.c" - > - </File> - <File - RelativePath=".\SKP_Silk_biquad.c" - > - </File> - <File - RelativePath=".\SKP_Silk_biquad_alt.c" - > - </File> - <File - RelativePath=".\SKP_Silk_burg_modified.c" - > - </File> - <File - RelativePath=".\SKP_Silk_bwexpander.c" - > - </File> - <File - RelativePath=".\SKP_Silk_bwexpander_32.c" - > - </File> - <File - RelativePath=".\SKP_Silk_CNG.c" - > - </File> - <File - RelativePath=".\SKP_Silk_code_signs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_control_codec_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_corrMatrix_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_create_init_destroy.c" - > - </File> - <File - RelativePath=".\SKP_Silk_dec_API.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_core.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_frame.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_indices_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_parameters.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_parameters_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decode_pulses.c" - > - </File> - <File - RelativePath=".\SKP_Silk_decoder_set_fs.c" - > - </File> - <File - RelativePath=".\SKP_Silk_detect_SWB_input.c" - > - </File> - <File - RelativePath=".\SKP_Silk_enc_API.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_frame_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_parameters.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_parameters_v4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_encode_pulses.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_LPC_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_LTP_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_pitch_lags_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_find_pred_coefs_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_gain_quant.c" - > - </File> - <File - RelativePath=".\SKP_Silk_HP_variable_cutoff_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_init_encoder_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_inner_prod_aligned.c" - > - </File> - <File - RelativePath=".\SKP_Silk_interpolate.c" - > - </File> - <File - RelativePath=".\SKP_Silk_k2a.c" - > - </File> - <File - RelativePath=".\SKP_Silk_k2a_Q16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LBRR_reset.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lin2log.c" - > - </File> - <File - RelativePath=".\SKP_Silk_log2lin.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lowpass_int.c" - > - </File> - <File - RelativePath=".\SKP_Silk_lowpass_short.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LP_variable_cutoff.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_inv_pred_gain.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_stabilize.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_synthesis_filter.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LPC_synthesis_order16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LSF_cos_table.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LTP_analysis_filter_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_LTP_scale_ctrl_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_MA.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF2A.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF2A_stable.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_MSVQ_decode.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_MSVQ_encode_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_stabilize.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_rate_distortion_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_sum_error_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NLSF_VQ_weights_laroia.c" - > - </File> - <File - RelativePath=".\SKP_Silk_noise_shape_analysis_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NSQ.c" - > - </File> - <File - RelativePath=".\SKP_Silk_NSQ_del_dec.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_analysis_core.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_est_tables.c" - > - </File> - <File - RelativePath=".\SKP_Silk_PLC.c" - > - </File> - <File - RelativePath=".\SKP_Silk_prefilter_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_process_gains_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_process_NLSFs_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_pulses_to_bytes.c" - > - </File> - <File - RelativePath=".\SKP_Silk_quant_LTP_gains_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_range_coder.c" - > - </File> - <File - RelativePath=".\SKP_Silk_regularize_correlations_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_2_coarsest.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_1_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_1_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_coarse.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_coarsest.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_2_3_rom.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_1.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_2.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_2_rom.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_3_4.c" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_4_3.c" - > - </File> - <File - RelativePath=".\SKP_Silk_residual_energy16_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_residual_energy_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_scale_copy_vector16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_scale_vector.c" - > - </File> - <File - RelativePath=".\SKP_Silk_schur.c" - > - </File> - <File - RelativePath=".\SKP_Silk_schur64.c" - > - </File> - <File - RelativePath=".\SKP_Silk_shell_coder.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sigm_Q15.c" - > - </File> - <File - RelativePath=".\SKP_Silk_solve_LS_FIX.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sort.c" - > - </File> - <File - RelativePath=".\SKP_Silk_sum_sqr_shift.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_gain.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_LTP.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_other.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_pitch_lag.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_pulses_per_block.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_sign.c" - > - </File> - <File - RelativePath=".\SKP_Silk_tables_type_offset.c" - > - </File> - <File - RelativePath=".\SKP_Silk_VAD.c" - > - </File> - <File - RelativePath=".\SKP_Silk_VQ_nearest_neighbor_FIX.c" - > - </File> - </Filter> - <Filter - Name="Header Files" - Filter="h;hpp;hxx;hm;inl;inc;xsd" - UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" - > - <File - RelativePath="..\interface\SKP_Silk_control.h" - > - </File> - <File - RelativePath=".\SKP_Silk_define.h" - > - </File> - <File - RelativePath=".\SKP_Silk_define_FIX.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_errors.h" - > - </File> - <File - RelativePath=".\SKP_Silk_Inlines.h" - > - </File> - <File - RelativePath=".\SKP_Silk_macros.h" - > - </File> - <File - RelativePath=".\SKP_Silk_main.h" - > - </File> - <File - RelativePath=".\SKP_Silk_main_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_perceptual_parameters_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_pitch_est_defines.h" - > - </File> - <File - RelativePath=".\SKP_Silk_PLC.h" - > - </File> - <File - RelativePath=".\SKP_Silk_resample_rom.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_SDK_API.h" - > - </File> - <File - RelativePath=".\SKP_Silk_SigProc_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_structs.h" - > - </File> - <File - RelativePath=".\SKP_Silk_structs_FIX.h" - > - </File> - <File - RelativePath=".\SKP_Silk_tables.h" - > - </File> - <File - RelativePath="..\interface\SKP_Silk_typedef.h" - > - </File> - </Filter> - </Files> - <Globals> - </Globals> -</VisualStudioProject> diff --git a/src/SKP_Silk_HP_variable_cutoff_FIX.c b/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c similarity index 94% rename from src/SKP_Silk_HP_variable_cutoff_FIX.c rename to src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c index 68356fa1b..b695a5a29 100644 --- a/src/SKP_Silk_HP_variable_cutoff_FIX.c +++ b/src_FIX/SKP_Silk_HP_variable_cutoff_FIX.c @@ -67,7 +67,7 @@ void SKP_Silk_HP_variable_cutoff_FIX( } /* limit delta, to reduce impact of outliers */ - delta_freq_Q7 = SKP_LIMIT( delta_freq_Q7, -VARIABLE_HP_MAX_DELTA_FREQ_Q7, VARIABLE_HP_MAX_DELTA_FREQ_Q7 ); + delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -VARIABLE_HP_MAX_DELTA_FREQ_Q7, VARIABLE_HP_MAX_DELTA_FREQ_Q7 ); /* update smoother */ psEnc->variable_HP_smth1_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth1_Q15, @@ -81,7 +81,7 @@ void SKP_Silk_HP_variable_cutoff_FIX( psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) ); //pow( 2.0, psEnc->variable_HP_smth2 ); /* limit frequency range */ - psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT( psEncCtrl->pitch_freq_low_Hz, VARIABLE_HP_MIN_FREQ_Q0, VARIABLE_HP_MAX_FREQ_Q0 ); + psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, VARIABLE_HP_MIN_FREQ_Q0, VARIABLE_HP_MAX_FREQ_Q0 ); /********************************/ /* Compute Filter Coefficients */ diff --git a/src/SKP_Silk_LTP_analysis_filter_FIX.c b/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c similarity index 66% rename from src/SKP_Silk_LTP_analysis_filter_FIX.c rename to src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c index af851c713..1d90a97c2 100644 --- a/src/SKP_Silk_LTP_analysis_filter_FIX.c +++ b/src_FIX/SKP_Silk_LTP_analysis_filter_FIX.c @@ -28,14 +28,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main_FIX.h" void SKP_Silk_LTP_analysis_filter_FIX( - SKP_int16 *LTP_res, /* O: LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length ) */ - const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each NB_SUBFR subframe */ - const SKP_int pitchL[ NB_SUBFR ], /* I: Pitch lag, one for each subframe */ - const SKP_int32 invGains_Qxx[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */ - const SKP_int Qxx, /* I: Inverse quantization gains Q domain */ - const SKP_int subfr_length, /* I: Length of each subframe */ - const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */ + SKP_int16 *LTP_res, /* O: LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */ + const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I: Pitch lag, one for each subframe */ + const SKP_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */ + const SKP_int subfr_length, /* I: Length of each subframe */ + const SKP_int nb_subfr, /* I: Number of subframes */ + const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */ ) { const SKP_int16 *x_ptr, *x_lag_ptr; @@ -46,7 +46,7 @@ void SKP_Silk_LTP_analysis_filter_FIX( x_ptr = x; LTP_res_ptr = LTP_res; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { x_lag_ptr = x_ptr - pitchL[ k ]; for( i = 0; i < LTP_ORDER; i++ ) { @@ -61,18 +61,14 @@ void SKP_Silk_LTP_analysis_filter_FIX( LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] ); for( j = 1; j < LTP_ORDER; j++ ) { LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] ); - } + } LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0 /* Subtract long-term prediction */ LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est ); /* Scale residual */ - if( Qxx == 16 ) { - LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Qxx[ k ], LTP_res_ptr[ i ] ); - } else { - LTP_res_ptr[ i ] = ( SKP_int16 )SKP_CHECK_FIT16( SKP_RSHIFT64( SKP_SMULL( invGains_Qxx[ k ], LTP_res_ptr[ i ] ), Qxx ) ); - } + LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] ); x_lag_ptr++; } diff --git a/src/SKP_Silk_LTP_scale_ctrl_FIX.c b/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c similarity index 96% rename from src/SKP_Silk_LTP_scale_ctrl_FIX.c rename to src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c index 4d69a8a4a..9470e371f 100644 --- a/src/SKP_Silk_LTP_scale_ctrl_FIX.c +++ b/src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c @@ -63,7 +63,7 @@ void SKP_Silk_LTP_scale_ctrl_FIX( /* Only scale if first frame in packet 0% */ if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { - frames_per_packet = SKP_DIV32_16( psEnc->sCmn.PacketSize_ms, FRAME_LENGTH_MS ); + 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; thrld1_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss, NB_THRESHOLDS - 1 ) ]; diff --git a/src/SKP_Silk_NLSF_MSVQ_encode_FIX.c b/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c similarity index 91% rename from src/SKP_Silk_NLSF_MSVQ_encode_FIX.c rename to src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c index ba9255643..73e40c00b 100644 --- a/src/SKP_Silk_NLSF_MSVQ_encode_FIX.c +++ b/src_FIX/SKP_Silk_NLSF_MSVQ_encode_FIX.c @@ -78,6 +78,12 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS ); SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) ); +#ifdef SAVE_ALL_INTERNAL_DATA + /* Use sigtype.dat to seperate into signal types */ + DEBUG_STORE_DATA( NLSF.dat, pNLSF_Q15, LPC_order * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( WNLSF.dat, pW_Q6, LPC_order * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( NLSF_mu.dat, &NLSF_mu_Q15, sizeof( SKP_int32 ) ); +#endif /* Copy the input vector */ @@ -228,4 +234,17 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX( /* Decode and stabilize the best survivor */ SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order ); +#ifdef SAVE_ALL_INTERNAL_DATA + { + SKP_float rateBPF_LSF; + SKP_float NLSF_coef; + + rateBPF_LSF = (SKP_float)pRate_new_Q5[ bestIndex ] / 32.0f; // Q5 -> Q0 + DEBUG_STORE_DATA( rateBPF_LSF.dat, &rateBPF_LSF, sizeof( SKP_float )); + for( i = 0; i < LPC_order; i++ ) { + NLSF_coef = ( (SKP_float)pNLSF_Q15[ i ] ) * ( 1.0f / 32768.0f ); + DEBUG_STORE_DATA( NLSFq.dat, &NLSF_coef, sizeof( SKP_float ) ); + } + } +#endif } diff --git a/src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c b/src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c similarity index 100% rename from src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c rename to src_FIX/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c diff --git a/src/SKP_Silk_NLSF_VQ_sum_error_FIX.c b/src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c similarity index 100% rename from src/SKP_Silk_NLSF_VQ_sum_error_FIX.c rename to src_FIX/SKP_Silk_NLSF_VQ_sum_error_FIX.c diff --git a/src/SKP_Silk_VQ_nearest_neighbor_FIX.c b/src_FIX/SKP_Silk_VQ_nearest_neighbor_FIX.c similarity index 60% rename from src/SKP_Silk_VQ_nearest_neighbor_FIX.c rename to src_FIX/SKP_Silk_VQ_nearest_neighbor_FIX.c index 82727d5b7..5c7157454 100644 --- a/src/SKP_Silk_VQ_nearest_neighbor_FIX.c +++ b/src_FIX/SKP_Silk_VQ_nearest_neighbor_FIX.c @@ -41,60 +41,57 @@ void SKP_Silk_VQ_WMat_EC_FIX( { SKP_int k; const SKP_int16 *cb_row_Q14; - SKP_int32 sum1_Q14, sum2_Q16, diff_Q14_01, diff_Q14_23, diff_Q14_4; + SKP_int16 diff_Q14[ 5 ]; + SKP_int32 sum1_Q14, sum2_Q16; /* Loop over codebook */ *rate_dist_Q14 = SKP_int32_MAX; cb_row_Q14 = cb_Q14; for( k = 0; k < L; k++ ) { - /* Pack pairs of int16 values per int32 */ - diff_Q14_01 = (SKP_uint16)( in_Q14[ 0 ] - cb_row_Q14[ 0 ] ) | SKP_LSHIFT( ( SKP_int32 )in_Q14[ 1 ] - cb_row_Q14[ 1 ], 16 ); - diff_Q14_23 = (SKP_uint16)( in_Q14[ 2 ] - cb_row_Q14[ 2 ] ) | SKP_LSHIFT( ( SKP_int32 )in_Q14[ 3 ] - cb_row_Q14[ 3 ], 16 ); - diff_Q14_4 = in_Q14[ 4 ] - cb_row_Q14[ 4 ]; + diff_Q14[ 0 ] = in_Q14[ 0 ] - cb_row_Q14[ 0 ]; + diff_Q14[ 1 ] = in_Q14[ 1 ] - cb_row_Q14[ 1 ]; + diff_Q14[ 2 ] = in_Q14[ 2 ] - cb_row_Q14[ 2 ]; + diff_Q14[ 3 ] = in_Q14[ 3 ] - cb_row_Q14[ 3 ]; + diff_Q14[ 4 ] = in_Q14[ 4 ] - cb_row_Q14[ 4 ]; /* Weighted rate */ sum1_Q14 = SKP_SMULBB( mu_Q8, cl_Q6[ k ] ); SKP_assert( sum1_Q14 >= 0 ); - /* Add weighted quantization error, assuming W_Q18 is symmetric */ - /* NOTE: the code below loads two int16 values as one int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ /* first row of W_Q18 */ - sum2_Q16 = SKP_SMULWT( W_Q18[ 1 ], diff_Q14_01 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14_23 ); - sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 3 ], diff_Q14_23 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14_4 ); + sum2_Q16 = SKP_SMULWB( W_Q18[ 1 ], diff_Q14[ 1 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14[ 2 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 3 ], diff_Q14[ 3 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14[ 4 ] ); sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14_01 ); - sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_01 ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14[ 0 ] ); + sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 0 ] ); /* second row of W_Q18 */ - sum2_Q16 = SKP_SMULWB( W_Q18[ 7 ], diff_Q14_23 ); - sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 8 ], diff_Q14_23 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14_4 ); + sum2_Q16 = SKP_SMULWB( W_Q18[ 7 ], diff_Q14[ 2 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 8 ], diff_Q14[ 3 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14[ 4 ] ); sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 ); - sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 6 ], diff_Q14_01 ); - sum1_Q14 = SKP_SMLAWT( sum1_Q14, sum2_Q16, diff_Q14_01 ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 6 ], diff_Q14[ 1 ] ); + sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 1 ] ); /* third row of W_Q18 */ - sum2_Q16 = SKP_SMULWT( W_Q18[ 13 ], diff_Q14_23 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14_4 ); + sum2_Q16 = SKP_SMULWB( W_Q18[ 13 ], diff_Q14[ 3 ] ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] ); sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 ); - sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14_23 ); - sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_23 ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] ); + sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 2 ] ); /* fourth row of W_Q18 */ - sum2_Q16 = SKP_SMULWB( W_Q18[ 19 ], diff_Q14_4 ); + sum2_Q16 = SKP_SMULWB( W_Q18[ 19 ], diff_Q14[ 4 ] ); sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 ); - sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 18 ], diff_Q14_23 ); - sum1_Q14 = SKP_SMLAWT( sum1_Q14, sum2_Q16, diff_Q14_23 ); + sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] ); + sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 3 ] ); /* last row of W_Q18 */ - sum2_Q16 = SKP_SMULWB( W_Q18[ 24 ], diff_Q14_4 ); - sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_4 ); + sum2_Q16 = SKP_SMULWB( W_Q18[ 24 ], diff_Q14[ 4 ] ); + sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 4 ] ); SKP_assert( sum1_Q14 >= 0 ); diff --git a/src_FIX/SKP_Silk_control_codec_FIX.c b/src_FIX/SKP_Silk_control_codec_FIX.c new file mode 100644 index 000000000..b9bcca447 --- /dev/null +++ b/src_FIX/SKP_Silk_control_codec_FIX.c @@ -0,0 +1,583 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FIX.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( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int API_fs_Hz, /* I */ + SKP_int fs_kHz /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_packetsize( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int PacketSize_ms, /* I */ + SKP_int fs_kHz /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_fs( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int fs_kHz /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_complexity( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int Complexity /* I */ +); + +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_int INBandFEC_enabled /* I */ +); + +/* Control encoder SNR */ +SKP_int SKP_Silk_control_encoder_FIX( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */ + const SKP_int32 API_fs_Hz, /* I External (API) sampling rate (Hz) */ + const SKP_int max_internal_fs_kHz,/* I Maximum internal sampling rate (kHz) */ + const SKP_int PacketSize_ms, /* I Packet length (ms) */ + SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */ + const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */ + const SKP_int INBandFEC_enabled, /* I Enable (1) / disable (0) inband FEC */ + const SKP_int DTX_enabled, /* I Enable / disable DTX */ + const SKP_int InputFramesize_ms, /* I Inputframe in ms */ + const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */ +) +{ + SKP_int fs_kHz, ret = 0; + + /* State machine for the SWB/WB switching */ + fs_kHz = psEnc->sCmn.fs_kHz; + + /* Only switch during low speech activity, when no frames are sitting in the payload buffer */ + if( API_fs_Hz == 8000 || fs_kHz == 0 || API_fs_Hz < SKP_SMULBB( fs_kHz, 1000 ) || fs_kHz > max_internal_fs_kHz ) { + /* Switching is not possible, encoder just initialized, internal mode higher than external, */ + /* or internal mode higher than maximum allowed internal mode */ + fs_kHz = SKP_min( SKP_DIV32_16( API_fs_Hz, 1000 ), max_internal_fs_kHz ); + } else { + /* Accumulate the difference between the target rate and limit for switching down */ + psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - psEnc->sCmn.bitrate_threshold_down ); + psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 ); + + if( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) { /* Low speech activity and payload buffer empty */ + /* Check if we should switch down */ +#if SWITCH_TRANSITION_FILTERING + if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */ + ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || /* Bitrate threshold is met */ + ( psEnc->sCmn.sSWBdetect.WB_detected * psEnc->sCmn.fs_kHz == 24 ) ) ) { /* Forced down-switching due to WB input */ + psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */ + psEnc->sCmn.sLP.mode = 0; /* Switch down */ + } else if( + ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && /* Transition phase complete */ + ( psEnc->sCmn.sLP.mode == 0 ) ) { /* Ready to switch down */ + psEnc->sCmn.sLP.transition_frame_no = 0; /* Ready for new transition phase */ +#else + if( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) { /* Bitrate threshold is met */ +#endif + psEnc->sCmn.bitrateDiff = 0; + + /* Switch to a lower sample frequency */ + if( psEnc->sCmn.fs_kHz == 24 ) { + fs_kHz = 16; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + fs_kHz = 12; + } else { + SKP_assert( psEnc->sCmn.fs_kHz == 12 ); + fs_kHz = 8; + } + } + + /* Check if we should switch up */ + if( ( ( SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) < API_fs_Hz ) && + ( TargetRate_bps >= psEnc->sCmn.bitrate_threshold_up ) && + ( psEnc->sCmn.sSWBdetect.WB_detected * psEnc->sCmn.fs_kHz != 16 ) ) && + ( ( psEnc->sCmn.fs_kHz == 16 ) && ( max_internal_fs_kHz >= 24 ) || + ( psEnc->sCmn.fs_kHz == 12 ) && ( max_internal_fs_kHz >= 16 ) || + ( psEnc->sCmn.fs_kHz == 8 ) && ( max_internal_fs_kHz >= 12 ) ) +#if SWITCH_TRANSITION_FILTERING + && ( psEnc->sCmn.sLP.transition_frame_no == 0 ) ) { /* No transition phase running, ready to switch */ + psEnc->sCmn.sLP.mode = 1; /* Switch up */ +#else + ) { +#endif + psEnc->sCmn.bitrateDiff = 0; + + /* Switch to a higher sample frequency */ + if( psEnc->sCmn.fs_kHz == 8 ) { + fs_kHz = 12; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + fs_kHz = 16; + } else { + SKP_assert( psEnc->sCmn.fs_kHz == 16 ); + fs_kHz = 24; + } + } + } + } + +#if SWITCH_TRANSITION_FILTERING + /* After switching up, stop transition filter during speech inactivity */ + if( ( psEnc->sCmn.sLP.mode == 1 ) && + ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && + ( psEnc->speech_activity_Q8 < 128 ) && + ( psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { + + psEnc->sCmn.sLP.transition_frame_no = 0; + + /* Reset transition filter state */ + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + } +#endif + +#ifdef FORCE_FS_KHZ + SKP_assert( FORCE_FS_KHZ == 8 || FORCE_FS_KHZ == 12 || FORCE_FS_KHZ == 16 || FORCE_FS_KHZ == 24 ); + if( psEnc->sCmn.fs_kHz != 0 ) { + /* Force except during init */ + fs_kHz = FORCE_FS_KHZ; + } +#endif + +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( bitrate.dat, &TargetRate_bps, 1 * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( fs.dat, &fs_kHz, 1 * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( diff.dat, &psEnc->sCmn.bitrateDiff, 1 * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( lashape.dat, &psEnc->sCmn.la_shape, 1 * sizeof( SKP_int32 ) ); +#endif + /********************************************/ + /* Prepare resampler and buffered data */ + /********************************************/ + SKP_Silk_setup_resamplers( psEnc, API_fs_Hz, fs_kHz ); + + /********************************************/ + /* Set packet size */ + /********************************************/ + ret += SKP_Silk_setup_packetsize( psEnc, PacketSize_ms, fs_kHz ); + + /********************************************/ + /* Set internal sampling frequency */ + /********************************************/ + ret += SKP_Silk_setup_fs( psEnc, fs_kHz ); + + /********************************************/ + /* Set encoding complexity */ + /********************************************/ + ret += SKP_Silk_setup_complexity( psEnc, Complexity ); + + /********************************************/ + /* Set bitrate/coding quality */ + /********************************************/ + ret += SKP_Silk_setup_rate( psEnc, TargetRate_bps ); + + /********************************************/ + /* Set packet loss rate measured by farend */ + /********************************************/ + if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) { + ret = SKP_SILK_ENC_INVALID_LOSS_RATE; + } + psEnc->sCmn.PacketLoss_perc = PacketLoss_perc; + + /********************************************/ + /* Set LBRR usage */ + /********************************************/ + ret += SKP_Silk_setup_LBRR( psEnc, INBandFEC_enabled ); + + /********************************************/ + /* Set DTX mode */ + /********************************************/ + if( DTX_enabled < 0 || DTX_enabled > 1 ) { + ret = SKP_SILK_ENC_INVALID_DTX_SETTING; + } + psEnc->sCmn.useDTX = DTX_enabled; + + return ret; +} + +/* Control low bitrate redundancy usage */ +void SKP_Silk_LBRR_ctrl_FIX( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */ + SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control */ +) +{ + SKP_int LBRR_usage; + + if( psEnc->sCmn.LBRR_enabled ) { + /* Control LBRR */ + + /* Usage Control based on sensitivity and packet loss caracteristics */ + /* For now only enable adding to next for active frames. Make more complex later */ + LBRR_usage = SKP_SILK_NO_LBRR; + if( psEnc->speech_activity_Q8 > LBRR_SPEECH_ACTIVITY_THRES_Q8 && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity + LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1; + } + psEncCtrl->sCmn.LBRR_usage = LBRR_usage; + } else { + psEncCtrl->sCmn.LBRR_usage = SKP_SILK_NO_LBRR; + } +} + +SKP_INLINE SKP_int SKP_Silk_setup_packetsize( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int PacketSize_ms, /* I */ + SKP_int fs_kHz /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + if( ( PacketSize_ms != 10 ) && + ( PacketSize_ms != 20 ) && + ( PacketSize_ms != 40 ) && + ( PacketSize_ms != 60 ) && + ( PacketSize_ms != 80 ) && + ( PacketSize_ms != 100 ) ) { + ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; + } else { + if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) { + if( PacketSize_ms == 10 ) { + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + /* Only allowed when the payload buffer is empty */ + psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1; + psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.PacketSize_ms = PacketSize_ms; + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); + /* Packet length changes. Reset LBRR buffer */ + SKP_Silk_LBRR_reset( &psEnc->sCmn ); + } + } else{ + psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; + psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.PacketSize_ms = PacketSize_ms; + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); + /* Packet length changes. Reset LBRR buffer */ + SKP_Silk_LBRR_reset( &psEnc->sCmn ); + } + } + } + return(ret); +} + +SKP_INLINE SKP_int SKP_Silk_setup_resamplers( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int API_fs_Hz, /* I */ + SKP_int fs_kHz /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != API_fs_Hz ) { + + /* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */ + SKP_int16 x_buf_API_fs_Hz[ ( MAX_API_FS_KHZ / 8 ) * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; + + SKP_int32 nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape; + + if( SKP_SMULBB( fs_kHz, 1000 ) < API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) { + /* Resample buffered data in x_buf to API_fs_Hz */ + + SKP_Silk_resampler_state_struct temp_resampler_state; + + /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */ + ret += SKP_Silk_resampler_init( &temp_resampler_state, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), API_fs_Hz ); + + /* Temporary resampling of x_buf data to API_fs_Hz */ + ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp ); + + /* Calculate number of samples that has been temporarily upsampled */ + nSamples_temp = SKP_DIV32_16( nSamples_temp * API_fs_Hz, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) ); + + /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ + ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, API_fs_Hz, SKP_SMULBB( fs_kHz, 1000 ) ); + + } else { + /* Copy data */ + SKP_memcpy( x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp * sizeof( SKP_int16 ) ); + } + + if( 1000 * fs_kHz != API_fs_Hz ) { + /* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */ + ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, psEnc->x_buf, x_buf_API_fs_Hz, nSamples_temp ); + } + } + psEnc->sCmn.prev_API_fs_Hz = API_fs_Hz; + + return(ret); +} + +SKP_INLINE SKP_int SKP_Silk_setup_fs( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int fs_kHz /* I */ +) +{ + SKP_int ret = 0; + + if( psEnc->sCmn.fs_kHz != fs_kHz ) { + /* reset part of the state */ + SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) ); + SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) ); + SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) ); + SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) ); + SKP_memset( psEnc->sNSQ.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) ); + SKP_memset( psEnc->sNSQ_LBRR.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) ); + SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) ); +#if SWITCH_TRANSITION_FILTERING + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + if( psEnc->sCmn.sLP.mode == 1 ) { + /* Begin transition phase */ + psEnc->sCmn.sLP.transition_frame_no = 1; + } else { + /* End transition phase */ + psEnc->sCmn.sLP.transition_frame_no = 0; + } +#endif + psEnc->sCmn.inputBufIx = 0; + psEnc->sCmn.nFramesInPayloadBuf = 0; + psEnc->sCmn.nBytesInPayloadBuf = 0; + psEnc->sCmn.oldest_LBRR_idx = 0; + psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */ + + SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); + + /* Initialize non-zero parameters */ + psEnc->sCmn.prevLag = 100; + psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED; + 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.fs_kHz = fs_kHz; + if( psEnc->sCmn.fs_kHz == 8 ) { + psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER; + psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10; + psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10; + } else { + psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER; + psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16; + psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16; + } + psEnc->sCmn.subfr_length = SKP_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz ); + psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); + psEnc->sCmn.la_pitch = SKP_SMULBB( LA_PITCH_MS, fs_kHz ); + psEnc->sCmn.la_shape = SKP_SMULBB( LA_SHAPE_MS, fs_kHz ); + psEnc->sPred.min_pitch_lag = SKP_SMULBB( 3, fs_kHz ); + psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz ); + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){ + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); + } else { + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); + } + if( psEnc->sCmn.fs_kHz == 24 ) { + psEnc->mu_LTP_Q8 = MU_LTP_QUANT_SWB_Q8; + psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX; + psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + psEnc->mu_LTP_Q8 = MU_LTP_QUANT_WB_Q8; + psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + psEnc->mu_LTP_Q8 = MU_LTP_QUANT_MB_Q8; + psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS; + } else { + psEnc->mu_LTP_Q8 = MU_LTP_QUANT_NB_Q8; + psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = 0; + } + psEnc->sCmn.fs_kHz_changed = 1; + + /* Check that settings are valid */ + SKP_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length ); + } + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_complexity( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int Complexity /* I */ +) +{ + SKP_int ret = 0; + + /* Check that settings are valid */ + if( LOW_COMPLEXITY_ONLY && Complexity != 0 ) { + ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING; + } + + /* Set encoding complexity */ + if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) { + /* Low complexity */ + psEnc->sCmn.Complexity = 0; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_LC_MODE; + psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_LC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 8; + psEnc->sCmn.shapingLPCOrder = 8; + psEnc->sCmn.nStatesDelayedDecision = 1; + psEnc->sCmn.useInterpolatedNLSFs = 0; + psEnc->sCmn.LTPQuantLowComplexity = 1; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE; + } else if( Complexity == 1 ) { + /* Medium complexity */ + psEnc->sCmn.Complexity = 1; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_MC_MODE; + psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_MC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 12; + psEnc->sCmn.shapingLPCOrder = 12; + psEnc->sCmn.nStatesDelayedDecision = 2; + psEnc->sCmn.useInterpolatedNLSFs = 0; + psEnc->sCmn.LTPQuantLowComplexity = 0; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE; + } else if( Complexity == 2 ) { + /* High complexity */ + psEnc->sCmn.Complexity = 2; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_HC_MODE; + psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_HC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 16; + psEnc->sCmn.shapingLPCOrder = 16; + psEnc->sCmn.nStatesDelayedDecision = 4; + psEnc->sCmn.useInterpolatedNLSFs = 1; + psEnc->sCmn.LTPQuantLowComplexity = 0; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS; + } else { + ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING; + } + + /* Do not allow higher pitch estimation LPC order than predict LPC order */ + psEnc->sCmn.pitchEstimationLPCOrder = SKP_min_int( psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.predictLPCOrder ); + + SKP_assert( psEnc->sCmn.pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); + SKP_assert( psEnc->sCmn.shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); + SKP_assert( psEnc->sCmn.nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); + + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_rate( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int TargetRate_bps /* I */ +) +{ + SKP_int k, ret = 0; + SKP_int32 frac_Q6; + const SKP_int32 *rateTable; + + TargetRate_bps = SKP_min( TargetRate_bps, 100000 ); + if( psEnc->sCmn.fs_kHz == 8 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_NB_BPS ); + } else if( psEnc->sCmn.fs_kHz == 12 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_MB_BPS ); + } else if( psEnc->sCmn.fs_kHz == 16 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_WB_BPS ); + } else { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_SWB_BPS ); + } + if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) { + psEnc->sCmn.TargetRate_bps = TargetRate_bps; + + /* If new TargetRate_bps, translate to SNR_dB value */ + if( psEnc->sCmn.fs_kHz == 8 ) { + rateTable = TargetRate_table_NB; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + rateTable = TargetRate_table_MB; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + rateTable = TargetRate_table_WB; + } else { + rateTable = TargetRate_table_SWB; + } + for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { + /* Find bitrate interval in table and interpolate */ + 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 ] ); + break; + } + } + } + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_LBRR( + SKP_Silk_encoder_state_FIX *psEnc, /* I/O */ + SKP_int INBandFEC_enabled /* I */ +) +{ + SKP_int ret = 0; + SKP_int32 LBRRRate_thres_bps; + +#if USE_LBRR + if( INBandFEC_enabled < 0 || INBandFEC_enabled > 1 ) { + ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; + } + + /* Only change settings if first frame in packet */ + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + + psEnc->sCmn.LBRR_enabled = INBandFEC_enabled; + 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 aprox same mean / weighted bitrate as no inband FEC */ + psEnc->inBandFEC_SNR_comp_Q8 = ( 6 << 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( INBandFEC_enabled != 0 ) { + ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; + } + psEnc->sCmn.LBRR_enabled = 0; +#endif + return( ret ); +} \ No newline at end of file diff --git a/src/SKP_Silk_corrMatrix_FIX.c b/src_FIX/SKP_Silk_corrMatrix_FIX.c similarity index 100% rename from src/SKP_Silk_corrMatrix_FIX.c rename to src_FIX/SKP_Silk_corrMatrix_FIX.c diff --git a/src/SKP_Silk_define_FIX.h b/src_FIX/SKP_Silk_define_FIX.h similarity index 90% rename from src/SKP_Silk_define_FIX.h rename to src_FIX/SKP_Silk_define_FIX.h index ff42ace0e..183b6aa74 100644 --- a/src/SKP_Silk_define_FIX.h +++ b/src_FIX/SKP_Silk_define_FIX.h @@ -85,11 +85,6 @@ extern "C" /* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */ #define VARIABLE_HP_MAX_DELTA_FREQ_Q7 51 // 0.4 in Q7 -/* Defines for CN generation */ -#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH)) */ -#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */ -#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */ - #ifdef __cplusplus } #endif diff --git a/src/SKP_Silk_encode_frame_FIX.c b/src_FIX/SKP_Silk_encode_frame_FIX.c similarity index 58% rename from src/SKP_Silk_encode_frame_FIX.c rename to src_FIX/SKP_Silk_encode_frame_FIX.c index 4f97ec5f3..7d42a4d31 100644 --- a/src/SKP_Silk_encode_frame_FIX.c +++ b/src_FIX/SKP_Silk_encode_frame_FIX.c @@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "SKP_Silk_main_FIX.h" + /****************/ /* Encode frame */ /****************/ @@ -43,39 +44,44 @@ SKP_int SKP_Silk_encode_frame_FIX( 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 LBRR_idx, frame_terminator, SNR_dB_Q7; + SKP_int LBRR_idx, frame_terminator; const SKP_uint16 *FrameTermination_CDF; /* Low bitrate redundancy parameters */ SKP_uint8 LBRRpayload[ MAX_ARITHM_BYTES ]; SKP_int16 nBytesLBRR; + ec_byte_buffer range_enc_celt_buf; - //SKP_int32 Seed[ MAX_LAYERS ]; sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3; +TIC(ENCODE_FRAME) /**************************************************************/ /* Setup Input Pointers, and insert frame in input buffer */ /*************************************************************/ - x_frame = psEnc->x_buf + psEnc->sCmn.frame_length; /* start of frame to encode */ - res_pitch_frame = res_pitch + psEnc->sCmn.frame_length; /* start of pitch LPC residual frame */ + x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; /* start of frame to encode */ + res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; /* start of pitch LPC residual frame */ /****************************/ /* Voice Activity Detection */ /****************************/ - ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, &SNR_dB_Q7, +TIC(VAD) + ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, sEncCtrl.input_quality_bands_Q15, &sEncCtrl.input_tilt_Q15, - pIn,psEnc->sCmn.frame_length ); + pIn, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz ); +TOC(VAD) /*******************************************/ /* High-pass filtering of the input signal */ /*******************************************/ +TIC(HP_IN) #if HIGH_PASS_INPUT /* Variable high-pass filter */ SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, pIn_HP, pIn ); #else SKP_memcpy( pIn_HP, pIn,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); #endif +TOC(HP_IN) #if SWITCH_TRANSITION_FILTERING /* Ensure smooth bandwidth transitions */ @@ -87,28 +93,37 @@ SKP_int SKP_Silk_encode_frame_FIX( /*****************************************/ /* Find pitch lags, initial LPC analysis */ /*****************************************/ +TIC(FIND_PITCH) SKP_Silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame ); +TOC(FIND_PITCH) /************************/ /* Noise shape analysis */ /************************/ - SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame ); +TIC(NOISE_SHAPE_ANALYSIS) + SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame ); +TOC(NOISE_SHAPE_ANALYSIS) /*****************************************/ /* Prefiltering for noise shaper */ /*****************************************/ +TIC(PREFILTER) SKP_Silk_prefilter_FIX( psEnc, &sEncCtrl, xfw, x_frame ); - +TOC(PREFILTER) /***************************************************/ /* Find linear prediction coefficients (LPC + LTP) */ /***************************************************/ +TIC(FIND_PRED_COEF) SKP_Silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch ); +TOC(FIND_PRED_COEF) /****************************************/ /* Process gains */ /****************************************/ +TIC(PROCESS_GAINS) SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl ); +TOC(PROCESS_GAINS) psEnc->sCmn.sigtype[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.sigtype; psEnc->sCmn.QuantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.QuantOffsetType; @@ -117,16 +132,28 @@ SKP_int SKP_Silk_encode_frame_FIX( /* Low Bitrate Redundant Encoding */ /****************************************/ nBytesLBRR = MAX_ARITHM_BYTES; +TIC(LBRR) SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw ); +TOC(LBRR) /*****************************************/ /* Noise shaping quantization */ /*****************************************/ - psEnc->NoiseShapingQuantizer( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, - &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], sEncCtrl.sCmn.NLSFInterpCoef_Q2, - 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 ); +TIC(NSQ) + if( psEnc->sCmn.nStatesDelayedDecision > 1 ) { + SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, + &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], sEncCtrl.sCmn.NLSFInterpCoef_Q2, + 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 ); + } else { + SKP_Silk_NSQ( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, + &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], sEncCtrl.sCmn.NLSFInterpCoef_Q2, + 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 ); + } +TOC(NSQ) /**************************************************/ /* Convert speech activity into VAD and DTX flags */ @@ -151,6 +178,9 @@ SKP_int SKP_Silk_encode_frame_FIX( /* Initialize arithmetic coder */ /****************************************/ if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC.buffer, MAX_ARITHM_BYTES ); + ec_enc_init( &psEnc->sCmn.sRC.range_enc_celt_state, &range_enc_celt_buf ); + SKP_Silk_range_enc_init( &psEnc->sCmn.sRC ); psEnc->sCmn.nBytesInPayloadBuf = 0; } @@ -158,24 +188,20 @@ SKP_int SKP_Silk_encode_frame_FIX( /****************************************/ /* Encode Parameters */ /****************************************/ - if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) { - SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC ); - FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF; - } else { - SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC, - &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ] ); - FrameTermination_CDF = SKP_Silk_FrameTermination_CDF; - } +TIC(ENCODE_PARAMS) + SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC ); + FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF; +TOC(ENCODE_PARAMS) /****************************************/ /* Update Buffers and State */ /****************************************/ /* Update Input buffer */ - SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], ( psEnc->sCmn.frame_length + psEnc->sCmn.la_shape ) * sizeof( SKP_int16 ) ); + SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], ( psEnc->sCmn.ltp_mem_length + psEnc->sCmn.la_shape ) * sizeof( SKP_int16 ) ); /* parameters needed for next frame */ psEnc->sCmn.prev_sigtype = sEncCtrl.sCmn.sigtype; - psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ NB_SUBFR - 1]; + psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; psEnc->sCmn.first_frame_after_reset = 0; if( psEnc->sCmn.sRC.error ) { @@ -188,7 +214,7 @@ SKP_int SKP_Silk_encode_frame_FIX( /****************************************/ /* finalize payload and copy to output */ /****************************************/ - if( psEnc->sCmn.nFramesInPayloadBuf * FRAME_LENGTH_MS >= psEnc->sCmn.PacketSize_ms ) { + if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) { LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK; @@ -201,24 +227,33 @@ SKP_int SKP_Silk_encode_frame_FIX( frame_terminator = SKP_SILK_LBRR_VER2; LBRR_idx = psEnc->sCmn.oldest_LBRR_idx; } + /* Add the frame termination info to stream */ SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF ); - if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) { - /* Code excitation signal */ - for( i = 0; i <psEnc->sCmn.nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ],psEnc->sCmn.QuantOffsetType[ i ], - &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length],psEnc->sCmn.frame_length ); - } + /* Code excitation signal */ + for( i = 0; i <psEnc->sCmn.nFramesInPayloadBuf; i++ ) { + SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ],psEnc->sCmn.QuantOffsetType[ i ], + &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length],psEnc->sCmn.frame_length ); } /* payload length so far */ - SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes ); + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes ); /* check that there is enough space in external output buffer, and move data */ if( *pnBytesOut >= nBytes ) { - SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC ); - SKP_memcpy( pCode, psEnc->sCmn.sRC.buffer, nBytes * sizeof( SKP_uint8 ) ); + SKP_int bits_in_stream, mask; + bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC.range_enc_celt_state, 0 ); + ec_enc_done( &psEnc->sCmn.sRC.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.range_enc_celt_state.buf->buf[ nBytes - 1 ] |= mask; + } + } + SKP_memcpy( pCode, psEnc->sCmn.sRC.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) ); + if( frame_terminator > SKP_SILK_MORE_FRAMES && *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) { /* Get old packet and add to payload. */ @@ -256,13 +291,11 @@ SKP_int SKP_Silk_encode_frame_FIX( SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF ); /* payload length so far */ - SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes ); - - if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) { - /* Take into account the q signal that isnt in the bitstream yet */ - nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, - &psEnc->sCmn.q[ (psEnc->sCmn.nFramesInPayloadBuf - 1) * psEnc->sCmn.frame_length ] ); - } + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes ); + + /* Take into account the q signal that isnt in the bitstream yet */ + nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, + &psEnc->sCmn.q[ (psEnc->sCmn.nFramesInPayloadBuf - 1) * psEnc->sCmn.frame_length ] ); } /* Check for arithmetic coder errors */ @@ -275,15 +308,63 @@ SKP_int SKP_Silk_encode_frame_FIX( 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 -= FRAME_LENGTH_MS; - psEnc->BufferedInChannel_ms = SKP_LIMIT( psEnc->BufferedInChannel_ms, 0, 100 ); + 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; if( psEnc->speech_activity_Q8 > WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES_Q8 ) { - psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, FRAME_LENGTH_MS ); + psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) ); } - +TOC(ENCODE_FRAME) + +#ifdef SAVE_ALL_INTERNAL_DATA + { + SKP_float tmp[ MAX_NB_SUBFR * LTP_ORDER ]; + int i; + DEBUG_STORE_DATA( xf.dat, x_frame +psEnc->sCmn.la_shape, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + DEBUG_STORE_DATA( xfw.dat, xfw, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) ); + // DEBUG_STORE_DATA( q.dat, &psEnc->sCmn.q[ ( psEnc->sCmn.nFramesInPayloadBuf - 1)*psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length * sizeof( SKP_int8 ) ); + DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.sCmn.pitchL, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); + for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) { + tmp[ i ] = (SKP_float)sEncCtrl.LTPCoef_Q14[ i ] / 16384.0f; + } + DEBUG_STORE_DATA( pitchG_quantized.dat, tmp, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( SKP_float ) ); + for( i = 0; i <psEnc->sCmn.predictLPCOrder; i++ ) { + tmp[ i ] = (SKP_float)sEncCtrl.PredCoef_Q12[ 1 ][ i ] / 4096.0f; + } + DEBUG_STORE_DATA( PredCoef.dat, tmp, psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); + + tmp[ 0 ] = (SKP_float)sEncCtrl.pitch_freq_low_Hz; + DEBUG_STORE_DATA( pitch_freq_low_Hz.dat, tmp, sizeof( SKP_float ) ); + tmp[ 0 ] = (SKP_float)sEncCtrl.LTPredCodGain_Q7 / 128.0f; + DEBUG_STORE_DATA( LTPredCodGain.dat, tmp, sizeof( SKP_float ) ); + tmp[ 0 ] = (SKP_float)psEnc->LTPCorr_Q15 / 32768.0f; + DEBUG_STORE_DATA( LTPcorr.dat, tmp, sizeof( SKP_float ) ); + tmp[ 0 ] = (SKP_float)sEncCtrl.input_tilt_Q15 / 32768.0f; + DEBUG_STORE_DATA( tilt.dat, tmp, sizeof( SKP_float ) ); + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + 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 ) ); + 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 ) ); + 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( sigtype.dat, &sEncCtrl.sCmn.sigtype, 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 ) ); + } +#endif return( ret ); } @@ -296,10 +377,12 @@ void SKP_Silk_LBRR_encode_FIX( SKP_int16 xfw[] /* I Input signal */ ) { - SKP_int i, TempGainsIndices[ NB_SUBFR ], frame_terminator; + SKP_int i, TempGainsIndices[ MAX_NB_SUBFR ], frame_terminator; SKP_int nBytes, nFramesInPayloadBuf; - SKP_int32 TempGains_Q16[ NB_SUBFR ]; + SKP_int32 TempGains_Q16[ MAX_NB_SUBFR ]; SKP_int typeOffset, LTP_scaleIndex, Rate_only_parameters = 0; + ec_byte_buffer range_enc_celt_buf; + /*******************************************/ /* Control use of inband LBRR */ /*******************************************/ @@ -307,8 +390,8 @@ void SKP_Silk_LBRR_encode_FIX( if( psEnc->sCmn.LBRR_enabled ) { /* Save original Gains */ - SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, NB_SUBFR * sizeof( SKP_int ) ); - SKP_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) ); + 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; @@ -334,20 +417,28 @@ void SKP_Silk_LBRR_encode_FIX( 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( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 ); + 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.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, psEnc->sCmn.nb_subfr ); /*****************************************/ /* Noise shaping quantization */ /*****************************************/ - psEnc->NoiseShapingQuantizer( &psEnc->sCmn, &psEncCtrl->sCmn, - &psEnc->sNSQ_LBRR, xfw, &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ], - 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 ); + if( psEnc->sCmn.nStatesDelayedDecision > 1 ) { + SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, + &psEnc->sNSQ_LBRR, xfw, &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ], + 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[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ], + 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[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], 0, psEnc->sCmn.frame_length * sizeof( SKP_int ) ); @@ -357,6 +448,9 @@ void SKP_Silk_LBRR_encode_FIX( /* Initialize arithmetic coder */ /****************************************/ if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES ); + ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, &range_enc_celt_buf ); + SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR ); psEnc->sCmn.nBytesInPayloadBuf = 0; } @@ -364,12 +458,7 @@ void SKP_Silk_LBRR_encode_FIX( /****************************************/ /* Encode Parameters */ /****************************************/ - if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) { - SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR ); - } else { - SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR, - &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length] ); - } + SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR ); if( psEnc->sCmn.sRC_LBRR.error ) { /* encoder returned error: clear payload buffer */ @@ -381,31 +470,39 @@ void SKP_Silk_LBRR_encode_FIX( /****************************************/ /* finalize payload and copy to output */ /****************************************/ - if( SKP_SMULBB( nFramesInPayloadBuf, FRAME_LENGTH_MS ) >= psEnc->sCmn.PacketSize_ms ) { + 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 */ - SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF ); + SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF ); - if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) { - /*********************************************/ - /* Encode quantization indices of excitation */ - /*********************************************/ - for( i = 0; i < nFramesInPayloadBuf; i++ ) { - SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], - &psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); - } + /*********************************************/ + /* Encode quantization indices of excitation */ + /*********************************************/ + for( i = 0; i < nFramesInPayloadBuf; i++ ) { + SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], + &psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); } /* payload length so far */ - SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes ); + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes ); /* check that there is enough space in external output buffer, and move data */ if( *pnBytesOut >= nBytes ) { - SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC_LBRR ); - SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.buffer, nBytes * sizeof( SKP_uint8 ) ); - + SKP_int bits_in_stream, mask; + bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, 0 ); + 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 ) ); +//#endif *pnBytesOut = nBytes; } else { /* not enough space: payload will be discarded */ @@ -418,12 +515,12 @@ void SKP_Silk_LBRR_encode_FIX( /* Encode that more frames follows */ frame_terminator = SKP_SILK_MORE_FRAMES; - SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF ); + SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF ); } /* Restore original Gains */ - SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, NB_SUBFR * sizeof( SKP_int ) ); - SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, NB_SUBFR * sizeof( SKP_int32 ) ); + SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, MAX_NB_SUBFR * sizeof( SKP_int ) ); + SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, MAX_NB_SUBFR * sizeof( SKP_int32 ) ); /* Restore LTP scale index and typeoffset */ psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex; diff --git a/src/SKP_Silk_find_LPC_FIX.c b/src_FIX/SKP_Silk_find_LPC_FIX.c similarity index 91% rename from src/SKP_Silk_find_LPC_FIX.c rename to src_FIX/SKP_Silk_find_LPC_FIX.c index d45506cac..fbf260834 100644 --- a/src/SKP_Silk_find_LPC_FIX.c +++ b/src_FIX/SKP_Silk_find_LPC_FIX.c @@ -35,7 +35,8 @@ void SKP_Silk_find_LPC_FIX( const SKP_int useInterpolatedNLSFs, /* I Flag */ const SKP_int LPC_order, /* I LPC order */ const SKP_int16 x[], /* I Input signal */ - const SKP_int subfr_length /* I Input signal subframe length including preceeding samples */ + const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */ + const SKP_int nb_subfr /* I: Number of subframes */ ) { SKP_int k; @@ -51,19 +52,19 @@ void SKP_Silk_find_LPC_FIX( SKP_int res_nrg_interp_Q, res_nrg_Q, res_tmp_nrg_Q, res_nrg_2nd_Q; SKP_int16 a_tmp_Q12[ MAX_LPC_ORDER ]; SKP_int NLSF0_Q15[ MAX_LPC_ORDER ]; - SKP_int16 LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; + SKP_int16 LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; /* Default: no interpolation */ *interpIndex = 4; /* Burg AR analysis for the full frame */ - SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, NB_SUBFR, FIND_LPC_COND_FAC_Q32, LPC_order ); + SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, nb_subfr, FIND_LPC_COND_FAC_Q32, LPC_order ); - if( useInterpolatedNLSFs == 1 ) { + if( useInterpolatedNLSFs == 1 && nb_subfr == MAX_NB_SUBFR ) { /* Optimal solution for last 10 ms */ - SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( NB_SUBFR >> 1 ) * subfr_length, - subfr_length, ( NB_SUBFR >> 1 ), FIND_LPC_COND_FAC_Q32, LPC_order ); + SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( MAX_NB_SUBFR >> 1 ) * subfr_length, + subfr_length, ( MAX_NB_SUBFR >> 1 ), FIND_LPC_COND_FAC_Q32, LPC_order ); /* subtract residual energy here, as that's easier than adding it to the */ /* residual energy of the first 10 ms in each iteration of the search below */ diff --git a/src/SKP_Silk_find_LTP_FIX.c b/src_FIX/SKP_Silk_find_LTP_FIX.c similarity index 82% rename from src/SKP_Silk_find_LTP_FIX.c rename to src_FIX/SKP_Silk_find_LTP_FIX.c index c8ac22d16..2f0881e9f 100644 --- a/src/SKP_Silk_find_LTP_FIX.c +++ b/src_FIX/SKP_Silk_find_LTP_FIX.c @@ -33,16 +33,16 @@ void SKP_Silk_fit_LTP( ); void SKP_Silk_find_LTP_FIX( - SKP_int16 b_Q14[ NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ - SKP_int32 WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ - SKP_int *LTPredCodGain_Q7, /* O LTP coding gain */ - const SKP_int16 r_first[], /* I residual signal after LPC signal + state for first 10 ms */ - const SKP_int16 r_last[], /* I residual signal after LPC signal + state for last 10 ms */ - const SKP_int lag[ NB_SUBFR ], /* I LTP lags */ - const SKP_int32 Wght_Q15[ NB_SUBFR ], /* I weights */ - const SKP_int subfr_length, /* I subframe length */ - const SKP_int mem_offset, /* I number of samples in LTP memory */ - SKP_int corr_rshifts[ NB_SUBFR ] /* O right shifts applied to correlations */ + SKP_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ + SKP_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ + SKP_int *LTPredCodGain_Q7, /* O LTP coding gain */ + const SKP_int16 r_lpc[] , /* I residual signal after LPC signal + state for first 10 ms */ + const SKP_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ + const SKP_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ + const SKP_int subfr_length, /* I subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int mem_offset, /* I number of samples in LTP memory */ + SKP_int corr_rshifts[ MAX_NB_SUBFR ] /* O right shifts applied to correlations */ ) { SKP_int i, k, lshift; @@ -51,23 +51,20 @@ void SKP_Silk_find_LTP_FIX( SKP_int32 regu; SKP_int32 *WLTP_ptr; - SKP_int32 b_Q16[ LTP_ORDER ], delta_b_Q14[ LTP_ORDER ], d_Q14[ NB_SUBFR ], nrg[ NB_SUBFR ], g_Q26; - SKP_int32 w[ NB_SUBFR ], WLTP_max, max_abs_d_Q14, max_w_bits; + SKP_int32 b_Q16[ LTP_ORDER ], delta_b_Q14[ LTP_ORDER ], d_Q14[ MAX_NB_SUBFR ], nrg[ MAX_NB_SUBFR ], g_Q26; + SKP_int32 w[ MAX_NB_SUBFR ], WLTP_max, max_abs_d_Q14, max_w_bits; SKP_int32 temp32, denom32; SKP_int extra_shifts; SKP_int rr_shifts, maxRshifts, maxRshifts_wxtra, LZs; SKP_int32 LPC_res_nrg, LPC_LTP_res_nrg, div_Q16; - SKP_int32 Rr[ LTP_ORDER ], rr[ NB_SUBFR ]; + SKP_int32 Rr[ LTP_ORDER ], rr[ MAX_NB_SUBFR ]; SKP_int32 wd, m_Q12; b_Q14_ptr = b_Q14; WLTP_ptr = WLTP; - r_ptr = &r_first[ mem_offset ]; - for( k = 0; k < NB_SUBFR; k++ ) { - if( k == ( NB_SUBFR >> 1 ) ) { /* shift residual for last 10 ms */ - r_ptr = &r_last[ mem_offset ]; - } + r_ptr = &r_lpc[ mem_offset ]; + for( k = 0; k < nb_subfr; k++ ) { lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); SKP_Silk_sum_sqr_shift( &rr[ k ], &rr_shifts, r_ptr, subfr_length ); /* rr[ k ] in Q( -rr_shifts ) */ @@ -128,7 +125,7 @@ void SKP_Silk_find_LTP_FIX( } maxRshifts = 0; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { maxRshifts = SKP_max_int( corr_rshifts[ k ], maxRshifts ); } @@ -137,7 +134,7 @@ void SKP_Silk_find_LTP_FIX( LPC_LTP_res_nrg = 0; LPC_res_nrg = 0; SKP_assert( LTP_CORRS_HEAD_ROOM >= 2 ); /* Check that no overflow will happen when adding */ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { LPC_res_nrg = SKP_ADD32( LPC_res_nrg, SKP_RSHIFT( SKP_ADD32( SKP_SMULWB( rr[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /* Q( -maxRshifts ) */ LPC_LTP_res_nrg = SKP_ADD32( LPC_LTP_res_nrg, SKP_RSHIFT( SKP_ADD32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /* Q( -maxRshifts ) */ } @@ -152,7 +149,7 @@ void SKP_Silk_find_LTP_FIX( /* smoothing */ /* d = sum( B, 1 ); */ b_Q14_ptr = b_Q14; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { d_Q14[ k ] = 0; for( i = 0; i < LTP_ORDER; i++ ) { d_Q14[ k ] += b_Q14_ptr[ i ]; @@ -165,7 +162,7 @@ void SKP_Silk_find_LTP_FIX( /* Find maximum absolute value of d_Q14 and the bits used by w in Q0 */ max_abs_d_Q14 = 0; max_w_bits = 0; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { max_abs_d_Q14 = SKP_max_32( max_abs_d_Q14, SKP_abs( d_Q14[ k ] ) ); /* w[ k ] is in Q( 18 - corr_rshifts[ k ] ) */ /* Find bits needed in Q( 18 - maxRshifts ) */ @@ -186,7 +183,7 @@ void SKP_Silk_find_LTP_FIX( temp32 = SKP_RSHIFT( 262, maxRshifts + extra_shifts ) + 1; /* 1e-3f in Q( 18 - (maxRshifts + extra_shifts) ) */ wd = 0; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { /* w has at least 2 bits of headroom so no overflow should happen */ temp32 = SKP_ADD32( temp32, SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ) ); /* Q( 18 - maxRshifts_wxtra ) */ wd = SKP_ADD32( wd, SKP_LSHIFT( SKP_SMULWW( SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ), d_Q14[ k ] ), 2 ) ); /* Q( 18 - maxRshifts_wxtra ) */ @@ -194,7 +191,7 @@ void SKP_Silk_find_LTP_FIX( m_Q12 = SKP_DIV32_varQ( wd, temp32, 12 ); b_Q14_ptr = b_Q14; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { /* w_fix[ k ] from Q( 18 - corr_rshifts[ k ] ) to Q( 16 ) */ if( 2 - corr_rshifts[k] > 0 ) { temp32 = SKP_RSHIFT( w[ k ], 2 - corr_rshifts[ k ] ); @@ -215,10 +212,11 @@ void SKP_Silk_find_LTP_FIX( } temp32 = SKP_DIV32( g_Q26, temp32 ); /* Q14->Q12 */ for( i = 0; i < LTP_ORDER; i++ ) { - b_Q14_ptr[ i ] = SKP_LIMIT( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 ); + b_Q14_ptr[ i ] = SKP_LIMIT_32( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 ); } b_Q14_ptr += LTP_ORDER; } +TOC(find_LTP_FIX) } void SKP_Silk_fit_LTP( diff --git a/src/SKP_Silk_find_pitch_lags_FIX.c b/src_FIX/SKP_Silk_find_pitch_lags_FIX.c similarity index 85% rename from src/SKP_Silk_find_pitch_lags_FIX.c rename to src_FIX/SKP_Silk_find_pitch_lags_FIX.c index dc7b2d328..3601b255a 100644 --- a/src/SKP_Silk_find_pitch_lags_FIX.c +++ b/src_FIX/SKP_Silk_find_pitch_lags_FIX.c @@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "SKP_Silk_main_FIX.h" +#include "SKP_Silk_common_pitch_est_defines.h" /* Find pitch lags */ void SKP_Silk_find_pitch_lags_FIX( @@ -36,29 +37,28 @@ void SKP_Silk_find_pitch_lags_FIX( ) { SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred; - SKP_int buf_len, i; - SKP_int32 scale; + SKP_int buf_len, i, scale; SKP_int32 thrhld_Q15; const SKP_int16 *x_buf, *x_buf_ptr; SKP_int16 Wsig[ FIND_PITCH_LPC_WIN_MAX ], *Wsig_ptr; - SKP_int32 auto_corr[ FIND_PITCH_LPC_ORDER_MAX + 1 ]; - SKP_int16 rc_Q15[ FIND_PITCH_LPC_ORDER_MAX ]; - SKP_int32 A_Q24[ FIND_PITCH_LPC_ORDER_MAX ]; - SKP_int32 FiltState[ FIND_PITCH_LPC_ORDER_MAX ]; - SKP_int16 A_Q12[ FIND_PITCH_LPC_ORDER_MAX ]; + 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 ]; /******************************************/ - /* Setup buffer lengths etc based of Fs. */ + /* Setup buffer lengths etc based on Fs */ /******************************************/ - buf_len = SKP_ADD_LSHIFT( psEnc->sCmn.la_pitch, psEnc->sCmn.frame_length, 1 ); + buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length; /* Safty check */ SKP_assert( buf_len >= psPredSt->pitch_LPC_win_length ); - x_buf = x - psEnc->sCmn.frame_length; + x_buf = x - psEnc->sCmn.ltp_mem_length; /*************************************/ - /* Estimate LPC AR coeficients */ + /* Estimate LPC AR coefficients */ /*************************************/ /* Calculate windowed signal */ @@ -101,7 +101,7 @@ void SKP_Silk_find_pitch_lags_FIX( /*****************************************/ /* LPC analysis filtering */ /*****************************************/ - SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) ); + 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 ) ); @@ -114,9 +114,11 @@ void SKP_Silk_find_pitch_lags_FIX( thrhld_Q15 = SKP_SAT16( thrhld_Q15 ); /*****************************************/ - /* Call Pitch estimator */ + /* Call pitch estimator */ /*****************************************/ +TIC(pitch_analysis_core_FIX) psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->pitchEstimationThreshold_Q16, - ( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity ); + ( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr ); +TOC(pitch_analysis_core_FIX) } diff --git a/src_FIX/SKP_Silk_find_pred_coefs_FIX.c b/src_FIX/SKP_Silk_find_pred_coefs_FIX.c new file mode 100644 index 000000000..efb8ead26 --- /dev/null +++ b/src_FIX/SKP_Silk_find_pred_coefs_FIX.c @@ -0,0 +1,442 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#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_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 */ + const SKP_int16 res_pitch[] /* I Residual from pitch analysis */ +) +{ + SKP_int i; + SKP_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; + SKP_int32 invGains_Q16[ MAX_NB_SUBFR ], local_gains[ MAX_NB_SUBFR ], Wght_Q15[ MAX_NB_SUBFR ]; + SKP_int NLSF_Q15[ MAX_LPC_ORDER ]; + const SKP_int16 *x_ptr; + SKP_int16 *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ]; + 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++ ) { + min_gain_Q16 = SKP_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] ); + } + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + /* Divide to Q16 */ + SKP_assert( psEncCtrl->Gains_Q16[ i ] > 0 ); + /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */ + invGains_Q16[ i ] = SKP_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 ); + + /* Ensure Wght_Q15 a minimum value 1 */ + invGains_Q16[ i ] = SKP_max( invGains_Q16[ i ], 363 ); + + /* Square the inverted gains */ + SKP_assert( invGains_Q16[ i ] == SKP_SAT16( invGains_Q16[ i ] ) ); + tmp = SKP_SMULWB( invGains_Q16[ i ], invGains_Q16[ i ] ); + Wght_Q15[ i ] = SKP_RSHIFT( tmp, 1 ); + + /* Invert the inverted and normalized gains */ + local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] ); + } + + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + /**********/ + /* VOICED */ + /**********/ + SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.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, + 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_FIX( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, + WLTP, psEnc->mu_LTP_Q8, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr); + + /* Control LTP scaling */ + SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl ); + + /* 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 ); + + } else { + /************/ + /* UNVOICED */ + /************/ + /* Create signal with prepended subframes, scaled by inverse gains */ + x_ptr = psEnc->x_buf + psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder; + x_pre_ptr = LPC_in_pre; + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + SKP_Silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ], + psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); + x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder; + x_ptr += psEnc->sCmn.subfr_length; + } + + SKP_memset( psEncCtrl->LTPCoef_Q14, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( SKP_int16 ) ); + psEncCtrl->LTPredCodGain_Q7 = 0; + } + + /* 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, + 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 ); + TOC(PROCESS_LSFS) + + /* Calculate residual energy using quantized LPC coefficients */ + SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains, + psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); + + /* 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.sigtype == SIG_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.sigtype == SIG_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.sigtype == SIG_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; +} + +/* 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]; + } +} + +#endif diff --git a/src/SKP_Silk_init_encoder_FIX.c b/src_FIX/SKP_Silk_init_encoder_FIX.c similarity index 86% rename from src/SKP_Silk_init_encoder_FIX.c rename to src_FIX/SKP_Silk_init_encoder_FIX.c index 457c37b1b..63c378f0f 100644 --- a/src/SKP_Silk_init_encoder_FIX.c +++ b/src_FIX/SKP_Silk_init_encoder_FIX.c @@ -32,14 +32,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /*********************************/ SKP_int SKP_Silk_init_encoder_FIX( SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk encoder state */ -) -{ +) { SKP_int ret = 0; /* Clear the entire encoder state */ SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) ); - /* Initialize to 24 kHz sampling, 20 ms packets, 25 kbps, 0% packet loss, and init non-zero values */ - ret = SKP_Silk_control_encoder_FIX( psEnc, 24, 20, 25, 0, 0, 0, 10, 1 ); + /* Initialize to 24 kHz API sampling, 24 kHz max internal sampling, 20 ms packets, 25 kbps, 0% packet loss, and init non-zero values */ + ret = SKP_Silk_control_encoder_FIX( psEnc, 24000, 24, 20, 25, 0, 0, 0, 10, 0 ); #if HIGH_PASS_INPUT psEnc->variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */ @@ -55,10 +54,8 @@ SKP_int SKP_Silk_init_encoder_FIX( ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD ); /* Initialize NSQ */ - psEnc->sNSQ.prev_inv_gain_Q16 = 65536; /* 1.0 in Q16 */ - psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; /* 1.0 in Q16 */ - - psEnc->sCmn.bitstream_v = USE_BIT_STREAM_V; + psEnc->sNSQ.prev_inv_gain_Q16 = 65536; + psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; return( ret ); } diff --git a/src/SKP_Silk_main_FIX.h b/src_FIX/SKP_Silk_main_FIX.h similarity index 72% rename from src/SKP_Silk_main_FIX.h rename to src_FIX/SKP_Silk_main_FIX.h index ff28f9a13..6d7d0ddc3 100644 --- a/src/SKP_Silk_main_FIX.h +++ b/src_FIX/SKP_Silk_main_FIX.h @@ -34,8 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" #include "SKP_Silk_define_FIX.h" #include "SKP_Silk_PLC.h" -#define TIC(TAG_NAME) -#define TOC(TAG_NAME) +#include "SKP_debug.h" +#include "entenc.h" #ifndef FORCE_CPP_BUILD #ifdef __cplusplus @@ -55,12 +55,13 @@ SKP_int SKP_Silk_init_encoder_FIX( /* Control the Silk encoder */ SKP_int SKP_Silk_control_encoder_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - const SKP_int API_fs_kHz, /* I External (API) sampling rate (kHz) */ + SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */ + const SKP_int32 API_fs_Hz, /* I External (API) sampling rate (Hz) */ + const SKP_int max_internal_fs_kHz,/* I Maximum internal sampling rate (kHz) */ const SKP_int PacketSize_ms, /* I Packet length (ms) */ SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */ const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */ - const SKP_int INBandFec_enabled, /* I Enable (1) / disable (0) inband FEC */ + const SKP_int INBandFEC_enabled, /* I Enable (1) / disable (0) inband FEC */ const SKP_int DTX_enabled, /* I Enable / disable DTX */ const SKP_int InputFramesize_ms, /* I Inputframe in ms */ const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */ @@ -106,10 +107,20 @@ void SKP_Silk_prefilter_FIX( /* Compute noise shaping coefficients and initial gain values */ /**************************************************************/ void SKP_Silk_noise_shape_analysis_FIX( - SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ - SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */ + SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ + SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ const SKP_int16 *pitch_res, /* I LPC residual from pitch analysis */ - const SKP_int16 *x /* I Input signal [ 2 * frame_length + la_shape ]*/ + const SKP_int16 *x /* I Input signal [ frame_length + la_shape ] */ +); + +/* Autocorrelations for a warped frequency axis */ +void SKP_Silk_warped_autocorrelation_FIX( + SKP_int32 *corr, /* O Result [order + 1] */ + SKP_int *scale, /* O Scaling of the correlation vector */ + const SKP_int16 *input, /* I Input data to correlate */ + const SKP_int16 warping_Q16, /* I Warping coefficient */ + const SKP_int length, /* I Length of input */ + const SKP_int order /* I Correlation order (even) */ ); /* Processing of gains */ @@ -118,7 +129,6 @@ void SKP_Silk_process_gains_FIX( SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O Encoder control */ ); - /* Control low bitrate redundancy usage */ void SKP_Silk_LBRR_ctrl_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */ @@ -150,48 +160,50 @@ void SKP_Silk_find_pred_coefs_FIX( ); void SKP_Silk_find_LPC_FIX( - SKP_int NLSF_Q15[], /* O LSFs */ - SKP_int *interpIndex, /* O LSF interpolation index, only used for LSF interpolation */ - const SKP_int prev_NLSFq_Q15[], /* I previous LSFs, only used for LSF interpolation */ - const SKP_int useInterpolatedLSFs, /* I Flag */ - const SKP_int LPC_order, /* I LPC order */ - const SKP_int16 x[], /* I Input signal */ - const SKP_int subfr_length /* I Input signal subframe length including preceeding samples */ + SKP_int NLSF_Q15[], /* O NLSFs */ + SKP_int *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 */ + const SKP_int16 x[], /* I Input signal */ + const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */ + const SKP_int nb_subfr /* I: Number of subframes */ ); void SKP_Silk_LTP_analysis_filter_FIX( - SKP_int16 *LTP_res, /* O: LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length ) */ - const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each NB_SUBFR subframe */ - const SKP_int pitchL[ NB_SUBFR ], /* I: Pitch lag, one for each subframe */ - const SKP_int32 invGains_Qxx[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */ - const SKP_int Qxx, /* I: Inverse quantization gains Q domain */ - const SKP_int subfr_length, /* I: Length of each subframe */ - const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */ + SKP_int16 *LTP_res, /* O: LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */ + const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */ + const SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I: Pitch lag, one for each subframe */ + const SKP_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */ + const SKP_int subfr_length, /* I: Length of each subframe */ + const SKP_int nb_subfr, /* I: Number of subframes */ + const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */ ); /* Finds LTP vector from correlations */ void SKP_Silk_find_LTP_FIX( - SKP_int16 b_Q14[ NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ - SKP_int32 WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ - SKP_int *LTPredCodGain_Q7, /* O LTP coding gain */ - const SKP_int16 r_first[], /* I residual signal after LPC signal + state for first 10 ms */ - const SKP_int16 r_last[], /* I residual signal after LPC signal + state for last 10 ms */ - const SKP_int lag[ NB_SUBFR ], /* I LTP lags */ - const SKP_int32 Wght_Q15[ NB_SUBFR ], /* I weights */ - const SKP_int subfr_length, /* I subframe length */ - const SKP_int mem_offset, /* I number of samples in LTP memory */ - SKP_int corr_rshifts[ NB_SUBFR ] /* O right shifts applied to correlations */ + SKP_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ + SKP_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ + SKP_int *LTPredCodGain_Q7, /* O LTP coding gain */ + const SKP_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */ + const SKP_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ + const SKP_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ + const SKP_int subfr_length, /* I subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int mem_offset, /* I number of samples in LTP memory */ + SKP_int corr_rshifts[ MAX_NB_SUBFR ] /* O right shifts applied to correlations */ ); /* LTP tap quantizer */ void SKP_Silk_quant_LTP_gains_FIX( - SKP_int16 B_Q14[], /* I/O (un)quantized LTP gains */ - SKP_int cbk_index[], /* O Codebook Index */ - SKP_int *periodicity_index, /* O Periodicity Index */ - const SKP_int32 W_Q18[], /* I Error Weights in Q18 */ - SKP_int mu_Q8, /* I Mu value (R/D tradeoff) */ - SKP_int lowComplexity /* I Flag for low complexity */ + SKP_int16 B_Q14[], /* I/O (un)quantized LTP gains */ + SKP_int cbk_index[], /* O Codebook Index */ + SKP_int *periodicity_index, /* O Periodicity Index */ + const SKP_int32 W_Q18[], /* I Error Weights in Q18 */ + SKP_int mu_Q8, /* I Mu value (R/D tradeoff) */ + SKP_int lowComplexity, /* I Flag for low complexity */ + const SKP_int nb_subfr /* I number of subframes */ ); /******************/ @@ -270,7 +282,7 @@ void SKP_Silk_corrMatrix_FIX( /* Calculates correlation vector X'*t */ void SKP_Silk_corrVector_FIX( const SKP_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ - const SKP_int16 *t, /* I target vector [L] */ + const SKP_int16 *t, /* I Target vector [L] */ const SKP_int L, /* I Length of vectors */ const SKP_int order, /* I Max lag for correlation */ SKP_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */ @@ -306,14 +318,14 @@ SKP_int32 SKP_Silk_residual_energy16_covar_FIX( /* Calculates residual energies of input subframes where all subframes have LPC_order */ /* of preceeding samples */ void SKP_Silk_residual_energy_FIX( - SKP_int32 nrgs[ NB_SUBFR ], /* O Residual energy per subframe */ - SKP_int nrgsQ[ NB_SUBFR ], /* O Q value per subframe */ - const SKP_int16 x[], /* I Input signal */ - const SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I AR coefs for each frame half */ - const SKP_int32 gains_Qx[ NB_SUBFR ], /* I Quantization gains in Qx */ - const SKP_int Qx, /* I Quantization gains Q value */ - const SKP_int subfr_length, /* I Subframe length */ - const SKP_int LPC_order /* I LPC order */ + SKP_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + SKP_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ + const SKP_int16 x[], /* I Input signal */ + const SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ + const SKP_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I Number of subframes */ + const SKP_int LPC_order /* I LPC order */ ); #ifndef FORCE_CPP_BUILD diff --git a/src/SKP_Silk_noise_shape_analysis_FIX.c b/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c similarity index 68% rename from src/SKP_Silk_noise_shape_analysis_FIX.c rename to src_FIX/SKP_Silk_noise_shape_analysis_FIX.c index b0f884958..a695d1dd2 100644 --- a/src/SKP_Silk_noise_shape_analysis_FIX.c +++ b/src_FIX/SKP_Silk_noise_shape_analysis_FIX.c @@ -28,6 +28,94 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main_FIX.h" #include "SKP_Silk_perceptual_parameters_FIX.h" +/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a */ +/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.) */ +SKP_INLINE SKP_int32 warped_gain( // gain in Q16 + const SKP_int32 *coefs_Q24, + SKP_int lambda_Q16, + SKP_int order +) { + SKP_int i; + SKP_int32 gain_Q24; + + lambda_Q16 = -lambda_Q16; + gain_Q24 = coefs_Q24[ order - 1 ]; + for( i = order - 2; i >= 0; i-- ) { + gain_Q24 = SKP_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 ); + } + gain_Q24 = SKP_SMLAWB( 1 << 24, gain_Q24, -lambda_Q16 ); + return SKP_INVERSE32_varQ( gain_Q24, 40 ); +} + +/* Convert warped filter coefficients to monic pseudo-warped coefficients */ +SKP_INLINE void warped_true2monic_coefs( + SKP_int32 *coefs_Q24, + SKP_int lambda_Q16, + SKP_int order +) { + SKP_int i; + SKP_int32 gain_Q16, nom_Q16, den_Q24; + + lambda_Q16 = -lambda_Q16; + for( i = order - 1; i > 0; i-- ) { + coefs_Q24[ i - 1 ] = SKP_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16 ); + } + nom_Q16 = SKP_SMLAWB( 1 << 16, lambda_Q16, -lambda_Q16 ); + den_Q24 = SKP_SMLAWB( 1 << 24, coefs_Q24[ 0 ], -lambda_Q16 ); + gain_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 ); + for( i = 0; i < order; i++ ) { + coefs_Q24[ i ] = SKP_SMULWW( gain_Q16, coefs_Q24[ i ] ); + } +} + +/* Limit max amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ +SKP_INLINE void limit_warped_coefs( + SKP_int32 *coefs_syn_Q24, + SKP_int32 *coefs_ana_Q24, + SKP_int lambda_Q16, + SKP_int32 limit_Q24, + SKP_int order +) { + SKP_int i, iter, ind; + SKP_int32 tmp, maxabs_Q24, chirp_Q16; + + for( iter = 0; iter < 10; iter++ ) { + /* Find maximum absolute value */ + ind = 1; + maxabs_Q24 = SKP_abs( coefs_syn_Q24[ ind ] ); + for( i = 2; i < order - 1; i++ ) { + tmp = SKP_abs( coefs_syn_Q24[ i ] ); + if( tmp > maxabs_Q24 ) { + maxabs_Q24 = tmp; + ind = i; + } + } + if( maxabs_Q24 <= limit_Q24 ) { + return; + } + + /* Convert to true warped coefficients */ + for( i = 1; i < order; i++ ) { + coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 ); + coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 ); + } + + /* Apply bandwidth expansion */ + chirp_Q16 = SKP_FIX_CONST( 0.99, 16 ) - SKP_DIV32_varQ( + SKP_SMULWB( maxabs_Q24 - limit_Q24, SKP_SMLABB( SKP_FIX_CONST( 0.8, 10 ), SKP_FIX_CONST( 0.1, 10 ), iter ) ), + SKP_MUL( maxabs_Q24, ind + 1 ), 22 ); + SKP_Silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 ); + SKP_Silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 ); + + /* Convert back to monic warped coefficients */ + lambda_Q16 = -lambda_Q16; + for( i = order - 1; i > 0; i-- ) { + coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 ); + coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 ); + } + lambda_Q16 = -lambda_Q16; + } +} /**************************************************************/ /* Compute noise shaping coefficients and initial gain values */ @@ -36,30 +124,35 @@ void SKP_Silk_noise_shape_analysis_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ const SKP_int16 *pitch_res, /* I LPC residual from pitch analysis */ - const SKP_int16 *x /* I Input signal [ 2 * frame_length + la_shape ]*/ + const SKP_int16 *x /* I Input signal [ frame_length + la_shape ] */ ) { SKP_Silk_shape_state_FIX *psShapeSt = &psEnc->sShape; - SKP_int k, nSamples, lz, Qnrg, b_Q14, scale = 0, sz; + SKP_int k, i, nSamples, Qnrg, b_Q14, scale = 0, sz; SKP_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32; SKP_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7; SKP_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; - SKP_int32 auto_corr[ SHAPE_LPC_ORDER_MAX + 1 ]; - SKP_int32 refl_coef_Q16[ SHAPE_LPC_ORDER_MAX ]; - SKP_int32 AR_Q24[ SHAPE_LPC_ORDER_MAX ]; + SKP_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; + SKP_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; + 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[ NB_SUBFR ], Qnrg_vec[ NB_SUBFR ]; + SKP_int32 sqrt_nrg[ MAX_NB_SUBFR ], Qnrg_vec[ MAX_NB_SUBFR ]; /* Point to start of first LPC analysis block */ - x_ptr = x + psEnc->sCmn.la_shape - SKP_SMULBB( SHAPE_LPC_WIN_MS, psEnc->sCmn.fs_kHz ) + psEnc->sCmn.frame_length / NB_SUBFR; + x_ptr = x + psEnc->sCmn.la_shape - SKP_SMULBB( SHAPE_LPC_WIN_MS, psEnc->sCmn.fs_kHz ) + psEnc->sCmn.subfr_length; /****************/ /* CONTROL SNR */ /****************/ +#if DEACTIVATE_SNR_FEEDBACK + psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7; +#else /* 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 ), 3277 ); +#endif /* Reduce SNR_dB if inband FEC used */ if( psEnc->speech_activity_Q8 > LBRR_SPEECH_ACTIVITY_THRES_Q8 ) { @@ -72,8 +165,9 @@ void SKP_Silk_noise_shape_analysis_FIX( /* Input quality is the average of the quality in the lowest two VAD bands */ psEncCtrl->input_quality_Q14 = ( SKP_int )SKP_RSHIFT( ( SKP_int32 )psEncCtrl->input_quality_bands_Q15[ 0 ] + psEncCtrl->input_quality_bands_Q15[ 1 ], 2 ); + /* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */ - psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 - ( 18 << 7 ), 4 ) ), 1 ); + psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 - ( 17 << 7 ), 4 ) ), 1 ); /* Reduce coding SNR during low speech activity */ b_Q8 = ( 1 << 8 ) - psEnc->speech_activity_Q8; @@ -106,7 +200,7 @@ void SKP_Silk_noise_shape_analysis_FIX( energy_variation_Q7 = 0; log_energy_prev_Q7 = 0; pitch_res_ptr = pitch_res; - for( k = 0; k < FRAME_LENGTH_MS / 2; k++ ) { + for( k = 0; k < SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { SKP_Silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples ); nrg += SKP_RSHIFT( nSamples, scale ); // Q(-scale) @@ -118,7 +212,7 @@ void SKP_Silk_noise_shape_analysis_FIX( pitch_res_ptr += nSamples; } - psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 - ( 5 << 7 ), 6554 ) ), 7 ); // 6554_Q16 = 0.1_Q0 + psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 - ( 5 << 7 ), 6554 ) ), 7 ); // 6554_Q16 = 0.1_Q0 /* Set quantization offset depending on sparseness measure */ if( psEncCtrl->sparseness_Q8 > SPARSENESS_THRESHOLD_QNT_OFFSET_Q8 ) { @@ -145,44 +239,50 @@ void SKP_Silk_noise_shape_analysis_FIX( /* BWExp1 will be applied after BWExp2, so make it relative */ BWExp1_Q16 = SKP_DIV32_16( SKP_LSHIFT( BWExp1_Q16, 14 ), SKP_RSHIFT( BWExp2_Q16, 2 ) ); + /* Warping coefficient */ + psEncCtrl->sCmn.warping_Q16 = psEnc->sCmn.fs_kHz * WARPING_MULTIPLIER_Q16; + psEncCtrl->sCmn.warping_Q16 = SKP_min( psEncCtrl->sCmn.warping_Q16, 32767 ); + /********************************************/ /* Compute noise shaping AR coefs and gains */ /********************************************/ sz = ( SKP_int )SKP_SMULBB( SHAPE_LPC_WIN_MS, psEnc->sCmn.fs_kHz ); - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Apply window */ SKP_Silk_apply_sine_window( x_windowed, x_ptr, 0, SHAPE_LPC_WIN_MS * psEnc->sCmn.fs_kHz ); /* Update pointer: next LPC analysis block */ - x_ptr += psEnc->sCmn.frame_length / NB_SUBFR; + x_ptr += psEnc->sCmn.subfr_length; - /* Calculate auto correlation */ - SKP_Silk_autocorr( auto_corr, &scale, x_windowed, sz, psEnc->sCmn.shapingLPCOrder + 1 ); + /* Calculate warped auto correlation */ + SKP_Silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, psEncCtrl->sCmn.warping_Q16, sz, psEnc->sCmn.shapingLPCOrder ); /* Add white noise, as a fraction of energy */ auto_corr[0] = SKP_ADD32( auto_corr[0], SKP_max_32( SKP_SMULWB( SKP_RSHIFT( auto_corr[ 0 ], 4 ), SHAPE_WHITE_NOISE_FRACTION_Q20 ), 1 ) ); /* Calculate the reflection coefficients using schur */ nrg = SKP_Silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder ); + SKP_assert( nrg >= 0 ); /* Convert reflection coefficients to prediction coefficients */ - SKP_Silk_k2a_Q16( AR_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); + SKP_Silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); - /* Bandwidth expansion for synthesis filter shaping */ - SKP_Silk_bwexpander_32( AR_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 ); + /* Convert residual energy to non-warped scale */ + gain_mult_Q16 = warped_gain( AR2_Q24, psEncCtrl->sCmn.warping_Q16, psEnc->sCmn.shapingLPCOrder ); + gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, gain_mult_Q16 ); + SKP_assert( gain_mult_Q16 >= 0 ); // If breaking, add dynamic scaling + nrg = SKP_SMULWW( nrg, gain_mult_Q16 ); + SKP_assert( nrg >= 0 ); // If breaking, add dynamic scaling - /* Make sure to fit in Q13 SKP_int16 */ - SKP_Silk_LPC_fit( &psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ], AR_Q24, 13, psEnc->sCmn.shapingLPCOrder ); + /* Bandwidth expansion for synthesis filter shaping */ + SKP_Silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 ); /* Compute noise shaping filter coefficients */ - SKP_memcpy( - &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ], - &psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ], - psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int16 ) ); + SKP_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) ); /* Bandwidth expansion for analysis filter shaping */ SKP_assert( BWExp1_Q16 <= ( 1 << 16 ) ); // If ever breaking, use LPC_stabilize() in these cases to stay within range - SKP_Silk_bwexpander( &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); + SKP_Silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); /* Increase residual energy */ nrg = SKP_SMLAWB( nrg, SKP_RSHIFT( auto_corr[ 0 ], 8 ), SHAPE_MIN_ENERGY_RATIO_Q24 ); @@ -204,14 +304,27 @@ void SKP_Silk_noise_shape_analysis_FIX( Qnrg_vec[ k ] = Qnrg; psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( tmp32, 16 - Qnrg ); + /* Ratio of prediction gains, in energy domain */ - SKP_Silk_LPC_inverse_pred_gain_Q13( &pre_nrg_Q30, &psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder ); - SKP_Silk_LPC_inverse_pred_gain_Q13( &nrg, &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder ); + SKP_Silk_LPC_inverse_pred_gain_Q24( &pre_nrg_Q30, AR2_Q24, psEnc->sCmn.shapingLPCOrder ); + SKP_Silk_LPC_inverse_pred_gain_Q24( &nrg, AR1_Q24, psEnc->sCmn.shapingLPCOrder ); + + //psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg; + pre_nrg_Q30 = SKP_LSHIFT32( SKP_SMULWB( pre_nrg_Q30, SKP_FIX_CONST( 0.7, 15 ) ), 1 ); + psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int ) SKP_FIX_CONST( 0.3, 14 ) + SKP_DIV32_varQ( pre_nrg_Q30, nrg, 14 ); - lz = SKP_min_32( SKP_Silk_CLZ32( pre_nrg_Q30 ) - 1, 19 ); - pre_nrg_Q30 = SKP_DIV32( SKP_LSHIFT( pre_nrg_Q30, lz ), SKP_RSHIFT( nrg, 20 - lz ) + 1 ); // Q20 - pre_nrg_Q30 = SKP_RSHIFT( SKP_LSHIFT_SAT32( pre_nrg_Q30, 9 ), 1 ); /* Q28 */ - psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int )SKP_Silk_SQRT_APPROX( pre_nrg_Q30 ); + /* Convert to monic warped prediction coefficients */ + warped_true2monic_coefs( AR1_Q24, psEncCtrl->sCmn.warping_Q16, psEnc->sCmn.shapingLPCOrder ); + warped_true2monic_coefs( AR2_Q24, psEncCtrl->sCmn.warping_Q16, psEnc->sCmn.shapingLPCOrder ); + + /* Limit absolute values */ + limit_warped_coefs( AR2_Q24, AR1_Q24, psEncCtrl->sCmn.warping_Q16, SKP_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder ); + + /* Convert from Q24 to Q13 and store in int16 */ + for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) { + psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) ); + psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) ); + } } /*****************/ @@ -225,12 +338,12 @@ void SKP_Silk_noise_shape_analysis_FIX( gain_add_Q16 = SKP_ADD_SAT32( gain_add_Q16, tmp32 ); SKP_assert( gain_mult_Q16 >= 0 ); - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); } - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->Gains_Q16[ k ] = SKP_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 ); psEnc->avgGain_Q16 = SKP_ADD_SAT32( psEnc->avgGain_Q16, @@ -263,7 +376,7 @@ void SKP_Silk_noise_shape_analysis_FIX( } } - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->GainsPre_Q14[ k ] = SKP_SMULWB( gain_mult_Q16, psEncCtrl->GainsPre_Q14[ k ] ); } @@ -276,7 +389,7 @@ void SKP_Silk_noise_shape_analysis_FIX( /* 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( 3277, psEnc->sCmn.fs_kHz ); // 0.2_Q0 = 3277_Q14 - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { b_Q14 = fs_kHz_inv + SKP_DIV32_16( ( 3 << 14 ), psEncCtrl->sCmn.pitchL[ k ] ); /* Pack two coefficients in one int32 */ psEncCtrl->LF_shp_Q14[ k ] = SKP_LSHIFT( ( 1 << 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 ); @@ -290,7 +403,7 @@ void SKP_Silk_noise_shape_analysis_FIX( /* Pack two coefficients in one int32 */ psEncCtrl->LF_shp_Q14[ 0 ] = SKP_LSHIFT( ( 1 << 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, SKP_SMULWB( 39322, b_Q14 ) ), 16 ); // 0.6_Q0 = 39322_Q16 psEncCtrl->LF_shp_Q14[ 0 ] |= (SKP_uint16)( b_Q14 - ( 1 << 14 ) ); - for( k = 1; k < NB_SUBFR; k++ ) { + for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ k - 1 ]; } Tilt_Q16 = -HP_NOISE_COEF_Q16; @@ -323,7 +436,7 @@ void SKP_Silk_noise_shape_analysis_FIX( /*************************/ /* Smooth over subframes */ /*************************/ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < MAX_NB_SUBFR; k++ ) { psShapeSt->HarmBoost_smth_Q16 = SKP_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SUBFR_SMTH_COEF_Q16 ); psShapeSt->HarmShapeGain_smth_Q16 = diff --git a/src_FIX/SKP_Silk_perceptual_parameters_FIX.h b/src_FIX/SKP_Silk_perceptual_parameters_FIX.h new file mode 100644 index 000000000..2df96505c --- /dev/null +++ b/src_FIX/SKP_Silk_perceptual_parameters_FIX.h @@ -0,0 +1,117 @@ +/*********************************************************************** +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_PERCEPTUAL_PARAMETERS_FIX_H +#define SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H + +#include "SKP_Silk_perceptual_parameters.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* reduction in coding SNR during low speech activity */ +#define BG_SNR_DECR_dB_Q7 SKP_FIX_CONST( BG_SNR_DECR_dB, 7 ) + +/* factor for reducing quantization noise during voiced speech */ +#define HARM_SNR_INCR_dB_Q7 SKP_FIX_CONST( HARM_SNR_INCR_dB, 7 ) + +/* factor for reducing quantization noise for unvoiced sparse signals */ +#define SPARSE_SNR_INCR_dB_Q7 SKP_FIX_CONST( SPARSE_SNR_INCR_dB, 7 ) + +/* threshold for sparseness measure above which to use lower quantization offset during unvoiced */ +#define SPARSENESS_THRESHOLD_QNT_OFFSET_Q8 SKP_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) + + +/* noise shaping filter chirp factor */ +#define BANDWIDTH_EXPANSION_Q16 SKP_FIX_CONST( BANDWIDTH_EXPANSION, 16 ) + +/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */ +#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA_Q16 SKP_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) + +/* factor to reduce all bandwidth expansion coefficients for super wideband, relative to wideband */ +#define SWB_BANDWIDTH_EXPANSION_REDUCTION_Q16 SKP_FIX_CONST( SWB_BANDWIDTH_EXPANSION_REDUCTION, 16 ) + +/* gain reduction for fricatives */ +#define DE_ESSER_COEF_SWB_dB_Q7 SKP_FIX_CONST( DE_ESSER_COEF_SWB_dB, 7 ) +#define DE_ESSER_COEF_WB_dB_Q7 SKP_FIX_CONST( DE_ESSER_COEF_WB_dB, 7 ) + +/* extra harmonic boosting (signal shaping) at low bitrates */ +#define LOW_RATE_HARMONIC_BOOST_Q16 SKP_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) + +/* extra harmonic boosting (signal shaping) for noisy input signals */ +#define LOW_INPUT_QUALITY_HARMONIC_BOOST_Q16 SKP_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) + +/* harmonic noise shaping */ +#define HARMONIC_SHAPING_Q16 SKP_FIX_CONST( HARMONIC_SHAPING, 16 ) + +/* extra harmonic noise shaping for high bitrates or noisy input */ +#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING_Q16 SKP_FIX_CONST( HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16 ) + + +/* parameter for shaping noise towards higher frequencies */ +#define HP_NOISE_COEF_Q16 SKP_FIX_CONST( HP_NOISE_COEF, 16 ) + +/* parameter for shaping noise extra towards higher frequencies during voiced speech */ +#define HARM_HP_NOISE_COEF_Q24 SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ) + +/* parameter for applying a high-pass tilt to the input signal */ +#define INPUT_TILT_Q26 SKP_FIX_CONST( INPUT_TILT, 26 ) + +/* parameter for extra high-pass tilt to the input signal at high rates */ +#define HIGH_RATE_INPUT_TILT_Q12 SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) + +/* parameter for reducing noise at the very low frequencies */ +#define LOW_FREQ_SHAPING_Q0 SKP_FIX_CONST( LOW_FREQ_SHAPING, 0 ) + +/* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */ +#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR_Q1 SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 1 ) + +/* fraction added to first autocorrelation value */ +#define SHAPE_WHITE_NOISE_FRACTION_Q20 SKP_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) + +/* fraction of first autocorrelation value added to residual energy value; limits prediction gain */ +#define SHAPE_MIN_ENERGY_RATIO_Q24 SKP_FIX_CONST( SHAPE_MIN_ENERGY_RATIO, 24 ) + +/* noise floor to put a low limit on the quantization step size */ +#define NOISE_FLOOR_dB_Q7 SKP_FIX_CONST( NOISE_FLOOR_dB, 7 ) + +/* noise floor relative to active speech gain level */ +#define RELATIVE_MIN_GAIN_dB_Q7 SKP_FIX_CONST( RELATIVE_MIN_GAIN_dB, 7 ) + +/* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */ +#define GAIN_SMOOTHING_COEF_Q10 SKP_FIX_CONST( GAIN_SMOOTHING_COEF, 10 ) + +/* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */ +#define SUBFR_SMTH_COEF_Q16 SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) + +#ifdef __cplusplus +} +#endif + +#endif //SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H diff --git a/src/SKP_Silk_prefilter_FIX.c b/src_FIX/SKP_Silk_prefilter_FIX.c similarity index 68% rename from src/SKP_Silk_prefilter_FIX.c rename to src_FIX/SKP_Silk_prefilter_FIX.c index d4c98b680..1b7dcd2d7 100644 --- a/src/SKP_Silk_prefilter_FIX.c +++ b/src_FIX/SKP_Silk_prefilter_FIX.c @@ -40,6 +40,47 @@ SKP_INLINE void SKP_Silk_prefilt_FIX( SKP_int length /* I Length of signals */ ); +void SKP_Silk_warped_LPC_analysis_filter_FIX( + SKP_int32 state[], /* I/O State [order + 1] */ + SKP_int16 res[], /* O Residual signal [length] */ + const SKP_int16 coef_Q13[], /* I Coefficients [order] */ + const SKP_int16 input[], /* I Input signal [length] */ + const SKP_int16 lambda_Q16, /* I Warping factor */ + const SKP_int length, /* I Length of input signal */ + const SKP_int order /* I Filter order (even) */ +) +{ + SKP_int n, i; + SKP_int32 acc_Q11, tmp1, tmp2; + + /* Order must be even */ + SKP_assert( ( order & 1 ) == 0 ); + + for( n = 0; n < length; n++ ) { + /* Output of lowpass section */ + tmp2 = SKP_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 ); + state[ 0 ] = SKP_LSHIFT( input[ n ], 14 ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 ); + state[ 1 ] = tmp2; + acc_Q11 = SKP_SMULWB( tmp2, coef_Q13[ 0 ] ); + /* Loop over allpass sections */ + for( i = 2; i < order; i += 2 ) { + /* Output of allpass section */ + tmp2 = SKP_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 ); + state[ i ] = tmp1; + acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 ); + state[ i + 1 ] = tmp2; + acc_Q11 = SKP_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] ); + } + state[ order ] = tmp1; + acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] ); + res[ n ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )input[ n ] - SKP_RSHIFT_ROUND( acc_Q11, 11 ) ); + } +} + void SKP_Silk_prefilter_FIX( SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ const SKP_Silk_encoder_control_FIX *psEncCtrl, /* I Encoder control FIX */ @@ -49,20 +90,21 @@ void SKP_Silk_prefilter_FIX( { SKP_Silk_prefilter_state_FIX *P = &psEnc->sPrefilt; SKP_int j, k, lag; - SKP_int32 tmp_32, B_Q12; + SKP_int32 tmp_32; const SKP_int16 *AR1_shp_Q13; const SKP_int16 *px; - SKP_int16 *pxw, *pst_res; - SKP_int HarmShapeGain_Q12, Tilt_Q14, LF_shp_Q14; - SKP_int32 HarmShapeFIRPacked_Q12; - SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / NB_SUBFR ], filterState[ MAX_LPC_ORDER ]; - SKP_int16 st_res[ ( MAX_FRAME_LENGTH / NB_SUBFR ) + MAX_LPC_ORDER ]; + SKP_int16 *pxw; + SKP_int HarmShapeGain_Q12, Tilt_Q14; + SKP_int32 HarmShapeFIRPacked_Q12, LF_shp_Q14; + SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / MAX_NB_SUBFR ]; + SKP_int16 st_res[ ( MAX_FRAME_LENGTH / MAX_NB_SUBFR ) + MAX_LPC_ORDER ]; + SKP_int16 B_Q12[ 2 ]; /* Setup pointers */ px = x; pxw = xw; lag = P->lagPrev; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Update Variables that change per sub frame */ if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { lag = psEncCtrl->sCmn.pitchL[ k ]; @@ -71,36 +113,29 @@ void SKP_Silk_prefilter_FIX( /* Noise shape parameters */ HarmShapeGain_Q12 = SKP_SMULWB( psEncCtrl->HarmShapeGain_Q14[ k ], 16384 - psEncCtrl->HarmBoost_Q14[ k ] ); SKP_assert( HarmShapeGain_Q12 >= 0 ); - HarmShapeFIRPacked_Q12 = SKP_RSHIFT( HarmShapeGain_Q12, 2 ); + HarmShapeFIRPacked_Q12 = SKP_RSHIFT( HarmShapeGain_Q12, 2 ); HarmShapeFIRPacked_Q12 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q12, 1 ), 16 ); Tilt_Q14 = psEncCtrl->Tilt_Q14[ k ]; LF_shp_Q14 = psEncCtrl->LF_shp_Q14[ k ]; - AR1_shp_Q13 = &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ]; + AR1_shp_Q13 = &psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER ]; /* Short term FIR filtering*/ - SKP_memset( filterState, 0, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) ); - SKP_Silk_MA_Prediction_Q13( px - psEnc->sCmn.shapingLPCOrder, AR1_shp_Q13, filterState, - st_res, psEnc->sCmn.subfr_length + psEnc->sCmn.shapingLPCOrder, psEnc->sCmn.shapingLPCOrder ); - - pst_res = st_res + psEnc->sCmn.shapingLPCOrder; /* Point to first sample */ + SKP_Silk_warped_LPC_analysis_filter_FIX( P->sAR_shp1, st_res, AR1_shp_Q13, px, + psEncCtrl->sCmn.warping_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder ); /* reduce (mainly) low frequencies during harmonic emphasis */ - B_Q12 = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 ); + B_Q12[ 0 ] = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 ); tmp_32 = SKP_SMLABB( INPUT_TILT_Q26, psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 ); /* Q26 */ tmp_32 = SKP_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, HIGH_RATE_INPUT_TILT_Q12 ); /* Q26 */ tmp_32 = SKP_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] ); /* Q24 */ tmp_32 = SKP_RSHIFT_ROUND( tmp_32, 12 ); /* Q12 */ - B_Q12 |= SKP_LSHIFT( SKP_SAT16( tmp_32 ), 16 ); + B_Q12[ 1 ]= SKP_SAT16( tmp_32 ); - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLABB and SMLABT instructions should solve the problem. */ - x_filt_Q12[ 0 ] = SKP_SMLABT( SKP_SMULBB( pst_res[ 0 ], B_Q12 ), P->sHarmHP, B_Q12 ); + x_filt_Q12[ 0 ] = SKP_SMLABB( SKP_SMULBB( st_res[ 0 ], B_Q12[ 0 ] ), P->sHarmHP, B_Q12[ 1 ] ); for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) { - x_filt_Q12[ j ] = SKP_SMLABT( SKP_SMULBB( pst_res[ j ], B_Q12 ), pst_res[ j - 1 ], B_Q12 ); + x_filt_Q12[ j ] = SKP_SMLABB( SKP_SMULBB( st_res[ j ], B_Q12[ 0 ] ), st_res[ j - 1 ], B_Q12[ 1 ] ); } - P->sHarmHP = pst_res[ psEnc->sCmn.subfr_length - 1 ]; + P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ]; SKP_Silk_prefilt_FIX( P, x_filt_Q12, pxw, HarmShapeFIRPacked_Q12, Tilt_Q14, LF_shp_Q14, lag, psEnc->sCmn.subfr_length ); @@ -109,7 +144,7 @@ void SKP_Silk_prefilter_FIX( pxw += psEnc->sCmn.subfr_length; } - P->lagPrev = psEncCtrl->sCmn.pitchL[ NB_SUBFR - 1 ]; + P->lagPrev = psEncCtrl->sCmn.pitchL[ MAX_NB_SUBFR - 1 ]; } /* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal */ @@ -147,13 +182,13 @@ SKP_INLINE void SKP_Silk_prefilt_FIX( n_LTP_Q12 = 0; } - n_LF_Q10 = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 ); n_Tilt_Q10 = SKP_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 ); + n_LF_Q10 = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 ); sLF_AR_shp_Q12 = SKP_SUB32( st_res_Q12[ i ], SKP_LSHIFT( n_Tilt_Q10, 2 ) ); sLF_MA_shp_Q12 = SKP_SUB32( sLF_AR_shp_Q12, SKP_LSHIFT( n_LF_Q10, 2 ) ); - LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; + LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; LTP_shp_buf[ LTP_shp_buf_idx ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) ); xw[i] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 12 ) ); diff --git a/src/SKP_Silk_process_NLSFs_FIX.c b/src_FIX/SKP_Silk_process_NLSFs_FIX.c similarity index 100% rename from src/SKP_Silk_process_NLSFs_FIX.c rename to src_FIX/SKP_Silk_process_NLSFs_FIX.c diff --git a/src/SKP_Silk_process_gains_FIX.c b/src_FIX/SKP_Silk_process_gains_FIX.c similarity index 92% rename from src/SKP_Silk_process_gains_FIX.c rename to src_FIX/SKP_Silk_process_gains_FIX.c index e6400aa37..272fd29d6 100644 --- a/src/SKP_Silk_process_gains_FIX.c +++ b/src_FIX/SKP_Silk_process_gains_FIX.c @@ -41,7 +41,7 @@ void SKP_Silk_process_gains_FIX( if( psEncCtrl->sCmn.sigtype == SIG_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 - (12 << 7), 4 ) ); - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { psEncCtrl->Gains_Q16[ k ] = SKP_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 ); } } @@ -51,7 +51,7 @@ void SKP_Silk_process_gains_FIX( InvMaxSqrVal_Q16 = SKP_DIV32_16( SKP_Silk_log2lin( SKP_SMULWB( (69 << 7) - psEncCtrl->current_SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 )) ), psEnc->sCmn.subfr_length ); - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Soft limit on ratio residual energy and squared gains */ ResNrg = psEncCtrl->ResNrg[ k ]; ResNrgPart = SKP_SMULWW( ResNrg, InvMaxSqrVal_Q16 ); @@ -84,7 +84,7 @@ void SKP_Silk_process_gains_FIX( /* Noise shaping quantization */ SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, psEncCtrl->Gains_Q16, - &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf ); + &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf, 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.sigtype == SIG_TYPE_VOICED ) { if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > ( 1 << 7 ) ) { @@ -96,19 +96,18 @@ void SKP_Silk_process_gains_FIX( /* Quantizer boundary adjustment */ if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { - psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.3, 10 ) - - SKP_SMULWB( SKP_FIX_CONST( 0.5, 18 ), psEnc->speech_activity_Q8 ) + psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.2, 10 ) + - SKP_SMULWB( SKP_FIX_CONST( 0.4, 18 ), psEnc->speech_activity_Q8 ) - SKP_SMULWB( SKP_FIX_CONST( 0.3, 12 ), psEncCtrl->input_quality_Q14 ) + SKP_SMULBB( SKP_FIX_CONST( 0.2, 10 ), psEncCtrl->sCmn.QuantOffsetType ) - SKP_SMULWB( SKP_FIX_CONST( 0.1, 12 ), psEncCtrl->coding_quality_Q14 ); } else { - psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.3, 10 ) - - SKP_SMULWB( SKP_FIX_CONST( 0.5, 18 ), psEnc->speech_activity_Q8 ) + psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.2, 10 ) + - SKP_SMULWB( SKP_FIX_CONST( 0.4, 18 ), psEnc->speech_activity_Q8 ) - SKP_SMULWB( SKP_FIX_CONST( 0.4, 12 ), psEncCtrl->input_quality_Q14 ) + SKP_SMULBB( SKP_FIX_CONST( 0.4, 10 ), psEncCtrl->sCmn.QuantOffsetType ) - SKP_SMULWB( SKP_FIX_CONST( 0.1, 12 ), psEncCtrl->coding_quality_Q14 ); } SKP_assert( psEncCtrl->Lambda_Q10 >= 0 ); SKP_assert( psEncCtrl->Lambda_Q10 < SKP_FIX_CONST( 2, 10 ) ); - } diff --git a/src/SKP_Silk_quant_LTP_gains_FIX.c b/src_FIX/SKP_Silk_quant_LTP_gains_FIX.c similarity index 76% rename from src/SKP_Silk_quant_LTP_gains_FIX.c rename to src_FIX/SKP_Silk_quant_LTP_gains_FIX.c index 63c5a0f1a..74ea26cbf 100644 --- a/src/SKP_Silk_quant_LTP_gains_FIX.c +++ b/src_FIX/SKP_Silk_quant_LTP_gains_FIX.c @@ -28,15 +28,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main_FIX.h" void SKP_Silk_quant_LTP_gains_FIX( - SKP_int16 B_Q14[], /* I/O (un)quantized LTP gains */ - SKP_int cbk_index[], /* O Codebook Index */ - SKP_int *periodicity_index, /* O Periodicity Index */ - const SKP_int32 W_Q18[], /* I Error Weights in Q18 */ - SKP_int mu_Q8, /* I Mu value (R/D tradeoff) */ - SKP_int lowComplexity /* I Flag for low complexity */ + SKP_int16 B_Q14[], /* I/O (un)quantized LTP gains */ + SKP_int cbk_index[], /* O Codebook Index */ + SKP_int *periodicity_index, /* O Periodicity Index */ + const SKP_int32 W_Q18[], /* I Error Weights in Q18 */ + SKP_int mu_Q8, /* 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[ NB_SUBFR ], cbk_size; + SKP_int j, k, temp_idx[ MAX_NB_SUBFR ], cbk_size; const SKP_uint16 *cdf_ptr; const SKP_int16 *cl_ptr; const SKP_int16 *cbk_ptr_Q14; @@ -45,6 +46,7 @@ void SKP_Silk_quant_LTP_gains_FIX( SKP_int32 rate_dist_subfr, rate_dist, min_rate_dist; +TIC(quant_LTP_fix) /***************************************************/ /* iterate over different codebooks with different */ @@ -62,7 +64,7 @@ void SKP_Silk_quant_LTP_gains_FIX( b_Q14_ptr = B_Q14; rate_dist = 0; - for( j = 0; j < NB_SUBFR; j++ ) { + for( j = 0; j < nb_subfr; j++ ) { SKP_Silk_VQ_WMat_EC_FIX( &temp_idx[ j ], /* O index of best codebook vector */ @@ -86,7 +88,7 @@ void SKP_Silk_quant_LTP_gains_FIX( if( rate_dist < min_rate_dist ) { min_rate_dist = rate_dist; - SKP_memcpy( cbk_index, temp_idx, NB_SUBFR * sizeof( SKP_int ) ); + SKP_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( SKP_int ) ); *periodicity_index = k; } @@ -97,10 +99,26 @@ void SKP_Silk_quant_LTP_gains_FIX( } cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ *periodicity_index ]; - for( j = 0; j < NB_SUBFR; j++ ) { + for( j = 0; j < nb_subfr; j++ ) { for( k = 0; k < LTP_ORDER; k++ ) { B_Q14[ j * LTP_ORDER + k ] = cbk_ptr_Q14[ SKP_MLA( k, cbk_index[ j ], LTP_ORDER ) ]; } } +TOC(quant_LTP_fix) +#ifdef SAVE_ALL_INTERNAL_DATA + /* save rate */ + { + SKP_int nbits_LTP; + SKP_float rateBPF_LTP; + + cl_ptr = SKP_Silk_LTP_gain_BITS_Q6_ptrs[*periodicity_index]; + nbits_LTP = 0; + for(j = 0; j < nb_subfr; j++){ + nbits_LTP += cl_ptr[cbk_index[j]]; + } + rateBPF_LTP = (SKP_float)nbits_LTP / 64.0f; // Q6 -> Q0 + SAVE_DATA( rateBPF_LTP.dat, &rateBPF_LTP, sizeof(SKP_float)); + } +#endif } diff --git a/src/SKP_Silk_regularize_correlations_FIX.c b/src_FIX/SKP_Silk_regularize_correlations_FIX.c similarity index 100% rename from src/SKP_Silk_regularize_correlations_FIX.c rename to src_FIX/SKP_Silk_regularize_correlations_FIX.c diff --git a/src/SKP_Silk_residual_energy16_FIX.c b/src_FIX/SKP_Silk_residual_energy16_FIX.c similarity index 100% rename from src/SKP_Silk_residual_energy16_FIX.c rename to src_FIX/SKP_Silk_residual_energy16_FIX.c diff --git a/src/SKP_Silk_residual_energy_FIX.c b/src_FIX/SKP_Silk_residual_energy_FIX.c similarity index 66% rename from src/SKP_Silk_residual_energy_FIX.c rename to src_FIX/SKP_Silk_residual_energy_FIX.c index 640bcc245..6d538ecbf 100644 --- a/src/SKP_Silk_residual_energy_FIX.c +++ b/src_FIX/SKP_Silk_residual_energy_FIX.c @@ -30,18 +30,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Calculates residual energies of input subframes where all subframes have LPC_order */ /* of preceeding samples */ void SKP_Silk_residual_energy_FIX( - SKP_int32 nrgs[ NB_SUBFR ], /* O Residual energy per subframe */ - SKP_int nrgsQ[ NB_SUBFR ], /* O Q value per subframe */ - const SKP_int16 x[], /* I Input signal */ - const SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I AR coefs for each frame half */ - const SKP_int32 gains_Qx[ NB_SUBFR ], /* I Quantization gains in Qx */ - const SKP_int Qx, /* I Quantization gains Q value */ - const SKP_int subfr_length, /* I Subframe length */ - const SKP_int LPC_order /* I LPC order */ + SKP_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + SKP_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ + const SKP_int16 x[], /* I Input signal */ + const SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ + const SKP_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I Number of subframes */ + const SKP_int LPC_order /* I LPC order */ ) { SKP_int offset, i, j, rshift, lz1, lz2; - SKP_int16 *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; + 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; @@ -50,40 +50,40 @@ void SKP_Silk_residual_energy_FIX( offset = LPC_order + subfr_length; /* Filter input to create the LPC residual for each frame half, and measure subframe energies */ - for( i = 0; i < 2; i++ ) { + 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, ( NB_SUBFR >> 1 ) * offset, LPC_order ); + SKP_Silk_LPC_analysis_filter( x_ptr, a_Q12[ i ], S, LPC_res, ( 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; - for( j = 0; j < ( NB_SUBFR >> 1 ); j++ ) { + for( j = 0; j < ( MAX_NB_SUBFR >> 1 ); j++ ) { /* Measure subframe energy */ - SKP_Silk_sum_sqr_shift( &nrgs[ i * ( NB_SUBFR >> 1 ) + j ], &rshift, LPC_res_ptr, subfr_length ); + SKP_Silk_sum_sqr_shift( &nrgs[ i * ( MAX_NB_SUBFR >> 1 ) + j ], &rshift, LPC_res_ptr, subfr_length ); /* Set Q values for the measured energy */ - nrgsQ[ i * ( NB_SUBFR >> 1 ) + j ] = -rshift; + nrgsQ[ i * ( MAX_NB_SUBFR >> 1 ) + j ] = -rshift; /* Move to next subframe */ LPC_res_ptr += offset; } /* Move to next frame half */ - x_ptr += ( NB_SUBFR >> 1 ) * offset; + x_ptr += ( MAX_NB_SUBFR >> 1 ) * offset; } /* Apply the squared subframe gains */ - for( i = 0; i < NB_SUBFR; i++ ) { + for( i = 0; i < nb_subfr; i++ ) { /* Fully upscale gains and energies */ - lz1 = SKP_Silk_CLZ32( nrgs[ i ] ) - 1; - lz2 = SKP_Silk_CLZ32( gains_Qx[ i ] ) - 1; + lz1 = SKP_Silk_CLZ32( nrgs[ i ] ) - 1; + lz2 = SKP_Silk_CLZ32( gains[ i ] ) - 1; - tmp32 = SKP_LSHIFT32( gains_Qx[ i ], lz2 ); + tmp32 = SKP_LSHIFT32( gains[ i ], lz2 ); /* Find squared gains */ - tmp32 = SKP_SMMUL( tmp32, tmp32 ); // Q( 2 * ( Qx + lz2 ) - 32 ) + tmp32 = SKP_SMMUL( tmp32, tmp32 ); // Q( 2 * lz2 - 32 ) /* Scale energies */ - nrgs[ i ] = SKP_SMMUL( tmp32, SKP_LSHIFT32( nrgs[ i ], lz1 ) ); // Q( nrgsQ[ i ] + lz1 + 2 * ( Qx + lz2 ) - 32 - 32 ) - nrgsQ[ i ] += lz1 + 2 * ( Qx + lz2 ) - 32 - 32; + nrgs[ i ] = SKP_SMMUL( tmp32, SKP_LSHIFT32( nrgs[ i ], lz1 ) ); // Q( nrgsQ[ i ] + lz1 + 2 * lz2 - 32 - 32 ) + nrgsQ[ i ] += lz1 + 2 * lz2 - 32 - 32; } } diff --git a/src/SKP_Silk_solve_LS_FIX.c b/src_FIX/SKP_Silk_solve_LS_FIX.c similarity index 100% rename from src/SKP_Silk_solve_LS_FIX.c rename to src_FIX/SKP_Silk_solve_LS_FIX.c diff --git a/src/SKP_Silk_structs_FIX.h b/src_FIX/SKP_Silk_structs_FIX.h similarity index 72% rename from src/SKP_Silk_structs_FIX.h rename to src_FIX/SKP_Silk_structs_FIX.h index d38bea719..8e2eb2c32 100644 --- a/src/SKP_Silk_structs_FIX.h +++ b/src_FIX/SKP_Silk_structs_FIX.h @@ -33,10 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" #include "SKP_Silk_structs.h" -#if LOW_COMPLEXITY_ONLY -#include "SKP_Silk_resample_rom.h" -#endif - #ifdef __cplusplus extern "C" { @@ -57,7 +53,8 @@ typedef struct { /********************************/ typedef struct { SKP_int16 sLTP_shp1[ LTP_BUF_LENGTH ]; - SKP_int32 sAR_shp2_Q14[ SHAPE_LPC_ORDER_MAX ]; + SKP_int32 sAR_shp1[ MAX_SHAPE_LPC_ORDER + 1 ]; + SKP_int32 sAR_shp2_Q14[ MAX_SHAPE_LPC_ORDER ]; SKP_int16 sLTP_shp2_FIX[ LTP_BUF_LENGTH ]; SKP_int sLTP_shp_buf_idx1; SKP_int sAR_shp_buf_idx2; @@ -78,33 +75,9 @@ typedef struct { SKP_int pitch_LPC_win_length; SKP_int min_pitch_lag; /* Lowest possible pitch lag (samples) */ SKP_int max_pitch_lag; /* Highest possible pitch lag (samples) */ - SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Prev. quant. normalized LSF vector */ + SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */ } SKP_Silk_predict_state_FIX; -#if( defined( SAVE_ALL_INTERNAL_DATA ) || defined( USE_FLT2FIX_WRAPPER ) ) -/*******************************************/ -/* Structure containing NLSF MSVQ codebook */ -/*******************************************/ -/* structure for one stage of MSVQ */ -typedef struct { - const SKP_int32 nVectors; - const SKP_float *CB; - const SKP_float *Rates; -} SKP_Silk_NLSF_CBS_FLP_TMP; - -typedef struct { - const SKP_int32 nStages; - - /* fields for (de)quantizing */ - const SKP_Silk_NLSF_CBS_FLP_TMP *CBStages; - const SKP_float *NDeltaMin; - - /* fields for arithmetic (de)coding */ - const SKP_uint16 *CDF; - const SKP_uint16 * const *StartPtr; - const SKP_int *MiddleIx; -} SKP_Silk_NLSF_CB_struct_FLP_TMP; -#endif /********************************/ /* Encoder state FIX */ @@ -121,12 +94,6 @@ typedef struct { 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 ) */ - - /* Function pointer to noise shaping quantizer (will be set to SKP_Silk_NSQ or SKP_Silk_NSQ_del_dec) */ - void (* NoiseShapingQuantizer)( SKP_Silk_encoder_state *, SKP_Silk_encoder_control *, SKP_Silk_nsq_state *, const SKP_int16 *, - SKP_int *, const SKP_int, const SKP_int16 *, const SKP_int16 *, const SKP_int16 *, const SKP_int *, - const SKP_int *, const SKP_int32 *, const SKP_int32 *, SKP_int, const SKP_int - ); /* Buffer for find pitch and noise shape analysis */ SKP_array_of_int16_4_byte_aligned( x_buf, 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ); @@ -138,16 +105,13 @@ typedef struct { SKP_int BufferedInChannel_ms; /* Simulated number of ms buffer because of exceeded TargetRate_bps */ SKP_int speech_activity_Q8; /* Speech activity in Q8 */ SKP_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */ - + /* Parameters For LTP scaling Control */ SKP_int prevLTPredCodGain_Q7; SKP_int HPLTPredCodGain_Q7; SKP_int32 inBandFEC_SNR_comp_Q8; /* Compensation to SNR_dB when using inband FEC Voiced */ -#ifdef USE_FLT2FIX_WRAPPER - const SKP_Silk_NLSF_CB_struct_FLP_TMP *psNLSF_CB_FLP[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ -#endif } SKP_Silk_encoder_state_FIX; /************************/ @@ -157,20 +121,20 @@ typedef struct { SKP_Silk_encoder_control sCmn; /* Common struct, shared with floating-point code */ /* Prediction and coding parameters */ - SKP_int32 Gains_Q16[ NB_SUBFR ]; + SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; SKP_array_of_int16_4_byte_aligned( PredCoef_Q12[ 2 ], MAX_LPC_ORDER ); - SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ]; + SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; SKP_int LTP_scale_Q14; /* Noise shaping parameters */ /* Testing */ - SKP_array_of_int16_4_byte_aligned( AR1_Q13, NB_SUBFR * SHAPE_LPC_ORDER_MAX ); - SKP_array_of_int16_4_byte_aligned( AR2_Q13, NB_SUBFR * SHAPE_LPC_ORDER_MAX ); - SKP_int32 LF_shp_Q14[ NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */ - SKP_int GainsPre_Q14[ NB_SUBFR ]; - SKP_int HarmBoost_Q14[ NB_SUBFR ]; - SKP_int Tilt_Q14[ NB_SUBFR ]; - SKP_int HarmShapeGain_Q14[ NB_SUBFR ]; + SKP_array_of_int16_4_byte_aligned( AR1_Q13, MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ); + SKP_array_of_int16_4_byte_aligned( 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 GainsPre_Q14[ MAX_NB_SUBFR ]; + SKP_int HarmBoost_Q14[ MAX_NB_SUBFR ]; + SKP_int Tilt_Q14[ MAX_NB_SUBFR ]; + SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ]; SKP_int Lambda_Q10; SKP_int input_quality_Q14; SKP_int coding_quality_Q14; @@ -182,8 +146,8 @@ typedef struct { SKP_int LTPredCodGain_Q7; SKP_int input_quality_bands_Q15[ VAD_N_BANDS ]; SKP_int input_tilt_Q15; - SKP_int32 ResNrg[ NB_SUBFR ]; /* Residual energy per subframe */ - SKP_int ResNrgQ[ NB_SUBFR ]; /* Q domain for the residual energy > 0 */ + SKP_int32 ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */ + SKP_int ResNrgQ[ MAX_NB_SUBFR ]; /* Q domain for the residual energy > 0 */ } SKP_Silk_encoder_control_FIX; diff --git a/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c b/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c new file mode 100644 index 000000000..7bb4ae041 --- /dev/null +++ b/src_FIX/SKP_Silk_warped_autocorrelation_FIX.c @@ -0,0 +1,82 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FIX.h" + +#define QC 10 + +/* Autocorrelations for a warped frequency axis */ +void SKP_Silk_warped_autocorrelation_FIX( + SKP_int32 *corr, /* O Result [order + 1] */ + SKP_int *scale, /* O Scaling of the correlation vector */ + const SKP_int16 *input, /* I Input data to correlate */ + const SKP_int16 warping_Q16, /* I Warping coefficient */ + const SKP_int length, /* I Length of input */ + const SKP_int order /* I Correlation order (even) */ +) +{ + SKP_int n, i, lsh; + SKP_int32 tmp1_Q16, tmp2_Q16; + SKP_int32 state_Q16[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; + SKP_int64 corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; + + /* Order must be even */ + SKP_assert( ( order & 1 ) == 0 ); + + /* Loop over samples */ + for( n = 0; n < length; n++ ) { + tmp1_Q16 = SKP_LSHIFT32( ( SKP_int32 )input[ n ], 16 ); + /* Loop over allpass sections */ + for( i = 0; i < order; i += 2 ) { + /* Output of allpass section */ + tmp2_Q16 = SKP_SMLAWB( state_Q16[ i ], state_Q16[ i + 1 ] - tmp1_Q16, warping_Q16 ); + state_Q16[ i ] = tmp1_Q16; + corr_QC[ i ] += SKP_RSHIFT64( SKP_SMULL( tmp1_Q16, state_Q16[ 0 ] ), 32 - QC ); + /* Output of allpass section */ + tmp1_Q16 = SKP_SMLAWB( state_Q16[ i + 1 ], state_Q16[ i + 2 ] - tmp2_Q16, warping_Q16 ); + state_Q16[ i + 1 ] = tmp2_Q16; + corr_QC[ i + 1 ] += SKP_RSHIFT64( SKP_SMULL( tmp2_Q16, state_Q16[ 0 ] ), 32 - QC ); + } + state_Q16[ order ] = tmp1_Q16; + corr_QC[ order ] += SKP_RSHIFT64( SKP_SMULL( tmp1_Q16, state_Q16[ 0 ] ), 32 - QC ); + } + + lsh = SKP_Silk_CLZ64( corr_QC[ 0 ] ) - 35; + lsh = SKP_LIMIT( lsh, -12 - QC, 30 - QC ); + *scale = -( QC + lsh ); + SKP_assert( *scale >= -30 && *scale <= 12 ); + if( lsh >= 0 ) { + for( i = 0; i < order + 1; i++ ) { + corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_LSHIFT64( corr_QC[ i ], lsh ) ); + } + } else { + for( i = 0; i < order + 1; i++ ) { + corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_RSHIFT64( corr_QC[ i ], -lsh ) ); + } + } + SKP_assert( corr_QC[ 0 ] >= 0 ); // If breaking, decrease QC +} diff --git a/src_FIX/Silk_FIX.vcproj b/src_FIX/Silk_FIX.vcproj new file mode 100644 index 000000000..2d1cd54b7 --- /dev/null +++ b/src_FIX/Silk_FIX.vcproj @@ -0,0 +1,288 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="Silk_FIX" + ProjectGUID="{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories=""../../../celt-0.8.0/libcelt";../interface;../src_common;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_FIX_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories=""../../../celt-0.8.0/libcelt";../interface;../src_common;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;HAVE_CONFIG_H" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_FIX_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_control_codec_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_corrMatrix_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_frame_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_LPC_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_LTP_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_pitch_lags_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_pred_coefs_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_HP_variable_cutoff_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_init_encoder_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LTP_analysis_filter_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LTP_scale_ctrl_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_MSVQ_encode_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_rate_distortion_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_sum_error_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_noise_shape_analysis_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_prefilter_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_process_gains_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_process_NLSFs_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_quant_LTP_gains_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_regularize_correlations_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_residual_energy16_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_residual_energy_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_solve_LS_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_VQ_nearest_neighbor_FIX.c" + > + </File> + <File + RelativePath=".\SKP_Silk_warped_autocorrelation_FIX.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_define_FIX.h" + > + </File> + <File + RelativePath=".\SKP_Silk_main_FIX.h" + > + </File> + <File + RelativePath=".\SKP_Silk_perceptual_parameters_FIX.h" + > + </File> + <File + RelativePath=".\SKP_Silk_structs_FIX.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c b/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c new file mode 100644 index 000000000..66ee3d950 --- /dev/null +++ b/src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c @@ -0,0 +1,103 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +#if HIGH_PASS_INPUT + +/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ +void SKP_Silk_HP_variable_cutoff_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_int16 *out, /* O High-pass filtered output signal */ + const SKP_int16 *in /* I Input signal */ +) +{ + SKP_float pitch_freq_Hz, pitch_freq_log, quality, delta_freq, smth_coef, Fc, r; + SKP_int32 B_Q28[ 3 ], A_Q28[ 2 ]; + + /*********************************************/ + /* Estimate low end of pitch frequency range */ + /*********************************************/ + if( psEnc->sCmn.prev_sigtype == SIG_TYPE_VOICED ) { + + /* Difference, in log domain */ + pitch_freq_Hz = 1e3f * psEnc->sCmn.fs_kHz / psEnc->sCmn.prevLag; + pitch_freq_log = SKP_Silk_log2( pitch_freq_Hz ); + + /* Adjustment based on quality */ + quality = psEncCtrl->input_quality_bands[ 0 ]; + pitch_freq_log -= quality * quality * ( pitch_freq_log - SKP_Silk_log2( VARIABLE_HP_MIN_FREQ ) ); + pitch_freq_log += 0.5f * ( 0.6f - quality ); + + delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; + if( delta_freq < 0.0 ) { + /* Less smoothing for decreasing pitch frequency, to track something close to the minimum */ + delta_freq *= 3.0f; + } + + /* Limit delta, to reduce impact of outliers */ + delta_freq = SKP_LIMIT_float( delta_freq, -VARIABLE_HP_MAX_DELTA_FREQ, VARIABLE_HP_MAX_DELTA_FREQ ); + + /* Update smoother */ + smth_coef = VARIABLE_HP_SMTH_COEF1 * psEnc->speech_activity; + psEnc->variable_HP_smth1 += smth_coef * delta_freq; + } + + /* Second smoother */ + psEnc->variable_HP_smth2 += VARIABLE_HP_SMTH_COEF2 * ( psEnc->variable_HP_smth1 - psEnc->variable_HP_smth2 ); + + /* Convert from log scale to Hertz */ + psEncCtrl->pitch_freq_low_Hz = ( SKP_float )pow( 2.0, psEnc->variable_HP_smth2 ); + + /* Limit frequency range */ + psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_float( psEncCtrl->pitch_freq_low_Hz, VARIABLE_HP_MIN_FREQ, VARIABLE_HP_MAX_FREQ ); + + /*******************************/ + /* Compute filter coefficients */ + /*******************************/ + /* Compute cut-off frequency, in radians */ + Fc = ( SKP_float )( 0.45f * 2.0f * 3.14159265359 * psEncCtrl->pitch_freq_low_Hz / ( 1e3f * psEnc->sCmn.fs_kHz ) ); + + /* 2nd order ARMA coefficients */ + r = 1.0f - 0.92f * Fc; + + /* b = r * [1; -2; 1]; */ + /* a = [1; -2 * r * (1 - 0.5 * Fc^2); r^2]; */ + B_Q28[ 0 ] = SKP_float2int( ( 1 << 28 ) * r ); + B_Q28[ 1 ] = SKP_float2int( ( 1 << 28 ) * -2.0f * r ); + B_Q28[ 2 ] = B_Q28[ 0 ]; + A_Q28[ 0 ] = SKP_float2int( ( 1 << 28 ) * -2.0f * r * ( 1.0f - 0.5f * Fc * Fc ) ); + A_Q28[ 1 ] = SKP_float2int( ( 1 << 28 ) * r * r ); + + /********************/ + /* High-pass filter */ + /********************/ + SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psEnc->sCmn.In_HP_State, out, psEnc->sCmn.frame_length ); +} + +#endif // HIGH_PASS_INPUT diff --git a/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c b/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c new file mode 100644 index 000000000..3bbe58683 --- /dev/null +++ b/src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c @@ -0,0 +1,206 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include <stdlib.h> +#include "SKP_Silk_main_FLP.h" + +/*******************************************/ +/* LPC analysis filter */ +/* NB! State is kept internally and the */ +/* filter always starts with zero state */ +/* first Order output samples are not set */ +/*******************************************/ + +void SKP_Silk_LPC_analysis_filter_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length, /* I Length of input signal */ + const SKP_int Order /* I LPC order */ +) +{ + SKP_assert( Order <= length ); + + switch( Order ) { + case 8: + SKP_Silk_LPC_analysis_filter8_FLP( r_LPC, PredCoef, s, length ); + break; + + case 10: + SKP_Silk_LPC_analysis_filter10_FLP( r_LPC, PredCoef, s, length ); + break; + + case 12: + SKP_Silk_LPC_analysis_filter12_FLP( r_LPC, PredCoef, s, length ); + break; + + case 16: + SKP_Silk_LPC_analysis_filter16_FLP( r_LPC, PredCoef, s, length ); + break; + + default: + SKP_assert( 0 ); + break; + } + + /* Set first LPC Order samples to zero instead of undefined */ + SKP_memset( r_LPC, 0, Order * sizeof( SKP_float ) ); +} + +/* 16th order LPC analysis filter, does not write first 16 samples */ +void SKP_Silk_LPC_analysis_filter16_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +) +{ + SKP_int ix = 16; + SKP_float LPC_pred; + const SKP_float *s_ptr; + + for ( ; ix < length; ix++) { + s_ptr = &s[ix - 1]; + + /* short-term prediction */ + LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + + s_ptr[-1] * PredCoef[ 1 ] + + s_ptr[-2] * PredCoef[ 2 ] + + s_ptr[-3] * PredCoef[ 3 ] + + s_ptr[-4] * PredCoef[ 4 ] + + s_ptr[-5] * PredCoef[ 5 ] + + s_ptr[-6] * PredCoef[ 6 ] + + s_ptr[-7] * PredCoef[ 7 ] + + s_ptr[-8] * PredCoef[ 8 ] + + s_ptr[-9] * PredCoef[ 9 ] + + s_ptr[-10] * PredCoef[ 10 ] + + s_ptr[-11] * PredCoef[ 11 ] + + s_ptr[-12] * PredCoef[ 12 ] + + s_ptr[-13] * PredCoef[ 13 ] + + s_ptr[-14] * PredCoef[ 14 ] + + s_ptr[-15] * PredCoef[ 15 ]; + + /* prediction error */ + r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; + } +} + +/* 12th order LPC analysis filter, does not write first 12 samples */ +void SKP_Silk_LPC_analysis_filter12_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +) +{ + SKP_int ix = 12; + SKP_float LPC_pred; + const SKP_float *s_ptr; + + for ( ; ix < length; ix++) { + s_ptr = &s[ix - 1]; + + /* short-term prediction */ + LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + + s_ptr[-1] * PredCoef[ 1 ] + + s_ptr[-2] * PredCoef[ 2 ] + + s_ptr[-3] * PredCoef[ 3 ] + + s_ptr[-4] * PredCoef[ 4 ] + + s_ptr[-5] * PredCoef[ 5 ] + + s_ptr[-6] * PredCoef[ 6 ] + + s_ptr[-7] * PredCoef[ 7 ] + + s_ptr[-8] * PredCoef[ 8 ] + + s_ptr[-9] * PredCoef[ 9 ] + + s_ptr[-10] * PredCoef[ 10 ] + + s_ptr[-11] * PredCoef[ 11 ]; + + /* prediction error */ + r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; + } +} + +/* 10th order LPC analysis filter, does not write first 10 samples */ +void SKP_Silk_LPC_analysis_filter10_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +) +{ + SKP_int ix = 10; + SKP_float LPC_pred; + const SKP_float *s_ptr; + + for ( ; ix < length; ix++) { + s_ptr = &s[ix - 1]; + + /* short-term prediction */ + LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + + s_ptr[-1] * PredCoef[ 1 ] + + s_ptr[-2] * PredCoef[ 2 ] + + s_ptr[-3] * PredCoef[ 3 ] + + s_ptr[-4] * PredCoef[ 4 ] + + s_ptr[-5] * PredCoef[ 5 ] + + s_ptr[-6] * PredCoef[ 6 ] + + s_ptr[-7] * PredCoef[ 7 ] + + s_ptr[-8] * PredCoef[ 8 ] + + s_ptr[-9] * PredCoef[ 9 ]; + + /* prediction error */ + r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; + } +} + +/* 8th order LPC analysis filter, does not write first 8 samples */ +void SKP_Silk_LPC_analysis_filter8_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +) +{ + SKP_int ix = 8; + SKP_float LPC_pred; + const SKP_float *s_ptr; + + for ( ; ix < length; ix++) { + s_ptr = &s[ix - 1]; + + /* short-term prediction */ + LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + + s_ptr[ -1 ] * PredCoef[ 1 ] + + s_ptr[ -2 ] * PredCoef[ 2 ] + + s_ptr[ -3 ] * PredCoef[ 3 ] + + s_ptr[ -4 ] * PredCoef[ 4 ] + + s_ptr[ -5 ] * PredCoef[ 5 ] + + s_ptr[ -6 ] * PredCoef[ 6 ] + + s_ptr[ -7 ] * PredCoef[ 7 ]; + + /* prediction error */ + r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; + } +} diff --git a/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c b/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c new file mode 100644 index 000000000..1089a27ba --- /dev/null +++ b/src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c @@ -0,0 +1,71 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +void SKP_Silk_LTP_analysis_filter_FLP( + SKP_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */ + const SKP_float *x, /* I Input signal, with preceeding samples */ + const SKP_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ + const SKP_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */ + const SKP_int subfr_length, /* I Length of each subframe */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int pre_length /* I Preceeding samples for each subframe */ +) +{ + const SKP_float *x_ptr, *x_lag_ptr; + SKP_float Btmp[ LTP_ORDER ]; + SKP_float *LTP_res_ptr; + SKP_float inv_gain; + SKP_int k, i, j; + + x_ptr = x; + LTP_res_ptr = LTP_res; + for( k = 0; k < nb_subfr; k++ ) { + x_lag_ptr = x_ptr - pitchL[ k ]; + inv_gain = invGains[ k ]; + for( i = 0; i < LTP_ORDER; i++ ) { + Btmp[ i ] = B[ k * LTP_ORDER + i ]; + } + + /* LTP analysis FIR filter */ + for( i = 0; i < subfr_length + pre_length; i++ ) { + LTP_res_ptr[ i ] = x_ptr[ i ]; + /* Subtract long-term prediction */ + for( j = 0; j < LTP_ORDER; j++ ) { + LTP_res_ptr[ i ] -= Btmp[ j ] * x_lag_ptr[ LTP_ORDER / 2 - j ]; + } + LTP_res_ptr[ i ] *= inv_gain; + x_lag_ptr++; + } + + /* Update pointers */ + LTP_res_ptr += subfr_length + pre_length; + x_ptr += subfr_length; + } +} diff --git a/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c b/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c new file mode 100644 index 000000000..0380d12af --- /dev/null +++ b/src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c @@ -0,0 +1,84 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +#define NB_THRESHOLDS 11 +/* Table containing trained thresholds for LTP scaling */ +static const SKP_float LTPScaleThresholds[ NB_THRESHOLDS ] = +{ + 0.95f, 0.8f, 0.50f, 0.400f, 0.3f, 0.2f, + 0.15f, 0.1f, 0.08f, 0.075f, 0.0f +}; + + +void SKP_Silk_LTP_scale_ctrl_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ +) +{ + SKP_int round_loss, frames_per_packet; + SKP_float g_out, g_limit, thrld1, thrld2; + + /* 1st order high-pass filter */ + //g_HP(n) = g(n) - g(n-1) + 0.5 * g_HP(n-1); // tune the 0.5: higher means longer impact of jump + psEnc->HPLTPredCodGain = SKP_max_float( psEncCtrl->LTPredCodGain - psEnc->prevLTPredCodGain, 0.0f ) + + 0.5f * psEnc->HPLTPredCodGain; + + psEnc->prevLTPredCodGain = psEncCtrl->LTPredCodGain; + + /* combine input and filtered input */ + g_out = 0.5f * psEncCtrl->LTPredCodGain + ( 1.0f - 0.5f ) * psEnc->HPLTPredCodGain; + g_limit = SKP_sigmoid( 0.5f * ( g_out - 6 ) ); + + + /* Default is minimum scaling */ + psEncCtrl->sCmn.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 ){ + + frames_per_packet = psEnc->sCmn.PacketSize_ms / ( SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr ); + + round_loss += ( frames_per_packet - 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; + } else if( g_limit > thrld2 ) { + /* Middle Scaling */ + psEncCtrl->sCmn.LTP_scaleIndex = 1; + } + } + psEncCtrl->LTP_scale = ( SKP_float)SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.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 new file mode 100644 index 000000000..589ac3641 --- /dev/null +++ b/src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c @@ -0,0 +1,90 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* NLSF vector decoder */ +void SKP_Silk_NLSF_MSVQ_decode_FLP( + SKP_float *pNLSF, /* O Decoded output vector [ LPC_ORDER ] */ + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP, /* I NLSF codebook struct */ + const SKP_int *NLSFIndices, /* I NLSF indices [ nStages ] */ + const SKP_int LPC_order /* I LPC order used */ +) +{ + const SKP_float *pCB_element; + SKP_int s; + SKP_int i; + + + /* Check that each index is within valid range */ + SKP_assert( 0 <= NLSFIndices[ 0 ] && NLSFIndices[ 0 ] < psNLSF_CB_FLP->CBStages[ 0 ].nVectors ); + + /* Point to the first vector element */ + pCB_element = &psNLSF_CB_FLP->CBStages[ 0 ].CB[ SKP_MUL( NLSFIndices[ 0 ], LPC_order ) ]; + + /* Initialize with the codebook vector from stage 0 */ + SKP_memcpy( pNLSF, pCB_element, LPC_order * sizeof( SKP_float ) ); + + for( s = 1; s < psNLSF_CB_FLP->nStages; s++ ) { + /* Check that each index is within valid range */ + SKP_assert( 0 <= NLSFIndices[ s ] && NLSFIndices[ s ] < psNLSF_CB_FLP->CBStages[ s ].nVectors ); + + if( LPC_order == 16 ) { + /* Point to the first vector element */ + pCB_element = &psNLSF_CB_FLP->CBStages[ s ].CB[ SKP_LSHIFT( NLSFIndices[ s ], 4 ) ]; + + /* Add the codebook vector from the current stage */ + pNLSF[ 0 ] += pCB_element[ 0 ]; + pNLSF[ 1 ] += pCB_element[ 1 ]; + pNLSF[ 2 ] += pCB_element[ 2 ]; + pNLSF[ 3 ] += pCB_element[ 3 ]; + pNLSF[ 4 ] += pCB_element[ 4 ]; + pNLSF[ 5 ] += pCB_element[ 5 ]; + pNLSF[ 6 ] += pCB_element[ 6 ]; + pNLSF[ 7 ] += pCB_element[ 7 ]; + pNLSF[ 8 ] += pCB_element[ 8 ]; + pNLSF[ 9 ] += pCB_element[ 9 ]; + pNLSF[ 10 ] += pCB_element[ 10 ]; + pNLSF[ 11 ] += pCB_element[ 11 ]; + pNLSF[ 12 ] += pCB_element[ 12 ]; + pNLSF[ 13 ] += pCB_element[ 13 ]; + pNLSF[ 14 ] += pCB_element[ 14 ]; + pNLSF[ 15 ] += pCB_element[ 15 ]; + } else { + /* Point to the first vector element */ + pCB_element = &psNLSF_CB_FLP->CBStages[ s ].CB[ NLSFIndices[ s ] * LPC_order ]; + + /* Add the codebook vector from the current stage */ + for( i = 0; i < LPC_order; i++ ) { + pNLSF[ i ] += pCB_element[ i ]; + } + } + } + + /* NLSF stabilization */ + SKP_Silk_NLSF_stabilize_FLP( pNLSF, psNLSF_CB_FLP->NDeltaMin, LPC_order ); +} diff --git a/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c b/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c new file mode 100644 index 000000000..bf0878eb3 --- /dev/null +++ b/src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c @@ -0,0 +1,225 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/***********************/ +/* NLSF vector encoder */ +/***********************/ +void SKP_Silk_NLSF_MSVQ_encode_FLP( + SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_float *pNLSF, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP, /* I Codebook object */ + const SKP_float *pNLSF_q_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ + const SKP_float *pW, /* I NLSF weight vector [ LPC_ORDER ] */ + const SKP_float NLSF_mu, /* I Rate weight for the RD optimization */ + const SKP_float NLSF_mu_fluc_red, /* I Fluctuation reduction error weight */ + const SKP_int NLSF_MSVQ_Survivors,/* I Max survivors from each stage */ + const SKP_int LPC_order, /* I LPC order */ + const SKP_int deactivate_fluc_red /* I Deactivate fluctuation reduction */ +) +{ + SKP_int i, s, k, cur_survivors, prev_survivors, input_index, cb_index, bestIndex; + SKP_float se, wsse, rateDistThreshold, bestRateDist; + SKP_float pNLSF_in[ MAX_LPC_ORDER ]; + +#if( LOW_COMPLEXITY_ONLY == 1 ) + SKP_float pRateDist[ NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE ]; + SKP_float pRate[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ]; + SKP_float pRate_new[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ]; + SKP_int pTempIndices[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ]; + SKP_int pPath[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_int pPath_new[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ]; + SKP_float pRes[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ]; + SKP_float pRes_new[ MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ]; +#else + SKP_float pRateDist[ NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED ]; + 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_float pRes[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; + SKP_float pRes_new[ MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ]; +#endif + + const SKP_float *pConstFloat; + SKP_float *pFloat; + const SKP_int *pConstInt; + SKP_int *pInt; + const SKP_float *pCB_element; + const SKP_Silk_NLSF_CBS_FLP *pCurrentCBStage; + + SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS ); + SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) ); + + cur_survivors = NLSF_MSVQ_Survivors; + + + + /* Copy the input vector */ + SKP_memcpy( pNLSF_in, pNLSF, LPC_order * sizeof(SKP_float) ); + + /****************************************************/ + /* Tree search for the multi-stage vector quantizer */ + /****************************************************/ + + /* Clear accumulated rates */ + SKP_memset( pRate, 0, NLSF_MSVQ_Survivors * sizeof( SKP_float ) ); + + /* Copy NLSFs into residual signal vector */ + SKP_memcpy( pRes, pNLSF, LPC_order * sizeof( SKP_float ) ); + + /* Set first stage values */ + prev_survivors = 1; + + /* Loop over all stages */ + for( s = 0; s < psNLSF_CB_FLP->nStages; s++ ) { + + /* Set a pointer to the current stage codebook */ + pCurrentCBStage = &psNLSF_CB_FLP->CBStages[ s ]; + + /* Calculate the number of survivors in the current stage */ + cur_survivors = SKP_min_32( NLSF_MSVQ_Survivors, prev_survivors * pCurrentCBStage->nVectors ); + +#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 0 ) + /* Find a single best survivor in the last stage, if we */ + /* do not need candidates for fluctuation reduction */ + if( s == psNLSF_CB_FLP->nStages - 1 ) { + cur_survivors = 1; + } +#endif + /* Nearest neighbor clustering for multiple input data vectors */ + SKP_Silk_NLSF_VQ_rate_distortion_FLP( pRateDist, pCurrentCBStage, pRes, pW, pRate, NLSF_mu, prev_survivors, LPC_order ); + + /* Sort the rate-distortion errors */ + SKP_Silk_insertion_sort_increasing_FLP( pRateDist, pTempIndices, prev_survivors * pCurrentCBStage->nVectors, cur_survivors ); + + /* Discard survivors with rate-distortion values too far above the best one */ + rateDistThreshold = NLSF_MSVQ_SURV_MAX_REL_RD * pRateDist[ 0 ]; + while( pRateDist[ cur_survivors - 1 ] > rateDistThreshold && cur_survivors > 1 ) { + cur_survivors--; + } + + /* Update accumulated codebook contributions for the 'cur_survivors' best codebook indices */ + for( k = 0; k < cur_survivors; k++ ) { + if( s > 0 ) { + /* Find the indices of the input and the codebook vector */ + if( pCurrentCBStage->nVectors == 8 ) { + input_index = SKP_RSHIFT( pTempIndices[ k ], 3 ); + cb_index = pTempIndices[ k ] & 7; + } else { + input_index = pTempIndices[ k ] / pCurrentCBStage->nVectors; + cb_index = pTempIndices[ k ] - input_index * pCurrentCBStage->nVectors; + } + } else { + /* Find the indices of the input and the codebook vector */ + input_index = 0; + cb_index = pTempIndices[ k ]; + } + + /* Subtract new contribution from the previous residual vector for each of 'cur_survivors' */ + pConstFloat = &pRes[ input_index * LPC_order ]; + pCB_element = &pCurrentCBStage->CB[ cb_index * LPC_order ]; + pFloat = &pRes_new[ k * LPC_order ]; + for( i = 0; i < LPC_order; i++ ) { + pFloat[ i ] = pConstFloat[ i ] - pCB_element[ i ]; + } + + /* Update accumulated rate for stage 1 to the current */ + pRate_new[ k ] = pRate[ input_index ] + pCurrentCBStage->Rates[ cb_index ]; + + /* Copy paths from previous matrix, starting with the best path */ + pConstInt = &pPath[ input_index * psNLSF_CB_FLP->nStages ]; + pInt = &pPath_new[ k * psNLSF_CB_FLP->nStages ]; + for( i = 0; i < s; i++ ) { + pInt[ i ] = pConstInt[ i ]; + } + /* Write the current stage indices for the 'cur_survivors' to the best path matrix */ + pInt[ s ] = cb_index; + } + + if( s < psNLSF_CB_FLP->nStages - 1 ) { + /* Copy NLSF residual matrix for next stage */ + SKP_memcpy(pRes, pRes_new, cur_survivors * LPC_order * sizeof( SKP_float ) ); + + /* Copy rate vector for next stage */ + 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_FLP->nStages * sizeof( SKP_int ) ); + } + + prev_survivors = cur_survivors; + } + + /* (Preliminary) index of the best survivor, later to be decoded */ + bestIndex = 0; + +#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 ) + /******************************/ + /* NLSF fluctuation reduction */ + /******************************/ + if( deactivate_fluc_red != 1 ) { + + /* Search among all survivors, now taking also weighted fluctuation errors into account */ + bestRateDist = SKP_float_MAX; + for( s = 0; s < cur_survivors; s++ ) { + /* Decode survivor to compare with previous quantized NLSF vector */ + SKP_Silk_NLSF_MSVQ_decode_FLP( pNLSF, psNLSF_CB_FLP, &pPath_new[ s * psNLSF_CB_FLP->nStages ], LPC_order ); + + /* Compare decoded NLSF vector with the previously quantized vector */ + wsse = 0; + for( i = 0; i < LPC_order; i += 2 ) { + /* Compute weighted squared quantization error for index i */ + se = pNLSF[ i ] - pNLSF_q_prev[ i ]; + wsse += pW[ i ] * se * se; + + /* Compute weighted squared quantization error for index i + 1 */ + se = pNLSF[ i + 1 ] - pNLSF_q_prev[ i + 1 ]; + wsse += pW[ i + 1 ] * se * se; + } + + /* Add the fluctuation reduction penalty to the rate distortion error */ + wsse = pRateDist[s] + wsse * NLSF_mu_fluc_red; + + /* Keep index of best survivor */ + if( wsse < bestRateDist ) { + bestRateDist = wsse; + bestIndex = s; + } + } + } +#endif + + /* Copy best path to output argument */ + SKP_memcpy( NLSFIndices, &pPath_new[ bestIndex * psNLSF_CB_FLP->nStages ], psNLSF_CB_FLP->nStages * sizeof( SKP_int ) ); + + /* Decode and stabilize the best survivor */ + SKP_Silk_NLSF_MSVQ_decode_FLP( pNLSF, psNLSF_CB_FLP, 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 new file mode 100644 index 000000000..914dbdd2c --- /dev/null +++ b/src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c @@ -0,0 +1,57 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Rate-Distortion calculations for multiple input data vectors */ +void SKP_Silk_NLSF_VQ_rate_distortion_FLP( + SKP_float *pRD, /* O Rate-distortion values [psNLSF_CBS_FLP->nVectors*N] */ + const SKP_Silk_NLSF_CBS_FLP *psNLSF_CBS_FLP, /* I NLSF codebook stage struct */ + const SKP_float *in, /* I Input vectors to be quantized */ + const SKP_float *w, /* I Weight vector */ + const SKP_float *rate_acc, /* I Accumulated rates from previous stage */ + const SKP_float mu, /* I Weight between weighted error and rate */ + const SKP_int N, /* I Number of input vectors to be quantized */ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_float *pRD_vec; + SKP_int i, n; + + /* Compute weighted quantization errors for all input vectors over one codebook stage */ + SKP_Silk_NLSF_VQ_sum_error_FLP( pRD, in, w, psNLSF_CBS_FLP->CB, N, psNLSF_CBS_FLP->nVectors, LPC_order ); + + /* Loop over input vectors */ + pRD_vec = pRD; + for( n = 0; n < N; n++ ) { + /* Add rate cost to error for each codebook vector */ + for( i = 0; i < psNLSF_CBS_FLP->nVectors; i++ ) { + pRD_vec[ i ] += mu * ( rate_acc[n] + psNLSF_CBS_FLP->Rates[ i ] ); + } + pRD_vec += psNLSF_CBS_FLP->nVectors; + } +} diff --git a/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c b/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c new file mode 100644 index 000000000..5359da7cb --- /dev/null +++ b/src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c @@ -0,0 +1,132 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* compute weighted quantization errors for LPC_order element input vectors, over one codebook stage */ +void SKP_Silk_NLSF_VQ_sum_error_FLP( + SKP_float *err, /* O Weighted quantization errors [ N * K ] */ + const SKP_float *in, /* I Input vectors [ N * LPC_order ] */ + const SKP_float *w, /* I Weighting vectors [ N * LPC_order ] */ + const SKP_float *pCB, /* I Codebook vectors [ K * LPC_order ] */ + const SKP_int N, /* I Number of input vectors */ + const SKP_int K, /* I Number of codebook vectors */ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_int i, n; + SKP_float diff, sum_error; + SKP_float Wcpy[ MAX_LPC_ORDER ]; + const SKP_float *cb_vec; + + /* Copy to local stack */ + SKP_memcpy( Wcpy, w, LPC_order * sizeof( SKP_float ) ); + + if( LPC_order == 16 ) { + /* Loop over input vectors */ + for( n = 0; n < N; n++ ) { + /* Loop over codebook */ + cb_vec = pCB; + for( i = 0; i < K; i++ ) { + /* Compute weighted squared quantization error */ + diff = in[ 0 ] - cb_vec[ 0 ]; + sum_error = Wcpy[ 0 ] * diff * diff; + diff = in[ 1 ] - cb_vec[ 1 ]; + sum_error += Wcpy[ 1 ] * diff * diff; + diff = in[ 2 ] - cb_vec[ 2 ]; + sum_error += Wcpy[ 2 ] * diff * diff; + diff = in[ 3 ] - cb_vec[ 3 ]; + sum_error += Wcpy[ 3 ] * diff * diff; + diff = in[ 4 ] - cb_vec[ 4 ]; + sum_error += Wcpy[ 4 ] * diff * diff; + diff = in[ 5 ] - cb_vec[ 5 ]; + sum_error += Wcpy[ 5 ] * diff * diff; + diff = in[ 6 ] - cb_vec[ 6 ]; + sum_error += Wcpy[ 6 ] * diff * diff; + diff = in[ 7 ] - cb_vec[ 7 ]; + sum_error += Wcpy[ 7 ] * diff * diff; + diff = in[ 8 ] - cb_vec[ 8 ]; + sum_error += Wcpy[ 8 ] * diff * diff; + diff = in[ 9 ] - cb_vec[ 9 ]; + sum_error += Wcpy[ 9 ] * diff * diff; + diff = in[ 10 ] - cb_vec[ 10 ]; + sum_error += Wcpy[ 10 ] * diff * diff; + diff = in[ 11 ] - cb_vec[ 11 ]; + sum_error += Wcpy[ 11 ] * diff * diff; + diff = in[ 12 ] - cb_vec[ 12 ]; + sum_error += Wcpy[ 12 ] * diff * diff; + diff = in[ 13 ] - cb_vec[ 13 ]; + sum_error += Wcpy[ 13 ] * diff * diff; + diff = in[ 14 ] - cb_vec[ 14 ]; + sum_error += Wcpy[ 14 ] * diff * diff; + diff = in[ 15 ] - cb_vec[ 15 ]; + sum_error += Wcpy[ 15 ] * diff * diff; + + err[ i ] = sum_error; + cb_vec += 16; + } + err += K; + in += 16; + } + } else { + SKP_assert( LPC_order == 10 ); + + /* Loop over input vectors */ + for( n = 0; n < N; n++ ) { + /* Loop over codebook */ + cb_vec = pCB; + for( i = 0; i < K; i++ ) { + /* Compute weighted squared quantization error */ + diff = in[ 0 ] - cb_vec[ 0 ]; + sum_error = Wcpy[ 0 ] * diff * diff; + diff = in[ 1 ] - cb_vec[ 1 ]; + sum_error += Wcpy[ 1 ] * diff * diff; + diff = in[ 2 ] - cb_vec[ 2 ]; + sum_error += Wcpy[ 2 ] * diff * diff; + diff = in[ 3 ] - cb_vec[ 3 ]; + sum_error += Wcpy[ 3 ] * diff * diff; + diff = in[ 4 ] - cb_vec[ 4 ]; + sum_error += Wcpy[ 4 ] * diff * diff; + diff = in[ 5 ] - cb_vec[ 5 ]; + sum_error += Wcpy[ 5 ] * diff * diff; + diff = in[ 6 ] - cb_vec[ 6 ]; + sum_error += Wcpy[ 6 ] * diff * diff; + diff = in[ 7 ] - cb_vec[ 7 ]; + sum_error += Wcpy[ 7 ] * diff * diff; + diff = in[ 8 ] - cb_vec[ 8 ]; + sum_error += Wcpy[ 8 ] * diff * diff; + diff = in[ 9 ] - cb_vec[ 9 ]; + sum_error += Wcpy[ 9 ] * diff * diff; + + err[ i ] = sum_error; + cb_vec += 10; + } + err += K; + in += 10; + } + } +} diff --git a/src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c b/src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c new file mode 100644 index 000000000..192758f31 --- /dev/null +++ b/src_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c @@ -0,0 +1,69 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.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 */ +) +{ + 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; + + tmp2 = 1.0f / SKP_max_float( pX[ k + 2 ] - pX[ k + 1 ], MIN_NDELTA ); + pXW[ k + 1 ] = tmp1 + tmp2; + } + + /* Last value */ + tmp1 = 1.0f / SKP_max_float( 1.0f - pX[ D - 1 ], MIN_NDELTA ); + pXW[ D - 1 ] = tmp1 + tmp2; +} diff --git a/src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c b/src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c new file mode 100644 index 000000000..490903f6b --- /dev/null +++ b/src_FLP/SKP_Silk_VQ_nearest_neighbor_FLP.c @@ -0,0 +1,96 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* entropy constrained MATRIX-weighted VQ, for a single input data vector */ +void SKP_Silk_VQ_WMat_EC_FLP( + SKP_int *ind, /* O Index of best codebook vector */ + SKP_float *rate_dist, /* O Best weighted quant. error + mu * rate */ + const SKP_float *in, /* I Input vector to be quantized */ + const SKP_float *W, /* I Weighting matrix */ + const SKP_int16 *cb, /* I Codebook */ + const SKP_int16 *cl_Q6, /* I Code length for each codebook vector */ + const SKP_float mu, /* I Tradeoff between WSSE and rate */ + const SKP_int L /* I Number of vectors in codebook */ +) +{ + SKP_int k; + SKP_float sum1; + SKP_float diff[ 5 ]; + const SKP_int16 *cb_row; + + /* Loop over codebook */ + *rate_dist = SKP_float_MAX; + cb_row = cb; + for( k = 0; k < L; k++ ) { + /* Calc difference between in vector and cbk vector */ + diff[ 0 ] = in[ 0 ] - ( SKP_float )cb_row[ 0 ] * Q14_CONVERSION_FAC; + diff[ 1 ] = in[ 1 ] - ( SKP_float )cb_row[ 1 ] * Q14_CONVERSION_FAC; + diff[ 2 ] = in[ 2 ] - ( SKP_float )cb_row[ 2 ] * Q14_CONVERSION_FAC; + diff[ 3 ] = in[ 3 ] - ( SKP_float )cb_row[ 3 ] * Q14_CONVERSION_FAC; + diff[ 4 ] = in[ 4 ] - ( SKP_float )cb_row[ 4 ] * Q14_CONVERSION_FAC; + + /* Weighted rate */ + sum1 = mu * cl_Q6[ k ] / 64.0f; + + /* Add weighted quantization error, assuming W is symmetric */ + /* first row of W */ + sum1 += diff[ 0 ] * ( W[ 0 ] * diff[ 0 ] + + 2.0f * ( W[ 1 ] * diff[ 1 ] + + W[ 2 ] * diff[ 2 ] + + W[ 3 ] * diff[ 3 ] + + W[ 4 ] * diff[ 4 ] ) ); + + /* second row of W */ + sum1 += diff[ 1 ] * ( W[ 6 ] * diff[ 1 ] + + 2.0f * ( W[ 7 ] * diff[ 2 ] + + W[ 8 ] * diff[ 3 ] + + W[ 9 ] * diff[ 4 ] ) ); + + /* third row of W */ + sum1 += diff[ 2 ] * ( W[ 12 ] * diff[ 2 ] + + 2.0f * ( W[ 13 ] * diff[ 3 ] + + W[ 14 ] * diff[ 4 ] ) ); + + /* fourth row of W */ + sum1 += diff[ 3 ] * ( W[ 18 ] * diff[ 3 ] + + 2.0f * ( W[ 19 ] * diff[ 4 ] ) ); + + /* last row of W */ + sum1 += diff[ 4 ] * ( W[ 24 ] * diff[ 4 ] ); + + /* find best */ + if( sum1 < *rate_dist ) { + *rate_dist = sum1; + *ind = k; + } + + /* Go to next cbk vector */ + cb_row += LTP_ORDER; + } +} diff --git a/src_FLP/SKP_Silk_apply_sine_window_FLP.c b/src_FLP/SKP_Silk_apply_sine_window_FLP.c new file mode 100644 index 000000000..8fcbbe206 --- /dev/null +++ b/src_FLP/SKP_Silk_apply_sine_window_FLP.c @@ -0,0 +1,79 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Apply sine window to signal vector. */ +/* Window types: */ +/* 0 -> sine window from 0 to pi */ +/* 1 -> sine window from 0 to pi/2 */ +/* 2 -> sine window from pi/2 to pi */ +void SKP_Silk_apply_sine_window_FLP( + SKP_float px_win[], /* O Pointer to windowed signal */ + const SKP_float px[], /* I Pointer to input signal */ + const SKP_int win_type, /* I Selects a window type */ + const SKP_int length /* I Window length, multiple of 4 */ +) +{ + SKP_int k; + SKP_float freq, c, S0, S1; + + /* Length must be multiple of 4 */ + SKP_assert( ( length & 3 ) == 0 ); + + freq = PI / ( length + 1 ); + if( win_type == 0 ) { + freq = 2.0f * freq; + } + + /* Approximation of 2 * cos(f) */ + c = 2.0f - freq * freq; + + /* Initialize state */ + if( win_type < 2 ) { + /* Start from 0 */ + S0 = 0.0f; + /* Approximation of sin(f) */ + S1 = freq; + } else { + /* Start from 1 */ + S0 = 1.0f; + /* Approximation of cos(f) */ + S1 = 0.5f * c; + } + + /* Uses the recursive equation: sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f) */ + /* 4 samples at a time */ + for( k = 0; k < length; k += 4 ) { + px_win[ k + 0 ] = px[ k + 0 ] * 0.5f * ( S0 + S1 ); + px_win[ k + 1 ] = px[ k + 1 ] * S1; + S0 = c * S1 - S0; + px_win[ k + 2 ] = px[ k + 2 ] * 0.5f * ( S1 + S0 ); + px_win[ k + 3 ] = px[ k + 3 ] * S0; + S1 = c * S0 - S1; + } +} diff --git a/COPYING b/src_FLP/SKP_Silk_assembler_FLP.h similarity index 79% rename from COPYING rename to src_FLP/SKP_Silk_assembler_FLP.h index 4ec0218b9..d949c6767 100644 --- a/COPYING +++ b/src_FLP/SKP_Silk_assembler_FLP.h @@ -24,3 +24,19 @@ 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_ASSEMBLER_FLP_H +#define SKP_SILK_ASSEMBLER_FLP_H + +#include "SKP_Silk_typedef.h" + +/* Declaration of assembler functions */ + +void SKP_Silk_LPC_ana_sse( + float *r_LPC, /* O LPC residual signal */ + const float *coefs, /* I LPC coefficients */ + const float *speech, /* I Input signal */ + int len /* I Length of input signal */ +); + +#endif diff --git a/src_FLP/SKP_Silk_control_codec_FLP.c b/src_FLP/SKP_Silk_control_codec_FLP.c new file mode 100644 index 000000000..ba75d03db --- /dev/null +++ b/src_FLP/SKP_Silk_control_codec_FLP.c @@ -0,0 +1,578 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* ToDo: Move the functions below to common to be able to use them in FLP control codec also */ +SKP_INLINE SKP_int SKP_Silk_setup_resamplers( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int API_fs_Hz, /* I */ + SKP_int fs_kHz /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_packetsize( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int PacketSize_ms /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_fs( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int fs_kHz /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_complexity( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int Complexity /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_rate( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int TargetRate_bps /* I */ +); + +SKP_INLINE SKP_int SKP_Silk_setup_LBRR( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int INBandFEC_enabled /* I */ +); + +/* Control encoder SNR */ +SKP_int SKP_Silk_control_encoder_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ + const SKP_int32 API_fs_Hz, /* I External (API) sampling rate (Hz) */ + const SKP_int max_internal_fs_kHz,/* I Maximum internal sampling rate (kHz) */ + const SKP_int PacketSize_ms, /* I Packet length (ms) */ + SKP_int32 TargetRate_bps, /* I Target max bitrate (if SNR_dB == 0) */ + const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */ + const SKP_int INBandFEC_enabled, /* I Enable (1) / disable (0) inband FEC */ + const SKP_int DTX_enabled, /* I Enable / disable DTX */ + const SKP_int InputFramesize_ms, /* I Inputframe in ms */ + const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */ +) +{ + SKP_int fs_kHz, ret = 0; + + /* State machine for the SWB/WB switching */ + fs_kHz = psEnc->sCmn.fs_kHz; + + /* Only switch during low speech activity, when no frames are sitting in the payload buffer */ + if( API_fs_Hz == 8000 || fs_kHz == 0 || API_fs_Hz < fs_kHz * 1000 || fs_kHz > max_internal_fs_kHz ) { + /* Switching is not possible, encoder just initialized, internal mode higher than external, */ + /* or internal mode higher than maximum allowed internal mode */ + fs_kHz = SKP_min( SKP_DIV32_16( API_fs_Hz, 1000 ), max_internal_fs_kHz ); + } else { + /* Accumulate the difference between the target rate and limit for switching down */ + psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - psEnc->sCmn.bitrate_threshold_down ); + psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 ); + + if( psEnc->speech_activity < 0.5f && psEnc->sCmn.nFramesInPayloadBuf == 0 ) { /* Low speech activity and payload buffer empty */ + /* Check if we should switch down */ +#if SWITCH_TRANSITION_FILTERING + if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */ + ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || /* Bitrate threshold is met */ + ( psEnc->sCmn.sSWBdetect.WB_detected * psEnc->sCmn.fs_kHz == 24 ) ) ) { /* Forced down-switching due to WB input */ + psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */ + psEnc->sCmn.sLP.mode = 0; /* Switch down */ + } else if( + ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && /* Transition phase complete */ + ( psEnc->sCmn.sLP.mode == 0 ) ) { /* Ready to switch down */ + psEnc->sCmn.sLP.transition_frame_no = 0; /* Ready for new transition phase */ +#else + if( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) { /* Bitrate threshold is met */ +#endif + psEnc->sCmn.bitrateDiff = 0; + + /* Switch to a lower sample frequency */ + if( psEnc->sCmn.fs_kHz == 24 ) { + fs_kHz = 16; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + fs_kHz = 12; + } else { + SKP_assert( psEnc->sCmn.fs_kHz == 12 ); + fs_kHz = 8; + } + } + + /* Check if we should switch up */ + if( ( ( psEnc->sCmn.fs_kHz * 1000 < API_fs_Hz ) && + ( TargetRate_bps >= psEnc->sCmn.bitrate_threshold_up ) && + ( psEnc->sCmn.sSWBdetect.WB_detected * psEnc->sCmn.fs_kHz != 16 ) ) && + ( ( psEnc->sCmn.fs_kHz == 16 ) && ( max_internal_fs_kHz >= 24 ) || + ( psEnc->sCmn.fs_kHz == 12 ) && ( max_internal_fs_kHz >= 16 ) || + ( psEnc->sCmn.fs_kHz == 8 ) && ( max_internal_fs_kHz >= 12 ) ) +#if SWITCH_TRANSITION_FILTERING + && ( psEnc->sCmn.sLP.transition_frame_no == 0 ) ) { /* No transition phase running, ready to switch */ + psEnc->sCmn.sLP.mode = 1; /* Switch up */ +#else + ) { +#endif + psEnc->sCmn.bitrateDiff = 0; + + /* Switch to a higher sample frequency */ + if( psEnc->sCmn.fs_kHz == 8 ) { + fs_kHz = 12; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + fs_kHz = 16; + } else { + SKP_assert( psEnc->sCmn.fs_kHz == 16 ); + fs_kHz = 24; + } + } + } + } + +#if SWITCH_TRANSITION_FILTERING + /* After switching up, stop transition filter during speech inactivity */ + if( ( psEnc->sCmn.sLP.mode == 1 ) && + ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && + ( psEnc->speech_activity < 0.5f ) && + ( psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) { + + psEnc->sCmn.sLP.transition_frame_no = 0; + + /* Reset transition filter state */ + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + } +#endif + + /********************************************/ + /* Prepare resampler and buffered data */ + /********************************************/ + SKP_Silk_setup_resamplers( psEnc, API_fs_Hz, fs_kHz ); + + /********************************************/ + /* Set packet size */ + /********************************************/ + ret += SKP_Silk_setup_packetsize( psEnc, PacketSize_ms ); + + /********************************************/ + /* Set internal sampling frequency */ + /********************************************/ + ret += SKP_Silk_setup_fs( psEnc, fs_kHz ); + + /********************************************/ + /* Set encoding complexity */ + /********************************************/ + ret += SKP_Silk_setup_complexity( psEnc, Complexity ); + + /********************************************/ + /* Set bitrate/coding quality */ + /********************************************/ + ret += SKP_Silk_setup_rate( psEnc, TargetRate_bps ); + + /********************************************/ + /* Set packet loss rate measured by farend */ + /********************************************/ + if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) { + ret = SKP_SILK_ENC_INVALID_LOSS_RATE; + } + psEnc->sCmn.PacketLoss_perc = PacketLoss_perc; + + /********************************************/ + /* Set LBRR usage */ + /********************************************/ + ret += SKP_Silk_setup_LBRR( psEnc, INBandFEC_enabled ); + + /********************************************/ + /* Set DTX mode */ + /********************************************/ + if( DTX_enabled < 0 || DTX_enabled > 1 ) { + ret = SKP_SILK_ENC_INVALID_DTX_SETTING; + } + psEnc->sCmn.useDTX = DTX_enabled; + + return ret; +} + +/* Control low bitrate redundancy usage */ +void SKP_Silk_LBRR_ctrl_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I Encoder state FLP */ + SKP_Silk_encoder_control *psEncCtrl /* I/O Encoder control */ +) +{ + SKP_int LBRR_usage; + + if( psEnc->sCmn.LBRR_enabled ) { + /* Control LBRR */ + + /* Usage Control based on sensitivity and packet loss caracteristics */ + /* For now only enable adding to next for active frames. Make more complex later */ + LBRR_usage = SKP_SILK_NO_LBRR; + if( psEnc->speech_activity > LBRR_SPEECH_ACTIVITY_THRES && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity + LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1; + } + psEncCtrl->LBRR_usage = LBRR_usage; + } else { + psEncCtrl->LBRR_usage = SKP_SILK_NO_LBRR; + } +} + +SKP_INLINE SKP_int SKP_Silk_setup_packetsize( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int PacketSize_ms /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + if( ( PacketSize_ms != 10 ) && + ( PacketSize_ms != 20 ) && + ( PacketSize_ms != 40 ) && + ( PacketSize_ms != 60 ) && + ( PacketSize_ms != 80 ) && + ( PacketSize_ms != 100 ) ) { + ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; + } else { + if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) { + if( PacketSize_ms == 10 ) { + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + /* Only allowed when the payload buffer is empty */ + psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1; + psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.PacketSize_ms = PacketSize_ms; + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, psEnc->sCmn.fs_kHz ); + /* Packet length changes. Reset LBRR buffer */ + SKP_Silk_LBRR_reset( &psEnc->sCmn ); + } + } else{ + psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; + psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.PacketSize_ms = PacketSize_ms; + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, psEnc->sCmn.fs_kHz ); + /* Packet length changes. Reset LBRR buffer */ + SKP_Silk_LBRR_reset( &psEnc->sCmn ); + } + } + } + return(ret); +} + +SKP_INLINE SKP_int SKP_Silk_setup_resamplers( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int API_fs_Hz, /* I */ + SKP_int fs_kHz /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != API_fs_Hz ) { + + /* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */ + SKP_int16 x_buf_API_fs_Hz[ ( MAX_API_FS_KHZ / 8 ) * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ]; + SKP_int16 x_bufFIX[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; + + SKP_int32 nSamples_temp = 2 * psEnc->sCmn.frame_length + psEnc->sCmn.la_shape; + + SKP_float2short_array( x_bufFIX, psEnc->x_buf, 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ); + + if( fs_kHz * 1000 < API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) { + /* Resample buffered data in x_buf to API_fs_Hz */ + + SKP_Silk_resampler_state_struct temp_resampler_state; + + /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */ + ret += SKP_Silk_resampler_init( &temp_resampler_state, psEnc->sCmn.fs_kHz * 1000, API_fs_Hz ); + + /* Temporary resampling of x_buf data to API_fs_Hz */ + ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, nSamples_temp ); + + /* Calculate number of samples that has been temporarily upsampled */ + nSamples_temp = SKP_DIV32_16( nSamples_temp * API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 ); + + /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ + ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, API_fs_Hz, fs_kHz * 1000 ); + + } else { + /* Copy data */ + SKP_memcpy( x_buf_API_fs_Hz, x_bufFIX, nSamples_temp * sizeof( SKP_int16 ) ); + } + + if( 1000 * fs_kHz != API_fs_Hz ) { + /* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */ + ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, nSamples_temp ); + } + SKP_short2float_array( psEnc->x_buf, x_bufFIX, 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ); + } + + psEnc->sCmn.prev_API_fs_Hz = API_fs_Hz; + + return(ret); +} + +SKP_INLINE SKP_int SKP_Silk_setup_fs( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int fs_kHz /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + /* 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->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) ); +#if SWITCH_TRANSITION_FILTERING + SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) ); + if( psEnc->sCmn.sLP.mode == 1 ) { + /* Begin transition phase */ + psEnc->sCmn.sLP.transition_frame_no = 1; + } else { + /* End transition phase */ + psEnc->sCmn.sLP.transition_frame_no = 0; + } +#endif + psEnc->sCmn.inputBufIx = 0; + psEnc->sCmn.nFramesInPayloadBuf = 0; + psEnc->sCmn.nBytesInPayloadBuf = 0; + psEnc->sCmn.oldest_LBRR_idx = 0; + psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */ + + SKP_memset( psEnc->sPred.prev_NLSFq, 0, MAX_LPC_ORDER * sizeof( SKP_float ) ); + + /* Initialize non-zero parameters */ + psEnc->sCmn.prevLag = 100; + psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED; + 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.fs_kHz = fs_kHz; + if( psEnc->sCmn.fs_kHz == 8 ) { + psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER; + psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10; + psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10; + psEnc->psNLSF_CB_FLP[ 0 ] = &SKP_Silk_NLSF_CB0_10_FLP; + psEnc->psNLSF_CB_FLP[ 1 ] = &SKP_Silk_NLSF_CB1_10_FLP; + } else { + psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER; + psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16; + psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16; + psEnc->psNLSF_CB_FLP[ 0 ] = &SKP_Silk_NLSF_CB0_16_FLP; + psEnc->psNLSF_CB_FLP[ 1 ] = &SKP_Silk_NLSF_CB1_16_FLP; + } + psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz; + psEnc->sCmn.frame_length = psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr; + psEnc->sCmn.ltp_mem_length = LTP_MEM_LENGTH_MS * fs_kHz; + psEnc->sCmn.la_pitch = LA_PITCH_MS * fs_kHz; + psEnc->sCmn.la_shape = LA_SHAPE_MS * fs_kHz; + psEnc->sPred.min_pitch_lag = 3 * fs_kHz; + psEnc->sPred.max_pitch_lag = 18 * fs_kHz; + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){ + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); + } else { + psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); + } + if( psEnc->sCmn.fs_kHz == 24 ) { + psEnc->mu_LTP = MU_LTP_QUANT_SWB; + psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX; + psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + psEnc->mu_LTP = MU_LTP_QUANT_WB; + psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + psEnc->mu_LTP = MU_LTP_QUANT_MB; + psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS; + } else { + psEnc->mu_LTP = MU_LTP_QUANT_NB; + psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS; + psEnc->sCmn.bitrate_threshold_down = 0; + } + psEnc->sCmn.fs_kHz_changed = 1; + + /* Check that settings are valid */ + SKP_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length ); + } + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_complexity( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int Complexity /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + /* Check that settings are valid */ + if( LOW_COMPLEXITY_ONLY && Complexity != 0 ) { + ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING; + } + + /* Set encoding complexity */ + if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) { + /* Low complexity */ + psEnc->sCmn.Complexity = 0; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_LC_MODE; + psEnc->pitchEstimationThreshold = FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 8; + psEnc->sCmn.shapingLPCOrder = 8; + psEnc->sCmn.nStatesDelayedDecision = 1; + psEnc->sCmn.useInterpolatedNLSFs = 0; + psEnc->sCmn.LTPQuantLowComplexity = 1; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE; + } else if( Complexity == 1 ) { + /* Medium complexity */ + psEnc->sCmn.Complexity = 1; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_MC_MODE; + psEnc->pitchEstimationThreshold = FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 12; + psEnc->sCmn.shapingLPCOrder = 12; + psEnc->sCmn.nStatesDelayedDecision = 2; + psEnc->sCmn.useInterpolatedNLSFs = 0; + psEnc->sCmn.LTPQuantLowComplexity = 0; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE; + } else if( Complexity == 2 ) { + /* High complexity */ + psEnc->sCmn.Complexity = 2; + psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_HC_MODE; + psEnc->pitchEstimationThreshold = FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE; + psEnc->sCmn.pitchEstimationLPCOrder = 16; + psEnc->sCmn.shapingLPCOrder = 16; + psEnc->sCmn.nStatesDelayedDecision = 4; + psEnc->sCmn.useInterpolatedNLSFs = 1; + psEnc->sCmn.LTPQuantLowComplexity = 0; + psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS; + } else { + ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING; + } + + /* Do not allow higher pitch estimation LPC order than predict LPC order */ + psEnc->sCmn.pitchEstimationLPCOrder = SKP_min_int( psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.predictLPCOrder ); + + SKP_assert( psEnc->sCmn.pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); + SKP_assert( psEnc->sCmn.shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); + SKP_assert( psEnc->sCmn.nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_rate( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int TargetRate_bps /* I */ +) +{ + SKP_int k, ret = SKP_SILK_NO_ERROR; + SKP_float frac; + const SKP_int32 *rateTable; + + /* Set bitrate/coding quality */ + TargetRate_bps = SKP_min( TargetRate_bps, 100000 ); + if( psEnc->sCmn.fs_kHz == 8 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_NB_BPS ); + } else if( psEnc->sCmn.fs_kHz == 12 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_MB_BPS ); + } else if( psEnc->sCmn.fs_kHz == 16 ) { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_WB_BPS ); + } else { + TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_SWB_BPS ); + } + if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) { + psEnc->sCmn.TargetRate_bps = TargetRate_bps; + + /* If new TargetRate_bps, translate to SNR_dB value */ + if( psEnc->sCmn.fs_kHz == 8 ) { + rateTable = TargetRate_table_NB; + } else if( psEnc->sCmn.fs_kHz == 12 ) { + rateTable = TargetRate_table_MB; + } else if( psEnc->sCmn.fs_kHz == 16 ) { + rateTable = TargetRate_table_WB; + } else { + rateTable = TargetRate_table_SWB; + } + for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { + /* Find bitrate interval in table and interpolate */ + 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 ] ) ); + break; + } + } + } + return( ret ); +} + +SKP_INLINE SKP_int SKP_Silk_setup_LBRR( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O */ + SKP_int INBandFEC_enabled /* I */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + SKP_int32 LBRRRate_thres_bps; + +#if USE_LBRR + if( INBandFEC_enabled < 0 || INBandFEC_enabled > 1 ) { + ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING; + } + + /* Only change settings if first frame in packet */ + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + + psEnc->sCmn.LBRR_enabled = INBandFEC_enabled; + 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 aprox 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( INBandFEC_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 new file mode 100644 index 000000000..996e20de1 --- /dev/null +++ b/src_FLP/SKP_Silk_corrMatrix_FLP.c @@ -0,0 +1,89 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/********************************************************************** + * Correlation matrix computations for LS estimate. + **********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Calculates correlation vector X'*t */ +void SKP_Silk_corrVector_FLP( + const SKP_float *x, /* I x vector [L+order-1] used to create X */ + const SKP_float *t, /* I Target vector [L] */ + const SKP_int L, /* I Length of vecors */ + const SKP_int Order, /* I Max lag for correlation */ + SKP_float *Xt /* O X'*t correlation vector [order] */ +) +{ + SKP_int lag; + const SKP_float *ptr1; + + ptr1 = &x[ Order - 1 ]; /* Points to first sample of column 0 of X: X[:,0] */ + for( lag = 0; lag < Order; lag++ ) { + /* Calculate X[:,lag]'*t */ + Xt[ lag ] = (SKP_float)SKP_Silk_inner_product_FLP( ptr1, t, L ); + ptr1--; /* Next column of X */ + } +} + +/* Calculates correlation matrix X'*X */ +void SKP_Silk_corrMatrix_FLP( + const SKP_float *x, /* I x vector [ L+order-1 ] used to create X */ + const SKP_int L, /* I Length of vectors */ + const SKP_int Order, /* I Max lag for correlation */ + SKP_float *XX /* O X'*X correlation matrix [order x order] */ +) +{ + SKP_int j, lag; + double energy; + const SKP_float *ptr1, *ptr2; + + ptr1 = &x[ Order - 1 ]; /* First sample of column 0 of X */ + energy = SKP_Silk_energy_FLP( ptr1, L ); /* X[:,0]'*X[:,0] */ + matrix_ptr( XX, 0, 0, Order ) = ( SKP_float )energy; + for( j = 1; j < Order; j++ ) { + /* Calculate X[:,j]'*X[:,j] */ + energy += ptr1[ -j ] * ptr1[ -j ] - ptr1[ L - j ] * ptr1[ L - j ]; + matrix_ptr( XX, j, j, Order ) = ( SKP_float )energy; + } + + ptr2 = &x[ Order - 2 ]; /* First sample of column 1 of X */ + for( lag = 1; lag < Order; lag++ ) { + /* Calculate X[:,0]'*X[:,lag] */ + energy = SKP_Silk_inner_product_FLP( ptr1, ptr2, L ); + matrix_ptr( XX, lag, 0, Order ) = ( SKP_float )energy; + matrix_ptr( XX, 0, lag, Order ) = ( SKP_float )energy; + /* Calculate X[:,j]'*X[:,j + lag] */ + for( j = 1; j < ( Order - lag ); j++ ) { + energy += ptr1[ -j ] * ptr2[ -j ] - ptr1[ L - j ] * ptr2[ L - j ]; + matrix_ptr( XX, lag + j, j, Order ) = ( SKP_float )energy; + matrix_ptr( XX, j, lag + j, Order ) = ( SKP_float )energy; + } + ptr2--; /* Next column of X */ + } +} diff --git a/src_FLP/SKP_Silk_define_FLP.h b/src_FLP/SKP_Silk_define_FLP.h new file mode 100644 index 000000000..e518430a5 --- /dev/null +++ b/src_FLP/SKP_Silk_define_FLP.h @@ -0,0 +1,103 @@ +/*********************************************************************** +Copyright (c) 2006-2010, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, (subject to the limitations in the disclaimer below) +are permitted provided that the following conditions are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Skype Limited, nor the names of specific +contributors, may be used to endorse or promote products derived from +this software without specific prior written permission. +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED +BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************/ + +#ifndef SKP_SILK_DEFINE_FLP_H +#define SKP_SILK_DEFINE_FLP_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*******************/ +/* Pitch estimator */ +/*******************/ + +/* Level of noise floor for whitening filter LPC analysis in pitch analysis */ +#define FIND_PITCH_WHITE_NOISE_FRACTION 1e-3f + +/* Bandwidth expansion for whitening filter in pitch analysis */ +#define FIND_PITCH_BANDWITH_EXPANSION 0.99f + +/* Threshold used by pitch estimator for early escape */ +#define FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE 0.7f +#define FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE 0.75f +#define FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE 0.8f + +/***********************/ +/* Long-Term predictor */ +/***********************/ + +/* Regualarization factor for correlation matrix. Equivalent to adding noise at -50 dB */ +#define FIND_LTP_COND_FAC 1e-5f +#define FIND_LPC_COND_FAC 6e-5f + +/* Find prediction coefficients defines */ +#define LTP_DAMPING 0.001f +#define LTP_SMOOTHING 0.1f + +/* LTP quantization settings */ +#define MU_LTP_QUANT_NB 0.03f +#define MU_LTP_QUANT_MB 0.025f +#define MU_LTP_QUANT_WB 0.02f +#define MU_LTP_QUANT_SWB 0.016f + +/***********************/ +/* High pass filtering */ +/***********************/ + +/* Smoothing parameters for low end of pitch frequency range estimation */ +#define VARIABLE_HP_SMTH_COEF1 0.1f +#define VARIABLE_HP_SMTH_COEF2 0.015f + +/* Min and max values for low end of pitch frequency range estimation */ +#define VARIABLE_HP_MIN_FREQ 80.0f +#define VARIABLE_HP_MAX_FREQ 150.0f + +/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */ +#define VARIABLE_HP_MAX_DELTA_FREQ 0.4f + +/***********/ +/* Various */ +/***********/ + +/* Required speech activity for counting frame as active */ +#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES 0.7f + +#define SPEECH_ACTIVITY_DTX_THRES 0.1f + +/* Speech Activity LBRR enable threshold (needs tuning) */ +#define LBRR_SPEECH_ACTIVITY_THRES 0.5f + +#define Q14_CONVERSION_FAC 6.1035e-005f // 1 / 2^14 + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src_FLP/SKP_Silk_encode_frame_FLP.c b/src_FLP/SKP_Silk_encode_frame_FLP.c new file mode 100644 index 000000000..8fb954a2f --- /dev/null +++ b/src_FLP/SKP_Silk_encode_frame_FLP.c @@ -0,0 +1,472 @@ +#include <stdlib.h> +#include "SKP_Silk_main_FLP.h" + +/****************/ +/* Encode frame */ +/****************/ +SKP_int SKP_Silk_encode_frame_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_uint8 *pCode, /* O Payload */ + SKP_int16 *pnBytesOut, /* I/O Number of payload bytes; */ + /* input: max length; output: used */ + const SKP_int16 *pIn /* I Input speech frame */ +) +{ + SKP_Silk_encoder_control_FLP sEncCtrl; + SKP_int k, i, nBytes, ret = 0; + 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_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; + SKP_int LBRR_idx, frame_terminator; + + /* Low bitrate redundancy parameters */ + SKP_uint8 LBRRpayload[ MAX_ARITHM_BYTES ]; + SKP_int16 nBytesLBRR; + + ec_byte_buffer range_enc_celt_buf; + + const SKP_uint16 *FrameTermination_CDF; + +TIC(ENCODE_FRAME) + + sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3; + /**************************************************************/ + /* Setup Input Pointers, and insert frame in input buffer */ + /*************************************************************/ + /* pointers aligned with start of frame to encode */ + x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; /* start of frame to encode */ + res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; /* start of pitch LPC residual frame */ + + /****************************/ + /* Voice Activity Detection */ + /****************************/ +TIC(VAD) + SKP_Silk_VAD_FLP( psEnc, &sEncCtrl, pIn ); +TOC(VAD) + + /*******************************************/ + /* High-pass filtering of the input signal */ + /*******************************************/ +TIC(HP_IN) +#if HIGH_PASS_INPUT + /* Variable high-pass filter */ + SKP_Silk_HP_variable_cutoff_FLP( psEnc, &sEncCtrl, pIn_HP, pIn ); +#else + SKP_memcpy( pIn_HP, pIn, 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 ) ); +#endif + + /*******************************************/ + /* Copy new frame to front of input buffer */ + /*******************************************/ + SKP_short2float_array( x_frame + psEnc->sCmn.la_shape, pIn_HP_LP, 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[ psEnc->sCmn.la_shape + k * ( psEnc->sCmn.frame_length >> 3 ) ] += ( 1 - ( k & 2 ) ) * 1e-6f; + } + + /*****************************************/ + /* Find pitch lags, initial LPC analysis */ + /*****************************************/ +TIC(FIND_PITCH) + SKP_Silk_find_pitch_lags_FLP( psEnc, &sEncCtrl, res_pitch, x_frame ); +TOC(FIND_PITCH) + + /************************/ + /* Noise shape analysis */ + /************************/ +TIC(NOISE_SHAPE_ANALYSIS) + SKP_Silk_noise_shape_analysis_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_frame ); +TOC(NOISE_SHAPE_ANALYSIS) + + /*****************************************/ + /* Prefiltering for noise shaper */ + /*****************************************/ +TIC(PREFILTER) + SKP_Silk_prefilter_FLP( psEnc, &sEncCtrl, xfw, x_frame ); +TOC(PREFILTER) + + /***************************************************/ + /* Find linear prediction coefficients (LPC + LTP) */ + /***************************************************/ +TIC(FIND_PRED_COEF) + SKP_Silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch ); +TOC(FIND_PRED_COEF) + + /****************************************/ + /* Process gains */ + /****************************************/ +TIC(PROCESS_GAINS) + SKP_Silk_process_gains_FLP( psEnc, &sEncCtrl ); +TOC(PROCESS_GAINS) + + psEnc->sCmn.sigtype[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.sigtype; + psEnc->sCmn.QuantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.QuantOffsetType; + /****************************************/ + /* Low Bitrate Redundant Encoding */ + /****************************************/ + nBytesLBRR = MAX_ARITHM_BYTES; +TIC(LBRR) + SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw ); +TOC(LBRR) + + /*****************************************/ + /* Noise shaping quantization */ + /*****************************************/ +TIC(NSQ) + SKP_Silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, xfw, + &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ], 0 ); +TOC(NSQ) + + /**************************************************/ + /* Convert speech activity into VAD and DTX flags */ + /**************************************************/ + if( psEnc->speech_activity < SPEECH_ACTIVITY_DTX_THRES ) { + psEnc->sCmn.vadFlag = NO_VOICE_ACTIVITY; + psEnc->sCmn.noSpeechCounter++; + if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) { + psEnc->sCmn.inDTX = 1; + } + if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) { + psEnc->sCmn.noSpeechCounter = 0; + psEnc->sCmn.inDTX = 0; + } + } else { + psEnc->sCmn.noSpeechCounter = 0; + psEnc->sCmn.inDTX = 0; + psEnc->sCmn.vadFlag = VOICE_ACTIVITY; + } + + /****************************************/ + /* Initialize arithmetic coder */ + /****************************************/ + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC.buffer, MAX_ARITHM_BYTES ); + ec_enc_init( &psEnc->sCmn.sRC.range_enc_celt_state, &range_enc_celt_buf ); + + SKP_Silk_range_enc_init( &psEnc->sCmn.sRC ); + psEnc->sCmn.nBytesInPayloadBuf = 0; + } + + /****************************************/ + /* Encode Parameters */ + /****************************************/ +TIC(ENCODE_PARAMS) + SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC ); + FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF; +TOC(ENCODE_PARAMS) + + /****************************************/ + /* Update Buffers and State */ + /****************************************/ + /* Update input buffer */ + SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], + ( psEnc->sCmn.ltp_mem_length + psEnc->sCmn.la_shape ) * sizeof( SKP_float ) ); + + /* Parameters needed for next frame */ + psEnc->sCmn.prev_sigtype = sEncCtrl.sCmn.sigtype; + psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; + psEnc->sCmn.first_frame_after_reset = 0; + + if( psEnc->sCmn.sRC.error ) { + /* Encoder returned error: Clear payload buffer */ + psEnc->sCmn.nFramesInPayloadBuf = 0; + } else { + psEnc->sCmn.nFramesInPayloadBuf++; + } + + /****************************************/ + /* Finalize payload and copy to output */ + /****************************************/ + if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) { + + LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK; + + /* Check if FEC information should be added */ + frame_terminator = SKP_SILK_LAST_FRAME; + if( psEnc->sCmn.LBRR_buffer[ LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS1 ) { + frame_terminator = SKP_SILK_LBRR_VER1; + } + if( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS2 ) { + frame_terminator = SKP_SILK_LBRR_VER2; + LBRR_idx = psEnc->sCmn.oldest_LBRR_idx; + } + + /* Add the frame termination info to stream */ + SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF ); + for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) { + SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], + &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); + } + + /* Payload length so far */ + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes ); + + /* 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_enc_tell( &psEnc->sCmn.sRC.range_enc_celt_state, 0 ); + ec_enc_done( &psEnc->sCmn.sRC.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.range_enc_celt_state.buf->buf[ nBytes - 1 ] |= mask; + } + } + SKP_memcpy( pCode, psEnc->sCmn.sRC.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) ); + + if( frame_terminator > SKP_SILK_MORE_FRAMES && + *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) { + /* Get old packet and add to payload. */ + SKP_memcpy( &pCode[ nBytes ], + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].payload, + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) ); + nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes; + } + *pnBytesOut = nBytes; + + /* Update FEC buffer */ + SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload, + nBytesLBRR * sizeof( SKP_uint8 ) ); + psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].nBytes = nBytesLBRR; + /* The below line describes how FEC should be used */ + psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage; + psEnc->sCmn.oldest_LBRR_idx = ( ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK ); + + /* Reset the number of frames in payload buffer */ + psEnc->sCmn.nFramesInPayloadBuf = 0; + } else { + /* Not enough space: Payload will be discarded */ + *pnBytesOut = 0; + nBytes = 0; + psEnc->sCmn.nFramesInPayloadBuf = 0; + ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT; + } + } else { + /* No payload for you this time */ + *pnBytesOut = 0; + + /* Encode that more frames follows */ + frame_terminator = SKP_SILK_MORE_FRAMES; + SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF ); + + /* Payload length so far */ + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes ); + + /* 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 ] ); + } + + /* Check for arithmetic coder errors */ + if( psEnc->sCmn.sRC.error ) { + ret = SKP_SILK_ENC_INTERNAL_ERROR; + } + + /* 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 -= 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; + + if( psEnc->speech_activity > WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES ) { + psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr ); + } + +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( q.dat, q, psEnc->sCmn.frame_length * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.sCmn.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, MAX_LAYERS * psEnc->sCmn.nb_subfr * sizeof( SKP_int ) ); + DEBUG_STORE_DATA( nBytes.dat, &nBytes, 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 ) ); + DEBUG_STORE_DATA( input_quality_bands.dat, sEncCtrl.input_quality_bands, VAD_N_BANDS * sizeof( SKP_float ) ); + DEBUG_STORE_DATA( sigtype.dat, &sEncCtrl.sCmn.sigtype, 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( 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 ) ); +#endif + return( ret ); +} + +/* 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_int16 *pnBytesOut, /* I/O Payload bytes; in: max; out: used */ + const SKP_float xfw[] /* I Input signal */ +) +{ + 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; + + /* Control use of inband LBRR */ + SKP_Silk_LBRR_ctrl_FLP( psEnc, &psEncCtrl->sCmn ); + + if( psEnc->sCmn.LBRR_enabled ) { + /* 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 if( psEnc->sCmn.fs_kHz == 24 ) { + Rate_only_parameters = 19500; + } else { + SKP_assert( 0 ); + } + + if( psEnc->sCmn.Complexity > 0 && 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( 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 * psEnc->sCmn.frame_length ], 1 ); + } else { + SKP_memset( &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ], 0, + psEnc->sCmn.frame_length * sizeof( SKP_int ) ); + + psEncCtrl->sCmn.LTP_scaleIndex = 0; + } + /****************************************/ + /* Initialize arithmetic coder */ + /****************************************/ + if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { + ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES ); + ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, &range_enc_celt_buf ); + + SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR ); + psEnc->sCmn.nBytesInPayloadBuf = 0; + } + + /****************************************/ + /* Encode Parameters */ + /****************************************/ + SKP_Silk_encode_parameters_v4( &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; + } + + /****************************************/ + /* 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 */ + SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF ); + + /*********************************************/ + /* Encode quantization indices of excitation */ + /*********************************************/ + for( i = 0; i < nFramesInPayloadBuf; i++ ) { + SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], + &psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length ); + } + + /* Payload length so far */ + SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes ); + + /* 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_enc_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, 0 ); + 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 for you this time */ + *pnBytesOut = 0; + + /* Encode that more frames follows */ + frame_terminator = SKP_SILK_MORE_FRAMES; + SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF ); + } + + /* 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; + } +} diff --git a/src_FLP/SKP_Silk_find_LPC_FLP.c b/src_FLP/SKP_Silk_find_LPC_FLP.c new file mode 100644 index 000000000..88f135854 --- /dev/null +++ b/src_FLP/SKP_Silk_find_LPC_FLP.c @@ -0,0 +1,97 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +void SKP_Silk_find_LPC_FLP( + SKP_float NLSF[], /* O NLSFs */ + SKP_int *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 */ + const SKP_float x[], /* I Input signal */ + const SKP_int subfr_length, /* I Subframe length incl preceeding samples */ + const SKP_int nb_subfr /* I: Number of subframes */ +) +{ + SKP_int k; + SKP_float a[ MAX_LPC_ORDER ]; + + /* Used only for NLSF interpolation */ + double res_nrg, res_nrg_2nd, res_nrg_interp; + SKP_float a_tmp[ MAX_LPC_ORDER ], NLSF0[ MAX_LPC_ORDER ]; + SKP_float LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; + + /* Default: No interpolation */ + *interpIndex = 4; + + /* Burg AR analysis for the full frame */ + res_nrg = SKP_Silk_burg_modified_FLP( a, x, subfr_length, nb_subfr, FIND_LPC_COND_FAC, LPC_order ); + + if( useInterpNLSFs == 1 && nb_subfr == MAX_NB_SUBFR ) { + /* Optimal solution for last 10 ms; subtract residual energy here, as that's easier than */ + /* adding it to the residual energy of the first 10 ms in each iteration of the search below */ + res_nrg -= SKP_Silk_burg_modified_FLP( a_tmp, x + ( MAX_NB_SUBFR / 2 ) * subfr_length, + subfr_length, MAX_NB_SUBFR / 2, FIND_LPC_COND_FAC, LPC_order ); + + /* Convert to NLSFs */ + SKP_Silk_A2NLSF_FLP( NLSF, a_tmp, LPC_order ); + + /* Search over interpolation indices to find the one with lowest residual energy */ + res_nrg_2nd = SKP_float_MAX; + for( k = 3; k >= 0; k-- ) { + /* Interpolate NLSFs for first half */ + SKP_Silk_interpolate_wrapper_FLP( NLSF0, prev_NLSFq, NLSF, 0.25f * k, LPC_order ); + + /* Convert to LPC for residual energy evaluation */ + SKP_Silk_NLSF2A_stable_FLP( a_tmp, NLSF0, LPC_order ); + + /* Calculate residual energy with LSF interpolation */ + SKP_Silk_LPC_analysis_filter_FLP( LPC_res, a_tmp, x, 2 * subfr_length, LPC_order ); + res_nrg_interp = + SKP_Silk_energy_FLP( LPC_res + LPC_order, subfr_length - LPC_order ) + + SKP_Silk_energy_FLP( LPC_res + LPC_order + subfr_length, subfr_length - LPC_order ); + + /* Determine whether current interpolated NLSFs are best so far */ + if( res_nrg_interp < res_nrg ) { + /* Interpolation has lower residual energy */ + res_nrg = res_nrg_interp; + *interpIndex = k; + } else if( res_nrg_interp > res_nrg_2nd ) { + /* No reason to continue iterating - residual energies will continue to climb */ + break; + } + res_nrg_2nd = res_nrg_interp; + } + } + + if( *interpIndex == 4 ) { + /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */ + SKP_Silk_A2NLSF_FLP( NLSF, a, LPC_order ); + } + +} diff --git a/src_FLP/SKP_Silk_find_LTP_FLP.c b/src_FLP/SKP_Silk_find_LTP_FLP.c new file mode 100644 index 000000000..42acbcfd9 --- /dev/null +++ b/src_FLP/SKP_Silk_find_LTP_FLP.c @@ -0,0 +1,124 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +void SKP_Silk_find_LTP_FLP( + SKP_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ + SKP_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ + SKP_float *LTPredCodGain, /* O LTP coding gain */ + const SKP_float r_lpc[], /* I LPC residual */ + const SKP_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ + const SKP_float Wght[ MAX_NB_SUBFR ], /* I Weights */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int mem_offset /* I Number of samples in LTP memory */ +) +{ + SKP_int i, k; + SKP_float *b_ptr, temp, *WLTP_ptr; + SKP_float LPC_res_nrg, LPC_LTP_res_nrg; + SKP_float d[ MAX_NB_SUBFR ], m, g, delta_b[ LTP_ORDER ]; + SKP_float w[ MAX_NB_SUBFR ], nrg[ MAX_NB_SUBFR ], regu; + SKP_float Rr[ LTP_ORDER ], rr[ MAX_NB_SUBFR ]; + const SKP_float *r_ptr, *lag_ptr; + + b_ptr = b; + WLTP_ptr = WLTP; + r_ptr = &r_lpc[ mem_offset ]; + for( k = 0; k < nb_subfr; k++ ) { + lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); + + SKP_Silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, WLTP_ptr ); + SKP_Silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr ); + + rr[ k ] = ( SKP_float )SKP_Silk_energy_FLP( r_ptr, subfr_length ); + regu = LTP_DAMPING * ( rr[ k ] + 1.0f ); + SKP_Silk_regularize_correlations_FLP( WLTP_ptr, &rr[ k ], regu, LTP_ORDER ); + SKP_Silk_solve_LDL_FLP( WLTP_ptr, LTP_ORDER, Rr, b_ptr ); + + /* Calculate residual energy */ + nrg[ k ] = SKP_Silk_residual_energy_covar_FLP( b_ptr, WLTP_ptr, Rr, rr[ k ], LTP_ORDER ); + + temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); + SKP_Silk_scale_vector_FLP( WLTP_ptr, temp, LTP_ORDER * LTP_ORDER ); + w[ k ] = matrix_ptr( WLTP_ptr, LTP_ORDER / 2, LTP_ORDER / 2, LTP_ORDER ); + + r_ptr += subfr_length; + b_ptr += LTP_ORDER; + WLTP_ptr += LTP_ORDER * LTP_ORDER; + } + + /* Compute LTP coding gain */ + if( LTPredCodGain != NULL ) { + LPC_LTP_res_nrg = 1e-6f; + LPC_res_nrg = 0.0f; + for( k = 0; k < nb_subfr; k++ ) { + LPC_res_nrg += rr[ k ] * Wght[ k ]; + LPC_LTP_res_nrg += nrg[ k ] * Wght[ k ]; + } + + SKP_assert( LPC_LTP_res_nrg > 0 ); + *LTPredCodGain = 3.0f * SKP_Silk_log2( LPC_res_nrg / LPC_LTP_res_nrg ); + } + + /* Smoothing */ + /* d = sum( B, 1 ); */ + b_ptr = b; + for( k = 0; k < nb_subfr; k++ ) { + d[ k ] = 0; + for( i = 0; i < LTP_ORDER; i++ ) { + d[ k ] += b_ptr[ i ]; + } + b_ptr += LTP_ORDER; + } + /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */ + temp = 1e-3f; + for( k = 0; k < nb_subfr; k++ ) { + temp += w[ k ]; + } + m = 0; + for( k = 0; k < nb_subfr; k++ ) { + m += d[ k ] * w[ k ]; + } + m = m / temp; + + b_ptr = b; + for( k = 0; k < nb_subfr; k++ ) { + g = LTP_SMOOTHING / ( LTP_SMOOTHING + w[ k ] ) * ( m - d[ k ] ); + temp = 0; + for( i = 0; i < LTP_ORDER; i++ ) { + delta_b[ i ] = SKP_max_float( b_ptr[ i ], 0.1f ); + temp += delta_b[ i ]; + } + temp = g / temp; + for( i = 0; i < LTP_ORDER; i++ ) { + b_ptr[ i ] = b_ptr[ i ] + delta_b[ i ] * temp; + } + b_ptr += LTP_ORDER; + } +} diff --git a/src_FLP/SKP_Silk_find_pitch_lags_FLP.c b/src_FLP/SKP_Silk_find_pitch_lags_FLP.c new file mode 100644 index 000000000..09482dc65 --- /dev/null +++ b/src_FLP/SKP_Silk_find_pitch_lags_FLP.c @@ -0,0 +1,112 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include <stdlib.h> +#include "SKP_Silk_main_FLP.h" + +void SKP_Silk_find_pitch_lags_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_float res[], /* O Residual */ + const SKP_float x[] /* I Speech signal */ +) +{ + SKP_Silk_predict_state_FLP *psPredSt = &psEnc->sPred; + const SKP_float *x_buf_ptr, *x_buf; + SKP_float auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ]; + SKP_float A[ MAX_FIND_PITCH_LPC_ORDER ]; + SKP_float refl_coef[ MAX_FIND_PITCH_LPC_ORDER ]; + SKP_float Wsig[ FIND_PITCH_LPC_WIN_MAX ]; + SKP_float thrhld, *Wsig_ptr; + SKP_int buf_len; + + /******************************************/ + /* Setup buffer lengths etc based on Fs */ + /******************************************/ + buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length; + + /* Safty check */ + SKP_assert( buf_len >= psPredSt->pitch_LPC_win_length ); + + x_buf = x - psEnc->sCmn.ltp_mem_length; + + /******************************************/ + /* Estimate LPC AR coeficients */ + /******************************************/ + + /* Calculate windowed signal */ + + /* First LA_LTP samples */ + x_buf_ptr = x_buf + buf_len - psPredSt->pitch_LPC_win_length; + Wsig_ptr = Wsig; + SKP_Silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch ); + + /* Middle non-windowed samples */ + Wsig_ptr += psEnc->sCmn.la_pitch; + x_buf_ptr += psEnc->sCmn.la_pitch; + SKP_memcpy( Wsig_ptr, x_buf_ptr, ( psPredSt->pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ) ) * sizeof( SKP_float ) ); + + /* Last LA_LTP samples */ + Wsig_ptr += psPredSt->pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ); + x_buf_ptr += psPredSt->pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ); + SKP_Silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch ); + + /* Calculate autocorrelation sequence */ + SKP_Silk_autocorrelation_FLP( auto_corr, Wsig, psPredSt->pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 ); + + /* Add white noise, as a fraction of the energy */ + auto_corr[ 0 ] += auto_corr[ 0 ] * FIND_PITCH_WHITE_NOISE_FRACTION; + + /* Calculate the reflection coefficients using Schur */ + SKP_Silk_schur_FLP( refl_coef, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder ); + + /* Convert reflection coefficients to prediction coefficients */ + SKP_Silk_k2a_FLP( A, refl_coef, psEnc->sCmn.pitchEstimationLPCOrder ); + + /* Bandwidth expansion */ + SKP_Silk_bwexpander_FLP( A, psEnc->sCmn.pitchEstimationLPCOrder, FIND_PITCH_BANDWITH_EXPANSION ); + + /*****************************************/ + /* 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 ) ); + + /* Threshold for pitch estimator */ + thrhld = 0.5f; + thrhld -= 0.004f * psEnc->sCmn.pitchEstimationLPCOrder; + thrhld -= 0.1f * ( SKP_float )sqrt( psEnc->speech_activity ); + thrhld += 0.14f * psEnc->sCmn.prev_sigtype; + thrhld -= 0.12f * psEncCtrl->input_tilt; + + /*****************************************/ + /* Call Pitch estimator */ + /*****************************************/ + psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core_FLP( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, + &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->pitchEstimationThreshold, + thrhld, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr ); +} diff --git a/src_FLP/SKP_Silk_find_pred_coefs_FLP.c b/src_FLP/SKP_Silk_find_pred_coefs_FLP.c new file mode 100644 index 000000000..9553f0c16 --- /dev/null +++ b/src_FLP/SKP_Silk_find_pred_coefs_FLP.c @@ -0,0 +1,110 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + + +void SKP_Silk_find_pred_coefs_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 res_pitch[] /* I Residual from pitch analysis */ +) +{ + SKP_int i; + SKP_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; + SKP_float invGains[ MAX_NB_SUBFR ], Wght[ MAX_NB_SUBFR ]; + SKP_float NLSF[ MAX_LPC_ORDER ]; + 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 ); + invGains[ i ] = 1.0f / psEncCtrl->Gains[ i ]; + Wght[ i ] = invGains[ i ] * invGains[ i ]; + } + + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + /**********/ + /* VOICED */ + /**********/ + SKP_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.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 ); + + /* Quantize LTP gain parameters */ + SKP_Silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, + WLTP, psEnc->mu_LTP, psEnc->sCmn.LTPQuantLowComplexity , psEnc->sCmn.nb_subfr ); + + /* Control LTP scaling */ + SKP_Silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl ); + + /* 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 ); + + } else { + /************/ + /* UNVOICED */ + /************/ + /* Create signal with prepended subframes, scaled by inverse gains */ + x_ptr = psEnc->x_buf + psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder; + x_pre_ptr = LPC_in_pre; + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + SKP_Silk_scale_copy_vector_FLP( x_pre_ptr, x_ptr, invGains[ i ], + psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); + x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder; + x_ptr += psEnc->sCmn.subfr_length; + } + + SKP_memset( psEncCtrl->LTPCoef, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( SKP_float ) ); + psEncCtrl->LTPredCodGain = 0.0f; + } + + /* 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, + 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 */ + SKP_Silk_process_NLSFs_FLP( psEnc, psEncCtrl, NLSF ); + + /* Calculate residual energy using quantized LPC coefficients */ + SKP_Silk_residual_energy_FLP( psEncCtrl->ResNrg, LPC_in_pre, psEncCtrl->PredCoef, psEncCtrl->Gains, + psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); + + /* Copy to prediction struct for use in next frame for fluctuation reduction */ + SKP_memcpy( psEnc->sPred.prev_NLSFq, NLSF, psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); + + +} + diff --git a/src_FLP/SKP_Silk_init_encoder_FLP.c b/src_FLP/SKP_Silk_init_encoder_FLP.c new file mode 100644 index 000000000..d9a17a7ca --- /dev/null +++ b/src_FLP/SKP_Silk_init_encoder_FLP.c @@ -0,0 +1,63 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include <stdlib.h> +#include "SKP_Silk_main_FLP.h" + +/*********************************/ +/* Initialize Silk Encoder state */ +/*********************************/ +SKP_int SKP_Silk_init_encoder_FLP( + SKP_Silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */ +) { + SKP_int ret = 0; + + /* Clear the entire encoder state */ + SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FLP ) ); + + /* Initialize to 24 kHz API sampling, 24 kHz max internal sampling, 20 ms packets, 25 kbps, 0% packet loss, and init non-zero values */ + ret = SKP_Silk_control_encoder_FLP( psEnc, 24000, 24, 20, 25, 0, 0, 0, 10, 0 ); + +#if HIGH_PASS_INPUT + psEnc->variable_HP_smth1 = SKP_Silk_log2( 70.0 ); + psEnc->variable_HP_smth2 = SKP_Silk_log2( 70.0 ); +#endif + + /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */ + psEnc->sCmn.first_frame_after_reset = 1; + psEnc->sCmn.fs_kHz_changed = 0; + psEnc->sCmn.LBRR_enabled = 0; + + /* 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 new file mode 100644 index 000000000..1612e09c8 --- /dev/null +++ b/src_FLP/SKP_Silk_main_FLP.h @@ -0,0 +1,435 @@ +/*********************************************************************** +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_MAIN_FLP_H +#define SKP_SILK_MAIN_FLP_H + +#include "SKP_Silk_SigProc_FLP.h" +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_structs_FLP.h" +#include "SKP_Silk_tables_FLP.h" +#include "SKP_Silk_main.h" +#include "SKP_Silk_define_FLP.h" + +/* uncomment to compile without SSE optimizations */ +//#undef SKP_USE_SSE + +#ifdef __cplusplus +extern "C" +{ +#endif + +void SKP_Silk_LBRR_ctrl_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I Encoder state FLP */ + SKP_Silk_encoder_control *psEncCtrl /* I/O Encoder control */ +); + +void SKP_Silk_LTP_scale_ctrl_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control 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 */ + const SKP_float W[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error weights */ + const SKP_float mu, /* I Mu value (R/D tradeoff) */ + const SKP_int lowComplexity, /* I Flag for low complexity */ + const SKP_int nb_subfr /* I number of subframes */ +); + +/*********************/ +/* Encoder Functions */ +/*********************/ + +/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ +void SKP_Silk_HP_variable_cutoff_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_int16 *out, /* O High-pass filtered output signal */ + const SKP_int16 *in /* I Input signal */ +); + +/* Encoder main function */ +SKP_int SKP_Silk_encode_frame_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_uint8 *pCode, /* O Payload */ + SKP_int16 *pnBytesOut, /* I/O Number of payload bytes; */ + /* input: max length; output: used */ + const SKP_int16 *pIn /* I Input speech frame */ +); + +/* Limit, stabilize, and quantize NLSFs */ +void SKP_Silk_process_NLSFs_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_float *pNLSF /* I/O NLSFs (quantized output) */ +); + +/* 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_int16 *pnBytesOut, /* I/O Payload bytes; in: max; out: used */ + const SKP_float xfw[] /* I Input signal */ +); + +/* Initializes the Silk encoder state */ +SKP_int SKP_Silk_init_encoder_FLP( + SKP_Silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */ +); + +/* Control the Silk encoder */ +SKP_int SKP_Silk_control_encoder_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ + const SKP_int32 API_fs_Hz, /* I External (API) sampling rate (Hz) */ + const SKP_int max_internal_fs_kHz,/* I Maximum internal sampling rate (kHz) */ + const SKP_int PacketSize_ms, /* I Packet length (ms) */ + SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */ + const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */ + const SKP_int INBandFEC_enabled, /* I Enable (1) / disable (0) inband FEC */ + const SKP_int DTX_enabled, /* I Enable / disable DTX */ + const SKP_int InputFramesize_ms, /* I Inputframe in ms */ + const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */ +); + +/****************/ +/* Prefiltering */ +/****************/ +/* Main Prefilter Function */ +void SKP_Silk_prefilter_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + const SKP_Silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */ + SKP_float xw[], /* O Weighted signal */ + const SKP_float x[] /* I Speech signal */ +); + +/**************************/ +/* Noise shaping analysis */ +/**************************/ +/* Compute noise shaping coefficients and initial gain values */ +void SKP_Silk_noise_shape_analysis_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 *pitch_res, /* I LPC residual from pitch analysis */ + const SKP_float *x /* I Input signal [frame_length + la_shape] */ +); + +/* Autocorrelations for a warped frequency axis */ +void SKP_Silk_warped_autocorrelation_FLP( + SKP_float *corr, /* O Result [order + 1] */ + const SKP_float *input, /* I Input data to correlate */ + const SKP_float warping, /* I Warping coefficient */ + const SKP_int length, /* I Length of input */ + const SKP_int order /* I Correlation order (even) */ +); + +/**************/ +/* Find pitch */ +/**************/ +void SKP_Silk_find_pitch_lags_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_float res[], /* O Residual */ + const SKP_float x[] /* I Speech signal */ +); + +/******************/ +/* NLSF Quantizer */ +/******************/ +/* NLSF vector encoder */ +void SKP_Silk_NLSF_MSVQ_encode_FLP( + SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */ + SKP_float *pNLSF, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP, /* I Codebook object */ + const SKP_float *pNLSF_q_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */ + const SKP_float *pW, /* I NLSF weight vector [ LPC_ORDER ] */ + const SKP_float NLSF_mu, /* I Rate weight for the RD optimization */ + const SKP_float NLSF_mu_fluc_red, /* I Fluctuation reduction error weight */ + const SKP_int NLSF_MSVQ_Survivors,/* I Max survivors from each stage */ + const SKP_int LPC_order, /* I LPC order */ + const SKP_int deactivate_fluc_red /* I Deactivate fluctuation reduction */ +); + +/* NLSF vector decoder */ +void SKP_Silk_NLSF_MSVQ_decode_FLP( + SKP_float *pNLSF, /* O Decoded output vector [ LPC_ORDER ] */ + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP, /* I NLSF codebook struct */ + const SKP_int *NLSFIndices, /* I NLSF indices [ nStages ] */ + const SKP_int LPC_order /* I LPC order used */ +); + +/* Rate-Distortion calculations for multiple input data vectors */ +void SKP_Silk_NLSF_VQ_rate_distortion_FLP( + SKP_float *pRD, /* O Rate-distortion values [psNLSF_CBS_FLP->nVectors*N] */ + const SKP_Silk_NLSF_CBS_FLP *psNLSF_CBS_FLP, /* I NLSF codebook stage struct */ + const SKP_float *in, /* I Input vectors to be quantized */ + const SKP_float *w, /* I Weight vector */ + const SKP_float *rate_acc, /* I Accumulated rates from previous stage */ + const SKP_float mu, /* I Weight between weighted error and rate */ + const SKP_int N, /* I Number of input vectors to be quantized */ + const SKP_int LPC_order /* I LPC order */ +); + +/* compute weighted quantization errors for LPC_order element input vectors, over one codebook stage */ +void SKP_Silk_NLSF_VQ_sum_error_FLP( + SKP_float *err, /* O Weighted quantization errors [ N * K ] */ + const SKP_float *in, /* I Input vectors [ N * LPC_order ] */ + const SKP_float *w, /* I Weighting vectors [ N * LPC_order ] */ + const SKP_float *pCB, /* I Codebook vectors [ K * LPC_order ] */ + const SKP_int N, /* I Number of input vectors */ + const SKP_int K, /* I Number of codebook vectors */ + const SKP_int LPC_order /* I LPC order */ +); + +/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ +SKP_float SKP_Silk_residual_energy_covar_FLP( /* O Weighted residual energy */ + const SKP_float *c, /* I Filter coefficients */ + SKP_float *wXX, /* I/O Weighted correlation matrix, reg. out */ + const SKP_float *wXx, /* I Weighted correlation vector */ + const SKP_float wxx, /* I Weighted correlation value */ + const SKP_int D /* I Dimension */ +); + +/* Entropy constrained MATRIX-weighted VQ, for a single input data vector */ +void SKP_Silk_VQ_WMat_EC_FLP( + SKP_int *ind, /* O Index of best codebook vector */ + SKP_float *rate_dist, /* O Best weighted quant. error + mu * rate */ + const SKP_float *in, /* I Input vector to be quantized */ + const SKP_float *W, /* I Weighting matrix */ + const SKP_int16 *cb, /* I Codebook */ + const SKP_int16 *cl_Q6, /* I Code length for each codebook vector */ + const SKP_float mu, /* I Tradeoff between WSSE and rate */ + const SKP_int L /* I Number of vectors in codebook */ +); + +/* Processing of gains */ +void SKP_Silk_process_gains_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ +); + +void SKP_Silk_find_LTP_FLP( + SKP_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ + SKP_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ + SKP_float *LTPredCodGain, /* O LTP coding gain */ + const SKP_float r_lpc[], /* I LPC residual */ + const SKP_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ + const SKP_float Wght[ MAX_NB_SUBFR ], /* I Weights */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int mem_offset /* I Number of samples in LTP memory */ +); + +void SKP_Silk_find_LPC_FLP( + SKP_float NLSF[], /* O NLSFs */ + SKP_int *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 */ + const SKP_float x[], /* I Input signal */ + const SKP_int subfr_length, /* I Subframe length incl preceeding samples */ + const SKP_int nb_subfr /* I: Number of subframes */ +); + +void SKP_Silk_LTP_analysis_filter_FLP( + SKP_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */ + const SKP_float *x, /* I Input signal, with preceeding samples */ + const SKP_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */ + const SKP_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ + const SKP_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */ + const SKP_int subfr_length, /* I Length of each subframe */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int pre_length /* I Preceeding samples for each subframe */ +); + +void SKP_Silk_residual_energy_FLP( + SKP_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + const SKP_float x[], /* I Input signal */ + const SKP_float a[ 2 ][ MAX_LPC_ORDER ],/* I AR coefs for each frame half */ + const SKP_float gains[], /* I Quantization gains */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int LPC_order /* I LPC order */ +); + +void SKP_Silk_find_pred_coefs_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 res_pitch[] /* I Residual from pitch analysis */ +); + +/* 16th order LPC analysis filter */ +void SKP_Silk_LPC_analysis_filter_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length, /* I Length of input signal */ + const SKP_int Order /* I LPC order */ +); + +/* 16th order LPC analysis filter, does not write first 16 samples */ +void SKP_Silk_LPC_analysis_filter16_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +); + +/* 12th order LPC analysis filter, does not write first 12 samples */ +void SKP_Silk_LPC_analysis_filter12_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +); + +/* 10th order LPC analysis filter, does not write first 10 samples */ +void SKP_Silk_LPC_analysis_filter10_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +); + +/* 8th order LPC analysis filter, does not write first 8 samples */ +void SKP_Silk_LPC_analysis_filter8_FLP( + SKP_float r_LPC[], /* O LPC residual signal */ + const SKP_float PredCoef[], /* I LPC coefficients */ + const SKP_float s[], /* I Input signal */ + const SKP_int length /* I Length of input signal */ +); + +/******************/ +/* Linear Algebra */ +/******************/ +/* Calculates correlation matrix X'*X */ +void SKP_Silk_corrMatrix_FLP( + const SKP_float *x, /* I x vector [ L+order-1 ] used to create X */ + const SKP_int L, /* I Length of vectors */ + const SKP_int Order, /* I Max lag for correlation */ + SKP_float *XX /* O X'*X correlation matrix [order x order] */ +); + +/* Calculates correlation vector X'*t */ +void SKP_Silk_corrVector_FLP( + const SKP_float *x, /* I x vector [L+order-1] used to create X */ + const SKP_float *t, /* I Target vector [L] */ + const SKP_int L, /* I Length of vecors */ + const SKP_int Order, /* I Max lag for correlation */ + SKP_float *Xt /* O X'*t correlation vector [order] */ +); + +void SKP_Silk_regularize_correlations_FLP( + SKP_float *XX, /* I/O Correlation matrices */ + SKP_float *xx, /* I/O Correlation values */ + const SKP_float noise, /* I Noise energy to add */ + const SKP_int D /* I Dimension of XX */ +); + +/* Function to solve linear equation Ax = b, when A is an MxM symmetric square matrix */ +void SKP_Silk_solve_LDL_FLP( + SKP_float *A, /* I/O Symmetric square matrix, out: reg. */ + const SKP_int M, /* I Size of matrix */ + const SKP_float *b, /* I Pointer to b vector */ + SKP_float *x /* O Pointer to x solution vector */ +); + +/* Apply sine window to signal vector. */ +/* Window types: */ +/* 0 -> sine window from 0 to pi */ +/* 1 -> sine window from 0 to pi/2 */ +/* 2 -> sine window from pi/2 to pi */ +void SKP_Silk_apply_sine_window_FLP( + SKP_float px_win[], /* O Pointer to windowed signal */ + const SKP_float px[], /* I Pointer to input signal */ + const SKP_int win_type, /* I Selects a window type */ + const SKP_int length /* I Window length, multiple of 4 */ +); + +/* Wrappers. Calls flp / fix code */ + +/* Convert AR filter coefficients to NLSF parameters */ +void SKP_Silk_A2NLSF_FLP( + SKP_float *pNLSF, /* O NLSF vector [ LPC_order ] */ + const SKP_float *pAR, /* I LPC coefficients [ LPC_order ] */ + const SKP_int LPC_order /* I LPC order */ +); + +/* Convert NLSF parameters to AR prediction filter coefficients */ +void SKP_Silk_NLSF2A_stable_FLP( + SKP_float *pAR, /* O LPC coefficients [ LPC_order ] */ + const SKP_float *pNLSF, /* I NLSF vector [ LPC_order ] */ + const SKP_int LPC_order /* I LPC order */ +); + +/* NLSF stabilizer, for a single input data vector */ +void SKP_Silk_NLSF_stabilize_FLP( + SKP_float *pNLSF, /* I/O (Un)stable NLSF vector [ LPC_order ] */ + const SKP_float *pNDelta_min, /* I Normalized delta min vector[LPC_order+1]*/ + const SKP_int LPC_order /* I LPC order */ +); + +/* Interpolation function with fixed point rounding */ +void SKP_Silk_interpolate_wrapper_FLP( + SKP_float xi[], /* O Interpolated vector */ + const SKP_float x0[], /* I First vector */ + const SKP_float x1[], /* I Second vector */ + const SKP_float ifact, /* I Interp. factor, weight on second vector */ + const SKP_int d /* I Number of parameters */ +); + +/****************************************/ +/* Floating-point Silk VAD wrapper */ +/****************************************/ +SKP_int SKP_Silk_VAD_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_int16 *pIn /* I Input signal */ +); + +/****************************************/ +/* Floating-point Silk NSQ wrapper */ +/****************************************/ +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 */ +); + +/* using log2() helps the fixed-point conversion */ +SKP_INLINE SKP_float SKP_Silk_log2( double x ) { return ( SKP_float )( 3.32192809488736 * log10( x ) ); } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c b/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c new file mode 100644 index 000000000..0511ebed6 --- /dev/null +++ b/src_FLP/SKP_Silk_noise_shape_analysis_FLP.c @@ -0,0 +1,367 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" +#include "SKP_Silk_perceptual_parameters.h" + +/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a */ +/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.) */ +SKP_INLINE SKP_float warped_gain( + const SKP_float *coefs, + SKP_float lambda, + SKP_int order +) { + SKP_int i; + SKP_float gain; + + lambda = -lambda; + gain = coefs[ order - 1 ]; + for( i = order - 2; i >= 0; i-- ) { + gain = lambda * gain + coefs[ i ]; + } + return (SKP_float)( 1.0f / ( 1.0f - lambda * gain ) ); +} + +/* Convert warped filter coefficients to monic pseudo-warped coefficients */ +SKP_INLINE void warped_true2monic_coefs( + SKP_float *coefs, + SKP_float lambda, + SKP_int order +) { + SKP_int i; + SKP_float gain; + + lambda = -lambda; + for( i = order - 1; i > 0; i-- ) { + coefs[ i - 1 ] += lambda * coefs[ i ]; + } + gain = ( 1.0f - lambda * lambda ) / ( 1.0f - lambda * coefs[ 0 ] ); + for( i = 0; i < order; i++ ) { + coefs[ i ] *= gain; + } +} + +/* Limit max amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ +SKP_INLINE void limit_warped_coefs( + SKP_float *coefs_syn, + SKP_float *coefs_ana, + SKP_float lambda, + SKP_float limit, + SKP_int order +) { + SKP_int i, iter, ind; + SKP_float tmp, maxabs, chirp; + + for( iter = 0; iter < 10; iter++ ) { + /* Find maximum absolute value */ + ind = 1; + maxabs = SKP_abs( coefs_syn[ ind ] ); + for( i = 2; i < order - 1; i++ ) { + tmp = SKP_abs( coefs_syn[ i ] ); + if( tmp > maxabs ) { + maxabs = tmp; + ind = i; + } + } + if( maxabs <= limit ) { + return; + } + + /* Convert to true warped coefficients */ + for( i = 1; i < order; i++ ) { + coefs_syn[ i - 1 ] += lambda * coefs_syn[ i ]; + coefs_ana[ i - 1 ] += lambda * coefs_ana[ i ]; + } + + /* Apply bandwidth expansion */ + chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs * ( ind + 1 ) ); + SKP_Silk_bwexpander_FLP( coefs_syn, order, chirp ); + SKP_Silk_bwexpander_FLP( coefs_ana, order, chirp ); + + /* Convert back to monic warped coefficients */ + for( i = order - 1; i > 0; i-- ) { + coefs_syn[ i - 1 ] -= lambda * coefs_syn[ i ]; + coefs_ana[ i - 1 ] -= lambda * coefs_ana[ i ]; + } + } +} + +/* Compute noise shaping coefficients and initial gain values */ +void SKP_Silk_noise_shape_analysis_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 *pitch_res, /* I LPC residual from pitch analysis */ + const SKP_float *x /* I Input signal [frame_length + la_shape] */ +) +{ + SKP_Silk_shape_state_FLP *psShapeSt = &psEnc->sShape; + SKP_int k, nSamples; + SKP_float SNR_adj_dB, HarmBoost, HarmShapeGain, Tilt; + SKP_float nrg, pre_nrg, log_energy, log_energy_prev, energy_variation; + SKP_float delta, BWExp1, BWExp2, gain_mult, gain_add, strength, b, warping; + SKP_float x_windowed[ SHAPE_LPC_WIN_MAX ]; + SKP_float auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; + const SKP_float *x_ptr, *pitch_res_ptr; + + /* Point to start of first LPC analysis block */ + x_ptr = x + psEnc->sCmn.la_shape - SHAPE_LPC_WIN_MS * psEnc->sCmn.fs_kHz + psEnc->sCmn.subfr_length; + + /****************/ + /* CONTROL SNR */ + /****************/ + /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */ + psEncCtrl->current_SNR_dB = psEnc->SNR_dB - 0.05f * 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; + } + + /****************/ + /* GAIN CONTROL */ + /****************/ + /* Input quality is the average of the quality in the lowest two VAD bands */ + psEncCtrl->input_quality = 0.5f * ( psEncCtrl->input_quality_bands[ 0 ] + psEncCtrl->input_quality_bands[ 1 ] ); + + /* Coding quality level, between 0.0 and 1.0 */ + psEncCtrl->coding_quality = SKP_sigmoid( 0.25f * ( psEncCtrl->current_SNR_dB - 17.0f ) ); + + /* Reduce coding SNR during low speech activity */ + b = 1.0f - psEnc->speech_activity; + SNR_adj_dB = psEncCtrl->current_SNR_dB - + BG_SNR_DECR_dB * psEncCtrl->coding_quality * ( 0.5f + 0.5f * psEncCtrl->input_quality ) * b * b; + + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + /* Reduce gains for periodic signals */ + SNR_adj_dB += HARM_SNR_INCR_dB * psEnc->LTPCorr; + } else { + /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */ + SNR_adj_dB += ( -0.4f * psEncCtrl->current_SNR_dB + 6.0f ) * ( 1.0f - psEncCtrl->input_quality ); + } + + /*************************/ + /* SPARSENESS PROCESSING */ + /*************************/ + /* Set quantizer offset */ + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + /* Initally set to 0; may be overruled in process_gains(..) */ + psEncCtrl->sCmn.QuantOffsetType = 0; + psEncCtrl->sparseness = 0.0f; + } else { + /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ + nSamples = 2 * psEnc->sCmn.fs_kHz; + energy_variation = 0.0f; + log_energy_prev = 0.0f; + pitch_res_ptr = pitch_res; + for( k = 0; k < SKP_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { + nrg = ( SKP_float )nSamples + ( SKP_float )SKP_Silk_energy_FLP( pitch_res_ptr, nSamples ); + log_energy = SKP_Silk_log2( nrg ); + if( k > 0 ) { + energy_variation += SKP_abs_float( log_energy - log_energy_prev ); + } + log_energy_prev = log_energy; + pitch_res_ptr += nSamples; + } + psEncCtrl->sparseness = SKP_sigmoid( 0.4f * ( energy_variation - 5.0f ) ); + + /* Set quantization offset depending on sparseness measure */ + if( psEncCtrl->sparseness > SPARSENESS_THRESHOLD_QNT_OFFSET ) { + psEncCtrl->sCmn.QuantOffsetType = 0; + } else { + psEncCtrl->sCmn.QuantOffsetType = 1; + } + + /* Increase coding SNR for sparse signals */ + SNR_adj_dB += SPARSE_SNR_INCR_dB * ( psEncCtrl->sparseness - 0.5f ); + } + + /*******************************/ + /* Control bandwidth expansion */ + /*******************************/ + delta = LOW_RATE_BANDWIDTH_EXPANSION_DELTA * ( 1.0f - 0.75f * psEncCtrl->coding_quality ); + BWExp1 = BANDWIDTH_EXPANSION - delta; + BWExp2 = BANDWIDTH_EXPANSION + delta; + if( psEnc->sCmn.fs_kHz == 24 ) { + /* Less bandwidth expansion for super wideband */ + BWExp1 = 1.0f - ( 1.0f - BWExp1 ) * SWB_BANDWIDTH_EXPANSION_REDUCTION; + BWExp2 = 1.0f - ( 1.0f - BWExp2 ) * SWB_BANDWIDTH_EXPANSION_REDUCTION; + } + /* BWExp1 will be applied after BWExp2, so make it relative */ + BWExp1 /= BWExp2; + + /* Warping coefficient */ + psEncCtrl->sCmn.warping_Q16 = psEnc->sCmn.fs_kHz * WARPING_MULTIPLIER_Q16; + psEncCtrl->sCmn.warping_Q16 = SKP_min( psEncCtrl->sCmn.warping_Q16, 32767 ); + warping = (SKP_float)psEncCtrl->sCmn.warping_Q16 / 65536.0f; + + /********************************************/ + /* Compute noise shaping AR coefs and gains */ + /********************************************/ + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + /* Apply window */ + SKP_Silk_apply_sine_window_FLP( x_windowed, x_ptr, 0, SHAPE_LPC_WIN_MS * psEnc->sCmn.fs_kHz ); + + /* Update pointer: next LPC analysis block */ + x_ptr += psEnc->sCmn.subfr_length; + + /* Calculate warped auto correlation */ + SKP_Silk_warped_autocorrelation_FLP( auto_corr, x_windowed, warping, + SHAPE_LPC_WIN_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.shapingLPCOrder ); + + /* Add white noise, as a fraction of energy */ + auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION; + + /* Convert correlations to prediction coefficients, and compute residual energy */ + nrg = SKP_Silk_levinsondurbin_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], auto_corr, psEnc->sCmn.shapingLPCOrder ); + + /* Convert residual energy to non-warped scale */ + gain_mult = warped_gain( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); + nrg *= gain_mult * gain_mult; + + /* Bandwidth expansion for synthesis filter shaping */ + SKP_Silk_bwexpander_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp2 ); + + /* Compute noise shaping filter coefficients */ + SKP_memcpy( + &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], + &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], + psEnc->sCmn.shapingLPCOrder * sizeof( SKP_float ) ); + + /* Bandwidth expansion for analysis filter shaping */ + SKP_Silk_bwexpander_FLP( &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp1 ); + + /* Increase residual energy */ + nrg += SHAPE_MIN_ENERGY_RATIO * auto_corr[ 0 ]; + psEncCtrl->Gains[ k ] = ( SKP_float )sqrt( nrg ); + + /* Ratio of prediction gains, in energy domain */ + SKP_Silk_LPC_inverse_pred_gain_FLP( &pre_nrg, &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); + SKP_Silk_LPC_inverse_pred_gain_FLP( &nrg, &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); + psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ); + + /* Convert to monic warped prediction coefficients */ + warped_true2monic_coefs( &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); + warped_true2monic_coefs( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); + + /* Limit absolute values */ + limit_warped_coefs( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], + warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); + } + + /*****************/ + /* Gain tweaking */ + /*****************/ + /* Increase gains during low speech activity and put lower limit on gains */ + gain_mult = ( SKP_float )pow( 2.0f, -0.16f * SNR_adj_dB ); + gain_add = ( SKP_float )pow( 2.0f, 0.16f * NOISE_FLOOR_dB ) + + ( SKP_float )pow( 2.0f, 0.16f * RELATIVE_MIN_GAIN_dB ) * psEnc->avgGain; + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + psEncCtrl->Gains[ k ] *= gain_mult; + psEncCtrl->Gains[ k ] += gain_add; + psEnc->avgGain += psEnc->speech_activity * GAIN_SMOOTHING_COEF * ( psEncCtrl->Gains[ k ] - psEnc->avgGain ); + } + + /************************************************/ + /* Decrease level during fricatives (de-essing) */ + /************************************************/ + gain_mult = 1.0f + INPUT_TILT + psEncCtrl->coding_quality * HIGH_RATE_INPUT_TILT; + if( psEncCtrl->input_tilt <= 0.0f && psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED ) { + SKP_float essStrength = -psEncCtrl->input_tilt * psEnc->speech_activity * ( 1.0f - psEncCtrl->sparseness ); + if( psEnc->sCmn.fs_kHz == 24 ) { + gain_mult *= ( SKP_float )pow( 2.0f, -0.16f * DE_ESSER_COEF_SWB_dB * essStrength ); + } else if( psEnc->sCmn.fs_kHz == 16 ) { + gain_mult *= (SKP_float)pow( 2.0f, -0.16f * DE_ESSER_COEF_WB_dB * essStrength ); + } else { + SKP_assert( psEnc->sCmn.fs_kHz == 12 || psEnc->sCmn.fs_kHz == 8 ); + } + } + + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + psEncCtrl->GainsPre[ k ] *= gain_mult; + } + + /************************************************/ + /* Control low-frequency shaping and noise tilt */ + /************************************************/ + /* 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 ) ); + if( psEncCtrl->sCmn.sigtype == SIG_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 ]; + psEncCtrl->LF_MA_shp[ k ] = -1.0f + b; + psEncCtrl->LF_AR_shp[ k ] = 1.0f - b - b * strength; + } + Tilt = - HP_NOISE_COEF - + (1 - HP_NOISE_COEF) * HARM_HP_NOISE_COEF * psEnc->speech_activity; + } else { + b = 1.3f / psEnc->sCmn.fs_kHz; + psEncCtrl->LF_MA_shp[ 0 ] = -1.0f + b; + psEncCtrl->LF_AR_shp[ 0 ] = 1.0f - b - b * strength * 0.6f; + for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { + psEncCtrl->LF_MA_shp[ k ] = psEncCtrl->LF_MA_shp[ k - 1 ]; + psEncCtrl->LF_AR_shp[ k ] = psEncCtrl->LF_AR_shp[ k - 1 ]; + } + Tilt = -HP_NOISE_COEF; + } + + /****************************/ + /* HARMONIC SHAPING CONTROL */ + /****************************/ + /* Control boosting of harmonic frequencies */ + HarmBoost = LOW_RATE_HARMONIC_BOOST * ( 1.0f - psEncCtrl->coding_quality ) * psEnc->LTPCorr; + + /* More harmonic boost for noisy input signals */ + HarmBoost += LOW_INPUT_QUALITY_HARMONIC_BOOST * ( 1.0f - psEncCtrl->input_quality ); + + if( USE_HARM_SHAPING && psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + /* Harmonic noise shaping */ + HarmShapeGain = HARMONIC_SHAPING; + + /* More harmonic noise shaping for high bitrates or noisy input */ + HarmShapeGain += HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING * + ( 1.0f - ( 1.0f - psEncCtrl->coding_quality ) * psEncCtrl->input_quality ); + + /* Less harmonic noise shaping for less periodic signals */ + HarmShapeGain *= ( SKP_float )sqrt( psEnc->LTPCorr ); + } else { + HarmShapeGain = 0.0f; + } + + /*************************/ + /* Smooth over subframes */ + /*************************/ + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + psShapeSt->HarmBoost_smth += SUBFR_SMTH_COEF * ( HarmBoost - psShapeSt->HarmBoost_smth ); + psEncCtrl->HarmBoost[ k ] = psShapeSt->HarmBoost_smth; + psShapeSt->HarmShapeGain_smth += SUBFR_SMTH_COEF * ( HarmShapeGain - psShapeSt->HarmShapeGain_smth ); + psEncCtrl->HarmShapeGain[ k ] = psShapeSt->HarmShapeGain_smth; + psShapeSt->Tilt_smth += SUBFR_SMTH_COEF * ( Tilt - psShapeSt->Tilt_smth ); + psEncCtrl->Tilt[ k ] = psShapeSt->Tilt_smth; + } +} diff --git a/src_FLP/SKP_Silk_prefilter_FLP.c b/src_FLP/SKP_Silk_prefilter_FLP.c new file mode 100644 index 000000000..85bdb4453 --- /dev/null +++ b/src_FLP/SKP_Silk_prefilter_FLP.c @@ -0,0 +1,202 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" +#include "SKP_Silk_perceptual_parameters.h" + +/* +* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal +*/ +SKP_INLINE void SKP_Silk_prefilt_FLP( + SKP_Silk_prefilter_state_FLP *P,/* I/O state */ + SKP_float st_res[], /* I */ + SKP_float xw[], /* O */ + SKP_float *HarmShapeFIR, /* I */ + SKP_float Tilt, /* I */ + SKP_float LF_MA_shp, /* I */ + SKP_float LF_AR_shp, /* I */ + SKP_int lag, /* I */ + SKP_int length /* I */ +); + +void SKP_Silk_warped_LPC_analysis_filter_FLP( + SKP_float state[], /* I/O State [order + 1] */ + SKP_float res[], /* O Residual signal [length] */ + const SKP_float coef[], /* I Coefficients [order] */ + const SKP_float input[], /* I Input signal [length] */ + const SKP_float lambda, /* I Warping factor */ + const SKP_int length, /* I Length of input signal */ + const SKP_int order /* I Filter order (even) */ +) +{ + SKP_int n, i; + SKP_float acc, tmp1, tmp2; + + /* Order must be even */ + SKP_assert( ( order & 1 ) == 0 ); + + for( n = 0; n < length; n++ ) { + /* Output of lowpass section */ + tmp2 = state[ 0 ] + lambda * state[ 1 ]; + state[ 0 ] = input[ n ]; + /* Output of allpass section */ + tmp1 = state[ 1 ] + lambda * ( state[ 2 ] - tmp2 ); + state[ 1 ] = tmp2; + acc = coef[ 0 ] * tmp2; + /* Loop over allpass sections */ + for( i = 2; i < order; i += 2 ) { + /* Output of allpass section */ + tmp2 = state[ i ] + lambda * ( state[ i + 1 ] - tmp1 ); + state[ i ] = tmp1; + acc += coef[ i - 1 ] * tmp1; + /* Output of allpass section */ + tmp1 = state[ i + 1 ] + lambda * ( state[ i + 2 ] - tmp2 ); + state[ i + 1 ] = tmp2; + acc += coef[ i ] * tmp2; + } + state[ order ] = tmp1; + acc += coef[ order - 1 ] * tmp1; + res[ n ] = input[ n ] - acc; + } +} + +/* +* SKP_Silk_prefilter. Main prefilter function +*/ +void SKP_Silk_prefilter_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + const SKP_Silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */ + SKP_float xw[], /* O Weighted signal */ + const SKP_float x[] /* I Speech signal */ +) +{ + SKP_Silk_prefilter_state_FLP *P = &psEnc->sPrefilt; + SKP_int j, k, lag; + SKP_float HarmShapeGain, Tilt, LF_MA_shp, LF_AR_shp; + SKP_float B[ 2 ]; + const SKP_float *AR1_shp; + const SKP_float *px; + SKP_float *pxw; + SKP_float HarmShapeFIR[ 3 ]; + SKP_float st_res[ MAX_SUB_FRAME_LENGTH + MAX_LPC_ORDER ]; + + /* Setup pointers */ + px = x; + pxw = xw; + lag = P->lagPrev; + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + /* Update Variables that change per sub frame */ + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + lag = psEncCtrl->sCmn.pitchL[ k ]; + } + + /* Noise shape parameters */ + HarmShapeGain = psEncCtrl->HarmShapeGain[ k ] * ( 1.0f - psEncCtrl->HarmBoost[ k ] ); + HarmShapeFIR[ 0 ] = SKP_Silk_HarmShapeFIR_FLP[ 0 ] * HarmShapeGain; + HarmShapeFIR[ 1 ] = SKP_Silk_HarmShapeFIR_FLP[ 1 ] * HarmShapeGain; + HarmShapeFIR[ 2 ] = SKP_Silk_HarmShapeFIR_FLP[ 2 ] * HarmShapeGain; + Tilt = psEncCtrl->Tilt[ k ]; + LF_MA_shp = psEncCtrl->LF_MA_shp[ k ]; + LF_AR_shp = psEncCtrl->LF_AR_shp[ k ]; + AR1_shp = &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ]; + + /* Short term FIR filtering*/ + SKP_Silk_warped_LPC_analysis_filter_FLP( P->sAR_shp1, st_res, AR1_shp, px, + (SKP_float)psEncCtrl->sCmn.warping_Q16 / 65536.0f, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder ); + + /* reduce (mainly) low frequencies during harmonic emphasis */ + B[ 0 ] = psEncCtrl->GainsPre[ k ]; + B[ 1 ] = -psEncCtrl->GainsPre[ k ] * + ( psEncCtrl->HarmBoost[ k ] * HarmShapeGain + INPUT_TILT + psEncCtrl->coding_quality * HIGH_RATE_INPUT_TILT ); + pxw[ 0 ] = B[ 0 ] * st_res[ 0 ] + B[ 1 ] * P->sHarmHP; + for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) { + pxw[ j ] = B[ 0 ] * st_res[ j ] + B[ 1 ] * st_res[ j - 1 ]; + } + P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ]; + + SKP_Silk_prefilt_FLP( P, pxw, pxw, HarmShapeFIR, Tilt, LF_MA_shp, LF_AR_shp, lag, psEnc->sCmn.subfr_length ); + + px += psEnc->sCmn.subfr_length; + pxw += psEnc->sCmn.subfr_length; + } + P->lagPrev = psEncCtrl->sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; +} + +/* +* SKP_Silk_prefilter_part1. Prefilter for finding Quantizer input signal +*/ +SKP_INLINE void SKP_Silk_prefilt_FLP( + SKP_Silk_prefilter_state_FLP *P,/* I/O state */ + SKP_float st_res[], /* I */ + SKP_float xw[], /* O */ + SKP_float *HarmShapeFIR, /* I */ + SKP_float Tilt, /* I */ + SKP_float LF_MA_shp, /* I */ + SKP_float LF_AR_shp, /* I */ + SKP_int lag, /* I */ + SKP_int length /* I */ +) +{ + SKP_int i; + SKP_int idx, LTP_shp_buf_idx; + SKP_float n_Tilt, n_LF, n_LTP; + SKP_float sLF_AR_shp, sLF_MA_shp; + SKP_float *LTP_shp_buf; + + /* To speed up use temp variables instead of using the struct */ + LTP_shp_buf = P->sLTP_shp1; + LTP_shp_buf_idx = P->sLTP_shp_buf_idx1; + sLF_AR_shp = P->sLF_AR_shp1; + sLF_MA_shp = P->sLF_MA_shp1; + + for( i = 0; i < length; i++ ) { + if( lag > 0 ) { + SKP_assert( HARM_SHAPE_FIR_TAPS == 3 ); + idx = lag + LTP_shp_buf_idx; + n_LTP = LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ] * HarmShapeFIR[ 0 ]; + n_LTP += LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 ) & LTP_MASK ] * HarmShapeFIR[ 1 ]; + n_LTP += LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ] * HarmShapeFIR[ 2 ]; + } else { + n_LTP = 0; + } + + n_Tilt = sLF_AR_shp * Tilt; + n_LF = sLF_AR_shp * LF_AR_shp + sLF_MA_shp * LF_MA_shp; + + sLF_AR_shp = st_res[ i ] - n_Tilt; + sLF_MA_shp = sLF_AR_shp - n_LF; + + LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; + LTP_shp_buf[ LTP_shp_buf_idx ] = sLF_MA_shp; + + xw[ i ] = sLF_MA_shp - n_LTP; + } + /* Copy temp variable back to state */ + P->sLF_AR_shp1 = sLF_AR_shp; + P->sLF_MA_shp1 = sLF_MA_shp; + P->sLTP_shp_buf_idx1 = LTP_shp_buf_idx; +} diff --git a/src_FLP/SKP_Silk_process_NLSFs_FLP.c b/src_FLP/SKP_Silk_process_NLSFs_FLP.c new file mode 100644 index 000000000..e1ceff500 --- /dev/null +++ b/src_FLP/SKP_Silk_process_NLSFs_FLP.c @@ -0,0 +1,106 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include <stdlib.h> +#include "SKP_Silk_main_FLP.h" + +/* Limit, stabilize, convert and quantize NLSFs */ +void SKP_Silk_process_NLSFs_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + SKP_float *pNLSF /* I/O NLSFs (quantized output) */ +) +{ + SKP_int doInterpolate; + SKP_float pNLSFW[ MAX_LPC_ORDER ]; + SKP_float NLSF_mu, NLSF_mu_fluc_red, i_sqr, NLSF_interpolation_factor = 0.0f; + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP; + + /* Used only for NLSF interpolation */ + SKP_float pNLSF0_temp[ MAX_LPC_ORDER ]; + SKP_float pNLSFW0_temp[ MAX_LPC_ORDER ]; + SKP_int i; + + SKP_assert( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED || psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED ); + + /***********************/ + /* Calculate mu values */ + /***********************/ + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + NLSF_mu = 0.002f - 0.001f * psEnc->speech_activity; + NLSF_mu_fluc_red = 0.1f - 0.05f * psEnc->speech_activity; + } else { + NLSF_mu = 0.005f - 0.004f * psEnc->speech_activity; + NLSF_mu_fluc_red = 0.2f - 0.1f * ( psEnc->speech_activity + psEncCtrl->sparseness ); + } + + /* Calculate NLSF weights */ + 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 ) ); + if( doInterpolate ) { + + /* Calculate the interpolated NLSF vector for the first half */ + NLSF_interpolation_factor = 0.25f * psEncCtrl->sCmn.NLSFInterpCoef_Q2; + SKP_Silk_interpolate_wrapper_FLP( pNLSF0_temp, psEnc->sPred.prev_NLSFq, pNLSF, + NLSF_interpolation_factor, psEnc->sCmn.predictLPCOrder ); + + /* Calculate first half NLSF weights for the interpolated NLSFs */ + SKP_Silk_NLSF_VQ_weights_laroia_FLP( pNLSFW0_temp, pNLSF0_temp, psEnc->sCmn.predictLPCOrder ); + + /* Update NLSF weights with contribution from first half */ + i_sqr = NLSF_interpolation_factor * NLSF_interpolation_factor; + for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) { + pNLSFW[ i ] = 0.5f * ( pNLSFW[ i ] + i_sqr * pNLSFW0_temp[ i ] ); + } + } + + /* Set pointer to the NLSF codebook for the current signal type and LPC order */ + psNLSF_CB_FLP = psEnc->psNLSF_CB_FLP[ psEncCtrl->sCmn.sigtype ]; + + /* Quantize NLSF parameters given the trained NLSF codebooks */ + SKP_Silk_NLSF_MSVQ_encode_FLP( psEncCtrl->sCmn.NLSFIndices, pNLSF, psNLSF_CB_FLP, 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 */ + SKP_Silk_NLSF2A_stable_FLP( psEncCtrl->PredCoef[ 1 ], pNLSF, psEnc->sCmn.predictLPCOrder ); + + if( doInterpolate ) { + /* Calculate the interpolated, quantized NLSF vector for the first half */ + SKP_Silk_interpolate_wrapper_FLP( pNLSF0_temp, psEnc->sPred.prev_NLSFq, pNLSF, + NLSF_interpolation_factor, psEnc->sCmn.predictLPCOrder ); + + /* Convert back to LPC coefficients */ + SKP_Silk_NLSF2A_stable_FLP( psEncCtrl->PredCoef[ 0 ], pNLSF0_temp, psEnc->sCmn.predictLPCOrder ); + + } else { + /* Copy LPC coefficients for first half from second half */ + SKP_memcpy( psEncCtrl->PredCoef[ 0 ], psEncCtrl->PredCoef[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) ); + } +} + diff --git a/src_FLP/SKP_Silk_process_gains_FLP.c b/src_FLP/SKP_Silk_process_gains_FLP.c new file mode 100644 index 000000000..ba5a369dc --- /dev/null +++ b/src_FLP/SKP_Silk_process_gains_FLP.c @@ -0,0 +1,96 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Processing of gains */ +void SKP_Silk_process_gains_FLP( + SKP_Silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ + SKP_Silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ +) +{ + SKP_Silk_shape_state_FLP *psShapeSt = &psEnc->sShape; + SKP_int k; + SKP_int32 pGains_Q16[ MAX_NB_SUBFR ]; + SKP_float s, InvMaxSqrVal, gain; + + /* Gain reduction when LTP coding gain is high */ + if( psEncCtrl->sCmn.sigtype == SIG_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; + } + } + + /* Limit the quantized signal */ + InvMaxSqrVal = ( SKP_float )( pow( 2.0f, 0.33f * ( 21.0f - psEncCtrl->current_SNR_dB ) ) / psEnc->sCmn.subfr_length ); + + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + /* Soft limit on ratio residual energy and squared gains */ + gain = psEncCtrl->Gains[ k ]; + gain = ( SKP_float )sqrt( gain * gain + psEncCtrl->ResNrg[ k ] * InvMaxSqrVal ); + psEncCtrl->Gains[ k ] = SKP_min_float( gain, 32767.0f ); + } + + /* Prepare gains for noise shaping quantization */ + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + pGains_Q16[ k ] = ( SKP_int32 ) ( psEncCtrl->Gains[ k ] * 65536.0f ); + } + + /* Noise shaping quantization */ + SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, pGains_Q16, + &psShapeSt->LastGainIndex, 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 ] = pGains_Q16[ k ] / 65536.0f; + } + + /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */ + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + if( psEncCtrl->LTPredCodGain + psEncCtrl->input_tilt > 1.0f ) { + psEncCtrl->sCmn.QuantOffsetType = 0; + } else { + psEncCtrl->sCmn.QuantOffsetType = 1; + } + } + + /* Quantizer boundary adjustment */ + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + psEncCtrl->Lambda = 1.2f - 0.4f * psEnc->speech_activity + - 0.3f * psEncCtrl->input_quality + + 0.2f * psEncCtrl->sCmn.QuantOffsetType + - 0.1f * psEncCtrl->coding_quality; + } else { + psEncCtrl->Lambda = 1.2f - 0.4f * psEnc->speech_activity + - 0.4f * psEncCtrl->input_quality + + 0.4f * psEncCtrl->sCmn.QuantOffsetType + - 0.1f * psEncCtrl->coding_quality; + } + + SKP_assert( psEncCtrl->Lambda >= 0.0f ); + SKP_assert( psEncCtrl->Lambda < 2.0f ); +} diff --git a/src_FLP/SKP_Silk_quant_LTP_gains_FLP.c b/src_FLP/SKP_Silk_quant_LTP_gains_FLP.c new file mode 100644 index 000000000..e29c3a26f --- /dev/null +++ b/src_FLP/SKP_Silk_quant_LTP_gains_FLP.c @@ -0,0 +1,108 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +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 */ + const SKP_float W[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error weights */ + const SKP_float mu, /* I Mu value (R/D tradeoff) */ + const 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; + const SKP_uint16 *cdf_ptr; + const SKP_int16 *cl_ptr; + const SKP_int16 *cbk_ptr_Q14; + const SKP_float *b_ptr, *W_ptr; + SKP_float rate_dist_subfr, rate_dist, min_rate_dist; + + + + /***************************************************/ + /* Iterate over different codebooks with different */ + /* rates/distortions, and choose best */ + /***************************************************/ + min_rate_dist = SKP_float_MAX; + for( k = 0; k < 3; k++ ) { + cdf_ptr = SKP_Silk_LTP_gain_CDF_ptrs[ k ]; + cl_ptr = SKP_Silk_LTP_gain_BITS_Q6_ptrs[ k ]; + cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ k ]; + cbk_size = SKP_Silk_LTP_vq_sizes[ k ]; + + /* Setup pointer to first subframe */ + W_ptr = W; + b_ptr = B; + + rate_dist = 0.0f; + for( j = 0; j < nb_subfr; j++ ) { + + SKP_Silk_VQ_WMat_EC_FLP( + &temp_idx[ j ], /* O index of best codebook vector */ + &rate_dist_subfr, /* O best weighted quantization error + mu * rate */ + b_ptr, /* I input vector to be quantized */ + W_ptr, /* I weighting matrix */ + cbk_ptr_Q14, /* I codebook */ + cl_ptr, /* I code length for each codebook vector */ + mu, /* I tradeoff between weighted error and rate */ + cbk_size /* I number of vectors in codebook */ + ); + + rate_dist += rate_dist_subfr; + + b_ptr += LTP_ORDER; + W_ptr += LTP_ORDER * LTP_ORDER; + } + + if( rate_dist < min_rate_dist ) { + min_rate_dist = rate_dist; + SKP_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( SKP_int ) ); + *periodicity_index = k; + } + + /* Break early in low-complexity mode if rate distortion is below threshold */ + if( lowComplexity && ( rate_dist * 16384.0f < ( SKP_float )SKP_Silk_LTP_gain_middle_avg_RD_Q14 ) ) { + break; + } + } + + cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ *periodicity_index ]; + for( j = 0; j < nb_subfr; j++ ) { + SKP_short2float_array( &B[ j * LTP_ORDER ], + &cbk_ptr_Q14[ cbk_index[ j ] * LTP_ORDER ], + LTP_ORDER ); + } + + for( j = 0; j < nb_subfr * LTP_ORDER; j++ ) { + B[ j ] *= Q14_CONVERSION_FAC; + } + +} + diff --git a/src_FLP/SKP_Silk_regularize_correlations_FLP.c b/src_FLP/SKP_Silk_regularize_correlations_FLP.c new file mode 100644 index 000000000..14eadb7d7 --- /dev/null +++ b/src_FLP/SKP_Silk_regularize_correlations_FLP.c @@ -0,0 +1,43 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +void SKP_Silk_regularize_correlations_FLP( + SKP_float *XX, /* I/O Correlation matrices */ + SKP_float *xx, /* I/O Correlation values */ + const SKP_float noise, /* I Noise energy to add */ + const SKP_int D /* I Dimension of XX */ +) +{ + SKP_int i; + + for( i = 0; i < D; i++ ) { + matrix_ptr( &XX[ 0 ], i, i, D ) += noise; + } + xx[ 0 ] += noise; +} diff --git a/src_FLP/SKP_Silk_residual_energy_FLP.c b/src_FLP/SKP_Silk_residual_energy_FLP.c new file mode 100644 index 000000000..f7a734ce0 --- /dev/null +++ b/src_FLP/SKP_Silk_residual_energy_FLP.c @@ -0,0 +1,113 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +#define MAX_ITERATIONS_RESIDUAL_NRG 10 +#define REGULARIZATION_FACTOR 1e-8f + +/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ +SKP_float SKP_Silk_residual_energy_covar_FLP( /* O Weighted residual energy */ + const SKP_float *c, /* I Filter coefficients */ + SKP_float *wXX, /* I/O Weighted correlation matrix, reg. out */ + const SKP_float *wXx, /* I Weighted correlation vector */ + const SKP_float wxx, /* I Weighted correlation value */ + const SKP_int D /* I Dimension */ +) +{ + SKP_int i, j, k; + SKP_float tmp, nrg, regularization; + + /* Safety checks */ + SKP_assert( D >= 0 ); + + regularization = REGULARIZATION_FACTOR * ( wXX[ 0 ] + wXX[ D * D - 1 ] ); + for( k = 0; k < MAX_ITERATIONS_RESIDUAL_NRG; k++ ) { + nrg = wxx; + + tmp = 0.0f; + for( i = 0; i < D; i++ ) { + tmp += wXx[ i ] * c[ i ]; + } + nrg -= 2.0f * tmp; + + /* compute c' * wXX * c, assuming wXX is symmetric */ + for( i = 0; i < D; i++ ) { + tmp = 0.0f; + for( j = i + 1; j < D; j++ ) { + tmp += matrix_c_ptr( wXX, i, j, D ) * c[ j ]; + } + nrg += c[ i ] * ( 2.0f * tmp + matrix_c_ptr( wXX, i, i, D ) * c[ i ] ); + } + if( nrg > 0 ) { + break; + } else { + /* Add white noise */ + for( i = 0; i < D; i++ ) { + matrix_c_ptr( wXX, i, i, D ) += regularization; + } + /* Increase noise for next run */ + regularization *= 2.0f; + } + } + if( k == MAX_ITERATIONS_RESIDUAL_NRG ) { + SKP_assert( nrg == 0 ); + nrg = 1.0f; + } + + return nrg; +} + +/* Calculates residual energies of input subframes where all subframes have LPC_order */ +/* of preceeding samples */ +void SKP_Silk_residual_energy_FLP( + SKP_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + const SKP_float x[], /* I Input signal */ + const SKP_float a[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ + const SKP_float gains[], /* I Quantization gains */ + const SKP_int subfr_length, /* I Subframe length */ + const SKP_int nb_subfr, /* I number of subframes */ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_int shift; + SKP_float *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; + + LPC_res_ptr = LPC_res + LPC_order; + shift = LPC_order + subfr_length; + + /* Filter input to create the LPC residual for each frame half, and measure subframe energies */ + SKP_Silk_LPC_analysis_filter_FLP( LPC_res, a[ 0 ], x + 0 * shift, 2 * shift, LPC_order ); + nrgs[ 0 ] = ( SKP_float )( gains[ 0 ] * gains[ 0 ] * SKP_Silk_energy_FLP( LPC_res_ptr + 0 * shift, subfr_length ) ); + nrgs[ 1 ] = ( SKP_float )( gains[ 1 ] * gains[ 1 ] * SKP_Silk_energy_FLP( LPC_res_ptr + 1 * shift, subfr_length ) ); + + if( nb_subfr == MAX_NB_SUBFR ) { + SKP_Silk_LPC_analysis_filter_FLP( LPC_res, a[ 1 ], x + 2 * shift, 2 * shift, LPC_order ); + nrgs[ 2 ] = ( SKP_float )( gains[ 2 ] * gains[ 2 ] * SKP_Silk_energy_FLP( LPC_res_ptr + 0 * shift, subfr_length ) ); + nrgs[ 3 ] = ( SKP_float )( gains[ 3 ] * gains[ 3 ] * SKP_Silk_energy_FLP( LPC_res_ptr + 1 * shift, subfr_length ) ); + } +} diff --git a/src_FLP/SKP_Silk_solve_LS_FLP.c b/src_FLP/SKP_Silk_solve_LS_FLP.c new file mode 100644 index 000000000..59f572c71 --- /dev/null +++ b/src_FLP/SKP_Silk_solve_LS_FLP.c @@ -0,0 +1,203 @@ +/*********************************************************************** +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. +***********************************************************************/ + + +#include "SKP_Silk_main_FLP.h" + +/********************************************************************** + * LDL Factorisation. Finds the upper triangular matrix L and the diagonal + * Matrix D (only the diagonal elements returned in a vector)such that + * the symmetric matric A is given by A = L*D*L'. + **********************************************************************/ +void SKP_Silk_LDL_FLP( + SKP_float *A, /* (I/O) Pointer to Symetric Square Matrix */ + SKP_int M, /* (I) Size of Matrix */ + SKP_float *L, /* (I/O) Pointer to Square Upper triangular Matrix */ + SKP_float *Dinv /* (I/O) Pointer to vector holding the inverse diagonal elements of D */ +); + +/********************************************************************** + * Function to solve linear equation Ax = b, when A is a MxM lower + * triangular matrix, with ones on the diagonal. + **********************************************************************/ +void SKP_Silk_SolveWithLowerTriangularWdiagOnes_FLP( + const SKP_float *L, /* (I) Pointer to Lower Triangular Matrix */ + SKP_int M, /* (I) Dim of Matrix equation */ + const SKP_float *b, /* (I) b Vector */ + SKP_float *x /* (O) x Vector */ +); + +/********************************************************************** + * Function to solve linear equation (A^T)x = b, when A is a MxM lower + * triangular, with ones on the diagonal. (ie then A^T is upper triangular) + **********************************************************************/ +void SKP_Silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( + const SKP_float *L, /* (I) Pointer to Lower Triangular Matrix */ + SKP_int M, /* (I) Dim of Matrix equation */ + const SKP_float *b, /* (I) b Vector */ + SKP_float *x /* (O) x Vector */ +); + +/********************************************************************** + * Function to solve linear equation Ax = b, when A is a MxM + * symmetric square matrix - using LDL factorisation + **********************************************************************/ +void SKP_Silk_solve_LDL_FLP( + SKP_float *A, /* I/O Symmetric square matrix, out: reg. */ + const SKP_int M, /* I Size of matrix */ + const SKP_float *b, /* I Pointer to b vector */ + SKP_float *x /* O Pointer to x solution vector */ +) +{ + SKP_int i; + SKP_float L[ MAX_MATRIX_SIZE ][ MAX_MATRIX_SIZE ]; + SKP_float T[ MAX_MATRIX_SIZE ]; + SKP_float Dinv[ MAX_MATRIX_SIZE ]; // inverse diagonal elements of D + + SKP_assert( M <= MAX_MATRIX_SIZE ); + + /*************************************************** + Factorize A by LDL such that A = L*D*(L^T), + where L is lower triangular with ones on diagonal + ****************************************************/ + SKP_Silk_LDL_FLP( A, M, &L[ 0 ][ 0 ], Dinv ); + + /**************************************************** + * substitute D*(L^T) = T. ie: + L*D*(L^T)*x = b => L*T = b <=> T = inv(L)*b + ******************************************************/ + SKP_Silk_SolveWithLowerTriangularWdiagOnes_FLP( &L[ 0 ][ 0 ], M, b, T ); + + /**************************************************** + D*(L^T)*x = T <=> (L^T)*x = inv(D)*T, because D is + diagonal just multiply with 1/d_i + ****************************************************/ + for( i = 0; i < M; i++ ) { + T[ i ] = T[ i ] * Dinv[ i ]; + } + /**************************************************** + x = inv(L') * inv(D) * T + *****************************************************/ + SKP_Silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( &L[ 0 ][ 0 ], M, T, x ); +} + +void SKP_Silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( + const SKP_float *L, /* (I) Pointer to Lower Triangular Matrix */ + SKP_int M, /* (I) Dim of Matrix equation */ + const SKP_float *b, /* (I) b Vector */ + SKP_float *x /* (O) x Vector */ +) +{ + SKP_int i, j; + SKP_float temp; + const SKP_float *ptr1; + + for( i = M - 1; i >= 0; i-- ) { + ptr1 = matrix_adr( L, 0, i, M ); + temp = 0; + for( j = M - 1; j > i ; j-- ) { + temp += ptr1[ j * M ] * x[ j ]; + } + temp = b[ i ] - temp; + x[ i ] = temp; + } +} + +void SKP_Silk_SolveWithLowerTriangularWdiagOnes_FLP( + const SKP_float *L, /* (I) Pointer to Lower Triangular Matrix */ + SKP_int M, /* (I) Dim of Matrix equation */ + const SKP_float *b, /* (I) b Vector */ + SKP_float *x /* (O) x Vector */ +) +{ + SKP_int i, j; + SKP_float temp; + const SKP_float *ptr1; + + for( i = 0; i < M; i++ ) { + ptr1 = matrix_adr( L, i, 0, M ); + temp = 0; + for( j = 0; j < i; j++ ) { + temp += ptr1[ j ] * x[ j ]; + } + temp = b[ i ] - temp; + x[ i ] = temp; + } +} + +void SKP_Silk_LDL_FLP( + SKP_float *A, /* (I/O) Pointer to Symetric Square Matrix */ + SKP_int M, /* (I) Size of Matrix */ + SKP_float *L, /* (I/O) Pointer to Square Upper triangular Matrix */ + SKP_float *Dinv /* (I/O) Pointer to vector holding the inverse diagonal elements of D */ +) +{ + SKP_int i, j, k, loop_count, err = 1; + SKP_float *ptr1, *ptr2; + double temp, diag_min_value; + SKP_float v[ MAX_MATRIX_SIZE ], D[ MAX_MATRIX_SIZE ]; // temp arrays + + SKP_assert( M <= MAX_MATRIX_SIZE ); + + diag_min_value = FIND_LTP_COND_FAC * 0.5f * ( A[ 0 ] + A[ M * M - 1 ] ); + for( loop_count = 0; loop_count < M && err == 1; loop_count++ ) { + err = 0; + for( j = 0; j < M; j++ ) { + ptr1 = matrix_adr( L, j, 0, M ); + temp = matrix_ptr( A, j, j, M ); // element in row j column j + for( i = 0; i < j; i++ ) { + v[ i ] = ptr1[ i ] * D[ i ]; + temp -= ptr1[ i ] * v[ i ]; + } + if( temp < diag_min_value ) { + /* Badly conditioned matrix: add white noise and run again */ + temp = ( loop_count + 1 ) * diag_min_value - temp; + for( i = 0; i < M; i++ ) { + matrix_ptr( A, i, i, M ) += ( SKP_float )temp; + } + err = 1; + break; + } + D[ j ] = ( SKP_float )temp; + Dinv[ j ] = ( SKP_float )( 1.0f / temp ); + matrix_ptr( L, j, j, M ) = 1.0f; + + ptr1 = matrix_adr( A, j, 0, M ); + ptr2 = matrix_adr( L, j + 1, 0, M); + for( i = j + 1; i < M; i++ ) { + temp = 0.0; + for( k = 0; k < j; k++ ) { + temp += ptr2[ k ] * v[ k ]; + } + matrix_ptr( L, i, j, M ) = ( SKP_float )( ( ptr1[ i ] - temp ) * Dinv[ j ] ); + ptr2 += M; // go to next column + } + } + } + SKP_assert( err == 0 ); +} + diff --git a/src_FLP/SKP_Silk_structs_FLP.h b/src_FLP/SKP_Silk_structs_FLP.h new file mode 100644 index 000000000..212c20a48 --- /dev/null +++ b/src_FLP/SKP_Silk_structs_FLP.h @@ -0,0 +1,176 @@ +/*********************************************************************** +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_STRUCTS_FLP_H +#define SKP_SILK_STRUCTS_FLP_H + +#include "SKP_Silk_typedef.h" +#include "SKP_Silk_main.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/********************************/ +/* Noise shaping analysis state */ +/********************************/ +typedef struct { + SKP_int LastGainIndex; + SKP_float HarmBoost_smth; + SKP_float HarmShapeGain_smth; + SKP_float Tilt_smth; +} SKP_Silk_shape_state_FLP; + +/********************************/ +/* Prefilter state */ +/********************************/ +typedef struct { + SKP_float sLTP_shp1[ LTP_BUF_LENGTH ]; + SKP_float sLTP_shp2[ LTP_BUF_LENGTH ]; + SKP_float sAR_shp1[ MAX_SHAPE_LPC_ORDER + 1 ]; + SKP_float sAR_shp2[ MAX_SHAPE_LPC_ORDER ]; + SKP_int sLTP_shp_buf_idx1; + SKP_int sLTP_shp_buf_idx2; + SKP_int sAR_shp_buf_idx2; + SKP_float sLF_AR_shp1; + SKP_float sLF_MA_shp1; + SKP_float sLF_AR_shp2; + SKP_float sLF_MA_shp2; + SKP_float sHarmHP; + SKP_int32 rand_seed; + SKP_int lagPrev; +} SKP_Silk_prefilter_state_FLP; + +/*****************************/ +/* Prediction analysis state */ +/*****************************/ +typedef struct { + SKP_int pitch_LPC_win_length; + SKP_int min_pitch_lag; /* Lowest possible pitch lag (samples) */ + SKP_int max_pitch_lag; /* Highest possible pitch lag (samples) */ + SKP_float prev_NLSFq[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */ +} SKP_Silk_predict_state_FLP; + +/*******************************************/ +/* Structure containing NLSF MSVQ codebook */ +/*******************************************/ +/* structure for one stage of MSVQ */ +typedef struct { + const SKP_int32 nVectors; + const SKP_float *CB; + const SKP_float *Rates; +} SKP_Silk_NLSF_CBS_FLP; + +typedef struct { + const SKP_int32 nStages; + + /* fields for (de)quantizing */ + const SKP_Silk_NLSF_CBS_FLP *CBStages; + const SKP_float *NDeltaMin; + + /* fields for arithmetic (de)coding */ + const SKP_uint16 *CDF; + const SKP_uint16 * const *StartPtr; + const SKP_int *MiddleIx; +} SKP_Silk_NLSF_CB_FLP; + +/********************************/ +/* Encoder state FLP */ +/********************************/ +typedef struct { + SKP_Silk_encoder_state sCmn; /* Common struct, shared with fixed-point code */ + + SKP_float variable_HP_smth1; /* State of first smoother */ + SKP_float variable_HP_smth2; /* State of second smoother */ + + 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 */ + SKP_float LTPCorr; /* Normalized correlation from pitch lag estimator */ + SKP_float mu_LTP; /* Rate-distortion tradeoff in LTP quantization */ + SKP_float SNR_dB; /* Quality setting */ + SKP_float avgGain; /* average gain during active speech */ + SKP_float BufferedInChannel_ms; /* Simulated number of ms buffer in channel because of exceeded TargetRate_bps */ + SKP_float speech_activity; /* Speech activity */ + SKP_float pitchEstimationThreshold; /* Threshold for pitch estimator */ + + /* Parameters for LTP scaling control */ + SKP_float prevLTPredCodGain; + SKP_float HPLTPredCodGain; + + SKP_float inBandFEC_SNR_comp; /* Compensation to SNR_DB when using inband FEC Voiced */ + + const SKP_Silk_NLSF_CB_FLP *psNLSF_CB_FLP[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ +} SKP_Silk_encoder_state_FLP; + + +/************************/ +/* 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; + + /* Noise shaping parameters */ + SKP_float AR1[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; + SKP_float AR2[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; + SKP_float LF_MA_shp[ MAX_NB_SUBFR ]; + SKP_float LF_AR_shp[ MAX_NB_SUBFR ]; + SKP_float GainsPre[ MAX_NB_SUBFR ]; + SKP_float HarmBoost[ MAX_NB_SUBFR ]; + SKP_float Tilt[ MAX_NB_SUBFR ]; + SKP_float HarmShapeGain[ MAX_NB_SUBFR ]; + SKP_float Lambda; + SKP_float input_quality; + SKP_float coding_quality; + SKP_float pitch_freq_low_Hz; + SKP_float current_SNR_dB; + + /* Measures */ + SKP_float sparseness; + SKP_float LTPredCodGain; + SKP_float input_quality_bands[ VAD_N_BANDS ]; + SKP_float input_tilt; + SKP_float ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */ +} SKP_Silk_encoder_control_FLP; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src_FLP/SKP_Silk_tables_FLP.h b/src_FLP/SKP_Silk_tables_FLP.h new file mode 100644 index 000000000..d2cbf2f0f --- /dev/null +++ b/src_FLP/SKP_Silk_tables_FLP.h @@ -0,0 +1,43 @@ +/*********************************************************************** +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_TABLES_FLP_H +#define SKP_SILK_TABLES_FLP_H + +#include "SKP_Silk_structs_FLP.h" + +/* filters */ +extern const SKP_float SKP_Silk_HarmShapeFIR_FLP[ HARM_SHAPE_FIR_TAPS ]; + +/* Table of quantization offset values */ +extern const SKP_float SKP_Silk_Quantization_Offsets[ 2 ][ 2 ]; + +/* NLSF codebooks */ +extern const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB0_16_FLP, SKP_Silk_NLSF_CB1_16_FLP; +extern const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB0_10_FLP, SKP_Silk_NLSF_CB1_10_FLP; + +#endif diff --git a/src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c b/src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c new file mode 100644 index 000000000..a6a6146b5 --- /dev/null +++ b/src_FLP/SKP_Silk_tables_NLSF_CB0_10_FLP.c @@ -0,0 +1,739 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/**********************************************/ +/* This file has been automatically generated */ +/* */ +/* ROM usage: 5.32 kB */ +/**********************************************/ + +#include "SKP_Silk_tables_FLP.h" +#include "SKP_Silk_tables_NLSF_CB0_10.h" + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_10_rates[ NLSF_MSVQ_CB0_10_VECTORS ] = +{ + 4.62500000000000000000f, 5.21875000000000000000f, + 5.28125000000000000000f, 5.31250000000000000000f, + 5.31250000000000000000f, 5.40625000000000000000f, + 5.40625000000000000000f, 5.46875000000000000000f, + 5.50000000000000000000f, 5.50000000000000000000f, + 5.50000000000000000000f, 5.53125000000000000000f, + 5.59375000000000000000f, 5.65625000000000000000f, + 5.65625000000000000000f, 5.65625000000000000000f, + 5.71875000000000000000f, 5.71875000000000000000f, + 5.71875000000000000000f, 5.75000000000000000000f, + 5.78125000000000000000f, 5.78125000000000000000f, + 5.78125000000000000000f, 5.78125000000000000000f, + 5.81250000000000000000f, 5.90625000000000000000f, + 5.90625000000000000000f, 5.90625000000000000000f, + 5.96875000000000000000f, 5.96875000000000000000f, + 5.96875000000000000000f, 6.06250000000000000000f, + 6.06250000000000000000f, 6.06250000000000000000f, + 6.09375000000000000000f, 6.09375000000000000000f, + 6.12500000000000000000f, 6.18750000000000000000f, + 6.21875000000000000000f, 6.25000000000000000000f, + 6.28125000000000000000f, 6.28125000000000000000f, + 6.31250000000000000000f, 6.34375000000000000000f, + 6.37500000000000000000f, 6.37500000000000000000f, + 6.40625000000000000000f, 6.40625000000000000000f, + 6.43750000000000000000f, 6.53125000000000000000f, + 6.56250000000000000000f, 6.56250000000000000000f, + 6.65625000000000000000f, 6.68750000000000000000f, + 6.81250000000000000000f, 6.87500000000000000000f, + 6.90625000000000000000f, 7.06250000000000000000f, + 7.21875000000000000000f, 7.31250000000000000000f, + 7.46875000000000000000f, 8.00000000000000000000f, + 8.00000000000000000000f, 8.00000000000000000000f, + 3.71875000000000000000f, 3.84375000000000000000f, + 3.84375000000000000000f, 3.84375000000000000000f, + 3.90625000000000000000f, 3.93750000000000000000f, + 3.93750000000000000000f, 3.93750000000000000000f, + 4.00000000000000000000f, 4.06250000000000000000f, + 4.06250000000000000000f, 4.09375000000000000000f, + 4.09375000000000000000f, 4.21875000000000000000f, + 4.31250000000000000000f, 4.34375000000000000000f, + 2.93750000000000000000f, 2.93750000000000000000f, + 2.96875000000000000000f, 2.96875000000000000000f, + 3.00000000000000000000f, 3.06250000000000000000f, + 3.06250000000000000000f, 3.09375000000000000000f, + 2.90625000000000000000f, 2.90625000000000000000f, + 2.96875000000000000000f, 3.00000000000000000000f, + 3.00000000000000000000f, 3.03125000000000000000f, + 3.06250000000000000000f, 3.12500000000000000000f, + 2.87500000000000000000f, 2.90625000000000000000f, + 3.03125000000000000000f, 3.03125000000000000000f, + 3.03125000000000000000f, 3.03125000000000000000f, + 3.06250000000000000000f, 3.06250000000000000000f, + 3.90625000000000000000f, 3.93750000000000000000f, + 3.93750000000000000000f, 3.96875000000000000000f, + 3.96875000000000000000f, 4.00000000000000000000f, + 4.00000000000000000000f, 4.00000000000000000000f, + 4.00000000000000000000f, 4.00000000000000000000f, + 4.03125000000000000000f, 4.03125000000000000000f, + 4.03125000000000000000f, 4.06250000000000000000f, + 4.06250000000000000000f, 4.09375000000000000000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min[ 10 + 1 ] = +{ + 0.01718139648437500000f, + 0.00009155273437500000f, + 0.00067138671874999989f, + 0.00061035156250000000f, + 0.00009155273437500000f, + 0.00009155273437500000f, + 0.00402832031250000000f, + 0.00363159179687500000f, + 0.01092529296875000000f, + 0.00262451171875000000f, + 0.02941894531250000300f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * NLSF_MSVQ_CB0_10_VECTORS ] = +{ + 0.06744384765625000000f, 0.12277221679687500000f, + 0.21304321289062497000f, 0.28259277343750000000f, + 0.38369750976562500000f, 0.47872924804687500000f, + 0.58615112304687500000f, 0.68307495117187489000f, + 0.79287719726562500000f, 0.88934326171875011000f, + 0.10025024414062500000f, 0.12731933593750000000f, + 0.18664550781250003000f, 0.33129882812500000000f, + 0.46658325195312494000f, 0.51348876953125000000f, + 0.60122680664062500000f, 0.67169189453125000000f, + 0.75442504882812500000f, 0.89456176757812500000f, + 0.04742431640624999300f, 0.07662963867187500000f, + 0.20071411132812500000f, 0.31546020507812500000f, + 0.42227172851562494000f, 0.50387573242187500000f, + 0.61297607421875000000f, 0.70843505859375000000f, + 0.80810546875000000000f, 0.89916992187500000000f, + 0.09344482421875000000f, 0.12258911132812500000f, + 0.17611694335937500000f, 0.30630493164062500000f, + 0.40786743164062500000f, 0.45629882812500000000f, + 0.61462402343750000000f, 0.69857788085937500000f, + 0.76992797851562500000f, 0.90341186523437500000f, + 0.06362915039062500000f, 0.10549926757812500000f, + 0.18109130859375000000f, 0.26605224609375000000f, + 0.35098266601562494000f, 0.41717529296875000000f, + 0.54922485351562500000f, 0.66580200195312500000f, + 0.76095581054687489000f, 0.87722778320312500000f, + 0.08471679687500000000f, 0.12490844726562501000f, + 0.19595336914062500000f, 0.31777954101562500000f, + 0.46115112304687500000f, 0.51287841796875000000f, + 0.63552856445312500000f, 0.72711181640625000000f, + 0.80285644531250000000f, 0.89755249023437500000f, + 0.08291625976562498600f, 0.12310791015625000000f, + 0.17385864257812500000f, 0.25827026367187500000f, + 0.43643188476562500000f, 0.49908447265625000000f, + 0.58004760742187500000f, 0.71450805664062500000f, + 0.78771972656249989000f, 0.86993408203125011000f, + 0.08764648437500000000f, 0.11297607421875001000f, + 0.17947387695312500000f, 0.33673095703124994000f, + 0.52310180664062500000f, 0.57614135742187500000f, + 0.64532470703125000000f, 0.71566772460937500000f, + 0.78787231445312500000f, 0.90332031250000000000f, + 0.09152221679687500000f, 0.12252807617187500000f, + 0.22451782226562500000f, 0.34237670898437500000f, + 0.39263916015625000000f, 0.52816772460937500000f, + 0.61282348632812500000f, 0.69104003906250000000f, + 0.81707763671875000000f, 0.88827514648437500000f, + 0.08978271484375000000f, 0.11798095703125000000f, + 0.18060302734375003000f, 0.36361694335937500000f, + 0.42446899414062500000f, 0.49047851562500000000f, + 0.62417602539062500000f, 0.67990112304687500000f, + 0.83343505859375000000f, 0.91021728515625011000f, + 0.06930541992187500000f, 0.10763549804687500000f, + 0.20159912109375000000f, 0.29690551757812500000f, + 0.39498901367187506000f, 0.53045654296875000000f, + 0.61718750000000000000f, 0.68191528320312500000f, + 0.75079345703125000000f, 0.86334228515624989000f, + 0.06735229492187500000f, 0.10101318359375000000f, + 0.17834472656250000000f, 0.28500366210937500000f, + 0.33999633789062500000f, 0.47763061523437506000f, + 0.56689453125000000000f, 0.64627075195312511000f, + 0.77975463867187489000f, 0.86145019531250011000f, + 0.12094116210937500000f, 0.15182495117187500000f, + 0.21060180664062500000f, 0.35363769531250000000f, + 0.41094970703125000000f, 0.47537231445312494000f, + 0.58688354492187500000f, 0.65209960937500000000f, + 0.77850341796875000000f, 0.84713745117187500000f, + 0.08389282226562500000f, 0.10830688476562500000f, + 0.21258544921875000000f, 0.42138671875000000000f, + 0.47769165039062500000f, 0.53848266601562500000f, + 0.61309814453125000000f, 0.68966674804687511000f, + 0.80770874023437500000f, 0.87088012695312489000f, + 0.06488037109375000000f, 0.10693359375000001000f, + 0.15591430664062500000f, 0.30377197265625000000f, + 0.38299560546875006000f, 0.44616699218750000000f, + 0.60128784179687500000f, 0.66183471679687500000f, + 0.80740356445312500000f, 0.88824462890625000000f, + 0.12103271484375000000f, 0.17532348632812500000f, + 0.22711181640625000000f, 0.29776000976562500000f, + 0.44152832031250000000f, 0.50061035156250000000f, + 0.58395385742187500000f, 0.70336914062500000000f, + 0.77438354492187489000f, 0.86642456054687500000f, + 0.09756469726562500000f, 0.14498901367187500000f, + 0.19686889648437500000f, 0.28375244140625000000f, + 0.39788818359374994000f, 0.45391845703125000000f, + 0.54815673828125000000f, 0.62948608398437500000f, + 0.72738647460937500000f, 0.86865234375000000000f, + 0.09750366210937500000f, 0.12454223632812500000f, + 0.19833374023437500000f, 0.37390136718750000000f, + 0.43606567382812500000f, 0.48950195312500000000f, + 0.56021118164062500000f, 0.63262939453125000000f, + 0.82336425781250000000f, 0.89443969726562489000f, + 0.04678344726562500000f, 0.07540893554687500000f, + 0.13690185546875000000f, 0.23791503906250000000f, + 0.37634277343750000000f, 0.48089599609375000000f, + 0.59713745117187500000f, 0.68048095703124989000f, + 0.78347778320312489000f, 0.88656616210937511000f, + 0.06109619140625000000f, 0.09066772460937500000f, + 0.15213012695312500000f, 0.24667358398437497000f, + 0.40225219726562500000f, 0.47103881835937500000f, + 0.55654907226562500000f, 0.65664672851562500000f, + 0.75057983398437500000f, 0.86520385742187500000f, + 0.11621093750000000000f, 0.15029907226562500000f, + 0.20477294921875003000f, 0.31130981445312500000f, + 0.36654663085937500000f, 0.43640136718750000000f, + 0.56326293945312500000f, 0.62228393554687500000f, + 0.80947875976562500000f, 0.88366699218750000000f, + 0.06961059570312500000f, 0.10430908203125000000f, + 0.15194702148437500000f, 0.26629638671875000000f, + 0.48718261718750000000f, 0.55249023437500000000f, + 0.61798095703125000000f, 0.69491577148437500000f, + 0.77166748046875000000f, 0.88360595703125000000f, + 0.09310913085937500000f, 0.16720581054687500000f, + 0.22247314453125000000f, 0.30053710937500000000f, + 0.38891601562500000000f, 0.44259643554687500000f, + 0.56961059570312500000f, 0.72277832031250000000f, + 0.79544067382812511000f, 0.88339233398437500000f, + 0.07214355468750000000f, 0.10879516601562499000f, + 0.16790771484375000000f, 0.29360961914062500000f, + 0.45538330078125000000f, 0.50723266601562500000f, + 0.57998657226562500000f, 0.64074707031250000000f, + 0.80291748046875000000f, 0.89422607421875000000f, + 0.12490844726562501000f, 0.15905761718750000000f, + 0.20852661132812500000f, 0.30151367187500000000f, + 0.49752807617187500000f, 0.55804443359375000000f, + 0.62777709960937500000f, 0.72064208984375000000f, + 0.79550170898437500000f, 0.88891601562500000000f, + 0.08975219726562500000f, 0.12194824218750000000f, + 0.18426513671875000000f, 0.32464599609374994000f, + 0.38659667968750000000f, 0.44100952148437500000f, + 0.51263427734375000000f, 0.59179687500000000000f, + 0.79501342773437500000f, 0.87026977539062489000f, + 0.11788940429687500000f, 0.15905761718750000000f, + 0.21420288085937500000f, 0.28894042968750000000f, + 0.33688354492187500000f, 0.40325927734374994000f, + 0.60858154296875000000f, 0.68188476562500000000f, + 0.76678466796875000000f, 0.90145874023437489000f, + 0.14083862304687500000f, 0.18835449218749997000f, + 0.23965454101562500000f, 0.31286621093750000000f, + 0.38485717773437506000f, 0.44082641601562500000f, + 0.60177612304687500000f, 0.68484497070312500000f, + 0.76055908203125000000f, 0.89541625976562500000f, + 0.10882568359375000000f, 0.13769531250000000000f, + 0.21316528320312500000f, 0.26501464843750000000f, + 0.32177734375000000000f, 0.49124145507812500000f, + 0.55108642578125000000f, 0.68588256835937500000f, + 0.79547119140625000000f, 0.85958862304687500000f, + 0.13674926757812500000f, 0.16751098632812500000f, + 0.22680664062500000000f, 0.34832763671875000000f, + 0.40255737304687500000f, 0.46463012695312500000f, + 0.61526489257812500000f, 0.67926025390625000000f, + 0.80822753906250000000f, 0.90686035156250000000f, + 0.10131835937500000000f, 0.13183593750000000000f, + 0.20205688476562500000f, 0.30111694335937500000f, + 0.35342407226562500000f, 0.42828369140625000000f, + 0.64599609375000000000f, 0.70831298828125000000f, + 0.81140136718750000000f, 0.91256713867187500000f, + 0.11578369140625000000f, 0.14309692382812500000f, + 0.21105957031250000000f, 0.26412963867187500000f, + 0.30953979492187500000f, 0.49267578125000000000f, + 0.59716796875000000000f, 0.65881347656250000000f, + 0.84097290039062500000f, 0.90310668945312489000f, + 0.07464599609375000000f, 0.09997558593750000000f, + 0.18060302734375003000f, 0.38583374023437500000f, + 0.50662231445312500000f, 0.54971313476562500000f, + 0.64471435546875011000f, 0.70724487304687489000f, + 0.83312988281250000000f, 0.90435791015625000000f, + 0.07476806640625000000f, 0.10748291015625000000f, + 0.16592407226562500000f, 0.26123046875000000000f, + 0.46646118164062500000f, 0.60763549804687500000f, + 0.66607666015625000000f, 0.73538208007812500000f, + 0.81076049804687489000f, 0.88739013671875000000f, + 0.07873535156250000000f, 0.11584472656249999000f, + 0.17028808593750000000f, 0.25445556640625000000f, + 0.30422973632812500000f, 0.38681030273437500000f, + 0.57699584960937500000f, 0.69436645507812500000f, + 0.77667236328125000000f, 0.89392089843749989000f, + 0.10147094726562500000f, 0.13159179687500000000f, + 0.19046020507812500000f, 0.23526000976562500000f, + 0.27966308593750000000f, 0.44104003906250000000f, + 0.66116333007812489000f, 0.72622680664062511000f, + 0.82690429687500000000f, 0.91116333007812489000f, + 0.10186767578125000000f, 0.12704467773437500000f, + 0.23614501953125000000f, 0.33917236328125000000f, + 0.38659667968750000000f, 0.45022583007812500000f, + 0.51669311523437500000f, 0.69384765625000000000f, + 0.78341674804687500000f, 0.85733032226562500000f, + 0.11718749999999999000f, 0.14511108398437500000f, + 0.23666381835937500000f, 0.41110229492187506000f, + 0.46807861328125000000f, 0.52429199218750000000f, + 0.61270141601562500000f, 0.68215942382812500000f, + 0.82949829101562500000f, 0.90768432617187500000f, + 0.07641601562500000000f, 0.12448120117187500000f, + 0.25485229492187500000f, 0.36981201171875000000f, + 0.45916748046875000000f, 0.56747436523437500000f, + 0.66174316406250000000f, 0.75390625000000000000f, + 0.83981323242187500000f, 0.91360473632812500000f, + 0.15972900390625000000f, 0.19354248046875000000f, + 0.25228881835937500000f, 0.36074829101562500000f, + 0.46249389648437500000f, 0.51147460937500000000f, + 0.63070678710937500000f, 0.71679687500000000000f, + 0.79190063476562500000f, 0.89437866210937500000f, + 0.08181762695312500000f, 0.10870361328125000000f, + 0.18395996093750003000f, 0.33041381835937506000f, + 0.56329345703125000000f, 0.62432861328125000000f, + 0.68063354492187500000f, 0.75381469726562500000f, + 0.82128906250000000000f, 0.91418457031250000000f, + 0.10296630859375000000f, 0.13818359375000000000f, + 0.19012451171875000000f, 0.25195312500000000000f, + 0.29031372070312500000f, 0.38848876953124994000f, + 0.56964111328125000000f, 0.63232421875000000000f, + 0.79367065429687500000f, 0.86746215820312500000f, + 0.08334350585937500000f, 0.11074829101562500000f, + 0.25390625000000000000f, 0.37994384765625000000f, + 0.43066406250000000000f, 0.50143432617187500000f, + 0.56604003906250000000f, 0.67437744140625000000f, + 0.77297973632812500000f, 0.84588623046875000000f, + 0.10623168945312500000f, 0.13430786132812500000f, + 0.22341918945312503000f, 0.28439331054687500000f, + 0.33758544921875000000f, 0.39956665039062500000f, + 0.46145629882812500000f, 0.68099975585937489000f, + 0.80355834960937500000f, 0.87707519531250000000f, + 0.10916137695312500000f, 0.15090942382812500000f, + 0.20352172851562500000f, 0.26831054687500000000f, + 0.31430053710937500000f, 0.38589477539062506000f, + 0.59524536132812500000f, 0.75579833984375000000f, + 0.82385253906250011000f, 0.90435791015625000000f, + 0.12384033203125000000f, 0.15441894531250000000f, + 0.22241210937500000000f, 0.31097412109375000000f, + 0.35778808593750000000f, 0.42529296875000000000f, + 0.48367309570312500000f, 0.56576538085937500000f, + 0.81484985351562500000f, 0.91079711914062500000f, + 0.13006591796875000000f, 0.16448974609374997000f, + 0.21536254882812503000f, 0.27410888671875000000f, + 0.31088256835937500000f, 0.46582031250000000000f, + 0.62500000000000000000f, 0.68176269531250000000f, + 0.79217529296875000000f, 0.85668945312500000000f, + 0.10388183593750000000f, 0.13211059570312500000f, + 0.20230102539062497000f, 0.24249267578125000000f, + 0.30886840820312500000f, 0.52383422851562500000f, + 0.59936523437500000000f, 0.67883300781249989000f, + 0.76483154296875000000f, 0.83837890625000000000f, + 0.09634399414062501400f, 0.12719726562500000000f, + 0.18905639648437500000f, 0.28439331054687500000f, + 0.32870483398437500000f, 0.40664672851562500000f, + 0.47045898437500000000f, 0.60473632812500000000f, + 0.75292968750000000000f, 0.84332275390625000000f, + 0.07638549804687500000f, 0.10598754882812500000f, + 0.15655517578125000000f, 0.20651245117187500000f, + 0.26156616210937500000f, 0.45477294921875000000f, + 0.58084106445312500000f, 0.66912841796874989000f, + 0.79544067382812511000f, 0.87670898437500000000f, + 0.12612915039062500000f, 0.15570068359375000000f, + 0.23049926757812503000f, 0.30682373046875000000f, + 0.35879516601562500000f, 0.45544433593750000000f, + 0.53207397460937500000f, 0.61602783203125000000f, + 0.73202514648437489000f, 0.80175781249999989000f, + 0.15173339843750000000f, 0.18734741210937500000f, + 0.24090576171875000000f, 0.29397583007812500000f, + 0.34545898437500000000f, 0.43624877929687500000f, + 0.66336059570312500000f, 0.74176025390625000000f, + 0.82150268554687489000f, 0.91268920898437500000f, + 0.09027099609375000000f, 0.11645507812500000000f, + 0.20907592773437500000f, 0.28088378906250000000f, + 0.33248901367187506000f, 0.55090332031250000000f, + 0.63449096679687500000f, 0.71221923828125000000f, + 0.84094238281250000000f, 0.90359497070312500000f, + 0.15972900390625000000f, 0.18395996093750003000f, + 0.24517822265625000000f, 0.30987548828125000000f, + 0.34307861328125000000f, 0.45132446289062500000f, + 0.57824707031250000000f, 0.63983154296875000000f, + 0.81130981445312500000f, 0.88888549804687500000f, + 0.15994262695312503000f, 0.20867919921875000000f, + 0.32122802734375006000f, 0.39120483398437500000f, + 0.44802856445312500000f, 0.52880859375000000000f, + 0.60815429687500000000f, 0.68164062500000000000f, + 0.79934692382812500000f, 0.87576293945312500000f, + 0.10412597656250000000f, 0.12973022460937500000f, + 0.18273925781250000000f, 0.21649169921875000000f, + 0.30233764648437500000f, 0.55673217773437500000f, + 0.66128540039062500000f, 0.72561645507812511000f, + 0.82302856445312500000f, 0.88766479492187500000f, + 0.07537841796875000000f, 0.09817504882812500000f, + 0.23794555664062500000f, 0.46679687499999994000f, + 0.52993774414062500000f, 0.58395385742187500000f, + 0.67074584960937500000f, 0.74023437500000000000f, + 0.83380126953124989000f, 0.89849853515625000000f, + 0.15072631835937500000f, 0.17712402343750000000f, + 0.24856567382812500000f, 0.36038208007812506000f, + 0.42337036132812500000f, 0.47601318359375000000f, + 0.52593994140625000000f, 0.59274291992187500000f, + 0.80798339843750000000f, 0.90469360351562500000f, + 0.15414428710937500000f, 0.18820190429687497000f, + 0.25094604492187500000f, 0.29464721679687500000f, + 0.37106323242187500000f, 0.54916381835937500000f, + 0.62451171875000000000f, 0.69677734375000011000f, + 0.81225585937500000000f, 0.86859130859375000000f, + 0.15219116210937500000f, 0.18026733398437500000f, + 0.28439331054687500000f, 0.34317016601562500000f, + 0.40075683593750000000f, 0.45849609375000000000f, + 0.53359985351562500000f, 0.69235229492187511000f, + 0.79379272460937511000f, 0.86282348632812489000f, + 0.15676879882812500000f, 0.21008300781250000000f, + 0.33645629882812500000f, 0.45623779296875000000f, + 0.52462768554687500000f, 0.59280395507812500000f, + 0.66549682617187489000f, 0.74441528320312511000f, + 0.82208251953125000000f, 0.89379882812500000000f, + 0.21536254882812503000f, 0.24060058593750000000f, + 0.29077148437500000000f, 0.31991577148437500000f, + 0.33447265625000000000f, 0.45199584960937500000f, + 0.58197021484375000000f, 0.66146850585937500000f, + 0.78262329101562511000f, 0.85507202148437500000f, + 0.20626831054687500000f, 0.21850585937500000000f, + 0.26080322265625000000f, 0.35946655273437500000f, + 0.37521362304687500000f, 0.39743041992187500000f, + 0.50741577148437500000f, 0.64389038085937500000f, + 0.75369262695312500000f, 0.86325073242187500000f, + 0.11788940429687500000f, 0.29791259765625000000f, + 0.33776855468749994000f, 0.34927368164062500000f, + 0.36770629882812506000f, 0.42602539062500000000f, + 0.55191040039062500000f, 0.65634155273437500000f, + 0.76977539062500000000f, 0.88491821289062489000f, + 0.01211547851562500000f, 0.01022338867187500000f, + 0.01986694335937500000f, 0.03564453125000000000f, + 0.01953125000000000000f, 0.02334594726562500000f, + 0.01419067382812500000f, 0.01010131835937500000f, + 0.00653076171875000000f, -0.00592041015625000000f, + -0.01763916015625000000f, -0.01974487304687500000f, + -0.02005004882812500000f, 0.02288818359375000000f, + 0.01721191406250000000f, 0.01870727539062500000f, + 0.01675415039062500000f, 0.01922607421875000000f, + 0.00927734375000000000f, -0.00158691406250000020f, + 0.02526855468749999700f, 0.02813720703125000000f, + 0.01351928710937500000f, 0.00338745117187500000f, + 0.00421142578125000000f, 0.00378417968750000000f, + 0.00515747070312500000f, 0.00042724609375000000f, + 0.00439453125000000000f, 0.00253295898437500040f, + 0.00402832031250000000f, 0.00177001953125000000f, + -0.01260375976562500000f, -0.02294921875000000000f, + 0.02651977539062500000f, 0.01025390625000000000f, + 0.01174926757812500200f, 0.00210571289062500000f, + 0.00170898437500000000f, 0.02532958984375000000f, + -0.00692749023437500000f, -0.00811767578125000000f, + -0.01123046875000000000f, -0.01342773437500000000f, + -0.03646850585937500000f, 0.00497436523437500000f, + 0.00384521484375000000f, -0.00695800781250000000f, + 0.02447509765625000000f, 0.00476074218750000000f, + 0.00573730468750000000f, 0.00366210937499999960f, + 0.01147460937500000000f, 0.00180053710937500000f, + -0.01092529296875000000f, -0.01702880859375000000f, + -0.04046630859375000000f, -0.00775146484375000000f, + -0.00616455078125000000f, -0.02407836914062500000f, + 0.00903320312500000000f, 0.00280761718750000000f, + -0.00213623046875000000f, -0.00393676757812500000f, + -0.02191162109375000000f, -0.03463745117187500000f, + 0.00891113281250000000f, -0.00088500976562500000f, + -0.01925659179687500000f, 0.01486206054687500000f, + -0.00479125976562500000f, -0.00466918945312500000f, + -0.00851440429687500000f, 0.00006103515625000000f, + -0.01278686523437500000f, -0.01043701171875000000f, + -0.00103759765625000000f, -0.01568603515625000000f, + -0.02438354492187499700f, -0.04794311523437500000f, + -0.02096557617187500000f, -0.01858520507812500000f, + -0.01666259765625000000f, -0.00396728515625000000f, + -0.00656127929687500000f, -0.00769042968750000000f, + -0.01361083984375000000f, -0.01751708984375000000f, + -0.04080200195312500000f, 0.00631713867187499910f, + -0.00219726562500000000f, 0.00097656250000000000f, + 0.00314331054687500000f, -0.01959228515625000000f, + 0.02874755859375000300f, 0.02236938476562499700f, + 0.00570678710937500090f, 0.00088500976562500000f, + -0.00643920898437500000f, -0.02484130859375000300f, + 0.00436401367187500000f, 0.00686645507812500000f, + 0.00061035156250000000f, 0.00073242187500000000f, + -0.00817871093750000000f, -0.01150512695312500000f, + 0.04953002929687499300f, 0.03457641601562500000f, + 0.02035522460937500000f, 0.00500488281250000000f, + 0.00936889648437500000f, 0.01116943359375000000f, + 0.00570678710937500090f, 0.00103759765625000000f, + 0.00189208984375000000f, -0.00955200195312500000f, + -0.02539062500000000300f, -0.04522705078125000000f, + -0.03604125976562500000f, 0.01473999023437500000f, + -0.00128173828125000000f, -0.00119018554687500000f, + -0.01373291015625000000f, -0.04290771484375000000f, + -0.01791381835937500000f, -0.00158691406250000020f, + -0.02319335937500000000f, 0.01019287109375000000f, + 0.00299072265625000000f, -0.00183105468749999980f, + -0.01525878906249999800f, -0.01489257812500000000f, + -0.03228759765625000000f, 0.00912475585937500000f, + 0.00399780273437500000f, -0.00762939453124999910f, + -0.00765991210937500090f, -0.02145385742187500000f, + 0.03164672851562500000f, 0.01733398437500000000f, + -0.01260375976562500000f, -0.00808715820312500000f, + 0.05148315429687500000f, 0.01748657226562500000f, + 0.01052856445312500000f, 0.00985717773437500000f, + 0.00299072265625000000f, 0.00186157226562500000f, + -0.00311279296875000000f, 0.00094604492187500000f, + 0.00411987304687500000f, 0.00454711914062500000f, + 0.01882934570312500000f, 0.01113891601562500000f, + -0.00119018554687500000f, 0.00103759765625000000f, + -0.01864624023437500000f, 0.03665161132812500000f, + 0.04336547851562500000f, 0.02246093750000000000f, + -0.01263427734374999800f, -0.01199340820312500000f, + -0.01501464843750000000f, -0.01046752929687500200f, + -0.00964355468750000000f, -0.01623535156250000000f, + 0.01611328125000000000f, 0.00524902343750000000f, + 0.00274658203125000000f, 0.00982666015625000000f, + -0.00897216796875000000f, -0.00973510742187500000f, + -0.01651000976562500000f, 0.01535034179687500000f, + 0.01950073242187500000f, 0.01223754882812500000f, + 0.00003051757812500000f, -0.00454711914062500000f, + -0.00222778320312500000f, -0.00509643554687500000f, + 0.00457763671875000000f, 0.00360107421875000000f, + 0.00939941406250000000f, 0.00665283203124999910f, + 0.00369262695312500000f, 0.00595092773437500000f, + -0.00436401367187500000f, -0.00796508789062500000f, + -0.03091430664062500000f, -0.02447509765625000000f, + 0.01181030273437500000f, 0.01330566406249999800f, + 0.00396728515625000000f, -0.01303100585937500200f, + -0.01367187500000000000f, -0.02078247070312500000f, + 0.00375366210937500000f, -0.00265502929687500000f, + -0.00765991210937500090f, -0.00344848632812500000f, + 0.00836181640625000000f, 0.00946044921875000000f, + 0.01358032226562500000f, 0.01528930664062500000f, + 0.01080322265625000200f, 0.00830078125000000000f, + 0.00430297851562500000f, -0.00869750976562500000f, + 0.01736450195312500000f, 0.02001953125000000000f, + 0.00112915039062500000f, -0.00149536132812500000f, + 0.00765991210937500090f, -0.01177978515625000000f, + -0.00802612304687500000f, 0.03424072265625000000f, + 0.01843261718750000000f, 0.01849365234375000000f, + 0.01025390625000000000f, 0.00289916992187500000f, + 0.00103759765625000000f, 0.00000000000000000000f, + 0.00259399414062500000f, 0.00549316406250000000f, + 0.00631713867187499910f, -0.01119995117187500000f, + -0.01898193359375000000f, 0.03265380859375000000f, + -0.00018310546875000000f, -0.00241088867187500000f, + -0.00488281250000000000f, -0.00280761718750000000f, + -0.00418090820312500000f, -0.00842285156250000000f, + -0.00985717773437500000f, -0.01132202148437500000f, + -0.02124023437500000000f, -0.03161621093750000000f, + 0.01242065429687500200f, 0.00311279296875000000f, + -0.00262451171875000000f, -0.00653076171875000000f, + -0.01470947265625000200f, -0.01974487304687500000f, + -0.00085449218750000000f, -0.00888061523437500000f, + -0.00296020507812500000f, -0.00549316406250000000f, + -0.00762939453124999910f, -0.01327514648437500000f, + -0.00054931640625000000f, -0.00231933593750000000f, + -0.01013183593750000200f, 0.01251220703125000000f, + 0.01242065429687500200f, 0.00512695312500000000f, + 0.01644897460937500000f, 0.01254272460937500000f, + 0.00775146484375000000f, 0.00338745117187500000f, + 0.00177001953125000000f, -0.00442504882812500000f, + 0.00610351562500000000f, 0.00091552734374999989f, + 0.00570678710937500090f, 0.00354003906250000000f, + 0.00399780273437500000f, -0.01119995117187500000f, + -0.01449584960937500000f, 0.02383422851562500300f, + -0.01705932617187500000f, 0.01712036132812500000f, + 0.00595092773437500000f, -0.00350952148437500040f, + 0.00024414062500000000f, -0.00512695312500000000f, + 0.00091552734374999989f, 0.00167846679687500000f, + -0.00372314453125000000f, 0.00399780273437500000f, + 0.00250244140625000000f, -0.00015258789062500000f, + -0.00833129882812500000f, -0.00152587890625000000f, + -0.01928710937500000000f, 0.02038574218750000000f, + 0.00012207031250000000f, 0.00097656250000000000f, + -0.00079345703125000011f, -0.00851440429687500000f, + 0.00961303710937500000f, 0.00503540039062499910f, + 0.00601196289062499910f, 0.01150512695312500000f, + 0.00473022460937500000f, -0.00125122070312500000f, + -0.00421142578125000000f, -0.00988769531250000000f, + -0.00332641601562499960f, -0.01882934570312500000f, + 0.01098632812500000000f, 0.00299072265625000000f, + -0.00161743164062500000f, -0.00973510742187500000f, + -0.00347900390625000000f, -0.00747680664062500000f, + -0.00250244140625000000f, 0.01547241210937500000f, + 0.01428222656250000000f, 0.00802612304687500000f, + -0.00418090820312500000f, -0.01187133789062500000f, + 0.01989746093750000000f, 0.01080322265625000200f, + -0.00054931640625000000f, -0.00692749023437500000f, + -0.01409912109375000000f, -0.00411987304687500000f, + 0.00967407226562500000f, 0.00161743164062500000f, + -0.00048828125000000000f, 0.00201416015625000000f, + -0.00219726562500000000f, -0.00384521484375000000f, + -0.01086425781250000000f, -0.01058959960937500000f, + -0.01000976562500000000f, -0.00219726562500000000f, + -0.01028442382812500000f, 0.00988769531250000000f, + 0.00463867187500000000f, 0.01065063476562500000f, + 0.00515747070312500000f, -0.00598144531250000000f, + 0.00546264648437500000f, 0.00775146484375000000f, + 0.00793457031250000000f, 0.00991821289062500000f, + -0.00225830078125000000f, -0.00244140625000000000f, + 0.00228881835937500000f, -0.00094604492187500000f, + 0.00823974609375000000f, 0.00839233398437500000f, + 0.00265502929687500000f, 0.00848388671875000000f, + -0.01361083984375000000f, -0.00918579101562500000f, + 0.00942993164062500000f, 0.00216674804687500000f, + -0.00076293945312500000f, -0.00738525390625000000f, + 0.01574707031250000000f, 0.00491333007812500000f, + -0.00494384765625000000f, -0.00253295898437500040f, + 0.01004028320312500000f, 0.00701904296875000090f, + -0.00949096679687500000f, -0.00790405273437500000f, + 0.00540161132812500090f, -0.00079345703125000011f, + -0.01409912109375000000f, 0.00271606445312500000f, + 0.00784301757812500000f, 0.00018310546875000000f, + -0.00396728515625000000f, -0.00283813476562499960f, + -0.01391601562500000000f, -0.00967407226562500000f, + -0.00674438476562500000f, -0.00628662109375000000f, + -0.01272583007812500000f, -0.00555419921875000000f, + -0.00225830078125000000f, 0.00714111328125000000f, + 0.00146484375000000000f, 0.00796508789062500000f, + 0.01095581054687500000f, 0.00704956054687500000f, + 0.00787353515625000000f, 0.00259399414062500000f, + -0.00860595703125000000f, 0.00769042968750000000f, + -0.00448608398437500000f, -0.00677490234375000000f, + 0.00765991210937500090f, -0.00631713867187499910f, + 0.01351928710937500000f, 0.00375366210937500000f, + -0.01272583007812500000f, -0.00109863281250000000f, + 0.00833129882812500000f, -0.00735473632812500090f, + 0.00732421874999999910f, -0.00341796875000000000f, + 0.00134277343749999980f, -0.00509643554687500000f, + 0.00384521484375000000f, -0.00378417968750000000f, + -0.00234985351562500000f, 0.00177001953125000000f, + -0.01223754882812500000f, 0.01016235351562500000f, + -0.00360107421875000000f, 0.00250244140625000000f, + 0.00384521484375000000f, 0.00460815429687500000f, + -0.01321411132812500000f, 0.01095581054687500000f, + -0.00396728515625000000f, -0.00311279296875000000f, + 0.00399780273437500000f, -0.00744628906250000000f, + 0.00262451171875000000f, 0.00259399414062500000f, + -0.01409912109375000000f, 0.01263427734374999800f, + -0.00732421874999999910f, 0.00048828125000000000f, + 0.00442504882812500000f, 0.00085449218750000000f, + -0.00625610351562500000f, -0.01467895507812500000f, + 0.01138305664062500000f, 0.00894165039062500000f, + -0.00219726562500000000f, -0.00531005859375000000f, + 0.00189208984375000000f, 0.00790405273437500000f, + -0.00024414062500000000f, -0.00054931640625000000f, + 0.01104736328125000000f, 0.00711059570312500000f, + 0.00564575195312500000f, 0.00131225585937500000f, + 0.00848388671875000000f, 0.00082397460937500000f, + 0.00588989257812500000f, 0.01739501953125000000f, + -0.00756835937500000000f, 0.00576782226562500000f, + 0.00280761718750000000f, 0.00094604492187500000f, + -0.00839233398437500000f, -0.00009155273437500000f, + 0.00741577148437500000f, 0.00537109374999999910f, + 0.01336669921875000200f, 0.00637817382812500090f, + 0.00628662109375000000f, -0.00155639648437500000f, + 0.00241088867187500000f, 0.00332641601562499960f, + 0.00512695312500000000f, -0.00564575195312500000f, + -0.00939941406250000000f, -0.00207519531250000000f, + -0.01885986328125000000f, 0.01174926757812500200f, + -0.00946044921875000000f, -0.00329589843750000000f, + -0.00500488281250000000f, 0.00503540039062499910f, + 0.00186157226562500000f, -0.00463867187500000000f, + -0.00308227539062500000f, -0.01257324218750000000f, + -0.00817871093750000000f, -0.00784301757812500000f, + -0.00122070312500000000f, -0.00061035156250000000f, + -0.00085449218750000000f, -0.00482177734375000000f, + -0.00918579101562500000f, 0.00827026367187500000f, + 0.01159667968750000000f, -0.01031494140625000000f, + -0.01119995117187500000f, -0.00402832031250000000f, + 0.00195312500000000000f, 0.00347900390625000000f, + -0.00399780273437500000f, -0.00686645507812500000f, + -0.00476074218750000000f, -0.00793457031250000000f, + -0.00192260742187500000f, -0.00354003906250000000f, + 0.00473022460937500000f, -0.01788330078125000000f, + -0.00616455078125000000f, 0.00775146484375000000f, + -0.00875854492187500000f, 0.00543212890625000000f, + 0.00692749023437500000f, -0.00323486328125000000f, + -0.00897216796875000000f, 0.00500488281250000000f, + 0.00909423828125000000f, -0.00305175781250000000f, + 0.00564575195312500000f, 0.00967407226562500000f, + 0.00588989257812500000f, -0.00137329101562500000f, + 0.00085449218750000000f, 0.00244140625000000000f, + -0.00265502929687500000f, -0.01321411132812500000f, + 0.00067138671874999989f, -0.00146484375000000000f, + 0.00146484375000000000f, -0.00723266601562500000f, + -0.00698852539062499910f, -0.00424194335937500000f, + 0.00366210937499999960f, -0.01110839843750000000f, + 0.00817871093750000000f, -0.00415039062500000000f, + 0.01208496093750000200f, 0.00381469726562499960f, + 0.00396728515625000000f, -0.00271606445312500000f, + -0.00830078125000000000f, 0.00360107421875000000f, + -0.00781250000000000000f, -0.00207519531250000000f, + -0.01376342773437500000f, 0.01489257812500000000f, + 0.00436401367187500000f, -0.00503540039062499910f, + -0.00146484375000000000f, -0.00579833984375000000f, + 0.00323486328125000000f, 0.00668334960937500090f, + 0.00143432617187500000f, 0.01327514648437500000f, + 0.00747680664062500000f, 0.00296020507812500000f, + 0.00228881835937500000f, -0.01275634765625000200f, + 0.00369262695312500000f, -0.00570678710937500090f, + 0.01739501953125000000f, -0.00610351562500000000f, + -0.01071166992187500000f, 0.00686645507812500000f, + -0.00064086914062500000f, -0.00662231445312500000f, + 0.00714111328125000000f, -0.00338745117187500000f, + 0.00592041015625000000f, 0.00042724609375000000f, + 0.00738525390625000000f, 0.00360107421875000000f, + 0.00427246093750000000f, -0.01211547851562500000f, + 0.01083374023437500000f, 0.01101684570312499800f, + -0.00137329101562500000f, -0.00595092773437500000f +}; + +const SKP_Silk_NLSF_CBS_FLP SKP_Silk_NLSF_CB0_10_Stage_info_FLP[ NLSF_MSVQ_CB0_10_STAGES ] = +{ + { 64, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 0 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 0 ] }, + { 16, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 64 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 64 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 80 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 80 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 88 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 88 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 96 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 96 ] }, + { 16, &SKP_Silk_NLSF_MSVQ_CB0_10[ 10 * 104 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates[ 104 ] } +}; + +const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB0_10_FLP = +{ + NLSF_MSVQ_CB0_10_STAGES, + SKP_Silk_NLSF_CB0_10_Stage_info_FLP, + SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min, + SKP_Silk_NLSF_MSVQ_CB0_10_CDF, + SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr, + SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx +}; + diff --git a/src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c b/src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c new file mode 100644 index 000000000..b6a1b8be4 --- /dev/null +++ b/src_FLP/SKP_Silk_tables_NLSF_CB0_16_FLP.c @@ -0,0 +1,1925 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/**********************************************/ +/* This file has been automatically generated */ +/* */ +/* ROM usage: 14.76 kB */ +/**********************************************/ + +#include "SKP_Silk_tables_FLP.h" +#include "SKP_Silk_tables_NLSF_CB0_16.h" + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_16_rates[ NLSF_MSVQ_CB0_16_VECTORS ] = +{ + 5.50000000000000000000f, 5.65625000000000000000f, + 5.68750000000000000000f, 5.71875000000000000000f, + 5.81250000000000000000f, 5.81250000000000000000f, + 5.96875000000000000000f, 5.96875000000000000000f, + 5.96875000000000000000f, 6.12500000000000000000f, + 6.15625000000000000000f, 6.28125000000000000000f, + 6.34375000000000000000f, 6.43750000000000000000f, + 6.43750000000000000000f, 6.43750000000000000000f, + 6.46875000000000000000f, 6.46875000000000000000f, + 6.53125000000000000000f, 6.53125000000000000000f, + 6.53125000000000000000f, 6.53125000000000000000f, + 6.56250000000000000000f, 6.56250000000000000000f, + 6.56250000000000000000f, 6.59375000000000000000f, + 6.59375000000000000000f, 6.59375000000000000000f, + 6.62500000000000000000f, 6.68750000000000000000f, + 6.75000000000000000000f, 6.75000000000000000000f, + 6.78125000000000000000f, 6.78125000000000000000f, + 6.78125000000000000000f, 6.78125000000000000000f, + 6.81250000000000000000f, 6.81250000000000000000f, + 6.84375000000000000000f, 6.84375000000000000000f, + 6.87500000000000000000f, 6.90625000000000000000f, + 6.93750000000000000000f, 6.96875000000000000000f, + 6.96875000000000000000f, 6.96875000000000000000f, + 6.96875000000000000000f, 7.00000000000000000000f, + 7.00000000000000000000f, 7.00000000000000000000f, + 7.03125000000000000000f, 7.03125000000000000000f, + 7.06250000000000000000f, 7.06250000000000000000f, + 7.06250000000000000000f, 7.06250000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.12500000000000000000f, 7.12500000000000000000f, + 7.12500000000000000000f, 7.12500000000000000000f, + 7.15625000000000000000f, 7.15625000000000000000f, + 7.15625000000000000000f, 7.18750000000000000000f, + 7.18750000000000000000f, 7.18750000000000000000f, + 7.21875000000000000000f, 7.21875000000000000000f, + 7.21875000000000000000f, 7.21875000000000000000f, + 7.25000000000000000000f, 7.25000000000000000000f, + 7.25000000000000000000f, 7.25000000000000000000f, + 7.28125000000000000000f, 7.31250000000000000000f, + 7.34375000000000000000f, 7.34375000000000000000f, + 7.34375000000000000000f, 7.37500000000000000000f, + 7.37500000000000000000f, 7.37500000000000000000f, + 7.37500000000000000000f, 7.40625000000000000000f, + 7.40625000000000000000f, 7.40625000000000000000f, + 7.40625000000000000000f, 7.50000000000000000000f, + 7.50000000000000000000f, 7.50000000000000000000f, + 7.50000000000000000000f, 7.53125000000000000000f, + 7.56250000000000000000f, 7.59375000000000000000f, + 7.62500000000000000000f, 7.62500000000000000000f, + 7.71875000000000000000f, 7.71875000000000000000f, + 7.75000000000000000000f, 7.75000000000000000000f, + 7.75000000000000000000f, 7.78125000000000000000f, + 7.84375000000000000000f, 7.96875000000000000000f, + 7.96875000000000000000f, 8.00000000000000000000f, + 8.12500000000000000000f, 8.12500000000000000000f, + 8.15625000000000000000f, 8.25000000000000000000f, + 8.25000000000000000000f, 8.31250000000000000000f, + 8.31250000000000000000f, 8.37500000000000000000f, + 8.46875000000000000000f, 8.56250000000000000000f, + 8.62500000000000000000f, 8.71875000000000000000f, + 9.00000000000000000000f, 9.00000000000000000000f, + 9.00000000000000000000f, 9.00000000000000000000f, + 3.68750000000000000000f, 3.75000000000000000000f, + 3.78125000000000000000f, 3.78125000000000000000f, + 3.81250000000000000000f, 3.90625000000000000000f, + 3.90625000000000000000f, 4.03125000000000000000f, + 4.03125000000000000000f, 4.06250000000000000000f, + 4.09375000000000000000f, 4.12500000000000000000f, + 4.25000000000000000000f, 4.28125000000000000000f, + 4.31250000000000000000f, 4.53125000000000000000f, + 2.71875000000000000000f, 2.75000000000000000000f, + 2.84375000000000000000f, 3.03125000000000000000f, + 3.06250000000000000000f, 3.12500000000000000000f, + 3.28125000000000000000f, 3.31250000000000000000f, + 2.87500000000000000000f, 2.96875000000000000000f, + 2.96875000000000000000f, 3.00000000000000000000f, + 3.03125000000000000000f, 3.03125000000000000000f, + 3.06250000000000000000f, 3.09375000000000000000f, + 2.75000000000000000000f, 2.87500000000000000000f, + 2.96875000000000000000f, 2.96875000000000000000f, + 3.00000000000000000000f, 3.03125000000000000000f, + 3.06250000000000000000f, 3.40625000000000000000f, + 2.90625000000000000000f, 2.90625000000000000000f, + 2.90625000000000000000f, 3.00000000000000000000f, + 3.03125000000000000000f, 3.03125000000000000000f, + 3.09375000000000000000f, 3.15625000000000000000f, + 2.90625000000000000000f, 2.93750000000000000000f, + 2.93750000000000000000f, 2.96875000000000000000f, + 2.96875000000000000000f, 3.09375000000000000000f, + 3.09375000000000000000f, 3.09375000000000000000f, + 2.90625000000000000000f, 2.90625000000000000000f, + 2.90625000000000000000f, 3.00000000000000000000f, + 3.00000000000000000000f, 3.03125000000000000000f, + 3.12500000000000000000f, 3.18750000000000000000f, + 2.90625000000000000000f, 2.96875000000000000000f, + 2.96875000000000000000f, 3.00000000000000000000f, + 3.00000000000000000000f, 3.00000000000000000000f, + 3.06250000000000000000f, 3.09375000000000000000f, + 3.90625000000000000000f, 3.90625000000000000000f, + 3.96875000000000000000f, 3.96875000000000000000f, + 3.96875000000000000000f, 3.96875000000000000000f, + 4.00000000000000000000f, 4.00000000000000000000f, + 4.00000000000000000000f, 4.00000000000000000000f, + 4.00000000000000000000f, 4.00000000000000000000f, + 4.03125000000000000000f, 4.06250000000000000000f, + 4.09375000000000000000f, 4.12500000000000000000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min[ 16 + 1 ] = +{ + 0.00811767578125000000f, + 0.00009155273437500000f, + 0.00122070312500000000f, + 0.00009155273437500000f, + 0.00009155273437500000f, + 0.00048828125000000000f, + 0.00238037109375000000f, + 0.00271606445312500000f, + 0.00326538085937500000f, + 0.00430297851562500000f, + 0.00573730468750000000f, + 0.00445556640625000000f, + 0.00830078125000000000f, + 0.00732421874999999910f, + 0.00717163085937500000f, + 0.00656127929687500000f, + 0.01928710937500000000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * NLSF_MSVQ_CB0_16_VECTORS ] = +{ + 0.03570556640625000000f, 0.06951904296875000000f, + 0.11163330078125001000f, 0.16400146484375000000f, + 0.23394775390625000000f, 0.27810668945312500000f, + 0.34478759765624994000f, 0.40600585937500000000f, + 0.46908569335937500000f, 0.53555297851562500000f, + 0.59774780273437500000f, 0.65573120117187500000f, + 0.72625732421875000000f, 0.79461669921875000000f, + 0.86419677734375000000f, 0.92166137695312500000f, + 0.04968261718750000700f, 0.07122802734375000000f, + 0.12557983398437500000f, 0.18420410156250000000f, + 0.23858642578125000000f, 0.29125976562500000000f, + 0.35940551757812500000f, 0.42788696289062500000f, + 0.48178100585937500000f, 0.53125000000000000000f, + 0.59405517578125000000f, 0.64883422851562500000f, + 0.69842529296875000000f, 0.74966430664062500000f, + 0.81524658203125000000f, 0.85629272460937500000f, + 0.05261230468750000000f, 0.08148193359375000000f, + 0.12377929687500000000f, 0.19934082031250000000f, + 0.25503540039062500000f, 0.30880737304687500000f, + 0.36904907226562506000f, 0.42910766601562500000f, + 0.50326538085937500000f, 0.57357788085937500000f, + 0.62307739257812500000f, 0.68365478515625000000f, + 0.74008178710937511000f, 0.80029296875000011000f, + 0.86700439453125000000f, 0.91418457031250000000f, + 0.04556274414062500000f, 0.10458374023437501000f, + 0.14614868164062500000f, 0.19528198242187500000f, + 0.25741577148437500000f, 0.31030273437500000000f, + 0.36621093750000000000f, 0.42926025390625000000f, + 0.49526977539062500000f, 0.55572509765625000000f, + 0.61157226562500000000f, 0.67437744140625000000f, + 0.73709106445312500000f, 0.79635620117187500000f, + 0.86007690429687500000f, 0.91921997070312489000f, + 0.03414916992187500000f, 0.06375122070312500000f, + 0.13107299804687500000f, 0.19058227539062500000f, + 0.26522827148437500000f, 0.32778930664062500000f, + 0.38720703125000000000f, 0.45950317382812500000f, + 0.51965332031250000000f, 0.57348632812500000000f, + 0.63223266601562500000f, 0.68707275390625011000f, + 0.74758911132812500000f, 0.81018066406250000000f, + 0.87338256835937500000f, 0.93475341796875000000f, + 0.04159545898437500000f, 0.07376098632812500000f, + 0.11984252929687500000f, 0.16955566406249997000f, + 0.22650146484375000000f, 0.28427124023437500000f, + 0.36251831054687500000f, 0.42013549804687500000f, + 0.49264526367187500000f, 0.56518554687500000000f, + 0.62432861328125000000f, 0.68902587890625000000f, + 0.74887084960937500000f, 0.80676269531250000000f, + 0.86419677734375000000f, 0.92523193359375000000f, + 0.03424072265625000000f, 0.07638549804687500000f, + 0.15917968750000000000f, 0.21813964843750000000f, + 0.28411865234375000000f, 0.33807373046874994000f, + 0.40206909179687500000f, 0.45166015625000000000f, + 0.51464843750000000000f, 0.57067871093750000000f, + 0.62365722656250000000f, 0.68627929687499989000f, + 0.74987792968750011000f, 0.81182861328125000000f, + 0.87142944335937500000f, 0.92852783203125000000f, + 0.01831054687500000000f, 0.04019165039062500700f, + 0.09063720703125001400f, 0.17117309570312500000f, + 0.23480224609375000000f, 0.29858398437500000000f, + 0.37136840820312500000f, 0.42990112304687506000f, + 0.49984741210937494000f, 0.56085205078125000000f, + 0.62716674804687500000f, 0.69232177734375000000f, + 0.75497436523437489000f, 0.81472778320312500000f, + 0.87420654296875000000f, 0.92636108398437500000f, + 0.02871704101562500000f, 0.05743408203125000000f, + 0.13043212890625000000f, 0.16906738281250000000f, + 0.25885009765625000000f, 0.30084228515625000000f, + 0.36437988281250000000f, 0.43600463867187494000f, + 0.49105834960937506000f, 0.56460571289062500000f, + 0.62030029296875000000f, 0.69006347656250000000f, + 0.75411987304687511000f, 0.81292724609374989000f, + 0.87933349609375000000f, 0.92864990234375000000f, + 0.01937866210937500000f, 0.05184936523437500000f, + 0.13354492187500000000f, 0.18151855468750000000f, + 0.24710083007812500000f, 0.30868530273437500000f, + 0.37457275390625000000f, 0.43267822265625000000f, + 0.49166870117187500000f, 0.54360961914062500000f, + 0.60104370117187500000f, 0.66445922851562511000f, + 0.73019409179687500000f, 0.78936767578124989000f, + 0.85516357421875000000f, 0.91961669921875000000f, + 0.04296874999999999300f, 0.06781005859375000000f, + 0.10754394531250000000f, 0.17135620117187503000f, + 0.22415161132812497000f, 0.27005004882812500000f, + 0.33535766601562500000f, 0.38977050781250000000f, + 0.46850585937500000000f, 0.51959228515625000000f, + 0.57736206054687500000f, 0.64276123046875000000f, + 0.71194458007812500000f, 0.76950073242187500000f, + 0.83035278320312511000f, 0.88571166992187500000f, + 0.02139282226562500000f, 0.03988647460937500000f, + 0.10827636718750001000f, 0.19229125976562500000f, + 0.23632812500000000000f, 0.29217529296875000000f, + 0.34262084960937494000f, 0.39605712890625000000f, + 0.46295166015625000000f, 0.53604125976562500000f, + 0.60348510742187500000f, 0.67434692382812500000f, + 0.73944091796875000000f, 0.80368041992187500000f, + 0.86599731445312500000f, 0.92257690429687500000f, + 0.05346679687500000700f, 0.07214355468750000000f, + 0.14889526367187500000f, 0.20046997070312500000f, + 0.23843383789062500000f, 0.29895019531250000000f, + 0.34176635742187500000f, 0.43609619140625006000f, + 0.48202514648437500000f, 0.54931640625000000000f, + 0.62243652343750000000f, 0.68411254882812489000f, + 0.74182128906250011000f, 0.79724121093750000000f, + 0.86547851562500000000f, 0.93484497070312500000f, + 0.02749633789062500000f, 0.04971313476562500000f, + 0.10241699218749999000f, 0.14144897460937500000f, + 0.22143554687500000000f, 0.26754760742187500000f, + 0.30429077148437500000f, 0.35272216796875000000f, + 0.46432495117187500000f, 0.53540039062500000000f, + 0.59579467773437500000f, 0.66687011718750000000f, + 0.72937011718750000000f, 0.79278564453125000000f, + 0.85855102539062500000f, 0.92114257812500000000f, + 0.02993774414062500000f, 0.05093383789062500000f, + 0.10140991210937499000f, 0.14321899414062500000f, + 0.18960571289062500000f, 0.26525878906250000000f, + 0.32391357421875006000f, 0.39538574218750000000f, + 0.46420288085937506000f, 0.54049682617187500000f, + 0.60595703125000000000f, 0.67510986328124989000f, + 0.74291992187500000000f, 0.81152343750000000000f, + 0.87655639648437500000f, 0.93020629882812500000f, + 0.04904174804687500000f, 0.07864379882812500000f, + 0.12878417968750000000f, 0.16821289062499997000f, + 0.26037597656250000000f, 0.31701660156250000000f, + 0.35482788085937500000f, 0.41720581054687494000f, + 0.48071289062500000000f, 0.52487182617187500000f, + 0.60546875000000000000f, 0.66708374023437500000f, + 0.71697998046875000000f, 0.78692626953125000000f, + 0.85726928710937500000f, 0.91952514648437500000f, + 0.02474975585937500000f, 0.04489135742187500000f, + 0.09594726562500000000f, 0.15383911132812500000f, + 0.22674560546875000000f, 0.28652954101562500000f, + 0.34100341796875000000f, 0.40451049804687500000f, + 0.46255493164062494000f, 0.51089477539062500000f, + 0.59762573242187500000f, 0.67648315429687500000f, + 0.73593139648437511000f, 0.79779052734375000000f, + 0.86618041992187500000f, 0.92758178710937500000f, + 0.04708862304687499300f, 0.06542968750000000000f, + 0.11074829101562500000f, 0.19369506835937500000f, + 0.22378540039062503000f, 0.28500366210937500000f, + 0.32684326171875000000f, 0.41491699218750006000f, + 0.46078491210937506000f, 0.52917480468750000000f, + 0.61346435546875000000f, 0.66790771484375000000f, + 0.72424316406250000000f, 0.78237915039062500000f, + 0.84893798828125000000f, 0.91299438476562511000f, + 0.01501464843750000000f, 0.03616333007812500000f, + 0.08972167968750000000f, 0.16748046875000003000f, + 0.21652221679687500000f, 0.26705932617187500000f, + 0.35388183593749994000f, 0.41439819335937500000f, + 0.48965454101562500000f, 0.54977416992187500000f, + 0.61578369140625000000f, 0.67526245117187500000f, + 0.74050903320312489000f, 0.80584716796875000000f, + 0.86926269531250000000f, 0.92642211914062500000f, + 0.04721069335937500000f, 0.06964111328125000000f, + 0.11270141601562500000f, 0.19351196289062500000f, + 0.23675537109374997000f, 0.29318237304687500000f, + 0.36157226562500000000f, 0.40393066406250000000f, + 0.50549316406250000000f, 0.55142211914062500000f, + 0.60299682617187500000f, 0.65319824218750011000f, + 0.73577880859375000000f, 0.81195068359375000000f, + 0.87847900390625000000f, 0.93551635742187511000f, + 0.02090454101562500000f, 0.04083251953125000000f, + 0.10403442382812500000f, 0.16058349609375000000f, + 0.21209716796875000000f, 0.28143310546875000000f, + 0.34832763671875000000f, 0.44320678710937500000f, + 0.49856567382812500000f, 0.54605102539062500000f, + 0.59313964843750000000f, 0.64996337890625000000f, + 0.71084594726562500000f, 0.76846313476562500000f, + 0.85366821289062500000f, 0.93139648437500000000f, + 0.02706909179687500300f, 0.04824829101562500000f, + 0.09329223632812500000f, 0.13177490234375000000f, + 0.21948242187500000000f, 0.26296997070312500000f, + 0.30661010742187500000f, 0.39996337890625000000f, + 0.49636840820312500000f, 0.54605102539062500000f, + 0.61746215820312500000f, 0.68206787109375000000f, + 0.74398803710937511000f, 0.80517578125000000000f, + 0.86407470703125000000f, 0.92129516601562489000f, + 0.06973266601562500000f, 0.11428833007812500000f, + 0.17279052734375000000f, 0.23120117187500000000f, + 0.28451538085937500000f, 0.34545898437500000000f, + 0.40402221679687500000f, 0.46359252929687494000f, + 0.52413940429687500000f, 0.58670043945312500000f, + 0.64416503906250000000f, 0.70104980468750000000f, + 0.75747680664062500000f, 0.81344604492187489000f, + 0.87161254882812500000f, 0.92956542968750000000f, + 0.04565429687500000700f, 0.06433105468750000000f, + 0.10522460937500000000f, 0.21051025390625003000f, + 0.25415039062500000000f, 0.29467773437500000000f, + 0.34338378906250000000f, 0.39132690429687500000f, + 0.45712280273437500000f, 0.50299072265625000000f, + 0.55480957031250000000f, 0.61294555664062500000f, + 0.70074462890624989000f, 0.76782226562500000000f, + 0.84548950195312500000f, 0.90420532226562500000f, + 0.01754760742187500000f, 0.03848266601562500000f, + 0.11782836914062500000f, 0.20223999023437500000f, + 0.25311279296875000000f, 0.32986450195312500000f, + 0.38772583007812500000f, 0.45068359375000000000f, + 0.52111816406250000000f, 0.58126831054687500000f, + 0.64019775390624989000f, 0.70358276367187500000f, + 0.76208496093750011000f, 0.81491088867187500000f, + 0.87646484375000000000f, 0.92605590820312500000f, + 0.05133056640625000000f, 0.06753540039062500000f, + 0.11846923828125000000f, 0.19036865234374997000f, + 0.21997070312500000000f, 0.29437255859375000000f, + 0.33193969726562500000f, 0.40988159179687500000f, + 0.45181274414062494000f, 0.49478149414062506000f, + 0.54751586914062500000f, 0.63699340820312489000f, + 0.71868896484375011000f, 0.78628540039062500000f, + 0.84704589843750000000f, 0.89907836914062500000f, + 0.02709960937500000000f, 0.04931640625000000000f, + 0.11975097656250000000f, 0.15853881835937500000f, + 0.21990966796875003000f, 0.26388549804687500000f, + 0.30035400390625000000f, 0.35012817382812500000f, + 0.49032592773437500000f, 0.55606079101562500000f, + 0.62081909179687500000f, 0.69500732421875000000f, + 0.74777221679687500000f, 0.80603027343750000000f, + 0.85614013671875000000f, 0.90731811523437500000f, + 0.02456665039062500000f, 0.04437255859375000000f, + 0.08187866210937500000f, 0.13647460937500000000f, + 0.24218750000000000000f, 0.28564453125000000000f, + 0.34783935546875000000f, 0.43777465820312500000f, + 0.49453735351562500000f, 0.54418945312500000000f, + 0.59365844726562500000f, 0.66058349609375000000f, + 0.72933959960937489000f, 0.79125976562500000000f, + 0.86630249023437511000f, 0.92965698242187500000f, + 0.05004882812500000000f, 0.07272338867187500000f, + 0.10632324218750000000f, 0.15509033203125000000f, + 0.18408203125000000000f, 0.26263427734375000000f, + 0.35522460937499994000f, 0.39569091796875000000f, + 0.48345947265625000000f, 0.53002929687500000000f, + 0.59039306640625000000f, 0.64642333984375000000f, + 0.72137451171875011000f, 0.79006958007812511000f, + 0.86572265625000000000f, 0.92465209960937500000f, + 0.04980468750000000000f, 0.06726074218750000000f, + 0.13763427734375000000f, 0.23132324218750003000f, + 0.26605224609375000000f, 0.32080078125000000000f, + 0.36505126953125000000f, 0.43017578125000000000f, + 0.47729492187500000000f, 0.52471923828125000000f, + 0.58419799804687500000f, 0.67892456054687511000f, + 0.74960327148437489000f, 0.81057739257812500000f, + 0.87292480468750000000f, 0.93106079101562500000f, + 0.06234741210937500000f, 0.07971191406250001400f, + 0.12161254882812500000f, 0.20907592773437500000f, + 0.24530029296875000000f, 0.29034423828125000000f, + 0.33505249023437500000f, 0.39028930664062500000f, + 0.47076416015625000000f, 0.51049804687500000000f, + 0.57675170898437500000f, 0.61880493164062500000f, + 0.69891357421875000000f, 0.79983520507812500000f, + 0.87619018554687500000f, 0.93438720703125011000f, + 0.06787109375000000000f, 0.08538818359375000000f, + 0.13626098632812500000f, 0.16235351562500000000f, + 0.21691894531249997000f, 0.28796386718750000000f, + 0.33526611328125000000f, 0.40350341796875000000f, + 0.44552612304687500000f, 0.55899047851562500000f, + 0.61465454101562500000f, 0.66659545898437500000f, + 0.72024536132812511000f, 0.78430175781250000000f, + 0.86010742187500000000f, 0.93328857421875000000f, + 0.02548217773437500000f, 0.04702758789062500000f, + 0.12460327148437500000f, 0.17605590820312503000f, + 0.22540283203125000000f, 0.28683471679687500000f, + 0.33480834960937500000f, 0.38012695312500000000f, + 0.45840454101562500000f, 0.56890869140625000000f, + 0.63607788085937500000f, 0.70495605468750000000f, + 0.77185058593750000000f, 0.82293701171875000000f, + 0.88354492187500000000f, 0.92840576171875011000f, + 0.05477905273437500000f, 0.07150268554687500000f, + 0.14675903320312500000f, 0.17993164062500003000f, + 0.21905517578125000000f, 0.26077270507812500000f, + 0.31198120117187500000f, 0.40802001953125000000f, + 0.44573974609375000000f, 0.50259399414062500000f, + 0.55764770507812500000f, 0.63281250000000000000f, + 0.72158813476562500000f, 0.80130004882812500000f, + 0.86132812500000000000f, 0.92742919921875000000f, + 0.05291748046875000000f, 0.06878662109375000000f, + 0.12301635742187500000f, 0.15832519531250000000f, + 0.19854736328125000000f, 0.24023437500000000000f, + 0.29452514648437500000f, 0.39749145507812500000f, + 0.44003295898437494000f, 0.52810668945312500000f, + 0.59494018554687500000f, 0.67718505859374989000f, + 0.74472045898437500000f, 0.80267333984375000000f, + 0.86044311523437500000f, 0.92092895507812500000f, + 0.05618286132812500000f, 0.07168579101562500000f, + 0.12109375000000000000f, 0.14538574218750000000f, + 0.19458007812500000000f, 0.29983520507812500000f, + 0.33715820312500000000f, 0.40725708007812500000f, + 0.44805908203125000000f, 0.49597167968750000000f, + 0.55490112304687500000f, 0.65194702148437500000f, + 0.72991943359375000000f, 0.79821777343750000000f, + 0.85543823242187500000f, 0.91354370117187500000f, + 0.04370117187500000000f, 0.06246948242187500000f, + 0.17184448242187500000f, 0.21139526367187500000f, + 0.25018310546875000000f, 0.29525756835937500000f, + 0.34661865234375000000f, 0.41217041015625000000f, + 0.45172119140625000000f, 0.50106811523437500000f, + 0.55966186523437500000f, 0.67196655273437500000f, + 0.73620605468750000000f, 0.79885864257812500000f, + 0.85845947265625000000f, 0.93341064453125000000f, + 0.05279541015625000700f, 0.07080078125000000000f, + 0.11425781250000000000f, 0.14672851562500000000f, + 0.18331909179687500000f, 0.29498291015625000000f, + 0.33560180664062500000f, 0.41571044921875000000f, + 0.46490478515625000000f, 0.53390502929687500000f, + 0.61303710937500000000f, 0.67144775390625000000f, + 0.72030639648437500000f, 0.77514648437500000000f, + 0.83554077148437489000f, 0.89276123046875000000f, + 0.03866577148437500000f, 0.05844116210937500000f, + 0.16732788085937503000f, 0.20788574218750000000f, + 0.25112915039062500000f, 0.30270385742187500000f, + 0.35366821289062494000f, 0.40701293945312500000f, + 0.45004272460937506000f, 0.54824829101562500000f, + 0.62719726562500000000f, 0.67648315429687500000f, + 0.74826049804687500000f, 0.81845092773437500000f, + 0.88143920898437500000f, 0.93511962890625000000f, + 0.04656982421875000000f, 0.06802368164062500000f, + 0.12939453125000000000f, 0.22546386718750000000f, + 0.27322387695312500000f, 0.31890869140625000000f, + 0.36312866210937500000f, 0.41864013671875006000f, + 0.51455688476562500000f, 0.55917358398437500000f, + 0.62191772460937500000f, 0.69189453125000000000f, + 0.75674438476562500000f, 0.82110595703125000000f, + 0.88214111328124989000f, 0.93450927734375000000f, + 0.06637573242187500000f, 0.08517456054687500000f, + 0.12524414062500000000f, 0.20980834960937500000f, + 0.26281738281250000000f, 0.29901123046875000000f, + 0.37084960937500000000f, 0.41308593750000000000f, + 0.47677612304687500000f, 0.53961181640625000000f, + 0.58633422851562500000f, 0.64270019531250000000f, + 0.74407958984375000000f, 0.81665039062499989000f, + 0.87380981445312500000f, 0.92309570312500000000f, + 0.01385498046875000000f, 0.03756713867187500000f, + 0.13241577148437500000f, 0.17510986328125000000f, + 0.23040771484375000000f, 0.27484130859375000000f, + 0.31494140625000000000f, 0.41275024414062506000f, + 0.48843383789062500000f, 0.54470825195312500000f, + 0.61251831054687500000f, 0.67114257812500000000f, + 0.73086547851562500000f, 0.79476928710937500000f, + 0.86196899414062511000f, 0.92086791992187489000f, + 0.06866455078125000000f, 0.08517456054687500000f, + 0.12908935546875000000f, 0.16122436523437500000f, + 0.20635986328125000000f, 0.32369995117187506000f, + 0.36251831054687500000f, 0.42178344726562500000f, + 0.48208618164062494000f, 0.52685546875000000000f, + 0.61123657226562500000f, 0.67950439453125000000f, + 0.75036621093750000000f, 0.80679321289062500000f, + 0.86193847656250000000f, 0.92831420898437489000f, + 0.05175781250000000000f, 0.06762695312500000000f, + 0.13146972656250000000f, 0.25588989257812500000f, + 0.29803466796875000000f, 0.33660888671875000000f, + 0.38317871093750000000f, 0.43026733398437500000f, + 0.49810791015625000000f, 0.53833007812500000000f, + 0.58489990234375000000f, 0.62835693359375000000f, + 0.73141479492187489000f, 0.81964111328125000000f, + 0.87884521484375000000f, 0.93267822265625000000f, + 0.07482910156250000000f, 0.09875488281250000000f, + 0.13333129882812500000f, 0.18670654296875000000f, + 0.21838378906250000000f, 0.27474975585937500000f, + 0.35122680664062500000f, 0.39050292968750000000f, + 0.48062133789062506000f, 0.52767944335937500000f, + 0.59481811523437500000f, 0.67874145507812500000f, + 0.74859619140625000000f, 0.80792236328125000000f, + 0.86282348632812489000f, 0.91775512695312511000f, + 0.05526733398437500000f, 0.07754516601562500000f, + 0.10848999023437500000f, 0.16723632812500000000f, + 0.27841186523437500000f, 0.32125854492187500000f, + 0.36297607421875000000f, 0.41683959960937500000f, + 0.46575927734374994000f, 0.51571655273437500000f, + 0.59100341796875000000f, 0.64297485351562511000f, + 0.69256591796875000000f, 0.74200439453125000000f, + 0.83178710937500000000f, 0.91500854492187500000f, + 0.04739379882812500000f, 0.06854248046875000000f, + 0.13912963867187500000f, 0.16784667968749997000f, + 0.20611572265625003000f, 0.24029541015625000000f, + 0.35824584960937500000f, 0.41415405273437500000f, + 0.46350097656250000000f, 0.54562377929687500000f, + 0.61892700195312500000f, 0.68695068359375000000f, + 0.75115966796875000000f, 0.81326293945312500000f, + 0.87847900390625000000f, 0.93856811523437500000f, + 0.06048583984375000000f, 0.08447265625000000000f, + 0.11700439453125001000f, 0.18200683593750000000f, + 0.26647949218750000000f, 0.30236816406250000000f, + 0.36001586914062500000f, 0.45205688476562500000f, + 0.49777221679687506000f, 0.54766845703125000000f, + 0.64382934570312500000f, 0.69735717773437500000f, + 0.74633789062500000000f, 0.80273437500000000000f, + 0.85955810546875000000f, 0.90805053710937511000f, + 0.05566406250000000000f, 0.07717895507812500000f, + 0.11648559570312500000f, 0.16629028320312500000f, + 0.20916748046875003000f, 0.26593017578125000000f, + 0.31680297851562500000f, 0.37493896484375006000f, + 0.43316650390625000000f, 0.48138427734375000000f, + 0.59582519531250000000f, 0.65228271484375000000f, + 0.72311401367187500000f, 0.79556274414062500000f, + 0.85742187500000000000f, 0.92199707031250011000f, + 0.06750488281250000000f, 0.08709716796875001400f, + 0.12045288085937500000f, 0.17999267578125000000f, + 0.30303955078125000000f, 0.35266113281250000000f, + 0.39227294921875000000f, 0.45129394531249994000f, + 0.49829101562500006000f, 0.54016113281250000000f, + 0.62014770507812500000f, 0.67437744140625000000f, + 0.72241210937500011000f, 0.77182006835937500000f, + 0.82324218750000011000f, 0.87237548828125000000f, + 0.06173706054687500000f, 0.07931518554687500000f, + 0.12280273437500000000f, 0.15002441406250000000f, + 0.20181274414062500000f, 0.34024047851562494000f, + 0.38015747070312500000f, 0.44635009765625000000f, + 0.49804687500000000000f, 0.54388427734375000000f, + 0.60037231445312500000f, 0.64611816406250000000f, + 0.70541381835937500000f, 0.79501342773437500000f, + 0.87966918945312500000f, 0.93865966796875000000f, + 0.04968261718750000700f, 0.06732177734375000000f, + 0.10580444335937500000f, 0.13317871093750000000f, + 0.26486206054687500000f, 0.31045532226562500000f, + 0.36206054687500000000f, 0.41744995117187500000f, + 0.45770263671874994000f, 0.51690673828125000000f, + 0.58615112304687500000f, 0.65197753906249989000f, + 0.72784423828125000000f, 0.79696655273437500000f, + 0.85827636718750000000f, 0.92385864257812500000f, + 0.06146240234375000000f, 0.07943725585937500000f, + 0.12554931640625000000f, 0.22137451171875000000f, + 0.25988769531250000000f, 0.30648803710937500000f, + 0.36077880859375000000f, 0.41207885742187500000f, + 0.49832153320312500000f, 0.54400634765625000000f, + 0.60110473632812500000f, 0.64941406250000000000f, + 0.70651245117187500000f, 0.75259399414062500000f, + 0.81808471679687500000f, 0.92044067382812511000f, + 0.07250976562500000000f, 0.09094238281250000000f, + 0.13494873046875000000f, 0.17608642578125000000f, + 0.21411132812500000000f, 0.29672241210937500000f, + 0.33950805664062506000f, 0.41247558593750000000f, + 0.47256469726562506000f, 0.51834106445312500000f, + 0.58471679687500000000f, 0.62826538085937500000f, + 0.74465942382812500000f, 0.82946777343750000000f, + 0.88641357421875000000f, 0.93527221679687500000f, + 0.07489013671875000000f, 0.10687255859375000000f, + 0.14111328125000000000f, 0.18368530273437500000f, + 0.23291015625000000000f, 0.27005004882812500000f, + 0.32934570312500000000f, 0.42614746093750000000f, + 0.47372436523437500000f, 0.52139282226562500000f, + 0.59848022460937500000f, 0.64813232421875000000f, + 0.69750976562500000000f, 0.76623535156249989000f, + 0.85772705078125011000f, 0.91217041015625000000f, + 0.04800415039062500700f, 0.06939697265625000000f, + 0.10095214843750000000f, 0.18307495117187500000f, + 0.27395629882812500000f, 0.30834960937500000000f, + 0.38015747070312500000f, 0.43511962890625000000f, + 0.48062133789062506000f, 0.55480957031250000000f, + 0.60955810546875000000f, 0.64859008789062500000f, + 0.70327758789062500000f, 0.76470947265625000000f, + 0.84658813476562500000f, 0.92514038085937500000f, + 0.05929565429687500000f, 0.08331298828125000000f, + 0.12634277343750000000f, 0.18798828125000003000f, + 0.22860717773437500000f, 0.27423095703125000000f, + 0.34512329101562500000f, 0.38986206054687500000f, + 0.45227050781250000000f, 0.50531005859375000000f, + 0.54653930664062500000f, 0.60293579101562500000f, + 0.65649414062500011000f, 0.72036743164062500000f, + 0.83233642578124989000f, 0.90109252929687500000f, + 0.06167602539062500000f, 0.07879638671875000000f, + 0.13714599609375000000f, 0.17807006835937503000f, + 0.21340942382812497000f, 0.25161743164062500000f, + 0.29989624023437500000f, 0.44961547851562500000f, + 0.50238037109375000000f, 0.54608154296875000000f, + 0.59957885742187500000f, 0.64340209960937489000f, + 0.72521972656250000000f, 0.81381225585937500000f, + 0.88720703125000000000f, 0.94573974609375000000f, + 0.03210449218750000000f, 0.05416870117187500000f, + 0.09820556640624998600f, 0.13360595703125000000f, + 0.23394775390625000000f, 0.28695678710937500000f, + 0.34326171875000000000f, 0.40670776367187500000f, + 0.45690917968750000000f, 0.54815673828125000000f, + 0.63348388671875000000f, 0.68218994140625000000f, + 0.76510620117187500000f, 0.83035278320312511000f, + 0.88504028320312500000f, 0.93411254882812489000f, + 0.06768798828125000000f, 0.08746337890624998600f, + 0.12887573242187500000f, 0.16333007812500000000f, + 0.20083618164062500000f, 0.30456542968750000000f, + 0.35360717773437500000f, 0.40042114257812500000f, + 0.46365356445312500000f, 0.50607299804687500000f, + 0.56109619140625000000f, 0.61279296875000000000f, + 0.67178344726562500000f, 0.77261352539062500000f, + 0.85836791992187500000f, 0.91186523437500011000f, + 0.06549072265625000000f, 0.08666992187500000000f, + 0.13418579101562500000f, 0.17822265625000000000f, + 0.22732543945312500000f, 0.26614379882812500000f, + 0.32080078125000000000f, 0.36425781250000000000f, + 0.41488647460937500000f, 0.52651977539062500000f, + 0.58929443359375000000f, 0.63754272460937500000f, + 0.71463012695312500000f, 0.78207397460937500000f, + 0.84683227539062500000f, 0.92257690429687500000f, + 0.06018066406250000000f, 0.07992553710937500000f, + 0.11462402343750000000f, 0.19430541992187500000f, + 0.23318481445312503000f, 0.26898193359375000000f, + 0.37493896484375006000f, 0.42016601562500000000f, + 0.46719360351562506000f, 0.55041503906250000000f, + 0.59683227539062500000f, 0.63793945312500000000f, + 0.68914794921875011000f, 0.75915527343750000000f, + 0.84838867187500000000f, 0.92895507812500000000f, + 0.06118774414062500000f, 0.07864379882812500000f, + 0.13037109375000000000f, 0.22500610351562500000f, + 0.26116943359375000000f, 0.31198120117187500000f, + 0.35919189453125000000f, 0.40899658203125000000f, + 0.50360107421875000000f, 0.54931640625000000000f, + 0.59951782226562500000f, 0.64404296875000000000f, + 0.70159912109375000000f, 0.81805419921875000000f, + 0.90042114257812489000f, 0.94427490234375000000f, + 0.03518676757812500000f, 0.05560302734375000000f, + 0.11364746093750001000f, 0.16610717773437500000f, + 0.21331787109375000000f, 0.26556396484375000000f, + 0.31399536132812500000f, 0.36312866210937500000f, + 0.42285156250000000000f, 0.46737670898437500000f, + 0.53713989257812500000f, 0.64282226562500000000f, + 0.72302246093750011000f, 0.79598999023437500000f, + 0.87237548828125000000f, 0.93502807617187500000f, + 0.03979492187500000000f, 0.05703735351562500000f, + 0.10125732421875000000f, 0.21957397460937500000f, + 0.29336547851562500000f, 0.32754516601562500000f, + 0.37820434570312500000f, 0.41894531250000000000f, + 0.48284912109375000000f, 0.53326416015625000000f, + 0.57623291015625000000f, 0.63146972656250000000f, + 0.70538330078125000000f, 0.77941894531250000000f, + 0.84484863281250000000f, 0.89245605468750011000f, + 0.06387329101562500000f, 0.08212280273437500000f, + 0.12261962890625000000f, 0.20318603515625000000f, + 0.24252319335937500000f, 0.27914428710937500000f, + 0.32034301757812500000f, 0.36257934570312500000f, + 0.48486328125000006000f, 0.54385375976562500000f, + 0.58999633789062500000f, 0.64797973632812500000f, + 0.71322631835937489000f, 0.77008056640625000000f, + 0.84085083007812500000f, 0.91546630859375000000f, + 0.01754760742187500000f, 0.04061889648437499300f, + 0.16186523437500000000f, 0.21087646484374997000f, + 0.25711059570312500000f, 0.30780029296875000000f, + 0.35330200195312500000f, 0.41192626953125006000f, + 0.50183105468750000000f, 0.56539916992187500000f, + 0.62759399414062500000f, 0.69723510742187500000f, + 0.76031494140625000000f, 0.81457519531249989000f, + 0.87765502929687500000f, 0.92031860351562500000f, + 0.04379272460937500000f, 0.06176757812500000000f, + 0.10018920898437500000f, 0.12683105468750000000f, + 0.23226928710937500000f, 0.32324218750000000000f, + 0.36770629882812506000f, 0.42501831054687500000f, + 0.47177124023437500000f, 0.56192016601562500000f, + 0.62545776367187500000f, 0.67962646484375000000f, + 0.73919677734375000000f, 0.79629516601562489000f, + 0.85647583007812500000f, 0.91854858398437500000f, + 0.04980468750000000000f, 0.06616210937500000000f, + 0.16906738281250000000f, 0.22821044921875000000f, + 0.26336669921875000000f, 0.31710815429687500000f, + 0.35534667968750000000f, 0.43704223632812494000f, + 0.48037719726562500000f, 0.52969360351562500000f, + 0.57238769531250000000f, 0.62359619140625000000f, + 0.69577026367187500000f, 0.79528808593750000000f, + 0.87103271484375000000f, 0.93676757812500000000f, + 0.04293823242187500000f, 0.06851196289062500000f, + 0.10391235351562501000f, 0.17208862304687500000f, + 0.28744506835937500000f, 0.32608032226562506000f, + 0.36938476562500000000f, 0.41183471679687494000f, + 0.47409057617187500000f, 0.56021118164062500000f, + 0.61022949218750000000f, 0.66189575195312500000f, + 0.74313354492187500000f, 0.81024169921874989000f, + 0.88052368164062500000f, 0.93273925781250011000f, + 0.05111694335937500700f, 0.06793212890625000000f, + 0.12222290039062501000f, 0.25094604492187500000f, + 0.30441284179687500000f, 0.34042358398437500000f, + 0.39129638671875000000f, 0.43688964843750000000f, + 0.50366210937500000000f, 0.55349731445312500000f, + 0.59735107421875000000f, 0.64239501953125000000f, + 0.69454956054687500000f, 0.76025390625000000000f, + 0.86352539062500011000f, 0.93487548828125000000f, + 0.03295898437500000000f, 0.04925537109375000000f, + 0.11053466796875000000f, 0.23086547851562497000f, + 0.26696777343750000000f, 0.31442260742187500000f, + 0.35745239257812500000f, 0.42260742187500000000f, + 0.47708129882812500000f, 0.53204345703125000000f, + 0.60305786132812500000f, 0.66604614257812500000f, + 0.71932983398437500000f, 0.77493286132812500000f, + 0.83636474609375000000f, 0.88693237304687500000f, + 0.05166625976562500000f, 0.06802368164062500000f, + 0.10546875000000000000f, 0.13287353515625000000f, + 0.17303466796875000000f, 0.33233642578125000000f, + 0.38339233398437500000f, 0.43234252929687500000f, + 0.48458862304687500000f, 0.53030395507812500000f, + 0.60476684570312500000f, 0.67050170898437500000f, + 0.73529052734375000000f, 0.79745483398437500000f, + 0.86358642578125000000f, 0.91854858398437500000f, + 0.06231689453125000000f, 0.09030151367187501400f, + 0.12802124023437500000f, 0.17517089843750000000f, + 0.21685791015625000000f, 0.25228881835937500000f, + 0.33953857421875000000f, 0.45693969726562500000f, + 0.51617431640625000000f, 0.55831909179687500000f, + 0.62658691406250000000f, 0.67083740234375000000f, + 0.72360229492187500000f, 0.78640747070312500000f, + 0.84255981445312511000f, 0.89572143554687500000f, + 0.03002929687500000000f, 0.04919433593750000000f, + 0.11621093750000000000f, 0.16067504882812500000f, + 0.21011352539062500000f, 0.25668334960937500000f, + 0.29135131835937500000f, 0.33230590820312500000f, + 0.38214111328125000000f, 0.50415039062500000000f, + 0.59658813476562500000f, 0.66036987304687500000f, + 0.72467041015625011000f, 0.79522705078125000000f, + 0.86395263671874989000f, 0.92694091796875011000f, + 0.06213378906250000000f, 0.07745361328125000000f, + 0.12713623046875000000f, 0.23684692382812500000f, + 0.27911376953125000000f, 0.31774902343750000000f, + 0.37060546875000006000f, 0.41531372070312500000f, + 0.47570800781250000000f, 0.52395629882812500000f, + 0.56637573242187500000f, 0.61380004882812500000f, + 0.66589355468750000000f, 0.74197387695312500000f, + 0.85537719726562489000f, 0.93420410156249989000f, + 0.05709838867187500000f, 0.07186889648437500000f, + 0.12393188476562500000f, 0.15695190429687500000f, + 0.22778320312500000000f, 0.30911254882812500000f, + 0.36441040039062506000f, 0.45779418945312506000f, + 0.50903320312500000000f, 0.56011962890625000000f, + 0.60903930664062500000f, 0.67990112304687500000f, + 0.75869750976562489000f, 0.82006835937500000000f, + 0.88464355468750000000f, 0.93429565429687511000f, + 0.07830810546875000000f, 0.09646606445312500000f, + 0.14169311523437500000f, 0.19003295898437500000f, + 0.22601318359375000000f, 0.30426025390625000000f, + 0.35455322265625000000f, 0.40942382812500000000f, + 0.48489379882812500000f, 0.52990722656250000000f, + 0.58352661132812500000f, 0.63528442382812500000f, + 0.68945312500000000000f, 0.75439453125000000000f, + 0.87686157226562489000f, 0.94854736328125000000f, + 0.05187988281249999300f, 0.07101440429687500000f, + 0.14733886718750000000f, 0.18124389648437500000f, + 0.23092651367187500000f, 0.27935791015625000000f, + 0.33834838867187500000f, 0.38973999023437500000f, + 0.43362426757812506000f, 0.49197387695312500000f, + 0.61712646484375000000f, 0.69186401367187500000f, + 0.75219726562500000000f, 0.81347656250000000000f, + 0.87573242187499989000f, 0.93826293945312500000f, + 0.09671020507812500000f, 0.11819458007812501000f, + 0.15399169921875000000f, 0.20959472656250000000f, + 0.24975585937500000000f, 0.28930664062500000000f, + 0.37643432617187500000f, 0.42932128906250000000f, + 0.48138427734375000000f, 0.54843139648437500000f, + 0.61740112304687500000f, 0.66256713867187500000f, + 0.71777343750000000000f, 0.77041625976562500000f, + 0.82476806640625000000f, 0.87677001953124989000f, + 0.04772949218750000000f, 0.07296752929687500000f, + 0.12905883789062500000f, 0.20538330078125000000f, + 0.27175903320312500000f, 0.31918334960937500000f, + 0.39752197265625000000f, 0.45877075195312500000f, + 0.52688598632812500000f, 0.60452270507812500000f, + 0.66677856445312500000f, 0.72451782226562500000f, + 0.77789306640625000000f, 0.83349609375000000000f, + 0.88687133789062500000f, 0.93161010742187511000f, + 0.08740234375000000000f, 0.10861206054687501000f, + 0.14401245117187500000f, 0.19656372070312503000f, + 0.29272460937500000000f, 0.33737182617187500000f, + 0.38949584960937500000f, 0.45117187500000000000f, + 0.50134277343750000000f, 0.55432128906250000000f, + 0.62518310546875000000f, 0.67938232421875000000f, + 0.73800659179687511000f, 0.80148315429687500000f, + 0.86618041992187500000f, 0.92236328125000000000f, + 0.08157348632812498600f, 0.10525512695312501000f, + 0.13980102539062500000f, 0.18258666992187500000f, + 0.20944213867187500000f, 0.25363159179687500000f, + 0.38037109375000000000f, 0.42453002929687506000f, + 0.48028564453125000000f, 0.54293823242187500000f, + 0.59252929687500000000f, 0.64642333984375000000f, + 0.73318481445312500000f, 0.81057739257812500000f, + 0.87655639648437500000f, 0.92895507812500000000f, + 0.07382202148437500000f, 0.09304809570312500000f, + 0.13043212890625000000f, 0.19482421875000000000f, + 0.26135253906250000000f, 0.29483032226562500000f, + 0.34448242187499994000f, 0.38684082031250000000f, + 0.44088745117187500000f, 0.53643798828125000000f, + 0.60473632812500000000f, 0.64791870117187511000f, + 0.70492553710937500000f, 0.77117919921874989000f, + 0.82089233398437500000f, 0.88275146484374989000f, + 0.03900146484375000000f, 0.06106567382812500000f, + 0.09155273437500000000f, 0.16336059570312500000f, + 0.30502319335937500000f, 0.35940551757812500000f, + 0.39727783203125000000f, 0.44464111328125000000f, + 0.48980712890625000000f, 0.54205322265625000000f, + 0.60980224609375000000f, 0.65969848632812511000f, + 0.71322631835937489000f, 0.76547241210937500000f, + 0.84399414062500000000f, 0.92077636718749989000f, + 0.02844238281250000000f, 0.04956054687500000000f, + 0.08538818359375000000f, 0.13946533203125000000f, + 0.26220703125000000000f, 0.30480957031250000000f, + 0.35253906249999994000f, 0.39825439453125000000f, + 0.51638793945312500000f, 0.56997680664062500000f, + 0.62301635742187500000f, 0.69610595703125000000f, + 0.75735473632812500000f, 0.81845092773437500000f, + 0.87902832031250011000f, 0.92727661132812489000f, + 0.07092285156250000000f, 0.09072875976562500000f, + 0.12683105468750000000f, 0.17401123046875000000f, + 0.21115112304687500000f, 0.26873779296875000000f, + 0.31307983398437500000f, 0.38156127929687494000f, + 0.45822143554687494000f, 0.50558471679687500000f, + 0.59259033203125000000f, 0.65231323242187500000f, + 0.70016479492187500000f, 0.74920654296875000000f, + 0.82470703124999989000f, 0.91091918945312500000f, + 0.04772949218750000000f, 0.07241821289062500000f, + 0.10543823242187499000f, 0.14974975585937500000f, + 0.18234252929687500000f, 0.22692871093750000000f, + 0.35968017578125000000f, 0.44265747070312500000f, + 0.49154663085937500000f, 0.55383300781250000000f, + 0.61093139648437500000f, 0.66079711914062500000f, + 0.72448730468749989000f, 0.78778076171875000000f, + 0.87213134765625000000f, 0.92687988281250000000f, + 0.09231567382812501400f, 0.11380004882812500000f, + 0.14849853515625000000f, 0.19897460937500000000f, + 0.28952026367187500000f, 0.33395385742187500000f, + 0.37713623046875000000f, 0.43511962890625000000f, + 0.49359130859375000000f, 0.53408813476562500000f, + 0.59436035156250000000f, 0.65332031250000000000f, + 0.70883178710937500000f, 0.76007080078125000000f, + 0.83456420898437500000f, 0.89743041992187500000f, + 0.03875732421875000000f, 0.05996704101562500000f, + 0.20758056640625000000f, 0.24398803710937500000f, + 0.28088378906250000000f, 0.33044433593750000000f, + 0.38168334960937500000f, 0.43426513671875000000f, + 0.48092651367187500000f, 0.54504394531250000000f, + 0.62161254882812500000f, 0.68670654296875000000f, + 0.75173950195312500000f, 0.80914306640625000000f, + 0.87081909179687500000f, 0.93154907226562500000f, + 0.06744384765625000000f, 0.08389282226562500000f, + 0.13018798828125000000f, 0.22848510742187503000f, + 0.30145263671875000000f, 0.33624267578125000000f, + 0.39132690429687500000f, 0.44039916992187500000f, + 0.49581909179687494000f, 0.56842041015625000000f, + 0.62408447265625000000f, 0.67303466796875011000f, + 0.72445678710937500000f, 0.77182006835937500000f, + 0.82623291015625000000f, 0.89016723632812500000f, + 0.03890991210937500000f, 0.05877685546875000000f, + 0.13214111328125000000f, 0.20059204101562503000f, + 0.25759887695312500000f, 0.33325195312500000000f, + 0.40466308593750000000f, 0.45800781249999994000f, + 0.51657104492187500000f, 0.56680297851562500000f, + 0.63000488281250000000f, 0.67800903320312500000f, + 0.73190307617187500000f, 0.77740478515625000000f, + 0.83532714843750000000f, 0.87417602539062489000f, + 0.09201049804687500000f, 0.11199951171875000000f, + 0.15521240234375000000f, 0.19445800781250000000f, + 0.24072265625000000000f, 0.28408813476562500000f, + 0.33465576171875006000f, 0.38580322265624994000f, + 0.44235229492187500000f, 0.49353027343750000000f, + 0.55175781250000000000f, 0.60949707031250000000f, + 0.68524169921874989000f, 0.75985717773437500000f, + 0.83502197265624989000f, 0.91476440429687500000f, + 0.08795166015625001400f, 0.11392211914062500000f, + 0.15603637695312500000f, 0.19781494140625000000f, + 0.24795532226562503000f, 0.29556274414062500000f, + 0.35394287109375000000f, 0.40551757812500006000f, + 0.47012329101562500000f, 0.52465820312500000000f, + 0.61578369140625000000f, 0.68438720703125011000f, + 0.75686645507812500000f, 0.82440185546875000000f, + 0.89147949218750000000f, 0.94027709960937511000f, + 0.07019042968750000000f, 0.09057617187500000000f, + 0.12515258789062500000f, 0.16607666015625000000f, + 0.19308471679687500000f, 0.24139404296875000000f, + 0.38009643554687500000f, 0.42303466796875000000f, + 0.48056030273437500000f, 0.53421020507812500000f, + 0.58145141601562500000f, 0.63107299804687500000f, + 0.69015502929687500000f, 0.75250244140625000000f, + 0.83920288085937500000f, 0.91751098632812500000f, + 0.06887817382812500000f, 0.08972167968750000000f, + 0.13519287109375000000f, 0.18283081054687497000f, + 0.21490478515624997000f, 0.25524902343750000000f, + 0.28729248046875000000f, 0.34252929687500000000f, + 0.47982788085937500000f, 0.53161621093750000000f, + 0.58755493164062500000f, 0.65518188476562489000f, + 0.72982788085937500000f, 0.79507446289062500000f, + 0.86761474609375000000f, 0.92724609375000000000f, + 0.03744506835937500000f, 0.06240844726562500000f, + 0.11651611328124999000f, 0.15292358398437500000f, + 0.21331787109375000000f, 0.28170776367187500000f, + 0.33642578124999994000f, 0.39706420898437494000f, + 0.52920532226562500000f, 0.58035278320312500000f, + 0.62814331054687500000f, 0.69577026367187500000f, + 0.76889038085937500000f, 0.82019042968750000000f, + 0.89572143554687500000f, 0.94009399414062489000f, + 0.04132080078125000000f, 0.05871582031250000000f, + 0.11563110351562500000f, 0.24649047851562500000f, + 0.31900024414062500000f, 0.35519409179687500000f, + 0.40747070312500000000f, 0.45217895507812500000f, + 0.51095581054687500000f, 0.55508422851562500000f, + 0.61325073242187500000f, 0.67181396484374989000f, + 0.75051879882812500000f, 0.81411743164062500000f, + 0.87423706054687500000f, 0.92333984375000000000f, + 0.09588623046875000000f, 0.12356567382812501000f, + 0.18911743164062500000f, 0.22634887695312500000f, + 0.26712036132812500000f, 0.30993652343750000000f, + 0.35195922851562500000f, 0.40225219726562500000f, + 0.48666381835937500000f, 0.53878784179687500000f, + 0.59832763671875000000f, 0.65313720703125000000f, + 0.71676635742187500000f, 0.78305053710937511000f, + 0.85824584960937511000f, 0.92480468750000000000f, + 0.04019165039062500700f, 0.06906127929687500000f, + 0.14419555664062500000f, 0.23226928710937500000f, + 0.29501342773437500000f, 0.35504150390625000000f, + 0.43161010742187500000f, 0.49615478515625000000f, + 0.57141113281250000000f, 0.63165283203125000000f, + 0.68295288085937500000f, 0.73263549804687511000f, + 0.78659057617187489000f, 0.83163452148437500000f, + 0.88287353515625000000f, 0.93362426757812500000f, + 0.04791259765625000000f, 0.07089233398437500000f, + 0.11651611328124999000f, 0.18966674804687500000f, + 0.30191040039062500000f, 0.35266113281250000000f, + 0.39886474609375000000f, 0.44650268554687500000f, + 0.49291992187500006000f, 0.55816650390625000000f, + 0.65264892578125000000f, 0.71246337890625000000f, + 0.76641845703125011000f, 0.82162475585937500000f, + 0.87622070312500000000f, 0.92065429687500000000f, + 0.07009887695312500000f, 0.11917114257812500000f, + 0.19186401367187503000f, 0.26116943359375000000f, + 0.32556152343750006000f, 0.38958740234375000000f, + 0.45834350585937500000f, 0.52191162109375000000f, + 0.58093261718750000000f, 0.63101196289062500000f, + 0.68179321289062500000f, 0.72848510742187500000f, + 0.77752685546875000000f, 0.82656860351562500000f, + 0.88046264648437500000f, 0.93139648437500000000f, + 0.05844116210937500000f, 0.07650756835937500000f, + 0.12307739257812499000f, 0.17544555664062500000f, + 0.21542358398437497000f, 0.27072143554687500000f, + 0.32528686523437500000f, 0.37225341796875006000f, + 0.42532348632812500000f, 0.46945190429687500000f, + 0.51480102539062500000f, 0.57089233398437500000f, + 0.70724487304687489000f, 0.78790283203125011000f, + 0.87017822265625000000f, 0.93081665039062500000f, + 0.07336425781250000000f, 0.08905029296875000000f, + 0.15838623046875000000f, 0.19079589843750000000f, + 0.22662353515625003000f, 0.30172729492187500000f, + 0.37802124023437500000f, 0.45150756835937494000f, + 0.51129150390625000000f, 0.56054687500000000000f, + 0.62066650390625000000f, 0.67147827148437511000f, + 0.73962402343750000000f, 0.80737304687500000000f, + 0.86944580078125000000f, 0.92764282226562500000f, + 0.04946899414062500000f, 0.06796264648437500000f, + 0.10617065429687500000f, 0.15518188476562500000f, + 0.28762817382812500000f, 0.39343261718750006000f, + 0.43475341796875006000f, 0.47766113281250000000f, + 0.52505493164062500000f, 0.56988525390625000000f, + 0.62396240234375000000f, 0.67776489257812500000f, + 0.72564697265625000000f, 0.78939819335937500000f, + 0.85238647460937500000f, 0.91836547851562500000f, + 0.05703735351562500000f, 0.07293701171875000000f, + 0.12527465820312500000f, 0.21426391601562500000f, + 0.34243774414062500000f, 0.38986206054687500000f, + 0.42904663085937500000f, 0.47576904296875006000f, + 0.51953125000000000000f, 0.56787109375000000000f, + 0.62850952148437500000f, 0.67367553710937500000f, + 0.72171020507812489000f, 0.76763916015625000000f, + 0.82135009765625000000f, 0.87496948242187500000f, + 0.07785034179687500000f, 0.09924316406250000000f, + 0.14306640625000000000f, 0.20025634765625000000f, + 0.24014282226562500000f, 0.27847290039062500000f, + 0.31967163085937506000f, 0.36010742187500000000f, + 0.47003173828125000000f, 0.57312011718750000000f, + 0.64062500000000000000f, 0.68832397460937500000f, + 0.74124145507812500000f, 0.79248046874999989000f, + 0.83816528320312500000f, 0.89208984375000000000f, + 0.08255004882812500000f, 0.10659790039062501000f, + 0.14450073242187500000f, 0.19409179687500000000f, + 0.24124145507812503000f, 0.28540039062500000000f, + 0.35211181640625006000f, 0.40985107421875000000f, + 0.46505737304687500000f, 0.51632690429687500000f, + 0.56820678710937500000f, 0.61322021484375000000f, + 0.66528320312500000000f, 0.71234130859375000000f, + 0.76904296875000000000f, 0.89285278320312500000f, + 0.06610107421875000000f, 0.08517456054687500000f, + 0.12240600585937499000f, 0.15505981445312500000f, + 0.17993164062500003000f, 0.27581787109375000000f, + 0.40914916992187494000f, 0.44869995117187506000f, + 0.50485229492187500000f, 0.55508422851562500000f, + 0.60717773437500000000f, 0.66702270507812500000f, + 0.75903320312500000000f, 0.82308959960937500000f, + 0.88363647460937500000f, 0.93121337890625000000f, + 0.05691528320312499300f, 0.09219360351562500000f, + 0.14331054687500000000f, 0.19940185546875003000f, + 0.25460815429687500000f, 0.30255126953125000000f, + 0.39028930664062500000f, 0.43038940429687500000f, + 0.50454711914062500000f, 0.54104614257812500000f, + 0.65124511718750000000f, 0.68478393554687500000f, + 0.75906372070312500000f, 0.80352783203125000000f, + 0.86755371093750000000f, 0.92022705078125000000f, + 0.10281372070312500000f, 0.13259887695312500000f, + 0.20059204101562503000f, 0.26742553710937500000f, + 0.31460571289062500000f, 0.35745239257812500000f, + 0.40792846679687500000f, 0.45117187500000000000f, + 0.50302124023437500000f, 0.55374145507812500000f, + 0.60543823242187500000f, 0.64840698242187500000f, + 0.71081542968750000000f, 0.77749633789062489000f, + 0.84091186523437489000f, 0.89865112304687500000f, + 0.03860473632812500000f, 0.06665039062500000000f, + 0.16610717773437500000f, 0.24087524414062500000f, + 0.32321166992187500000f, 0.40097045898437506000f, + 0.46096801757812500000f, 0.50778198242187500000f, + 0.56158447265625000000f, 0.60504150390625000000f, + 0.65365600585937500000f, 0.70175170898437500000f, + 0.75436401367187500000f, 0.80679321289062500000f, + 0.86557006835937500000f, 0.91934204101562500000f, + 0.04833984375000000700f, 0.06115722656250000000f, + 0.10787963867187500000f, 0.13580322265625000000f, + 0.26434326171875000000f, 0.32849121093750000000f, + 0.39160156250000000000f, 0.45709228515625000000f, + 0.51794433593750000000f, 0.57354736328125000000f, + 0.63879394531250000000f, 0.68807983398437500000f, + 0.75183105468750000000f, 0.80935668945312500000f, + 0.87588500976562500000f, 0.93283081054687511000f, + 0.10433959960937500000f, 0.13818359375000000000f, + 0.20147705078124997000f, 0.24078369140624997000f, + 0.29016113281250000000f, 0.33187866210937494000f, + 0.38973999023437500000f, 0.43814086914062500000f, + 0.48983764648437500000f, 0.55938720703125000000f, + 0.62957763671875000000f, 0.68634033203125000000f, + 0.76507568359375000000f, 0.82202148437499989000f, + 0.88336181640625011000f, 0.93206787109375000000f, + 0.05267333984375000000f, 0.06872558593750000000f, + 0.14028930664062500000f, 0.21209716796875000000f, + 0.25570678710937500000f, 0.29977416992187500000f, + 0.34677124023437500000f, 0.39044189453125006000f, + 0.43658447265625000000f, 0.47229003906250000000f, + 0.51263427734375000000f, 0.54986572265625000000f, + 0.66134643554687511000f, 0.77972412109375000000f, + 0.85900878906249989000f, 0.92672729492187500000f, + 0.10330200195312500000f, 0.11810302734375000000f, + 0.16195678710937503000f, 0.19494628906250000000f, + 0.21792602539062500000f, 0.26501464843750000000f, + 0.38742065429687500000f, 0.45590209960937500000f, + 0.50292968750000000000f, 0.55776977539062500000f, + 0.62673950195312500000f, 0.67285156249999989000f, + 0.73080444335937489000f, 0.79238891601562500000f, + 0.86102294921875000000f, 0.91418457031250000000f, + 0.08456420898437500000f, 0.10089111328124999000f, + 0.13580322265625000000f, 0.16967773437500000000f, + 0.19692993164062497000f, 0.28970336914062500000f, + 0.41345214843750000000f, 0.45025634765625006000f, + 0.51095581054687500000f, 0.56295776367187500000f, + 0.61120605468750000000f, 0.66333007812499989000f, + 0.72467041015625011000f, 0.77371215820312500000f, + 0.82827758789062500000f, 0.88702392578125000000f, + 0.09240722656250000000f, 0.11901855468750001000f, + 0.20193481445312503000f, 0.24087524414062500000f, + 0.28109741210937500000f, 0.31982421875000000000f, + 0.36764526367187500000f, 0.41452026367187494000f, + 0.46331787109375000000f, 0.50848388671875000000f, + 0.56463623046875000000f, 0.61315917968750000000f, + 0.67718505859374989000f, 0.74334716796875000000f, + 0.80267333984375000000f, 0.88369750976562489000f, + 0.06103515624999999300f, 0.07781982421875000000f, + 0.12411499023437500000f, 0.20864868164062503000f, + 0.29382324218750000000f, 0.33575439453125000000f, + 0.38433837890625006000f, 0.43023681640625000000f, + 0.47573852539062500000f, 0.52474975585937500000f, + 0.57003784179687500000f, 0.61337280273437500000f, + 0.65704345703125000000f, 0.70449829101562500000f, + 0.75198364257812500000f, 0.88568115234375000000f, + 0.08679199218749998600f, 0.10076904296875000000f, + 0.15573120117187500000f, 0.18637084960937500000f, + 0.21090698242187500000f, 0.26239013671875000000f, + 0.37890625000000000000f, 0.42889404296875000000f, + 0.48907470703125000000f, 0.56661987304687500000f, + 0.63085937500000000000f, 0.67962646484375000000f, + 0.73095703125000000000f, 0.78646850585937500000f, + 0.84405517578125000000f, 0.91632080078125000000f, + 0.12338256835937500000f, 0.15716552734375000000f, + 0.22180175781250000000f, 0.27636718750000000000f, + 0.33312988281250000000f, 0.38568115234375006000f, + 0.44381713867187500000f, 0.49389648437500000000f, + 0.54772949218750000000f, 0.60092163085937500000f, + 0.65176391601562500000f, 0.70132446289062500000f, + 0.75759887695312500000f, 0.81149291992187500000f, + 0.86911010742187500000f, 0.92263793945312500000f, + 0.06436157226562500000f, 0.08010864257812500000f, + 0.13183593750000000000f, 0.16860961914062500000f, + 0.22747802734375000000f, 0.31188964843750000000f, + 0.39611816406250006000f, 0.44854736328125000000f, + 0.53793334960937500000f, 0.58786010742187500000f, + 0.62515258789062500000f, 0.68301391601562500000f, + 0.74093627929687500000f, 0.78665161132812500000f, + 0.84982299804687500000f, 0.92950439453125000000f, + 0.04730224609375000000f, 0.08139038085937501400f, + 0.19754028320312500000f, 0.28979492187500000000f, + 0.33523559570312500000f, 0.37695312500000000000f, + 0.42098999023437500000f, 0.46487426757812500000f, + 0.52182006835937500000f, 0.56890869140625000000f, + 0.62442016601562500000f, 0.67492675781250000000f, + 0.73843383789062489000f, 0.80233764648437500000f, + 0.86679077148437500000f, 0.91955566406250000000f, + 0.07357788085937500000f, 0.09411621093750000000f, + 0.12649536132812500000f, 0.16461181640625000000f, + 0.19430541992187500000f, 0.24884033203124997000f, + 0.40054321289062500000f, 0.48977661132812500000f, + 0.53591918945312500000f, 0.58364868164062500000f, + 0.64874267578125000000f, 0.69464111328125000000f, + 0.74642944335937500000f, 0.80313110351562500000f, + 0.86227416992187500000f, 0.90643310546875000000f, + 0.12692260742187500000f, 0.13781738281250000000f, + 0.18176269531250000000f, 0.23300170898437500000f, + 0.25189208984375000000f, 0.27404785156250000000f, + 0.34204101562500000000f, 0.43130493164062500000f, + 0.49468994140624994000f, 0.54550170898437500000f, + 0.61633300781250000000f, 0.66723632812500011000f, + 0.72753906250000000000f, 0.78573608398437511000f, + 0.85626220703125000000f, 0.91589355468750000000f, + 0.06182861328125000000f, 0.07418823242187500000f, + 0.08682250976562500000f, 0.11041259765625000000f, + 0.24261474609375000000f, 0.29913330078125000000f, + 0.38821411132812500000f, 0.44128417968750000000f, + 0.50585937500000000000f, 0.57934570312500000000f, + 0.65234375000000000000f, 0.71163940429687500000f, + 0.76174926757812500000f, 0.81536865234375000000f, + 0.88412475585937500000f, 0.93505859375000000000f, + 0.10464477539062500000f, 0.11697387695312500000f, + 0.13647460937500000000f, 0.14990234375000000000f, + 0.23568725585937500000f, 0.31695556640625000000f, + 0.39614868164062500000f, 0.46759033203125000000f, + 0.50961303710937500000f, 0.57394409179687500000f, + 0.63409423828125000000f, 0.68820190429687511000f, + 0.75155639648437500000f, 0.80853271484375000000f, + 0.86468505859375000000f, 0.93023681640625000000f, + 0.14465332031250000000f, 0.15774536132812500000f, + 0.17687988281250003000f, 0.19790649414062503000f, + 0.21356201171874997000f, 0.26947021484375000000f, + 0.35940551757812500000f, 0.43988037109375000000f, + 0.51364135742187500000f, 0.56192016601562500000f, + 0.63442993164062500000f, 0.68264770507812489000f, + 0.73962402343750000000f, 0.78842163085937511000f, + 0.84860229492187500000f, 0.91616821289062500000f, + 0.00457763671875000000f, 0.00512695312500000000f, + -0.00051879882812500000f, -0.00326538085937500000f, + -0.00433349609375000000f, -0.00698852539062499910f, + -0.00976562500000000000f, -0.01239013671875000000f, + -0.01535034179687500000f, -0.01892089843750000000f, + -0.02645874023437500000f, -0.02853393554687500000f, + -0.02752685546875000000f, -0.02075195312500000000f, + -0.01214599609375000000f, -0.00347900390625000000f, + -0.01214599609375000000f, -0.01083374023437500000f, + 0.00149536132812500000f, 0.00778198242187500000f, + 0.00347900390625000000f, 0.00793457031250000000f, + 0.01217651367187500000f, 0.00805664062500000000f, + 0.00967407226562500000f, 0.01315307617187500000f, + 0.01568603515625000000f, 0.01620483398437500000f, + 0.01327514648437500000f, 0.01086425781250000000f, + 0.00726318359375000000f, 0.00323486328125000000f, + -0.00131225585937500000f, -0.00109863281250000000f, + -0.00515747070312500000f, -0.00683593750000000000f, + -0.01193237304687500000f, -0.01931762695312500000f, + -0.02368164062500000000f, -0.02960205078125000000f, + -0.02575683593750000000f, -0.01388549804687500000f, + -0.00552368164062500000f, -0.00036621093750000000f, + 0.00259399414062500000f, 0.00259399414062500000f, + 0.00500488281250000000f, 0.00595092773437500000f, + 0.00372314453125000000f, 0.00259399414062500000f, + -0.00482177734375000000f, -0.01953125000000000000f, + -0.02755737304687500000f, 0.00027465820312500000f, + 0.00021362304687500000f, -0.00378417968750000000f, + 0.00454711914062500000f, 0.00097656250000000000f, + 0.00671386718750000000f, 0.01126098632812500000f, + 0.00738525390625000000f, 0.00350952148437500040f, + 0.00241088867187500000f, 0.00256347656250000000f, + -0.00445556640625000000f, -0.00659179687500000000f, + -0.00213623046875000000f, 0.03125000000000000000f, + 0.02291870117187500000f, 0.01751708984375000000f, + 0.01342773437500000000f, 0.01150512695312500000f, + 0.01074218749999999800f, 0.00619506835937500000f, + 0.00091552734374999989f, 0.00048828125000000000f, + -0.00009155273437500000f, 0.00247192382812500000f, + 0.00491333007812500000f, 0.00305175781250000000f, + -0.00451660156250000000f, -0.00537109374999999910f, + 0.02847290039062500000f, 0.02288818359375000000f, + 0.01232910156250000000f, 0.00521850585937500000f, + -0.00006103515625000000f, -0.00445556640625000000f, + -0.01254272460937500000f, -0.01348876953125000000f, + -0.01651000976562500000f, -0.01684570312500000000f, + -0.01348876953125000000f, -0.00820922851562500000f, + -0.00732421874999999910f, -0.00158691406250000020f, + 0.01840209960937500000f, 0.01937866210937500000f, + 0.01235961914062499800f, 0.00543212890625000000f, + 0.00656127929687500000f, 0.00057983398437500000f, + -0.00466918945312500000f, -0.00509643554687500000f, + -0.00885009765625000000f, -0.00668334960937500090f, + 0.00460815429687500000f, 0.00827026367187500000f, + 0.00460815429687500000f, 0.00363159179687500000f, + 0.00924682617187500000f, 0.00811767578125000000f, + 0.00305175781250000000f, 0.00210571289062500000f, + -0.00894165039062500000f, -0.02005004882812500000f, + 0.02865600585937500000f, 0.02011108398437500000f, + 0.01348876953125000000f, 0.01071166992187500000f, + 0.00402832031250000000f, 0.00299072265625000000f, + -0.00048828125000000000f, -0.00003051757812500000f, + -0.00411987304687500000f, -0.00610351562500000000f, + -0.00680541992187500000f, -0.00271606445312500000f, + 0.00509643554687500000f, 0.00469970703125000000f, + 0.00524902343750000000f, 0.00723266601562500000f, + -0.00137329101562500000f, -0.00558471679687500000f, + -0.00695800781250000000f, -0.01483154296875000000f, + 0.00802612304687500000f, 0.01855468750000000000f, + 0.00482177734375000000f, -0.00381469726562499960f, + -0.01190185546875000000f, -0.00692749023437500000f, + -0.00360107421875000000f, 0.00131225585937500000f, + -0.01394653320312500000f, -0.01196289062500000000f, + -0.02346801757812500000f, -0.02563476562500000000f, + 0.00061035156250000000f, -0.00357055664062500000f, + -0.00592041015625000000f, -0.00576782226562500000f, + -0.00527954101562500000f, -0.00527954101562500000f, + -0.00100708007812500000f, 0.00097656250000000000f, + 0.00531005859375000000f, 0.00439453125000000000f, + 0.00350952148437500040f, 0.00509643554687500000f, + 0.00173950195312500000f, 0.00134277343749999980f, + 0.00042724609375000000f, 0.00448608398437500000f, + 0.00292968750000000000f, -0.00164794921875000000f, + -0.00433349609375000000f, -0.00393676757812500000f, + -0.00775146484375000000f, -0.01010131835937500000f, + 0.00927734375000000000f, 0.00946044921875000000f, + -0.00158691406250000020f, -0.01278686523437500000f, + -0.02581787109375000000f, -0.03234863281250000000f, + -0.00268554687499999960f, -0.00375366210937500000f, + -0.00616455078125000000f, -0.01046752929687500200f, + -0.01690673828125000000f, -0.02932739257812500000f, + -0.02902221679687500000f, 0.00997924804687500000f, + 0.00485229492187500000f, 0.00247192382812500000f, + 0.00778198242187500000f, 0.00692749023437500000f, + 0.00366210937499999960f, 0.00619506835937500000f, + 0.00781250000000000000f, 0.00585937500000000000f, + 0.00500488281250000000f, 0.00683593750000000000f, + 0.00885009765625000000f, 0.00595092773437500000f, + 0.00659179687500000000f, 0.00637817382812500090f, + 0.00390625000000000000f, 0.02539062500000000300f, + 0.03137207031250000000f, 0.02713012695312500000f, + 0.02130126953125000000f, 0.01538085937500000000f, + 0.01245117187500000000f, 0.01083374023437500000f, + 0.00665283203124999910f, 0.00097656250000000000f, + -0.00350952148437500040f, -0.00256347656250000000f, + -0.00842285156250000000f, -0.00305175781250000000f, + -0.00952148437500000000f, -0.01477050781250000000f, + 0.02743530273437500000f, 0.02081298828124999700f, + 0.01419067382812500000f, 0.01391601562500000000f, + 0.00735473632812500090f, -0.00036621093750000000f, + -0.00839233398437500000f, -0.01296997070312499800f, + -0.01406860351562500000f, -0.01119995117187500000f, + -0.00100708007812500000f, -0.00085449218750000000f, + -0.00311279296875000000f, -0.00592041015625000000f, + -0.01608276367187500000f, 0.02633666992187500000f, + 0.02764892578125000000f, 0.01412963867187500000f, + 0.00747680664062500000f, 0.00039672851562500005f, + -0.00646972656250000000f, -0.00930786132812500000f, + -0.00320434570312500000f, 0.00497436523437500000f, + 0.00851440429687500000f, 0.00537109374999999910f, + 0.00283813476562499960f, 0.00204467773437500000f, + 0.00350952148437500040f, 0.00585937500000000000f, + 0.00186157226562500000f, -0.00152587890625000000f, + -0.00402832031250000000f, -0.00534057617187499910f, + -0.00683593750000000000f, -0.00827026367187500000f, + -0.01919555664062500000f, -0.00769042968750000000f, + 0.03533935546875000000f, 0.02966308593750000000f, + 0.01947021484375000000f, 0.00854492187500000000f, + 0.00915527343750000000f, 0.00994873046875000000f, + 0.00436401367187500000f, -0.00463867187500000000f, + -0.00653076171875000000f, -0.00875854492187500000f, + 0.00161743164062500000f, -0.00128173828125000000f, + -0.00720214843750000000f, -0.01074218749999999800f, + -0.01290893554687500000f, -0.00756835937500000000f, + -0.00393676757812500000f, -0.00497436523437500000f, + -0.00543212890625000000f, -0.00363159179687500000f, + 0.00259399414062500000f, 0.00173950195312500000f, + 0.01568603515625000000f, 0.01165771484375000000f, + 0.01141357421875000200f, 0.01226806640625000000f, + 0.01293945312500000000f, 0.01290893554687500000f, + 0.00827026367187500000f, 0.00601196289062499910f, + 0.00296020507812500000f, 0.00122070312500000000f, + 0.00119018554687500000f, -0.00296020507812500000f, + -0.00582885742187500000f, -0.00500488281250000000f, + -0.00701904296875000090f, -0.00781250000000000000f, + -0.01251220703125000000f, 0.01208496093750000200f, + 0.00997924804687500000f, 0.00387573242187500000f, + 0.00030517578125000000f, -0.00363159179687500000f, + -0.00509643554687500000f, -0.00888061523437500000f, + -0.00836181640625000000f, -0.00430297851562500000f, + -0.00302124023437500040f, -0.00689697265625000000f, + -0.00665283203124999910f, -0.00424194335937500000f, + -0.00683593750000000000f, -0.00637817382812500090f, + -0.00817871093750000000f, -0.01348876953125000000f, + -0.01260375976562500000f, 0.00677490234375000000f, + 0.00177001953125000000f, 0.01589965820312500000f, + 0.01049804687500000000f, 0.00787353515625000000f, + 0.00231933593750000000f, -0.00128173828125000000f, + -0.00433349609375000000f, -0.00503540039062499910f, + -0.00375366210937500000f, -0.00280761718750000000f, + 0.00143432617187500000f, 0.00024414062500000000f, + -0.00009155273437500000f, -0.00582885742187500000f, + -0.00033569335937499995f, -0.00500488281250000000f, + -0.00509643554687500000f, -0.01071166992187500000f, + -0.02258300781250000000f, 0.00949096679687500000f, + 0.01641845703125000000f, 0.00888061523437500000f, + 0.00561523437500000000f, 0.00088500976562500000f, + -0.00320434570312500000f, 0.00027465820312500000f, + -0.00091552734374999989f, -0.00164794921875000000f, + -0.00051879882812500000f, -0.00234985351562500000f, + -0.00827026367187500000f, -0.01257324218750000000f, + -0.01898193359375000000f, -0.01977539062500000000f, + 0.01452636718750000000f, 0.00567626953124999910f, + -0.00201416015625000000f, -0.00601196289062499910f, + -0.00222778320312500000f, -0.00286865234375000000f, + -0.00045776367187499995f, 0.00143432617187500000f, + 0.00085449218750000000f, 0.00341796875000000000f, + -0.00177001953125000000f, -0.00100708007812500000f, + 0.00198364257812500000f, 0.00057983398437500000f, + 0.00256347656250000000f, 0.00262451171875000000f, + 0.00842285156250000000f, 0.00347900390625000000f, + 0.01440429687500000000f, 0.02398681640625000000f, + 0.02438354492187499700f, 0.01907348632812500000f, + 0.01266479492187500000f, 0.00543212890625000000f, + -0.00106811523437500000f, -0.00079345703125000011f, + 0.00015258789062500000f, 0.00027465820312500000f, + 0.00253295898437500040f, 0.00119018554687500000f, + 0.00112915039062500000f, 0.00119018554687500000f, + -0.00561523437500000000f, -0.01141357421875000200f, + -0.00808715820312500000f, -0.01104736328125000000f, + -0.01528930664062500000f, 0.01028442382812500000f, + 0.02185058593750000000f, 0.01458740234374999800f, + -0.00183105468749999980f, -0.00381469726562499960f, + -0.00497436523437500000f, 0.01104736328125000000f, + 0.00051879882812500000f, -0.00372314453125000000f, + -0.00711059570312500000f, 0.00851440429687500000f, + 0.00421142578125000000f, 0.00479125976562500000f, + 0.00970458984375000000f, 0.00588989257812500000f, + 0.00576782226562500000f, 0.00637817382812500090f, + 0.00811767578125000000f, 0.00769042968750000000f, + -0.00140380859375000000f, -0.00170898437500000000f, + -0.00845336914062500000f, -0.01309204101562500000f, + 0.01416015625000000000f, 0.01177978515625000000f, + 0.00433349609375000000f, 0.00134277343749999980f, + -0.00131225585937500000f, 0.00201416015625000000f, + 0.00805664062500000000f, 0.00555419921875000000f, + 0.00143432617187500000f, 0.00042724609375000000f, + -0.00079345703125000011f, -0.00241088867187500000f, + 0.00149536132812500000f, 0.00045776367187499995f, + -0.00390625000000000000f, -0.00619506835937500000f, + -0.01220703125000000000f, -0.01458740234374999800f, + 0.00991821289062500000f, 0.00082397460937500000f, + 0.00714111328125000000f, 0.01254272460937500000f, + 0.00625610351562500000f, 0.00393676757812500000f, + 0.00036621093750000000f, 0.00177001953125000000f, + 0.00375366210937500000f, 0.00173950195312500000f, + 0.00521850585937500000f, 0.00418090820312500000f, + 0.00292968750000000000f, 0.00390625000000000000f, + -0.00097656250000000000f, 0.00408935546875000000f, + -0.00036621093750000000f, 0.00173950195312500000f, + 0.00363159179687500000f, 0.00079345703125000011f, + -0.00067138671874999989f, -0.00503540039062499910f, + -0.01525878906249999800f, -0.02139282226562500000f, + -0.01611328125000000000f, -0.00354003906250000000f, + 0.00195312500000000000f, -0.00024414062500000000f, + 0.00296020507812500000f, -0.00027465820312500000f, + -0.00494384765625000000f, -0.00201416015625000000f, + -0.00476074218750000000f, -0.00592041015625000000f, + -0.00924682617187500000f, -0.01666259765625000000f, + -0.01040649414062499800f, 0.01666259765625000000f, + 0.01092529296875000000f, 0.00289916992187500000f, + 0.00137329101562500000f, 0.00231933593750000000f, + 0.00823974609375000000f, 0.01229858398437500000f, + 0.00625610351562500000f, 0.00305175781250000000f, + 0.00375366210937500000f, 0.00152587890625000000f, + -0.00161743164062500000f, -0.00439453125000000000f, + -0.00335693359375000000f, -0.00039672851562500005f, + 0.00097656250000000000f, -0.00695800781250000000f, + -0.00396728515625000000f, 0.01077270507812500000f, + 0.00903320312500000000f, 0.00170898437500000000f, + -0.01135253906249999800f, -0.00772094726562500000f, + 0.01113891601562500000f, 0.00222778320312500000f, + 0.00030517578125000000f, -0.00103759765625000000f, + -0.00424194335937500000f, -0.00582885742187500000f, + -0.00292968750000000000f, 0.00015258789062500000f, + 0.00134277343749999980f, -0.00259399414062500000f, + -0.00546264648437500000f, -0.00393676757812500000f, + -0.00585937500000000000f, -0.00750732421875000000f, + -0.00259399414062500000f, -0.00335693359375000000f, + -0.00473022460937500000f, -0.00134277343749999980f, + -0.00082397460937500000f, 0.00442504882812500000f, + 0.00421142578125000000f, 0.00241088867187500000f, + 0.00097656250000000000f, -0.00451660156250000000f, + -0.01760864257812500000f, -0.01934814453125000000f, + 0.00582885742187500000f, 0.00286865234375000000f, + -0.00027465820312500000f, -0.00106811523437500000f, + -0.00234985351562500000f, -0.00256347656250000000f, + -0.00170898437500000000f, -0.00521850585937500000f, + -0.00909423828125000000f, -0.00827026367187500000f, + -0.00741577148437500000f, -0.00476074218750000000f, + -0.01000976562500000000f, -0.00717163085937500000f, + -0.00231933593750000000f, -0.00390625000000000000f, + -0.00369262695312500000f, 0.00393676757812500000f, + 0.00039672851562500005f, -0.00067138671874999989f, + 0.00097656250000000000f, 0.00137329101562500000f, + -0.00756835937500000000f, -0.00198364257812500000f, + 0.00588989257812500000f, -0.00247192382812500000f, + 0.00912475585937500000f, 0.00173950195312500000f, + -0.00448608398437500000f, 0.00585937500000000000f, + -0.00503540039062499910f, -0.01080322265625000200f, + -0.01019287109375000000f, -0.00323486328125000000f, + -0.00476074218750000000f, -0.00122070312500000000f, + -0.00009155273437500000f, -0.00207519531250000000f, + 0.00378417968750000000f, -0.00784301757812500000f, + 0.00238037109375000000f, 0.00378417968750000000f, + 0.00518798828125000000f, 0.01257324218750000000f, + 0.00692749023437500000f, 0.00320434570312500000f, + -0.00317382812500000040f, 0.00036621093750000000f, + 0.00469970703125000000f, 0.00762939453124999910f, + 0.00836181640625000000f, 0.00787353515625000000f, + 0.00012207031250000000f, -0.00082397460937500000f, + 0.00717163085937500000f, 0.00463867187500000000f, + 0.00155639648437500000f, 0.01031494140625000000f, + 0.00915527343750000000f, 0.00021362304687500000f, + -0.00958251953125000000f, -0.01254272460937500000f, + 0.00656127929687500000f, 0.00518798828125000000f, + -0.00027465820312500000f, -0.00283813476562499960f, + -0.00234985351562500000f, 0.00231933593750000000f, + 0.00204467773437500000f, 0.00164794921875000000f, + 0.00610351562500000000f, 0.00961303710937500000f, + 0.00497436523437500000f, 0.00219726562500000000f, + -0.00277709960937500000f, -0.01226806640625000000f, + 0.00482177734375000000f, 0.00570678710937500090f, + -0.00476074218750000000f, -0.00277709960937500000f, + 0.00885009765625000000f, 0.00814819335937500000f, + 0.00509643554687500000f, 0.00277709960937500000f, + 0.00427246093750000000f, 0.00521850585937500000f, + 0.00341796875000000000f, 0.00027465820312500000f, + -0.00128173828125000000f, -0.00540161132812500090f, + -0.01342773437500000000f, 0.01174926757812500200f, + 0.00244140625000000000f, 0.00045776367187499995f, + 0.00524902343750000000f, 0.00393676757812500000f, + 0.00125122070312500000f, -0.00393676757812500000f, + -0.01135253906249999800f, -0.00073242187500000000f, + -0.00228881835937500000f, -0.00091552734374999989f, + -0.00518798828125000000f, 0.00030517578125000000f, + -0.00360107421875000000f, 0.00173950195312500000f, + 0.00238037109375000000f, -0.00308227539062500000f, + 0.00708007812500000000f, 0.00491333007812500000f, + 0.00375366210937500000f, 0.00781250000000000000f, + 0.00845336914062500000f, 0.00308227539062500000f, + -0.00585937500000000000f, -0.01919555664062500000f, + -0.00305175781250000000f, -0.00183105468749999980f, + -0.00708007812500000000f, 0.00201416015625000000f, + 0.00039672851562500005f, -0.00039672851562500005f, + -0.00244140625000000000f, -0.00729370117187499910f, + 0.00729370117187499910f, 0.00112915039062500000f, + 0.00097656250000000000f, 0.00271606445312500000f, + -0.00973510742187500000f, -0.01766967773437500000f, + 0.01373291015625000000f, 0.01098632812500000000f, + 0.00009155273437500000f, -0.00088500976562500000f, + -0.00912475585937500000f, -0.00271606445312500000f, + -0.00164794921875000000f, -0.00335693359375000000f, + -0.00750732421875000000f, -0.00500488281250000000f, + 0.00018310546875000000f, -0.00573730468750000000f, + 0.01031494140625000000f, 0.00537109374999999910f, + -0.00280761718750000000f, 0.00601196289062499910f, + 0.00418090820312500000f, 0.00408935546875000000f, + 0.00036621093750000000f, -0.00006103515625000000f, + 0.00170898437500000000f, -0.00558471679687500000f, + 0.00347900390625000000f, -0.00109863281250000000f, + -0.00399780273437500000f, -0.00622558593750000000f, + 0.00228881835937500000f, -0.00076293945312500000f, + -0.00531005859375000000f, 0.00582885742187500000f, + -0.00045776367187499995f, -0.00885009765625000000f, + -0.01309204101562500000f, -0.00814819335937500000f, + 0.00241088867187500000f, 0.00112915039062500000f, + 0.00323486328125000000f, 0.00070190429687500000f, + -0.01171875000000000000f, 0.01296997070312499800f, + 0.00213623046875000000f, -0.00042724609375000000f, + 0.00646972656250000000f, 0.00320434570312500000f, + 0.00045776367187499995f, -0.00006103515625000000f, + -0.00128173828125000000f, -0.00112915039062500000f, + -0.00375366210937500000f, 0.00329589843750000000f, + 0.00085449218750000000f, -0.00146484375000000000f, + 0.00588989257812500000f, 0.00601196289062499910f, + 0.00527954101562500000f, -0.00100708007812500000f, + 0.00112915039062500000f, 0.00222778320312500000f, + -0.00173950195312500000f, 0.00781250000000000000f, + 0.00418090820312500000f, -0.00177001953125000000f, + -0.01312255859375000000f, -0.00695800781250000000f, + 0.00662231445312500000f, -0.00155639648437500000f, + -0.00030517578125000000f, -0.00177001953125000000f, + -0.00018310546875000000f, 0.00067138671874999989f, + 0.00317382812500000040f, 0.00186157226562500000f, + -0.00363159179687500000f, 0.00515747070312500000f, + 0.00439453125000000000f, 0.00048828125000000000f, + -0.00140380859375000000f, -0.01202392578124999800f, + 0.00183105468749999980f, 0.01385498046875000000f, + -0.00244140625000000000f, -0.00909423828125000000f, + -0.00198364257812500000f, 0.00076293945312500000f, + 0.00000000000000000000f, -0.00073242187500000000f, + -0.00198364257812500000f, -0.01272583007812500000f, + 0.01419067382812500000f, 0.00842285156250000000f, + -0.00009155273437500000f, -0.00592041015625000000f, + -0.00039672851562500005f, 0.00396728515625000000f, + 0.00057983398437500000f, -0.00018310546875000000f, + -0.00064086914062500000f, -0.00073242187500000000f, + -0.00549316406250000000f, -0.00161743164062500000f, + -0.00259399414062500000f, 0.00061035156250000000f, + 0.00360107421875000000f, 0.00448608398437500000f, + 0.00344848632812500000f, -0.00228881835937500000f, + -0.00881958007812500000f, 0.00689697265625000000f, + -0.00372314453125000000f, 0.00692749023437500000f, + 0.00823974609375000000f, 0.00381469726562499960f, + 0.00332641601562499960f, 0.00601196289062499910f, + 0.00381469726562499960f, 0.00421142578125000000f, + 0.00134277343749999980f, 0.00183105468749999980f, + 0.00076293945312500000f, -0.00167846679687500000f, + -0.00509643554687500000f, -0.00097656250000000000f, + -0.00424194335937500000f, -0.00588989257812500000f, + -0.00527954101562500000f, -0.00964355468750000000f, + 0.00875854492187500000f, -0.00634765625000000090f, + 0.00772094726562500000f, 0.00729370117187499910f, + 0.00082397460937500000f, -0.00244140625000000000f, + -0.00573730468750000000f, -0.00085449218750000000f, + -0.00555419921875000000f, -0.00717163085937500000f, + 0.00476074218750000000f, -0.00357055664062500000f, + 0.00390625000000000000f, -0.00146484375000000000f, + -0.00177001953125000000f, -0.00689697265625000000f, + 0.00524902343750000000f, 0.00552368164062500000f, + 0.00509643554687500000f, 0.00057983398437500000f, + 0.00189208984375000000f, 0.00030517578125000000f, + 0.00006103515625000000f, 0.00552368164062500000f, + 0.00460815429687500000f, 0.00329589843750000000f, + -0.00048828125000000000f, -0.00033569335937499995f, + -0.00238037109375000000f, -0.01010131835937500000f, + 0.01254272460937500000f, 0.00405883789062500000f, + 0.00051879882812500000f, 0.00317382812500000040f, + 0.00195312500000000000f, -0.00561523437500000000f, + 0.00073242187500000000f, -0.00091552734374999989f, + -0.00009155273437500000f, -0.00863647460937500000f, + 0.00369262695312500000f, 0.00622558593750000000f, + -0.00024414062500000000f, -0.00607299804687500000f, + -0.00064086914062500000f, -0.00244140625000000000f, + -0.00515747070312500000f, -0.00479125976562500000f, + -0.00582885742187500000f, -0.00415039062500000000f, + 0.00247192382812500000f, 0.00473022460937500000f, + 0.00042724609375000000f, -0.00399780273437500000f, + 0.00744628906250000000f, 0.00225830078125000000f, + -0.00173950195312500000f, -0.00143432617187500000f, + -0.00854492187500000000f, 0.01058959960937500000f, + 0.00338745117187500000f, -0.00234985351562500000f, + -0.00390625000000000000f, -0.00433349609375000000f, + -0.00592041015625000000f, -0.00381469726562499960f, + -0.00018310546875000000f, -0.00207519531250000000f, + 0.00277709960937500000f, 0.00003051757812500000f, + 0.00070190429687500000f, 0.00042724609375000000f, + -0.00469970703125000000f, -0.00103759765625000000f, + 0.00070190429687500000f, -0.00115966796875000000f, + -0.01046752929687500200f, 0.01535034179687500000f, + 0.00445556640625000000f, -0.00115966796875000000f, + -0.00140380859375000000f, -0.00125122070312500000f, + 0.00177001953125000000f, 0.00094604492187500000f, + 0.00192260742187500000f, -0.00146484375000000000f, + -0.00357055664062500000f, 0.00137329101562500000f, + 0.00085449218750000000f, 0.00003051757812500000f, + -0.00271606445312500000f, -0.00015258789062500000f, + -0.00134277343749999980f, -0.00088500976562500000f, + -0.01367187500000000000f, 0.01486206054687500000f, + 0.00622558593750000000f, 0.00247192382812500000f, + 0.00140380859375000000f, -0.00323486328125000000f, + -0.00921630859375000000f, 0.01159667968750000000f, + 0.00366210937499999960f, -0.00115966796875000000f, + -0.00036621093750000000f, -0.00119018554687500000f, + 0.00213623046875000000f, -0.00009155273437500000f, + 0.00076293945312500000f, -0.00198364257812500000f, + 0.00091552734374999989f, -0.00033569335937499995f, + 0.00103759765625000000f, -0.00045776367187499995f, + 0.00067138671874999989f, -0.00350952148437500040f, + 0.00000000000000000000f, -0.00241088867187500000f, + -0.00253295898437500040f, 0.00137329101562500000f, + 0.00347900390625000000f, 0.00131225585937500000f, + 0.00457763671875000000f, 0.00109863281250000000f, + 0.00711059570312500000f, 0.00454711914062500000f, + 0.00595092773437500000f, 0.00015258789062500000f, + 0.00076293945312500000f, -0.00158691406250000020f, + -0.01449584960937500000f, 0.00836181640625000000f, + 0.00085449218750000000f, -0.00119018554687500000f, + -0.00024414062500000000f, -0.00201416015625000000f, + -0.00778198242187500000f, 0.00787353515625000000f, + 0.00170898437500000000f, 0.00436401367187500000f, + -0.00137329101562500000f, -0.00579833984375000000f, + 0.00503540039062499910f, -0.00183105468749999980f, + 0.00061035156250000000f, 0.00006103515625000000f, + 0.00381469726562499960f, -0.00393676757812500000f, + 0.00155639648437500000f, -0.00024414062500000000f, + -0.01022338867187500000f, 0.00878906250000000000f, + 0.00115966796875000000f, 0.00180053710937500000f, + 0.00076293945312500000f, -0.00128173828125000000f, + 0.00070190429687500000f, -0.00360107421875000000f, + -0.00341796875000000000f, 0.00033569335937499995f, + -0.00167846679687500000f, -0.00405883789062500000f, + -0.00332641601562499960f, 0.00073242187500000000f, + -0.00320434570312500000f, 0.00238037109375000000f, + -0.00195312500000000000f, -0.00747680664062500000f, + 0.00616455078125000000f, -0.00198364257812500000f, + -0.00387573242187500000f, 0.00494384765625000000f, + 0.00122070312500000000f, -0.00286865234375000000f, + 0.00271606445312500000f, -0.00259399414062500000f, + -0.00363159179687500000f, -0.00314331054687500000f, + 0.00296020507812500000f, 0.00027465820312500000f, + -0.00213623046875000000f, -0.00085449218750000000f, + 0.00592041015625000000f, 0.00262451171875000000f, + -0.00341796875000000000f, -0.00280761718750000000f, + -0.00347900390625000000f, 0.00225830078125000000f, + -0.00149536132812500000f, 0.00140380859375000000f, + -0.00256347656250000000f, -0.00543212890625000000f, + 0.00344848632812500000f, 0.00158691406250000020f, + -0.00625610351562500000f, 0.01016235351562500000f, + 0.00268554687499999960f, 0.00677490234375000000f, + 0.00170898437500000000f, -0.00167846679687500000f, + 0.00039672851562500005f, 0.00262451171875000000f, + 0.00012207031250000000f, -0.00234985351562500000f, + 0.00683593750000000000f, 0.00347900390625000000f, + -0.00320434570312500000f, 0.00341796875000000000f, + 0.00381469726562499960f, -0.00088500976562500000f, + -0.00054931640625000000f, -0.00439453125000000000f, + 0.00067138671874999989f, -0.00177001953125000000f, + -0.00302124023437500040f, 0.00085449218750000000f, + 0.00347900390625000000f, -0.00201416015625000000f, + -0.00097656250000000000f, -0.00515747070312500000f, + -0.00958251953125000000f, 0.00869750976562500000f, + 0.00219726562500000000f, -0.00225830078125000000f, + 0.00546264648437500000f, 0.00085449218750000000f, + -0.00241088867187500000f, -0.00555419921875000000f, + 0.00039672851562500005f, -0.00167846679687500000f, + 0.00448608398437500000f, 0.00039672851562500005f, + 0.00036621093750000000f, -0.00164794921875000000f, + 0.00094604492187500000f, -0.00256347656250000000f, + -0.00051879882812500000f, -0.00228881835937500000f, + -0.00695800781250000000f, 0.00253295898437500040f, + -0.01144409179687500000f, 0.01330566406249999800f, + 0.00335693359375000000f, -0.00192260742187500000f, + -0.00082397460937500000f, -0.00415039062500000000f, + 0.00515747070312500000f, -0.00170898437500000000f, + -0.00024414062500000000f, -0.00521850585937500000f, + 0.00561523437500000000f, -0.00128173828125000000f, + 0.00451660156250000000f, 0.00207519531250000000f, + 0.00622558593750000000f, 0.00717163085937500000f, + 0.00335693359375000000f, -0.00698852539062499910f, + 0.00277709960937500000f, 0.00521850585937500000f, + -0.00131225585937500000f, -0.00009155273437500000f, + -0.00079345703125000011f, -0.00302124023437500040f, + -0.00338745117187500000f, 0.00216674804687500000f, + -0.00518798828125000000f, 0.00616455078125000000f, + -0.00204467773437500000f, 0.00552368164062500000f, + -0.00112915039062500000f, 0.00332641601562499960f, + -0.00366210937499999960f, 0.00009155273437500000f, + -0.00167846679687500000f, -0.00793457031250000000f, + -0.00048828125000000000f, 0.00463867187500000000f, + 0.00277709960937500000f, 0.00433349609375000000f, + 0.00128173828125000000f, 0.00134277343749999980f, + 0.00408935546875000000f, 0.00143432617187500000f, + 0.00051879882812500000f, -0.00106811523437500000f, + 0.00067138671874999989f, 0.00241088867187500000f, + -0.00515747070312500000f, 0.00125122070312500000f, + 0.00140380859375000000f, 0.00845336914062500000f, + -0.00283813476562499960f, -0.00149536132812500000f, + -0.00384521484375000000f, 0.00112915039062500000f, + -0.00314331054687500000f, -0.00103759765625000000f, + -0.00067138671874999989f, -0.00274658203125000000f, + -0.00408935546875000000f, -0.00625610351562500000f, + 0.00280761718750000000f, -0.00027465820312500000f, + 0.00003051757812500000f, -0.00595092773437500000f, + -0.00729370117187499910f, 0.00137329101562500000f, + 0.00164794921875000000f, 0.00054931640625000000f, + -0.00070190429687500000f, -0.00003051757812500000f, + -0.00244140625000000000f, -0.00299072265625000000f, + -0.00061035156250000000f, -0.00796508789062500000f, + 0.00933837890625000000f, 0.00219726562500000000f, + 0.00061035156250000000f, -0.00271606445312500000f, + -0.00662231445312500000f, 0.00033569335937499995f, + 0.00018310546875000000f, -0.00250244140625000000f, + 0.00271606445312500000f, 0.00039672851562500005f, + -0.00393676757812500000f, -0.00271606445312500000f, + 0.00253295898437500040f, -0.00216674804687500000f, + -0.00167846679687500000f, 0.00396728515625000000f, + -0.00299072265625000000f, -0.00445556640625000000f, + -0.00082397460937500000f, -0.00173950195312500000f, + 0.00161743164062500000f, 0.00839233398437500000f, + 0.00051879882812500000f, 0.00518798828125000000f, + -0.00015258789062500000f, -0.00164794921875000000f, + 0.00402832031250000000f, -0.00195312500000000000f, + 0.00219726562500000000f, 0.00488281250000000000f, + -0.00381469726562499960f, -0.00512695312500000000f, + 0.00219726562500000000f, 0.00122070312500000000f, + 0.00518798828125000000f, 0.00238037109375000000f, + 0.00756835937500000000f, 0.00354003906250000000f, + 0.00061035156250000000f, 0.00256347656250000000f, + 0.00094604492187500000f, -0.00103759765625000000f, + 0.00579833984375000000f, 0.00115966796875000000f, + 0.00039672851562500005f, -0.00323486328125000000f, + 0.00686645507812500000f, 0.00082397460937500000f, + -0.00512695312500000000f, 0.00073242187500000000f, + -0.00479125976562500000f, -0.00372314453125000000f, + 0.00503540039062499910f, 0.00033569335937499995f, + -0.00491333007812500000f, -0.00650024414062500000f, + -0.00036621093750000000f, -0.00155639648437500000f, + -0.00308227539062500000f, 0.00128173828125000000f, + 0.00308227539062500000f, 0.00082397460937500000f, + 0.00167846679687500000f, 0.00338745117187500000f, + 0.00228881835937500000f, 0.00216674804687500000f, + -0.00292968750000000000f, -0.00003051757812500000f, + 0.00198364257812500000f, -0.00845336914062500000f, + 0.01199340820312500000f, -0.00079345703125000011f, + -0.00134277343749999980f, -0.00207519531250000000f, + -0.00256347656250000000f, -0.00201416015625000000f, + -0.00289916992187500000f, 0.00717163085937500000f, + 0.00546264648437500000f, -0.00076293945312500000f, + -0.00125122070312500000f, 0.00082397460937500000f, + -0.00277709960937500000f, -0.00390625000000000000f, + -0.00677490234375000000f, 0.00445556640625000000f, + -0.00219726562500000000f, -0.00091552734374999989f, + -0.00073242187500000000f, 0.00167846679687500000f, + -0.00384521484375000000f, -0.00207519531250000000f, + -0.00177001953125000000f, -0.00387573242187500000f, + 0.00039672851562500005f, -0.00296020507812500000f, + -0.00323486328125000000f, 0.00531005859375000000f, + -0.00305175781250000000f, 0.00473022460937500000f, + 0.00308227539062500000f, -0.00445556640625000000f, + -0.00064086914062500000f, 0.00796508789062500000f, + 0.00067138671874999989f, 0.00115966796875000000f, + -0.00201416015625000000f, 0.00198364257812500000f, + 0.00012207031250000000f, 0.00213623046875000000f, + 0.00195312500000000000f, 0.00439453125000000000f, + 0.00180053710937500000f, 0.00650024414062500000f, + 0.00216674804687500000f, -0.01028442382812500000f, + 0.00924682617187500000f, -0.00158691406250000020f, + 0.00155639648437500000f, -0.00170898437500000000f, + 0.00003051757812500000f, 0.00030517578125000000f, + -0.00045776367187499995f, -0.00015258789062500000f, + 0.00103759765625000000f, 0.00158691406250000020f, + 0.00695800781250000000f, 0.00399780273437500000f, + 0.00491333007812500000f, -0.00387573242187500000f, + -0.00653076171875000000f, 0.00726318359375000000f, + 0.00375366210937500000f, 0.00195312500000000000f, + -0.00448608398437500000f, -0.00152587890625000000f, + -0.00103759765625000000f, -0.00387573242187500000f, + 0.00622558593750000000f, 0.00494384765625000000f, + 0.00259399414062500000f, 0.00125122070312500000f, + 0.00015258789062500000f, -0.00427246093750000000f, + 0.00222778320312500000f, -0.00457763671875000000f, + 0.00170898437500000000f, -0.00292968750000000000f, + -0.00201416015625000000f, -0.00061035156250000000f, + 0.00006103515625000000f, -0.00717163085937500000f, + 0.00180053710937500000f, -0.00067138671874999989f, + -0.00326538085937500000f, 0.00457763671875000000f, + -0.00048828125000000000f, -0.00143432617187500000f, + -0.00012207031250000000f, 0.00247192382812500000f, + -0.00204467773437500000f, 0.00509643554687500000f, + 0.00454711914062500000f, 0.00454711914062500000f, + -0.00479125976562500000f, 0.00878906250000000000f, + -0.00476074218750000000f, -0.00082397460937500000f, + -0.00024414062500000000f, 0.00054931640625000000f, + 0.00253295898437500040f, -0.00073242187500000000f, + -0.00125122070312500000f, -0.00509643554687500000f, + 0.00482177734375000000f, -0.00305175781250000000f, + 0.00283813476562499960f, 0.00161743164062500000f, + 0.00613403320312500000f, 0.00045776367187499995f, + 0.00128173828125000000f, 0.00811767578125000000f, + 0.00848388671875000000f, -0.00036621093750000000f, + -0.00018310546875000000f, -0.00112915039062500000f, + 0.00259399414062500000f, 0.00018310546875000000f, + 0.00061035156250000000f, -0.00573730468750000000f, + -0.00827026367187500000f, 0.00326538085937500000f, + -0.00039672851562500005f, -0.00244140625000000000f, + 0.00155639648437500000f, 0.00616455078125000000f, + 0.00527954101562500000f, -0.00210571289062500000f, + 0.00238037109375000000f, -0.00573730468750000000f, + 0.00140380859375000000f, 0.00012207031250000000f, + 0.00466918945312500000f, 0.00036621093750000000f, + -0.00421142578125000000f, 0.00515747070312500000f, + 0.00015258789062500000f, -0.00177001953125000000f, + -0.00375366210937500000f, -0.00329589843750000000f, + -0.00741577148437500000f, 0.00457763671875000000f, + 0.00030517578125000000f, -0.00582885742187500000f, + 0.00750732421875000000f, -0.00045776367187499995f, + 0.00115966796875000000f, 0.00076293945312500000f, + -0.00030517578125000000f, 0.00042724609375000000f, + 0.00186157226562500000f, 0.00152587890625000000f, + -0.00628662109375000000f, -0.00656127929687500000f, + -0.00671386718750000000f, 0.00274658203125000000f, + 0.00015258789062500000f, -0.00454711914062500000f, + -0.00668334960937500090f, 0.00170898437500000000f, + 0.00433349609375000000f, 0.00073242187500000000f, + -0.01147460937500000000f, 0.00234985351562500000f, + -0.00244140625000000000f, 0.00228881835937500000f, + 0.00018310546875000000f, 0.00128173828125000000f, + -0.00308227539062500000f, 0.00048828125000000000f, + 0.00170898437500000000f, 0.00042724609375000000f, + -0.00173950195312500000f, 0.00009155273437500000f, + -0.00051879882812500000f, 0.00244140625000000000f, + 0.00173950195312500000f, -0.00109863281250000000f, + 0.00268554687499999960f, -0.00180053710937500000f, + -0.00296020507812500000f, -0.00057983398437500000f, + -0.00451660156250000000f, 0.00140380859375000000f, + -0.00668334960937500090f, 0.00689697265625000000f, + 0.00347900390625000000f, -0.00012207031250000000f, + -0.00219726562500000000f, -0.00045776367187499995f, + 0.00112915039062500000f, -0.00149536132812500000f, + -0.00085449218750000000f, 0.00753784179687500000f, + 0.00134277343749999980f, 0.00375366210937500000f, + 0.00143432617187500000f, -0.00372314453125000000f, + -0.00115966796875000000f, 0.00051879882812500000f, + 0.00012207031250000000f, -0.00344848632812500000f, + -0.00097656250000000000f, -0.00683593750000000000f, + 0.00469970703125000000f, -0.00408935546875000000f, + 0.00598144531250000000f, 0.00216674804687500000f, + -0.00814819335937500000f, -0.00259399414062500000f, + 0.00085449218750000000f, -0.00213623046875000000f, + 0.00271606445312500000f, -0.00366210937499999960f, + 0.00302124023437500040f, -0.00006103515625000000f, + 0.00195312500000000000f, 0.00231933593750000000f, + -0.00506591796875000090f, -0.00146484375000000000f, + 0.00576782226562500000f, -0.00106811523437500000f, + -0.00280761718750000000f, -0.00515747070312500000f, + -0.00375366210937500000f, 0.01034545898437500000f, + 0.00115966796875000000f, -0.00076293945312500000f, + 0.00115966796875000000f, -0.00106811523437500000f, + 0.00686645507812500000f, -0.00424194335937500000f, + -0.00152587890625000000f, -0.00192260742187500000f, + 0.00750732421875000000f, 0.00183105468749999980f, + -0.00564575195312500000f, -0.00332641601562499960f, + -0.00149536132812500000f, -0.00161743164062500000f, + -0.00509643554687500000f, 0.00155639648437500000f, + 0.00454711914062500000f, 0.00183105468749999980f, + -0.00308227539062500000f, -0.00100708007812500000f, + 0.00076293945312500000f, -0.00231933593750000000f, + 0.00366210937499999960f, 0.00097656250000000000f, + -0.00091552734374999989f, -0.00253295898437500040f, + 0.00311279296875000000f, 0.00277709960937500000f, + -0.00567626953124999910f, -0.00796508789062500000f, + 0.00399780273437500000f, -0.00601196289062499910f +}; + +const SKP_Silk_NLSF_CBS_FLP SKP_Silk_NLSF_CB0_16_Stage_info_FLP[ NLSF_MSVQ_CB0_16_STAGES ] = +{ + { 128, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 0 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 0 ] }, + { 16, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 128 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 128 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 144 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 144 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 152 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 152 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 160 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 160 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 168 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 168 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 176 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 176 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 184 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 184 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 192 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 192 ] }, + { 16, &SKP_Silk_NLSF_MSVQ_CB0_16[ 16 * 200 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates[ 200 ] } +}; + +const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB0_16_FLP = +{ + NLSF_MSVQ_CB0_16_STAGES, + SKP_Silk_NLSF_CB0_16_Stage_info_FLP, + SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min, + SKP_Silk_NLSF_MSVQ_CB0_16_CDF, + SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr, + SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx +}; + diff --git a/src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c b/src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c new file mode 100644 index 000000000..5cd706b48 --- /dev/null +++ b/src_FLP/SKP_Silk_tables_NLSF_CB1_10_FLP.c @@ -0,0 +1,475 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/**********************************************/ +/* This file has been automatically generated */ +/* */ +/* ROM usage: 3.21 kB */ +/**********************************************/ + +#include "SKP_Silk_tables_FLP.h" +#include "SKP_Silk_tables_NLSF_CB1_10.h" + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_10_rates[ NLSF_MSVQ_CB1_10_VECTORS ] = +{ + 1.93750000000000000000f, 3.21875000000000000000f, + 3.75000000000000000000f, 3.96875000000000000000f, + 4.21875000000000000000f, 4.21875000000000000000f, + 4.84375000000000000000f, 5.21875000000000000000f, + 5.25000000000000000000f, 5.37500000000000000000f, + 5.40625000000000000000f, 5.50000000000000000000f, + 5.59375000000000000000f, 5.65625000000000000000f, + 5.65625000000000000000f, 5.78125000000000000000f, + 5.81250000000000000000f, 6.18750000000000000000f, + 6.21875000000000000000f, 6.34375000000000000000f, + 6.40625000000000000000f, 6.93750000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 1.68750000000000000000f, 2.37500000000000000000f, + 3.15625000000000000000f, 3.37500000000000000000f, + 3.71875000000000000000f, 3.75000000000000000000f, + 3.84375000000000000000f, 3.90625000000000000000f, + 2.12500000000000000000f, 2.65625000000000000000f, + 2.71875000000000000000f, 3.21875000000000000000f, + 3.34375000000000000000f, 3.50000000000000000000f, + 3.59375000000000000000f, 3.62500000000000000000f, + 2.43750000000000000000f, 2.65625000000000000000f, + 2.65625000000000000000f, 3.15625000000000000000f, + 3.28125000000000000000f, 3.28125000000000000000f, + 3.43750000000000000000f, 3.46875000000000000000f, + 2.59375000000000000000f, 2.84375000000000000000f, + 3.03125000000000000000f, 3.03125000000000000000f, + 3.03125000000000000000f, 3.12500000000000000000f, + 3.15625000000000000000f, 3.28125000000000000000f, + 2.87500000000000000000f, 2.90625000000000000000f, + 2.90625000000000000000f, 2.96875000000000000000f, + 3.00000000000000000000f, 3.06250000000000000000f, + 3.09375000000000000000f, 3.21875000000000000000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min[ 10 + 1 ] = +{ + 0.01409912109375000000f, + 0.00009155273437500000f, + 0.00195312500000000000f, + 0.00225830078125000000f, + 0.00299072265625000000f, + 0.00152587890625000000f, + 0.00296020507812500000f, + 0.00207519531250000000f, + 0.00366210937499999960f, + 0.00161743164062500000f, + 0.01950073242187500000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * NLSF_MSVQ_CB1_10_VECTORS ] = +{ + 0.05728149414062500000f, 0.14178466796875000000f, + 0.23535156250000003000f, 0.32791137695312500000f, + 0.42614746093750000000f, 0.51965332031250000000f, + 0.61764526367187500000f, 0.70745849609375000000f, + 0.80783081054687511000f, 0.89376831054687500000f, + 0.04919433593750000000f, 0.10003662109375001000f, + 0.21624755859374997000f, 0.30441284179687500000f, + 0.40368652343750000000f, 0.49633789062499994000f, + 0.59802246093750000000f, 0.69244384765625011000f, + 0.79458618164062500000f, 0.88394165039062500000f, + 0.06619262695312500000f, 0.11688232421875000000f, + 0.19714355468750000000f, 0.27337646484375000000f, + 0.36499023437500000000f, 0.45013427734375000000f, + 0.56176757812500000000f, 0.66098022460937500000f, + 0.76348876953125000000f, 0.85580444335937489000f, + 0.11230468750000001000f, 0.18383789062500000000f, + 0.27423095703125000000f, 0.37402343749999994000f, + 0.46389770507812494000f, 0.55505371093750000000f, + 0.66348266601562500000f, 0.74645996093750000000f, + 0.83874511718749989000f, 0.91732788085937500000f, + 0.07885742187500000000f, 0.15829467773437500000f, + 0.23800659179687500000f, 0.33270263671874994000f, + 0.40219116210937500000f, 0.48110961914062500000f, + 0.58035278320312500000f, 0.68453979492187500000f, + 0.79013061523437500000f, 0.87579345703125000000f, + 0.11386108398437500000f, 0.17550659179687500000f, + 0.26397705078125000000f, 0.35833740234375000000f, + 0.46051025390625000000f, 0.53121948242187500000f, + 0.62228393554687500000f, 0.71475219726562500000f, + 0.80041503906250000000f, 0.89254760742187511000f, + 0.06430053710937500000f, 0.19296264648437500000f, + 0.27206420898437500000f, 0.37310791015625000000f, + 0.45089721679687500000f, 0.54293823242187500000f, + 0.63061523437500000000f, 0.72262573242187500000f, + 0.81875610351562500000f, 0.89578247070312500000f, + 0.05117797851562500000f, 0.08758544921875000000f, + 0.16436767578125000000f, 0.24649047851562500000f, + 0.36062622070312500000f, 0.46313476562500000000f, + 0.56936645507812500000f, 0.67156982421875011000f, + 0.77859497070312500000f, 0.87551879882812500000f, + 0.06442260742187500000f, 0.11062622070312501000f, + 0.21444702148437500000f, 0.32312011718750000000f, + 0.42904663085937500000f, 0.52468872070312500000f, + 0.64505004882812489000f, 0.74035644531250000000f, + 0.84158325195312500000f, 0.91662597656250011000f, + 0.07409667968750000000f, 0.12237548828125000000f, + 0.17593383789062500000f, 0.28613281250000000000f, + 0.42129516601562500000f, 0.48281860351562500000f, + 0.59338378906250000000f, 0.68325805664062511000f, + 0.77194213867187500000f, 0.89447021484375000000f, + 0.06884765625000000000f, 0.14123535156250000000f, + 0.25564575195312500000f, 0.37966918945312500000f, + 0.46640014648437500000f, 0.59393310546875000000f, + 0.67922973632812500000f, 0.77975463867187489000f, + 0.86767578124999989000f, 0.92480468750000000000f, + 0.07177734375000000000f, 0.11215209960937499000f, + 0.18704223632812500000f, 0.36218261718750000000f, + 0.44406127929687494000f, 0.50827026367187500000f, + 0.59887695312500000000f, 0.66781616210937500000f, + 0.80950927734375000000f, 0.88040161132812500000f, + 0.16000366210937500000f, 0.22119140625000000000f, + 0.32220458984375000000f, 0.40493774414062500000f, + 0.47763061523437506000f, 0.54684448242187500000f, + 0.64517211914062500000f, 0.72714233398437500000f, + 0.82708740234375000000f, 0.90084838867187489000f, + 0.13494873046875000000f, 0.20523071289062500000f, + 0.31887817382812500000f, 0.40505981445312500000f, + 0.49206542968750000000f, 0.60794067382812500000f, + 0.69659423828124989000f, 0.79531860351562500000f, + 0.87777709960937500000f, 0.93331909179687500000f, + 0.13757324218750000000f, 0.19198608398437500000f, + 0.29003906250000000000f, 0.36038208007812506000f, + 0.42196655273437500000f, 0.48675537109375000000f, + 0.58218383789062500000f, 0.67395019531250000000f, + 0.78552246093750000000f, 0.87457275390625000000f, + 0.07751464843750000000f, 0.13113403320312500000f, + 0.26181030273437500000f, 0.41436767578125000000f, + 0.50762939453125000000f, 0.58291625976562500000f, + 0.65756225585937500000f, 0.72897338867187500000f, + 0.81716918945312489000f, 0.88946533203125000000f, + 0.10305786132812501000f, 0.19403076171875003000f, + 0.31201171875000000000f, 0.44305419921875000000f, + 0.54641723632812500000f, 0.64257812500000000000f, + 0.72134399414062500000f, 0.78686523437500011000f, + 0.85940551757812500000f, 0.91885375976562500000f, + 0.12747192382812500000f, 0.18133544921875000000f, + 0.24899291992187497000f, 0.30847167968750000000f, + 0.37017822265625000000f, 0.47210693359375000000f, + 0.61618041992187500000f, 0.71185302734375000000f, + 0.81732177734375000000f, 0.89596557617187500000f, + 0.07604980468750000000f, 0.11599731445312501000f, + 0.18750000000000000000f, 0.29983520507812500000f, + 0.48828124999999994000f, 0.56979370117187500000f, + 0.63760375976562489000f, 0.72213745117187500000f, + 0.79037475585937500000f, 0.88421630859374989000f, + 0.09188842773437500000f, 0.14425659179687500000f, + 0.20855712890625000000f, 0.32058715820312500000f, + 0.38040161132812500000f, 0.44238281250000000000f, + 0.52078247070312500000f, 0.61193847656250000000f, + 0.77102661132812500000f, 0.85623168945312500000f, + 0.12661743164062500000f, 0.21963500976562500000f, + 0.37652587890625000000f, 0.46008300781249994000f, + 0.54937744140625000000f, 0.61614990234375000000f, + 0.67709350585937500000f, 0.75448608398437500000f, + 0.82650756835937500000f, 0.88882446289062511000f, + 0.09078979492187500000f, 0.13970947265625000000f, + 0.19677734375000000000f, 0.25567626953125000000f, + 0.29513549804687500000f, 0.40359497070312500000f, + 0.59515380859375000000f, 0.67984008789062500000f, + 0.79522705078125000000f, 0.88043212890625000000f, + 0.12518310546875000000f, 0.17578125000000000000f, + 0.23632812500000000000f, 0.28942871093750000000f, + 0.32788085937500000000f, 0.37561035156250000000f, + 0.44790649414062500000f, 0.59835815429687500000f, + 0.75808715820312500000f, 0.86611938476562489000f, + 0.15048217773437500000f, 0.28341674804687500000f, + 0.38076782226562500000f, 0.40878295898437500000f, + 0.41845703125000000000f, 0.43795776367187506000f, + 0.48974609375000000000f, 0.60629272460937500000f, + 0.73815917968750000000f, 0.88482666015624989000f, + 0.12637329101562500000f, 0.24008178710937500000f, + 0.40100097656250000000f, 0.54077148437500000000f, + 0.61230468750000000000f, 0.64416503906250000000f, + 0.66198730468750000000f, 0.69342041015625000000f, + 0.72436523437500000000f, 0.83767700195312500000f, + 0.12240600585937499000f, 0.26611328125000000000f, + 0.40386962890625006000f, 0.49456787109375006000f, + 0.53713989257812500000f, 0.55813598632812500000f, + 0.56530761718750000000f, 0.60086059570312500000f, + 0.70904541015625000000f, 0.85089111328125000000f, + 0.10437011718750000000f, 0.18295288085937500000f, + 0.34271240234375006000f, 0.46133422851562500000f, + 0.48544311523437500000f, 0.51217651367187500000f, + 0.54205322265625000000f, 0.71249389648437500000f, + 0.82086181640625000000f, 0.91387939453125000000f, + 0.09399414062500001400f, 0.20709228515625000000f, + 0.31936645507812506000f, 0.41735839843750000000f, + 0.55111694335937500000f, 0.72067260742187489000f, + 0.82574462890624989000f, 0.88751220703124989000f, + 0.90219116210937500000f, 0.91262817382812500000f, + 0.09271240234375000000f, 0.17150878906250003000f, + 0.28277587890625000000f, 0.39276123046875000000f, + 0.57382202148437500000f, 0.59844970703125000000f, + 0.61065673828125000000f, 0.63482666015625000000f, + 0.72882080078125011000f, 0.89434814453125000000f, + 0.10113525390625000000f, 0.19592285156250000000f, + 0.27606201171875000000f, 0.40472412109375000000f, + 0.48428344726562500000f, 0.70547485351562500000f, + 0.72225952148437500000f, 0.73898315429687500000f, + 0.74728393554687500000f, 0.79086303710937500000f, + 0.10586547851562500000f, 0.21249389648437500000f, + 0.30831909179687500000f, 0.46636962890625006000f, + 0.62655639648437500000f, 0.70922851562500000000f, + 0.76367187500000000000f, 0.79409790039062500000f, + 0.81591796875000000000f, 0.83175659179687500000f, + 0.09280395507812500000f, 0.19711303710937500000f, + 0.29837036132812500000f, 0.39355468750000000000f, + 0.49789428710937500000f, 0.59234619140625000000f, + 0.73455810546875000000f, 0.89578247070312500000f, + 0.97030639648437500000f, 0.97885131835937500000f, + -0.00610351562500000000f, -0.00408935546875000000f, + -0.00344848632812500000f, -0.00622558593750000000f, + -0.01058959960937500000f, -0.01342773437500000000f, + -0.01074218749999999800f, -0.00643920898437500000f, + -0.01275634765625000200f, -0.00524902343750000000f, + -0.00955200195312500000f, 0.00180053710937500000f, + 0.01510620117187500000f, 0.02355957031250000000f, + 0.02200317382812500000f, 0.01873779296875000000f, + 0.01019287109375000000f, 0.01354980468750000000f, + 0.00686645507812500000f, 0.00738525390625000000f, + 0.00491333007812500000f, 0.00048828125000000000f, + 0.00836181640625000000f, 0.01721191406250000000f, + -0.00222778320312500000f, -0.00573730468750000000f, + -0.01205444335937500000f, -0.00521850585937500000f, + 0.02371215820312499700f, 0.01550292968750000000f, + 0.04089355468750000000f, 0.03494262695312500000f, + 0.02133178710937500000f, 0.00598144531250000000f, + 0.00680541992187500000f, 0.00527954101562500000f, + 0.00274658203125000000f, 0.00076293945312500000f, + -0.00079345703125000011f, 0.00054931640625000000f, + 0.00405883789062500000f, -0.00320434570312500000f, + -0.01098632812500000000f, -0.00845336914062500000f, + 0.02621459960937500000f, 0.01934814453125000000f, + 0.00125122070312500000f, -0.01699829101562500000f, + -0.02343750000000000000f, -0.02825927734375000000f, + -0.01834106445312500000f, -0.03115844726562500000f, + -0.03628540039062500000f, -0.01113891601562500000f, + 0.00686645507812500000f, 0.00326538085937500000f, + 0.01141357421875000200f, -0.00152587890625000000f, + 0.01321411132812500000f, 0.01272583007812500000f, + 0.00476074218750000000f, 0.00119018554687500000f, + -0.01821899414062500000f, -0.04263305664062499300f, + -0.04864501953125000000f, -0.01806640625000000000f, + -0.01480102539062500000f, -0.00891113281250000000f, + 0.00772094726562500000f, 0.00265502929687500000f, + -0.00000000000000000000f, -0.00018310546875000000f, + -0.00076293945312500000f, -0.01052856445312500000f, + -0.00732421874999999910f, 0.00366210937499999960f, + 0.03848266601562500000f, 0.02886962890625000000f, + 0.00506591796875000090f, -0.00845336914062500000f, + 0.00735473632812500090f, 0.00509643554687500000f, + 0.00518798828125000000f, 0.01309204101562500000f, + 0.01580810546875000000f, 0.02178955078125000000f, + 0.01837158203125000000f, 0.00775146484375000000f, + 0.00408935546875000000f, 0.00280761718750000000f, + -0.00463867187500000000f, -0.00988769531250000000f, + -0.01202392578124999800f, 0.00149536132812500000f, + -0.00460815429687500000f, -0.00927734375000000000f, + -0.02209472656250000000f, -0.02005004882812500000f, + -0.00494384765625000000f, -0.01126098632812500000f, + -0.00106811523437500000f, 0.00009155273437500000f, + -0.00006103515625000000f, -0.00952148437500000000f, + -0.00610351562500000000f, -0.00280761718750000000f, + -0.00692749023437500000f, 0.00738525390625000000f, + 0.01916503906250000000f, 0.01724243164062500000f, + -0.00378417968750000000f, 0.03222656250000000000f, + 0.02349853515625000300f, 0.00308227539062500000f, + -0.00256347656250000000f, -0.00100708007812500000f, + 0.00012207031250000000f, -0.00585937500000000000f, + -0.00830078125000000000f, 0.00015258789062500000f, + -0.01913452148437500000f, -0.02981567382812500000f, + 0.01278686523437500000f, 0.01440429687500000000f, + 0.00161743164062500000f, -0.00314331054687500000f, + 0.00442504882812500000f, 0.00982666015625000000f, + -0.00289916992187500000f, -0.00094604492187500000f, + -0.00305175781250000000f, -0.00924682617187500000f, + -0.01708984375000000000f, -0.03256225585937500000f, + -0.01260375976562500000f, 0.02178955078125000000f, + 0.00863647460937500000f, 0.00006103515625000000f, + -0.00680541992187500000f, -0.01119995117187500000f, + 0.01596069335937500000f, 0.01098632812500000000f, + -0.00115966796875000000f, -0.00350952148437500040f, + 0.01153564453125000000f, -0.01803588867187500000f, + -0.02191162109375000000f, 0.01367187500000000000f, + -0.01467895507812500000f, -0.00836181640625000000f, + 0.00549316406250000000f, -0.00268554687499999960f, + -0.01773071289062500000f, -0.00479125976562500000f, + -0.02124023437500000000f, -0.03860473632812500000f, + 0.01202392578124999800f, -0.01461791992187500000f, + -0.00070190429687500000f, 0.00378417968750000000f, + -0.00131225585937500000f, 0.00057983398437500000f, + -0.00344848632812500000f, -0.00720214843750000000f, + -0.01257324218750000000f, -0.02011108398437500000f, + -0.00610351562500000000f, 0.00006103515625000000f, + -0.00210571289062500000f, -0.01043701171875000000f, + 0.00607299804687500000f, 0.00167846679687500000f, + 0.00177001953125000000f, -0.00109863281250000000f, + -0.00155639648437500000f, -0.00189208984375000000f, + 0.01547241210937500000f, 0.01547241210937500000f, + 0.01303100585937500200f, 0.01348876953125000000f, + 0.00109863281250000000f, 0.01834106445312500000f, + -0.00430297851562500000f, 0.00207519531250000000f, + 0.00836181640625000000f, 0.00836181640625000000f, + 0.00207519531250000000f, -0.00036621093750000000f, + -0.00012207031250000000f, 0.00216674804687500000f, + -0.00588989257812500000f, -0.01416015625000000000f, + -0.01296997070312499800f, -0.01168823242187499800f, + 0.01245117187500000000f, 0.00619506835937500000f, + -0.01028442382812500000f, 0.00720214843750000000f, + 0.01251220703125000000f, -0.00180053710937500000f, + -0.00076293945312500000f, -0.01040649414062499800f, + -0.01370239257812500200f, 0.00085449218750000000f, + -0.00027465820312500000f, 0.00274658203125000000f, + 0.01013183593750000200f, -0.00042724609375000000f, + -0.02761840820312499700f, 0.00292968750000000000f, + -0.01647949218750000000f, -0.00738525390625000000f, + 0.02072143554687500000f, -0.00180053710937500000f, + 0.00585937500000000000f, -0.00073242187500000000f, + 0.00183105468749999980f, -0.00662231445312500000f, + 0.00015258789062500000f, -0.00112915039062500000f, + 0.00546264648437500000f, -0.00061035156250000000f, + 0.00949096679687500000f, 0.01583862304687500000f, + 0.00836181640625000000f, 0.00219726562500000000f, + -0.00994873046875000000f, -0.03143310546875000000f, + -0.00799560546875000000f, 0.00650024414062500000f, + 0.01159667968750000000f, 0.00250244140625000000f, + 0.01000976562500000000f, 0.01254272460937500000f, + -0.01647949218750000000f, 0.01751708984375000000f, + -0.00863647460937500000f, 0.00460815429687500000f, + 0.00552368164062500000f, -0.01226806640625000000f, + -0.00848388671875000000f, -0.00732421874999999910f, + -0.00335693359375000000f, -0.00692749023437500000f, + -0.00805664062500000000f, -0.00271606445312500000f, + -0.00762939453124999910f, -0.00790405273437500000f, + -0.00082397460937500000f, 0.00323486328125000000f, + -0.00729370117187499910f, -0.00299072265625000000f, + -0.01190185546875000000f, 0.00360107421875000000f, + 0.00186157226562500000f, 0.00317382812500000040f, + 0.00897216796875000000f, 0.01623535156250000000f, + 0.00280761718750000000f, -0.00039672851562500005f, + 0.00183105468749999980f, -0.00711059570312500000f, + 0.01022338867187500000f, 0.01651000976562500000f, + 0.00936889648437500000f, -0.00079345703125000011f, + -0.00335693359375000000f, -0.00277709960937500000f, + -0.00704956054687500000f, -0.01403808593750000200f, + 0.00518798828125000000f, 0.00613403320312500000f, + 0.00292968750000000000f, -0.01135253906249999800f, + 0.00402832031250000000f, 0.01327514648437500000f, + -0.00921630859375000000f, 0.00659179687500000000f, + -0.00851440429687500000f, -0.00125122070312500000f, + 0.00225830078125000000f, 0.00579833984375000000f, + 0.01123046875000000000f, 0.00833129882812500000f, + -0.00567626953124999910f, -0.01855468750000000000f, + -0.00479125976562500000f, 0.00485229492187500000f, + 0.00036621093750000000f, 0.00848388671875000000f, + 0.00747680664062500000f, 0.00936889648437500000f, + 0.00076293945312500000f, -0.00570678710937500090f, + -0.00048828125000000000f, 0.00167846679687500000f, + 0.00091552734374999989f, -0.00497436523437500000f, + 0.01672363281250000000f, -0.00936889648437500000f, + 0.00323486328125000000f, -0.00015258789062500000f, + 0.00082397460937500000f, 0.01007080078124999800f, + -0.01269531250000000200f, 0.01449584960937500000f, + 0.01336669921875000200f, -0.00717163085937500000f, + 0.00317382812500000040f, 0.00418090820312500000f, + 0.00064086914062500000f, -0.00015258789062500000f, + -0.00915527343750000000f, -0.01428222656250000000f, + 0.01589965820312500000f, -0.01058959960937500000f, + 0.00518798828125000000f, -0.00610351562500000000f, + -0.00668334960937500090f, 0.00939941406250000000f, + -0.00372314453125000000f, -0.00405883789062500000f, + 0.00668334960937500090f, -0.00048828125000000000f, + 0.01095581054687500000f, 0.01257324218750000000f, + -0.00271606445312500000f, -0.00338745117187500000f, + 0.00146484375000000000f, 0.00982666015625000000f, + 0.00433349609375000000f, 0.00540161132812500090f, + -0.00872802734375000000f, -0.00387573242187500000f, + -0.00119018554687500000f, -0.00192260742187500000f, + -0.00128173828125000000f, -0.01376342773437500000f, + 0.00488281250000000000f, 0.00939941406250000000f, + -0.00173950195312500000f, 0.00588989257812500000f, + -0.00146484375000000000f, 0.00225830078125000000f, + -0.01055908203125000000f, 0.00180053710937500000f, + -0.00082397460937500000f, 0.00082397460937500000f, + -0.01431274414062499800f, -0.00845336914062500000f, + -0.01049804687500000000f, 0.00860595703125000000f, + 0.00799560546875000000f, 0.00372314453125000000f, + 0.00521850585937500000f, -0.00759887695312500000f, + 0.00082397460937500000f, 0.00787353515625000000f, + 0.00573730468750000000f, -0.00009155273437500000f, + 0.00204467773437500000f, -0.00628662109375000000f, + -0.00866699218750000000f, 0.00888061523437500000f, + -0.00357055664062500000f, -0.00268554687499999960f, + -0.01455688476562500000f, 0.01144409179687500000f, + 0.00152587890625000000f, 0.00323486328125000000f, + 0.00302124023437500040f, -0.00555419921875000000f, + 0.01336669921875000200f, -0.01147460937500000000f, + -0.01223754882812500000f, -0.00149536132812500000f, + 0.00363159179687500000f, -0.00070190429687500000f, + -0.00030517578125000000f, -0.00146484375000000000f, + -0.00354003906250000000f, -0.00610351562500000000f, + -0.00946044921875000000f, 0.00369262695312500000f, + 0.00222778320312500000f, 0.00021362304687500000f, + 0.00723266601562500000f, -0.00689697265625000000f, + 0.00424194335937500000f, -0.01391601562500000000f, + 0.01211547851562500000f, 0.00106811523437500000f, + 0.00009155273437500000f, -0.00329589843750000000f, + 0.00985717773437500000f, -0.00228881835937500000f, + 0.01013183593750000200f, 0.00604248046875000090f, + -0.00302124023437500040f, -0.00064086914062500000f +}; + +const SKP_Silk_NLSF_CBS_FLP SKP_Silk_NLSF_CB1_10_Stage_info_FLP[ NLSF_MSVQ_CB1_10_STAGES ] = +{ + { 32, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 0 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 0 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 32 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 32 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 40 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 40 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 48 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 48 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 56 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 56 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_10[ 10 * 64 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates[ 64 ] } +}; + +const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB1_10_FLP = +{ + NLSF_MSVQ_CB1_10_STAGES, + SKP_Silk_NLSF_CB1_10_Stage_info_FLP, + SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min, + SKP_Silk_NLSF_MSVQ_CB1_10_CDF, + SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr, + SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx +}; + diff --git a/src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c b/src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c new file mode 100644 index 000000000..494166f29 --- /dev/null +++ b/src_FLP/SKP_Silk_tables_NLSF_CB1_16_FLP.c @@ -0,0 +1,973 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/**********************************************/ +/* This file has been automatically generated */ +/* */ +/* ROM usage: 7.14 kB */ +/**********************************************/ + +#include "SKP_Silk_tables_FLP.h" +#include "SKP_Silk_tables_NLSF_CB1_16.h" + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_16_rates[ NLSF_MSVQ_CB1_16_VECTORS ] = +{ + 1.78125000000000000000f, 3.06250000000000000000f, + 4.15625000000000000000f, 4.18750000000000000000f, + 4.31250000000000000000f, 4.50000000000000000000f, + 4.53125000000000000000f, 4.59375000000000000000f, + 4.75000000000000000000f, 5.53125000000000000000f, + 5.53125000000000000000f, 5.56250000000000000000f, + 5.65625000000000000000f, 5.71875000000000000000f, + 5.75000000000000000000f, 6.31250000000000000000f, + 6.43750000000000000000f, 6.71875000000000000000f, + 6.81250000000000000000f, 6.93750000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 7.09375000000000000000f, 7.09375000000000000000f, + 1.18750000000000000000f, 2.71875000000000000000f, + 3.03125000000000000000f, 3.71875000000000000000f, + 4.00000000000000000000f, 4.21875000000000000000f, + 4.37500000000000000000f, 4.46875000000000000000f, + 1.25000000000000000000f, 2.53125000000000000000f, + 3.34375000000000000000f, 3.34375000000000000000f, + 4.03125000000000000000f, 4.18750000000000000000f, + 4.18750000000000000000f, 4.46875000000000000000f, + 0.96875000000000000000f, 3.40625000000000000000f, + 3.56250000000000000000f, 3.75000000000000000000f, + 4.00000000000000000000f, 4.06250000000000000000f, + 4.09375000000000000000f, 4.12500000000000000000f, + 1.34375000000000000000f, 1.90625000000000000000f, + 3.87500000000000000000f, 3.90625000000000000000f, + 4.12500000000000000000f, 4.25000000000000000000f, + 4.40625000000000000000f, 4.43750000000000000000f, + 0.93750000000000000000f, 3.43750000000000000000f, + 3.68750000000000000000f, 3.75000000000000000000f, + 4.03125000000000000000f, 4.09375000000000000000f, + 4.15625000000000000000f, 4.15625000000000000000f, + 0.96875000000000000000f, 3.37500000000000000000f, + 3.59375000000000000000f, 3.78125000000000000000f, + 3.87500000000000000000f, 4.06250000000000000000f, + 4.15625000000000000000f, 4.28125000000000000000f, + 1.25000000000000000000f, 3.06250000000000000000f, + 3.59375000000000000000f, 3.59375000000000000000f, + 3.62500000000000000000f, 3.65625000000000000000f, + 3.84375000000000000000f, 3.87500000000000000000f, + 1.56250000000000000000f, 2.90625000000000000000f, + 3.37500000000000000000f, 3.43750000000000000000f, + 3.50000000000000000000f, 3.50000000000000000000f, + 3.56250000000000000000f, 3.59375000000000000000f, + 2.28125000000000000000f, 2.96875000000000000000f, + 2.96875000000000000000f, 3.00000000000000000000f, + 3.00000000000000000000f, 3.28125000000000000000f, + 3.34375000000000000000f, 3.43750000000000000000f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min[ 16 + 1 ] = +{ + 0.00451660156250000000f, + 0.00009155273437500000f, + 0.00183105468749999980f, + 0.00207519531250000000f, + 0.00357055664062500000f, + 0.00262451171875000000f, + 0.00369262695312500000f, + 0.00378417968750000000f, + 0.00463867187500000000f, + 0.00466918945312500000f, + 0.00631713867187499910f, + 0.00460815429687500000f, + 0.00686645507812500000f, + 0.00729370117187499910f, + 0.00384521484375000000f, + 0.00558471679687500000f, + 0.02416992187500000300f +}; + +const SKP_float SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * NLSF_MSVQ_CB1_16_VECTORS ] = +{ + 0.03994750976562499300f, 0.09338378906250000000f, + 0.15475463867187500000f, 0.21350097656250000000f, + 0.27551269531250000000f, 0.33380126953125000000f, + 0.39471435546875000000f, 0.45443725585937500000f, + 0.51675415039062500000f, 0.57537841796875000000f, + 0.63452148437500000000f, 0.69470214843750000000f, + 0.75540161132812500000f, 0.81356811523437500000f, + 0.87359619140625000000f, 0.93081665039062500000f, + 0.03857421875000000000f, 0.08377075195312498600f, + 0.14068603515625000000f, 0.19555664062500000000f, + 0.25286865234375000000f, 0.30648803710937500000f, + 0.36877441406250000000f, 0.43054199218750000000f, + 0.49188232421875006000f, 0.55429077148437500000f, + 0.61325073242187500000f, 0.67639160156250000000f, + 0.74047851562500000000f, 0.80310058593750000000f, + 0.86453247070312500000f, 0.92318725585937500000f, + 0.03186035156250000000f, 0.06347656250000000000f, + 0.11206054687500000000f, 0.15805053710937500000f, + 0.21789550781250003000f, 0.27770996093750000000f, + 0.33782958984375000000f, 0.39871215820312494000f, + 0.47067260742187500000f, 0.54290771484375000000f, + 0.60824584960937500000f, 0.67446899414062500000f, + 0.74127197265625000000f, 0.80447387695312500000f, + 0.86972045898437500000f, 0.92828369140625000000f, + 0.03451538085937500000f, 0.07556152343750000000f, + 0.13665771484375000000f, 0.18765258789062500000f, + 0.24114990234375000000f, 0.30136108398437500000f, + 0.36431884765624994000f, 0.42141723632812500000f, + 0.48428344726562500000f, 0.54107666015625000000f, + 0.60876464843750000000f, 0.66244506835937500000f, + 0.72512817382812500000f, 0.77926635742187500000f, + 0.83697509765625000000f, 0.88247680664062500000f, + 0.03173828125000000000f, 0.06115722656250000000f, + 0.12286376953125000000f, 0.18615722656250000000f, + 0.25732421875000000000f, 0.32025146484375000000f, + 0.38482666015625000000f, 0.44842529296875000000f, + 0.51260375976562500000f, 0.57296752929687500000f, + 0.63473510742187500000f, 0.69525146484375000000f, + 0.75598144531250000000f, 0.81427001953125000000f, + 0.87374877929687511000f, 0.93127441406250000000f, + 0.07049560546875000000f, 0.11633300781250001000f, + 0.18045043945312497000f, 0.24209594726562500000f, + 0.30618286132812500000f, 0.36257934570312500000f, + 0.42373657226562500000f, 0.48211669921875000000f, + 0.54171752929687500000f, 0.59741210937500000000f, + 0.65557861328125000000f, 0.71032714843750000000f, + 0.76773071289062500000f, 0.82427978515624989000f, + 0.87991333007812500000f, 0.93453979492187500000f, + 0.03826904296875000000f, 0.08688354492187500000f, + 0.15298461914062500000f, 0.20693969726562500000f, + 0.26324462890625000000f, 0.31646728515625000000f, + 0.38836669921875000000f, 0.44656372070312500000f, + 0.49685668945312494000f, 0.54479980468750000000f, + 0.60638427734375000000f, 0.65527343749999989000f, + 0.70196533203124989000f, 0.75161743164062500000f, + 0.81512451171875000000f, 0.85327148437500000000f, + 0.04479980468750000000f, 0.09335327148437500000f, + 0.15219116210937500000f, 0.21441650390625000000f, + 0.26675415039062500000f, 0.31774902343750000000f, + 0.37478637695312500000f, 0.42785644531250000000f, + 0.48736572265625000000f, 0.54086303710937500000f, + 0.59936523437500000000f, 0.65679931640625000000f, + 0.71630859375000000000f, 0.78311157226562500000f, + 0.85406494140625000000f, 0.92239379882812500000f, + 0.06625366210937500000f, 0.10882568359375000000f, + 0.17105102539062497000f, 0.22534179687500000000f, + 0.28698730468750000000f, 0.34240722656249994000f, + 0.39764404296875000000f, 0.45037841796875000000f, + 0.50924682617187500000f, 0.56204223632812500000f, + 0.62091064453125000000f, 0.67416381835937511000f, + 0.73410034179687489000f, 0.79992675781250000000f, + 0.86535644531250000000f, 0.92764282226562500000f, + 0.07351684570312500000f, 0.14270019531250000000f, + 0.23019409179687497000f, 0.29864501953125000000f, + 0.34848022460937500000f, 0.39474487304687500000f, + 0.43847656250000006000f, 0.47769165039062500000f, + 0.52996826171875000000f, 0.57809448242187500000f, + 0.63360595703125000000f, 0.68594360351562511000f, + 0.74584960937500000000f, 0.80343627929687500000f, + 0.86315917968750000000f, 0.92291259765625000000f, + 0.07183837890625000000f, 0.12884521484375000000f, + 0.20812988281250003000f, 0.27792358398437500000f, + 0.35388183593749994000f, 0.42523193359375000000f, + 0.48745727539062494000f, 0.53961181640625000000f, + 0.58465576171875000000f, 0.62612915039062500000f, + 0.67111206054687500000f, 0.71472167968750000000f, + 0.76837158203125000000f, 0.82202148437499989000f, + 0.87872314453125000000f, 0.93161010742187511000f, + 0.04037475585937500000f, 0.07366943359375000000f, + 0.12768554687500000000f, 0.18429565429687500000f, + 0.22991943359375000000f, 0.28680419921875000000f, + 0.33871459960937500000f, 0.39968872070312500000f, + 0.45162963867187500000f, 0.50204467773437500000f, + 0.56256103515625000000f, 0.63742065429687500000f, + 0.71685791015624989000f, 0.78851318359375011000f, + 0.85589599609374989000f, 0.92239379882812500000f, + 0.04153442382812500700f, 0.09896850585937500000f, + 0.18457031250000000000f, 0.25973510742187500000f, + 0.33572387695312500000f, 0.40115356445312500000f, + 0.45999145507812500000f, 0.50683593750000000000f, + 0.55316162109375000000f, 0.59146118164062500000f, + 0.63818359375000000000f, 0.68991088867187500000f, + 0.75256347656250011000f, 0.81384277343750000000f, + 0.87472534179687500000f, 0.93280029296875000000f, + 0.03710937500000000000f, 0.08081054687500000000f, + 0.18008422851562503000f, 0.25701904296875000000f, + 0.30630493164062500000f, 0.34866333007812500000f, + 0.39590454101562500000f, 0.44564819335937500000f, + 0.50921630859375000000f, 0.56762695312500000000f, + 0.62728881835937500000f, 0.68405151367187500000f, + 0.74615478515625000000f, 0.80200195312500000000f, + 0.86077880859375000000f, 0.91787719726562500000f, + 0.07376098632812500000f, 0.12353515625000000000f, + 0.19274902343750000000f, 0.25735473632812500000f, + 0.32073974609375000000f, 0.38931274414062494000f, + 0.45996093750000006000f, 0.52780151367187500000f, + 0.59732055664062500000f, 0.65621948242187489000f, + 0.71194458007812500000f, 0.75628662109375011000f, + 0.80062866210937489000f, 0.84500122070312500000f, + 0.89154052734375000000f, 0.94052124023437500000f, + 0.03088378906250000000f, 0.07156372070312500000f, + 0.15231323242187500000f, 0.22512817382812503000f, + 0.28884887695312500000f, 0.36364746093750000000f, + 0.43627929687500000000f, 0.50555419921875000000f, + 0.56982421875000000000f, 0.62695312500000000000f, + 0.68029785156250000000f, 0.72747802734375000000f, + 0.77560424804687511000f, 0.82550048828125011000f, + 0.88037109375000000000f, 0.93234252929687500000f, + 0.05911254882812500000f, 0.11270141601562500000f, + 0.19125366210937500000f, 0.24472045898437500000f, + 0.31652832031250000000f, 0.37213134765625000000f, + 0.43600463867187494000f, 0.47781372070312500000f, + 0.53195190429687500000f, 0.57568359375000000000f, + 0.63381958007812500000f, 0.67767333984375000000f, + 0.73355102539062500000f, 0.77706909179687489000f, + 0.83566284179687500000f, 0.87286376953125000000f, + 0.06008911132812500000f, 0.10086059570312500000f, + 0.15310668945312500000f, 0.20526123046875000000f, + 0.25558471679687500000f, 0.30496215820312500000f, + 0.35504150390625000000f, 0.40527343750000000000f, + 0.46014404296875000000f, 0.51119995117187500000f, + 0.56347656250000000000f, 0.61398315429687500000f, + 0.67013549804687500000f, 0.72808837890625000000f, + 0.80029296875000011000f, 0.89410400390625011000f, + 0.03656005859375000000f, 0.08078002929687500000f, + 0.16564941406250000000f, 0.22653198242187500000f, + 0.29830932617187500000f, 0.37094116210937500000f, + 0.44754028320312500000f, 0.49877929687500000000f, + 0.55300903320312500000f, 0.60394287109375000000f, + 0.65786743164062489000f, 0.69723510742187500000f, + 0.74719238281250011000f, 0.78558349609375000000f, + 0.84347534179687500000f, 0.87619018554687500000f, + 0.04992675781250000000f, 0.10232543945312500000f, + 0.16622924804687500000f, 0.23184204101562503000f, + 0.30020141601562500000f, 0.35543823242187500000f, + 0.42614746093750000000f, 0.48886108398437500000f, + 0.54510498046875000000f, 0.61389160156250000000f, + 0.68112182617187500000f, 0.73355102539062500000f, + 0.79241943359375000000f, 0.85711669921875011000f, + 0.91290283203125011000f, 0.95501708984375000000f, + 0.08166503906250000000f, 0.12527465820312500000f, + 0.19464111328125000000f, 0.25094604492187500000f, + 0.30694580078125000000f, 0.35244750976562500000f, + 0.39892578124999994000f, 0.44107055664062494000f, + 0.48693847656249994000f, 0.52963256835937500000f, + 0.57772827148437500000f, 0.62261962890625000000f, + 0.67697143554687500000f, 0.72888183593750000000f, + 0.78482055664062500000f, 0.84603881835937500000f, + 0.04190063476562500000f, 0.07913208007812500000f, + 0.13577270507812500000f, 0.17190551757812500000f, + 0.22277832031250000000f, 0.25711059570312500000f, + 0.28912353515625000000f, 0.33013916015625000000f, + 0.38967895507812500000f, 0.47979736328125006000f, + 0.57989501953125000000f, 0.65396118164062500000f, + 0.72271728515625000000f, 0.79113769531250000000f, + 0.85861206054687500000f, 0.92568969726562500000f, + 0.04870605468750000000f, 0.09713745117187500000f, + 0.16412353515625003000f, 0.21862792968750000000f, + 0.26458740234375000000f, 0.30838012695312500000f, + 0.35003662109375000000f, 0.39166259765625000000f, + 0.42697143554687500000f, 0.45904541015624994000f, + 0.50787353515625000000f, 0.54635620117187500000f, + 0.63351440429687500000f, 0.77157592773437500000f, + 0.84747314453125000000f, 0.92285156249999989000f, + 0.06216430664062500000f, 0.12167358398437500000f, + 0.19033813476562500000f, 0.24771118164062500000f, + 0.30377197265625000000f, 0.37368774414062500000f, + 0.43386840820312500000f, 0.48498535156250000000f, + 0.54244995117187500000f, 0.61383056640625000000f, + 0.68096923828125000000f, 0.79168701171875000000f, + 0.80276489257812500000f, 0.80819702148437500000f, + 0.81774902343750000000f, 0.87161254882812500000f, + 0.06655883789062500000f, 0.11773681640625000000f, + 0.17578125000000000000f, 0.24182128906250000000f, + 0.30642700195312500000f, 0.35330200195312500000f, + 0.42019653320312494000f, 0.47912597656250000000f, + 0.53189086914062500000f, 0.60665893554687500000f, + 0.71969604492187500000f, 0.74884033203125000000f, + 0.76940917968750000000f, 0.78408813476562511000f, + 0.87548828125000000000f, 0.93099975585937489000f, + 0.06079101562500000000f, 0.11846923828125000000f, + 0.19757080078125000000f, 0.24057006835937503000f, + 0.28628540039062500000f, 0.38671875000000006000f, + 0.43762207031250000000f, 0.47915649414062500000f, + 0.50836181640625000000f, 0.54418945312500000000f, + 0.63629150390625000000f, 0.69839477539062500000f, + 0.75308227539062511000f, 0.80740356445312500000f, + 0.86947631835937500000f, 0.92956542968750000000f, + 0.07296752929687500000f, 0.12170410156250000000f, + 0.16625976562500000000f, 0.22680664062500000000f, + 0.33612060546875000000f, 0.38388061523437500000f, + 0.40100097656250000000f, 0.43170166015625000000f, + 0.48516845703125006000f, 0.56738281250000000000f, + 0.64404296875000000000f, 0.70169067382812500000f, + 0.75296020507812500000f, 0.82965087890624989000f, + 0.85882568359375000000f, 0.90368652343750000000f, + 0.05227661132812500000f, 0.15570068359375000000f, + 0.21328735351562500000f, 0.23797607421875000000f, + 0.26458740234375000000f, 0.30853271484375000000f, + 0.38897705078125000000f, 0.45413208007812500000f, + 0.50991821289062500000f, 0.56173706054687500000f, + 0.61419677734375000000f, 0.67465209960937500000f, + 0.73794555664062500000f, 0.79949951171874989000f, + 0.86172485351562500000f, 0.91970825195312500000f, + 0.04919433593750000000f, 0.11038208007812500000f, + 0.18762207031250000000f, 0.25509643554687500000f, + 0.29223632812500000000f, 0.35180664062500006000f, + 0.45581054687500000000f, 0.54348754882812500000f, + 0.55807495117187500000f, 0.57156372070312500000f, + 0.57986450195312500000f, 0.64425659179687500000f, + 0.75167846679687500000f, 0.81164550781250000000f, + 0.87707519531250000000f, 0.93515014648437500000f, + 0.06915283203125000000f, 0.12719726562500000000f, + 0.23992919921875000000f, 0.29132080078125000000f, + 0.29351806640625000000f, 0.29611206054687500000f, + 0.30926513671875000000f, 0.42410278320312500000f, + 0.49636840820312500000f, 0.56250000000000000000f, + 0.62826538085937500000f, 0.68984985351562500000f, + 0.75543212890625000000f, 0.82379150390625000000f, + 0.88882446289062511000f, 0.94116210937500000000f, + 0.05615234375000000700f, 0.11953735351562501000f, + 0.19140625000000000000f, 0.23831176757812500000f, + 0.29644775390625000000f, 0.34906005859375000000f, + 0.42013549804687500000f, 0.48214721679687500000f, + 0.58728027343750000000f, 0.67053222656250000000f, + 0.70129394531250000000f, 0.70739746093750000000f, + 0.72396850585937489000f, 0.78277587890625000000f, + 0.88858032226562500000f, 0.94863891601562500000f, + 0.04449462890625000000f, 0.11022949218750000000f, + 0.18334960937500000000f, 0.22851562500000000000f, + 0.29989624023437500000f, 0.36294555664062500000f, + 0.42987060546875000000f, 0.48016357421875000000f, + 0.53222656250000000000f, 0.59616088867187500000f, + 0.68432617187500000000f, 0.75582885742187500000f, + 0.89251708984375000000f, 0.91333007812499989000f, + 0.93127441406250000000f, 0.94442749023437489000f, + -0.00311279296875000000f, -0.00369262695312500000f, + -0.00094604492187500000f, -0.00018310546875000000f, + 0.00015258789062500000f, -0.00006103515625000000f, + 0.00024414062500000000f, -0.00054931640625000000f, + -0.00012207031250000000f, 0.00018310546875000000f, + 0.00042724609375000000f, -0.00006103515625000000f, + -0.00036621093750000000f, -0.00048828125000000000f, + -0.00036621093750000000f, -0.00183105468749999980f, + -0.00384521484375000000f, -0.01077270507812500000f, + -0.01751708984375000000f, -0.02066040039062500000f, + -0.02005004882812500000f, -0.01882934570312500000f, + -0.01519775390625000000f, -0.01199340820312500000f, + -0.01062011718750000000f, -0.00845336914062500000f, + -0.00686645507812500000f, -0.00500488281250000000f, + -0.00311279296875000000f, -0.00213623046875000000f, + -0.00094604492187500000f, 0.00100708007812500000f, + 0.00012207031250000000f, 0.01156616210937500000f, + 0.01181030273437500000f, 0.01681518554687500000f, + 0.01846313476562500000f, 0.01892089843750000000f, + 0.01623535156250000000f, 0.01470947265625000200f, + 0.01348876953125000000f, 0.01385498046875000000f, + 0.01174926757812500200f, 0.01058959960937500000f, + 0.00982666015625000000f, 0.00912475585937500000f, + 0.00811767578125000000f, 0.00610351562500000000f, + 0.03564453125000000000f, 0.02902221679687500000f, + 0.02050781250000000000f, 0.00750732421875000000f, + 0.00183105468749999980f, -0.00491333007812500000f, + -0.00790405273437500000f, -0.00714111328125000000f, + -0.00772094726562500000f, -0.00860595703125000000f, + -0.00619506835937500000f, -0.00570678710937500090f, + -0.00473022460937500000f, -0.00537109374999999910f, + -0.00604248046875000090f, -0.00543212890625000000f, + 0.00030517578125000000f, 0.00518798828125000000f, + 0.01199340820312500000f, 0.01858520507812500000f, + 0.01693725585937500000f, 0.00634765625000000090f, + -0.01007080078124999800f, -0.01742553710937500000f, + -0.02346801757812500000f, -0.01931762695312500000f, + -0.00973510742187500000f, -0.00131225585937500000f, + 0.00289916992187500000f, 0.00320434570312500000f, + 0.00323486328125000000f, 0.00354003906250000000f, + -0.00463867187500000000f, -0.00427246093750000000f, + -0.00381469726562499960f, 0.00015258789062500000f, + 0.00527954101562500000f, 0.00836181640625000000f, + 0.00805664062500000000f, 0.01010131835937500000f, + -0.00112915039062500000f, -0.00894165039062500000f, + -0.01858520507812500000f, -0.02398681640625000000f, + -0.02926635742187500000f, -0.02484130859375000300f, + -0.01968383789062500000f, -0.00726318359375000000f, + -0.00277709960937500000f, 0.00109863281250000000f, + -0.00033569335937499995f, -0.00308227539062500000f, + -0.00851440429687500000f, -0.00692749023437500000f, + -0.00122070312500000000f, 0.00274658203125000000f, + 0.01617431640625000000f, 0.02066040039062500000f, + 0.02716064453125000000f, 0.03369140625000000000f, + 0.03048706054687500000f, 0.02548217773437500000f, + 0.01721191406250000000f, 0.00900268554687500000f, + -0.00854492187500000000f, -0.01110839843750000000f, + -0.01037597656250000000f, -0.01010131835937500000f, + -0.00866699218750000000f, 0.00878906250000000000f, + 0.02322387695312500000f, 0.02685546875000000000f, + 0.03015136718750000000f, 0.01913452148437500000f, + 0.00445556640625000000f, -0.00689697265625000000f, + -0.00619506835937500000f, -0.00552368164062500000f, + -0.00433349609375000000f, 0.00119018554687500000f, + 0.00073242187500000000f, -0.00079345703125000011f, + -0.00326538085937500000f, -0.00280761718750000000f, + -0.00491333007812500000f, -0.00411987304687500000f, + -0.00399780273437500000f, -0.00268554687499999960f, + -0.00488281250000000000f, -0.00476074218750000000f, + -0.00228881835937500000f, -0.00131225585937500000f, + -0.00109863281250000000f, -0.00018310546875000000f, + -0.00100708007812500000f, 0.00100708007812500000f, + -0.00988769531250000000f, -0.01266479492187500000f, + -0.00329589843750000000f, 0.00378417968750000000f, + 0.00479125976562500000f, 0.00582885742187500000f, + 0.00619506835937500000f, 0.00601196289062499910f, + 0.00439453125000000000f, 0.00332641601562499960f, + 0.00463867187500000000f, 0.00537109374999999910f, + 0.00579833984375000000f, 0.00372314453125000000f, + 0.00308227539062500000f, 0.00485229492187500000f, + 0.02023315429687500000f, 0.02038574218750000000f, + 0.01464843749999999800f, 0.01220703125000000000f, + 0.01156616210937500000f, 0.01354980468750000000f, + 0.01361083984375000000f, 0.01397705078124999800f, + 0.01046752929687500200f, 0.01071166992187500000f, + 0.00946044921875000000f, 0.00695800781250000000f, + 0.00405883789062500000f, 0.00134277343749999980f, + 0.00228881835937500000f, 0.00192260742187500000f, + -0.00256347656250000000f, 0.00119018554687500000f, + -0.00088500976562500000f, 0.00106811523437500000f, + -0.00286865234375000000f, -0.00711059570312500000f, + -0.00796508789062500000f, -0.01080322265625000200f, + 0.00234985351562500000f, 0.00799560546875000000f, + -0.00073242187500000000f, -0.00442504882812500000f, + -0.01016235351562500000f, -0.01248168945312500000f, + -0.01232910156250000000f, -0.01821899414062500000f, + -0.01489257812500000000f, -0.00915527343750000000f, + 0.02777099609375000000f, 0.01806640625000000000f, + 0.01257324218750000000f, 0.00366210937499999960f, + 0.00396728515625000000f, -0.00155639648437500000f, + -0.00112915039062500000f, -0.00234985351562500000f, + -0.00524902343750000000f, -0.00552368164062500000f, + -0.00485229492187500000f, -0.00451660156250000000f, + -0.00219726562500000000f, -0.00189208984375000000f, + 0.01556396484375000000f, 0.01574707031250000000f, + 0.00344848632812500000f, -0.01785278320312500000f, + -0.03280639648437500000f, -0.02920532226562500000f, + -0.01272583007812500000f, -0.00595092773437500000f, + 0.00027465820312500000f, 0.00021362304687500000f, + -0.00268554687499999960f, -0.00527954101562500000f, + -0.00277709960937500000f, 0.00164794921875000000f, + 0.00299072265625000000f, 0.00289916992187500000f, + -0.00085449218750000000f, 0.00601196289062499910f, + -0.01608276367187500000f, -0.01895141601562500000f, + 0.00479125976562500000f, 0.00372314453125000000f, + -0.00512695312500000000f, 0.00448608398437500000f, + 0.00942993164062500000f, 0.00915527343750000000f, + 0.01025390625000000000f, 0.00961303710937500000f, + 0.01208496093750000200f, 0.01245117187500000000f, + 0.01147460937500000000f, 0.00323486328125000000f, + -0.00494384765625000000f, -0.00518798828125000000f, + -0.00961303710937500000f, 0.00299072265625000000f, + 0.02505493164062499700f, 0.02770996093750000000f, + 0.01739501953125000000f, -0.00100708007812500000f, + -0.00952148437500000000f, -0.01733398437500000000f, + -0.01745605468750000000f, -0.01153564453125000000f, + -0.00326538085937500000f, 0.00070190429687500000f, + 0.00476074218750000000f, 0.00283813476562499960f, + -0.00393676757812500000f, -0.00265502929687500000f, + 0.00061035156250000000f, -0.00219726562500000000f, + -0.00112915039062500000f, 0.00122070312500000000f, + 0.00064086914062500000f, 0.00082397460937500000f, + 0.00146484375000000000f, 0.00228881835937500000f, + 0.00234985351562500000f, 0.00198364257812500000f, + 0.00140380859375000000f, 0.00216674804687500000f, + 0.00201416015625000000f, 0.00143432617187500000f, + 0.00415039062500000000f, 0.01049804687500000000f, + 0.00720214843750000000f, 0.00982666015625000000f, + 0.00518798828125000000f, 0.00863647460937500000f, + 0.00820922851562500000f, 0.00888061523437500000f, + 0.00494384765625000000f, -0.00131225585937500000f, + -0.00622558593750000000f, -0.00790405273437500000f, + -0.00732421874999999910f, -0.00930786132812500000f, + -0.01068115234374999800f, -0.00952148437500000000f, + 0.01364135742187499800f, 0.01062011718750000000f, + 0.01052856445312500000f, 0.00784301757812500000f, + 0.00216674804687500000f, -0.00399780273437500000f, + -0.00234985351562500000f, -0.00579833984375000000f, + -0.00616455078125000000f, -0.00122070312500000000f, + 0.00106811523437500000f, 0.00405883789062500000f, + 0.00796508789062500000f, 0.01113891601562500000f, + 0.01336669921875000200f, 0.00924682617187500000f, + -0.00024414062500000000f, 0.00067138671874999989f, + 0.00427246093750000000f, 0.00418090820312500000f, + -0.00915527343750000000f, -0.01956176757812500000f, + -0.02331542968750000000f, -0.00817871093750000000f, + -0.00070190429687500000f, -0.00076293945312500000f, + 0.00222778320312500000f, -0.00494384765625000000f, + -0.00457763671875000000f, -0.00646972656250000000f, + -0.00219726562500000000f, 0.00018310546875000000f, + 0.00119018554687500000f, 0.00238037109375000000f, + 0.00317382812500000040f, -0.00283813476562499960f, + -0.00939941406250000000f, -0.00415039062500000000f, + 0.00357055664062500000f, -0.00216674804687500000f, + -0.01565551757812500000f, -0.02502441406250000000f, + -0.02136230468749999700f, -0.01373291015625000000f, + -0.00491333007812500000f, -0.00070190429687500000f, + 0.00088500976562500000f, 0.00238037109375000000f, + 0.01028442382812500000f, 0.00323486328125000000f, + -0.01239013671875000000f, -0.02386474609375000000f, + -0.00341796875000000000f, 0.00711059570312500000f, + 0.01168823242187499800f, 0.00189208984375000000f, + -0.00384521484375000000f, 0.00018310546875000000f, + -0.00234985351562500000f, -0.00088500976562500000f, + -0.00445556640625000000f, -0.00375366210937500000f, + -0.00155639648437500000f, -0.00082397460937500000f, + -0.00082397460937500000f, -0.01162719726562500000f, + -0.01956176757812500000f, 0.01226806640625000000f, + 0.01644897460937500000f, 0.00024414062500000000f, + -0.00631713867187499910f, -0.01116943359375000000f, + -0.00109863281250000000f, -0.00082397460937500000f, + -0.00622558593750000000f, -0.00692749023437500000f, + -0.00723266601562500000f, -0.00576782226562500000f, + -0.00195312500000000000f, 0.00155639648437500000f, + -0.00280761718750000000f, -0.00418090820312500000f, + -0.00857543945312500000f, 0.00189208984375000000f, + 0.00711059570312500000f, 0.00280761718750000000f, + 0.00451660156250000000f, 0.00897216796875000000f, + 0.01107788085937500200f, 0.01269531250000000200f, + 0.01721191406250000000f, 0.01907348632812500000f, + 0.01129150390625000000f, -0.00109863281250000000f, + -0.01431274414062499800f, -0.01409912109375000000f, + 0.00311279296875000000f, 0.00512695312500000000f, + 0.00097656250000000000f, 0.00357055664062500000f, + -0.00064086914062500000f, 0.00296020507812500000f, + 0.00424194335937500000f, 0.00271606445312500000f, + 0.00317382812500000040f, 0.00106811523437500000f, + 0.00012207031250000000f, 0.00250244140625000000f, + 0.00201416015625000000f, 0.00177001953125000000f, + 0.00222778320312500000f, 0.00283813476562499960f, + -0.00231933593750000000f, -0.00976562500000000000f, + -0.00720214843750000000f, -0.00576782226562500000f, + -0.00619506835937500000f, -0.00433349609375000000f, + -0.00082397460937500000f, -0.00222778320312500000f, + 0.00027465820312500000f, -0.00027465820312500000f, + -0.00076293945312500000f, 0.00036621093750000000f, + -0.00045776367187499995f, 0.00012207031250000000f, + 0.00012207031250000000f, -0.00152587890625000000f, + 0.00958251953125000000f, 0.00549316406250000000f, + 0.00494384765625000000f, -0.00149536132812500000f, + 0.00607299804687500000f, -0.00329589843750000000f, + -0.00692749023437500000f, -0.00201416015625000000f, + -0.01364135742187499800f, -0.00204467773437500000f, + -0.00805664062500000000f, -0.01202392578124999800f, + 0.00015258789062500000f, 0.00167846679687500000f, + -0.00405883789062500000f, -0.00537109374999999910f, + -0.00354003906250000000f, -0.00735473632812500090f, + 0.00830078125000000000f, 0.00332641601562499960f, + 0.00860595703125000000f, 0.00799560546875000000f, + 0.00585937500000000000f, -0.00195312500000000000f, + -0.01196289062500000000f, -0.01568603515625000000f, + 0.00476074218750000000f, 0.00619506835937500000f, + 0.00469970703125000000f, 0.00219726562500000000f, + -0.00103759765625000000f, -0.00488281250000000000f, + -0.00222778320312500000f, 0.00009155273437500000f, + -0.00100708007812500000f, -0.01315307617187500000f, + 0.00979614257812500000f, 0.00054931640625000000f, + -0.01730346679687500000f, -0.01800537109375000000f, + -0.00329589843750000000f, 0.00268554687499999960f, + 0.00201416015625000000f, 0.00155639648437500000f, + -0.00094604492187500000f, -0.00588989257812500000f, + -0.00140380859375000000f, 0.00198364257812500000f, + -0.00088500976562500000f, -0.00070190429687500000f, + 0.00656127929687500000f, -0.00094604492187500000f, + 0.00308227539062500000f, -0.00344848632812500000f, + 0.00097656250000000000f, 0.00927734375000000000f, + 0.00268554687499999960f, 0.00976562500000000000f, + 0.01367187500000000000f, 0.00015258789062500000f, + -0.01339721679687500000f, -0.01715087890625000000f, + -0.01550292968750000000f, -0.00411987304687500000f, + -0.00039672851562500005f, -0.00521850585937500000f, + -0.00024414062500000000f, 0.00555419921875000000f, + -0.00302124023437500040f, -0.00552368164062500000f, + -0.00454711914062500000f, 0.01147460937500000000f, + 0.01452636718750000000f, 0.00195312500000000000f, + -0.01208496093750000200f, -0.01989746093750000000f, + -0.00457763671875000000f, 0.00537109374999999910f, + 0.00677490234375000000f, 0.00198364257812500000f, + -0.01800537109375000000f, 0.02194213867187500300f, + 0.00827026367187500000f, 0.01217651367187500000f, + 0.00747680664062500000f, 0.00219726562500000000f, + -0.00476074218750000000f, -0.00463867187500000000f, + -0.00537109374999999910f, 0.00180053710937500000f, + 0.00286865234375000000f, 0.00381469726562499960f, + -0.00027465820312500000f, -0.00021362304687500000f, + 0.00027465820312500000f, 0.00003051757812500000f, + -0.00186157226562500000f, -0.00354003906250000000f, + -0.00250244140625000000f, 0.00003051757812500000f, + 0.00241088867187500000f, 0.00067138671874999989f, + -0.00134277343749999980f, -0.00045776367187499995f, + -0.00146484375000000000f, -0.00198364257812500000f, + -0.00189208984375000000f, -0.00308227539062500000f, + -0.00311279296875000000f, -0.00164794921875000000f, + -0.00213623046875000000f, -0.00238037109375000000f, + -0.00244140625000000000f, -0.00076293945312500000f, + 0.01214599609375000000f, 0.00216674804687500000f, + 0.00424194335937500000f, 0.00115966796875000000f, + 0.00274658203125000000f, 0.00592041015625000000f, + 0.00677490234375000000f, 0.00759887695312500000f, + 0.00503540039062499910f, 0.00286865234375000000f, + 0.00674438476562500000f, 0.00799560546875000000f, + 0.00497436523437500000f, 0.00277709960937500000f, + -0.00628662109375000000f, 0.01748657226562500000f, + 0.00610351562500000000f, -0.00875854492187500000f, + -0.00448608398437500000f, 0.00015258789062500000f, + -0.00054931640625000000f, -0.00259399414062500000f, + -0.00225830078125000000f, -0.00381469726562499960f, + -0.00265502929687500000f, 0.00259399414062500000f, + 0.00430297851562500000f, 0.00012207031250000000f, + -0.00012207031250000000f, 0.00085449218750000000f, + 0.00714111328125000000f, 0.00146484375000000000f, + -0.00457763671875000000f, -0.00338745117187500000f, + -0.01544189453125000000f, 0.00723266601562500000f, + -0.00637817382812500090f, 0.01052856445312500000f, + 0.00286865234375000000f, -0.00378417968750000000f, + 0.00234985351562500000f, 0.00369262695312500000f, + 0.00436401367187500000f, 0.00036621093750000000f, + -0.00244140625000000000f, -0.00146484375000000000f, + 0.00582885742187500000f, 0.00439453125000000000f, + -0.00283813476562499960f, -0.00198364257812500000f, + -0.00460815429687500000f, -0.01962280273437500000f, + 0.01327514648437500000f, 0.00323486328125000000f, + 0.00265502929687500000f, 0.00021362304687500000f, + 0.00198364257812500000f, 0.00311279296875000000f, + 0.00286865234375000000f, 0.00207519531250000000f, + 0.00015258789062500000f, 0.00302124023437500040f, + 0.00677490234375000000f, 0.00283813476562499960f, + 0.00286865234375000000f, 0.01083374023437500000f, + -0.00039672851562500005f, -0.00271606445312500000f, + -0.00695800781250000000f, -0.01535034179687500000f, + 0.00875854492187500000f, 0.00332641601562499960f, + 0.00329589843750000000f, 0.01370239257812500200f, + 0.00772094726562500000f, -0.00088500976562500000f, + -0.00332641601562499960f, -0.00354003906250000000f, + 0.00045776367187499995f, -0.00222778320312500000f, + -0.00061035156250000000f, 0.00399780273437500000f, + -0.00448608398437500000f, 0.00219726562500000000f, + 0.00180053710937500000f, -0.00457763671875000000f, + -0.01812744140625000000f, 0.00833129882812500000f, + 0.00964355468750000000f, 0.00402832031250000000f, + 0.00607299804687500000f, 0.00323486328125000000f, + 0.00604248046875000090f, 0.00646972656250000000f, + 0.00671386718750000000f, 0.00250244140625000000f, + 0.00137329101562500000f, -0.00039672851562500005f, + 0.00680541992187500000f, 0.00418090820312500000f, + 0.00823974609375000000f, 0.00115966796875000000f, + 0.00769042968750000000f, 0.00411987304687500000f, + -0.00540161132812500090f, -0.00631713867187499910f, + -0.01098632812500000000f, -0.00311279296875000000f, + 0.01229858398437500000f, 0.01239013671875000000f, + -0.00042724609375000000f, 0.00253295898437500040f, + 0.00195312500000000000f, 0.00155639648437500000f, + -0.00021362304687500000f, -0.00302124023437500040f, + -0.00296020507812500000f, -0.00268554687499999960f, + -0.00378417968750000000f, -0.00198364257812500000f, + 0.00128173828125000000f, 0.00097656250000000000f, + 0.00085449218750000000f, 0.00088500976562500000f, + 0.00036621093750000000f, 0.00061035156250000000f, + 0.00363159179687500000f, -0.00079345703125000011f, + -0.00646972656250000000f, -0.00613403320312500000f, + 0.01138305664062500000f, 0.00765991210937500090f, + 0.00430297851562500000f, 0.00314331054687500000f, + 0.00109863281250000000f, -0.00158691406250000020f, + 0.00201416015625000000f, 0.00054931640625000000f, + -0.00018310546875000000f, -0.00289916992187500000f, + -0.00598144531250000000f, 0.00015258789062500000f, + 0.00299072265625000000f, -0.00259399414062500000f, + -0.00329589843750000000f, 0.00665283203124999910f, + -0.00500488281250000000f, 0.00061035156250000000f, + 0.01086425781250000000f, 0.00524902343750000000f, + 0.00112915039062500000f, 0.00811767578125000000f, + 0.00070190429687500000f, 0.00341796875000000000f, + -0.00073242187500000000f, -0.00302124023437500040f, + -0.00280761718750000000f, -0.00543212890625000000f, + 0.00088500976562500000f, -0.00848388671875000000f, + 0.01184082031250000000f, -0.00183105468749999980f, + -0.00671386718750000000f, 0.00915527343750000000f, + -0.00039672851562500005f, 0.00469970703125000000f, + 0.00582885742187500000f, 0.00045776367187499995f, + -0.00112915039062500000f, -0.00335693359375000000f, + -0.00466918945312500000f, -0.00457763671875000000f, + -0.00347900390625000000f, -0.00021362304687500000f, + -0.00286865234375000000f, -0.00094604492187500000f, + -0.00189208984375000000f, -0.00540161132812500090f, + 0.00012207031250000000f, -0.00213623046875000000f, + 0.00106811523437500000f, 0.01382446289062500000f, + 0.00448608398437500000f, -0.00753784179687500000f, + -0.01000976562500000000f, 0.00308227539062500000f, + 0.00061035156250000000f, -0.00347900390625000000f, + 0.00448608398437500000f, 0.00329589843750000000f, + -0.00363159179687500000f, -0.00332641601562499960f, + -0.00311279296875000000f, -0.00726318359375000000f, + 0.00167846679687500000f, -0.00311279296875000000f, + 0.00527954101562500000f, -0.00271606445312500000f, + 0.00393676757812500000f, 0.00421142578125000000f, + -0.01007080078124999800f, -0.00488281250000000000f, + 0.01480102539062500000f, 0.00469970703125000000f, + -0.00180053710937500000f, -0.00518798828125000000f, + -0.00061035156250000000f, -0.00103759765625000000f, + -0.00796508789062500000f, -0.00122070312500000000f, + -0.00393676757812500000f, 0.00234985351562500000f, + -0.00256347656250000000f, 0.00210571289062500000f, + 0.00253295898437500040f, 0.00488281250000000000f, + 0.00515747070312500000f, 0.00192260742187500000f, + -0.01574707031250000000f, 0.00091552734374999989f, + 0.01025390625000000000f, 0.00158691406250000020f, + -0.00000000000000000000f, -0.00158691406250000020f, + -0.00378417968750000000f, 0.00482177734375000000f, + 0.00057983398437500000f, 0.00601196289062499910f, + -0.00030517578125000000f, -0.01144409179687500000f, + 0.01235961914062499800f, 0.00869750976562500000f, + 0.00347900390625000000f, -0.01205444335937500000f, + -0.00143432617187500000f, 0.00598144531250000000f, + 0.00189208984375000000f, 0.00265502929687500000f, + -0.00323486328125000000f, -0.00198364257812500000f, + -0.00228881835937500000f, -0.00210571289062500000f, + -0.00039672851562500005f, 0.00103759765625000000f, + 0.00302124023437500040f, 0.00180053710937500000f, + 0.00253295898437500040f, 0.00299072265625000000f, + 0.00134277343749999980f, 0.00000000000000000000f, + 0.00073242187500000000f, 0.00054931640625000000f, + 0.00051879882812500000f, 0.00213623046875000000f, + -0.00067138671874999989f, 0.00592041015625000000f, + 0.00634765625000000090f, 0.00439453125000000000f, + -0.00241088867187500000f, -0.00045776367187499995f, + 0.00097656250000000000f, -0.00317382812500000040f, + -0.00085449218750000000f, -0.00320434570312500000f, + -0.00567626953124999910f, -0.00646972656250000000f, + -0.00695800781250000000f, -0.00241088867187500000f, + -0.00231933593750000000f, 0.00155639648437500000f, + -0.00216674804687500000f, 0.00219726562500000000f, + 0.00360107421875000000f, -0.00103759765625000000f, + -0.00009155273437500000f, -0.00521850585937500000f, + 0.00015258789062500000f, 0.00006103515625000000f, + -0.00329589843750000000f, -0.00381469726562499960f, + 0.00189208984375000000f, -0.00177001953125000000f, + 0.00177001953125000000f, -0.00369262695312500000f, + 0.00222778320312500000f, -0.01422119140625000000f, + 0.00280761718750000000f, 0.00192260742187500000f, + -0.00286865234375000000f, -0.00238037109375000000f, + -0.00231933593750000000f, 0.00646972656250000000f, + 0.00109863281250000000f, -0.00686645507812500000f, + -0.00216674804687500000f, -0.01080322265625000200f, + 0.00463867187500000000f, 0.00436401367187500000f, + -0.00241088867187500000f, -0.00750732421875000000f, + -0.00155639648437500000f, -0.00094604492187500000f, + -0.00018310546875000000f, -0.00823974609375000000f, + 0.00732421874999999910f, 0.00640869140625000000f, + 0.00091552734374999989f, -0.00479125976562500000f, + -0.00704956054687500000f, 0.00225830078125000000f, + -0.00445556640625000000f, 0.00268554687499999960f, + -0.00833129882812500000f, 0.00476074218750000000f, + 0.00280761718750000000f, 0.00170898437500000000f, + 0.00216674804687500000f, 0.00006103515625000000f, + 0.00970458984375000000f, 0.00500488281250000000f, + 0.00097656250000000000f, -0.00335693359375000000f, + -0.00106811523437500000f, -0.00125122070312500000f, + -0.00289916992187500000f, -0.00323486328125000000f, + 0.00033569335937499995f, 0.00402832031250000000f, + -0.00207519531250000000f, 0.00167846679687500000f, + 0.00375366210937500000f, -0.00253295898437500040f, + -0.00454711914062500000f, 0.00646972656250000000f, + 0.00402832031250000000f, 0.00000000000000000000f, + -0.00592041015625000000f, 0.00167846679687500000f, + 0.00628662109375000000f, -0.00329589843750000000f, + -0.01077270507812500000f, 0.00881958007812500000f, + -0.00595092773437500000f, 0.00003051757812500000f, + 0.00711059570312500000f, -0.00067138671874999989f, + -0.00183105468749999980f, 0.00061035156250000000f, + 0.00079345703125000011f, 0.00207519531250000000f, + 0.00506591796875000090f, 0.00082397460937500000f, + -0.00177001953125000000f, 0.00396728515625000000f, + 0.00341796875000000000f, 0.00326538085937500000f, + 0.00082397460937500000f, -0.00503540039062499910f, + 0.00350952148437500040f, -0.00283813476562499960f, + -0.00112915039062500000f, 0.00115966796875000000f, + 0.00253295898437500040f, 0.01473999023437500000f, + 0.00198364257812500000f, -0.00698852539062499910f, + -0.00039672851562500005f, 0.00479125976562500000f, + 0.00259399414062500000f, 0.00152587890625000000f, + 0.00415039062500000000f, 0.00030517578125000000f, + 0.00097656250000000000f, 0.00253295898437500040f, + 0.00250244140625000000f, 0.00167846679687500000f, + 0.00015258789062500000f, -0.00027465820312500000f, + -0.00158691406250000020f, -0.00238037109375000000f, + -0.00247192382812500000f, -0.00155639648437500000f, + 0.00122070312500000000f, 0.00054931640625000000f, + -0.00387573242187500000f, -0.00683593750000000000f, + -0.00125122070312500000f, 0.00161743164062500000f, + -0.00640869140625000000f, -0.00344848632812500000f, + 0.00073242187500000000f, -0.00051879882812500000f, + -0.00570678710937500090f, -0.00271606445312500000f, + 0.00024414062500000000f, 0.00369262695312500000f, + 0.00253295898437500040f, 0.00234985351562500000f, + 0.00277709960937500000f, -0.00225830078125000000f, + -0.00106811523437500000f, -0.00341796875000000000f, + -0.00491333007812500000f, -0.00527954101562500000f, + 0.00311279296875000000f, 0.00402832031250000000f, + -0.00381469726562499960f, -0.00186157226562500000f, + 0.00314331054687500000f, -0.00793457031250000000f, + 0.00158691406250000020f, 0.00506591796875000090f, + -0.00097656250000000000f, -0.00476074218750000000f, + -0.00265502929687500000f, -0.00170898437500000000f, + 0.00183105468749999980f, -0.00213623046875000000f, + -0.00378417968750000000f, 0.00738525390625000000f, + 0.00347900390625000000f, -0.00765991210937500090f, + -0.00506591796875000090f, 0.00613403320312500000f, + 0.00387573242187500000f, 0.00085449218750000000f, + -0.00033569335937499995f, 0.00070190429687500000f, + -0.00244140625000000000f, -0.00350952148437500040f, + -0.00061035156250000000f, -0.00155639648437500000f, + -0.01062011718750000000f, 0.01037597656250000000f, + -0.00103759765625000000f, 0.00405883789062500000f, + 0.00039672851562500005f, 0.00280761718750000000f, + -0.00378417968750000000f, -0.00415039062500000000f, + -0.00366210937499999960f, -0.00079345703125000011f, + -0.00018310546875000000f, 0.00051879882812500000f, + 0.00085449218750000000f, 0.00064086914062500000f, + 0.00366210937499999960f, -0.00512695312500000000f, + 0.00488281250000000000f, -0.00106811523437500000f, + 0.00350952148437500040f, 0.00085449218750000000f, + 0.00027465820312500000f, 0.00021362304687500000f, + -0.00170898437500000000f, 0.00119018554687500000f, + 0.00476074218750000000f, 0.00781250000000000000f, + -0.00054931640625000000f, 0.00003051757812500000f, + 0.00845336914062500000f, 0.00250244140625000000f, + -0.00213623046875000000f, -0.00439453125000000000f, + -0.00268554687499999960f, -0.00039672851562500005f, + -0.00180053710937500000f, -0.00479125976562500000f, + 0.00024414062500000000f, -0.00408935546875000000f, + 0.00064086914062500000f, -0.00122070312500000000f, + 0.00177001953125000000f, -0.00064086914062500000f, + 0.00592041015625000000f, -0.00842285156250000000f, + 0.00296020507812500000f, 0.00851440429687500000f, + -0.00170898437500000000f, -0.00427246093750000000f, + 0.00381469726562499960f, 0.00173950195312500000f, + -0.00561523437500000000f, -0.00622558593750000000f, + -0.00213623046875000000f, -0.00006103515625000000f, + 0.00390625000000000000f, -0.00616455078125000000f, + -0.00238037109375000000f, 0.00701904296875000090f, + -0.00070190429687500000f, 0.00491333007812500000f, + -0.00311279296875000000f, 0.00003051757812500000f, + 0.00003051757812500000f, 0.00549316406250000000f, + -0.00094604492187500000f, -0.00262451171875000000f, + -0.00509643554687500000f, -0.00173950195312500000f, + -0.00183105468749999980f, 0.00082397460937500000f, + -0.00039672851562500005f, 0.00302124023437500040f, + 0.00329589843750000000f, 0.00338745117187500000f, + 0.00231933593750000000f, 0.00210571289062500000f, + 0.00103759765625000000f, -0.00064086914062500000f, + 0.00161743164062500000f, 0.00115966796875000000f, + 0.00103759765625000000f, 0.00238037109375000000f, + 0.00222778320312500000f, 0.00668334960937500090f, + 0.00155639648437500000f, 0.00045776367187499995f, + -0.00219726562500000000f, -0.00314331054687500000f, + -0.00631713867187499910f, 0.00091552734374999989f, + 0.00650024414062500000f, -0.00042724609375000000f, + 0.00094604492187500000f, -0.00286865234375000000f, + -0.00122070312500000000f, -0.00439453125000000000f, + 0.00204467773437500000f, 0.00012207031250000000f, + 0.00320434570312500000f, 0.00180053710937500000f, + -0.00732421874999999910f, 0.00076293945312500000f, + 0.00744628906250000000f, 0.00210571289062500000f, + 0.00177001953125000000f, 0.00070190429687500000f, + -0.00073242187500000000f, -0.00015258789062500000f, + -0.00045776367187499995f, -0.00405883789062500000f, + -0.00216674804687500000f, -0.00204467773437500000f, + 0.00552368164062500000f, 0.00088500976562500000f, + -0.00137329101562500000f, 0.00369262695312500000f, + 0.00292968750000000000f, 0.00155639648437500000f, + -0.00219726562500000000f, -0.00161743164062500000f, + 0.00170898437500000000f, -0.00466918945312500000f, + -0.00082397460937500000f, 0.00259399414062500000f, + 0.00558471679687500000f, 0.00643920898437500000f, + 0.00320434570312500000f, -0.00103759765625000000f, + -0.00140380859375000000f, 0.00131225585937500000f, + -0.00219726562500000000f, -0.00283813476562499960f, + 0.00109863281250000000f, -0.00390625000000000000f, + 0.00088500976562500000f, 0.00338745117187500000f, + -0.00289916992187500000f, -0.00476074218750000000f, + -0.00546264648437500000f, -0.00717163085937500000f, + 0.00064086914062500000f, -0.00119018554687500000f, + -0.00216674804687500000f, -0.00100708007812500000f, + -0.00186157226562500000f, -0.00769042968750000000f, + 0.00701904296875000090f, -0.00399780273437500000f, + 0.00479125976562500000f, -0.00064086914062500000f, + -0.00259399414062500000f, -0.00085449218750000000f, + -0.00375366210937500000f, 0.00244140625000000000f, + -0.00488281250000000000f, 0.00192260742187500000f, + 0.00143432617187500000f, -0.00018310546875000000f, + -0.00149536132812500000f, -0.00292968750000000000f, + -0.00057983398437500000f, 0.00051879882812500000f, + -0.00177001953125000000f, 0.00051879882812500000f, + -0.00000000000000000000f, -0.00039672851562500005f, + -0.00518798828125000000f, 0.00076293945312500000f, + -0.00106811523437500000f, 0.00180053710937500000f, + 0.00030517578125000000f, -0.00094604492187500000f, + -0.01260375976562500000f, 0.00247192382812500000f, + 0.00189208984375000000f, 0.00054931640625000000f, + -0.00500488281250000000f, 0.00747680664062500000f, + 0.00280761718750000000f, -0.00503540039062499910f, + 0.00128173828125000000f, 0.00079345703125000011f, + 0.00384521484375000000f, -0.00756835937500000000f, + 0.00588989257812500000f, -0.00167846679687500000f, + 0.00048828125000000000f, 0.00119018554687500000f, + 0.00042724609375000000f, 0.00152587890625000000f +}; + +const SKP_Silk_NLSF_CBS_FLP SKP_Silk_NLSF_CB1_16_Stage_info_FLP[ NLSF_MSVQ_CB1_16_STAGES ] = +{ + { 32, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 0 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 0 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 32 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 32 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 40 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 40 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 48 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 48 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 56 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 56 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 64 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 64 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 72 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 72 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 80 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 80 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 88 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 88 ] }, + { 8, &SKP_Silk_NLSF_MSVQ_CB1_16[ 16 * 96 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates[ 96 ] } +}; + +const SKP_Silk_NLSF_CB_FLP SKP_Silk_NLSF_CB1_16_FLP = +{ + NLSF_MSVQ_CB1_16_STAGES, + SKP_Silk_NLSF_CB1_16_Stage_info_FLP, + SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min, + SKP_Silk_NLSF_MSVQ_CB1_16_CDF, + SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr, + SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx +}; + diff --git a/src_FLP/SKP_Silk_tables_other_FLP.c b/src_FLP/SKP_Silk_tables_other_FLP.c new file mode 100644 index 000000000..1531446fc --- /dev/null +++ b/src_FLP/SKP_Silk_tables_other_FLP.c @@ -0,0 +1,36 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_structs_FLP.h" +#include "SKP_Silk_define_FLP.h" +#include "SKP_Silk_perceptual_parameters.h" + +const SKP_float SKP_Silk_HarmShapeFIR_FLP[ HARM_SHAPE_FIR_TAPS ] = { 16384.0f / 65536.0f, 32767.0f / 65536.0f, 16384.0f / 65536.0f }; + +const SKP_float SKP_Silk_Quantization_Offsets[ 2 ][ 2 ] = { + { OFFSET_VL_Q10 / 1024.0f, OFFSET_VH_Q10 / 1024.0f }, { OFFSET_UVL_Q10 / 1024.0f, OFFSET_UVH_Q10 / 1024.0f } +}; diff --git a/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c b/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c new file mode 100644 index 000000000..5ed5dc8a9 --- /dev/null +++ b/src_FLP/SKP_Silk_warped_autocorrelation_FLP.c @@ -0,0 +1,69 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Autocorrelations for a warped frequency axis */ +void SKP_Silk_warped_autocorrelation_FLP( + SKP_float *corr, /* O Result [order + 1] */ + const SKP_float *input, /* I Input data to correlate */ + const SKP_float warping, /* I Warping coefficient */ + const SKP_int length, /* I Length of input */ + const SKP_int order /* I Correlation order (even) */ +) +{ + SKP_int n, i; + double tmp1, tmp2; + double state[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; + double C[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; + + /* Order must be even */ + SKP_assert( ( order & 1 ) == 0 ); + + /* Loop over samples */ + for( n = 0; n < length; n++ ) { + tmp1 = input[ n ]; + /* Loop over allpass sections */ + for( i = 0; i < order; i += 2 ) { + /* Output of allpass section */ + tmp2 = state[ i ] + warping * ( state[ i + 1 ] - tmp1 ); + state[ i ] = tmp1; + C[ i ] += state[ 0 ] * tmp1; + /* Output of allpass section */ + tmp1 = state[ i + 1 ] + warping * ( state[ i + 2 ] - tmp2 ); + state[ i + 1 ] = tmp2; + C[ i + 1 ] += state[ 0 ] * tmp2; + } + state[ order ] = tmp1; + C[ order ] += state[ 0 ] * tmp1; + } + + /* Copy correlations in SKP_float output format */ + for( i = 0; i < order + 1; i++ ) { + corr[ i ] = ( SKP_float )C[ i ]; + } +} diff --git a/src_FLP/SKP_Silk_wrappers_FLP.c b/src_FLP/SKP_Silk_wrappers_FLP.c new file mode 100644 index 000000000..41da37928 --- /dev/null +++ b/src_FLP/SKP_Silk_wrappers_FLP.c @@ -0,0 +1,245 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main_FLP.h" + +/* Wrappers. Calls flp / fix code */ + +/* Convert AR filter coefficients to NLSF parameters */ +void SKP_Silk_A2NLSF_FLP( + SKP_float *pNLSF, /* O NLSF vector [ LPC_order ] */ + const SKP_float *pAR, /* I LPC coefficients [ LPC_order ] */ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_int i; + SKP_int NLSF_fix[ MAX_LPC_ORDER ]; + SKP_int32 a_fix_Q16[ MAX_LPC_ORDER ]; + + for( i = 0; i < LPC_order; i++ ) { + a_fix_Q16[ i ] = SKP_float2int( pAR[ i ] * 65536.0f ); + } + SKP_Silk_A2NLSF( NLSF_fix, a_fix_Q16, LPC_order ); + + for( i = 0; i < LPC_order; i++ ) { + pNLSF[ i ] = ( SKP_float )NLSF_fix[ i ] * ( 1.0f / 32768.0f ); + } +} + +/* Convert LSF parameters to AR prediction filter coefficients */ +void SKP_Silk_NLSF2A_stable_FLP( + SKP_float *pAR, /* O LPC coefficients [ LPC_order ] */ + const SKP_float *pNLSF, /* I NLSF vector [ LPC_order ] */ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_int i; + SKP_int NLSF_fix[ MAX_LPC_ORDER ]; + SKP_int16 a_fix_Q12[ MAX_LPC_ORDER ]; + + for( i = 0; i < LPC_order; i++ ) { + NLSF_fix[ i ] = ( SKP_int )SKP_CHECK_FIT16( SKP_float2int( pNLSF[ i ] * 32768.0f ) ); + } + + SKP_Silk_NLSF2A_stable( a_fix_Q12, NLSF_fix, LPC_order ); + + for( i = 0; i < LPC_order; i++ ) { + pAR[ i ] = ( SKP_float )a_fix_Q12[ i ] / 4096.0f; + } +} + + +/* LSF stabilizer, for a single input data vector */ +void SKP_Silk_NLSF_stabilize_FLP( + SKP_float *pNLSF, /* I/O (Un)stable NLSF vector [ LPC_order ] */ + const SKP_float *pNDelta_min, /* I Normalized delta min vector[LPC_order+1]*/ + const SKP_int LPC_order /* I LPC order */ +) +{ + SKP_int i; + SKP_int NLSF_Q15[ MAX_LPC_ORDER ], ndelta_min_Q15[ MAX_LPC_ORDER + 1 ]; + + for( i = 0; i < LPC_order; i++ ) { + NLSF_Q15[ i ] = ( SKP_int )SKP_float2int( pNLSF[ i ] * 32768.0f ); + ndelta_min_Q15[ i ] = ( SKP_int )SKP_float2int( pNDelta_min[ i ] * 32768.0f ); + } + ndelta_min_Q15[ LPC_order ] = ( SKP_int )SKP_float2int( pNDelta_min[ LPC_order ] * 32768.0f ); + + /* NLSF stabilizer, for a single input data vector */ + SKP_Silk_NLSF_stabilize( NLSF_Q15, ndelta_min_Q15, LPC_order ); + + for( i = 0; i < LPC_order; i++ ) { + pNLSF[ i ] = ( SKP_float )NLSF_Q15[ i ] * ( 1.0f / 32768.0f ); + } +} + +/* Interpolation function with fixed point rounding */ +void SKP_Silk_interpolate_wrapper_FLP( + SKP_float xi[], /* O Interpolated vector */ + const SKP_float x0[], /* I First vector */ + const SKP_float x1[], /* I Second vector */ + const SKP_float ifact, /* I Interp. factor, weight on second vector */ + const SKP_int d /* I Number of parameters */ +) +{ + SKP_int x0_int[ MAX_LPC_ORDER ], x1_int[ MAX_LPC_ORDER ], xi_int[ MAX_LPC_ORDER ]; + SKP_int ifact_Q2 = ( SKP_int )( ifact * 4.0f ); + SKP_int i; + + /* Convert input from flp to fix */ + for( i = 0; i < d; i++ ) { + x0_int[ i ] = SKP_float2int( x0[ i ] * 32768.0f ); + x1_int[ i ] = SKP_float2int( x1[ i ] * 32768.0f ); + } + + /* Interpolate two vectors */ + SKP_Silk_interpolate( xi_int, x0_int, x1_int, ifact_Q2, d ); + + /* Convert output from fix to flp */ + for( i = 0; i < d; i++ ) { + xi[ i ] = ( SKP_float )xi_int[ i ] * ( 1.0f / 32768.0f ); + } +} + +/****************************************/ +/* Floating-point Silk VAD wrapper */ +/****************************************/ +SKP_int SKP_Silk_VAD_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_int16 *pIn /* I Input signal */ +) +{ + SKP_int i, ret, SA_Q8, Tilt_Q15; + SKP_int Quality_Bands_Q15[ VAD_N_BANDS ]; + + ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &SA_Q8, Quality_Bands_Q15, &Tilt_Q15, + pIn, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz ); + + psEnc->speech_activity = ( SKP_float )SA_Q8 / 256.0f; + for( i = 0; i < VAD_N_BANDS; i++ ) { + psEncCtrl->input_quality_bands[ i ] = ( SKP_float )Quality_Bands_Q15[ i ] / 32768.0f; + } + psEncCtrl->input_tilt = ( SKP_float )Tilt_Q15 / 32768.0f; + + return ret; +} + +/****************************************/ +/* Floating-point Silk NSQ wrapper */ +/****************************************/ +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 */ +) +{ + SKP_int i, j; + SKP_float tmp_float; + SKP_int16 x_16[ MAX_FRAME_LENGTH ]; + /* Prediction and coding parameters */ + SKP_int32 Gains_Q16[ MAX_NB_SUBFR ]; + SKP_array_of_int16_4_byte_aligned( PredCoef_Q12[ 2 ], MAX_LPC_ORDER ); + SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; + 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; + SKP_int Tilt_Q14[ MAX_NB_SUBFR ]; + SKP_int HarmShapeGain_Q14[ MAX_NB_SUBFR ]; + + /* Convert control struct to fix control struct */ + /* Noise shape parameters */ + for( i = 0; i < MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER; i++ ) { + AR2_Q13[ i ] = (SKP_int16)SKP_SAT16( SKP_float2int( psEncCtrl->AR2[ i ] * 8192.0f ) ); + } + + for( i = 0; i < MAX_NB_SUBFR; i++ ) { + LF_shp_Q14[ i ] = SKP_LSHIFT32( SKP_float2int( psEncCtrl->LF_AR_shp[ i ] * 16384.0f ), 16 ) | + (SKP_uint16)SKP_float2int( psEncCtrl->LF_MA_shp[ i ] * 16384.0f ); + Tilt_Q14[ i ] = (SKP_int)SKP_float2int( psEncCtrl->Tilt[ i ] * 16384.0f ); + HarmShapeGain_Q14[ i ] = (SKP_int)SKP_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f ); + } + Lambda_Q10 = ( SKP_int )SKP_float2int( psEncCtrl->Lambda * 1024.0f ); + + /* prediction and coding parameters */ + for( i = 0; i < MAX_NB_SUBFR * LTP_ORDER; i++ ) { + LTPCoef_Q14[ i ] = ( SKP_int16 )SKP_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f ); + } + + for( j = 0; j < MAX_NB_SUBFR >> 1; j++ ) { + for( i = 0; i < MAX_LPC_ORDER; i++ ) { + PredCoef_Q12[ j ][ i ] = ( SKP_int16 )SKP_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f ); + } + } + + for( i = 0; i < MAX_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 ); + } + } + + if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) { + LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ]; + } else { + LTP_scale_Q14 = 0; + } + + /* Convert input to fix */ + SKP_float2short_array( x_16, x, psEnc->sCmn.frame_length ); + + /* Call NSQ */ + if( useLBRR ) { + if( psEnc->sCmn.nStatesDelayedDecision > 1 ) { + 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 ); + } + } else { + if( psEnc->sCmn.nStatesDelayedDecision > 1 ) { + 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 ); + } + } +} diff --git a/src_FLP/Silk_FLP.vcproj b/src_FLP/Silk_FLP.vcproj new file mode 100644 index 000000000..9decc1e01 --- /dev/null +++ b/src_FLP/Silk_FLP.vcproj @@ -0,0 +1,328 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="Silk_FLP" + ProjectGUID="{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_common;../src_SigProc_FLP;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_FLP_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_common;../src_SigProc_FLP;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;HAVE_CONFIG_H" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_FLP_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_apply_sine_window_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_control_codec_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_corrMatrix_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_frame_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_LPC_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_LTP_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_pitch_lags_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_find_pred_coefs_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_HP_variable_cutoff_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_init_encoder_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_analysis_filter_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LTP_analysis_filter_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LTP_scale_ctrl_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_MSVQ_decode_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_MSVQ_encode_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_rate_distortion_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_sum_error_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_noise_shape_analysis_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_prefilter_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_process_gains_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_process_NLSFs_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_quant_LTP_gains_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_regularize_correlations_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_residual_energy_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_solve_LS_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_10_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_16_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_10_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_16_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_other_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_VQ_nearest_neighbor_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_warped_autocorrelation_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_wrappers_FLP.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_assembler_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_define_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_main_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_perceptual_parameters_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_structs_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_FLP.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src/SKP_Silk_A2NLSF.c b/src_SigProc_FIX/SKP_Silk_A2NLSF.c similarity index 96% rename from src/SKP_Silk_A2NLSF.c rename to src_SigProc_FIX/SKP_Silk_A2NLSF.c index f8e56ca78..23c1760b6 100644 --- a/src/SKP_Silk_A2NLSF.c +++ b/src_SigProc_FIX/SKP_Silk_A2NLSF.c @@ -57,7 +57,6 @@ SKP_INLINE void SKP_Silk_A2NLSF_trans_poly( p[ k - 2 ] -= SKP_LSHIFT( p[ k ], 1 ); } } - /* Helper function for A2NLSF(..) */ /* Polynomial evaluation */ SKP_INLINE SKP_int32 SKP_Silk_A2NLSF_eval_poly( /* return the polynomial evaluation, in QPoly */ @@ -127,8 +126,8 @@ void SKP_Silk_A2NLSF( SKP_int32 xlo, xhi, xmid; SKP_int32 ylo, yhi, ymid; SKP_int32 nom, den; - SKP_int32 P[ SigProc_MAX_ORDER_LPC / 2 + 1 ]; - SKP_int32 Q[ SigProc_MAX_ORDER_LPC / 2 + 1 ]; + SKP_int32 P[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ]; + SKP_int32 Q[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ]; SKP_int32 *PQ[ 2 ]; SKP_int32 *p; diff --git a/src/SKP_Silk_Inlines.h b/src_SigProc_FIX/SKP_Silk_Inlines.h similarity index 90% rename from src/SKP_Silk_Inlines.h rename to src_SigProc_FIX/SKP_Silk_Inlines.h index 66a09bd71..6eb0bb1a7 100644 --- a/src/SKP_Silk_Inlines.h +++ b/src_SigProc_FIX/SKP_Silk_Inlines.h @@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /*! \file SKP_Silk_Inlines.h - * \brief SigProcFix_Inlines.h defines inline signal processing functions. + * \brief SKP_Silk_Inlines.h defines inline signal processing functions. */ #ifndef _SKP_SILK_FIX_INLINES_H_ @@ -57,20 +57,15 @@ SKP_INLINE void SKP_Silk_CLZ_FRAC(SKP_int32 in, /* I: input */ SKP_int32 *lz, /* O: number of leading zeros */ SKP_int32 *frac_Q7) /* O: the 7 bits right after the leading one */ { - SKP_int32 leadingZeros; + SKP_int32 lzeros = SKP_Silk_CLZ32(in); - leadingZeros = SKP_Silk_CLZ32(in); - *lz = leadingZeros; - if( leadingZeros < 24 ) { - *frac_Q7 = SKP_RSHIFT(in, 24 - leadingZeros) & 0x7F; - } else { - *frac_Q7 = SKP_LSHIFT(in, leadingZeros - 24) & 0x7F; - } + * lz = lzeros; + * frac_Q7 = SKP_ROR32(in, 24 - lzeros) & 0x7f; } /* Approximation of square root */ -/* Accuracy: < +/- 10% for output values > 15 */ -/* < +/- 2.5% for output values > 120 */ +/* Accuracy: < +/- 10% for output values > 15 */ +/* < +/- 2.5% for output values > 120 */ SKP_INLINE SKP_int32 SKP_Silk_SQRT_APPROX(SKP_int32 x) { SKP_int32 y, lz, frac_Q7; @@ -125,9 +120,9 @@ SKP_INLINE SKP_int32 SKP_Silk_norm32(SKP_int32 a) { /* Divide two int32 values and return result as int32 in a given Q-domain */ SKP_INLINE SKP_int32 SKP_DIV32_varQ( /* O returns a good approximation of "(a32 << Qres) / b32" */ - const SKP_int32 a32, /* I numerator (Q0) */ - const SKP_int32 b32, /* I denominator (Q0) */ - const SKP_int Qres /* I Q-domain of result (>= 0) */ + const SKP_int32 a32, /* I numerator (Q0) */ + const SKP_int32 b32, /* I denominator (Q0) */ + const SKP_int Qres /* I Q-domain of result (>= 0) */ ) { SKP_int a_headrm, b_headrm, lshift; @@ -170,8 +165,8 @@ SKP_INLINE SKP_int32 SKP_DIV32_varQ( /* O returns a good approximation of /* Invert int32 value and return result as int32 in a given Q-domain */ SKP_INLINE SKP_int32 SKP_INVERSE32_varQ( /* O returns a good approximation of "(1 << Qres) / b32" */ - const SKP_int32 b32, /* I denominator (Q0) */ - const SKP_int Qres /* I Q-domain of result (> 0) */ + const SKP_int32 b32, /* I denominator (Q0) */ + const SKP_int Qres /* I Q-domain of result (> 0) */ ) { SKP_int b_headrm, lshift; diff --git a/src/SKP_Silk_LPC_inv_pred_gain.c b/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c similarity index 69% rename from src/SKP_Silk_LPC_inv_pred_gain.c rename to src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c index a350a6f40..c4f0e204e 100644 --- a/src/SKP_Silk_LPC_inv_pred_gain.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c @@ -31,30 +31,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Compute inverse of LPC prediction gain, and * * test if LPC coefficients are stable (all poles within unit circle) * * * - * Copyright 2008 (c), Skype Limited * + * Copyright 2008 (c), Skype Limited * * */ #include "SKP_Silk_SigProc_FIX.h" #define QA 16 -#define A_LIMIT 65520 +#define A_LIMIT SKP_FIX_CONST( 0.99975, QA ) /* Compute inverse of LPC prediction gain, and */ /* test if LPC coefficients are stable (all poles within unit circle) */ -SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise 0 */ +static SKP_int LPC_inverse_pred_gain_QA( /* O: Returns 1 if unstable, otherwise 0 */ SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ - const SKP_int16 *A_Q12, /* I: Prediction coefficients, Q12 [order] */ + SKP_int32 A_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ], + /* I: Prediction coefficients */ const SKP_int order /* I: Prediction order */ ) { SKP_int k, n, headrm; - SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16; - SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA; + SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16, tmp_QA; SKP_int32 *Aold_QA, *Anew_QA; - Anew_QA = Atmp_QA[ order & 1 ]; - /* Increase Q domain of the AR coefficients */ - for( k = 0; k < order; k++ ) { - Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 ); - } + Anew_QA = A_QA[ order & 1 ]; *invGain_Q30 = ( 1 << 30 ); for( k = order - 1; k > 0; k-- ) { @@ -82,7 +78,7 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, oth /* Swap pointers */ Aold_QA = Anew_QA; - Anew_QA = Atmp_QA[ k & 1 ]; + Anew_QA = A_QA[ k & 1 ]; /* Update AR coefficient */ headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1; @@ -113,77 +109,65 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, oth return 0; } -/* For input in Q13 domain */ -SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13( /* O: Returns 1 if unstable, otherwise 0 */ +/* For input in Q12 domain */ +SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise 0 */ SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ - const SKP_int16 *A_Q13, /* I: Prediction coefficients, Q13 [order] */ + const SKP_int16 *A_Q12, /* I: Prediction coefficients, Q12 [order] */ const SKP_int order /* I: Prediction order */ ) { - SKP_int k, n, headrm; - SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16; - SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA; - SKP_int32 *Aold_QA, *Anew_QA; + SKP_int k; + SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ]; + SKP_int32 *Anew_QA; Anew_QA = Atmp_QA[ order & 1 ]; + /* Increase Q domain of the AR coefficients */ for( k = 0; k < order; k++ ) { - Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q13[ k ], QA - 13 ); + Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 ); } - *invGain_Q30 = ( 1 << 30 ); - for( k = order - 1; k > 0; k-- ) { - /* Check for stability */ - if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) { - return 1; - } - - /* Set RC equal to negated AR coef */ - rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA ); - - /* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */ - rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 ); - SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */ - SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) ); + return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order ); +} - /* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */ - rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 ); /* 16 = 46 - 30 */ +/* For input in Q13 domain */ +SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13( /* O: Returns 1 if unstable, otherwise 0 */ + SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ + const SKP_int16 *A_Q13, /* I: Prediction coefficients, Q13 [order] */ + const SKP_int order /* I: Prediction order */ +) +{ + SKP_int k; + SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ]; + SKP_int32 *Anew_QA; - /* Update inverse gain */ - /* invGain_Q30 range: [ 0 : 2^30 ] */ - *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 ); - SKP_assert( *invGain_Q30 >= 0 ); - SKP_assert( *invGain_Q30 <= 1<<30 ); + Anew_QA = Atmp_QA[ order & 1 ]; - /* Swap pointers */ - Aold_QA = Anew_QA; - Anew_QA = Atmp_QA[ k & 1 ]; - - /* Update AR coefficient */ - headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1; - rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm ); /* Q: 16 + headrm */ - for( n = 0; n < k; n++ ) { - tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 ); - Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm ); - } + /* Increase Q domain of the AR coefficients */ + for( k = 0; k < order; k++ ) { + Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q13[ k ], QA - 13 ); } - /* Check for stability */ - if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) { - return 1; - } + return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order ); +} - /* Set RC equal to negated AR coef */ - rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA ); +/* For input in Q24 domain */ +SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O: Returns 1 if unstable, otherwise 0 */ + SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ + const SKP_int32 *A_Q24, /* I: Prediction coefficients, Q24 [order] */ + const SKP_int order /* I: Prediction order */ +) +{ + SKP_int k; + SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ]; + SKP_int32 *Anew_QA; - /* Range: [ 1 : 2^30 ] */ - rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 ); + Anew_QA = Atmp_QA[ order & 1 ]; - /* Update inverse gain */ - /* Range: [ 0 : 2^30 ] */ - *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 ); - SKP_assert( *invGain_Q30 >= 0 ); - SKP_assert( *invGain_Q30 <= 1<<30 ); + /* Increase Q domain of the AR coefficients */ + for( k = 0; k < order; k++ ) { + Anew_QA[ k ] = SKP_RSHIFT_ROUND( A_Q24[ k ], 24 - QA ); + } - return 0; + return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order ); } diff --git a/src/SKP_Silk_LPC_stabilize.c b/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c similarity index 94% rename from src/SKP_Silk_LPC_stabilize.c rename to src_SigProc_FIX/SKP_Silk_LPC_stabilize.c index bd58d1098..8d64c8c86 100644 --- a/src/SKP_Silk_LPC_stabilize.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_stabilize.c @@ -102,9 +102,10 @@ void SKP_Silk_LPC_fit( /***************************/ /* Limit the maximum absolute value of the prediction coefficients */ while( SKP_TRUE ) { - /* Find maximum absolute value and its index */ + /* Find maximum absolute value and its index; assumes stable coefficients */ + /* so that only the first half need to be tested */ maxabs = SKP_int32_MIN; - for( i = 0; i < L; i++ ) { + for( i = 1; i < L / 2; i++ ) { absval = SKP_abs( a_Q24[ i ] ); if( absval > maxabs ) { maxabs = absval; diff --git a/src/SKP_Silk_LPC_synthesis_filter.c b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c similarity index 66% rename from src/SKP_Silk_LPC_synthesis_filter.c rename to src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c index fff5e7001..c7916f359 100644 --- a/src/SKP_Silk_LPC_synthesis_filter.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_filter.c @@ -45,54 +45,40 @@ void SKP_Silk_LPC_synthesis_filter( ) { SKP_int k, j, idx, Order_half = SKP_RSHIFT( Order, 1 ); - SKP_int32 SA, SB, Atmp, A_align_Q12[SigProc_MAX_ORDER_LPC >> 1], out32_Q10, out32; + SKP_int32 SA, SB, out32_Q10, out32; /* Order must be even */ - SKP_assert( 2*Order_half == Order ); - - /* combine two A_Q12 values and ensure 32-bit alignment */ - for( k = 0; k < Order_half; k++ ) { - idx = SKP_SMULBB( 2, k ); - A_align_Q12[k] = (((SKP_int32)A_Q12[idx]) & 0x0000ffff) | SKP_LSHIFT( (SKP_int32)A_Q12[idx+1], 16 ); - } + SKP_assert( 2 * Order_half == Order ); /* S[] values are in Q14 */ for( k = 0; k < len; k++ ) { - SA = S[Order-1]; + SA = S[ Order - 1 ]; out32_Q10 = 0; - for( j=0;j<(Order_half-1); j++ ) { + for( j = 0; j < ( Order_half - 1 ); j++ ) { idx = SKP_SMULBB( 2, j ) + 1; - /* multiply-add two prediction coefficients for each loop */ - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ - Atmp = A_align_Q12[j]; - SB = S[Order - 1 - idx]; - S[Order - 1 - idx] = SA; - out32_Q10 = SKP_SMLAWB( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT( out32_Q10, SB, Atmp ); - SA = S[Order - 2 - idx]; - S[Order - 2 - idx] = SB; + SB = S[ Order - 1 - idx ]; + S[ Order - 1 - idx ] = SA; + out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ ( j << 1 ) ] ); + out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ ( j << 1 ) + 1 ] ); + SA = S[ Order - 2 - idx ]; + S[ Order - 2 - idx ] = SB; } /* unrolled loop: epilog */ - Atmp = A_align_Q12[Order_half-1]; - SB = S[0]; - S[0] = SA; - out32_Q10 = SKP_SMLAWB( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT( out32_Q10, SB, Atmp ); - + SB = S[ 0 ]; + S[ 0 ] = SA; + out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ Order - 2 ] ); + out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ Order - 1 ] ); /* apply gain to excitation signal and add to prediction */ - out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[k] ) ); + out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) ); /* scale to Q0 */ out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 ); /* saturate output */ - out[k] = (SKP_int16)SKP_SAT16( out32 ); + out[ k ] = ( SKP_int16 )SKP_SAT16( out32 ); /* move result into delay line */ - S[Order - 1] = SKP_LSHIFT_SAT32( out32_Q10, 4 ); + S[ Order - 1 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 ); } } diff --git a/src/SKP_Silk_LPC_synthesis_order16.c b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c similarity index 55% rename from src/SKP_Silk_LPC_synthesis_order16.c rename to src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c index ec2d35857..2b9c6a476 100644 --- a/src/SKP_Silk_LPC_synthesis_order16.c +++ b/src_SigProc_FIX/SKP_Silk_LPC_synthesis_order16.c @@ -43,98 +43,79 @@ void SKP_Silk_LPC_synthesis_order16(const SKP_int16 *in, /* I: excita ) { SKP_int k; - SKP_int32 SA, SB, Atmp, A_align_Q12[8], out32_Q10, out32; - - /* combine two A_Q12 values and ensure 32-bit alignment */ - for( k = 0; k < 8; k++ ) { - A_align_Q12[k] = (((SKP_int32)A_Q12[ 2*k ]) & 0x0000ffff) | SKP_LSHIFT( (SKP_int32)A_Q12[ 2*k + 1 ], 16 ); - } - - /* S[] values are in Q14 */ - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ + SKP_int32 SA, SB, out32_Q10, out32; for( k = 0; k < len; k++ ) { /* unrolled loop: prolog */ /* multiply-add two prediction coefficients per iteration */ - SA = S[15]; - Atmp = A_align_Q12[0]; - SB = S[14]; - S[14] = SA; - out32_Q10 = SKP_SMULWB( SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[13]; - S[13] = SB; + SA = S[ 15 ]; + SB = S[ 14 ]; + S[ 14 ] = SA; + out32_Q10 = SKP_SMULWB( SA, A_Q12[ 0 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 1 ] ); + SA = S[ 13 ]; + S[ 13 ] = SB; /* unrolled loop: main loop */ - Atmp = A_align_Q12[1]; - SB = S[12]; - S[12] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[11]; - S[11] = SB; - - Atmp = A_align_Q12[2]; - SB = S[10]; - S[10] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[9]; - S[9] = SB; - - Atmp = A_align_Q12[3]; - SB = S[8]; - S[8] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[7]; - S[7] = SB; - - Atmp = A_align_Q12[4]; - SB = S[6]; - S[6] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[5]; - S[5] = SB; - - Atmp = A_align_Q12[5]; - SB = S[4]; - S[4] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[3]; - S[3] = SB; - - Atmp = A_align_Q12[6]; - SB = S[2]; - S[2] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); - SA = S[1]; - S[1] = SB; + SB = S[ 12 ]; + S[ 12 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 2 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 3 ] ); + SA = S[ 11 ]; + S[ 11 ] = SB; + + SB = S[ 10 ]; + S[ 10 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 4 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 5 ] ); + SA = S[ 9 ]; + S[ 9 ] = SB; + + SB = S[ 8 ]; + S[ 8 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 6 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 7 ] ); + SA = S[ 7 ]; + S[ 7 ] = SB; + + SB = S[ 6 ]; + S[ 6 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 8 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 9 ] ); + SA = S[ 5 ]; + S[ 5 ] = SB; + + SB = S[ 4 ]; + S[ 4 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 10 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 11 ] ); + SA = S[ 3 ]; + S[ 3 ] = SB; + + SB = S[ 2 ]; + S[ 2 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 12 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 13 ] ); + SA = S[ 1 ]; + S[ 1 ] = SB; /* unrolled loop: epilog */ - Atmp = A_align_Q12[7]; - SB = S[0]; - S[0] = SA; - out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp ); - out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp ); + SB = S[ 0 ]; + S[ 0 ] = SA; + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 14 ] ); + out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 15 ] ); /* unrolled loop: end */ /* apply gain to excitation signal and add to prediction */ - out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[k] ) ); + out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) ); /* scale to Q0 */ out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 ); /* saturate output */ - out[k] = (SKP_int16)SKP_SAT16( out32 ); + out[ k ] = ( SKP_int16 )SKP_SAT16( out32 ); /* move result into delay line */ - S[15] = SKP_LSHIFT_SAT32( out32_Q10, 4 ); + S[ 15 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 ); } } diff --git a/src/SKP_Silk_LSF_cos_table.c b/src_SigProc_FIX/SKP_Silk_LSF_cos_table.c similarity index 100% rename from src/SKP_Silk_LSF_cos_table.c rename to src_SigProc_FIX/SKP_Silk_LSF_cos_table.c diff --git a/src/SKP_Silk_MA.c b/src_SigProc_FIX/SKP_Silk_MA.c similarity index 57% rename from src/SKP_Silk_MA.c rename to src_SigProc_FIX/SKP_Silk_MA.c index cdfaca7cf..3470a92f6 100644 --- a/src/SKP_Silk_MA.c +++ b/src_SigProc_FIX/SKP_Silk_MA.c @@ -74,47 +74,19 @@ void SKP_Silk_MA_Prediction( { SKP_int k, d, in16; SKP_int32 out32; - SKP_int32 B32; - if( ( order & 1 ) == 0 && (SKP_int32)( (SKP_int_ptr_size)B & 3 ) == 0 ) { - /* Even order and 4-byte aligned coefficient array */ - - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLABB and SMLABT instructions should solve the problem. */ - 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 - 2; d += 2 ) { - B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */ - S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B32 ); - S[ d + 1 ] = SKP_SMLABT_ovflw( S[ d + 2 ], in16, B32 ); - } - B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */ - S[ order - 2 ] = SKP_SMLABB_ovflw( S[ order - 1 ], in16, B32 ); - S[ order - 1 ] = SKP_SMULBT( in16, B32 ); - - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( 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 ] ); } - } else { - /* Odd order or not 4-byte aligned coefficient array */ - 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 ] ); + S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] ); - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); - } + /* Limit */ + out[ k ] = (SKP_int16)SKP_SAT16( out32 ); } } @@ -128,51 +100,22 @@ void SKP_Silk_MA_Prediction_Q13( ) { SKP_int k, d, in16; - SKP_int32 out32, B32; - - if( ( order & 1 ) == 0 && (SKP_int32)( (SKP_int_ptr_size)B & 3 ) == 0 ) { - /* Even order and 4-byte aligned coefficient array */ + 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 ); - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLABB and SMLABT instructions should solve the problem. */ - 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 - 2; d += 2 ) { - B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */ - S[ d ] = SKP_SMLABB( S[ d + 1 ], in16, B32 ); - S[ d + 1 ] = SKP_SMLABT( S[ d + 2 ], in16, B32 ); - } - B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */ - S[ order - 2 ] = SKP_SMLABB( S[ order - 1 ], in16, B32 ); - S[ order - 1 ] = SKP_SMULBT( in16, B32 ); - - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); + for( d = 0; d < order - 1; d++ ) { + S[ d ] = SKP_SMLABB( S[ d + 1 ], in16, B[ d ] ); } - } else { - /* Odd order or not 4-byte aligned coefficient array */ - 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 ] ); + S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] ); - /* Limit */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); - } + /* Limit */ + out[ k ] = ( SKP_int16 )SKP_SAT16( out32 ); } } -/* Variable order MA prediction error filter. */ -/* Inverse filter of SKP_Silk_LPC_synthesis_filter */ + void SKP_Silk_LPC_analysis_filter( const SKP_int16 *in, /* I: Input signal */ const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */ @@ -183,17 +126,11 @@ void SKP_Silk_LPC_analysis_filter( ) { SKP_int k, j, idx, Order_half = SKP_RSHIFT( Order, 1 ); - SKP_int32 Btmp, B_align_Q12[ SigProc_MAX_ORDER_LPC >> 1 ], out32_Q12, out32; + SKP_int32 out32_Q12, out32; SKP_int16 SA, SB; /* Order must be even */ SKP_assert( 2 * Order_half == Order ); - /* Combine two A_Q12 values and ensure 32-bit alignment */ - for( k = 0; k < Order_half; k++ ) { - idx = SKP_SMULBB( 2, k ); - B_align_Q12[ k ] = ( ( (SKP_int32)B[ idx ] ) & 0x0000ffff ) | SKP_LSHIFT( (SKP_int32)B[ idx + 1 ], 16 ); - } - /* S[] values are in Q0 */ for( k = 0; k < len; k++ ) { SA = S[ 0 ]; @@ -201,21 +138,19 @@ void SKP_Silk_LPC_analysis_filter( for( j = 0; j < ( Order_half - 1 ); j++ ) { idx = SKP_SMULBB( 2, j ) + 1; /* Multiply-add two prediction coefficients for each loop */ - Btmp = B_align_Q12[ j ]; SB = S[ idx ]; S[ idx ] = SA; - out32_Q12 = SKP_SMLABB( out32_Q12, SA, Btmp ); - out32_Q12 = SKP_SMLABT( out32_Q12, SB, Btmp ); + 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 */ - Btmp = B_align_Q12[ Order_half - 1 ]; SB = S[ Order - 1 ]; S[ Order - 1 ] = SA; - out32_Q12 = SKP_SMLABB( out32_Q12, SA, Btmp ); - out32_Q12 = SKP_SMLABT( out32_Q12, SB, Btmp ); + 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 ); @@ -224,7 +159,7 @@ void SKP_Silk_LPC_analysis_filter( out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 ); /* Saturate output */ - out[ k ] = (SKP_int16)SKP_SAT16( out32 ); + 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 new file mode 100644 index 000000000..93fbe4d11 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_MacroCount.h @@ -0,0 +1,692 @@ +#ifndef _SIGPROCFIX_API_MACROCOUNT_H_ +#define _SIGPROCFIX_API_MACROCOUNT_H_ +#include <stdio.h> + +#ifdef SKP_MACRO_COUNT +#define varDefine SKP_int64 ops_count = 0; + +extern SKP_int64 ops_count; + +SKP_INLINE SKP_int64 SKP_SaveCount(){ + return(ops_count); +} + +SKP_INLINE SKP_int64 SKP_SaveResetCount(){ + SKP_int64 ret; + + ret = ops_count; + ops_count = 0; + return(ret); +} + +SKP_INLINE SKP_PrintCount(){ + printf("ops_count = %d \n ", (SKP_int32)ops_count); +} + +#undef SKP_MUL +SKP_INLINE SKP_int32 SKP_MUL(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ops_count += 4; + ret = a32 * b32; + return ret; +} + +#undef SKP_MUL_uint +SKP_INLINE SKP_uint32 SKP_MUL_uint(SKP_uint32 a32, SKP_uint32 b32){ + SKP_uint32 ret; + ops_count += 4; + ret = a32 * b32; + return ret; +} +#undef SKP_MLA +SKP_INLINE SKP_int32 SKP_MLA(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 4; + ret = a32 + b32 * c32; + return ret; +} + +#undef SKP_MLA_uint +SKP_INLINE SKP_int32 SKP_MLA_uint(SKP_uint32 a32, SKP_uint32 b32, SKP_uint32 c32){ + SKP_uint32 ret; + ops_count += 4; + ret = a32 + b32 * c32; + return ret; +} + +#undef SKP_SMULWB +SKP_INLINE SKP_int32 SKP_SMULWB(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ops_count += 5; + ret = (a32 >> 16) * (SKP_int32)((SKP_int16)b32) + (((a32 & 0x0000FFFF) * (SKP_int32)((SKP_int16)b32)) >> 16); + return ret; +} +#undef SKP_SMLAWB +SKP_INLINE SKP_int32 SKP_SMLAWB(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 5; + ret = ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16))); + return ret; +} + +#undef SKP_SMULWT +SKP_INLINE SKP_int32 SKP_SMULWT(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ops_count += 4; + ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); + return ret; +} +#undef SKP_SMLAWT +SKP_INLINE SKP_int32 SKP_SMLAWT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 4; + ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); + return ret; +} + +#undef SKP_SMULBB +SKP_INLINE SKP_int32 SKP_SMULBB(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ops_count += 1; + ret = (SKP_int32)((SKP_int16)a32) * (SKP_int32)((SKP_int16)b32); + return ret; +} +#undef SKP_SMLABB +SKP_INLINE SKP_int32 SKP_SMLABB(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 1; + ret = a32 + (SKP_int32)((SKP_int16)b32) * (SKP_int32)((SKP_int16)c32); + return ret; +} + +#undef SKP_SMULBT +SKP_INLINE SKP_int32 SKP_SMULBT(SKP_int32 a32, SKP_int32 b32 ){ + SKP_int32 ret; + ops_count += 4; + ret = ((SKP_int32)((SKP_int16)a32)) * (b32 >> 16); + return ret; +} + +#undef SKP_SMLABT +SKP_INLINE SKP_int32 SKP_SMLABT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 1; + ret = a32 + ((SKP_int32)((SKP_int16)b32)) * (c32 >> 16); + return ret; +} + +#undef SKP_SMULTT +SKP_INLINE SKP_int32 SKP_SMULTT(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ops_count += 1; + ret = (a32 >> 16) * (b32 >> 16); + return ret; +} + +#undef SKP_SMLATT +SKP_INLINE SKP_int32 SKP_SMLATT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ops_count += 1; + ret = a32 + (b32 >> 16) * (c32 >> 16); + return ret; +} + + +// multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) +#undef SKP_MLA_ovflw +#define SKP_MLA_ovflw SKP_MLA + +#undef SKP_SMLABB_ovflw +#define SKP_SMLABB_ovflw SKP_SMLABB + +#undef SKP_SMLABT_ovflw +#define SKP_SMLABT_ovflw SKP_SMLABT + +#undef SKP_SMLATT_ovflw +#define SKP_SMLATT_ovflw SKP_SMLATT + +#undef SKP_SMLAWB_ovflw +#define SKP_SMLAWB_ovflw SKP_SMLAWB + +#undef SKP_SMLAWT_ovflw +#define SKP_SMLAWT_ovflw SKP_SMLAWT + +#undef SKP_SMULL +SKP_INLINE SKP_int64 SKP_SMULL(SKP_int32 a32, SKP_int32 b32){ + SKP_int64 ret; + ops_count += 8; + ret = ((SKP_int64)(a32) * /*(SKP_int64)*/(b32)); + return ret; +} + +#undef SKP_SMLAL +SKP_INLINE SKP_int64 SKP_SMLAL(SKP_int64 a64, SKP_int32 b32, SKP_int32 c32){ + SKP_int64 ret; + ops_count += 8; + ret = a64 + ((SKP_int64)(b32) * /*(SKP_int64)*/(c32)); + return ret; +} +#undef SKP_SMLALBB +SKP_INLINE SKP_int64 SKP_SMLALBB(SKP_int64 a64, SKP_int16 b16, SKP_int16 c16){ + SKP_int64 ret; + ops_count += 4; + ret = a64 + ((SKP_int64)(b16) * /*(SKP_int64)*/(c16)); + return ret; +} + +#undef SigProcFIX_CLZ16 +SKP_INLINE SKP_int32 SigProcFIX_CLZ16(SKP_int16 in16) +{ + SKP_int32 out32 = 0; + ops_count += 10; + if( in16 == 0 ) { + return 16; + } + /* test nibbles */ + if( in16 & 0xFF00 ) { + if( in16 & 0xF000 ) { + in16 >>= 12; + } else { + out32 += 4; + in16 >>= 8; + } + } else { + if( in16 & 0xFFF0 ) { + out32 += 8; + in16 >>= 4; + } else { + out32 += 12; + } + } + /* test bits and return */ + if( in16 & 0xC ) { + if( in16 & 0x8 ) + return out32 + 0; + else + return out32 + 1; + } else { + if( in16 & 0xE ) + return out32 + 2; + else + return out32 + 3; + } +} + +#undef SigProcFIX_CLZ32 +SKP_INLINE SKP_int32 SigProcFIX_CLZ32(SKP_int32 in32) +{ + /* test highest 16 bits and convert to SKP_int16 */ + ops_count += 2; + if( in32 & 0xFFFF0000 ) { + return SigProcFIX_CLZ16((SKP_int16)(in32 >> 16)); + } else { + return SigProcFIX_CLZ16((SKP_int16)in32) + 16; + } +} + +#undef SKP_DIV32 +SKP_INLINE SKP_int32 SKP_DIV32(SKP_int32 a32, SKP_int32 b32){ + ops_count += 64; + return a32 / b32; +} + +#undef SKP_DIV32_16 +SKP_INLINE SKP_int32 SKP_DIV32_16(SKP_int32 a32, SKP_int32 b32){ + ops_count += 32; + return a32 / b32; +} + +#undef SKP_SAT8 +SKP_INLINE SKP_int8 SKP_SAT8(SKP_int64 a){ + SKP_int8 tmp; + ops_count += 1; + tmp = (SKP_int8)((a) > SKP_int8_MAX ? SKP_int8_MAX : \ + ((a) < SKP_int8_MIN ? SKP_int8_MIN : (a))); + return(tmp); +} + +#undef SKP_SAT16 +SKP_INLINE SKP_int16 SKP_SAT16(SKP_int64 a){ + SKP_int16 tmp; + ops_count += 1; + tmp = (SKP_int16)((a) > SKP_int16_MAX ? SKP_int16_MAX : \ + ((a) < SKP_int16_MIN ? SKP_int16_MIN : (a))); + return(tmp); +} +#undef SKP_SAT32 +SKP_INLINE SKP_int32 SKP_SAT32(SKP_int64 a){ + SKP_int32 tmp; + ops_count += 1; + tmp = (SKP_int32)((a) > SKP_int32_MAX ? SKP_int32_MAX : \ + ((a) < SKP_int32_MIN ? SKP_int32_MIN : (a))); + return(tmp); +} +#undef SKP_POS_SAT32 +SKP_INLINE SKP_int32 SKP_POS_SAT32(SKP_int64 a){ + SKP_int32 tmp; + ops_count += 1; + tmp = (SKP_int32)((a) > SKP_int32_MAX ? SKP_int32_MAX : (a)); + return(tmp); +} + +#undef SKP_ADD_POS_SAT8 +SKP_INLINE SKP_int8 SKP_ADD_POS_SAT8(SKP_int64 a, SKP_int64 b){ + SKP_int8 tmp; + ops_count += 1; + tmp = (SKP_int8)((((a)+(b)) & 0x80) ? SKP_int8_MAX : ((a)+(b))); + return(tmp); +} +#undef SKP_ADD_POS_SAT16 +SKP_INLINE SKP_int16 SKP_ADD_POS_SAT16(SKP_int64 a, SKP_int64 b){ + SKP_int16 tmp; + ops_count += 1; + tmp = (SKP_int16)((((a)+(b)) & 0x8000) ? SKP_int16_MAX : ((a)+(b))); + return(tmp); +} + +#undef SKP_ADD_POS_SAT32 +SKP_INLINE SKP_int32 SKP_ADD_POS_SAT32(SKP_int64 a, SKP_int64 b){ + SKP_int32 tmp; + ops_count += 1; + tmp = (SKP_int32)((((a)+(b)) & 0x80000000) ? SKP_int32_MAX : ((a)+(b))); + return(tmp); +} + +#undef SKP_ADD_POS_SAT64 +SKP_INLINE SKP_int64 SKP_ADD_POS_SAT64(SKP_int64 a, SKP_int64 b){ + SKP_int64 tmp; + ops_count += 1; + tmp = ((((a)+(b)) & 0x8000000000000000LL) ? SKP_int64_MAX : ((a)+(b))); + return(tmp); +} + +#undef SKP_LSHIFT8 +SKP_INLINE SKP_int8 SKP_LSHIFT8(SKP_int8 a, SKP_int32 shift){ + SKP_int8 ret; + ops_count += 1; + ret = a << shift; + return ret; +} +#undef SKP_LSHIFT16 +SKP_INLINE SKP_int16 SKP_LSHIFT16(SKP_int16 a, SKP_int32 shift){ + SKP_int16 ret; + ops_count += 1; + ret = a << shift; + return ret; +} +#undef SKP_LSHIFT32 +SKP_INLINE SKP_int32 SKP_LSHIFT32(SKP_int32 a, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a << shift; + return ret; +} +#undef SKP_LSHIFT64 +SKP_INLINE SKP_int64 SKP_LSHIFT64(SKP_int64 a, SKP_int shift){ + ops_count += 1; + return a << shift; +} + +#undef SKP_LSHIFT_ovflw +SKP_INLINE SKP_int32 SKP_LSHIFT_ovflw(SKP_int32 a, SKP_int32 shift){ + ops_count += 1; + return a << shift; +} + +#undef SKP_LSHIFT_uint +SKP_INLINE SKP_uint32 SKP_LSHIFT_uint(SKP_uint32 a, SKP_int32 shift){ + SKP_uint32 ret; + ops_count += 1; + ret = a << shift; + return ret; +} + +#undef SKP_RSHIFT8 +SKP_INLINE SKP_int8 SKP_RSHIFT8(SKP_int8 a, SKP_int32 shift){ + ops_count += 1; + return a >> shift; +} +#undef SKP_RSHIFT16 +SKP_INLINE SKP_int16 SKP_RSHIFT16(SKP_int16 a, SKP_int32 shift){ + ops_count += 1; + return a >> shift; +} +#undef SKP_RSHIFT32 +SKP_INLINE SKP_int32 SKP_RSHIFT32(SKP_int32 a, SKP_int32 shift){ + ops_count += 1; + return a >> shift; +} +#undef SKP_RSHIFT64 +SKP_INLINE SKP_int64 SKP_RSHIFT64(SKP_int64 a, SKP_int64 shift){ + ops_count += 1; + return a >> shift; +} + +#undef SKP_RSHIFT_uint +SKP_INLINE SKP_uint32 SKP_RSHIFT_uint(SKP_uint32 a, SKP_int32 shift){ + ops_count += 1; + return a >> shift; +} + +#undef SKP_ADD_LSHIFT +SKP_INLINE SKP_int32 SKP_ADD_LSHIFT(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a + (b << shift); + return ret; // shift >= 0 +} +#undef SKP_ADD_LSHIFT32 +SKP_INLINE SKP_int32 SKP_ADD_LSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a + (b << shift); + return ret; // shift >= 0 +} +#undef SKP_ADD_LSHIFT_uint +SKP_INLINE SKP_uint32 SKP_ADD_LSHIFT_uint(SKP_uint32 a, SKP_uint32 b, SKP_int32 shift){ + SKP_uint32 ret; + ops_count += 1; + ret = a + (b << shift); + return ret; // shift >= 0 +} +#undef SKP_ADD_RSHIFT +SKP_INLINE SKP_int32 SKP_ADD_RSHIFT(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a + (b >> shift); + return ret; // shift > 0 +} +#undef SKP_ADD_RSHIFT32 +SKP_INLINE SKP_int32 SKP_ADD_RSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a + (b >> shift); + return ret; // shift > 0 +} +#undef SKP_ADD_RSHIFT_uint +SKP_INLINE SKP_uint32 SKP_ADD_RSHIFT_uint(SKP_uint32 a, SKP_uint32 b, SKP_int32 shift){ + SKP_uint32 ret; + ops_count += 1; + ret = a + (b >> shift); + return ret; // shift > 0 +} +#undef SKP_SUB_LSHIFT32 +SKP_INLINE SKP_int32 SKP_SUB_LSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a - (b << shift); + return ret; // shift >= 0 +} +#undef SKP_SUB_RSHIFT32 +SKP_INLINE SKP_int32 SKP_SUB_RSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 1; + ret = a - (b >> shift); + return ret; // shift > 0 +} + +#undef SKP_RSHIFT_ROUND +SKP_INLINE SKP_int32 SKP_RSHIFT_ROUND(SKP_int32 a, SKP_int32 shift){ + SKP_int32 ret; + ops_count += 3; + ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; + return ret; +} + +#undef SKP_RSHIFT_ROUND64 +SKP_INLINE SKP_int64 SKP_RSHIFT_ROUND64(SKP_int64 a, SKP_int32 shift){ + SKP_int64 ret; + ops_count += 6; + ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; + return ret; +} + +#undef SKP_abs_int64 +SKP_INLINE SKP_int64 SKP_abs_int64(SKP_int64 a){ + ops_count += 1; + return (((a) > 0) ? (a) : -(a)); // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN +} + +#undef SKP_abs_int32 +SKP_INLINE SKP_int32 SKP_abs_int32(SKP_int32 a){ + ops_count += 1; + return abs(a); +} + + +#undef SKP_min +static SKP_min(a, b){ + ops_count += 1; + return (((a) < (b)) ? (a) : (b)); +} +#undef SKP_max +static SKP_max(a, b){ + ops_count += 1; + return (((a) > (b)) ? (a) : (b)); +} +#undef SKP_sign +static SKP_sign(a){ + ops_count += 1; + return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )); +} + +#undef SKP_ADD16 +SKP_INLINE SKP_int16 SKP_ADD16(SKP_int16 a, SKP_int16 b){ + SKP_int16 ret; + ops_count += 1; + ret = a + b; + return ret; +} + +#undef SKP_ADD32 +SKP_INLINE SKP_int32 SKP_ADD32(SKP_int32 a, SKP_int32 b){ + SKP_int32 ret; + ops_count += 1; + ret = a + b; + return ret; +} + +#undef SKP_ADD64 +SKP_INLINE SKP_int64 SKP_ADD64(SKP_int64 a, SKP_int64 b){ + SKP_int64 ret; + ops_count += 2; + ret = a + b; + return ret; +} + +#undef SKP_SUB16 +SKP_INLINE SKP_int16 SKP_SUB16(SKP_int16 a, SKP_int16 b){ + SKP_int16 ret; + ops_count += 1; + ret = a - b; + return ret; +} + +#undef SKP_SUB32 +SKP_INLINE SKP_int32 SKP_SUB32(SKP_int32 a, SKP_int32 b){ + SKP_int32 ret; + ops_count += 1; + ret = a - b; + return ret; +} + +#undef SKP_SUB64 +SKP_INLINE SKP_int64 SKP_SUB64(SKP_int64 a, SKP_int64 b){ + SKP_int64 ret; + ops_count += 2; + ret = a - b; + return ret; +} + +#undef SKP_ADD_SAT16 +SKP_INLINE SKP_int16 SKP_ADD_SAT16( SKP_int16 a16, SKP_int16 b16 ) { + SKP_int16 res; + // Nb will be counted in AKP_add32 and SKP_SAT16 + res = (SKP_int16)SKP_SAT16( SKP_ADD32( (SKP_int32)(a16), (b16) ) ); + return res; +} + +#undef SKP_ADD_SAT32 +SKP_INLINE SKP_int32 SKP_ADD_SAT32(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 res; + ops_count += 1; + res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ + ((((a32) & (b32)) & 0x80000000) != 0 ? SKP_int32_MIN : (a32)+(b32)) : \ + ((((a32) | (b32)) & 0x80000000) == 0 ? SKP_int32_MAX : (a32)+(b32)) ); + return res; +} + +#undef SKP_ADD_SAT64 +SKP_INLINE SKP_int64 SKP_ADD_SAT64( SKP_int64 a64, SKP_int64 b64 ) { + SKP_int64 res; + ops_count += 1; + res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ + ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? SKP_int64_MIN : (a64)+(b64)) : \ + ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? SKP_int64_MAX : (a64)+(b64)) ); + return res; +} + +#undef SKP_SUB_SAT16 +SKP_INLINE SKP_int16 SKP_SUB_SAT16( SKP_int16 a16, SKP_int16 b16 ) { + SKP_int16 res; + SKP_assert(0); + // Nb will be counted in sub-macros + res = (SKP_int16)SKP_SAT16( SKP_SUB32( (SKP_int32)(a16), (b16) ) ); + return res; +} + +#undef SKP_SUB_SAT32 +SKP_INLINE SKP_int32 SKP_SUB_SAT32( SKP_int32 a32, SKP_int32 b32 ) { + SKP_int32 res; + ops_count += 1; + res = ((((a32)-(b32)) & 0x80000000) == 0 ? \ + (( (a32) & ((b32)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a32)-(b32)) : \ + ((((a32)^0x80000000) & (b32) & 0x80000000) ? SKP_int32_MAX : (a32)-(b32)) ); + return res; +} + +#undef SKP_SUB_SAT64 +SKP_INLINE SKP_int64 SKP_SUB_SAT64( SKP_int64 a64, SKP_int64 b64 ) { + SKP_int64 res; + ops_count += 1; + res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ + (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? SKP_int64_MIN : (a64)-(b64)) : \ + ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? SKP_int64_MAX : (a64)-(b64)) ); + + return res; +} + +#undef SKP_SMULWW +SKP_INLINE SKP_int32 SKP_SMULWW(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + // Nb will be counted in sub-macros + ret = SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16)); + return ret; +} + +#undef SKP_SMLAWW +SKP_INLINE SKP_int32 SKP_SMLAWW(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + // Nb will be counted in sub-macros + ret = SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16)); + return ret; +} + +#undef SKP_min_int +SKP_INLINE SKP_int SKP_min_int(SKP_int a, SKP_int b) +{ + ops_count += 1; + return (((a) < (b)) ? (a) : (b)); +} + +#undef SKP_min_16 +SKP_INLINE SKP_int16 SKP_min_16(SKP_int16 a, SKP_int16 b) +{ + ops_count += 1; + return (((a) < (b)) ? (a) : (b)); +} +#undef SKP_min_32 +SKP_INLINE SKP_int32 SKP_min_32(SKP_int32 a, SKP_int32 b) +{ + ops_count += 1; + return (((a) < (b)) ? (a) : (b)); +} +#undef SKP_min_64 +SKP_INLINE SKP_int64 SKP_min_64(SKP_int64 a, SKP_int64 b) +{ + ops_count += 1; + return (((a) < (b)) ? (a) : (b)); +} + +/* SKP_min() versions with typecast in the function call */ +#undef SKP_max_int +SKP_INLINE SKP_int SKP_max_int(SKP_int a, SKP_int b) +{ + ops_count += 1; + return (((a) > (b)) ? (a) : (b)); +} +#undef SKP_max_16 +SKP_INLINE SKP_int16 SKP_max_16(SKP_int16 a, SKP_int16 b) +{ + ops_count += 1; + return (((a) > (b)) ? (a) : (b)); +} +#undef SKP_max_32 +SKP_INLINE SKP_int32 SKP_max_32(SKP_int32 a, SKP_int32 b) +{ + ops_count += 1; + return (((a) > (b)) ? (a) : (b)); +} + +#undef SKP_max_64 +SKP_INLINE SKP_int64 SKP_max_64(SKP_int64 a, SKP_int64 b) +{ + ops_count += 1; + return (((a) > (b)) ? (a) : (b)); +} + + +#undef SKP_LIMIT_int +SKP_INLINE SKP_int SKP_LIMIT_int(SKP_int a, SKP_int limit1, SKP_int limit2) +{ + SKP_int ret; + ops_count += 6; + + ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + + return(ret); +} + +#undef SKP_LIMIT_16 +SKP_INLINE SKP_int16 SKP_LIMIT_16(SKP_int16 a, SKP_int16 limit1, SKP_int16 limit2) +{ + SKP_int16 ret; + ops_count += 6; + + ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + +return(ret); +} + + +#undef SKP_LIMIT_32 +SKP_INLINE SKP_int SKP_LIMIT_32(SKP_int32 a, SKP_int32 limit1, SKP_int32 limit2) +{ + SKP_int32 ret; + ops_count += 6; + + ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + return(ret); +} + +#else +#define exVarDefine +#define varDefine +#define SKP_SaveCount() + +#endif +#endif + diff --git a/src_SigProc_FIX/SKP_Silk_MacroDebug.h b/src_SigProc_FIX/SKP_Silk_MacroDebug.h new file mode 100644 index 000000000..29b27831c --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_MacroDebug.h @@ -0,0 +1,532 @@ +#ifndef _SIGPROCFIX_API_DEBUG_H_ +#define _SIGPROCFIX_API_DEBUG_H_ + +// Redefine macro functions with extensive assertion in Win32_DEBUG mode. +// As function can't be undefined, this file can't work with SigProcFIX_MacroCount.h + +#if 0 && defined (_WIN32) && defined (_DEBUG) && !defined (SKP_MACRO_COUNT) + +#undef SKP_ADD16 +SKP_INLINE SKP_int16 SKP_ADD16(SKP_int16 a, SKP_int16 b){ + SKP_int16 ret; + + ret = a + b; + SKP_assert( ret == SKP_ADD_SAT16( a, b )); + return ret; +} + +#undef SKP_ADD32 +SKP_INLINE SKP_int32 SKP_ADD32(SKP_int32 a, SKP_int32 b){ + SKP_int32 ret; + + ret = a + b; + SKP_assert( ret == SKP_ADD_SAT32( a, b )); + return ret; +} + +#undef SKP_ADD64 +SKP_INLINE SKP_int64 SKP_ADD64(SKP_int64 a, SKP_int64 b){ + SKP_int64 ret; + + ret = a + b; + SKP_assert( ret == SKP_ADD_SAT64( a, b )); + return ret; +} + +#undef SKP_SUB16 +SKP_INLINE SKP_int16 SKP_SUB16(SKP_int16 a, SKP_int16 b){ + SKP_int16 ret; + + ret = a - b; + SKP_assert( ret == SKP_SUB_SAT16( a, b )); + return ret; +} + +#undef SKP_SUB32 +SKP_INLINE SKP_int32 SKP_SUB32(SKP_int32 a, SKP_int32 b){ + SKP_int32 ret; + + ret = a - b; + SKP_assert( ret == SKP_SUB_SAT32( a, b )); + return ret; +} + +#undef SKP_SUB64 +SKP_INLINE SKP_int64 SKP_SUB64(SKP_int64 a, SKP_int64 b){ + SKP_int64 ret; + + ret = a - b; + SKP_assert( ret == SKP_SUB_SAT64( a, b )); + return ret; +} + +#undef SKP_ADD_SAT16 +SKP_INLINE SKP_int16 SKP_ADD_SAT16( SKP_int16 a16, SKP_int16 b16 ) { + SKP_int16 res; + res = (SKP_int16)SKP_SAT16( SKP_ADD32( (SKP_int32)(a16), (b16) ) ); + SKP_assert( res == SKP_SAT16( ( SKP_int32 )a16 + ( SKP_int32 )b16 ) ); + return res; +} + +#undef SKP_ADD_SAT32 +SKP_INLINE SKP_int32 SKP_ADD_SAT32(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 res; + res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ + ((((a32) & (b32)) & 0x80000000) != 0 ? SKP_int32_MIN : (a32)+(b32)) : \ + ((((a32) | (b32)) & 0x80000000) == 0 ? SKP_int32_MAX : (a32)+(b32)) ); + SKP_assert( res == SKP_SAT32( ( SKP_int64 )a32 + ( SKP_int64 )b32 ) ); + return res; +} + +#undef SKP_ADD_SAT64 +SKP_INLINE SKP_int64 SKP_ADD_SAT64( SKP_int64 a64, SKP_int64 b64 ) { + SKP_int64 res; + res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ + ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? SKP_int64_MIN : (a64)+(b64)) : \ + ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? SKP_int64_MAX : (a64)+(b64)) ); + if( res != a64 + b64 ) { + // Check that we saturated to the correct extreme value + SKP_assert( ( res == SKP_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( SKP_int64_MAX >> 3 ) ) ) || + ( res == SKP_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( SKP_int64_MIN >> 3 ) ) ) ); + } else { + // Saturation not necessary + SKP_assert( res == a64 + b64 ); + } + return res; +} + +#undef SKP_SUB_SAT16 +SKP_INLINE SKP_int16 SKP_SUB_SAT16( SKP_int16 a16, SKP_int16 b16 ) { + SKP_int16 res; + res = (SKP_int16)SKP_SAT16( SKP_SUB32( (SKP_int32)(a16), (b16) ) ); + SKP_assert( res == SKP_SAT16( ( SKP_int32 )a16 - ( SKP_int32 )b16 ) ); + return res; +} + +#undef SKP_SUB_SAT32 +SKP_INLINE SKP_int32 SKP_SUB_SAT32( SKP_int32 a32, SKP_int32 b32 ) { + SKP_int32 res; + res = ((((a32)-(b32)) & 0x80000000) == 0 ? \ + (( (a32) & ((b32)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a32)-(b32)) : \ + ((((a32)^0x80000000) & (b32) & 0x80000000) ? SKP_int32_MAX : (a32)-(b32)) ); + SKP_assert( res == SKP_SAT32( ( SKP_int64 )a32 - ( SKP_int64 )b32 ) ); + return res; +} + +#undef SKP_SUB_SAT64 +SKP_INLINE SKP_int64 SKP_SUB_SAT64( SKP_int64 a64, SKP_int64 b64 ) { + SKP_int64 res; + res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ + (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? SKP_int64_MIN : (a64)-(b64)) : \ + ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? SKP_int64_MAX : (a64)-(b64)) ); + + if( res != a64 - b64 ) { + // Check that we saturated to the correct extreme value + SKP_assert( ( res == SKP_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( SKP_int64_MAX >> 3 ) ) ) || + ( res == SKP_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( SKP_int64_MIN >> 3 ) ) ) ); + } else { + // Saturation not necessary + SKP_assert( res == a64 - b64 ); + } + return res; +} + +#undef SKP_MUL +SKP_INLINE SKP_int32 SKP_MUL(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + SKP_int64 ret64; // Will easily show how many bits that are needed + ret = a32 * b32; + ret64 = (SKP_int64)a32 * (SKP_int64)b32; + SKP_assert((SKP_int64)ret == ret64 ); //Check output overflow + return ret; +} + +#undef SKP_MUL_uint +SKP_INLINE SKP_uint32 SKP_MUL_uint(SKP_uint32 a32, SKP_uint32 b32){ + SKP_uint32 ret; + ret = a32 * b32; + SKP_assert((SKP_uint64)ret == (SKP_uint64)a32 * (SKP_uint64)b32); //Check output overflow + return ret; +} +#undef SKP_MLA +SKP_INLINE SKP_int32 SKP_MLA(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = a32 + b32 * c32; + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (SKP_int64)b32 * (SKP_int64)c32); //Check output overflow + return ret; +} + +#undef SKP_MLA_uint +SKP_INLINE SKP_int32 SKP_MLA_uint(SKP_uint32 a32, SKP_uint32 b32, SKP_uint32 c32){ + SKP_uint32 ret; + ret = a32 + b32 * c32; + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (SKP_int64)b32 * (SKP_int64)c32); //Check output overflow + return ret; +} + +#undef SKP_SMULWB +SKP_INLINE SKP_int32 SKP_SMULWB(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ret = (a32 >> 16) * (SKP_int32)((SKP_int16)b32) + (((a32 & 0x0000FFFF) * (SKP_int32)((SKP_int16)b32)) >> 16); + SKP_assert((SKP_int64)ret == ((SKP_int64)a32 * (SKP_int16)b32) >> 16); + return ret; +} +#undef SKP_SMLAWB +SKP_INLINE SKP_int32 SKP_SMLAWB(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = SKP_ADD32( a32, SKP_SMULWB( b32, c32 ) ); + SKP_assert(SKP_ADD32( a32, SKP_SMULWB( b32, c32 ) ) == SKP_ADD_SAT32( a32, SKP_SMULWB( b32, c32 ) )); + return ret; +} + +#undef SKP_SMULWT +SKP_INLINE SKP_int32 SKP_SMULWT(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret; + ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); + SKP_assert((SKP_int64)ret == ((SKP_int64)a32 * (b32 >> 16)) >> 16); + return ret; +} +#undef SKP_SMLAWT +SKP_INLINE SKP_int32 SKP_SMLAWT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (((SKP_int64)b32 * (c32 >> 16)) >> 16)); + return ret; +} + +#undef SKP_SMULL +SKP_INLINE SKP_int64 SKP_SMULL(SKP_int64 a64, SKP_int64 b64){ + SKP_int64 ret64; + ret64 = a64 * b64; + if( b64 != 0 ) { + SKP_assert( a64 == (ret64 / b64) ); + } else if( a64 != 0 ) { + SKP_assert( b64 == (ret64 / a64) ); + } + return ret64; +} + +// no checking needed for SKP_SMULBB +#undef SKP_SMLABB +SKP_INLINE SKP_int32 SKP_SMLABB(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = a32 + (SKP_int32)((SKP_int16)b32) * (SKP_int32)((SKP_int16)c32); + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (SKP_int64)b32 * (SKP_int16)c32); + return ret; +} + +// no checking needed for SKP_SMULBT +#undef SKP_SMLABT +SKP_INLINE SKP_int32 SKP_SMLABT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = a32 + ((SKP_int32)((SKP_int16)b32)) * (c32 >> 16); + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (SKP_int64)b32 * (c32 >> 16)); + return ret; +} + +// no checking needed for SKP_SMULTT +#undef SKP_SMLATT +SKP_INLINE SKP_int32 SKP_SMLATT(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret; + ret = a32 + (b32 >> 16) * (c32 >> 16); + SKP_assert((SKP_int64)ret == (SKP_int64)a32 + (b32 >> 16) * (c32 >> 16)); + return ret; +} + +#undef SKP_SMULWW +SKP_INLINE SKP_int32 SKP_SMULWW(SKP_int32 a32, SKP_int32 b32){ + SKP_int32 ret, tmp1, tmp2; + SKP_int64 ret64; + + ret = SKP_SMULWB( a32, b32 ); + tmp1 = SKP_RSHIFT_ROUND( b32, 16 ); + tmp2 = SKP_MUL( a32, tmp1 ); + + SKP_assert( (SKP_int64)tmp2 == (SKP_int64) a32 * (SKP_int64) tmp1 ); + + tmp1 = ret; + ret = SKP_ADD32( tmp1, tmp2 ); + SKP_assert( SKP_ADD32( tmp1, tmp2 ) == SKP_ADD_SAT32( tmp1, tmp2 ) ); + + ret64 = SKP_RSHIFT64( SKP_SMULL( a32, b32 ), 16 ); + SKP_assert( (SKP_int64)ret == ret64 ); + + return ret; +} + +#undef SKP_SMLAWW +SKP_INLINE SKP_int32 SKP_SMLAWW(SKP_int32 a32, SKP_int32 b32, SKP_int32 c32){ + SKP_int32 ret, tmp; + + tmp = SKP_SMULWW( b32, c32 ); + ret = SKP_ADD32( a32, tmp ); + SKP_assert( ret == SKP_ADD_SAT32( a32, tmp ) ); + return ret; +} + +// multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) +#undef SKP_MLA_ovflw +#define SKP_MLA_ovflw(a32, b32, c32) ((a32) + ((b32) * (c32))) +#undef SKP_SMLABB_ovflw +#define SKP_SMLABB_ovflw(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32))) +#undef SKP_SMLABT_ovflw +#define SKP_SMLABT_ovflw(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16)) +#undef SKP_SMLATT_ovflw +#define SKP_SMLATT_ovflw(a32, b32, c32) ((a32) + ((b32) >> 16) * ((c32) >> 16)) +#undef SKP_SMLAWB_ovflw +#define SKP_SMLAWB_ovflw(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16))) +#undef SKP_SMLAWT_ovflw +#define SKP_SMLAWT_ovflw(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16)) + +// no checking needed for SKP_SMULL +// no checking needed for SKP_SMLAL +// no checking needed for SKP_SMLALBB +// no checking needed for SigProcFIX_CLZ16 +// no checking needed for SigProcFIX_CLZ32 + +#undef SKP_DIV32 +SKP_INLINE SKP_int32 SKP_DIV32(SKP_int32 a32, SKP_int32 b32){ + SKP_assert( b32 != 0 ); + return a32 / b32; +} + +#undef SKP_DIV32_16 +SKP_INLINE SKP_int32 SKP_DIV32_16(SKP_int32 a32, SKP_int32 b32){ + SKP_assert( b32 != 0 ); + SKP_assert( b32 <= SKP_int16_MAX ); + SKP_assert( b32 >= SKP_int16_MIN ); + return a32 / b32; +} + +// no checking needed for SKP_SAT8 +// no checking needed for SKP_SAT16 +// no checking needed for SKP_SAT32 +// no checking needed for SKP_POS_SAT32 +// no checking needed for SKP_ADD_POS_SAT8 +// no checking needed for SKP_ADD_POS_SAT16 +// no checking needed for SKP_ADD_POS_SAT32 +// no checking needed for SKP_ADD_POS_SAT64 +#undef SKP_LSHIFT8 +SKP_INLINE SKP_int8 SKP_LSHIFT8(SKP_int8 a, SKP_int32 shift){ + SKP_int8 ret; + ret = a << shift; + SKP_assert(shift >= 0); + SKP_assert(shift < 8); + SKP_assert((SKP_int64)ret == ((SKP_int64)a) << shift); + return ret; +} +#undef SKP_LSHIFT16 +SKP_INLINE SKP_int16 SKP_LSHIFT16(SKP_int16 a, SKP_int32 shift){ + SKP_int16 ret; + ret = a << shift; + SKP_assert(shift >= 0); + SKP_assert(shift < 16); + SKP_assert((SKP_int64)ret == ((SKP_int64)a) << shift); + return ret; +} +#undef SKP_LSHIFT32 +SKP_INLINE SKP_int32 SKP_LSHIFT32(SKP_int32 a, SKP_int32 shift){ + SKP_int32 ret; + ret = a << shift; + SKP_assert(shift >= 0); + SKP_assert(shift < 32); + SKP_assert((SKP_int64)ret == ((SKP_int64)a) << shift); + return ret; +} +#undef SKP_LSHIFT64 +SKP_INLINE SKP_int64 SKP_LSHIFT64(SKP_int64 a, SKP_int shift){ + SKP_assert(shift >= 0); + SKP_assert(shift < 64); + return a << shift; +} + +#undef SKP_LSHIFT_ovflw +SKP_INLINE SKP_int32 SKP_LSHIFT_ovflw(SKP_int32 a, SKP_int32 shift){ + SKP_assert(shift >= 0); /* no check for overflow */ + return a << shift; +} + +#undef SKP_LSHIFT_uint +SKP_INLINE SKP_uint32 SKP_LSHIFT_uint(SKP_uint32 a, SKP_int32 shift){ + SKP_uint32 ret; + ret = a << shift; + SKP_assert(shift >= 0); + SKP_assert((SKP_int64)ret == ((SKP_int64)a) << shift); + return ret; +} + +#undef SKP_RSHIFT8 +SKP_INLINE SKP_int8 SKP_RSHIFT8(SKP_int8 a, SKP_int32 shift){ + SKP_assert(shift >= 0); + SKP_assert(shift < 8); + return a >> shift; +} +#undef SKP_RSHIFT16 +SKP_INLINE SKP_int16 SKP_RSHIFT16(SKP_int16 a, SKP_int32 shift){ + SKP_assert(shift >= 0); + SKP_assert(shift < 16); + return a >> shift; +} +#undef SKP_RSHIFT32 +SKP_INLINE SKP_int32 SKP_RSHIFT32(SKP_int32 a, SKP_int32 shift){ + SKP_assert(shift >= 0); + SKP_assert(shift < 32); + return a >> shift; +} +#undef SKP_RSHIFT64 +SKP_INLINE SKP_int64 SKP_RSHIFT64(SKP_int64 a, SKP_int64 shift){ + SKP_assert(shift >= 0); + SKP_assert(shift <= 63); + return a >> shift; +} + +#undef SKP_RSHIFT_uint +SKP_INLINE SKP_uint32 SKP_RSHIFT_uint(SKP_uint32 a, SKP_int32 shift){ + SKP_assert(shift >= 0); + SKP_assert(shift <= 32); + return a >> shift; +} + +#undef SKP_ADD_LSHIFT +SKP_INLINE SKP_int32 SKP_ADD_LSHIFT(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a + (b << shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) << shift)); + return ret; // shift >= 0 +} +#undef SKP_ADD_LSHIFT32 +SKP_INLINE SKP_int32 SKP_ADD_LSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a + (b << shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) << shift)); + return ret; // shift >= 0 +} +#undef SKP_ADD_LSHIFT_uint +SKP_INLINE SKP_uint32 SKP_ADD_LSHIFT_uint(SKP_uint32 a, SKP_uint32 b, SKP_int32 shift){ + SKP_uint32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 32); + ret = a + (b << shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) << shift)); + return ret; // shift >= 0 +} +#undef SKP_ADD_RSHIFT +SKP_INLINE SKP_int32 SKP_ADD_RSHIFT(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a + (b >> shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) >> shift)); + return ret; // shift > 0 +} +#undef SKP_ADD_RSHIFT32 +SKP_INLINE SKP_int32 SKP_ADD_RSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a + (b >> shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) >> shift)); + return ret; // shift > 0 +} +#undef SKP_ADD_RSHIFT_uint +SKP_INLINE SKP_uint32 SKP_ADD_RSHIFT_uint(SKP_uint32 a, SKP_uint32 b, SKP_int32 shift){ + SKP_uint32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 32); + ret = a + (b >> shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a + (((SKP_int64)b) >> shift)); + return ret; // shift > 0 +} +#undef SKP_SUB_LSHIFT32 +SKP_INLINE SKP_int32 SKP_SUB_LSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a - (b << shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a - (((SKP_int64)b) << shift)); + return ret; // shift >= 0 +} +#undef SKP_SUB_RSHIFT32 +SKP_INLINE SKP_int32 SKP_SUB_RSHIFT32(SKP_int32 a, SKP_int32 b, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift >= 0); + SKP_assert(shift <= 31); + ret = a - (b >> shift); + SKP_assert((SKP_int64)ret == (SKP_int64)a - (((SKP_int64)b) >> shift)); + return ret; // shift > 0 +} + +#undef SKP_RSHIFT_ROUND +SKP_INLINE SKP_int32 SKP_RSHIFT_ROUND(SKP_int32 a, SKP_int32 shift){ + SKP_int32 ret; + SKP_assert(shift > 0); /* the marco definition can't handle a shift of zero */ + SKP_assert(shift < 32); + ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; + SKP_assert((SKP_int64)ret == ((SKP_int64)a + ((SKP_int64)1 << (shift - 1))) >> shift); + return ret; +} + +#undef SKP_RSHIFT_ROUND64 +SKP_INLINE SKP_int64 SKP_RSHIFT_ROUND64(SKP_int64 a, SKP_int32 shift){ + SKP_int64 ret; + SKP_assert(shift > 0); /* the marco definition can't handle a shift of zero */ + SKP_assert(shift < 64); + ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; + return ret; +} + +// SKP_abs is used on floats also, so doesn't work... +//#undef SKP_abs +//SKP_INLINE SKP_int32 SKP_abs(SKP_int32 a){ +// SKP_assert(a != 0x80000000); +// return (((a) > 0) ? (a) : -(a)); // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN +//} + +#undef SKP_abs_int64 +SKP_INLINE SKP_int64 SKP_abs_int64(SKP_int64 a){ + SKP_assert(a != 0x8000000000000000); + return (((a) > 0) ? (a) : -(a)); // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN +} + +#undef SKP_abs_int32 +SKP_INLINE SKP_int32 SKP_abs_int32(SKP_int32 a){ + SKP_assert(a != 0x80000000); + return abs(a); +} + +#undef SKP_CHECK_FIT8 +SKP_INLINE SKP_int8 SKP_CHECK_FIT8( SKP_int64 a ){ + SKP_int8 ret; + ret = (SKP_int8)a; + SKP_assert( (SKP_int64)ret == a ); + return( ret ); +} + +#undef SKP_CHECK_FIT16 +SKP_INLINE SKP_int16 SKP_CHECK_FIT16( SKP_int64 a ){ + SKP_int16 ret; + ret = (SKP_int16)a; + SKP_assert( (SKP_int64)ret == a ); + return( ret ); +} + +#undef SKP_CHECK_FIT32 +SKP_INLINE SKP_int32 SKP_CHECK_FIT32( SKP_int64 a ){ + SKP_int32 ret; + ret = (SKP_int32)a; + SKP_assert( (SKP_int64)ret == a ); + return( ret ); +} + +// no checking for SKP_NSHIFT_MUL_32_32 +// no checking for SKP_NSHIFT_MUL_16_16 +// no checking needed for SKP_min +// no checking needed for SKP_max +// no checking needed for SKP_sign + +#endif +#endif diff --git a/src/SKP_Silk_NLSF2A.c b/src_SigProc_FIX/SKP_Silk_NLSF2A.c similarity index 93% rename from src/SKP_Silk_NLSF2A.c rename to src_SigProc_FIX/SKP_Silk_NLSF2A.c index 262b65456..b262068f0 100644 --- a/src/SKP_Silk_NLSF2A.c +++ b/src_SigProc_FIX/SKP_Silk_NLSF2A.c @@ -63,13 +63,13 @@ void SKP_Silk_NLSF2A( ) { SKP_int k, i, dd; - SKP_int32 cos_LSF_Q20[SigProc_MAX_ORDER_LPC]; - SKP_int32 P[SigProc_MAX_ORDER_LPC/2+1], Q[SigProc_MAX_ORDER_LPC/2+1]; + SKP_int32 cos_LSF_Q20[SKP_Silk_MAX_ORDER_LPC]; + SKP_int32 P[SKP_Silk_MAX_ORDER_LPC/2+1], Q[SKP_Silk_MAX_ORDER_LPC/2+1]; SKP_int32 Ptmp, Qtmp; SKP_int32 f_int; SKP_int32 f_frac; SKP_int32 cos_val, delta; - SKP_int32 a_int32[SigProc_MAX_ORDER_LPC]; + SKP_int32 a_int32[SKP_Silk_MAX_ORDER_LPC]; SKP_int32 maxabs, absval, idx=0, sc_Q16; SKP_assert(LSF_COS_TAB_SZ_FIX == 128); @@ -127,6 +127,7 @@ void SKP_Silk_NLSF2A( if( maxabs > SKP_int16_MAX ) { /* Reduce magnitude of prediction coefficients */ + maxabs = SKP_min( maxabs, 98369 ); // ( SKP_int32_MAX / ( 65470 >> 2 ) ) + SKP_int16_MAX = 98369 sc_Q16 = 65470 - SKP_DIV32( SKP_MUL( 65470 >> 2, maxabs - SKP_int16_MAX ), SKP_RSHIFT32( SKP_MUL( maxabs, idx + 1), 2 ) ); SKP_Silk_bwexpander_32( a_int32, d, sc_Q16 ); diff --git a/src/SKP_Silk_NLSF_VQ_weights_laroia.c b/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c similarity index 100% rename from src/SKP_Silk_NLSF_VQ_weights_laroia.c rename to src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c diff --git a/src/SKP_Silk_NLSF_stabilize.c b/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c similarity index 96% rename from src/SKP_Silk_NLSF_stabilize.c rename to src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c index 79325867d..19e134fd7 100644 --- a/src/SKP_Silk_NLSF_stabilize.c +++ b/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c @@ -106,7 +106,7 @@ void SKP_Silk_NLSF_stabilize( max_center_Q15 -= ( NDeltaMin_Q15[I] - SKP_RSHIFT( NDeltaMin_Q15[I], 1 ) ); /* Move apart, sorted by value, keeping the same center frequency */ - center_freq_Q15 = SKP_LIMIT( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ), + center_freq_Q15 = SKP_LIMIT_32( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ), min_center_Q15, max_center_Q15 ); NLSF_Q15[I-1] = center_freq_Q15 - SKP_RSHIFT( NDeltaMin_Q15[I], 1 ); NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I]; diff --git a/src/SKP_Silk_SigProc_FIX.h b/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h similarity index 79% rename from src/SKP_Silk_SigProc_FIX.h rename to src_SigProc_FIX/SKP_Silk_SigProc_FIX.h index 41d95f585..34f1b4e14 100644 --- a/src/SKP_Silk_SigProc_FIX.h +++ b/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h @@ -25,6 +25,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ + #ifndef _SKP_SILK_SIGPROC_FIX_H_ #define _SKP_SILK_SIGPROC_FIX_H_ @@ -33,142 +34,89 @@ extern "C" { #endif -#define SigProc_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */ -#define SigProc_MAX_CORRELATION_LENGTH 640 /* max input length to the correlation */ +//#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 */ #include "SKP_Silk_typedef.h" #include <string.h> #include <stdlib.h> /* for abs() */ -#include "SKP_Silk_macros.h" -#include "SKP_Silk_resample_rom.h" +#include "SKP_Silk_resampler_structs.h" + +# include "SKP_Silk_macros.h" + - /********************************************************************/ /* SIGNAL PROCESSING FUNCTIONS */ /********************************************************************/ -/* downsample by a factor 2 */ -void SKP_Silk_resample_1_2( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: State vector [6] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *scratch, /* I: Scratch memory [4*len] */ - const SKP_int32 len /* I: Number of OUTPUT samples */ -); - -/*! - * downsample by a factor 2, coarser (good for resampling audio) - */ -void SKP_Silk_resample_1_2_coarse( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: state vector [4] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *scratch, /* I: scratch memory [3*len] */ - const SKP_int32 len /* I: number of OUTPUT samples */ -); - -/*! - * downsample by a factor 2, coarsest (good for signals that are already oversampled, or for analysis purposes) - */ -void SKP_Silk_resample_1_2_coarsest( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: State vector [2] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *scratch, /* I: Scratch memory [3*len] */ - const SKP_int32 len /* I: Number of OUTPUT samples */ +/*! + * 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_int32 Fs_Hz_in, /* I: Input sampling rate (Hz) */ + SKP_int32 Fs_Hz_out /* I: Output sampling rate (Hz) */ ); -/*! - * upsample by a factor 2, coarser (good for resampling audio) - */ -void SKP_Silk_resample_2_1_coarse( - const SKP_int16 *in, /* I: 8 kHz signal [len] */ - SKP_int32 *S, /* I/O: State vector [4] */ - SKP_int16 *out, /* O: 16 kHz signal [2*len] */ - SKP_int32 *scratch, /* I: Scratch memory [3*len] */ - const SKP_int32 len /* I: Number of INPUT samples */ -); /*! - * Resamples by a factor 1/3 + * Clear the states of all resampling filters, without resetting sampling rate ratio */ -void SKP_Silk_resample_1_3( - SKP_int16 *out, /* O: Fs_low signal [inLen/3] */ - SKP_int32 *S, /* I/O: State vector [7] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int32 inLen /* I: Input length, must be a multiple of 3 */ +SKP_int SKP_Silk_resampler_clear( + SKP_Silk_resampler_state_struct *S /* I/O: Resampler state */ ); /*! - * Resamples by a factor 3/1 + * Resampler: convert from one sampling rate to another */ -void SKP_Silk_resample_3_1( - SKP_int16 *out, /* O: Fs_high signal [inLen*3] */ - SKP_int32 *S, /* I/O: State vector [7] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - const SKP_int32 inLen /* I: Input length */ +SKP_int SKP_Silk_resampler( + 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 */ ); /*! - * Resamples by a factor 2/3 - */ -void SKP_Silk_resample_2_3( - SKP_int16 *out, /* O: Fs_low signal [inLen * 2/3] */ - SKP_int32 *S, /* I/O: State vector [7+4] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int inLen /* I: Input length, must be a multiple of 3 */ -); - -/*! - * Resamples by a factor 3/2 + Upsample 2x, low quality */ -void SKP_Silk_resample_3_2( - SKP_int16 *out, /* O: Fs_high signal [inLen*3/2] */ - SKP_int32 *S, /* I/O: State vector [7+4] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - SKP_int inLen /* I: Input length, must be a multiple of 2 */ +void SKP_Silk_resampler_up2( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of INPUT samples */ ); /*! - * Resamples by a factor 4/3 - */ -void SKP_Silk_resample_4_3( - SKP_int16 *out, /* O: Fs_low signal [inLen * 4/3] */ - SKP_int32 *S, /* I/O: State vector [7+4+4] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int inLen /* I: input length, must be a multiple of 3 */ +* Downsample 2x, mediocre quality +*/ +void SKP_Silk_resampler_down2( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ len ] */ + const SKP_int16 *in, /* I: Input signal [ 2 * len ] */ + SKP_int32 len /* I: Number of OUTPUT samples */ ); -/*! - * Resamples by a factor 3/4 - */ - void SKP_Silk_resample_3_4( - SKP_int16 *out, /* O: Fs_high signal [inLen*3/4] */ - SKP_int32 *S, /* I/O: State vector [7+2+6] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - SKP_int inLen /* I: Input length, must be a multiple of 4 */ -); -/*! - * resample with a factor 2/3 coarse - */ -void SKP_Silk_resample_2_3_coarse( - SKP_int16 *out, /* O: Output signal */ - SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */ - const SKP_int16 *in, /* I: Input signal */ - const SKP_int frameLenIn, /* I: Number of input samples */ - SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */ +/*! + * Downsample by a factor 2/3, low quality +*/ +void SKP_Silk_resampler_down2_3( + SKP_int32 *S, /* I/O: State vector [ 6 ] */ + SKP_int16 *out, /* O: Output signal [ floor(2*inLen/3) ] */ + const SKP_int16 *in, /* I: Input signal [ inLen ] */ + SKP_int32 inLen /* I: Number of input samples */ ); -/*! - * resample with a factor 2/3 coarsest - */ -void SKP_Silk_resample_2_3_coarsest( - SKP_int16 *out, /* O: Output signal */ - SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */ - const SKP_int16 *in, /* I: Input signal */ - const SKP_int frameLenIn, /* I: Number of input samples */ - SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */ +/*! + * Downsamples by a factor 3, low quality +*/ +void SKP_Silk_resampler_down3( + SKP_int32 *S, /* I/O: State vector [ 8 ] */ + SKP_int16 *out, /* O: Output signal [ floor(inLen/3) ] */ + const SKP_int16 *in, /* I: Input signal [ inLen ] */ + SKP_int32 inLen /* I: Number of input samples */ ); /*! @@ -305,10 +253,10 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise const SKP_int order /* I: Prediction order */ ); -SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13( /* O: returns 1 if unstable, otherwise 0 */ - SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ - const SKP_int16 *A_Q13, /* I: Prediction coefficients, Q13 [order] */ - const SKP_int order /* I: Prediction order */ +SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O: Returns 1 if unstable, otherwise 0 */ + SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */ + const SKP_int32 *A_Q24, /* I: Prediction coefficients, Q24 [order] */ + const SKP_int order /* I: Prediction order */ ); /* split signal in two decimated bands using first-order allpass filters */ @@ -399,35 +347,37 @@ void SKP_Silk_apply_sine_window( /* Compute autocorrelation */ void SKP_Silk_autocorr( SKP_int32 *results, /* O Result (length correlationCount) */ - SKP_int32 *scale, /* O Scaling of the correlation vector */ + SKP_int *scale, /* O Scaling of the correlation vector */ const SKP_int16 *inputData, /* I Input data to correlate */ const SKP_int inputDataSize, /* I Length of input */ const SKP_int correlationCount /* I Number of correlation taps to compute */ ); /* Pitch estimator */ -#define SigProc_PITCH_EST_MIN_COMPLEX 0 -#define SigProc_PITCH_EST_MID_COMPLEX 1 -#define SigProc_PITCH_EST_MAX_COMPLEX 2 +#define SKP_Silk_PE_MIN_COMPLEX 0 +#define SKP_Silk_PE_MID_COMPLEX 1 +#define SKP_Silk_PE_MAX_COMPLEX 2 void SKP_Silk_decode_pitch( - SKP_int lagIndex, /* I */ - SKP_int contourIndex, /* O */ - SKP_int pitch_lags[], /* O 4 pitch values */ - SKP_int Fs_kHz /* I sampling frequency (kHz) */ -); - -SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ - const SKP_int16 *signal, /* I Signal of length PITCH_EST_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 */ + SKP_int lagIndex, /* I */ + SKP_int 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 */ ); /* parameter defining the size and accuracy of the piecewise linear */ @@ -573,20 +523,35 @@ SKP_int32 SKP_Silk_inner_prod16_aligned_sat( ); SKP_int64 SKP_Silk_inner_prod_aligned_64( - const SKP_int32 *inVec1, /* I input vector 1 */ + const SKP_int32 *inVec1, /* I input vector 1 */ const SKP_int32 *inVec2, /* I input vector 2 */ const SKP_int len /* I vector lengths */ ); SKP_int64 SKP_Silk_inner_prod16_aligned_64( - const SKP_int16 *inVec1, /* I input vector 1 */ + const SKP_int16 *inVec1, /* I input vector 1 */ const SKP_int16 *inVec2, /* I input vector 2 */ const SKP_int len /* I vector lengths */ ); /********************************************************************/ -/* MACROS */ +/* MACROS */ /********************************************************************/ +/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating + left. Output is 32bit int. + Note: contemporary compilers recognize the C expression below and + compile it into a 'ror' instruction if available. No need for inline ASM! */ +SKP_INLINE SKP_int32 SKP_ROR32( SKP_int32 a32, SKP_int rot ) +{ + SKP_uint32 x = (SKP_uint32) a32; + SKP_uint32 r = (SKP_uint32) rot; + SKP_uint32 m = (SKP_uint32) -rot; + if(rot <= 0) + return (SKP_int32) ((x << m) | (x >> (32 - m))); + else + return (SKP_int32) ((x << (32 - r)) | (x >> r)); +} + /* Define 4-byte aligned array of SKP_int16 */ #define SKP_array_of_int16_4_byte_aligned( arrayName, nElements ) \ SKP_int32 dummy_int32 ## arrayName; \ @@ -760,6 +725,10 @@ SKP_INLINE SKP_int64 SKP_max_64(SKP_int64 a, SKP_int64 b) #define SKP_LIMIT( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))) +#define SKP_LIMIT_int SKP_LIMIT +#define SKP_LIMIT_16 SKP_LIMIT +#define SKP_LIMIT_32 SKP_LIMIT + //#define SKP_non_neg(a) ((a) & ((-(a)) >> (8 * sizeof(a) - 1))) /* doesn't seem faster than SKP_max(0, a); #define SKP_abs(a) (((a) > 0) ? (a) : -(a)) // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN @@ -788,6 +757,8 @@ SKP_INLINE SKP_int64 SKP_max_64(SKP_int64 a, SKP_int64 b) #define SKP_SMMUL(a32, b32) (SKP_int32)SKP_RSHIFT64(SKP_SMULL((a32), (b32)), 32) #include "SKP_Silk_Inlines.h" +#include "SKP_Silk_MacroCount.h" +#include "SKP_Silk_MacroDebug.h" #ifdef __cplusplus } diff --git a/src/SKP_Silk_allpass_int.c b/src_SigProc_FIX/SKP_Silk_allpass_int.c similarity index 96% rename from src/SKP_Silk_allpass_int.c rename to src_SigProc_FIX/SKP_Silk_allpass_int.c index 20adfd5af..8f1560699 100644 --- a/src/SKP_Silk_allpass_int.c +++ b/src_SigProc_FIX/SKP_Silk_allpass_int.c @@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* First-order allpass filter */ void SKP_Silk_allpass_int( const SKP_int32 *in, /* I: Q25 input signal [len] */ - SKP_int32 *S, /* I/O: Q25 state [1] */ + SKP_int32 *S, /* I/O: Q25 state [1] */ SKP_int A, /* I: Q15 coefficient (0 <= A < 32768) */ SKP_int32 *out, /* O: Q25 output signal [len] */ const SKP_int32 len /* I: Number of samples */ diff --git a/src/SKP_Silk_ana_filt_bank_1.c b/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c similarity index 63% rename from src/SKP_Silk_ana_filt_bank_1.c rename to src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c index 3dd3b1bd8..d948a625e 100644 --- a/src/SKP_Silk_ana_filt_bank_1.c +++ b/src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c @@ -36,38 +36,45 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_SigProc_FIX.h" /* Coefficients for 2-band filter bank based on first-order allpass filters */ -static SKP_int16 A_fb1_20[ 1 ] = { 5394 }; -static SKP_int16 A_fb1_21[ 1 ] = { 20623 }; +// old +static SKP_int16 A_fb1_20[ 1 ] = { 5394 << 1 }; +static SKP_int16 A_fb1_21[ 1 ] = { 20623 << 1 }; /* wrap-around to negative number is intentional */ /* Split signal into two decimated bands using first-order allpass filters */ void SKP_Silk_ana_filt_bank_1( - const SKP_int16 *in, /* I: Input signal [N] */ + const SKP_int16 *in, /* I: Input signal [N] */ SKP_int32 *S, /* I/O: State vector [2] */ - SKP_int16 *outL, /* O: Low band [N/2] */ - SKP_int16 *outH, /* O: High band [N/2] */ - SKP_int32 *scratch, /* I: Scratch memory [3*N/2] */ + SKP_int16 *outL, /* O: Low band [N/2] */ + SKP_int16 *outH, /* O: High band [N/2] */ + SKP_int32 *scratch, /* I: Scratch memory [3*N/2] */ // todo: remove - no longer used const SKP_int32 N /* I: Number of input samples */ ) { - SKP_int k, N2 = SKP_RSHIFT( N, 1 ); - SKP_int32 out_tmp; + SKP_int k, N2 = SKP_RSHIFT( N, 1 ); + SKP_int32 in32, X, Y, out_1, out_2; - /* De-interleave three allpass inputs, and convert Q15 -> Q25 */ + /* Internal variables and state are in Q10 format */ for( k = 0; k < N2; k++ ) { - scratch[ k + N ] = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 ); - scratch[ k + N2 ] = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 ); - } + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 ); - /* Allpass filters */ - SKP_Silk_allpass_int( scratch + N2, S+0, A_fb1_20[ 0 ], scratch, N2 ); - SKP_Silk_allpass_int( scratch + N, S+1, A_fb1_21[ 0 ], scratch + N2, N2 ); + /* All-pass section for even input sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMLAWB( Y, Y, A_fb1_21[ 0 ] ); + out_1 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); - /* Add and subtract two allpass outputs to create bands */ - for( k = 0; k < N2; k++ ) { - out_tmp = scratch[ k ] + scratch[ k + N2 ]; - outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out_tmp, 11 ) ); + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 ); - out_tmp = scratch[ k ] - scratch[ k + N2 ]; - outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out_tmp, 11 ) ); - } + /* All-pass section for odd input sample, and add to output of previous section */ + Y = SKP_SUB32( in32, S[ 1 ] ); + X = SKP_SMULWB( Y, A_fb1_20[ 0 ] ); + out_2 = SKP_ADD32( S[ 1 ], X ); + S[ 1 ] = SKP_ADD32( in32, X ); + + /* Add/subtract, convert back to int16 and store to output */ + outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_ADD32( out_2, out_1 ), 11 ) ); + outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( out_2, out_1 ), 11 ) ); + } } diff --git a/src/SKP_Silk_apply_sine_window.c b/src_SigProc_FIX/SKP_Silk_apply_sine_window.c similarity index 89% rename from src/SKP_Silk_apply_sine_window.c rename to src_SigProc_FIX/SKP_Silk_apply_sine_window.c index 5d2b5692b..3b8c8cf9f 100644 --- a/src/SKP_Silk_apply_sine_window.c +++ b/src_SigProc_FIX/SKP_Silk_apply_sine_window.c @@ -41,8 +41,7 @@ void SKP_Silk_apply_sine_window( ) { SKP_int k; - SKP_int32 px32, f_Q16, c_Q20, S0_Q16, S1_Q16; - + SKP_int32 f_Q16, c_Q20, S0_Q16, S1_Q16; /* Length must be multiple of 4 */ SKP_assert( ( length & 3 ) == 0 ); @@ -74,18 +73,17 @@ void SKP_Silk_apply_sine_window( S1_Q16 = ( 1 << 16 ) + SKP_RSHIFT( c_Q20, 5 ); } + /* Uses the recursive equation: sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f) */ /* 4 samples at a time */ for( k = 0; k < length; k += 4 ) { - px32 = *( (SKP_int32 *)&px[ k ] ); /* load two values at once */ - px_win[ k ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px32 ); - px_win[ k + 1 ] = (SKP_int16)SKP_SMULWT( S1_Q16, px32 ); + px_win[ k ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k ] ); + px_win[ k + 1 ] = (SKP_int16)SKP_SMULWB( S1_Q16, px[ k + 1] ); S0_Q16 = SKP_RSHIFT( SKP_MUL( c_Q20, S1_Q16 ), 20 ) + SKP_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1; S0_Q16 = SKP_min( S0_Q16, ( 1 << 16 ) ); - px32 = *( (SKP_int32 *)&px[k + 2] ); /* load two values at once */ - px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px32 ); - px_win[ k + 3 ] = (SKP_int16)SKP_SMULWT( S0_Q16, px32 ); + px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k + 2] ); + px_win[ k + 3 ] = (SKP_int16)SKP_SMULWB( S0_Q16, px[ k + 3 ] ); S1_Q16 = SKP_RSHIFT( SKP_MUL( c_Q20, S0_Q16 ), 20 ) + SKP_LSHIFT( S0_Q16, 1 ) - S1_Q16; S1_Q16 = SKP_min( S1_Q16, ( 1 << 16 ) ); } diff --git a/src/SKP_Silk_array_maxabs.c b/src_SigProc_FIX/SKP_Silk_array_maxabs.c similarity index 91% rename from src/SKP_Silk_array_maxabs.c rename to src_SigProc_FIX/SKP_Silk_array_maxabs.c index 915af9feb..856152431 100644 --- a/src/SKP_Silk_array_maxabs.c +++ b/src_SigProc_FIX/SKP_Silk_array_maxabs.c @@ -37,6 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_SigProc_FIX.h" /* Function that returns the maximum absolut value of the input vector */ +#if (! defined(__mips__)) && EMBEDDED_ARM<4 SKP_int16 SKP_Silk_int16_array_maxabs( /* O Maximum absolute value, max: 2^15-1 */ const SKP_int16 *vec, /* I Input vector [len] */ const SKP_int32 len /* I Length of input vector */ @@ -55,10 +56,14 @@ SKP_int16 SKP_Silk_int16_array_maxabs( /* O Maximum absolute value, max: 2 } /* Do not return 32768, as it will not fit in an int16 so may lead to problems later on */ - lvl = SKP_abs( vec[ ind ] ); - if( lvl > SKP_int16_MAX ) { + if( max >= 1073676289 ) { // (2^15-1)^2 = 1073676289 return( SKP_int16_MAX ); } else { - return( (SKP_int16)lvl ); + if( vec[ ind ] < 0 ) { + return( -vec[ ind ] ); + } else { + return( vec[ ind ] ); + } } } +#endif diff --git a/src/SKP_Silk_autocorr.c b/src_SigProc_FIX/SKP_Silk_autocorr.c similarity index 96% rename from src/SKP_Silk_autocorr.c rename to src_SigProc_FIX/SKP_Silk_autocorr.c index 0d3652d5a..0cf8c0bbf 100644 --- a/src/SKP_Silk_autocorr.c +++ b/src_SigProc_FIX/SKP_Silk_autocorr.c @@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Compute autocorrelation */ void SKP_Silk_autocorr( SKP_int32 *results, /* O Result (length correlationCount) */ - SKP_int32 *scale, /* O Scaling of the correlation vector */ + SKP_int *scale, /* O Scaling of the correlation vector */ const SKP_int16 *inputData, /* I Input data to correlate */ const SKP_int inputDataSize, /* I Length of input */ const SKP_int correlationCount /* I Number of correlation taps to compute */ diff --git a/src/SKP_Silk_biquad.c b/src_SigProc_FIX/SKP_Silk_biquad.c similarity index 96% rename from src/SKP_Silk_biquad.c rename to src_SigProc_FIX/SKP_Silk_biquad.c index 81b76f1be..699a43d00 100644 --- a/src/SKP_Silk_biquad.c +++ b/src_SigProc_FIX/SKP_Silk_biquad.c @@ -42,7 +42,7 @@ void SKP_Silk_biquad( const SKP_int16 *in, /* I: input signal */ const SKP_int16 *B, /* I: MA coefficients, Q13 [3] */ const SKP_int16 *A, /* I: AR coefficients, Q13 [2] */ - SKP_int32 *S, /* I/O: state vector [2] */ + SKP_int32 *S, /* I/O: state vector [2] */ SKP_int16 *out, /* O: output signal */ const SKP_int32 len /* I: signal length */ ) diff --git a/src/SKP_Silk_biquad_alt.c b/src_SigProc_FIX/SKP_Silk_biquad_alt.c similarity index 100% rename from src/SKP_Silk_biquad_alt.c rename to src_SigProc_FIX/SKP_Silk_biquad_alt.c diff --git a/src/SKP_Silk_burg_modified.c b/src_SigProc_FIX/SKP_Silk_burg_modified.c similarity index 95% rename from src/SKP_Silk_burg_modified.c rename to src_SigProc_FIX/SKP_Silk_burg_modified.c index 1ac47dcf7..281001a9c 100644 --- a/src/SKP_Silk_burg_modified.c +++ b/src_SigProc_FIX/SKP_Silk_burg_modified.c @@ -61,12 +61,12 @@ void SKP_Silk_burg_modified( SKP_int32 C0, num, nrg, rc_Q31, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2; const SKP_int16 *x_ptr; - SKP_int32 C_first_row[ SigProc_MAX_ORDER_LPC ]; - SKP_int32 C_last_row[ SigProc_MAX_ORDER_LPC ]; - SKP_int32 Af_QA[ SigProc_MAX_ORDER_LPC ]; + SKP_int32 C_first_row[ SKP_Silk_MAX_ORDER_LPC ]; + SKP_int32 C_last_row[ SKP_Silk_MAX_ORDER_LPC ]; + SKP_int32 Af_QA[ SKP_Silk_MAX_ORDER_LPC ]; - SKP_int32 CAf[ SigProc_MAX_ORDER_LPC + 1 ]; - SKP_int32 CAb[ SigProc_MAX_ORDER_LPC + 1 ]; + SKP_int32 CAf[ SKP_Silk_MAX_ORDER_LPC + 1 ]; + SKP_int32 CAb[ SKP_Silk_MAX_ORDER_LPC + 1 ]; SKP_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); SKP_assert( nb_subfr <= MAX_NB_SUBFR ); @@ -90,7 +90,7 @@ void SKP_Silk_burg_modified( } rshifts += rshifts_extra; } - SKP_memset( C_first_row, 0, SigProc_MAX_ORDER_LPC * sizeof( SKP_int32 ) ); + SKP_memset( C_first_row, 0, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) ); if( rshifts > 0 ) { for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; @@ -108,7 +108,7 @@ void SKP_Silk_burg_modified( } } } - SKP_memcpy( C_last_row, C_first_row, SigProc_MAX_ORDER_LPC * sizeof( SKP_int32 ) ); + SKP_memcpy( C_last_row, C_first_row, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) ); /* Initialize */ CAb[ 0 ] = CAf[ 0 ] = C0 + SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ) + 1; // Q(-rshifts) diff --git a/src/SKP_Silk_bwexpander.c b/src_SigProc_FIX/SKP_Silk_bwexpander.c similarity index 100% rename from src/SKP_Silk_bwexpander.c rename to src_SigProc_FIX/SKP_Silk_bwexpander.c diff --git a/src/SKP_Silk_bwexpander_32.c b/src_SigProc_FIX/SKP_Silk_bwexpander_32.c similarity index 100% rename from src/SKP_Silk_bwexpander_32.c rename to src_SigProc_FIX/SKP_Silk_bwexpander_32.c diff --git a/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h b/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h new file mode 100644 index 000000000..e7f5ce778 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_common_pitch_est_defines.h @@ -0,0 +1,86 @@ +/*********************************************************************** +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 + +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 ]; +extern const SKP_int8 SKP_Silk_cbk_offsets_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_decode_pitch.c b/src_SigProc_FIX/SKP_Silk_decode_pitch.c new file mode 100644 index 000000000..b7a3e744f --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_decode_pitch.c @@ -0,0 +1,71 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/*********************************************************** +* Pitch analyser function +********************************************************** */ +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_pitch_est_defines.h" + +void SKP_Silk_decode_pitch( + SKP_int lagIndex, /* I */ + SKP_int 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 lag, k, min_lag, cbk_size; + const SKP_int8 *Lag_CB_ptr; + + if( Fs_kHz == 8 ) { + if( nb_subfr == PE_MAX_NB_SUBFR ) { + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2[ 0 ][ 0 ]; + cbk_size = PE_NB_CBKS_STAGE2_EXT; + } else { + SKP_assert( PE_MAX_NB_SUBFR >> 1 == nb_subfr ); + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; + cbk_size = PE_NB_CBKS_STAGE2_10MS; + } + } else { + if( nb_subfr == PE_MAX_NB_SUBFR ) { + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + } else { + SKP_assert( PE_MAX_NB_SUBFR >> 1 == nb_subfr ); + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + } + } + + min_lag = SKP_SMULBB( PE_MIN_LAG_MS, Fs_kHz ); + lag = min_lag + lagIndex; + + for( k = 0; k < nb_subfr; k++ ) { + pitch_lags[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, contourIndex, cbk_size ); + } +} \ No newline at end of file diff --git a/src/SKP_Silk_inner_prod_aligned.c b/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c similarity index 95% rename from src/SKP_Silk_inner_prod_aligned.c rename to src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c index 3ade172e1..318f0a573 100644 --- a/src/SKP_Silk_inner_prod_aligned.c +++ b/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c @@ -28,8 +28,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* * * SKP_Silk_inner_prod_aligned.c * * * - * * - * Copyright 2008 (c), Skype Limited * + * * + * Copyright 2008-2010 (c), Skype Limited * * Date: 080601 * * */ #include "SKP_Silk_SigProc_FIX.h" diff --git a/src/SKP_Silk_k2a.c b/src_SigProc_FIX/SKP_Silk_k2a.c similarity index 96% rename from src/SKP_Silk_k2a.c rename to src_SigProc_FIX/SKP_Silk_k2a.c index 0f9c34151..19e88070a 100644 --- a/src/SKP_Silk_k2a.c +++ b/src_SigProc_FIX/SKP_Silk_k2a.c @@ -44,7 +44,7 @@ void SKP_Silk_k2a( ) { SKP_int k, n; - SKP_int32 Atmp[ SigProc_MAX_ORDER_LPC ]; + SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ]; for( k = 0; k < order; k++ ) { for( n = 0; n < k; n++ ) { diff --git a/src/SKP_Silk_k2a_Q16.c b/src_SigProc_FIX/SKP_Silk_k2a_Q16.c similarity index 96% rename from src/SKP_Silk_k2a_Q16.c rename to src_SigProc_FIX/SKP_Silk_k2a_Q16.c index bc8e78c32..f12d1f281 100644 --- a/src/SKP_Silk_k2a_Q16.c +++ b/src_SigProc_FIX/SKP_Silk_k2a_Q16.c @@ -44,7 +44,7 @@ void SKP_Silk_k2a_Q16( ) { SKP_int k, n; - SKP_int32 Atmp[ SigProc_MAX_ORDER_LPC ]; + SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ]; for( k = 0; k < order; k++ ) { for( n = 0; n < k; n++ ) { diff --git a/src/SKP_Silk_lin2log.c b/src_SigProc_FIX/SKP_Silk_lin2log.c similarity index 100% rename from src/SKP_Silk_lin2log.c rename to src_SigProc_FIX/SKP_Silk_lin2log.c diff --git a/src/SKP_Silk_log2lin.c b/src_SigProc_FIX/SKP_Silk_log2lin.c similarity index 100% rename from src/SKP_Silk_log2lin.c rename to src_SigProc_FIX/SKP_Silk_log2lin.c diff --git a/src/SKP_Silk_lowpass_int.c b/src_SigProc_FIX/SKP_Silk_lowpass_int.c similarity index 100% rename from src/SKP_Silk_lowpass_int.c rename to src_SigProc_FIX/SKP_Silk_lowpass_int.c diff --git a/src/SKP_Silk_lowpass_short.c b/src_SigProc_FIX/SKP_Silk_lowpass_short.c similarity index 100% rename from src/SKP_Silk_lowpass_short.c rename to src_SigProc_FIX/SKP_Silk_lowpass_short.c diff --git a/src_SigProc_FIX/SKP_Silk_macros.h b/src_SigProc_FIX/SKP_Silk_macros.h new file mode 100644 index 000000000..7ec277fca --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_macros.h @@ -0,0 +1,132 @@ +/*********************************************************************** +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_API_C_H_ +#define _SKP_SILK_API_C_H_ + +// This is an inline header file for general platform. + +// (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int +#define SKP_SMULWB(a32, b32) ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16)) + +// a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int +#define SKP_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16))) + +// (a32 * (b32 >> 16)) >> 16 +#define SKP_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16)) + +// a32 + (b32 * (c32 >> 16)) >> 16 +#define SKP_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16)) + +// (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int +#define SKP_SMULBB(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32))) + +// a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int +#define SKP_SMLABB(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32))) + +// (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16) +#define SKP_SMULBT(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16)) + +// a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16) +#define SKP_SMLABT(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16)) + +// a64 + (b32 * c32) +#define SKP_SMLAL(a64, b32, c32) (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32)))) + +// (a32 * b32) >> 16 +#define SKP_SMULWW(a32, b32) SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16)) + +// a32 + ((b32 * c32) >> 16) +#define SKP_SMLAWW(a32, b32, c32) SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16)) + +/* add/subtract with output saturated */ +#define SKP_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \ + ((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) : \ + ((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) ) + +#define SKP_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \ + (( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) : \ + ((((a)^0x80000000) & (b) & 0x80000000) ? SKP_int32_MAX : (a)-(b)) ) + +SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16) +{ + SKP_int32 out32 = 0; + if( in16 == 0 ) { + return 16; + } + /* test nibbles */ + if( in16 & 0xFF00 ) { + if( in16 & 0xF000 ) { + in16 >>= 12; + } else { + out32 += 4; + in16 >>= 8; + } + } else { + if( in16 & 0xFFF0 ) { + out32 += 8; + in16 >>= 4; + } else { + out32 += 12; + } + } + /* test bits and return */ + if( in16 & 0xC ) { + if( in16 & 0x8 ) + return out32 + 0; + else + return out32 + 1; + } else { + if( in16 & 0xE ) + return out32 + 2; + else + return out32 + 3; + } +} + +SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32) +{ + /* test highest 16 bits and convert to SKP_int16 */ + if( in32 & 0xFFFF0000 ) { + return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16)); + } else { + return SKP_Silk_CLZ16((SKP_int16)in32) + 16; + } +} + +/* Row based */ +#define matrix_ptr(Matrix_base_adr, row, column, N) *(Matrix_base_adr + ((row)*(N)+(column))) +#define matrix_adr(Matrix_base_adr, row, column, N) (Matrix_base_adr + ((row)*(N)+(column))) + +/* Column based */ +#ifndef matrix_c_ptr +# define matrix_c_ptr(Matrix_base_adr, row, column, M) *(Matrix_base_adr + ((row)+(M)*(column))) +#endif +#define matrix_c_adr(Matrix_base_adr, row, column, M) (Matrix_base_adr + ((row)+(M)*(column))) + +#endif //_SKP_SILK_API_C_H_ + diff --git a/src/SKP_Silk_pitch_analysis_core.c b/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c similarity index 66% rename from src/SKP_Silk_pitch_analysis_core.c rename to src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c index 6d68c1a24..9e76ab3c4 100644 --- a/src/SKP_Silk_pitch_analysis_core.c +++ b/src_SigProc_FIX/SKP_Silk_pitch_analysis_core.c @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************** */ #include "SKP_Silk_SigProc_FIX.h" #include "SKP_Silk_pitch_est_defines.h" -#include "SKP_Silk_resample_rom.h" +#include "SKP_debug.h" #define SCRATCH_SIZE 22 @@ -38,18 +38,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Internally used functions */ /************************************************************/ void SKP_FIX_P_Ana_calc_corr_st3( - SKP_int32 cross_corr_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM correlation array */ + SKP_int32 cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ],/* (O) 3 DIM correlation array */ const SKP_int16 signal[], /* I vector to correlate */ SKP_int start_lag, /* I lag offset to search around */ SKP_int sf_length, /* I length of a 5 ms subframe */ + SKP_int nb_subfr, /* I number of subframes */ SKP_int complexity /* I Complexity setting */ ); void SKP_FIX_P_Ana_calc_energy_st3( - SKP_int32 energies_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM energy array */ + SKP_int32 energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ],/* (O) 3 DIM energy array */ const SKP_int16 signal[], /* I vector to calc energy in */ SKP_int start_lag, /* I lag offset to search around */ SKP_int sf_length, /* I length of one 5 ms subframe */ + SKP_int nb_subfr, /* I number of subframes */ SKP_int complexity /* I Complexity setting */ ); @@ -59,36 +61,11 @@ SKP_int32 SKP_FIX_P_Ana_find_scaling( const SKP_int sum_sqr_len ); -void SKP_Silk_decode_pitch( - SKP_int lagIndex, /* I */ - SKP_int contourIndex, /* O */ - SKP_int pitch_lags[], /* O 4 pitch values */ - SKP_int Fs_kHz /* I sampling frequency (kHz) */ -) -{ - SKP_int lag, i, min_lag; - - min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz ); - - /* Only for 24 / 16 kHz version for now */ - lag = min_lag + lagIndex; - if( Fs_kHz == 8 ) { - /* Only a small codebook for 8 khz */ - for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) { - pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ]; - } - } else { - for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) { - pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ]; - } - } -} - /*************************************************************/ /* 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 PITCH_EST_FRAME_LENGTH_MS*Fs_kHz */ +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 */ @@ -97,107 +74,79 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv 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 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[ PITCH_EST_MAX_FRAME_LENGTH_ST_2 ]; - SKP_int16 signal_4kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_1 ]; - SKP_int32 scratch_mem[ 3 * PITCH_EST_MAX_FRAME_LENGTH ]; + SKP_int16 signal_8kHz[ PE_MAX_FRAME_LENGTH_ST_2 ]; + SKP_int16 signal_4kHz[ PE_MAX_FRAME_LENGTH_ST_1 ]; + SKP_int32 scratch_mem[ 3 * PE_MAX_FRAME_LENGTH ]; SKP_int16 *input_signal_ptr; - SKP_int32 filt_state[ PITCH_EST_MAX_DECIMATE_STATE_LENGTH ]; + SKP_int32 filt_state[ PE_MAX_DECIMATE_STATE_LENGTH ]; SKP_int i, k, d, j; - SKP_int16 C[ PITCH_EST_NB_SUBFR ][ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ]; + SKP_int16 C[ PE_MAX_NB_SUBFR ][ ( PE_MAX_LAG >> 1 ) + 5 ]; const SKP_int16 *target_ptr, *basis_ptr; SKP_int32 cross_corr, normalizer, energy, shift, energy_basis, energy_target; - SKP_int d_srch[ PITCH_EST_D_SRCH_LENGTH ]; - SKP_int16 d_comp[ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ]; - SKP_int Cmax, length_d_srch, length_d_comp; - SKP_int32 sum, threshold, temp32; + SKP_int d_srch[ PE_D_SRCH_LENGTH ], Cmax, length_d_srch, length_d_comp; + SKP_int16 d_comp[ ( PE_MAX_LAG >> 1 ) + 5 ]; + SKP_int32 sum, threshold, temp32, lag_counter; SKP_int CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new; - SKP_int32 CC[ PITCH_EST_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new; - SKP_int32 energies_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ]; - SKP_int32 crosscorr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ]; - SKP_int32 lag_counter; + SKP_int32 CC[ PE_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new; + SKP_int32 energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; + SKP_int32 crosscorr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; SKP_int frame_length, frame_length_8kHz, frame_length_4kHz, max_sum_sq_length; SKP_int sf_length, sf_length_8kHz, sf_length_4kHz; SKP_int min_lag, min_lag_8kHz, min_lag_4kHz; SKP_int max_lag, max_lag_8kHz, max_lag_4kHz; - SKP_int32 contour_bias, diff; - SKP_int32 lz, lshift; - SKP_int cbk_offset, cbk_size, nb_cbks_stage2; + SKP_int32 contour_bias, diff, lz, lshift; + SKP_int cbk_offset, nb_cbk_search, cbk_size; SKP_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q15, corr_thres_Q15; - + const SKP_int8 *Lag_CB_ptr; /* Check for valid sampling frequency */ SKP_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 || Fs_kHz == 24 ); /* Check for valid complexity setting */ - SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX ); - SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX ); + SKP_assert( complexity >= SKP_Silk_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SKP_Silk_PE_MAX_COMPLEX ); SKP_assert( search_thres1_Q16 >= 0 && search_thres1_Q16 <= (1<<16) ); SKP_assert( search_thres2_Q15 >= 0 && search_thres2_Q15 <= (1<<15) ); /* Setup frame lengths max / min lag for the sampling frequency */ - frame_length = PITCH_EST_FRAME_LENGTH_MS * Fs_kHz; - frame_length_4kHz = PITCH_EST_FRAME_LENGTH_MS * 4; - frame_length_8kHz = PITCH_EST_FRAME_LENGTH_MS * 8; - sf_length = SKP_RSHIFT( frame_length, 3 ); - sf_length_4kHz = SKP_RSHIFT( frame_length_4kHz, 3 ); - sf_length_8kHz = SKP_RSHIFT( frame_length_8kHz, 3 ); - min_lag = PITCH_EST_MIN_LAG_MS * Fs_kHz; - min_lag_4kHz = PITCH_EST_MIN_LAG_MS * 4; - min_lag_8kHz = PITCH_EST_MIN_LAG_MS * 8; - max_lag = PITCH_EST_MAX_LAG_MS * Fs_kHz; - max_lag_4kHz = PITCH_EST_MAX_LAG_MS * 4; - max_lag_8kHz = PITCH_EST_MAX_LAG_MS * 8; - - SKP_memset( C, 0, sizeof( SKP_int16 ) * PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5) ); + frame_length = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * Fs_kHz; + frame_length_4kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 4; + frame_length_8kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 8; + sf_length = PE_SUBFR_LENGTH_MS * Fs_kHz; + sf_length_4kHz = PE_SUBFR_LENGTH_MS * 4; + sf_length_8kHz = PE_SUBFR_LENGTH_MS * 8; + min_lag = PE_MIN_LAG_MS * Fs_kHz; + min_lag_4kHz = PE_MIN_LAG_MS * 4; + min_lag_8kHz = PE_MIN_LAG_MS * 8; + max_lag = PE_MAX_LAG_MS * Fs_kHz; + max_lag_4kHz = PE_MAX_LAG_MS * 4; + max_lag_8kHz = PE_MAX_LAG_MS * 8; + + SKP_memset( C, 0, sizeof( SKP_int16 ) * nb_subfr * ( ( PE_MAX_LAG >> 1 ) + 5) ); /* Resample from input sampled at Fs_kHz to 8 kHz */ - if( Fs_kHz == 12 ) { - SKP_int16 R23[ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ]; - SKP_memset( R23, 0, ( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) ); - - SKP_Silk_resample_2_3_coarsest( signal_8kHz, R23, signal, - PITCH_EST_FRAME_LENGTH_MS * 12, (SKP_int16*)scratch_mem ); - } else if( Fs_kHz == 16 ) { - if( complexity == SigProc_PITCH_EST_MAX_COMPLEX ) { - SKP_assert( 4 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 4 * sizeof( SKP_int32 ) ); - - SKP_Silk_resample_1_2_coarse( signal, filt_state, signal_8kHz, - scratch_mem, frame_length_8kHz ); - } else { - SKP_assert( 2 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) ); - - SKP_Silk_resample_1_2_coarsest( signal, filt_state, signal_8kHz, - scratch_mem, frame_length_8kHz ); - } + if( Fs_kHz == 16 ) { + 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 ); } else if( Fs_kHz == 24 ) { - /* Resample to 24 -> 8 khz */ - SKP_assert( 7 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 7 * sizeof( SKP_int32 ) ); - - SKP_Silk_resample_1_3( signal_8kHz, filt_state, signal, 24 * PITCH_EST_FRAME_LENGTH_MS ); - + SKP_int32 filt_state_fix[ 8 ]; + SKP_memset( filt_state_fix, 0, 8 * sizeof(SKP_int32) ); + SKP_Silk_resampler_down3( filt_state_fix, 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. Set mem to zero */ - if( complexity == SigProc_PITCH_EST_MAX_COMPLEX ) { - SKP_assert( 4 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 4 * sizeof( SKP_int32 ) ); - SKP_Silk_resample_1_2_coarse( signal_8kHz, filt_state, - signal_4kHz, scratch_mem, frame_length_4kHz ); - } else { - SKP_assert( 2 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH ); - SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) ); - SKP_Silk_resample_1_2_coarsest( signal_8kHz, filt_state, - signal_4kHz, scratch_mem, frame_length_4kHz ); + 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 ); /* Low-pass filter */ for( i = frame_length_4kHz - 1; i > 0; i-- ) { @@ -210,7 +159,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv *******************************************************************************/ /* Inner product is calculated with different lengths, so scale for the worst case */ - max_sum_sq_length = SKP_max_32( sf_length_8kHz, SKP_RSHIFT( frame_length_4kHz, 1 ) ); + max_sum_sq_length = SKP_max_32( sf_length_8kHz, SKP_LSHIFT( sf_length_4kHz, 2 ) ); shift = SKP_FIX_P_Ana_find_scaling( signal_4kHz, frame_length_4kHz, max_sum_sq_length ); if( shift > 0 ) { for( i = 0; i < frame_length_4kHz; i++ ) { @@ -221,8 +170,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv /****************************************************************************** * FIRST STAGE, operating in 4 khz ******************************************************************************/ - target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ]; - for( k = 0; k < 2; k++ ) { + target_ptr = &signal_4kHz[ SKP_LSHIFT( sf_length_4kHz, 2 ) ]; + for( k = 0; k < nb_subfr >> 1; k++ ) { /* Check that we are within range of the array */ SKP_assert( target_ptr >= signal_4kHz ); SKP_assert( target_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz ); @@ -266,30 +215,39 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv } /* Combine two subframes into single correlation measure and apply short-lag bias */ - for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) { - sum = (SKP_int32)C[ 0 ][ i ] + (SKP_int32)C[ 1 ][ i ]; /* Q0 */ - SKP_assert( SKP_RSHIFT( sum, 1 ) == SKP_SAT16( SKP_RSHIFT( sum, 1 ) ) ); - sum = SKP_RSHIFT( sum, 1 ); /* Q-1 */ - SKP_assert( SKP_LSHIFT( (SKP_int32)-i, 4 ) == SKP_SAT16( SKP_LSHIFT( (SKP_int32)-i, 4 ) ) ); - sum = SKP_SMLAWB( sum, sum, SKP_LSHIFT( -i, 4 ) ); /* Q-1 */ - SKP_assert( sum == SKP_SAT16( sum ) ); - C[ 0 ][ i ] = (SKP_int16)sum; /* Q-1 */ + if( nb_subfr == PE_MAX_NB_SUBFR ) { + for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) { + sum = (SKP_int32)C[ 0 ][ i ] + (SKP_int32)C[ 1 ][ i ]; /* Q0 */ + SKP_assert( SKP_RSHIFT( sum, 1 ) == SKP_SAT16( SKP_RSHIFT( sum, 1 ) ) ); + sum = SKP_RSHIFT( sum, 1 ); /* Q-1 */ + SKP_assert( SKP_LSHIFT( (SKP_int32)-i, 4 ) == SKP_SAT16( SKP_LSHIFT( (SKP_int32)-i, 4 ) ) ); + sum = SKP_SMLAWB( sum, sum, SKP_LSHIFT( -i, 4 ) ); /* Q-1 */ + SKP_assert( sum == SKP_SAT16( sum ) ); + C[ 0 ][ i ] = (SKP_int16)sum; /* Q-1 */ + } + } else { + /* Only short lag bias */ + for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) { + sum = (SKP_int32)C[ 0 ][ i ]; + sum = SKP_SMLAWB( sum, sum, SKP_LSHIFT( -i, 4 ) ); /* Q-1 */ + C[ 0 ][ i ] = (SKP_int16)sum; /* Q-1 */ + } } - /* Sort */ length_d_srch = 5 + complexity; - SKP_assert( length_d_srch <= PITCH_EST_D_SRCH_LENGTH ); - SKP_Silk_insertion_sort_decreasing_int16( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch ); + SKP_assert( length_d_srch <= PE_D_SRCH_LENGTH ); + SKP_Silk_insertion_sort_decreasing_int16( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch ); /* Escape if correlation is very low already here */ - target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ]; - energy = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, SKP_RSHIFT( frame_length_4kHz, 1 ) ); + target_ptr = &signal_4kHz[ SKP_SMULBB( sf_length_4kHz, nb_subfr ) ]; + energy = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, SKP_LSHIFT( sf_length_4kHz, 2 ) ); energy = SKP_ADD_SAT32( energy, 1000 ); /* Q0 */ Cmax = (SKP_int)C[ 0 ][ min_lag_4kHz ]; /* Q-1 */ threshold = SKP_SMULBB( Cmax, Cmax ); /* Q-2 */ /* Compare in Q-2 domain */ + if( SKP_RSHIFT( energy, 4 + 2 ) > threshold ) { - SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) ); + SKP_memset( pitch_out, 0, nb_subfr * sizeof( SKP_int ) ); *LTPCorr_Q15 = 0; *lagIndex = 0; *contourIndex = 0; @@ -359,10 +317,10 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv /********************************************************************************* * Find energy of each subframe projected onto its history, for a range of delays *********************************************************************************/ - SKP_memset( C, 0, PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5 ) * sizeof( SKP_int16 ) ); + SKP_memset( C, 0, PE_MAX_NB_SUBFR * ( ( PE_MAX_LAG >> 1 ) + 5 ) * sizeof( SKP_int16 ) ); - target_ptr = &signal_8kHz[ frame_length_4kHz ]; /* point to middle of frame */ - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { + 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 ); @@ -375,7 +333,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv basis_ptr = target_ptr - d; /* Check that we are within range of the array */ - SKP_assert( basis_ptr >= signal_8kHz ); + SKP_assert( basis_ptr >= signal_8kHz ); SKP_assert( basis_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz ); cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz ); @@ -383,13 +341,13 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv if( cross_corr > 0 ) { energy = SKP_max( energy_target, energy_basis ); /* Find max to make sure first division < 1.0 */ lz = SKP_Silk_CLZ32( cross_corr ); - lshift = SKP_LIMIT( lz - 1, 0, 15 ); + lshift = SKP_LIMIT_32( lz - 1, 0, 15 ); temp32 = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); /* Q15 */ SKP_assert( temp32 == SKP_SAT16( temp32 ) ); temp32 = SKP_SMULWB( cross_corr, temp32 ); /* Q(-1), cc * ( cc / max(b, t) ) */ temp32 = SKP_ADD_SAT32( temp32, temp32 ); /* Q(0) */ lz = SKP_Silk_CLZ32( temp32 ); - lshift = SKP_LIMIT( lz - 1, 0, 15 ); + lshift = SKP_LIMIT_32( lz - 1, 0, 15 ); energy = SKP_min( energy_target, energy_basis ); C[ k ][ d ] = SKP_DIV32( SKP_LSHIFT( temp32, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); // Q15 } else { @@ -421,28 +379,37 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv prevLag_log2_Q7 = 0; } SKP_assert( search_thres2_Q15 == SKP_SAT16( search_thres2_Q15 ) ); - corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 13 ); - - /* If input is 8 khz use a larger codebook here because it is last stage */ - if( Fs_kHz == 8 && complexity > SigProc_PITCH_EST_MIN_COMPLEX ) { - nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2_EXT; - } else { - nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2; + /* Setup stage 2 codebook based on number of subframes */ + if( nb_subfr == PE_MAX_NB_SUBFR ) { + cbk_size = PE_NB_CBKS_STAGE2_EXT; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2[ 0 ][ 0 ]; + if( Fs_kHz == 8 && complexity > SKP_Silk_PE_MIN_COMPLEX ) { + /* If input is 8 khz use a larger codebook here because it is last stage */ + nb_cbk_search = PE_NB_CBKS_STAGE2_EXT; + } else { + nb_cbk_search = PE_NB_CBKS_STAGE2; + } + corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 13 ); + }else{ + cbk_size = PE_NB_CBKS_STAGE2_10MS; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; + nb_cbk_search = PE_NB_CBKS_STAGE2_10MS; + corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 14 ); } for( k = 0; k < length_d_srch; k++ ) { d = d_srch[ k ]; - for( j = 0; j < nb_cbks_stage2; j++ ) { + for( j = 0; j < nb_cbk_search; j++ ) { CC[ j ] = 0; - for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) { + for( i = 0; i < nb_subfr; i++ ) { /* Try all codebooks */ - CC[ j ] = CC[ j ] + (SKP_int32)C[ i ][ d + SKP_Silk_CB_lags_stage2[ i ][ j ] ]; + CC[ j ] = CC[ j ] + (SKP_int32)C[ i ][ d + matrix_ptr( Lag_CB_ptr, i, j, cbk_size )]; } } /* Find best codebook */ CCmax_new = SKP_int32_MIN; CBimax_new = 0; - for( i = 0; i < nb_cbks_stage2; i++ ) { + for( i = 0; i < nb_cbk_search; i++ ) { if( CC[ i ] > CCmax_new ) { CCmax_new = CC[ i ]; CBimax_new = i; @@ -452,16 +419,16 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv /* Bias towards shorter lags */ lag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)d ); /* Q7 */ SKP_assert( lag_log2_Q7 == SKP_SAT16( lag_log2_Q7 ) ); - SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 ) ); - CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */ + SKP_assert( nb_subfr * PE_SHORTLAG_BIAS_Q15 == SKP_SAT16( nb_subfr * PE_SHORTLAG_BIAS_Q15 ) ); + CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( nb_subfr * PE_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */ /* Bias towards previous lag */ - SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 ) ); + SKP_assert( nb_subfr * PE_PREVLAG_BIAS_Q15 == SKP_SAT16( nb_subfr * PE_PREVLAG_BIAS_Q15 ) ); if( prevLag > 0 ) { delta_lag_log2_sqr_Q7 = lag_log2_Q7 - prevLag_log2_Q7; SKP_assert( delta_lag_log2_sqr_Q7 == SKP_SAT16( delta_lag_log2_sqr_Q7 ) ); delta_lag_log2_sqr_Q7 = SKP_RSHIFT( SKP_SMULBB( delta_lag_log2_sqr_Q7, delta_lag_log2_sqr_Q7 ), 7 ); - prev_lag_bias_Q15 = SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15, ( *LTPCorr_Q15 ) ), 15 ); /* Q15 */ + prev_lag_bias_Q15 = SKP_RSHIFT( SKP_SMULBB( nb_subfr * PE_PREVLAG_BIAS_Q15, ( *LTPCorr_Q15 ) ), 15 ); /* Q15 */ prev_lag_bias_Q15 = SKP_DIV32( SKP_MUL( prev_lag_bias_Q15, delta_lag_log2_sqr_Q7 ), delta_lag_log2_sqr_Q7 + ( 1 << 6 ) ); CCmax_new_b -= prev_lag_bias_Q15; /* Q15 */ } @@ -476,7 +443,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv if( lag == -1 ) { /* No suitable candidate found */ - SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) ); + SKP_memset( pitch_out, 0, nb_subfr * sizeof( SKP_int ) ); *LTPCorr_Q15 = 0; *lagIndex = 0; *contourIndex = 0; @@ -515,7 +482,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv lag = SKP_SMULBB( lag, 3 ); } - lag = SKP_LIMIT( lag, min_lag, max_lag ); + lag = SKP_LIMIT_int( lag, min_lag, max_lag ); start_lag = SKP_max_int( lag - 2, min_lag ); end_lag = SKP_min_int( lag + 2, max_lag ); lag_new = lag; /* to avoid undefined lag */ @@ -525,36 +492,44 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv CCmax = SKP_int32_MIN; /* pitch lags according to second stage */ - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag + 2 * SKP_Silk_CB_lags_stage2[ k ][ CBimax_old ]; } /* Calculate the correlations and energies needed in stage 3 */ - SKP_FIX_P_Ana_calc_corr_st3( crosscorr_st3, input_signal_ptr, start_lag, sf_length, complexity ); - SKP_FIX_P_Ana_calc_energy_st3( energies_st3, input_signal_ptr, start_lag, sf_length, complexity ); + SKP_FIX_P_Ana_calc_corr_st3( crosscorr_st3, input_signal_ptr, start_lag, sf_length, nb_subfr, complexity ); + SKP_FIX_P_Ana_calc_energy_st3( energies_st3, input_signal_ptr, start_lag, sf_length, nb_subfr, complexity ); lag_counter = 0; SKP_assert( lag == SKP_SAT16( lag ) ); - contour_bias = SKP_DIV32_16( PITCH_EST_FLATCONTOUR_BIAS_Q20, lag ); - - /* Setup cbk parameters acording to complexity setting */ - cbk_size = (SKP_int)SKP_Silk_cbk_sizes_stage3[ complexity ]; - cbk_offset = (SKP_int)SKP_Silk_cbk_offsets_stage3[ complexity ]; - + contour_bias = SKP_DIV32_16( PE_FLATCONTOUR_BIAS_Q20, lag ); + + /* Setup cbk parameters acording to complexity setting and frame length */ + if( nb_subfr == PE_MAX_NB_SUBFR ) { + nb_cbk_search = (SKP_int)SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + cbk_offset = (SKP_int)SKP_Silk_cbk_offsets_stage3[ complexity ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + } else { + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + cbk_offset = 0; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + } for( d = start_lag; d <= end_lag; d++ ) { - for( j = cbk_offset; j < ( cbk_offset + cbk_size ); j++ ) { + for( j = cbk_offset; j < ( cbk_offset + nb_cbk_search ); j++ ) { cross_corr = 0; energy = 0; - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { - SKP_assert( PITCH_EST_NB_SUBFR == 4 ); + for( k = 0; k < nb_subfr; k++ ) { + SKP_assert( PE_MAX_NB_SUBFR == 4 ); energy += SKP_RSHIFT( energies_st3[ k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */ - SKP_assert( energy >= 0 ); + SKP_assert( energy >= 0 ); cross_corr += SKP_RSHIFT( crosscorr_st3[ k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */ } if( cross_corr > 0 ) { /* Divide cross_corr / energy and get result in Q15 */ lz = SKP_Silk_CLZ32( cross_corr ); /* Divide with result in Q13, cross_corr could be larger than energy */ - lshift = SKP_LIMIT( lz - 1, 0, 13 ); + lshift = SKP_LIMIT_32( lz - 1, 0, 13 ); CCmax_new = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 13 - lshift ) + 1 ); CCmax_new = SKP_SAT16( CCmax_new ); CCmax_new = SKP_SMULWB( cross_corr, CCmax_new ); @@ -565,7 +540,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv CCmax_new = SKP_LSHIFT( CCmax_new, 3 ); } /* Reduce depending on flatness of contour */ - diff = j - SKP_RSHIFT( PITCH_EST_NB_CBKS_STAGE3_MAX, 1 ); + diff = j - SKP_RSHIFT( cbk_size, 1 ); diff = SKP_MUL( diff, diff ); diff = SKP_int16_MAX - SKP_RSHIFT( SKP_MUL( contour_bias, diff ), 5 ); /* Q20 -> Q15 */ SKP_assert( diff == SKP_SAT16( diff ) ); @@ -583,8 +558,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv lag_counter++; } - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { - pitch_out[ k ] = lag_new + SKP_Silk_CB_lags_stage3[ k ][ CBimax ]; + 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; @@ -592,7 +567,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv /* Save Lags and correlation */ CCmax = SKP_max( CCmax, 0 ); *LTPCorr_Q15 = (SKP_int)SKP_Silk_SQRT_APPROX( SKP_LSHIFT( CCmax, 13 ) ); /* Output normalized correlation */ - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { pitch_out[ k ] = lag + SKP_Silk_CB_lags_stage2[ k ][ CBimax ]; } *lagIndex = lag - min_lag_8kHz; @@ -608,31 +583,47 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv /* the whole lag codebook for all the searched offset lags (lag +- 2), */ /*************************************************************************/ void SKP_FIX_P_Ana_calc_corr_st3( - SKP_int32 cross_corr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM correlation array */ + SKP_int32 cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ],/* (O) 3 DIM correlation array */ const SKP_int16 signal[], /* I vector to correlate */ SKP_int start_lag, /* I lag offset to search around */ SKP_int sf_length, /* I length of a 5 ms subframe */ + SKP_int nb_subfr, /* I number of subframes */ SKP_int complexity /* I Complexity setting */ ) { const SKP_int16 *target_ptr, *basis_ptr; - SKP_int32 cross_corr; - SKP_int i, j, k, lag_counter; - SKP_int cbk_offset, cbk_size, delta, idx; - SKP_int32 scratch_mem[ SCRATCH_SIZE ]; - - SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX ); - SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX ); - - cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; - cbk_size = SKP_Silk_cbk_sizes_stage3[ complexity ]; + SKP_int32 cross_corr; + SKP_int i, j, k, lag_counter, lag_low, lag_high; + SKP_int cbk_offset, nb_cbk_search, delta, idx, cbk_size; + SKP_int32 scratch_mem[ SCRATCH_SIZE ]; + const SKP_int8 *Lag_range_ptr, *Lag_CB_ptr; + + SKP_assert( complexity >= SKP_Silk_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SKP_Silk_PE_MAX_COMPLEX ); + + if( nb_subfr == PE_MAX_NB_SUBFR ){ + Lag_range_ptr = &SKP_Silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; + nb_cbk_search = SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + } else { + SKP_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); + Lag_range_ptr = &SKP_Silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + cbk_offset = 0; + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + } target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of frame */ - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { lag_counter = 0; /* Calculate the correlations for each subframe */ - for( j = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ]; j <= SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ]; j++ ) { + lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); + for( j = lag_low; j <= lag_high; j++ ) { basis_ptr = target_ptr - ( start_lag + j ); cross_corr = SKP_Silk_inner_prod_aligned( (SKP_int16*)target_ptr, (SKP_int16*)basis_ptr, sf_length ); SKP_assert( lag_counter < SCRATCH_SIZE ); @@ -640,12 +631,12 @@ void SKP_FIX_P_Ana_calc_corr_st3( lag_counter++; } - delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ]; - for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { + delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + for( i = cbk_offset; i < ( cbk_offset + nb_cbk_search ); i++ ) { /* Fill out the 3 dim array that stores the correlations for */ /* each code_book vector for each start lag */ - idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta; - for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) { + idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; + for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { SKP_assert( idx + j < SCRATCH_SIZE ); SKP_assert( idx + j < lag_counter ); cross_corr_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; @@ -660,37 +651,51 @@ void SKP_FIX_P_Ana_calc_corr_st3( /* calculated recursively. */ /********************************************************************/ void SKP_FIX_P_Ana_calc_energy_st3( - SKP_int32 energies_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM energy array */ + SKP_int32 energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ],/* (O) 3 DIM energy array */ const SKP_int16 signal[], /* I vector to calc energy in */ SKP_int start_lag, /* I lag offset to search around */ SKP_int sf_length, /* I length of one 5 ms subframe */ + SKP_int nb_subfr, /* I number of subframes */ SKP_int complexity /* I Complexity setting */ ) { const SKP_int16 *target_ptr, *basis_ptr; - SKP_int32 energy; - SKP_int k, i, j, lag_counter; - SKP_int cbk_offset, cbk_size, delta, idx; - SKP_int32 scratch_mem[ SCRATCH_SIZE ]; - - SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX ); - SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX ); - - cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; - cbk_size = SKP_Silk_cbk_sizes_stage3[ complexity ]; - + SKP_int32 energy; + SKP_int k, i, j, lag_counter; + SKP_int cbk_offset, nb_cbk_search, delta, idx, cbk_size, lag_diff; + SKP_int32 scratch_mem[ SCRATCH_SIZE ]; + const SKP_int8 *Lag_range_ptr, *Lag_CB_ptr; + + SKP_assert( complexity >= SKP_Silk_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SKP_Silk_PE_MAX_COMPLEX ); + + if( nb_subfr == PE_MAX_NB_SUBFR ){ + Lag_range_ptr = &SKP_Silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; + nb_cbk_search = SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + } else { + SKP_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); + Lag_range_ptr = &SKP_Silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + cbk_offset = 0; + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + } target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; - for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { lag_counter = 0; /* Calculate the energy for first lag */ - basis_ptr = target_ptr - ( start_lag + SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] ); + basis_ptr = target_ptr - ( start_lag + matrix_ptr( Lag_range_ptr, k, 0, 2 ) ); energy = SKP_Silk_inner_prod_aligned( basis_ptr, basis_ptr, sf_length ); SKP_assert( energy >= 0 ); scratch_mem[ lag_counter ] = energy; lag_counter++; - for( i = 1; i < ( SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ] - SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] + 1 ); i++ ) { + lag_diff = ( matrix_ptr( Lag_range_ptr, k, 1, 2 ) - matrix_ptr( Lag_range_ptr, k, 0, 2 ) + 1 ); + for( i = 1; i < lag_diff; i++ ) { /* remove part outside new window */ energy -= SKP_SMULBB( basis_ptr[ sf_length - i ], basis_ptr[ sf_length - i ] ); SKP_assert( energy >= 0 ); @@ -703,16 +708,16 @@ void SKP_FIX_P_Ana_calc_energy_st3( lag_counter++; } - delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ]; - for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { + delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + for( i = cbk_offset; i < ( cbk_offset + nb_cbk_search ); i++ ) { /* Fill out the 3 dim array that stores the correlations for */ - /* each code_book vector for each start lag */ - idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta; - for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) { + /* each code_book vector for each start lag */ + idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; + for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { SKP_assert( idx + j < SCRATCH_SIZE ); SKP_assert( idx + j < lag_counter ); energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; - SKP_assert( energies_st3[ k ][ i ][ j ] >= 0.0f ); + SKP_assert( energies_st3[ k ][ i ][ j ] >= 0 ); } } target_ptr += sf_length; diff --git a/src/SKP_Silk_pitch_est_defines.h b/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h similarity index 84% rename from src/SKP_Silk_pitch_est_defines.h rename to src_SigProc_FIX/SKP_Silk_pitch_est_defines.h index 97dd0a95e..86aabb15f 100644 --- a/src/SKP_Silk_pitch_est_defines.h +++ b/src_SigProc_FIX/SKP_Silk_pitch_est_defines.h @@ -25,19 +25,19 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -#ifndef SIGPROCFIX_PITCH_EST_DEFINES_H -#define SIGPROCFIX_PITCH_EST_DEFINES_H +#ifndef SKP_SILK_PE_DEFINES_H +#define SKP_SILK_PE_DEFINES_H #include "SKP_Silk_SigProc_FIX.h" #include "SKP_Silk_common_pitch_est_defines.h" /************************************************************/ -/* Definitions For Fix pitch estimator */ +/* Definitions For Fix pitch estimator */ /************************************************************/ -#define PITCH_EST_SHORTLAG_BIAS_Q15 6554 /* 0.2f. for logarithmic weighting */ -#define PITCH_EST_PREVLAG_BIAS_Q15 6554 /* Prev lag bias */ -#define PITCH_EST_FLATCONTOUR_BIAS_Q20 52429 /* 0.05f */ +#define PE_SHORTLAG_BIAS_Q15 6554 /* 0.2f. for logarithmic weighting */ +#define PE_PREVLAG_BIAS_Q15 6554 /* Prev lag bias */ +#define PE_FLATCONTOUR_BIAS_Q20 52429 /* 0.05f */ #endif diff --git a/src/SKP_Silk_pitch_est_tables.c b/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c similarity index 72% rename from src/SKP_Silk_pitch_est_tables.c rename to src_SigProc_FIX/SKP_Silk_pitch_est_tables.c index c15181928..8a49981b1 100644 --- a/src/SKP_Silk_pitch_est_tables.c +++ b/src_SigProc_FIX/SKP_Silk_pitch_est_tables.c @@ -28,11 +28,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_typedef.h" #include "SKP_Silk_pitch_est_defines.h" +const SKP_int8 SKP_Silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ PE_NB_CBKS_STAGE2_10MS ] = +{ + {0, 1, 0}, + {0, 0, 1} +}; + +const SKP_int8 SKP_Silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ PE_NB_CBKS_STAGE3_10MS ] = +{ + {-3,-2,-2,-1,-1, 0, 0, 1, 1, 2, 2,3}, + { 3, 3, 2, 2, 1, 1, 0, 0,-1,-1,-2,-2} +}; + +const SKP_int8 SKP_Silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ] = +{ + {-3, 7}, + {-2, 7} +}; + /********************************************************/ /* Auto Generated File from generate_pitch_est_tables.m */ /********************************************************/ -const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT] = +const SKP_int8 SKP_Silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ] = { {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, @@ -40,7 +58,7 @@ const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_ST {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1} }; -const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX] = +const SKP_int8 SKP_Silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ] = { {-9,-7,-6,-5,-5,-4,-4,-3,-3,-2,-2,-2,-1,-1,-1, 0, 0, 0, 1, 1, 0, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 5, 6, 8}, {-3,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 2, 2, 2, 2, 3}, @@ -48,7 +66,7 @@ const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_ST { 9, 8, 6, 5, 6, 5, 4, 4, 3, 3, 2, 2, 2, 1, 0, 1, 1, 0, 0, 0,-1,-1,-1,-2,-2,-2,-3,-3,-4,-4,-5,-5,-6,-7} }; -const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] = +const SKP_int8 SKP_Silk_Lag_range_stage3[ SKP_Silk_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ] = { /* Lags to search for low number of stage3 cbks */ { @@ -73,17 +91,17 @@ const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [ } }; -const SKP_int16 SKP_Silk_cbk_sizes_stage3[SigProc_PITCH_EST_MAX_COMPLEX + 1] = +const SKP_int8 SKP_Silk_nb_cbk_searchs_stage3[ SKP_Silk_PE_MAX_COMPLEX + 1 ] = { - PITCH_EST_NB_CBKS_STAGE3_MIN, - PITCH_EST_NB_CBKS_STAGE3_MID, - PITCH_EST_NB_CBKS_STAGE3_MAX + PE_NB_CBKS_STAGE3_MIN, + PE_NB_CBKS_STAGE3_MID, + PE_NB_CBKS_STAGE3_MAX }; -const SKP_int16 SKP_Silk_cbk_offsets_stage3[SigProc_PITCH_EST_MAX_COMPLEX + 1] = +const SKP_int8 SKP_Silk_cbk_offsets_stage3[ SKP_Silk_PE_MAX_COMPLEX + 1 ] = { - ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MIN) >> 1), - ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MID) >> 1), + ((PE_NB_CBKS_STAGE3_MAX - PE_NB_CBKS_STAGE3_MIN) >> 1), + ((PE_NB_CBKS_STAGE3_MAX - PE_NB_CBKS_STAGE3_MID) >> 1), 0 }; diff --git a/src_SigProc_FIX/SKP_Silk_resampler.c b/src_SigProc_FIX/SKP_Silk_resampler.c new file mode 100644 index 000000000..4ee313a3b --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler.c @@ -0,0 +1,323 @@ +/*********************************************************************** +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_resampler.c * + * * + * Description: Interface to collection of resamplers * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * */ + +/* Matrix of resampling methods used: + * Fs_out (kHz) + * 8 12 16 24 32 44.1 48 + * + * 8 C UF U UF UF UF UF + * 12 AF C UF U UF UF UF + * 16 D AF C UF U UF UF + * Fs_in (kHz) 24 AIF D AF C UF UF U + * 32 UF AF D AF C UF UF + * 44.1 AMI AMI AMI AMI AMI C UF + * 48 DAF DAF AF D AF UF C + * + * default method: UF + * + * C -> Copy (no resampling) + * D -> Allpass-based 2x downsampling + * U -> Allpass-based 2x upsampling + * DAF -> Allpass-based 2x downsampling followed by AR2 filter followed by FIR interpolation + * UF -> Allpass-based 2x upsampling followed by FIR interpolation + * AMI -> ARMA4 filter followed by FIR interpolation + * AF -> AR2 filter followed by FIR interpolation + * + * Input signals sampled above 48 kHz are first downsampled to at most 48 kHz. + * Output signals sampled above 48 kHz are upsampled from at most 48 kHz. + */ + +#include "SKP_Silk_resampler_private.h" + +/* Greatest common divisor */ +static SKP_int32 gcd( + SKP_int32 a, + SKP_int32 b +) +{ + SKP_int32 tmp; + while( b > 0 ) { + tmp = a - b * SKP_DIV32( a, b ); + a = b; + b = tmp; + } + return a; +} + +/* 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_int32 Fs_Hz_in, /* I: Input sampling rate (Hz) */ + SKP_int32 Fs_Hz_out /* I: Output sampling rate (Hz) */ +) +{ + SKP_int32 cycleLen, cyclesPerBatch, up2 = 0, down2 = 0; + + /* Clear state */ + SKP_memset( S, 0, sizeof( SKP_Silk_resampler_state_struct ) ); + + /* Input checking */ +#if RESAMPLER_SUPPORT_ABOVE_48KHZ + if( Fs_Hz_in < 8000 || Fs_Hz_in > 192000 || Fs_Hz_out < 8000 || Fs_Hz_out > 192000 ) { +#else + if( Fs_Hz_in < 8000 || Fs_Hz_in > 48000 || Fs_Hz_out < 8000 || Fs_Hz_out > 48000 ) { +#endif + SKP_assert( 0 ); + return -1; + } + +#if RESAMPLER_SUPPORT_ABOVE_48KHZ + /* Determine pre downsampling and post upsampling */ + if( Fs_Hz_in > 96000 ) { + S->nPreDownsamplers = 2; + S->down_pre_function = SKP_Silk_resampler_private_down4; + } else if( Fs_Hz_in > 48000 ) { + S->nPreDownsamplers = 1; + S->down_pre_function = SKP_Silk_resampler_down2; + } else { + S->nPreDownsamplers = 0; + S->down_pre_function = NULL; + } + + if( Fs_Hz_out > 96000 ) { + S->nPostUpsamplers = 2; + S->up_post_function = SKP_Silk_resampler_private_up4; + } else if( Fs_Hz_out > 48000 ) { + S->nPostUpsamplers = 1; + S->up_post_function = SKP_Silk_resampler_up2; + } else { + S->nPostUpsamplers = 0; + S->up_post_function = NULL; + } + + if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) { + /* Ratio of output/input samples */ + S->ratio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_out, 13 ), Fs_Hz_in ), 3 ); + /* Make sure the ratio is rounded up */ + while( SKP_SMULWW( S->ratio_Q16, Fs_Hz_in ) < Fs_Hz_out ) S->ratio_Q16++; + + /* Batch size is 10 ms */ + S->batchSizePrePost = SKP_DIV32_16( Fs_Hz_in, 100 ); + + /* Convert sampling rate to those after pre-downsampling and before post-upsampling */ + Fs_Hz_in = SKP_RSHIFT( Fs_Hz_in, S->nPreDownsamplers ); + Fs_Hz_out = SKP_RSHIFT( Fs_Hz_out, S->nPostUpsamplers ); + } +#endif + + /* Number of samples processed per batch */ + /* First, try 10 ms frames */ + S->batchSize = SKP_DIV32_16( Fs_Hz_in, 100 ); + if( ( SKP_MUL( S->batchSize, 100 ) != Fs_Hz_in ) || ( Fs_Hz_in % 100 != 0 ) ) { + /* No integer number of input or output samples with 10 ms frames, use greatest common divisor */ + cycleLen = SKP_DIV32( Fs_Hz_in, gcd( Fs_Hz_in, Fs_Hz_out ) ); + cyclesPerBatch = SKP_DIV32( RESAMPLER_MAX_BATCH_SIZE_IN, cycleLen ); + if( cyclesPerBatch == 0 ) { + /* cycleLen too big, let's just use the maximum batch size. Some distortion will result. */ + S->batchSize = RESAMPLER_MAX_BATCH_SIZE_IN; + SKP_assert( 0 ); + } else { + S->batchSize = SKP_MUL( cyclesPerBatch, cycleLen ); + } + } + + + /* Find resampler with the right sampling ratio */ + if( Fs_Hz_out > Fs_Hz_in ) { + /* Upsample */ + if( Fs_Hz_out == SKP_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 1 */ + /* Special case: directly use 2x upsampler */ + S->resampler_function = SKP_Silk_resampler_private_up2_HQ_wrapper; + } else { + /* Default resampler */ + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + up2 = 1; + if( Fs_Hz_in > 24000 ) { + /* Low-quality all-pass upsampler */ + S->up2_function = SKP_Silk_resampler_up2; + } else { + /* High-quality all-pass upsampler */ + S->up2_function = SKP_Silk_resampler_private_up2_HQ; + } + } + } else if ( Fs_Hz_out < Fs_Hz_in ) { + /* Downsample */ + if( SKP_MUL( Fs_Hz_out, 4 ) == SKP_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 4 */ + S->FIR_Fracs = 3; + S->Coefs = SKP_Silk_Resampler_3_4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 3 ) == SKP_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 3 */ + S->FIR_Fracs = 2; + S->Coefs = SKP_Silk_Resampler_2_3_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 2 */ + S->FIR_Fracs = 1; + S->Coefs = SKP_Silk_Resampler_1_2_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 8 ) == SKP_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 8 */ + S->FIR_Fracs = 3; + S->Coefs = SKP_Silk_Resampler_3_8_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 3 */ + S->FIR_Fracs = 1; + S->Coefs = SKP_Silk_Resampler_1_3_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 4 */ + S->FIR_Fracs = 1; + down2 = 1; + S->Coefs = SKP_Silk_Resampler_1_2_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 6 */ + S->FIR_Fracs = 1; + down2 = 1; + S->Coefs = SKP_Silk_Resampler_1_3_COEFS; + S->resampler_function = SKP_Silk_resampler_private_down_FIR; + } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 80 ) ) { /* Fs_out : Fs_in = 80 : 441 */ + S->Coefs = SKP_Silk_Resampler_80_441_ARMA4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 120 ) ) { /* Fs_out : Fs_in = 120 : 441 */ + S->Coefs = SKP_Silk_Resampler_120_441_ARMA4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 160 ) ) { /* Fs_out : Fs_in = 160 : 441 */ + S->Coefs = SKP_Silk_Resampler_160_441_ARMA4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 240 ) ) { /* Fs_out : Fs_in = 240 : 441 */ + S->Coefs = SKP_Silk_Resampler_240_441_ARMA4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 320 ) ) { /* Fs_out : Fs_in = 320 : 441 */ + S->Coefs = SKP_Silk_Resampler_320_441_ARMA4_COEFS; + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + } else { + /* Default resampler */ + S->resampler_function = SKP_Silk_resampler_private_IIR_FIR; + up2 = 1; + if( Fs_Hz_in > 24000 ) { + /* Low-quality all-pass upsampler */ + S->up2_function = SKP_Silk_resampler_up2; + } else { + /* High-quality all-pass upsampler */ + S->up2_function = SKP_Silk_resampler_private_up2_HQ; + } + } + } else { + /* Input and output sampling rates are equal: copy */ + S->resampler_function = SKP_Silk_resampler_private_copy; + } + + S->input2x = up2 | down2; + + /* Ratio of input/output samples */ + S->invRatio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_in, 14 + up2 - down2 ), Fs_Hz_out ), 2 ); + /* Make sure the ratio is rounded up */ + while( SKP_SMULWW( S->invRatio_Q16, SKP_LSHIFT32( Fs_Hz_out, down2 ) ) < SKP_LSHIFT32( Fs_Hz_in, up2 ) ) { + S->invRatio_Q16++; + } + + S->magic_number = 123456789; + + return 0; +} + +/* 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 */ +) +{ + /* Clear state */ + SKP_memset( S->sDown2, 0, sizeof( S->sDown2 ) ); + SKP_memset( S->sIIR, 0, sizeof( S->sIIR ) ); + SKP_memset( S->sFIR, 0, sizeof( S->sFIR ) ); +#if RESAMPLER_SUPPORT_ABOVE_48KHZ + SKP_memset( S->sDownPre, 0, sizeof( S->sDownPre ) ); + SKP_memset( S->sUpPost, 0, sizeof( S->sUpPost ) ); +#endif + return 0; +} + +/* Resampler: convert from one sampling rate to another */ +SKP_int SKP_Silk_resampler( + 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 */ +) +{ + /* Verify that state was initialized and has not been corrupted */ + if( S->magic_number != 123456789 ) { + SKP_assert( 0 ); + return -1; + } + +#if RESAMPLER_SUPPORT_ABOVE_48KHZ + if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) { + /* The input and/or output sampling rate is above 48000 Hz */ + SKP_int32 nSamplesIn, nSamplesOut; + SKP_int16 in_buf[ 480 ], out_buf[ 480 ]; + + while( inLen > 0 ) { + /* Number of input and output samples to process */ + nSamplesIn = SKP_min( inLen, S->batchSizePrePost ); + nSamplesOut = SKP_SMULWB( S->ratio_Q16, nSamplesIn ); + + SKP_assert( SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) <= 480 ); + SKP_assert( SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) <= 480 ); + + if( S->nPreDownsamplers > 0 ) { + S->down_pre_function( S->sDownPre, in_buf, in, nSamplesIn ); + if( S->nPostUpsamplers > 0 ) { + S->resampler_function( S, out_buf, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) ); + S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) ); + } else { + S->resampler_function( S, out, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) ); + } + } else { + S->resampler_function( S, out_buf, in, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) ); + S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) ); + } + + in += nSamplesIn; + out += nSamplesOut; + inLen -= nSamplesIn; + } + } else +#endif + { + /* Input and output sampling rate are at most 48000 Hz */ + S->resampler_function( S, out, in, inLen ); + } + + return 0; +} diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down2.c b/src_SigProc_FIX/SKP_Silk_resampler_down2.c new file mode 100644 index 000000000..a153c90f8 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_down2.c @@ -0,0 +1,79 @@ +/*********************************************************************** +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_resampler_down2.c * + * * + * Downsample by a factor 2, mediocre quality * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_rom.h" + +#if (EMBEDDED_ARM<5) && (!defined(__mips__)) +/* Downsample by a factor 2, mediocre quality */ +void SKP_Silk_resampler_down2( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ len ] */ + const SKP_int16 *in, /* I: Input signal [ floor(len/2) ] */ + SKP_int32 inLen /* I: Number of input samples */ +) +{ + SKP_int32 k, len2 = SKP_RSHIFT32( inLen, 1 ); + SKP_int32 in32, out32, Y, X; + + SKP_assert( SKP_Silk_resampler_down2_0 > 0 ); + SKP_assert( SKP_Silk_resampler_down2_1 < 0 ); + + /* Internal variables and state are in Q10 format */ + for( k = 0; k < len2; k++ ) { + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 ); + + /* All-pass section for even input sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 ); + out32 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); + + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 ); + + /* All-pass section for odd input sample, and add to output of previous section */ + Y = SKP_SUB32( in32, S[ 1 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 ); + out32 = SKP_ADD32( out32, S[ 1 ] ); + out32 = SKP_ADD32( out32, X ); + S[ 1 ] = SKP_ADD32( in32, X ); + + /* Add, convert back to int16 and store to output */ + out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) ); + } +} +#endif diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c b/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c new file mode 100644 index 000000000..9c4d64426 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_down2_3.c @@ -0,0 +1,102 @@ +/*********************************************************************** +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_resampler_down2_3.c * + * * + * Downsample by a factor 2/3, low quality * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +#define ORDER_FIR 4 + +/* Downsample by a factor 2/3, low quality */ +void SKP_Silk_resampler_down2_3( + SKP_int32 *S, /* I/O: State vector [ 6 ] */ + SKP_int16 *out, /* O: Output signal [ floor(2*inLen/3) ] */ + const SKP_int16 *in, /* I: Input signal [ inLen ] */ + SKP_int32 inLen /* I: Number of input samples */ +) +{ + SKP_int32 nSamplesIn, counter, res_Q6; + SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ]; + SKP_int32 *buf_ptr; + + /* Copy buffered samples to start of buffer */ + SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) ); + + /* Iterate over blocks of frameSizeIn input samples */ + while( 1 ) { + nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN ); + + /* Second-order AR filter (output in Q8) */ + SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, + SKP_Silk_Resampler_2_3_COEFS_LQ, nSamplesIn ); + + /* Interpolate filtered signal */ + buf_ptr = buf; + counter = nSamplesIn; + while( counter > 2 ) { + /* Inner product */ + res_Q6 = SKP_SMULWB( buf_ptr[ 0 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] ); + + /* Scale down, saturate and store in output array */ + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) ); + + res_Q6 = SKP_SMULWB( buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] ); + + /* Scale down, saturate and store in output array */ + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) ); + + buf_ptr += 3; + counter -= 3; + } + + in += nSamplesIn; + inLen -= nSamplesIn; + + if( inLen > 0 ) { + /* More iterations to do; copy last part of filtered signal to beginning of buffer */ + SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) ); + } else { + break; + } + } + + /* Copy last part of filtered signal to the state for the next call */ + SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) ); +} diff --git a/src_SigProc_FIX/SKP_Silk_resampler_down3.c b/src_SigProc_FIX/SKP_Silk_resampler_down3.c new file mode 100644 index 000000000..661673920 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_down3.c @@ -0,0 +1,93 @@ +/*********************************************************************** +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_resampler_down3.c * + * * + * Downsample by a factor 3, low quality * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +#define ORDER_FIR 6 + +/* Downsample by a factor 3, low quality */ +void SKP_Silk_resampler_down3( + SKP_int32 *S, /* I/O: State vector [ 8 ] */ + SKP_int16 *out, /* O: Output signal [ floor(inLen/3) ] */ + const SKP_int16 *in, /* I: Input signal [ inLen ] */ + SKP_int32 inLen /* I: Number of input samples */ +) +{ + SKP_int32 nSamplesIn, counter, res_Q6; + SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ]; + SKP_int32 *buf_ptr; + + /* Copy buffered samples to start of buffer */ + SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) ); + + /* Iterate over blocks of frameSizeIn input samples */ + while( 1 ) { + nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN ); + + /* Second-order AR filter (output in Q8) */ + SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, + SKP_Silk_Resampler_1_3_COEFS_LQ, nSamplesIn ); + + /* Interpolate filtered signal */ + buf_ptr = buf; + counter = nSamplesIn; + while( counter > 2 ) { + /* Inner product */ + res_Q6 = SKP_SMULWB( SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 5 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 4 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[ 3 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 4 ] ); + + /* Scale down, saturate and store in output array */ + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) ); + + buf_ptr += 3; + counter -= 3; + } + + in += nSamplesIn; + inLen -= nSamplesIn; + + if( inLen > 0 ) { + /* More iterations to do; copy last part of filtered signal to beginning of buffer */ + SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) ); + } else { + break; + } + } + + /* Copy last part of filtered signal to the state for the next call */ + SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) ); +} diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private.h b/src_SigProc_FIX/SKP_Silk_resampler_private.h new file mode 100644 index 000000000..d8dd74671 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private.h @@ -0,0 +1,130 @@ +/*********************************************************************** +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_resampler_structs.h * + * * + * Description: Structs for IIR/FIR resamplers * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * * + * */ + +#ifndef SKP_Silk_RESAMPLER_H +#define SKP_Silk_RESAMPLER_H +#ifdef __cplusplus +extern "C" { +#endif + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_structs.h" +#include "SKP_Silk_resampler_rom.h" + +/* Number of input samples to process in the inner loop */ +#define RESAMPLER_MAX_BATCH_SIZE_IN 480 + +/* Description: Hybrid IIR/FIR polyphase implementation of resampling */ +void SKP_Silk_resampler_private_IIR_FIR( + void *SS, /* 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 */ +); + +/* Description: Hybrid IIR/FIR polyphase implementation of resampling */ +void SKP_Silk_resampler_private_down_FIR( + void *SS, /* 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 */ +); + +/* Copy */ +void SKP_Silk_resampler_private_copy( + void *SS, /* I/O: Resampler state (unused) */ + SKP_int16 out[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + SKP_int32 inLen /* I: Number of input samples */ +); + +/* Upsample by a factor 2, high quality */ +void SKP_Silk_resampler_private_up2_HQ_wrapper( + void *SS, /* I/O: Resampler state (unused) */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of input samples */ +); + +/* Upsample by a factor 2, high quality */ +void SKP_Silk_resampler_private_up2_HQ( + SKP_int32 *S, /* I/O: Resampler state [ 6 ] */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of input samples */ +); + +/* Upsample 4x, low quality */ +void SKP_Silk_resampler_private_up4( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ 4 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of input samples */ +); + +/* Downsample 4x, low quality */ +void SKP_Silk_resampler_private_down4( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ floor(len/2) ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 inLen /* I: Number of input samples */ +); + +/* Second order AR filter */ +void SKP_Silk_resampler_private_AR2( + SKP_int32 S[], /* I/O: State vector [ 2 ] */ + SKP_int32 out_Q8[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + const SKP_int16 A_Q14[], /* I: AR coefficients, Q14 */ + SKP_int32 len /* I: Signal length */ +); + +/* Fourth order ARMA filter */ +void SKP_Silk_resampler_private_ARMA4( + SKP_int32 S[], /* I/O: State vector [ 4 ] */ + SKP_int16 out[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + const SKP_int16 Coef[], /* I: ARMA coefficients [ 7 ] */ + SKP_int32 len /* I: Signal length */ +); + + +#ifdef __cplusplus +} +#endif +#endif // SKP_Silk_RESAMPLER_H + diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c b/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c new file mode 100644 index 000000000..9e8a1416f --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_AR2.c @@ -0,0 +1,60 @@ +/*********************************************************************** +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_resampler_private_AR2. c * + * * + * Second order AR filter with single delay elements * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +#if (EMBEDDED_ARM<5) && (!defined(__mips__)) +/* Second order AR filter with single delay elements */ +void SKP_Silk_resampler_private_AR2( + SKP_int32 S[], /* I/O: State vector [ 2 ] */ + SKP_int32 out_Q8[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + const SKP_int16 A_Q14[], /* I: AR coefficients, Q14 */ + SKP_int32 len /* I: Signal length */ +) +{ + SKP_int32 k; + SKP_int32 out32; + + for( k = 0; k < len; k++ ) { + out32 = SKP_ADD_LSHIFT32( S[ 0 ], (SKP_int32)in[ k ], 8 ); + out_Q8[ k ] = out32; + out32 = SKP_LSHIFT( out32, 2 ); + S[ 0 ] = SKP_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] ); + S[ 1 ] = SKP_SMULWB( out32, A_Q14[ 1 ] ); + } +} +#endif diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c b/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c new file mode 100644 index 000000000..47230596a --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_ARMA4.c @@ -0,0 +1,79 @@ +/*********************************************************************** +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_resampler_private_ARMA4.c * + * * + * Fourth order ARMA filter, applies 64x gain * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +/* Fourth order ARMA filter */ +/* Internally operates as two biquad filters in sequence. */ + +/* Coeffients are stored in a packed format: */ +/* { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 } */ +/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384 */ +#if (EMBEDDED_ARM<5) && (!defined(__mips__)) +void SKP_Silk_resampler_private_ARMA4( + SKP_int32 S[], /* I/O: State vector [ 4 ] */ + SKP_int16 out[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + const SKP_int16 Coef[], /* I: ARMA coefficients [ 7 ] */ + SKP_int32 len /* I: Signal length */ +) +{ + SKP_int32 k; + SKP_int32 in_Q8, out1_Q8, out2_Q8, X; + + for( k = 0; k < len; k++ ) { + in_Q8 = SKP_LSHIFT32( (SKP_int32)in[ k ], 8 ); + + /* Outputs of first and second biquad */ + out1_Q8 = SKP_ADD_LSHIFT32( in_Q8, S[ 0 ], 2 ); + out2_Q8 = SKP_ADD_LSHIFT32( out1_Q8, S[ 2 ], 2 ); + + /* Update states, which are stored in Q6. Coefficients are in Q14 here */ + X = SKP_SMLAWB( S[ 1 ], in_Q8, Coef[ 0 ] ); + S[ 0 ] = SKP_SMLAWB( X, out1_Q8, Coef[ 2 ] ); + + X = SKP_SMLAWB( S[ 3 ], out1_Q8, Coef[ 1 ] ); + S[ 2 ] = SKP_SMLAWB( X, out2_Q8, Coef[ 4 ] ); + + S[ 1 ] = SKP_SMLAWB( SKP_RSHIFT32( in_Q8, 2 ), out1_Q8, Coef[ 3 ] ); + S[ 3 ] = SKP_SMLAWB( SKP_RSHIFT32( out1_Q8, 2 ), out2_Q8, Coef[ 5 ] ); + + /* Apply gain and store to output. The coefficient is in Q16 */ + out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( SKP_SMLAWB( 128, out2_Q8, Coef[ 6 ] ), 8 ) ); + } +} +#endif + diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c b/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c new file mode 100644 index 000000000..e80ce1ca6 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_IIR_FIR.c @@ -0,0 +1,105 @@ +/*********************************************************************** +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_resampler_private_IIR_FIR.c * + * * + * Description: Hybrid IIR/FIR polyphase implementation of resampling * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" +SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_IIR_FIR_INTERPOL( + SKP_int16 * out, SKP_int16 * buf, SKP_int32 max_index_Q16 , SKP_int32 index_increment_Q16 ){ + SKP_int32 index_Q16, res_Q15; + SKP_int16 *buf_ptr; + SKP_int32 table_index; + /* Interpolate upsampled signal and store in output array */ + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + table_index = SKP_SMULWB( index_Q16 & 0xFFFF, 144 ); + buf_ptr = &buf[ index_Q16 >> 16 ]; + + res_Q15 = SKP_SMULBB( buf_ptr[ 0 ], SKP_Silk_resampler_frac_FIR_144[ table_index ][ 0 ] ); + res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 1 ], SKP_Silk_resampler_frac_FIR_144[ table_index ][ 1 ] ); + res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 2 ], SKP_Silk_resampler_frac_FIR_144[ table_index ][ 2 ] ); + res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 3 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 2 ] ); + res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 4 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 1 ] ); + res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 5 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 0 ] ); + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q15, 15 ) ); + } + return out; +} +/* Upsample using a combination of allpass-based 2x upsampling and FIR interpolation */ +void SKP_Silk_resampler_private_IIR_FIR( + void *SS, /* 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 */ +) +{ + SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS; + SKP_int32 nSamplesIn; + SKP_int32 max_index_Q16, index_increment_Q16; + SKP_int16 buf[ 2 * RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_144 ]; + + + /* Copy buffered samples to start of buffer */ + SKP_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) ); + + /* Iterate over blocks of frameSizeIn input samples */ + index_increment_Q16 = S->invRatio_Q16; + while( 1 ) { + nSamplesIn = SKP_min( inLen, S->batchSize ); + + if( S->input2x == 1 ) { + /* Upsample 2x */ + S->up2_function( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, nSamplesIn ); + } else { + /* Fourth-order ARMA filter */ + SKP_Silk_resampler_private_ARMA4( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, S->Coefs, nSamplesIn ); + } + + max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 + S->input2x ); /* +1 if 2x upsampling */ + out = SKP_Silk_resampler_private_IIR_FIR_INTERPOL(out, buf, max_index_Q16, index_increment_Q16); + in += nSamplesIn; + inLen -= nSamplesIn; + + if( inLen > 0 ) { + /* More iterations to do; copy last part of filtered signal to beginning of buffer */ + SKP_memcpy( buf, &buf[ nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) ); + } else { + break; + } + } + + /* Copy last part of filtered signal to the state for the next call */ + SKP_memcpy( S->sFIR, &buf[nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) ); +} + diff --git a/src/SKP_Silk_resample_3_2_rom.c b/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c similarity index 66% rename from src/SKP_Silk_resample_3_2_rom.c rename to src_SigProc_FIX/SKP_Silk_resampler_private_copy.c index 371060416..2c151e7f6 100644 --- a/src/SKP_Silk_resample_3_2_rom.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_copy.c @@ -25,22 +25,25 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -/* * - * File Name: SKP_Silk_resample_3_2_rom.c * +/* * + * File Name: SKP_Silk_resampler_private_copy.c * + * * + * Description: Copy. * * * - * Description: Filter coefficients for FIR polyphase resampling * - * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090424 * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * * */ -#include "SKP_Silk_resample_rom.h" - -const SKP_int16 SigProc_Resample_3_2_coarse_INTERPOL[ SigProc_Resample_3_2_coarse_NUM_INTERPOLATORS ][ SigProc_Resample_3_2_coarse_NUM_FIR_COEFS ] = { - { 0, 0, 0, 32768, 0, 0, 0, 0 }, - { -384, 1630, -5217, 26674, 12714, -3572, 1050, -236 }, - { -236, 1050, -3572, 12714, 26674, -5217, 1630, -384 }, -}; +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" +/* Copy */ +void SKP_Silk_resampler_private_copy( + void *SS, /* I/O: Resampler state (unused) */ + SKP_int16 out[], /* O: Output signal */ + const SKP_int16 in[], /* I: Input signal */ + SKP_int32 inLen /* I: Number of input samples */ +) +{ + SKP_memcpy( out, in, inLen * sizeof( SKP_int16 ) ); +} diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c b/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c new file mode 100644 index 000000000..6fb1506a6 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_down4.c @@ -0,0 +1,77 @@ +/*********************************************************************** +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_resampler_private_down4.c * + * * + * Downsample by a factor 4 * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +/* Downsample by a factor 4. Note: very low quality, only use with input sampling rates above 96 kHz. */ +void SKP_Silk_resampler_private_down4( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ floor(len/2) ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 inLen /* I: Number of input samples */ +) +{ + SKP_int32 k, len4 = SKP_RSHIFT32( inLen, 2 ); + SKP_int32 in32, out32, Y, X; + + SKP_assert( SKP_Silk_resampler_down2_0 > 0 ); + SKP_assert( SKP_Silk_resampler_down2_1 < 0 ); + + /* Internal variables and state are in Q10 format */ + for( k = 0; k < len4; k++ ) { + /* Add two input samples and convert to Q10 */ + in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k ], (SKP_int32)in[ 4 * k + 1 ] ), 9 ); + + /* All-pass section for even input sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 ); + out32 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); + + /* Add two input samples and convert to Q10 */ + in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k + 2 ], (SKP_int32)in[ 4 * k + 3 ] ), 9 ); + + /* All-pass section for odd input sample */ + Y = SKP_SUB32( in32, S[ 1 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 ); + out32 = SKP_ADD32( out32, S[ 1 ] ); + out32 = SKP_ADD32( out32, X ); + S[ 1 ] = SKP_ADD32( in32, X ); + + /* Add, convert back to int16 and store to output */ + out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) ); + } +} diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c b/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c new file mode 100644 index 000000000..e86443716 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_down_FIR.c @@ -0,0 +1,160 @@ +/*********************************************************************** +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_resampler_private_down_FIR.c * + * * + * Description: Hybrid IIR/FIR polyphase implementation of resampling * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" +SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL0( + SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16){ + + SKP_int32 index_Q16, res_Q6; + SKP_int32 *buf_ptr; + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + /* Integer part gives pointer to buffered input */ + buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 ); + + /* Inner product */ + res_Q6 = SKP_SMULWB( SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 11 ] ), FIR_Coefs[ 0 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 10 ] ), FIR_Coefs[ 1 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[ 9 ] ), FIR_Coefs[ 2 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 3 ], buf_ptr[ 8 ] ), FIR_Coefs[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 4 ], buf_ptr[ 7 ] ), FIR_Coefs[ 4 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 5 ], buf_ptr[ 6 ] ), FIR_Coefs[ 5 ] ); + + /* Scale down, saturate and store in output array */ + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) ); + } + return out; +} + +SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL1( + SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16, SKP_int32 FIR_Fracs){ + + SKP_int32 index_Q16, res_Q6; + SKP_int32 *buf_ptr; + SKP_int32 interpol_ind; + const SKP_int16 *interpol_ptr; + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + /* Integer part gives pointer to buffered input */ + buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 ); + + /* Fractional part gives interpolation coefficients */ + interpol_ind = SKP_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs ); + + /* Inner product */ + interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * interpol_ind ]; + res_Q6 = SKP_SMULWB( buf_ptr[ 0 ], interpol_ptr[ 0 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] ); + interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * ( FIR_Fracs - 1 - interpol_ind ) ]; + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 0 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 1 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 9 ], interpol_ptr[ 2 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 8 ], interpol_ptr[ 3 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 7 ], interpol_ptr[ 4 ] ); + res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 6 ], interpol_ptr[ 5 ] ); + + /* Scale down, saturate and store in output array */ + *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) ); + } + return out; +} + + +/* Resample with a 2x downsampler (optional), a 2nd order AR filter followed by FIR interpolation */ +void SKP_Silk_resampler_private_down_FIR( + void *SS, /* 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 */ +) +{ + SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS; + SKP_int32 nSamplesIn; + SKP_int32 max_index_Q16, index_increment_Q16; + SKP_int16 buf1[ RESAMPLER_MAX_BATCH_SIZE_IN / 2 ]; + SKP_int32 buf2[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_DOWN_ORDER_FIR ]; + const SKP_int16 *FIR_Coefs; + + /* Copy buffered samples to start of buffer */ + SKP_memcpy( buf2, S->sFIR, RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) ); + + FIR_Coefs = &S->Coefs[ 2 ]; + + /* Iterate over blocks of frameSizeIn input samples */ + index_increment_Q16 = S->invRatio_Q16; + while( 1 ) { + nSamplesIn = SKP_min( inLen, S->batchSize ); + + if( S->input2x == 1 ) { + /* Downsample 2x */ + SKP_Silk_resampler_down2( S->sDown2, buf1, in, nSamplesIn ); + + nSamplesIn = SKP_RSHIFT32( nSamplesIn, 1 ); + + /* Second-order AR filter (output in Q8) */ + SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], buf1, S->Coefs, nSamplesIn ); + } else { + /* Second-order AR filter (output in Q8) */ + SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], in, S->Coefs, nSamplesIn ); + } + + max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 ); + + /* Interpolate filtered signal */ + if( S->FIR_Fracs == 1 ) { + out = SKP_Silk_resampler_private_down_FIR_INTERPOL0(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16); + } else { + out = SKP_Silk_resampler_private_down_FIR_INTERPOL1(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16, S->FIR_Fracs); + } + + in += nSamplesIn << S->input2x; + inLen -= nSamplesIn << S->input2x; + + if( inLen > S->input2x ) { + /* More iterations to do; copy last part of filtered signal to beginning of buffer */ + SKP_memcpy( buf2, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) ); + } else { + break; + } + } + + /* Copy last part of filtered signal to the state for the next call */ + SKP_memcpy( S->sFIR, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) ); +} + diff --git a/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c b/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c new file mode 100644 index 000000000..8b8b2fec4 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c @@ -0,0 +1,120 @@ +/*********************************************************************** +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_resampler_private_up2_HQ.c * + * * + * Upsample by a factor 2, high quality * + * * + * Copyright 2010 (c), Skype Limited * + * */ + +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_private.h" + +/* Upsample by a factor 2, high quality */ +/* Uses 2nd order allpass filters for the 2x upsampling, followed by a */ +/* notch filter just above Nyquist. */ +#if (EMBEDDED_ARM<5) && (!defined(__mips__)) +void SKP_Silk_resampler_private_up2_HQ( + SKP_int32 *S, /* I/O: Resampler state [ 6 ] */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of INPUT samples */ +) +{ + SKP_int32 k; + SKP_int32 in32, out32_1, out32_2, Y, X; + + SKP_assert( SKP_Silk_resampler_up2_hq_0[ 0 ] > 0 ); + SKP_assert( SKP_Silk_resampler_up2_hq_0[ 1 ] < 0 ); + SKP_assert( SKP_Silk_resampler_up2_hq_1[ 0 ] > 0 ); + SKP_assert( SKP_Silk_resampler_up2_hq_1[ 1 ] < 0 ); + + /* Internal variables and state are in Q10 format */ + for( k = 0; k < len; k++ ) { + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); + + /* First all-pass section for even output sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_0[ 0 ] ); + out32_1 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); + + /* Second all-pass section for even output sample */ + Y = SKP_SUB32( out32_1, S[ 1 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_0[ 1 ] ); + out32_2 = SKP_ADD32( S[ 1 ], X ); + S[ 1 ] = SKP_ADD32( out32_1, X ); + + /* Biquad notch filter */ + out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] ); + out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] ); + out32_1 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] ); + S[ 5 ] = SKP_SUB32( out32_2, S[ 5 ] ); + + /* Apply gain in Q15, convert back to int16 and store to output */ + out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( + SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) ); + + /* First all-pass section for odd output sample */ + Y = SKP_SUB32( in32, S[ 2 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_1[ 0 ] ); + out32_1 = SKP_ADD32( S[ 2 ], X ); + S[ 2 ] = SKP_ADD32( in32, X ); + + /* Second all-pass section for odd output sample */ + Y = SKP_SUB32( out32_1, S[ 3 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_1[ 1 ] ); + out32_2 = SKP_ADD32( S[ 3 ], X ); + S[ 3 ] = SKP_ADD32( out32_1, X ); + + /* Biquad notch filter */ + out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] ); + out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] ); + out32_1 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] ); + S[ 4 ] = SKP_SUB32( out32_2, S[ 4 ] ); + + /* Apply gain in Q15, convert back to int16 and store to output */ + out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( + SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) ); + } +} +#endif + + +void SKP_Silk_resampler_private_up2_HQ_wrapper( + void *SS, /* I/O: Resampler state (unused) */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of input samples */ +) +{ + SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS; + SKP_Silk_resampler_private_up2_HQ( S->sIIR, out, in, len ); +} diff --git a/src/SKP_Silk_resample_1_2.c b/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c similarity index 51% rename from src/SKP_Silk_resample_1_2.c rename to src_SigProc_FIX/SKP_Silk_resampler_private_up4.c index 712e32d92..add8419e4 100644 --- a/src/SKP_Silk_resample_1_2.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_private_up4.c @@ -26,52 +26,56 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * SKP_Silk_resample_1_2 * + * SKP_Silk_resampler_private_up4.c * * * - * Downsample by a factor 2 * + * Upsample by a factor 4, low quality * * * - * Copyright 2006 (c), Skype Limited * - * Date: 060221 * + * Copyright 2010 (c), Skype Limited * * */ -#include "SKP_Silk_SigProc_FIX.h" - -/* Coefficients for 2-fold resampling */ -static SKP_int16 A20_Resample_1_2[ 3 ] = { 1254, 10102, 22898 }; -static SKP_int16 A21_Resample_1_2[ 3 ] = { 4810, 16371, 29374 }; +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_rom.h" -/* Downsample by a factor 2 */ -void SKP_Silk_resample_1_2( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: State vector [6] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *scratch, /* I: Scratch memory [4*len] */ - const SKP_int32 len /* I: Number of OUTPUT samples*/ +/* Upsample by a factor 4, Note: very low quality, only use with output sampling rates above 96 kHz. */ +void SKP_Silk_resampler_private_up4( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ 4 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of INPUT samples */ ) { - SKP_int32 k, idx; + SKP_int32 k; + SKP_int32 in32, out32, Y, X; + SKP_int16 out16; + + SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 ); + SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 ); - /* De-interleave allpass inputs, and convert Q15 -> Q25 */ + /* Internal variables and state are in Q10 format */ for( k = 0; k < len; k++ ) { - idx = SKP_LSHIFT( k, 1 ); - scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 ); - scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 ); - } + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); - idx = SKP_LSHIFT( len, 1 ); + /* All-pass section for even output sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 ); + out32 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); - /* Allpass filters */ - SKP_Silk_allpass_int( scratch, S, A21_Resample_1_2[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 1, A21_Resample_1_2[ 1 ], scratch + idx + len, len ); - SKP_Silk_allpass_int( scratch + idx + len, S + 2, A21_Resample_1_2[ 2 ], scratch, len ); + /* Convert back to int16 and store to output */ + out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); + out[ 4 * k ] = out16; + out[ 4 * k + 1 ] = out16; - SKP_Silk_allpass_int( scratch + len, S + 3, A20_Resample_1_2[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 4, A20_Resample_1_2[ 1 ], scratch + idx + len, len ); - SKP_Silk_allpass_int( scratch + idx + len, S + 5, A20_Resample_1_2[ 2 ], scratch + len, len ); + /* All-pass section for odd output sample */ + Y = SKP_SUB32( in32, S[ 1 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 ); + out32 = SKP_ADD32( S[ 1 ], X ); + S[ 1 ] = SKP_ADD32( in32, X ); - /* Add two allpass outputs */ - for( k = 0; k < len; k++ ) { - out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + len ], 11 ) ); + /* Convert back to int16 and store to output */ + out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); + out[ 4 * k + 2 ] = out16; + out[ 4 * k + 3 ] = out16; } } - diff --git a/src_SigProc_FIX/SKP_Silk_resampler_rom.c b/src_SigProc_FIX/SKP_Silk_resampler_rom.c new file mode 100644 index 000000000..1418cae44 --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_rom.c @@ -0,0 +1,276 @@ +/*********************************************************************** +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_resampler_rom.c * + * * + * Description: Filter coefficients for IIR/FIR polyphase resampling * + * Total size: 550 Words (1.1 kB) * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * */ + +#include "SKP_Silk_resampler_private.h" + + +#if EMBEDDED_ARM +#define SKP_DWORD_ALIGN __attribute__((aligned(4))) +#else +#define SKP_DWORD_ALIGN +#endif + +/* Tables for 2x downsampler. Values above 32767 intentionally wrap to a negative value. */ +const SKP_int16 SKP_Silk_resampler_down2_0 = 9872; +const SKP_int16 SKP_Silk_resampler_down2_1 = 39809; + +/* Tables for 2x upsampler, low quality. Values above 32767 intentionally wrap to a negative value. */ +const SKP_int16 SKP_Silk_resampler_up2_lq_0 = 8102; +const SKP_int16 SKP_Silk_resampler_up2_lq_1 = 36783; + +/* Tables for 2x upsampler, high quality. Values above 32767 intentionally wrap to a negative value. */ +const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ] = { 4280, 33727 }; +const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ] = { 16295, 54015 }; +/* Matlab code for the notch filter coefficients: */ +/* B = [1, 0.12, 1]; A = [1, 0.055, 0.8]; G = 0.87; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]); */ +/* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */ +const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ] = { 7864, -3604, 13107, 28508 }; + + +/* Tables with IIR and FIR coefficients for fractional downsamplers (70 Words) */ +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = { + -18249, -12532, + -97, 284, -495, 309, 10268, 20317, + -94, 156, -48, -720, 5984, 18278, + -45, -4, 237, -847, 2540, 14662, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = { + -11891, -12486, + 20, 211, -657, 688, 8423, 15911, + -44, 197, -152, -653, 3855, 13015, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = { + 2415, -13101, + 158, -295, -400, 1265, 4832, 7968, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = { + 13270, -13738, + -294, -123, 747, 2043, 3339, 3995, + -151, -311, 414, 1583, 2947, 3877, + -33, -389, 143, 1141, 2503, 3653, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = { + 16643, -14000, + -331, 19, 581, 1421, 2290, 2845, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = { + -2797, -6507, + 4697, 10739, + 1567, 8276, +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ] = { + 16777, -9792, + 890, 1614, 2148, +}; + + +/* Tables with coefficients for 4th order ARMA filter (35 Words), in a packed format: */ +/* { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 } */ +/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384 */ +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ] = { + 31454, 24746, -9706, -3386, -17911, -13243, 24797 +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ] = { + 28721, 11254, 3189, -2546, -1495, -12618, 11562 +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ] = { + 23492, -6457, 14358, -4856, 14654, -13008, 4456 +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ] = { + 19311, -15569, 19489, -6950, 21441, -13559, 2370 +}; + +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ] = { + 13248, -23849, 24126, -9486, 26806, -14286, 1065 +}; + +/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */ +SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ] = { + { -647, 1884, 30078}, + { -625, 1736, 30044}, + { -603, 1591, 30005}, + { -581, 1448, 29963}, + { -559, 1308, 29917}, + { -537, 1169, 29867}, + { -515, 1032, 29813}, + { -494, 898, 29755}, + { -473, 766, 29693}, + { -452, 636, 29627}, + { -431, 508, 29558}, + { -410, 383, 29484}, + { -390, 260, 29407}, + { -369, 139, 29327}, + { -349, 20, 29242}, + { -330, -97, 29154}, + { -310, -211, 29062}, + { -291, -324, 28967}, + { -271, -434, 28868}, + { -253, -542, 28765}, + { -234, -647, 28659}, + { -215, -751, 28550}, + { -197, -852, 28436}, + { -179, -951, 28320}, + { -162, -1048, 28200}, + { -144, -1143, 28077}, + { -127, -1235, 27950}, + { -110, -1326, 27820}, + { -94, -1414, 27687}, + { -77, -1500, 27550}, + { -61, -1584, 27410}, + { -45, -1665, 27268}, + { -30, -1745, 27122}, + { -15, -1822, 26972}, + { 0, -1897, 26820}, + { 15, -1970, 26665}, + { 29, -2041, 26507}, + { 44, -2110, 26346}, + { 57, -2177, 26182}, + { 71, -2242, 26015}, + { 84, -2305, 25845}, + { 97, -2365, 25673}, + { 110, -2424, 25498}, + { 122, -2480, 25320}, + { 134, -2534, 25140}, + { 146, -2587, 24956}, + { 157, -2637, 24771}, + { 168, -2685, 24583}, + { 179, -2732, 24392}, + { 190, -2776, 24199}, + { 200, -2819, 24003}, + { 210, -2859, 23805}, + { 220, -2898, 23605}, + { 229, -2934, 23403}, + { 238, -2969, 23198}, + { 247, -3002, 22992}, + { 255, -3033, 22783}, + { 263, -3062, 22572}, + { 271, -3089, 22359}, + { 279, -3114, 22144}, + { 286, -3138, 21927}, + { 293, -3160, 21709}, + { 300, -3180, 21488}, + { 306, -3198, 21266}, + { 312, -3215, 21042}, + { 318, -3229, 20816}, + { 323, -3242, 20589}, + { 328, -3254, 20360}, + { 333, -3263, 20130}, + { 338, -3272, 19898}, + { 342, -3278, 19665}, + { 346, -3283, 19430}, + { 350, -3286, 19194}, + { 353, -3288, 18957}, + { 356, -3288, 18718}, + { 359, -3286, 18478}, + { 362, -3283, 18238}, + { 364, -3279, 17996}, + { 366, -3273, 17753}, + { 368, -3266, 17509}, + { 369, -3257, 17264}, + { 371, -3247, 17018}, + { 372, -3235, 16772}, + { 372, -3222, 16525}, + { 373, -3208, 16277}, + { 373, -3192, 16028}, + { 373, -3175, 15779}, + { 373, -3157, 15529}, + { 372, -3138, 15279}, + { 371, -3117, 15028}, + { 370, -3095, 14777}, + { 369, -3072, 14526}, + { 368, -3048, 14274}, + { 366, -3022, 14022}, + { 364, -2996, 13770}, + { 362, -2968, 13517}, + { 359, -2940, 13265}, + { 357, -2910, 13012}, + { 354, -2880, 12760}, + { 351, -2848, 12508}, + { 348, -2815, 12255}, + { 344, -2782, 12003}, + { 341, -2747, 11751}, + { 337, -2712, 11500}, + { 333, -2676, 11248}, + { 328, -2639, 10997}, + { 324, -2601, 10747}, + { 320, -2562, 10497}, + { 315, -2523, 10247}, + { 310, -2482, 9998}, + { 305, -2442, 9750}, + { 300, -2400, 9502}, + { 294, -2358, 9255}, + { 289, -2315, 9009}, + { 283, -2271, 8763}, + { 277, -2227, 8519}, + { 271, -2182, 8275}, + { 265, -2137, 8032}, + { 259, -2091, 7791}, + { 252, -2045, 7550}, + { 246, -1998, 7311}, + { 239, -1951, 7072}, + { 232, -1904, 6835}, + { 226, -1856, 6599}, + { 219, -1807, 6364}, + { 212, -1758, 6131}, + { 204, -1709, 5899}, + { 197, -1660, 5668}, + { 190, -1611, 5439}, + { 183, -1561, 5212}, + { 175, -1511, 4986}, + { 168, -1460, 4761}, + { 160, -1410, 4538}, + { 152, -1359, 4317}, + { 145, -1309, 4098}, + { 137, -1258, 3880}, + { 129, -1207, 3664}, + { 121, -1156, 3450}, + { 113, -1105, 3238}, + { 105, -1054, 3028}, + { 97, -1003, 2820}, + { 89, -952, 2614}, + { 81, -901, 2409}, + { 73, -851, 2207}, +}; diff --git a/src_SigProc_FIX/SKP_Silk_resampler_rom.h b/src_SigProc_FIX/SKP_Silk_resampler_rom.h new file mode 100644 index 000000000..9fcf5bacc --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_rom.h @@ -0,0 +1,91 @@ +/*********************************************************************** +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_resample_rom.h * + * * + * Description: Header file for FIR resampling of * + * 32 and 44 kHz input * + * * + * Copyright 2007 (c), Skype Limited * + * All rights reserved. * + * * + * Date: 070807 * + * */ + +#ifndef _SKP_SILK_FIX_RESAMPLER_ROM_H_ +#define _SKP_SILK_FIX_RESAMPLER_ROM_H_ + +#include "SKP_Silk_typedef.h" +#include "SKP_Silk_resampler_structs.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define RESAMPLER_DOWN_ORDER_FIR 12 +#define RESAMPLER_ORDER_FIR_144 6 + + +/* Tables for 2x downsampler. Values above 32767 intentionally wrap to a negative value. */ +extern const SKP_int16 SKP_Silk_resampler_down2_0; +extern const SKP_int16 SKP_Silk_resampler_down2_1; + +/* Tables for 2x upsampler, low quality. Values above 32767 intentionally wrap to a negative value. */ +extern const SKP_int16 SKP_Silk_resampler_up2_lq_0; +extern const SKP_int16 SKP_Silk_resampler_up2_lq_1; + +/* Tables for 2x upsampler, high quality. Values above 32767 intentionally wrap to a negative value. */ +extern const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ]; +extern const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ]; +extern const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ]; + +/* Tables with IIR and FIR coefficients for fractional downsamplers */ +extern const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ]; +extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ]; + +/* Tables with coefficients for 4th order ARMA filter */ +extern const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ]; +extern const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ]; +extern const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ]; +extern const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ]; +extern const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ]; + +/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */ +extern const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ]; + +#ifdef __cplusplus +} +#endif + +#endif // _SKP_SILK_FIX_RESAMPLER_ROM_H_ diff --git a/src_SigProc_FIX/SKP_Silk_resampler_structs.h b/src_SigProc_FIX/SKP_Silk_resampler_structs.h new file mode 100644 index 000000000..0a1a8cefc --- /dev/null +++ b/src_SigProc_FIX/SKP_Silk_resampler_structs.h @@ -0,0 +1,79 @@ +/*********************************************************************** +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_resampler_structs.h * + * * + * Description: Structs for IIR/FIR resamplers * + * * + * Copyright 2010 (c), Skype Limited * + * All rights reserved. * + * * + * */ + +#ifndef SKP_Silk_RESAMPLER_STRUCTS_H +#define SKP_Silk_RESAMPLER_STRUCTS_H +#ifdef __cplusplus +extern "C" { +#endif + +/* Flag to enable support for input/output sampling rates above 48 kHz. Turn off for embedded devices */ +#define RESAMPLER_SUPPORT_ABOVE_48KHZ 1 + +#define SKP_Silk_RESAMPLER_MAX_FIR_ORDER 16 +#define SKP_Silk_RESAMPLER_MAX_IIR_ORDER 6 + + +typedef struct _SKP_Silk_resampler_state_struct{ + SKP_int32 sIIR[ SKP_Silk_RESAMPLER_MAX_IIR_ORDER ]; /* this must be the first element of this struct */ + SKP_int32 sFIR[ SKP_Silk_RESAMPLER_MAX_FIR_ORDER ]; + SKP_int32 sDown2[ 2 ]; + void (*resampler_function)( void *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); + void (*up2_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); + SKP_int32 batchSize; + SKP_int32 invRatio_Q16; + SKP_int32 FIR_Fracs; + SKP_int32 input2x; + const SKP_int16 *Coefs; +#if RESAMPLER_SUPPORT_ABOVE_48KHZ + SKP_int32 sDownPre[ 2 ]; + SKP_int32 sUpPost[ 2 ]; + void (*down_pre_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); + void (*up_post_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); + SKP_int32 batchSizePrePost; + SKP_int32 ratio_Q16; + SKP_int32 nPreDownsamplers; + SKP_int32 nPostUpsamplers; +#endif + SKP_int32 magic_number; +} SKP_Silk_resampler_state_struct; + +#ifdef __cplusplus +} +#endif +#endif // SKP_Silk_RESAMPLER_STRUCTS_H + diff --git a/src/SKP_Silk_resample_2_1_coarse.c b/src_SigProc_FIX/SKP_Silk_resampler_up2.c similarity index 54% rename from src/SKP_Silk_resample_2_1_coarse.c rename to src_SigProc_FIX/SKP_Silk_resampler_up2.c index f01fbe923..835e11309 100644 --- a/src/SKP_Silk_resample_2_1_coarse.c +++ b/src_SigProc_FIX/SKP_Silk_resampler_up2.c @@ -26,48 +26,50 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * SKP_Silk_resample_2_1_coarse.c * + * SKP_Silk_resampler_up2.c * * * - * Upsample by a factor 2, coarser * + * Upsample by a factor 2, low quality * * * - * Copyright 2006 (c), Skype Limited * - * Date: 060221 * + * Copyright 2010 (c), Skype Limited * * */ + #include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_resampler_rom.h" -/* Upsample by a factor 2, coarser */ -void SKP_Silk_resample_2_1_coarse( - const SKP_int16 *in, /* I: 8 kHz signal [len] */ - SKP_int32 *S, /* I/O: State vector [4] */ - SKP_int16 *out, /* O: 16 kHz signal [2*len] */ - SKP_int32 *scratch, /* I: Scratch memory [3*len] */ - const SKP_int32 len /* I: Number of INPUT samples */ +/* Upsample by a factor 2, low quality */ +void SKP_Silk_resampler_up2( + SKP_int32 *S, /* I/O: State vector [ 2 ] */ + SKP_int16 *out, /* O: Output signal [ 2 * len ] */ + const SKP_int16 *in, /* I: Input signal [ len ] */ + SKP_int32 len /* I: Number of input samples */ ) { - SKP_int32 k, idx; - - /* Coefficients for coarser 2-fold resampling */ - const SKP_int16 A20c[ 2 ] = { 2119, 16663 }; - const SKP_int16 A21c[ 2 ] = { 8050, 26861 }; + SKP_int32 k; + SKP_int32 in32, out32, Y, X; - /* Convert Q15 -> Q25 */ + SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 ); + SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 ); + /* Internal variables and state are in Q10 format */ for( k = 0; k < len; k++ ) { - scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); - } - - idx = SKP_LSHIFT( len, 1 ); - - /* Allpass filters */ - SKP_Silk_allpass_int( scratch, S, A20c[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 1, A20c[ 1 ], scratch + len, len ); + /* Convert to Q10 */ + in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); - SKP_Silk_allpass_int( scratch, S + 2, A21c[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 3, A21c[ 1 ], scratch, len ); + /* All-pass section for even output sample */ + Y = SKP_SUB32( in32, S[ 0 ] ); + X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 ); + out32 = SKP_ADD32( S[ 0 ], X ); + S[ 0 ] = SKP_ADD32( in32, X ); - /* Interleave two allpass outputs */ - for( k = 0; k < len; k++ ) { - idx = SKP_LSHIFT( k, 1 ); - out[ idx ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k + len ], 10 ) ); - out[ idx + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ], 10 ) ); + /* Convert back to int16 and store to output */ + out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); + + /* All-pass section for odd output sample */ + Y = SKP_SUB32( in32, S[ 1 ] ); + X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 ); + out32 = SKP_ADD32( S[ 1 ], X ); + S[ 1 ] = SKP_ADD32( in32, X ); + + /* Convert back to int16 and store to output */ + out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); } } diff --git a/src/SKP_Silk_scale_copy_vector16.c b/src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c similarity index 100% rename from src/SKP_Silk_scale_copy_vector16.c rename to src_SigProc_FIX/SKP_Silk_scale_copy_vector16.c diff --git a/src/SKP_Silk_scale_vector.c b/src_SigProc_FIX/SKP_Silk_scale_vector.c similarity index 86% rename from src/SKP_Silk_scale_vector.c rename to src_SigProc_FIX/SKP_Silk_scale_vector.c index 78f4e1346..22e1429e9 100644 --- a/src/SKP_Silk_scale_vector.c +++ b/src_SigProc_FIX/SKP_Silk_scale_vector.c @@ -35,28 +35,13 @@ void SKP_Silk_scale_vector16_Q14( ) { SKP_int i; - SKP_int32 data32, gain_Q16; + SKP_int32 gain_Q16; SKP_assert( gain_Q14 < 32768 ); SKP_assert( gain_Q14 >= -32768 ); gain_Q16 = SKP_LSHIFT( gain_Q14, 2 ); - - if( (SKP_int32)( (SKP_int_ptr_size)data1 & 3 ) != 0 ) { - /* Input is not 4-byte aligned */ - data1[ 0 ] = SKP_SMULWB( gain_Q16, data1[ 0 ] ); - i = 1; - } else { - i = 0; - } - dataSize--; - for( ; i < dataSize; i += 2 ) { - data32 = *( (SKP_int32 *)&data1[ i ] ); /* load two values at once */ - data1[ i ] = SKP_SMULWB( gain_Q16, data32 ); - data1[ i + 1 ] = SKP_SMULWT( gain_Q16, data32 ); - } - if( i == dataSize ) { - /* One sample left to process */ + for( i = 0; i < dataSize; i ++ ) { data1[ i ] = SKP_SMULWB( gain_Q16, data1[ i ] ); } } diff --git a/src/SKP_Silk_schur.c b/src_SigProc_FIX/SKP_Silk_schur.c similarity index 96% rename from src/SKP_Silk_schur.c rename to src_SigProc_FIX/SKP_Silk_schur.c index c2da483c9..bd46750ba 100644 --- a/src/SKP_Silk_schur.c +++ b/src_SigProc_FIX/SKP_Silk_schur.c @@ -44,7 +44,7 @@ void SKP_Silk_schur( ) { SKP_int k, n, lz; - SKP_int32 C[ SigProc_MAX_ORDER_LPC + 1 ][ 2 ]; + SKP_int32 C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ]; SKP_int32 Ctmp1, Ctmp2, rc_tmp_Q15; /* Get number of leading zeros */ diff --git a/src/SKP_Silk_schur64.c b/src_SigProc_FIX/SKP_Silk_schur64.c similarity index 96% rename from src/SKP_Silk_schur64.c rename to src_SigProc_FIX/SKP_Silk_schur64.c index 048b684ca..154f45de6 100644 --- a/src/SKP_Silk_schur64.c +++ b/src_SigProc_FIX/SKP_Silk_schur64.c @@ -45,7 +45,7 @@ SKP_int32 SKP_Silk_schur64( /* O: Returns residual energy ) { SKP_int k, n; - SKP_int32 C[ SigProc_MAX_ORDER_LPC + 1 ][ 2 ]; + SKP_int32 C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ]; SKP_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31; /* Check for invalid input */ diff --git a/src/SKP_Silk_sigm_Q15.c b/src_SigProc_FIX/SKP_Silk_sigm_Q15.c similarity index 100% rename from src/SKP_Silk_sigm_Q15.c rename to src_SigProc_FIX/SKP_Silk_sigm_Q15.c diff --git a/src/SKP_Silk_sort.c b/src_SigProc_FIX/SKP_Silk_sort.c similarity index 65% rename from src/SKP_Silk_sort.c rename to src_SigProc_FIX/SKP_Silk_sort.c index 70930b57c..add67a652 100644 --- a/src/SKP_Silk_sort.c +++ b/src_SigProc_FIX/SKP_Silk_sort.c @@ -29,7 +29,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Best case: O(n) for an already sorted array */ /* Worst case: O(n^2) for an inversely sorted array */ /* */ -/* To be implemented: */ /* Shell short: http://en.wikipedia.org/wiki/Shell_sort */ #include "SKP_Silk_SigProc_FIX.h" @@ -65,7 +64,7 @@ void SKP_Silk_insertion_sort_increasing( index[ j + 1 ] = i; /* Write index */ } - /* If less than L values are asked check the remaining values, */ + /* If less than L values are asked for, check the remaining values, */ /* but only spend CPU to ensure that the K first values are correct */ for( i = K; i < L; i++ ) { value = a[ i ]; @@ -111,7 +110,7 @@ void SKP_Silk_insertion_sort_decreasing( index[ j + 1 ] = i; /* Write index */ } - /* If less than L values are asked check the remaining values, */ + /* If less than L values are asked for, check the remaining values, */ /* but only spend CPU to ensure that the K first values are correct */ for( i = K; i < L; i++ ) { value = a[ i ]; @@ -157,7 +156,7 @@ void SKP_Silk_insertion_sort_decreasing_int16( index[ j + 1 ] = i; /* Write index */ } - /* If less than L values are asked check the remaining values, */ + /* If less than L values are asked for, check the remaining values, */ /* but only spend CPU to ensure that the K first values are correct */ for( i = K; i < L; i++ ) { value = a[ i ]; @@ -193,3 +192,96 @@ void SKP_Silk_insertion_sort_increasing_all_values( } } +void SKP_Silk_shell_insertion_sort_increasing( + SKP_int32 *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L, /* I: Vector length */ + const SKP_int K /* I: Number of correctly sorted positions */ +) +{ + SKP_int32 value, inc_Q16_tmp; + SKP_int i, j, inc, idx; + + /* Safety checks */ + SKP_assert( K > 0 ); + SKP_assert( L > 0 ); + SKP_assert( L >= K ); + + /* Calculate initial step size */ + inc_Q16_tmp = SKP_LSHIFT( (SKP_int32)L, 15 ); + inc = SKP_RSHIFT( inc_Q16_tmp, 16 ); + + /* Write start indices in index vector */ + for( i = 0; i < K; i++ ) { + index[ i ] = i; + } + + /* Shell sort first values */ + while( inc > 0 ) { + for( i = inc; i < K; i++ ) { + value = a[ i ]; + idx = index[ i ]; + for( j = i - inc; ( j >= 0 ) && ( value < a[ j ] ); j -= inc ) { + a[ j + inc ] = a[ j ]; /* Shift value */ + index[ j + inc ] = index[ j ]; /* Shift index */ + } + a[ j + inc ] = value; /* Write value */ + index[ j + inc ] = idx; /* Write index */ + } + inc_Q16_tmp = SKP_SMULWB( inc_Q16_tmp, 29789 ); // 29789_Q16 = 2.2^(-1)_Q0 + inc = SKP_RSHIFT_ROUND( inc_Q16_tmp, 16 ); + } + + /* If less than L values are asked for, check the remaining values, */ + /* but only spend CPU to ensure that the K first values are correct */ + /* Insertion sort remaining values */ + for( i = K; i < L; i++ ) { + value = a[ i ]; + if( value < a[ K - 1 ] ) { + for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + index[ j + 1 ] = index[ j ]; /* Shift index */ + } + a[ j + 1 ] = value; /* Write value */ + index[ j + 1 ] = i; /* Write index */ + } + } +} + +void SKP_Silk_shell_sort_increasing_all_values( + SKP_int32 *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L /* I: Vector length */ +) +{ + SKP_int32 value, inc_Q16_tmp; + SKP_int i, j, inc, idx; + + /* Safety checks */ + SKP_assert( L > 0 ); + + /* Calculate initial step size */ + inc_Q16_tmp = SKP_LSHIFT( (SKP_int32)L, 15 ); + inc = SKP_RSHIFT( inc_Q16_tmp, 16 ); + + /* Write start indices in index vector */ + for( i = 0; i < L; i++ ) { + index[ i ] = i; + } + + /* Sort vector elements by value, increasing order */ + while( inc > 0 ) { + for( i = inc; i < L; i++ ) { + value = a[ i ]; + idx = index[ i ]; + for( j = i - inc; ( j >= 0 ) && ( value < a[ j ] ); j -= inc ) { + a[ j + inc ] = a[ j ]; /* Shift value */ + index[ j + inc ] = index[ j ]; /* Shift index */ + } + a[ j + inc ] = value; /* Write value */ + index[ j + inc ] = idx; /* Write index */ + } + inc_Q16_tmp = SKP_SMULWB( inc_Q16_tmp, 29789 ); // 29789_Q16 = 2.2^(-1)_Q0 + inc = SKP_RSHIFT_ROUND( inc_Q16_tmp, 16 ); + } +} diff --git a/src/SKP_Silk_sum_sqr_shift.c b/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c similarity index 97% rename from src/SKP_Silk_sum_sqr_shift.c rename to src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c index 4904f8af8..fcfdc529b 100644 --- a/src/SKP_Silk_sum_sqr_shift.c +++ b/src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c @@ -56,11 +56,12 @@ void SKP_Silk_sum_sqr_shift( } shft = 0; len--; - for( ; i < len; i += 2 ) { + while( i < len ) { /* Load two values at once */ in32 = *( (SKP_int32 *)&x[ i ] ); nrg = SKP_SMLABB_ovflw( nrg, in32, in32 ); nrg = SKP_SMLATT_ovflw( nrg, in32, in32 ); + i += 2; if( nrg < 0 ) { /* Scale down */ nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 ); @@ -96,3 +97,4 @@ void SKP_Silk_sum_sqr_shift( *shift = shft; *energy = nrg; } + diff --git a/src_SigProc_FIX/SigProc_FIX.vcproj b/src_SigProc_FIX/SigProc_FIX.vcproj new file mode 100644 index 000000000..4a07d15ed --- /dev/null +++ b/src_SigProc_FIX/SigProc_FIX.vcproj @@ -0,0 +1,408 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="SigProc_FIX" + ProjectGUID="{2769AFC5-8FC2-42E8-803C-528ACBA89C74}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../interface" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_SigProcFLP_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../interface" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_SigProcFLP_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_A2NLSF.c" + > + </File> + <File + RelativePath=".\SKP_Silk_allpass_int.c" + > + </File> + <File + RelativePath=".\SKP_Silk_ana_filt_bank_1.c" + > + </File> + <File + RelativePath=".\SKP_Silk_apply_sine_window.c" + > + </File> + <File + RelativePath=".\SKP_Silk_array_maxabs.c" + > + </File> + <File + RelativePath=".\SKP_Silk_autocorr.c" + > + </File> + <File + RelativePath=".\SKP_Silk_biquad.c" + > + </File> + <File + RelativePath=".\SKP_Silk_biquad_alt.c" + > + </File> + <File + RelativePath=".\SKP_Silk_burg_modified.c" + > + </File> + <File + RelativePath=".\SKP_Silk_bwexpander.c" + > + </File> + <File + RelativePath=".\SKP_Silk_bwexpander_32.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_pitch.c" + > + </File> + <File + RelativePath=".\SKP_Silk_inner_prod_aligned.c" + > + </File> + <File + RelativePath=".\SKP_Silk_k2a.c" + > + </File> + <File + RelativePath=".\SKP_Silk_k2a_Q16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_lin2log.c" + > + </File> + <File + RelativePath=".\SKP_Silk_log2lin.c" + > + </File> + <File + RelativePath=".\SKP_Silk_lowpass_int.c" + > + </File> + <File + RelativePath=".\SKP_Silk_lowpass_short.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_inv_pred_gain.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_stabilize.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_synthesis_filter.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_synthesis_order16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LSF_cos_table.c" + > + </File> + <File + RelativePath=".\SKP_Silk_MA.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF2A.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_stabilize.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_weights_laroia.c" + > + </File> + <File + RelativePath=".\SKP_Silk_pitch_analysis_core.c" + > + </File> + <File + RelativePath=".\SKP_Silk_pitch_est_tables.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_down2.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_down2_3.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_down3.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_AR2.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_ARMA4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_copy.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_down4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_down_FIR.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_IIR_FIR.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_up2_HQ.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_private_up4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_rom.c" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_up2.c" + > + </File> + <File + RelativePath=".\SKP_Silk_scale_copy_vector16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_scale_vector.c" + > + </File> + <File + RelativePath=".\SKP_Silk_schur.c" + > + </File> + <File + RelativePath=".\SKP_Silk_schur64.c" + > + </File> + <File + RelativePath=".\SKP_Silk_sigm_Q15.c" + > + </File> + <File + RelativePath=".\SKP_Silk_sort.c" + > + </File> + <File + RelativePath=".\SKP_Silk_sum_sqr_shift.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_common_pitch_est_defines.h" + > + </File> + <File + RelativePath=".\SKP_Silk_Inlines.h" + > + </File> + <File + RelativePath=".\SKP_Silk_macros.h" + > + </File> + <File + RelativePath=".\SKP_Silk_pitch_est_defines.h" + > + </File> + <File + RelativePath=".\SKP_Silk_resample_rom.h" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_rom.h" + > + </File> + <File + RelativePath=".\SKP_Silk_resampler_structs.h" + > + </File> + <File + RelativePath=".\SKP_Silk_SigProc_FIX.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src/SKP_Silk_resample_2_3.c b/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c similarity index 54% rename from src/SKP_Silk_resample_2_3.c rename to src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c index dbb16feaa..976f9fda8 100644 --- a/src/SKP_Silk_resample_2_3.c +++ b/src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c @@ -26,49 +26,56 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * File Name: SKP_Silk_resample_2_3.c * + * SKP_Silk_LPC_inverse_pred_gain.c * * * - * Resamples by a factor 2/3 * + * compute inverse of LPC prediction gain, and * + * test if LPC coefficients are stable (all poles within unit circle) * * * * Copyright 2008 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 081113 * * */ - #include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_SigProc_FLP.h" -#define OUT_SUBFR_LEN 80 +#define RC_THRESHOLD 0.9999f -/* Resamples by a factor 2/3 */ -void SKP_Silk_resample_2_3( - SKP_int16 *out, /* O: Fs_low signal [inLen * 2/3] */ - SKP_int32 *S, /* I/O: State vector [7+4] */ - const SKP_int16 *in, /* I: Fs_high signal [inLen] */ - const SKP_int inLen /* I: Input length, must be a multiple of 3 */ +/* compute inverse of LPC prediction gain, and */ +/* test if LPC coefficients are stable (all poles within unit circle) */ +/* this code is based on SKP_Silk_a2k_FLP() */ +SKP_int SKP_Silk_LPC_inverse_pred_gain_FLP( /* O: returns 1 if unstable, otherwise 0 */ + SKP_float *invGain, /* O: inverse prediction gain, energy domain */ + const SKP_float *A, /* I: prediction coefficients [order] */ + SKP_int32 order /* I: prediction order */ ) { - SKP_int outLen, LSubFrameIn, LSubFrameOut; - SKP_int16 outH[ 3 * OUT_SUBFR_LEN ]; - SKP_int32 scratch[ ( 9 * OUT_SUBFR_LEN ) / 2 ]; - - /* Check that input length is multiple of 3 */ - SKP_assert( inLen % 3 == 0 ); + SKP_int k, n; + double rc, rc_mult1, rc_mult2; + SKP_float Atmp[ 2 ][ SKP_Silk_MAX_ORDER_LPC ]; + SKP_float *Aold, *Anew; - outLen = SKP_DIV32_16( SKP_LSHIFT( inLen, 1 ), 3 ); - while( outLen > 0 ) { - LSubFrameOut = SKP_min_int( OUT_SUBFR_LEN, outLen ); - LSubFrameIn = SKP_SMULWB( 98304, LSubFrameOut ); /* 98304_Q16 = 3/2_Q0 */ - - /* Upsample by a factor 2 */ - /* Scratch size needs to be: 3 * LSubFrameIn * sizeof( SKP_int32 ) */ - SKP_Silk_resample_2_1_coarse( in, &S[ 0 ], outH, scratch, LSubFrameIn ); + Anew = Atmp[ order & 1 ]; + SKP_memcpy( Anew, A, order * sizeof(SKP_float) ); - /* Downsample by a factor 3 */ - SKP_Silk_resample_1_3( out, &S[ 4 ], outH, SKP_LSHIFT( LSubFrameIn, 1 ) ); - - in += LSubFrameIn; - out += LSubFrameOut; - outLen -= LSubFrameOut; + *invGain = 1.0f; + for( k = order - 1; k > 0; k-- ) { + rc = -Anew[ k ]; + if (rc > RC_THRESHOLD || rc < -RC_THRESHOLD) { + return 1; + } + rc_mult1 = 1.0f - rc * rc; + rc_mult2 = 1.0f / rc_mult1; + *invGain *= (SKP_float)rc_mult1; + /* swap pointers */ + Aold = Anew; + Anew = Atmp[ k & 1 ]; + for( n = 0; n < k; n++ ) { + Anew[ n ] = (SKP_float)( ( Aold[ n ] - Aold[ k - n - 1 ] * rc ) * rc_mult2 ); + } + } + rc = -Anew[ 0 ]; + if ( rc > RC_THRESHOLD || rc < -RC_THRESHOLD ) { + return 1; } + rc_mult1 = 1.0f - rc * rc; + *invGain *= (SKP_float)rc_mult1; + return 0; } 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 new file mode 100644 index 000000000..192758f31 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c @@ -0,0 +1,69 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.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 */ +) +{ + 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; + + tmp2 = 1.0f / SKP_max_float( pX[ k + 2 ] - pX[ k + 1 ], MIN_NDELTA ); + pXW[ k + 1 ] = tmp1 + tmp2; + } + + /* Last value */ + tmp1 = 1.0f / SKP_max_float( 1.0f - pX[ D - 1 ], MIN_NDELTA ); + pXW[ D - 1 ] = tmp1 + tmp2; +} diff --git a/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h b/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h new file mode 100644 index 000000000..c797c89dd --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_SigProc_FLP.h @@ -0,0 +1,249 @@ +/*********************************************************************** +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_SIGPROC_FLP_H_ +#define _SKP_SILK_SIGPROC_FLP_H_ + +#include "SKP_Silk_SigProc_FIX.h" +#include <math.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +/********************************************************************/ +/* 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) */ + const SKP_int d, /* i length of ar */ + const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */ +); + +/* compute inverse of LPC prediction gain, and */ +/* test if LPC coefficients are stable (all poles within unit circle) */ +/* this code is based on SKP_Silk_FLP_a2k() */ +SKP_int SKP_Silk_LPC_inverse_pred_gain_FLP( /* O: returns 1 if unstable, otherwise 0 */ + SKP_float *invGain, /* O: inverse prediction gain, energy domain */ + const SKP_float *A, /* I: prediction coefficients [order] */ + SKP_int32 order /* I: prediction order */ +); + +void SKP_Silk_schur_FLP( + SKP_float refl_coef[], /* O reflection coefficients (length order) */ + const SKP_float auto_corr[], /* I autotcorreation sequence (length order+1) */ + SKP_int order /* I order */ +); + +void SKP_Silk_k2a_FLP( + SKP_float *A, /* O: prediction coefficients [order] */ + const SKP_float *rc, /* I: reflection coefficients [order] */ + SKP_int32 order /* I: prediction order */ +); + +/* Solve the normal equations using the Levinson-Durbin recursion */ +SKP_float SKP_Silk_levinsondurbin_FLP( /* O prediction error energy */ + SKP_float A[], /* O prediction coefficients [order] */ + const SKP_float corr[], /* I input auto-correlations [order + 1] */ + const SKP_int order /* I prediction order */ +); + +/* compute autocorrelation */ +void SKP_Silk_autocorrelation_FLP( + SKP_float *results, /* o result (length correlationCount) */ + const SKP_float *inputData, /* i input data to correlate */ + SKP_int inputDataSize, /* i length of input */ + SKP_int correlationCount /* i number of correlation taps to compute */ +); + +/* Pitch estimator */ +#define SigProc_PE_MIN_COMPLEX 0 +#define SigProc_PE_MID_COMPLEX 1 +#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 */ + SKP_int *pitch_out, /* O 4 pitch lag values */ + SKP_int *lagIndex, /* O lag Index */ + SKP_int *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 */ + const SKP_float search_thres2, /* 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 */ +); + +#define PI (3.1415926536f) + +void SKP_Silk_insertion_sort_decreasing_FLP( + SKP_float *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L, /* I: Vector length */ + const SKP_int K /* I: Number of correctly sorted positions */ +); + +void SKP_Silk_insertion_sort_increasing_FLP( + SKP_float *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L, /* I: Vector length */ + const SKP_int K /* I: Number of correctly sorted positions */ +); + +/* 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 */ +); + +/* Compute reflection coefficients from input signal */ +SKP_float SKP_Silk_burg_modified_FLP( /* O returns residual energy */ + SKP_float A[], /* O prediction coefficients (length order) */ + const SKP_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ + const SKP_int subfr_length, /* I input signal subframe length (including D preceeding samples) */ + const SKP_int nb_subfr, /* I number of subframes stacked in x */ + const SKP_float WhiteNoiseFrac, /* I fraction added to zero-lag autocorrelation */ + const SKP_int D /* I order */ +); + +/* multiply a vector by a constant */ +void SKP_Silk_scale_vector_FLP( + SKP_float *data1, + SKP_float gain, + SKP_int dataSize +); + +/* copy and multiply a vector by a constant */ +void SKP_Silk_scale_copy_vector_FLP( + SKP_float *data_out, + const SKP_float *data_in, + SKP_float gain, + SKP_int dataSize +); + +/* inner product of two SKP_float arrays, with result as double */ +double SKP_Silk_inner_product_FLP( + const SKP_float *data1, + const SKP_float *data2, + SKP_int dataSize +); + +/* sum of squares of a SKP_float array, with result as double */ +double SKP_Silk_energy_FLP( + const SKP_float *data, + SKP_int dataSize +); + +/********************************************************************/ +/* MACROS */ +/********************************************************************/ + +#define SKP_min_float(a, b) (((a) < (b)) ? (a) : (b)) +#define SKP_max_float(a, b) (((a) > (b)) ? (a) : (b)) +#define SKP_abs_float(a) ((SKP_float)fabs(a)) + +#define SKP_LIMIT_float( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))) + +/* sigmoid function */ +SKP_INLINE SKP_float SKP_sigmoid(SKP_float x) +{ + return (SKP_float)(1.0 / (1.0 + exp(-x))); +} + +/* floating-point to integer conversion (rounding) */ +SKP_INLINE void SKP_float2short_array( + SKP_int16 *out, + const SKP_float *in, + SKP_int32 length +) +{ + 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 ); + } +} + +/* 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, + const SKP_int16 *in, + SKP_int32 length +) +{ + SKP_int32 k; + for (k = length-1; k >= 0; k--) { + out[k] = (SKP_float)in[k]; + } +} + +#define SKP_round(x) (SKP_float)((x)>=0 ? (SKP_int64)((x)+0.5) : (SKP_int64)((x)-0.5)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/SKP_Silk_resample_3_2.c b/src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c similarity index 55% rename from src/SKP_Silk_resample_3_2.c rename to src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c index 53fe50935..210780b81 100644 --- a/src/SKP_Silk_resample_3_2.c +++ b/src_SigProc_FLP/SKP_Silk_allpass_int_FLP.c @@ -26,48 +26,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * File Name: SKP_Silk_resample_3_2.c * + * SKP_Silk_allpass_int.c * * * - * Resamples by a factor 3/2 * + * First-order allpass filter with * * + * transfer function: * * * - * Copyright 2008 (c), Skype Limited * - * All rights reserved. * + * A + Z^(-1) * + * H(z) = ------------ * + * 1 + A*Z^(-1) * * * - * Date: 081113 * + * 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" -#include "SKP_Silk_SigProc_FIX.h" - -#define IN_SUBFR_LEN_RESAMPLE_3_2 80 - -/* Resamples by a factor 3/2 */ -void SKP_Silk_resample_3_2( - SKP_int16 *out, /* O: Fs_high signal [inLen*3/2] */ - SKP_int32 *S, /* I/O: State vector [7+4] */ - const SKP_int16 *in, /* I: Fs_low signal [inLen] */ - SKP_int inLen /* I: Input length, must be a multiple of 2 */ +/* 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_int LSubFrameIn, LSubFrameOut; - SKP_int16 outH[ 3 * IN_SUBFR_LEN_RESAMPLE_3_2 ]; - SKP_int32 scratch[ ( 9 * IN_SUBFR_LEN_RESAMPLE_3_2 ) / 2 ]; - - /* Check that input is multiple of 2 */ - SKP_assert( inLen % 2 == 0 ); - - while( inLen > 0 ) { - LSubFrameIn = SKP_min_int( IN_SUBFR_LEN_RESAMPLE_3_2, inLen ); - LSubFrameOut = SKP_SMULWB( 98304, LSubFrameIn ); - - /* Upsample by a factor 3 */ - SKP_Silk_resample_3_1( outH, &S[ 0 ], in, LSubFrameIn ); - - /* Downsample by a factor 2 */ - /* Scratch size needs to be: 3 * LSubFrameOut * sizeof( SKP_int32 ) */ - SKP_Silk_resample_1_2_coarse( outH, &S[ 7 ], out, scratch, LSubFrameOut ); + SKP_float Y2, X2, S0; + SKP_int32 k; - in += LSubFrameIn; - out += LSubFrameOut; - inLen -= LSubFrameIn; + 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 new file mode 100644 index 000000000..d1fde2ed1 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_autocorrelation_FLP.c @@ -0,0 +1,48 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_typedef.h" +#include "SKP_Silk_SigProc_FLP.h" + +/* compute autocorrelation */ +void SKP_Silk_autocorrelation_FLP( + SKP_float *results, /* O result (length correlationCount) */ + const SKP_float *inputData, /* I input data to correlate */ + SKP_int inputDataSize, /* I length of input */ + SKP_int correlationCount /* I number of correlation taps to compute */ +) +{ + SKP_int i; + + if ( correlationCount > inputDataSize ) { + correlationCount = inputDataSize; + } + + for( i = 0; i < correlationCount; i++ ) { + results[ i ] = (SKP_float)SKP_Silk_inner_product_FLP( inputData, inputData + i, inputDataSize - i ); + } +} diff --git a/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c b/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c new file mode 100644 index 000000000..f11693ff8 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_burg_modified_FLP.c @@ -0,0 +1,154 @@ +/*********************************************************************** +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_burg_modified.c * + * * + * Calculates the reflection coefficients from the input vector * + * Input vector contains nb_subfr sub vectors of length L_sub + D * + * * + * Copyright 2009 (c), Skype Limited * + * Date: 091130 * + */ + +#include "SKP_Silk_SigProc_FLP.h" + +#define MAX_FRAME_SIZE 544 // subfr_length * nb_subfr = ( 0.005 * 24000 + 16 ) * 4 = 544 +#define MAX_NB_SUBFR 4 + +/* Compute reflection coefficients from input signal */ +SKP_float SKP_Silk_burg_modified_FLP( /* O returns residual energy */ + SKP_float A[], /* O prediction coefficients (length order) */ + const SKP_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ + const SKP_int subfr_length, /* I input signal subframe length (including D preceeding samples) */ + const SKP_int nb_subfr, /* I number of subframes stacked in x */ + const SKP_float WhiteNoiseFrac, /* I fraction added to zero-lag autocorrelation */ + const SKP_int D /* I order */ +) +{ + SKP_int k, n, s; + double C0, num, nrg_f, nrg_b, rc, Atmp, tmp1, tmp2; + const SKP_float *x_ptr; + double C_first_row[ SKP_Silk_MAX_ORDER_LPC ], C_last_row[ SKP_Silk_MAX_ORDER_LPC ]; + double CAf[ SKP_Silk_MAX_ORDER_LPC + 1 ], CAb[ SKP_Silk_MAX_ORDER_LPC + 1 ]; + double Af[ SKP_Silk_MAX_ORDER_LPC ]; + + SKP_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); + SKP_assert( nb_subfr <= MAX_NB_SUBFR ); + + /* Compute autocorrelations, added over subframes */ + C0 = SKP_Silk_energy_FLP( x, nb_subfr * subfr_length ); + SKP_memset( C_first_row, 0, SKP_Silk_MAX_ORDER_LPC * sizeof( double ) ); + for( s = 0; s < nb_subfr; s++ ) { + x_ptr = x + s * subfr_length; + for( n = 1; n < D + 1; n++ ) { + C_first_row[ n - 1 ] += SKP_Silk_inner_product_FLP( x_ptr, x_ptr + n, subfr_length - n ); + } + } + SKP_memcpy( C_last_row, C_first_row, SKP_Silk_MAX_ORDER_LPC * sizeof( double ) ); + + /* Initialize */ + CAb[ 0 ] = CAf[ 0 ] = C0 + WhiteNoiseFrac * C0 + 1e-9f; + + for( n = 0; n < D; n++ ) { + /* Update first row of correlation matrix (without first element) */ + /* Update last row of correlation matrix (without last element, stored in reversed order) */ + /* Update C * Af */ + /* Update C * flipud(Af) (stored in reversed order) */ + for( s = 0; s < nb_subfr; s++ ) { + x_ptr = x + s * subfr_length; + tmp1 = x_ptr[ n ]; + tmp2 = x_ptr[ subfr_length - n - 1 ]; + for( k = 0; k < n; k++ ) { + C_first_row[ k ] -= x_ptr[ n ] * x_ptr[ n - k - 1 ]; + C_last_row[ k ] -= x_ptr[ subfr_length - n - 1 ] * x_ptr[ subfr_length - n + k ]; + Atmp = Af[ k ]; + tmp1 += x_ptr[ n - k - 1 ] * Atmp; + tmp2 += x_ptr[ subfr_length - n + k ] * Atmp; + } + for( k = 0; k <= n; k++ ) { + CAf[ k ] -= tmp1 * x_ptr[ n - k ]; + CAb[ k ] -= tmp2 * x_ptr[ subfr_length - n + k - 1 ]; + } + } + tmp1 = C_first_row[ n ]; + tmp2 = C_last_row[ n ]; + for( k = 0; k < n; k++ ) { + Atmp = Af[ k ]; + tmp1 += C_last_row[ n - k - 1 ] * Atmp; + tmp2 += C_first_row[ n - k - 1 ] * Atmp; + } + CAf[ n + 1 ] = tmp1; + CAb[ n + 1 ] = tmp2; + + /* Calculate nominator and denominator for the next order reflection (parcor) coefficient */ + num = CAb[ n + 1 ]; + nrg_b = CAb[ 0 ]; + nrg_f = CAf[ 0 ]; + for( k = 0; k < n; k++ ) { + Atmp = Af[ k ]; + num += CAb[ n - k ] * Atmp; + nrg_b += CAb[ k + 1 ] * Atmp; + nrg_f += CAf[ k + 1 ] * Atmp; + } + SKP_assert( nrg_f > 0.0 ); + SKP_assert( nrg_b > 0.0 ); + + /* Calculate the next order reflection (parcor) coefficient */ + rc = -2.0 * num / ( nrg_f + nrg_b ); + SKP_assert( rc > -1.0 && rc < 1.0 ); + + /* Update the AR coefficients */ + for( k = 0; k < (n + 1) >> 1; k++ ) { + tmp1 = Af[ k ]; + tmp2 = Af[ n - k - 1 ]; + Af[ k ] = tmp1 + rc * tmp2; + Af[ n - k - 1 ] = tmp2 + rc * tmp1; + } + Af[ n ] = rc; + + /* Update C * Af and C * Ab */ + for( k = 0; k <= n + 1; k++ ) { + tmp1 = CAf[ k ]; + CAf[ k ] += rc * CAb[ n - k + 1 ]; + CAb[ n - k + 1 ] += rc * tmp1; + } + } + + /* Return residual energy */ + nrg_f = CAf[ 0 ]; + tmp1 = 1.0; + for( k = 0; k < D; k++ ) { + Atmp = Af[ k ]; + nrg_f += CAf[ k + 1 ] * Atmp; + tmp1 += Atmp * Atmp; + A[ k ] = (SKP_float)(-Atmp); + } + nrg_f -= WhiteNoiseFrac * C0 * tmp1; + + return (SKP_float)nrg_f; +} diff --git a/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c b/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c new file mode 100644 index 000000000..3f6be99da --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_bwexpander_FLP.c @@ -0,0 +1,47 @@ +/*********************************************************************** +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. +***********************************************************************/ + + +#include "SKP_Silk_SigProc_FLP.h" + + +/* Chirp (bw expand) LP AR filter */ +void SKP_Silk_bwexpander_FLP( + SKP_float *ar, /* I/O AR filter to be expanded (without leading 1) */ + const SKP_int d, /* I length of ar */ + const SKP_float chirp /* I chirp factor (typically in range (0..1) ) */ +) +{ + SKP_int i; + SKP_float cfac = chirp; + + for( i = 0; i < d - 1; i++ ) { + ar[ i ] *= cfac; + cfac *= chirp; + } + ar[ d - 1 ] *= cfac; +} diff --git a/src/SKP_Silk_resample_1_2_coarse.c b/src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c similarity index 56% rename from src/SKP_Silk_resample_1_2_coarse.c rename to src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c index f90b059b8..4dffbc80a 100644 --- a/src/SKP_Silk_resample_1_2_coarse.c +++ b/src_SigProc_FLP/SKP_Silk_decimate2_coarse_FLP.c @@ -26,49 +26,47 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * SKP_Silk_resample_1_2_coarse.c * + * SKP_Silk_decimate2_coarse.c * * * - * Downsample by a factor 2, coarser * + * downsample by a factor 2, coarser * * * - * Copyright 2006 (c), Skype Limited * + * Copyright 2006 (c), Camino Networks * * Date: 060221 * * */ -#include "SKP_Silk_SigProc_FIX.h" +#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_resample_1_2_coarse( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: State vector [4] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *scratch, /* I: Scratch memory [3*len] */ - const SKP_int32 len /* I: Number of OUTPUT samples*/ +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, idx; - - /* Coefficients for coarser 2-fold resampling */ - const SKP_int16 A20c[ 2 ] = { 2119, 16663 }; - const SKP_int16 A21c[ 2 ] = { 8050, 26861 }; + SKP_int32 k; - /* De-interleave allpass inputs, and convert Q15 -> Q25 */ - for( k = 0; k < len; k++ ) { - idx = SKP_LSHIFT( k, 1 ); - scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 ); - scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 ); + /* de-interleave allpass inputs */ + for ( k = 0; k < len; k++) { + scratch[ k ] = in[ 2 * k ]; + scratch[ k + len ] = in[ 2 * k + 1 ]; } - idx = SKP_LSHIFT( len, 1 ); - /* Allpass filters */ - SKP_Silk_allpass_int( scratch, S, A21c[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 1, A21c[ 1 ], scratch, len ); - - SKP_Silk_allpass_int( scratch + len, S + 2, A20c[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + idx, S + 3, A20c[ 1 ], scratch + len, len ); - - /* Add two allpass outputs */ - for( k = 0; k < len; k++ ) { - out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + len ], 11 ) ); - } + /* 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/SKP_Silk_resample_1_2_coarsest.c b/src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c similarity index 58% rename from src/SKP_Silk_resample_1_2_coarsest.c rename to src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c index 8e729651f..8291a8f0e 100644 --- a/src/SKP_Silk_resample_1_2_coarsest.c +++ b/src_SigProc_FLP/SKP_Silk_decimate2_coarsest_FLP.c @@ -26,46 +26,45 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * SKP_Silk_resample_1_2_coarsest.c * + * SKP_Silk_decimate2_coarsest.c * * * - * Downsample by a factor 2, coarsest * + * downsample by a factor 2, coarsest * * * - * Copyright 2006 (c), Skype Limited * + * Copyright 2006 (c), Camino Networks * * Date: 060221 * * */ -#include "SKP_Silk_SigProc_FIX.h" +#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}; -/* Coefficients for coarsest 2-fold resampling */ -static SKP_int16 A20cst[ 1 ] = { 3786 }; -static SKP_int16 A21cst[ 1 ] = { 17908 }; - -/* Downsample by a factor 2, coarsest */ -void SKP_Silk_resample_1_2_coarsest( - const SKP_int16 *in, /* I: 16 kHz signal [2*len] */ - SKP_int32 *S, /* I/O: State vector [2] */ - SKP_int16 *out, /* O: 8 kHz signal [len] */ - SKP_int32 *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: 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, idx; + SKP_int32 k; - /* De-interleave allpass inputs, and convert Q15 -> Q25 */ - for( k = 0; k < len; k++ ) { - idx = SKP_LSHIFT( k, 1 ); - scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 ); - scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 ); + /* de-interleave allpass inputs */ + for ( k = 0; k < len; k++ ) { + scratch[ k ] = in[ 2 * k + 0 ]; + scratch[ k + len ] = in[ 2 * k + 1 ]; } - idx = SKP_LSHIFT( len, 1 ); - /* Allpass filters */ - SKP_Silk_allpass_int( scratch, S, A21cst[ 0 ], scratch + idx, len ); - SKP_Silk_allpass_int( scratch + len, S + 1, A20cst[ 0 ], scratch, len ); + /* 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 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + idx ], 11 ) ); + /* 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 new file mode 100644 index 000000000..6e2726f8d --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_energy_FLP.c @@ -0,0 +1,56 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.h" + +/* 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; +} diff --git a/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c b/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c new file mode 100644 index 000000000..29e2da7c7 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_inner_product_FLP.c @@ -0,0 +1,56 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.h" + +/* inner product of two SKP_float arrays, with result as double */ +double SKP_Silk_inner_product_FLP( /* O result */ + const SKP_float *data1, /* I vector 1 */ + const SKP_float *data2, /* I vector 2 */ + SKP_int dataSize /* I length of vectors */ +) +{ + SKP_int i, dataSize4; + double result; + + /* 4x unrolled loop */ + result = 0.0f; + dataSize4 = dataSize & 0xFFFC; + for( i = 0; i < dataSize4; i += 4 ) { + result += data1[ i + 0 ] * data2[ i + 0 ] + + data1[ i + 1 ] * data2[ i + 1 ] + + data1[ i + 2 ] * data2[ i + 2 ] + + data1[ i + 3 ] * data2[ i + 3 ]; + } + + /* add any remaining products */ + for( ; i < dataSize; i++ ) { + result += data1[ i ] * data2[ i ]; + } + + return result; +} diff --git a/src/SKP_Silk_resample_2_3_rom.c b/src_SigProc_FLP/SKP_Silk_k2a_FLP.c similarity index 59% rename from src/SKP_Silk_resample_2_3_rom.c rename to src_SigProc_FLP/SKP_Silk_k2a_FLP.c index 2c396a9e7..232c885dc 100644 --- a/src/SKP_Silk_resample_2_3_rom.c +++ b/src_SigProc_FLP/SKP_Silk_k2a_FLP.c @@ -26,25 +26,33 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - * File Name: SKP_Silk_resample_2_3_rom.c * + * SKP_Silk_k2a.c * * * - * Description: Filter coefficients for FIR polyphase resampling * + * step up function, converts reflection coefficients to prediction * + * coefficients * * * - * Copyright 2009 (c), Skype Limited * - * All rights reserved. * - * * - * Date: 090424 * + * Copyright 2008 (c), Skype Limited * + * Date: 080103 * * */ +#include "SKP_Silk_SigProc_FLP.h" -#include "SKP_Silk_resample_rom.h" - -const SKP_int16 SigProc_Resample_2_3_coarse_INTERPOL[ SigProc_Resample_2_3_coarse_NUM_INTERPOLATORS ][ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS ] = { - { 0, -74, 109, 0, -234, 329, 0, -610, 813, 0, -1437, 1954, 0, -4358, 8953, 21845, 8953, -4358, 0, 1954, -1437, 0, 813, -610, 0, 329, -234, 0, 109, -74, 0, 45 }, - { 48, -62, 0, 133, -195, 0, 386, -526, 0, 936, -1243, 0, 2311, -3417, 0, 18026, 18026, 0, -3417, 2311, 0, -1243, 936, 0, -526, 386, 0, -195, 133, 0, -62, 48 }, -}; - -const SKP_int16 SigProc_Resample_2_3_coarsest_INTERPOL[ SigProc_Resample_2_3_coarsest_NUM_INTERPOLATORS ][ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS ] = { - { 379, 0, -3081, 8239, 21845, 8239, -3081, 0, 379, -145 }, - { 0, 696, -1951, 0, 17659, 17659, 0, -1951, 696, 0 }, -}; +/* step up function, converts reflection coefficients to prediction coefficients */ +void SKP_Silk_k2a_FLP( + SKP_float *A, /* O: prediction coefficients [order] */ + const SKP_float *rc, /* I: reflection coefficients [order] */ + SKP_int32 order /* I: prediction order */ +) +{ + SKP_int k, n; + SKP_float Atmp[SKP_Silk_MAX_ORDER_LPC]; + for( k = 0; k < order; k++ ){ + for( n = 0; n < k; n++ ){ + Atmp[ n ] = A[ n ]; + } + for( n = 0; n < k; n++ ) { + A[ n ] += Atmp[ k - n - 1 ] * rc[ k ]; + } + A[ k ] = -rc[ k ]; + } +} diff --git a/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c b/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c new file mode 100644 index 000000000..924ae5966 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c @@ -0,0 +1,77 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.h" + +/* Solve the normal equations using the Levinson-Durbin recursion */ +SKP_float SKP_Silk_levinsondurbin_FLP( /* O prediction error energy */ + SKP_float A[], /* O prediction coefficients [order] */ + const SKP_float corr[], /* I input auto-correlations [order + 1] */ + const SKP_int order /* I prediction order */ +) +{ + SKP_int i, mHalf, m; + SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2; + + min_nrg = 1e-12f * corr[ 0 ] + 1e-9f; + nrg = corr[ 0 ]; + nrg = SKP_max_float(min_nrg, nrg); + A[ 0 ] = corr[ 1 ] / nrg; + nrg -= A[ 0 ] * corr[ 1 ]; + nrg = SKP_max_float(min_nrg, nrg); + + for( m = 1; m < order; m++ ) + { + t = corr[ m + 1 ]; + for( i = 0; i < m; i++ ) { + t -= A[ i ] * corr[ m - i ]; + } + + /* reflection coefficient */ + km = t / nrg; + + /* residual energy */ + nrg -= km * t; + nrg = SKP_max_float(min_nrg, nrg); + + mHalf = m >> 1; + for( i = 0; i < mHalf; i++ ) { + Atmp1 = A[ i ]; + Atmp2 = A[ m - i - 1 ]; + A[ m - i - 1 ] -= km * Atmp1; + A[ i ] -= km * Atmp2; + } + if( m & 1 ) { + A[ mHalf ] -= km * A[ mHalf ]; + } + A[ m ] = km; + } + + /* return the residual energy */ + return nrg; +} + diff --git a/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c b/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c new file mode 100644 index 000000000..5503c5d20 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c @@ -0,0 +1,672 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/***************************************************************************** +* +* Pitch analyser function +* +******************************************************************************/ +#include "SKP_Silk_SigProc_FLP.h" +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_Silk_pitch_est_defines_FLP.h" +#include "SKP_Silk_common_pitch_est_defines.h" + +#define SCRATCH_SIZE 22 + +/************************************************************/ +/* Definitions */ +/************************************************************/ +#define eps 1.192092896e-07f + +/* using log2() helps the fixed-point conversion */ +SKP_INLINE SKP_float SKP_P_log2(double x) { return (SKP_float)(3.32192809488736 * log10(x)); } + +/************************************************************/ +/* Internally used functions */ +/************************************************************/ +static void SKP_P_Ana_calc_corr_st3( + SKP_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ + const SKP_float signal[], /* I vector to correlate */ + SKP_int start_lag, /* I start lag */ + SKP_int sf_length, /* I sub frame length */ + SKP_int nb_subfr, /* I number of subframes */ + SKP_int complexity /* I Complexity setting */ +); + +static void SKP_P_Ana_calc_energy_st3( + SKP_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ + const SKP_float signal[], /* I vector to correlate */ + SKP_int start_lag, /* I start lag */ + SKP_int sf_length, /* I sub frame length */ + SKP_int nb_subfr, /* I number of subframes */ + SKP_int complexity /* I Complexity setting */ +); + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +//% CORE PITCH ANALYSIS FUNCTION % +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +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_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 */ + const SKP_float search_thres2, /* 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_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 threshold, contour_bias; + SKP_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ]; /* use to be +2 but then valgrind reported errors for SWB */ + SKP_float CC[ PE_NB_CBKS_STAGE2_EXT ]; + const SKP_float *target_ptr, *basis_ptr; + double cross_corr, normalizer, energy, energy_tmp; + SKP_int d_srch[ PE_D_SRCH_LENGTH ]; + SKP_int16 d_comp[ (PE_MAX_LAG >> 1) + 5 ]; + SKP_int length_d_srch, length_d_comp; + SKP_float Cmax, CCmax, CCmax_b, CCmax_new_b, CCmax_new; + SKP_int CBimax, CBimax_new, lag, start_lag, end_lag, lag_new; + SKP_int cbk_offset, cbk_size; + SKP_float lag_log2, prevLag_log2, delta_lag_log2_sqr; + SKP_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; + SKP_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; + SKP_int diff, lag_counter, frame_length, frame_length_8kHz, frame_length_4kHz; + SKP_int sf_length, sf_length_8kHz, sf_length_4kHz; + SKP_int min_lag, min_lag_8kHz, min_lag_4kHz; + SKP_int max_lag, max_lag_8kHz, max_lag_4kHz; + const SKP_int8 *Lag_CB_ptr; + SKP_int nb_cbk_search; + + /* Check for valid sampling frequency */ + SKP_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 || Fs_kHz == 24 ); + + /* Check for valid complexity setting */ + SKP_assert( complexity >= SigProc_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SigProc_PE_MAX_COMPLEX ); + + SKP_assert( search_thres1 >= 0.0f && search_thres1 <= 1.0f ); + SKP_assert( search_thres2 >= 0.0f && search_thres2 <= 1.0f ); + + /* Setup frame lengths max / min lag for the sampling frequency */ + frame_length = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * Fs_kHz; + frame_length_4kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 4; + frame_length_8kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 8; + sf_length = PE_SUBFR_LENGTH_MS * Fs_kHz; + sf_length_4kHz = PE_SUBFR_LENGTH_MS * 4; + sf_length_8kHz = PE_SUBFR_LENGTH_MS * 8; + min_lag = PE_MIN_LAG_MS * Fs_kHz; + min_lag_4kHz = PE_MIN_LAG_MS * 4; + min_lag_8kHz = PE_MIN_LAG_MS * 8; + max_lag = PE_MAX_LAG_MS * Fs_kHz; + max_lag_4kHz = PE_MAX_LAG_MS * 4; + max_lag_8kHz = PE_MAX_LAG_MS * 8; + + 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 ]; + + /* 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 ); + } + } else if( Fs_kHz == 24 ) { + SKP_int16 signal_24[ PE_MAX_FRAME_LENGTH ]; + SKP_int16 signal_8[ 8 * PE_MAX_FRAME_LENGTH_MS ]; + SKP_int32 filt_state_fix[ 8 ]; + + /* Resample to 24 -> 8 khz */ + SKP_float2short_array( signal_24, signal, frame_length ); + SKP_memset( filt_state_fix, 0, 8 * sizeof(SKP_int32) ); + SKP_Silk_resampler_down3( filt_state_fix, signal_8, signal_24, frame_length ); + SKP_short2float_array( signal_8kHz, signal_8, frame_length_8kHz ); + } else { + SKP_assert( Fs_kHz == 8 ); + SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_float) ); + } + + /* 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 ); + } + + /* Low-pass filter */ + for( i = frame_length_4kHz - 1; i > 0; i-- ) { + signal_4kHz[ i ] += signal_4kHz[ i - 1 ]; + } + + /****************************************************************************** + * FIRST STAGE, operating in 4 khz + ******************************************************************************/ + target_ptr = &signal_4kHz[ SKP_LSHIFT( sf_length_4kHz, 2 ) ]; + for( k = 0; k < nb_subfr >> 1; k++ ) { + /* Check that we are within range of the array */ + SKP_assert( target_ptr >= signal_4kHz ); + SKP_assert( target_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz ); + + basis_ptr = target_ptr - min_lag_4kHz; + + /* Check that we are within range of the array */ + SKP_assert( basis_ptr >= signal_4kHz ); + SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz ); + + /* Calculate first vector products before loop */ + cross_corr = SKP_Silk_inner_product_FLP( target_ptr, basis_ptr, sf_length_8kHz ); + normalizer = SKP_Silk_energy_FLP( basis_ptr, sf_length_8kHz ) + 1000.0f; + + C[ 0 ][ min_lag_4kHz ] += (SKP_float)(cross_corr / sqrt(normalizer)); + + /* From now on normalizer is computed recursively */ + for(d = min_lag_4kHz + 1; d <= max_lag_4kHz; d++) { + basis_ptr--; + + /* Check that we are within range of the array */ + SKP_assert( basis_ptr >= signal_4kHz ); + SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz ); + + cross_corr = SKP_Silk_inner_product_FLP(target_ptr, basis_ptr, sf_length_8kHz); + + /* Add contribution of new sample and remove contribution from oldest sample */ + normalizer += + basis_ptr[ 0 ] * basis_ptr[ 0 ] - + basis_ptr[ sf_length_8kHz ] * basis_ptr[ sf_length_8kHz ]; + C[ 0 ][ d ] += (SKP_float)(cross_corr / sqrt( normalizer )); + } + /* Update target pointer */ + target_ptr += sf_length_8kHz; + } + + /* apply short-lag bias */ + for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) { + C[ 0 ][ i ] -= C[ 0 ][ i ] * i / 4096.0f; + } + + /* Sort */ + length_d_srch = 5 + complexity; + SKP_assert( length_d_srch <= PE_D_SRCH_LENGTH ); + SKP_Silk_insertion_sort_decreasing_FLP( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch ); + + /* Escape if correlation is very low already here */ + Cmax = C[ 0 ][ min_lag_4kHz ]; + target_ptr = &signal_4kHz[ SKP_SMULBB( sf_length_4kHz, nb_subfr ) ]; + energy = 1000.0f; + for( i = 0; i < SKP_LSHIFT( sf_length_4kHz, 2 ); i++ ) { + energy += target_ptr[i] * target_ptr[i]; + } + threshold = Cmax * Cmax; + if( energy / 16.0f > threshold ) { + SKP_memset( pitch_out, 0, nb_subfr * sizeof(SKP_int) ); + *LTPCorr = 0.0f; + *lagIndex = 0; + *contourIndex = 0; + return 1; + } + + threshold = search_thres1 * Cmax; + for( i = 0; i < length_d_srch; i++ ) { + /* Convert to 8 kHz indices for the sorted correlation that exceeds the threshold */ + if( C[ 0 ][ min_lag_4kHz + i ] > threshold ) { + d_srch[ i ] = SKP_LSHIFT( d_srch[ i ] + min_lag_4kHz, 1 ); + } else { + length_d_srch = i; + break; + } + } + SKP_assert( length_d_srch > 0 ); + + for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) { + d_comp[ i ] = 0; + } + for( i = 0; i < length_d_srch; i++ ) { + d_comp[ d_srch[ i ] ] = 1; + } + + /* Convolution */ + for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) { + d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ]; + } + + length_d_srch = 0; + for( i = min_lag_8kHz; i < max_lag_8kHz + 1; i++ ) { + if( d_comp[ i + 1 ] > 0 ) { + d_srch[ length_d_srch ] = i; + length_d_srch++; + } + } + + /* Convolution */ + for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) { + d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ] + d_comp[ i - 3 ]; + } + + length_d_comp = 0; + for( i = min_lag_8kHz; i < max_lag_8kHz + 4; i++ ) { + if( d_comp[ i ] > 0 ) { + d_comp[ length_d_comp ] = i - 2; + length_d_comp++; + } + } + + /********************************************************************************** + ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation + *************************************************************************************/ + /********************************************************************************* + * Find energy of each subframe projected onto its history, for a range of delays + *********************************************************************************/ + 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 ]; + 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) { + C[ k ][ d ] = (SKP_float)(cross_corr * cross_corr / (energy * energy_tmp + eps)); + } else { + C[ k ][ d ] = 0.0f; + } + } + target_ptr += sf_length_8kHz; + } + + /* search over lag range and lags codebook */ + /* scale factor for lag codebook, as a function of center lag */ + + CCmax = 0.0f; /* This value doesn't matter */ + CCmax_b = -1000.0f; + + CBimax = 0; /* To avoid returning undefined lag values */ + lag = -1; /* To check if lag with strong enough correlation has been found */ + + if( prevLag > 0 ) { + if( Fs_kHz == 12 ) { + prevLag = SKP_LSHIFT( prevLag, 1 ) / 3; + } else if( Fs_kHz == 16 ) { + prevLag = SKP_RSHIFT( prevLag, 1 ); + } else if( Fs_kHz == 24 ) { + prevLag = prevLag / 3; + } + prevLag_log2 = SKP_P_log2((SKP_float)prevLag); + } else { + prevLag_log2 = 0; + } + + /* Setup stage 2 codebook based on number of subframes */ + if( nb_subfr == PE_MAX_NB_SUBFR ) { + cbk_size = PE_NB_CBKS_STAGE2_EXT; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2[ 0 ][ 0 ]; + if( Fs_kHz == 8 && complexity > SigProc_PE_MIN_COMPLEX ) { + /* If input is 8 khz use a larger codebook here because it is last stage */ + nb_cbk_search = PE_NB_CBKS_STAGE2_EXT; + } else { + nb_cbk_search = PE_NB_CBKS_STAGE2; + } + }else{ + cbk_size = PE_NB_CBKS_STAGE2_10MS; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; + nb_cbk_search = PE_NB_CBKS_STAGE2_10MS; + } + + for( k = 0; k < length_d_srch; k++ ) { + d = d_srch[ k ]; + for( j = 0; j < nb_cbk_search; j++ ) { + CC[j] = 0.0f; + for( i = 0; i < nb_subfr; i++ ) { + /* Try all codebooks */ + CC[ j ] += C[ i ][ d + matrix_ptr( Lag_CB_ptr, i, j, cbk_size )]; + } + } + /* Find best codebook */ + CCmax_new = -1000.0f; + CBimax_new = 0; + for( i = 0; i < nb_cbk_search; i++ ) { + if( CC[ i ] > CCmax_new ) { + CCmax_new = CC[ i ]; + CBimax_new = i; + } + } + CCmax_new = SKP_max_float(CCmax_new, 0.0f); /* To avoid taking square root of negative number later */ + CCmax_new_b = CCmax_new; + + /* Bias towards shorter lags */ + lag_log2 = SKP_P_log2((SKP_float)d); + CCmax_new_b -= PE_FLP_SHORTLAG_BIAS * nb_subfr * lag_log2; + + /* Bias towards previous lag */ + if ( prevLag > 0 ) { + delta_lag_log2_sqr = lag_log2 - prevLag_log2; + delta_lag_log2_sqr *= delta_lag_log2_sqr; + CCmax_new_b -= PE_FLP_PREVLAG_BIAS * nb_subfr * (*LTPCorr) * delta_lag_log2_sqr / (delta_lag_log2_sqr + 0.5f); + } + + if ( CCmax_new_b > CCmax_b && CCmax_new > nb_subfr * search_thres2 * search_thres2 ) { + CCmax_b = CCmax_new_b; + CCmax = CCmax_new; + lag = d; + CBimax = CBimax_new; + } + } + + if( lag == -1 ) { + /* No suitable candidate found */ + SKP_memset( pitch_out, 0, PE_MAX_NB_SUBFR * sizeof(SKP_int) ); + *LTPCorr = 0.0f; + *lagIndex = 0; + *contourIndex = 0; + return 1; + } + + if( Fs_kHz > 8 ) { + /* Search in original signal */ + + /* Compensate for decimation */ + SKP_assert( lag == SKP_SAT16( lag ) ); + if( Fs_kHz == 12 ) { + lag = SKP_RSHIFT_ROUND( SKP_SMULBB( lag, 3 ), 1 ); + } else if( Fs_kHz == 16 ) { + lag = SKP_LSHIFT( lag, 1 ); + } else { + lag = SKP_SMULBB( lag, 3 ); + } + + lag = SKP_LIMIT_int( lag, min_lag, max_lag ); + start_lag = SKP_max_int( lag - 2, min_lag ); + end_lag = SKP_min_int( lag + 2, max_lag ); + lag_new = lag; /* to avoid undefined lag */ + CBimax = 0; /* to avoid undefined lag */ + SKP_assert( CCmax >= 0.0f ); + *LTPCorr = (SKP_float)sqrt( CCmax / nb_subfr ); /* Output normalized correlation */ + + CCmax = -1000.0f; + + /* Calculate the correlations and energies needed in stage 3 */ + SKP_P_Ana_calc_corr_st3( cross_corr_st3, signal, start_lag, sf_length, nb_subfr, complexity ); + SKP_P_Ana_calc_energy_st3( energies_st3, signal, start_lag, sf_length, nb_subfr, complexity ); + + lag_counter = 0; + SKP_assert( lag == SKP_SAT16( lag ) ); + contour_bias = PE_FLP_FLATCONTOUR_BIAS / lag; + + /* Setup cbk parameters acording to complexity setting and frame length */ + if( nb_subfr == PE_MAX_NB_SUBFR ) { + nb_cbk_search = (SKP_int)SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + cbk_offset = (SKP_int)SKP_Silk_cbk_offsets_stage3[ complexity ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + } else { + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + cbk_offset = 0; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + } + + for( d = start_lag; d <= end_lag; d++ ) { + for( j = cbk_offset; j < ( cbk_offset + nb_cbk_search ); j++ ) { + cross_corr = 0.0; + energy = eps; + for( k = 0; k < nb_subfr; k++ ) { + energy += energies_st3[ k ][ j ][ lag_counter ]; + cross_corr += cross_corr_st3[ k ][ j ][ lag_counter ]; + } + if( cross_corr > 0.0 ) { + CCmax_new = (SKP_float)(cross_corr * cross_corr / energy); + /* Reduce depending on flatness of contour */ + diff = j - SKP_RSHIFT( cbk_size, 1 ); + CCmax_new *= ( 1.0f - contour_bias * diff * diff ); + } else { + CCmax_new = 0.0f; + } + + if( CCmax_new > CCmax ) { + CCmax = CCmax_new; + lag_new = d; + CBimax = j; + } + } + lag_counter++; + } + + 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; + } else { + /* Save Lags and correlation */ + SKP_assert( CCmax >= 0.0f ); + *LTPCorr = (SKP_float)sqrt( CCmax / nb_subfr ); /* Output normalized correlation */ + for( k = 0; k < nb_subfr; k++ ) { + pitch_out[ k ] = lag + SKP_Silk_CB_lags_stage2[ k ][ CBimax ]; + } + *lagIndex = lag - min_lag; + *contourIndex = CBimax; + } + SKP_assert( *lagIndex >= 0 ); + /* return as voiced */ + return 0; +} + +static void SKP_P_Ana_calc_corr_st3( + SKP_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ + const SKP_float signal[], /* I vector to correlate */ + SKP_int start_lag, /* I start lag */ + SKP_int sf_length, /* I sub frame length */ + SKP_int nb_subfr, /* I number of subframes */ + SKP_int complexity /* I Complexity setting */ +) + /*********************************************************************** + Calculates the correlations used in stage 3 search. In order to cover + the whole lag codebook for all the searched offset lags (lag +- 2), + the following correlations are needed in each sub frame: + + sf1: lag range [-8,...,7] total 16 correlations + sf2: lag range [-4,...,4] total 9 correlations + sf3: lag range [-3,....4] total 8 correltions + sf4: lag range [-6,....8] total 15 correlations + + In total 48 correlations. The direct implementation computed in worst case + 4*12*5 = 240 correlations, but more likely around 120. + **********************************************************************/ +{ + const SKP_float *target_ptr, *basis_ptr; + SKP_int i, j, k, lag_counter, lag_low, lag_high; + SKP_int cbk_offset, nb_cbk_search, delta, idx, cbk_size; + SKP_float scratch_mem[ SCRATCH_SIZE ]; + const SKP_int8 *Lag_range_ptr, *Lag_CB_ptr; + + SKP_assert( complexity >= SigProc_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SigProc_PE_MAX_COMPLEX ); + + if( nb_subfr == PE_MAX_NB_SUBFR ){ + Lag_range_ptr = &SKP_Silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; + nb_cbk_search = SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + } else { + SKP_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); + Lag_range_ptr = &SKP_Silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + cbk_offset = 0; + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + } + + target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of frame */ + for( k = 0; k < nb_subfr; k++ ) { + lag_counter = 0; + + /* Calculate the correlations for each subframe */ + lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); + for( j = lag_low; j <= lag_high; j++ ) { + basis_ptr = target_ptr - ( start_lag + j ); + SKP_assert( lag_counter < SCRATCH_SIZE ); + scratch_mem[ lag_counter ] = (SKP_float)SKP_Silk_inner_product_FLP( target_ptr, basis_ptr, sf_length ); + lag_counter++; + } + + delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + for( i = cbk_offset; i < ( cbk_offset + nb_cbk_search ); i++ ) { + /* Fill out the 3 dim array that stores the correlations for */ + /* each code_book vector for each start lag */ + idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; + for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { + SKP_assert( idx + j < SCRATCH_SIZE ); + SKP_assert( idx + j < lag_counter ); + cross_corr_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; + } + } + target_ptr += sf_length; + } +} + +static void SKP_P_Ana_calc_energy_st3( + SKP_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ + const SKP_float signal[], /* I vector to correlate */ + SKP_int start_lag, /* I start lag */ + SKP_int sf_length, /* I sub frame length */ + SKP_int nb_subfr, /* I number of subframes */ + SKP_int complexity /* I Complexity setting */ +) +/**************************************************************** +Calculate the energies for first two subframes. The energies are +calculated recursively. +****************************************************************/ +{ + const SKP_float *target_ptr, *basis_ptr; + double energy; + SKP_int k, i, j, lag_counter; + SKP_int cbk_offset, nb_cbk_search, delta, idx, cbk_size, lag_diff; + SKP_float scratch_mem[ SCRATCH_SIZE ]; + const SKP_int8 *Lag_range_ptr, *Lag_CB_ptr; + + SKP_assert( complexity >= SigProc_PE_MIN_COMPLEX ); + SKP_assert( complexity <= SigProc_PE_MAX_COMPLEX ); + + if( nb_subfr == PE_MAX_NB_SUBFR ){ + Lag_range_ptr = &SKP_Silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3[ 0 ][ 0 ]; + cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ]; + nb_cbk_search = SKP_Silk_nb_cbk_searchs_stage3[ complexity ]; + cbk_size = PE_NB_CBKS_STAGE3_MAX; + } else { + SKP_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); + Lag_range_ptr = &SKP_Silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; + Lag_CB_ptr = &SKP_Silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; + cbk_offset = 0; + nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; + cbk_size = PE_NB_CBKS_STAGE3_10MS; + } + + target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; + for( k = 0; k < nb_subfr; k++ ) { + lag_counter = 0; + + /* Calculate the energy for first lag */ + basis_ptr = target_ptr - ( start_lag + matrix_ptr( Lag_range_ptr, k, 0, 2 ) ); + energy = SKP_Silk_energy_FLP( basis_ptr, sf_length ) + 1e-3; + SKP_assert( energy >= 0.0 ); + scratch_mem[lag_counter] = (SKP_float)energy; + lag_counter++; + + lag_diff = ( matrix_ptr( Lag_range_ptr, k, 1, 2 ) - matrix_ptr( Lag_range_ptr, k, 0, 2 ) + 1 ); + for( i = 1; i < lag_diff; i++ ) { + /* remove part outside new window */ + energy -= basis_ptr[sf_length - i] * basis_ptr[sf_length - i]; + SKP_assert( energy >= 0.0 ); + + /* add part that comes into window */ + energy += basis_ptr[ -i ] * basis_ptr[ -i ]; + SKP_assert( energy >= 0.0 ); + SKP_assert( lag_counter < SCRATCH_SIZE ); + scratch_mem[lag_counter] = (SKP_float)energy; + lag_counter++; + } + + delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); + for( i = cbk_offset; i < ( cbk_offset + nb_cbk_search ); i++ ) { + /* Fill out the 3 dim array that stores the correlations for */ + /* each code_book vector for each start lag */ + idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; + for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { + SKP_assert( idx + j < SCRATCH_SIZE ); + SKP_assert( idx + j < lag_counter ); + energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; + SKP_assert( energies_st3[ k ][ i ][ j ] >= 0.0f ); + } + } + target_ptr += sf_length; + } +} diff --git a/src_SigProc_FLP/SKP_Silk_pitch_est_defines_FLP.h b/src_SigProc_FLP/SKP_Silk_pitch_est_defines_FLP.h new file mode 100644 index 000000000..562768583 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_pitch_est_defines_FLP.h @@ -0,0 +1,42 @@ +/*********************************************************************** +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 SIGPROCFLP_PE_DEFINES_H +#define SIGPROCFLP_PE_DEFINES_H + +#include "SKP_Silk_common_pitch_est_defines.h" + +/************************************************************/ +/* Definitions For FLP pitch estimator */ +/************************************************************/ + +#define PE_FLP_SHORTLAG_BIAS 0.2f /* for logarithmic weighting */ +#define PE_FLP_PREVLAG_BIAS 0.2f /* for logarithmic weighting */ +#define PE_FLP_FLATCONTOUR_BIAS 0.05f + +#endif + diff --git a/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c b/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c new file mode 100644 index 000000000..5cc24f35e --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c @@ -0,0 +1,53 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.h" + +/* copy and multiply a vector by a constant */ +void SKP_Silk_scale_copy_vector_FLP( + SKP_float *data_out, + const SKP_float *data_in, + SKP_float gain, + SKP_int dataSize +) +{ + SKP_int i, dataSize4; + + /* 4x unrolled loop */ + dataSize4 = dataSize & 0xFFFC; + for( i = 0; i < dataSize4; i += 4 ) { + data_out[ i + 0 ] = gain * data_in[ i + 0 ]; + data_out[ i + 1 ] = gain * data_in[ i + 1 ]; + data_out[ i + 2 ] = gain * data_in[ i + 2 ]; + data_out[ i + 3 ] = gain * data_in[ i + 3 ]; + } + + /* any remaining elements */ + for( ; i < dataSize; i++ ) { + data_out[ i ] = gain * data_in[ i ]; + } +} diff --git a/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c b/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c new file mode 100644 index 000000000..559d89c81 --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c @@ -0,0 +1,52 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_SigProc_FLP.h" + +/* multiply a vector by a constant */ +void SKP_Silk_scale_vector_FLP( + SKP_float *data1, + SKP_float gain, + SKP_int dataSize +) +{ + SKP_int i, dataSize4; + + /* 4x unrolled loop */ + dataSize4 = dataSize & 0xFFFC; + for( i = 0; i < dataSize4; i += 4 ) { + data1[ i + 0 ] *= gain; + data1[ i + 1 ] *= gain; + data1[ i + 2 ] *= gain; + data1[ i + 3 ] *= gain; + } + + /* any remaining elements */ + for( ; i < dataSize; i++ ) { + data1[ i ] *= gain; + } +} diff --git a/src_SigProc_FLP/SKP_Silk_schur_FLP.c b/src_SigProc_FLP/SKP_Silk_schur_FLP.c new file mode 100644 index 000000000..93362c9bb --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_schur_FLP.c @@ -0,0 +1,71 @@ +/*********************************************************************** +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_schur.c * + * * + * Calculates the reflection coefficients from the correlation sequence * + * * + * Copyright 2008 (c), Skype Limited * + * Date: 080103 * + */ + +#include "SKP_Silk_SigProc_FLP.h" + +void SKP_Silk_schur_FLP( + SKP_float refl_coef[], /* O reflection coefficients (length order) */ + const SKP_float auto_corr[], /* I autotcorreation sequence (length order+1) */ + SKP_int order /* I order */ +) +{ + SKP_int k, n; + SKP_float C[SKP_Silk_MAX_ORDER_LPC + 1][2]; + SKP_float Ctmp1, Ctmp2, rc_tmp; + + /* copy correlations */ + for( k = 0; k < order+1; k++ ){ + C[k][0] = C[k][1] = auto_corr[k]; + } + + for( k = 0; k < order; k++ ) + { + /* get reflection coefficient */ + rc_tmp = -C[k + 1][0] / SKP_max_float(C[0][1], 1e-9f); + + /* save the output */ + refl_coef[k] = rc_tmp; + + /* update correlations */ + for( n = 0; n < order - k; n++ ){ + Ctmp1 = C[n + k + 1][0]; + Ctmp2 = C[n][1]; + C[n + k + 1][0] = Ctmp1 + Ctmp2 * rc_tmp; + C[n][1] = Ctmp2 + Ctmp1 * rc_tmp; + } + } +} + diff --git a/src_SigProc_FLP/SKP_Silk_sort_FLP.c b/src_SigProc_FLP/SKP_Silk_sort_FLP.c new file mode 100644 index 000000000..25134ed9a --- /dev/null +++ b/src_SigProc_FLP/SKP_Silk_sort_FLP.c @@ -0,0 +1,150 @@ +/*********************************************************************** +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. +***********************************************************************/ + +/* Insertion sort (fast for already almost sorted arrays): */ +/* Best case: O(n) for an already sorted array */ +/* Worst case: O(n^2) for an inversely sorted array */ +/* */ +/* To be implemented: */ +/* Shell short: http://en.wikipedia.org/wiki/Shell_sort */ + +#include "SKP_Silk_typedef.h" +#include "SKP_Silk_SigProc_FLP.h" + +void SKP_Silk_insertion_sort_increasing_FLP( + SKP_float *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L, /* I: Vector length */ + const SKP_int K /* I: Number of correctly sorted positions */ +) +{ + SKP_float value; + SKP_int i, j; + + /* Safety checks */ + SKP_assert( K > 0 ); + SKP_assert( L > 0 ); + SKP_assert( L >= K ); + + /* Write start indices in index vector */ + for( i = 0; i < K; i++ ) { + index[ i ] = i; + } + + /* Sort vector elements by value, increasing order */ + for( i = 1; i < K; i++ ) { + value = a[ i ]; + for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + index[ j + 1 ] = index[ j ]; /* Shift index */ + } + a[ j + 1 ] = value; /* Write value */ + index[ j + 1 ] = i; /* Write index */ + } + + /* If less than L values are asked check the remaining values, */ + /* but only spend CPU to ensure that the K first values are correct */ + for( i = K; i < L; i++ ) { + value = a[ i ]; + if( value < a[ K - 1 ] ) { + for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + index[ j + 1 ] = index[ j ]; /* Shift index */ + } + a[ j + 1 ] = value; /* Write value */ + index[ j + 1 ] = i; /* Write index */ + } + } +} + +void SKP_Silk_insertion_sort_decreasing_FLP( + SKP_float *a, /* I/O: Unsorted / Sorted vector */ + SKP_int *index, /* O: Index vector for the sorted elements */ + const SKP_int L, /* I: Vector length */ + const SKP_int K /* I: Number of correctly sorted positions */ +) +{ + SKP_float value; + SKP_int i, j; + + /* Safety checks */ + SKP_assert( K > 0 ); + SKP_assert( L > 0 ); + SKP_assert( L >= K ); + + /* Write start indices in index vector */ + for( i = 0; i < K; i++ ) { + index[ i ] = i; + } + + /* Sort vector elements by value, decreasing order */ + for( i = 1; i < K; i++ ) { + value = a[ i ]; + for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + index[ j + 1 ] = index[ j ]; /* Shift index */ + } + a[ j + 1 ] = value; /* Write value */ + index[ j + 1 ] = i; /* Write index */ + } + + /* If less than L values are asked check the remaining values, */ + /* but only spend CPU to ensure that the K first values are correct */ + for( i = K; i < L; i++ ) { + value = a[ i ]; + if( value > a[ K - 1 ] ) { + for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + index[ j + 1 ] = index[ j ]; /* Shift index */ + } + a[ j + 1 ] = value; /* Write value */ + index[ j + 1 ] = i; /* Write index */ + } + } +} + +void SKP_Silk_insertion_sort_increasing_all_values_FLP( + SKP_float *a, /* I/O: Unsorted / Sorted vector */ + const SKP_int L /* I: Vector length */ +) +{ + SKP_float value; + SKP_int i, j; + + /* Safety checks */ + SKP_assert( L > 0 ); + + /* Sort vector elements by value, increasing order */ + for( i = 1; i < L; i++ ) { + value = a[ i ]; + for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { + a[ j + 1 ] = a[ j ]; /* Shift value */ + } + a[ j + 1 ] = value; /* Write value */ + } +} + diff --git a/src_SigProc_FLP/SigProc_FLP.vcproj b/src_SigProc_FLP/SigProc_FLP.vcproj new file mode 100644 index 000000000..2048ea9b0 --- /dev/null +++ b/src_SigProc_FLP/SigProc_FLP.vcproj @@ -0,0 +1,248 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="SigProc_FLP" + ProjectGUID="{793D0EC2-8554-4674-9A97-F25DE5DBE926}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_SigProcFIX_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_SigProcFIX_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_allpass_int_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_autocorrelation_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_burg_modified_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_bwexpander_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decimate2_coarse_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decimate2_coarsest_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_energy_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_inner_product_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_k2a_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_levinsondurbin_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LPC_inv_pred_gain_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_VQ_weights_laroia_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_pitch_analysis_core_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_scale_copy_vector_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_scale_vector_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_schur_FLP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_sort_FLP.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_pitch_est_defines_FLP.h" + > + </File> + <File + RelativePath=".\SKP_Silk_SigProc_FLP.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src/SKP_Silk_CNG.c b/src_common/SKP_Silk_CNG.c similarity index 94% rename from src/SKP_Silk_CNG.c rename to src_common/SKP_Silk_CNG.c index 2958fadb5..1b41962b9 100644 --- a/src/SKP_Silk_CNG.c +++ b/src_common/SKP_Silk_CNG.c @@ -25,7 +25,7 @@ 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_main_FIX.h" +#include "SKP_Silk_main.h" /* Generates excitation for CNG LPC synthesis */ SKP_INLINE void SKP_Silk_CNG_exc( @@ -102,18 +102,18 @@ void SKP_Silk_CNG( /* Find the subframe with the highest gain */ max_Gain_Q16 = 0; subfr = 0; - for( i = 0; i < NB_SUBFR; i++ ) { + for( i = 0; i < psDec->nb_subfr; i++ ) { if( psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16 ) { max_Gain_Q16 = psDecCtrl->Gains_Q16[ i ]; subfr = i; } } /* Update CNG excitation buffer with excitation from this subframe */ - SKP_memmove( &psCNG->CNG_exc_buf_Q10[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q10, ( NB_SUBFR - 1 ) * psDec->subfr_length * sizeof( SKP_int32 ) ); + SKP_memmove( &psCNG->CNG_exc_buf_Q10[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q10, ( psDec->nb_subfr - 1 ) * psDec->subfr_length * sizeof( SKP_int32 ) ); SKP_memcpy( psCNG->CNG_exc_buf_Q10, &psDec->exc_Q10[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof( SKP_int32 ) ); /* Smooth gains */ - for( i = 0; i < NB_SUBFR; i++ ) { + for( i = 0; i < psDec->nb_subfr; i++ ) { psCNG->CNG_smth_Gain_Q16 += SKP_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 ); } } diff --git a/src/SKP_Silk_LBRR_reset.c b/src_common/SKP_Silk_LBRR_reset.c similarity index 100% rename from src/SKP_Silk_LBRR_reset.c rename to src_common/SKP_Silk_LBRR_reset.c diff --git a/src/SKP_Silk_LP_variable_cutoff.c b/src_common/SKP_Silk_LP_variable_cutoff.c similarity index 94% rename from src/SKP_Silk_LP_variable_cutoff.c rename to src_common/SKP_Silk_LP_variable_cutoff.c index 87feef536..3f40356ac 100644 --- a/src/SKP_Silk_LP_variable_cutoff.c +++ b/src_common/SKP_Silk_LP_variable_cutoff.c @@ -119,8 +119,8 @@ void SKP_Silk_LP_variable_cutoff( const SKP_int frame_length /* I Frame length */ ) { - SKP_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ]; - SKP_int fac_Q16 = 0, ind = 0; + SKP_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0; + SKP_int ind = 0; SKP_assert( psLP->transition_frame_no >= 0 ); SKP_assert( ( ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_DOWN ) && ( psLP->mode == 0 ) ) || @@ -148,11 +148,13 @@ void SKP_Silk_LP_variable_cutoff( /* Increment transition frame number for next frame */ psLP->transition_frame_no++; - } else if( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN ) { + } else { + SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN ); /* End of transition phase */ SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, TRANSITION_INT_NUM - 1, 0 ); } - } else if( psLP->mode == 1 ) { + } else { + SKP_assert( psLP->mode == 1 ); if( psLP->transition_frame_no < TRANSITION_FRAMES_UP ) { /* Calculate index and interpolation factor for interpolation */ #if( TRANSITION_INT_STEPS_UP == 64 ) @@ -172,7 +174,8 @@ void SKP_Silk_LP_variable_cutoff( /* Increment transition frame number for next frame */ psLP->transition_frame_no++; - } else if( psLP->transition_frame_no == TRANSITION_FRAMES_UP ) { + } else { + SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_UP ); /* End of transition phase */ SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, 0, 0 ); } diff --git a/src/SKP_Silk_NLSF2A_stable.c b/src_common/SKP_Silk_NLSF2A_stable.c similarity index 100% rename from src/SKP_Silk_NLSF2A_stable.c rename to src_common/SKP_Silk_NLSF2A_stable.c diff --git a/src/SKP_Silk_NLSF_MSVQ_decode.c b/src_common/SKP_Silk_NLSF_MSVQ_decode.c similarity index 100% rename from src/SKP_Silk_NLSF_MSVQ_decode.c rename to src_common/SKP_Silk_NLSF_MSVQ_decode.c diff --git a/src/SKP_Silk_NSQ.c b/src_common/SKP_Silk_NSQ.c similarity index 66% rename from src/SKP_Silk_NSQ.c rename to src_common/SKP_Silk_NSQ.c index 19cb8ea65..12dd887e8 100644 --- a/src/SKP_Silk_NSQ.c +++ b/src_common/SKP_Silk_NSQ.c @@ -36,15 +36,15 @@ SKP_INLINE void SKP_Silk_nsq_scale_states( 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[ NB_SUBFR ], /* I */ - const SKP_int pitchL[ NB_SUBFR ] /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ] /* I */ ); SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ SKP_int sigtype, /* I Signal type */ const SKP_int32 x_sc_Q10[], /* I */ - SKP_int q[], /* O */ + SKP_int8 q[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -59,7 +59,14 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_int offset_Q10, /* I */ SKP_int length, /* I Input length */ SKP_int shapingLPCOrder, /* I Noise shaping AR filter order */ - SKP_int predictLPCOrder /* I Prediction filter order */ + SKP_int predictLPCOrder, /* I Prediction filter order */ + SKP_int32 warping_Q16 /* I */ +#ifdef SAVE_ALL_INTERNAL_DATA + ,SKP_float q_in_env[], /* O */ + SKP_float q_exc[], /* O */ + SKP_float q_LPC_exc[], /* O */ + SKP_float q_exc_prev[] /* O */ +#endif ); void SKP_Silk_NSQ( @@ -67,15 +74,15 @@ void SKP_Silk_NSQ( SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ const SKP_int16 x[], /* I prefiltered input signal */ - SKP_int q[], /* O quantized qulse signal */ + SKP_int8 q[], /* O quantized qulse signal */ const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I Long term prediction coefficients */ - const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */ - const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ 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 Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ) @@ -88,16 +95,27 @@ void SKP_Silk_NSQ( SKP_int32 HarmShapeFIRPacked_Q14; SKP_int offset_Q10; SKP_int32 FiltState[ MAX_LPC_ORDER ]; - SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ]; - - subfr_length = psEncC->frame_length / NB_SUBFR; + SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / MAX_NB_SUBFR ]; +#ifdef SAVE_ALL_INTERNAL_DATA + /* Date buffers for analysing */ + SKP_float q_in_env_buf[ MAX_FRAME_LENGTH ]; + SKP_float q_exc_buf[ MAX_FRAME_LENGTH ]; + SKP_float q_LPC_exc_buf[ MAX_FRAME_LENGTH ]; + SKP_float q_exc_prev_buf[ MAX_FRAME_LENGTH ]; + SKP_float *q_in_env, *q_exc, *q_LPC_exc, *q_exc_prev; + + q_in_env = q_in_env_buf; + q_exc = q_exc_buf; + q_LPC_exc = q_LPC_exc_buf; + q_exc_prev = q_exc_prev_buf; +#endif + + subfr_length = psEncC->frame_length / MAX_NB_SUBFR; NSQ->rand_seed = psEncCtrlC->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->sigtype ][ psEncCtrlC->QuantOffsetType ]; if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) { @@ -107,13 +125,13 @@ void SKP_Silk_NSQ( } /* Setup pointers to start of sub frame */ - NSQ->sLTP_shp_buf_idx = psEncC->frame_length; - NSQ->sLTP_buf_idx = psEncC->frame_length; - pxq = &NSQ->xq[ psEncC->frame_length ]; - for( k = 0; k < NB_SUBFR; k++ ) { + NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; + NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; + pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; + for( k = 0; k < psEncC->nb_subfr; k++ ) { A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ]; B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; - AR_shp_Q13 = &AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ]; + AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; /* Noise shape parameters */ SKP_assert( HarmShapeGain_Q14[ k ] >= 0 ); @@ -129,15 +147,15 @@ void SKP_Silk_NSQ( if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) { /* Rewhiten with new A coefs */ - start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; - start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder ); /* Limit */ + start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; + start_idx = SKP_LIMIT_int( start_idx, 0, psEncC->ltp_mem_length - psEncC->predictLPCOrder ); /* Limit */ SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) ); - SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * ( psEncC->frame_length >> 2 ) ], - A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder ); + 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 ); NSQ->rewhite_flag = 1; - NSQ->sLTP_buf_idx = psEncC->frame_length; + NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; } } @@ -146,22 +164,36 @@ void SKP_Silk_NSQ( SKP_Silk_noise_shape_quantizer( NSQ, psEncCtrlC->sigtype, 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, psEncC->shapingLPCOrder, psEncC->predictLPCOrder + offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncCtrlC->warping_Q16 +#ifdef SAVE_ALL_INTERNAL_DATA + , q_in_env, q_exc, q_LPC_exc, q_exc_prev +#endif ); x += psEncC->subfr_length; q += psEncC->subfr_length; pxq += psEncC->subfr_length; +#ifdef SAVE_ALL_INTERNAL_DATA + q_in_env += psEncC->subfr_length; + q_exc += psEncC->subfr_length; + q_LPC_exc += psEncC->subfr_length; + q_exc_prev += subfr_length; +#endif } - /* Save scalars for this layer */ - NSQ->sLF_AR_shp_Q12 = NSQ->sLF_AR_shp_Q12; - NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16; - NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ]; + /* Update lagPrev for next frame */ + NSQ->lagPrev = psEncCtrlC->pitchL[ psEncC->nb_subfr - 1 ]; /* Save quantized speech and noise shaping signals */ - SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) ); - SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) ); - + SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int16 ) ); + SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int32 ) ); + +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( q_in_env.dat, q_in_env_buf, psEncC->frame_length * sizeof( SKP_float ) ); + DEBUG_STORE_DATA( q_exc.dat, q_exc_buf, psEncC->frame_length * sizeof( SKP_float ) ); + DEBUG_STORE_DATA( q_lpc_exc.dat, q_LPC_exc_buf, psEncC->frame_length * sizeof( SKP_float ) ); + DEBUG_STORE_DATA( xq.dat, &NSQ->xq[ psEncC->ltp_mem_length - psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) ); + DEBUG_STORE_DATA( q.dat, &q[ -psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int8 ) ); +#endif } /***********************************/ @@ -171,7 +203,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ SKP_int sigtype, /* I Signal type */ const SKP_int32 x_sc_Q10[], /* I */ - SKP_int q[], /* O */ + SKP_int8 q[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -186,19 +218,23 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_int offset_Q10, /* I */ SKP_int length, /* I Input length */ SKP_int shapingLPCOrder, /* I Noise shaping AR filter order */ - SKP_int predictLPCOrder /* I Prediction filter order */ + SKP_int predictLPCOrder, /* I Prediction filter order */ + SKP_int warping_Q16 /* I */ +#ifdef SAVE_ALL_INTERNAL_DATA + ,SKP_float q_in_env[], /* O */ + SKP_float q_exc[], /* O */ + SKP_float q_LPC_exc[], /* O */ + SKP_float q_exc_prev[] /* O */ +#endif ) { SKP_int i, j; SKP_int32 LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14; SKP_int32 n_LF_Q10, r_Q10, q_Q0, q_Q10; SKP_int32 thr1_Q10, thr2_Q10, thr3_Q10; - SKP_int32 Atmp, dither; - SKP_int32 exc_Q10, LPC_exc_Q10, xq_Q10; - SKP_int32 tmp, sLF_AR_shp_Q10; - SKP_int32 *psLPC_Q14; - SKP_int32 *shp_lag_ptr, *pred_lag_ptr; - SKP_int32 a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ]; + SKP_int32 dither, exc_Q10, LPC_exc_Q10, xq_Q10; + SKP_int32 tmp1, tmp2, sLF_AR_shp_Q10; + SKP_int32 *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr; shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; @@ -211,11 +247,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( thr2_Q10 = SKP_SUB_RSHIFT32( -512, Lambda_Q10, 1); thr2_Q10 = SKP_ADD_RSHIFT32( thr2_Q10, SKP_SMULBB( offset_Q10, Lambda_Q10 ), 10 ); thr3_Q10 = SKP_ADD_RSHIFT32( 512, Lambda_Q10, 1); - - /* Preload LPC coeficients to array on stack. Gives small performance gain */ - SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) ); - SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) ); - + for( i = 0; i < length; i++ ) { /* Generate dither */ NSQ->rand_seed = SKP_RAND( NSQ->rand_seed ); @@ -228,30 +260,20 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */ SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */ - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ /* Partially unrolled */ - Atmp = a_Q12_tmp[ 0 ]; /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp ); - Atmp = a_Q12_tmp[ 1 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp ); - Atmp = a_Q12_tmp[ 2 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp ); - Atmp = a_Q12_tmp[ 3 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp ); - Atmp = a_Q12_tmp[ 4 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp ); - for( j = 10; j < predictLPCOrder; j += 2 ) { - Atmp = a_Q12_tmp[ j >> 1 ]; /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp ); + LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], a_Q12[ 0 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] ); + + for( j = 10; j < predictLPCOrder; j ++ ) { + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] ); } /* Long-term prediction */ @@ -268,41 +290,34 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( } /* Noise shape feedback */ - SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ - SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */ - SKP_assert( shapingLPCOrder >= 12 ); /* check that unrolling works */ - - /* Partially unrolled */ - Atmp = AR_shp_Q13_tmp[ 0 ]; /* read two coefficients at once */ - n_AR_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 1 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 2 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 3 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 4 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 5 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp ); - for( j = 12; j < shapingLPCOrder; j += 2 ) { - Atmp = AR_shp_Q13_tmp[ j >> 1 ]; /* read two coefficients at once */ - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp ); + SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ + /* Output of lowpass section */ + tmp2 = SKP_SMLAWB( psLPC_Q14[ 0 ], NSQ->sAR2_Q14[ 0 ], warping_Q16 ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( NSQ->sAR2_Q14[ 0 ], NSQ->sAR2_Q14[ 1 ] - tmp2, warping_Q16 ); + NSQ->sAR2_Q14[ 0 ] = tmp2; + n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] ); + /* Loop over allpass sections */ + for( j = 2; j < shapingLPCOrder; j += 2 ) { + /* Output of allpass section */ + tmp2 = SKP_SMLAWB( NSQ->sAR2_Q14[ j - 1 ], NSQ->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16 ); + NSQ->sAR2_Q14[ j - 1 ] = tmp1; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( NSQ->sAR2_Q14[ j + 0 ], NSQ->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16 ); + NSQ->sAR2_Q14[ j + 0 ] = tmp2; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] ); } + NSQ->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] ); + n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 ); /* Q11 -> Q10 */ - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 ); + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 ); - n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 ); - n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 ); + n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 ); + n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 ); - SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED); + SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED ); /* Long-term shaping */ if( lag > 0 ) { @@ -317,18 +332,17 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( /* Input minus prediction plus noise feedback */ //r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP; - tmp = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */ - tmp = SKP_RSHIFT_ROUND( tmp, 4 ); /* round to Q10 */ - tmp = SKP_ADD32( tmp, LPC_pred_Q10 ); /* add Q10 stuff */ - tmp = SKP_SUB32( tmp, n_AR_Q10 ); /* subtract Q10 stuff */ - tmp = SKP_SUB32( tmp, n_LF_Q10 ); /* subtract Q10 stuff */ - r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp ); - + tmp1 = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */ + tmp1 = SKP_RSHIFT( tmp1, 4 ); /* convert to Q10 */ + tmp1 = SKP_ADD32( tmp1, LPC_pred_Q10 ); /* add Q10 stuff */ + tmp1 = SKP_SUB32( tmp1, n_AR_Q10 ); /* subtract Q10 stuff */ + tmp1 = SKP_SUB32( tmp1, n_LF_Q10 ); /* subtract Q10 stuff */ + r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp1 ); /* Flip sign depending on dither */ r_Q10 = ( r_Q10 ^ dither ) - dither; r_Q10 = SKP_SUB32( r_Q10, offset_Q10 ); - r_Q10 = SKP_LIMIT( r_Q10, -64 << 10, 64 << 10 ); + r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 ); /* Quantize */ if( r_Q10 < thr1_Q10 ) { @@ -344,7 +358,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( q_Q0 = 0; q_Q10 = 0; } - q[ i ] = q_Q0; + q[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */ /* Excitation */ exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 ); @@ -357,6 +371,11 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( /* Scale XQ back to normal level before saving */ xq[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( xq_Q10, Gain_Q16 ), 10 ) ); +#ifdef SAVE_ALL_INTERNAL_DATA + q_in_env[ i ] = ( (SKP_float)r_Q10 * (SKP_float)Gain_Q16 ) / ( 1024.0f * 65536.0f ); + q_exc[ i ] = ( (SKP_float)exc_Q10 * (SKP_float)Gain_Q16 ) / ( 1024.0f * 65536.0f ); + q_LPC_exc[ i ] = ( (SKP_float)LPC_exc_Q10 * (SKP_float)Gain_Q16 ) / ( 1024.0f * 65536.0f ); +#endif /* Update states */ psLPC_Q14++; @@ -365,7 +384,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer( NSQ->sLF_AR_shp_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 ); NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx ] = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 ); - sLTP_Q16[NSQ->sLTP_buf_idx] = SKP_LSHIFT( LPC_exc_Q10, 6 ); + sLTP_Q16[ NSQ->sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 ); NSQ->sLTP_shp_buf_idx++; NSQ->sLTP_buf_idx++; @@ -385,14 +404,14 @@ SKP_INLINE void SKP_Silk_nsq_scale_states( 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[ NB_SUBFR ], /* I */ - const SKP_int pitchL[ NB_SUBFR ] /* I */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ] /* I */ ) { SKP_int i, scale_length, lag; SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32; - inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1) ); + inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 ); inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX ); lag = pitchL[ subfr ]; @@ -409,8 +428,8 @@ SKP_INLINE void SKP_Silk_nsq_scale_states( } /* Prepare for Worst case. Next frame starts with max lag voiced */ - scale_length = length * NB_SUBFR; /* approx max lag */ - scale_length = scale_length - SKP_SMULBB( NB_SUBFR - (subfr + 1), length ); /* subtract samples that will be too old in next frame */ + scale_length = length * MAX_NB_SUBFR; /* approx max lag */ + scale_length = scale_length - SKP_SMULBB( MAX_NB_SUBFR - (subfr + 1), length ); /* subtract samples that will be too old in next frame */ scale_length = SKP_max_int( scale_length, lag + LTP_ORDER ); /* make sure to scale whole pitch period if voiced */ /* Adjust for changing gain */ @@ -433,6 +452,9 @@ SKP_INLINE void SKP_Silk_nsq_scale_states( for( i = 0; i < MAX_LPC_ORDER; i++ ) { NSQ->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] ); } + for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { + NSQ->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] ); + } } /* Scale input */ @@ -443,4 +465,4 @@ SKP_INLINE void SKP_Silk_nsq_scale_states( /* save inv_gain */ SKP_assert( inv_gain_Q16 != 0 ); NSQ->prev_inv_gain_Q16 = inv_gain_Q16; -} +} \ No newline at end of file diff --git a/src/SKP_Silk_NSQ_del_dec.c b/src_common/SKP_Silk_NSQ_del_dec.c similarity index 77% rename from src/SKP_Silk_NSQ_del_dec.c rename to src_common/SKP_Silk_NSQ_del_dec.c index 360126312..f81ad6822 100644 --- a/src/SKP_Silk_NSQ_del_dec.c +++ b/src_common/SKP_Silk_NSQ_del_dec.c @@ -28,13 +28,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_main.h" typedef struct { - SKP_int RandState[ DECISION_DELAY ]; + 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 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ]; + 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; @@ -68,8 +69,8 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( 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[ NB_SUBFR ], /* I */ - const SKP_int pitchL[ NB_SUBFR ] /* I Pitch lag */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ] /* I Pitch lag */ ); /******************************************/ @@ -80,7 +81,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ SKP_int sigtype, /* I Signal type */ const SKP_int32 x_Q10[], /* I */ - SKP_int q[], /* O */ + SKP_int8 q[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP filter state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -96,7 +97,8 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( SKP_int length, /* I Input length */ SKP_int subfr, /* I Subframe number */ SKP_int shapingLPCOrder, /* I Shaping LPC filter order */ - SKP_int predictLPCOrder, /* I Prediction LPC filter order */ + SKP_int predictLPCOrder, /* I Prediction filter order */ + SKP_int warping_Q16, /* I */ SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */ SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */ SKP_int decisionDelay /* I */ @@ -107,15 +109,15 @@ void SKP_Silk_NSQ_del_dec( SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ const SKP_int16 x[], /* I Prefiltered input signal */ - SKP_int q[], /* O Quantized pulse signal */ + SKP_int8 q[], /* O Quantized pulse signal */ const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I LT prediction coefs */ - const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */ - const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ 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 Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ) @@ -129,11 +131,11 @@ void SKP_Silk_NSQ_del_dec( SKP_int32 HarmShapeFIRPacked_Q14; SKP_int offset_Q10; SKP_int32 FiltState[ MAX_LPC_ORDER ], RDmin_Q10; - SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ]; - NSQ_del_dec_struct psDelDec[ DEL_DEC_STATES_MAX ]; + SKP_int32 x_sc_Q10[ MAX_SUB_FRAME_LENGTH ]; + NSQ_del_dec_struct psDelDec[ MAX_DEL_DEC_STATES ]; NSQ_del_dec_struct *psDD; - subfr_length = psEncC->frame_length / NB_SUBFR; + subfr_length = psEncC->subfr_length; /* Set unvoiced lag to the previous one, overwrite later for voiced */ lag = NSQ->lagPrev; @@ -148,8 +150,9 @@ void SKP_Silk_NSQ_del_dec( psDD->SeedInit = psDD->Seed; psDD->RD_Q10 = 0; psDD->LF_AR_Q12 = NSQ->sLF_AR_shp_Q12; - psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ]; + psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->ltp_mem_length - 1 ]; SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) ); + SKP_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) ); } offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ]; @@ -158,7 +161,7 @@ void SKP_Silk_NSQ_del_dec( decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length ); /* For voiced frames limit the decision delay to lower than the pitch lag */ if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) { - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEncC->nb_subfr; k++ ) { decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 ); } } @@ -170,14 +173,14 @@ void SKP_Silk_NSQ_del_dec( } /* Setup pointers to start of sub frame */ - pxq = &NSQ->xq[ psEncC->frame_length ]; - NSQ->sLTP_shp_buf_idx = psEncC->frame_length; - NSQ->sLTP_buf_idx = psEncC->frame_length; + pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; + NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; + NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; subfr = 0; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEncC->nb_subfr; k++ ) { A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ]; B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; - AR_shp_Q13 = &AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ]; + AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; NSQ->rewhite_flag = 0; if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) { @@ -220,21 +223,21 @@ void SKP_Silk_NSQ_del_dec( } /* Rewhiten with new A coefs */ - start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; - start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder ); + start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; + start_idx = SKP_LIMIT_int( start_idx, 0, psEncC->ltp_mem_length - psEncC->predictLPCOrder ); 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->frame_length - start_idx, psEncC->predictLPCOrder ); + A_Q12, FiltState, sLTP + start_idx, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder ); - NSQ->sLTP_buf_idx = psEncC->frame_length; + NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; NSQ->rewhite_flag = 1; } } /* Noise shape parameters */ SKP_assert( HarmShapeGain_Q14[ k ] >= 0 ); - HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 ); + HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 ); HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 ); SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10, @@ -244,8 +247,7 @@ void SKP_Silk_NSQ_del_dec( SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, 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->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay - ); + psEncCtrlC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay ); x += psEncC->subfr_length; q += psEncC->subfr_length; @@ -268,24 +270,27 @@ 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_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); + q[ 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 ) ); 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 ]; - } SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) ); + SKP_memcpy( NSQ->sAR2_Q14, psDD->sAR2_Q14, sizeof( psDD->sAR2_Q14 ) ); /* Update states */ NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12; - NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16; - NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ]; + NSQ->lagPrev = psEncCtrlC->pitchL[ psEncC->nb_subfr - 1 ]; /* Save quantized speech and noise shaping signals */ - SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) ); - SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) ); + SKP_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int16 ) ); + SKP_memmove( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( SKP_int32 ) ); +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( sLTP_Q16, &sLTP_Q16[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) ); + DEBUG_STORE_DATA( xq.dat, &NSQ->xq[ psEncC->ltp_mem_length - psEncC->frame_length], psEncC->frame_length * sizeof( SKP_int16 ) ); +#endif } /******************************************/ @@ -296,7 +301,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ SKP_int sigtype, /* I Signal type */ const SKP_int32 x_Q10[], /* I */ - SKP_int q[], /* O */ + SKP_int8 q[], /* O */ SKP_int16 xq[], /* O */ SKP_int32 sLTP_Q16[], /* I/O LTP filter state */ const SKP_int16 a_Q12[], /* I Short term prediction coefs */ @@ -312,7 +317,8 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( SKP_int length, /* I Input length */ SKP_int subfr, /* I Subframe number */ SKP_int shapingLPCOrder, /* I Shaping LPC filter order */ - SKP_int predictLPCOrder, /* I Prediction LPC filter order */ + SKP_int predictLPCOrder, /* I Prediction filter order */ + SKP_int warping_Q16, /* I */ SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */ SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */ SKP_int decisionDelay /* I */ @@ -321,25 +327,16 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( SKP_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx; SKP_int32 Winner_rand_state; SKP_int32 LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14; - SKP_int32 n_LF_Q10; - SKP_int32 r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10; - SKP_int32 q1_Q10, q2_Q10; - SKP_int32 Atmp, dither; - SKP_int32 exc_Q10, LPC_exc_Q10, xq_Q10; - SKP_int32 tmp, sLF_AR_shp_Q10; - SKP_int32 *pred_lag_ptr, *shp_lag_ptr; - SKP_int32 *psLPC_Q14; - SKP_int32 a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ]; - NSQ_sample_struct psSampleState[ DEL_DEC_STATES_MAX ][ 2 ]; + SKP_int32 n_LF_Q10, r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10; + SKP_int32 q1_Q10, q2_Q10, dither, exc_Q10, LPC_exc_Q10, xq_Q10; + SKP_int32 tmp1, tmp2, sLF_AR_shp_Q10; + SKP_int32 *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14; + NSQ_sample_struct psSampleState[ MAX_DEL_DEC_STATES ][ 2 ]; NSQ_del_dec_struct *psDD; NSQ_sample_struct *psSS; shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; - - /* Preload LPC coeficients to array on stack. Gives small performance gain */ - SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) ); - SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) ); for( i = 0; i < length; i++ ) { /* Perform common calculations used in all states */ @@ -384,85 +381,65 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( /* Pointer used in short term prediction and shaping */ psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ]; /* Short-term prediction */ + SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */ SKP_assert( ( predictLPCOrder & 1 ) == 0 ); /* check that order is even */ SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */ - SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */ - /* Partially unrolled */ - Atmp = a_Q12_tmp[ 0 ]; /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp ); - Atmp = a_Q12_tmp[ 1 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp ); - Atmp = a_Q12_tmp[ 2 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp ); - Atmp = a_Q12_tmp[ 3 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp ); - Atmp = a_Q12_tmp[ 4 ]; - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp ); - for( j = 10; j < predictLPCOrder; j += 2 ) { - Atmp = a_Q12_tmp[ j >> 1 ]; /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp ); + LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], a_Q12[ 0 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] ); + for( j = 10; j < predictLPCOrder; j ++ ) { + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] ); } /* Noise shape feedback */ - SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ - SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */ - SKP_assert( shapingLPCOrder >= 12 ); /* check that unrolling works */ - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ - - /* Partially unrolled */ - Atmp = AR_shp_Q13_tmp[ 0 ]; /* read two coefficients at once */ - n_AR_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 1 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 2 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 3 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 4 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp ); - Atmp = AR_shp_Q13_tmp[ 5 ]; - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp ); - for( j = 12; j < shapingLPCOrder; j += 2 ) { - Atmp = AR_shp_Q13_tmp[ j >> 1 ]; /* read two coefficients at once */ - n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j ], Atmp ); - n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp ); + SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ + /* Output of lowpass section */ + tmp2 = SKP_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 ); + psDD->sAR2_Q14[ 0 ] = tmp2; + n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] ); + /* Loop over allpass sections */ + for( j = 2; j < shapingLPCOrder; j += 2 ) { + /* Output of allpass section */ + tmp2 = SKP_SMLAWB( psDD->sAR2_Q14[ j - 1 ], psDD->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16 ); + psDD->sAR2_Q14[ j - 1 ] = tmp1; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] ); + /* Output of allpass section */ + tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ j + 0 ], psDD->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16 ); + psDD->sAR2_Q14[ j + 0 ] = tmp2; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] ); } + psDD->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1; + n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] ); + n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 ); /* Q11 -> Q10 */ n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 ); - n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 ); - n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 ); + n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 ); + n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 ); /* Input minus prediction plus noise feedback */ /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP */ - tmp = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */ - tmp = SKP_RSHIFT_ROUND( tmp, 4 ); /* round to Q10 */ - tmp = SKP_ADD32( tmp, LPC_pred_Q10 ); /* add Q10 stuff */ - tmp = SKP_SUB32( tmp, n_AR_Q10 ); /* subtract Q10 stuff */ - tmp = SKP_SUB32( tmp, n_LF_Q10 ); /* subtract Q10 stuff */ - r_Q10 = SKP_SUB32( x_Q10[ i ], tmp ); /* residual error Q10 */ + tmp1 = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */ + tmp1 = SKP_RSHIFT( tmp1, 4 ); /* convert to Q10 */ + tmp1 = SKP_ADD32( tmp1, LPC_pred_Q10 ); /* add Q10 stuff */ + tmp1 = SKP_SUB32( tmp1, n_AR_Q10 ); /* subtract Q10 stuff */ + tmp1 = SKP_SUB32( tmp1, n_LF_Q10 ); /* subtract Q10 stuff */ + r_Q10 = SKP_SUB32( x_Q10[ i ], tmp1 ); /* residual error Q10 */ - /* Flip sign depending on dither */ r_Q10 = ( r_Q10 ^ dither ) - dither; r_Q10 = SKP_SUB32( r_Q10, offset_Q10 ); - r_Q10 = SKP_LIMIT( r_Q10, -64 << 10, 64 << 10 ); + r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 ); /* Find two quantization level candidates and measure their rate-distortion */ if( r_Q10 < -1536 ) { @@ -585,7 +562,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec( /* Write samples from winner to output and long-term filter states */ psDD = &psDelDec[ Winner_ind ]; if( subfr > 0 || i >= decisionDelay ) { - q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 ); + q[ 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 ) ); NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ]; @@ -629,15 +606,15 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( 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[ NB_SUBFR ], /* I */ - const SKP_int pitchL[ NB_SUBFR ] /* I Pitch lag */ + const SKP_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ + const SKP_int pitchL[ MAX_NB_SUBFR ] /* I Pitch lag */ ) { SKP_int i, k, scale_length, lag; SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32; NSQ_del_dec_struct *psDD; - inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1 ) ); + inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 ); inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX ); lag = pitchL[ subfr ]; /* After rewhitening the LTP state is un-scaled. So scale with inv_gain_Q16 */ @@ -667,6 +644,9 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] ); } + for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { + psDD->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sAR2_Q14[ i ] ); + } for( i = 0; i < DECISION_DELAY; i++ ) { psDD->Pred_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[ i ] ); psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] ); @@ -676,8 +656,8 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states( /* Scale long term shaping state */ /* Calculate length to be scaled, Worst case: Next frame is voiced with max lag */ - scale_length = length * NB_SUBFR; /* aprox max lag */ - scale_length = scale_length - SKP_SMULBB( NB_SUBFR - ( subfr + 1 ), length ); /* subtract samples that will be too old in next frame */ + scale_length = length * MAX_NB_SUBFR; /* aprox max lag */ + scale_length = scale_length - SKP_SMULBB( MAX_NB_SUBFR - ( subfr + 1 ), length ); /* subtract samples that will be too old in next frame */ scale_length = SKP_max_int( scale_length, lag + LTP_ORDER ); /* make sure to scale whole pitch period if voiced */ for( i = NSQ->sLTP_shp_buf_idx - scale_length; i < NSQ->sLTP_shp_buf_idx; i++ ) { @@ -708,12 +688,12 @@ SKP_INLINE void SKP_Silk_copy_del_dec_state( SKP_int LPC_state_idx /* I Index to LPC buffer */ ) { - SKP_memcpy( DD_dst->RandState, DD_src->RandState, DECISION_DELAY * sizeof( SKP_int ) ); - SKP_memcpy( DD_dst->Q_Q10, DD_src->Q_Q10, DECISION_DELAY * sizeof( SKP_int32 ) ); - SKP_memcpy( DD_dst->Pred_Q16, DD_src->Pred_Q16, DECISION_DELAY * sizeof( SKP_int32 ) ); - SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, DECISION_DELAY * sizeof( SKP_int32 ) ); - SKP_memcpy( DD_dst->Xq_Q10, DD_src->Xq_Q10, DECISION_DELAY * sizeof( SKP_int32 ) ); - + 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; diff --git a/src/SKP_Silk_PLC.c b/src_common/SKP_Silk_PLC.c similarity index 86% rename from src/SKP_Silk_PLC.c rename to src_common/SKP_Silk_PLC.c index 746ae102d..0129d832a 100644 --- a/src/SKP_Silk_PLC.c +++ b/src_common/SKP_Silk_PLC.c @@ -59,6 +59,8 @@ void SKP_Silk_PLC( /* Generate Signal */ /****************************/ SKP_Silk_PLC_conceal( psDec, psDecCtrl, signal, length ); + + psDec->lossCnt++; } else { /****************************/ /* Update state */ @@ -88,18 +90,21 @@ void SKP_Silk_PLC_update( LTP_Gain_Q14 = 0; if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) { /* Find the parameters for the last subframe which contains a pitch pulse */ - for( j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ NB_SUBFR - 1 ]; j++ ) { + for( j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; j++ ) { + if( j == psDec->nb_subfr ){ + break; + } temp_LTP_Gain_Q14 = 0; for( i = 0; i < LTP_ORDER; i++ ) { - temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( NB_SUBFR - 1 - j ) * LTP_ORDER + i ]; + temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( psDec->nb_subfr - 1 - j ) * LTP_ORDER + i ]; } if( temp_LTP_Gain_Q14 > LTP_Gain_Q14 ) { LTP_Gain_Q14 = temp_LTP_Gain_Q14; SKP_memcpy( psPLC->LTPCoef_Q14, - &psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( NB_SUBFR - 1 - j, LTP_ORDER ) ], + &psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( psDec->nb_subfr - 1 - j, LTP_ORDER ) ], LTP_ORDER * sizeof( SKP_int16 ) ); - psPLC->pitchL_Q8 = SKP_LSHIFT( psDecCtrl->pitchL[ NB_SUBFR - 1 - j ], 8 ); + psPLC->pitchL_Q8 = SKP_LSHIFT( psDecCtrl->pitchL[ psDec->nb_subfr - 1 - j ], 8 ); } } @@ -138,7 +143,7 @@ void SKP_Silk_PLC_update( psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14; /* Save Gains */ - SKP_memcpy( psPLC->prevGain_Q16, psDecCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) ); + SKP_memcpy( psPLC->prevGain_Q16, psDecCtrl->Gains_Q16, psDec->nb_subfr * sizeof( SKP_int32 ) ); } void SKP_Silk_PLC_conceal( @@ -153,14 +158,13 @@ void SKP_Silk_PLC_conceal( SKP_int16 rand_scale_Q14, A_Q12_tmp[ MAX_LPC_ORDER ]; SKP_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15; SKP_int lag, idx, shift1, shift2; - SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr, Atmp; + SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr; SKP_int32 sig_Q10[ MAX_FRAME_LENGTH ], *sig_Q10_ptr, LPC_exc_Q10, LPC_pred_Q10, LTP_pred_Q14; SKP_Silk_PLC_struct *psPLC; - psPLC = &psDec->sPLC; /* Update LTP buffer */ - SKP_memcpy( psDec->sLTP_Q16, &psDec->sLTP_Q16[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int32 ) ); + SKP_memmove( psDec->sLTP_Q16, &psDec->sLTP_Q16[ psDec->frame_length ], psDec->ltp_mem_length * sizeof( SKP_int32 ) ); /* LPC concealment. Apply BWE to previous LPC */ SKP_Silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, BWE_COEF_Q16 ); @@ -168,7 +172,7 @@ void SKP_Silk_PLC_conceal( /* Find random noise component */ /* Scale previous excitation signal */ exc_buf_ptr = exc_buf; - for( k = ( NB_SUBFR >> 1 ); k < NB_SUBFR; k++ ) { + for( k = ( psDec->nb_subfr >> 1 ); k < psDec->nb_subfr; k++ ) { for( i = 0; i < psDec->subfr_length; i++ ) { exc_buf_ptr[ i ] = ( SKP_int16 )SKP_RSHIFT( SKP_SMULWW( psDec->exc_Q10[ i + k * psDec->subfr_length ], psPLC->prevGain_Q16[ k ] ), 10 ); @@ -228,13 +232,13 @@ void SKP_Silk_PLC_conceal( rand_seed = psPLC->rand_seed; lag = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 ); - psDec->sLTP_buf_idx = psDec->frame_length; + psDec->sLTP_buf_idx = psDec->ltp_mem_length; /***************************/ /* LTP synthesis filtering */ /***************************/ sig_Q10_ptr = sig_Q10; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psDec->nb_subfr; k++ ) { /* Setup pointer */ pred_lag_ptr = &psDec->sLTP_Q16[ psDec->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; for( i = 0; i < psDec->subfr_length; i++ ) { @@ -281,28 +285,22 @@ void SKP_Silk_PLC_conceal( /* Preload LPC coeficients to array on stack. Gives small performance gain */ SKP_memcpy( A_Q12_tmp, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( SKP_int16 ) ); SKP_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psDec->nb_subfr; k++ ) { for( i = 0; i < psDec->subfr_length; i++ ){ - /* unrolled */ - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp ); - for( j = 10 ; j < psDec->LPC_order ; j+=2 ) { - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ j ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 - j ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 - j ], Atmp ); + /* partly unrolled */ + LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] ); + + for( j = 10; j < psDec->LPC_order; j++ ) { + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp[ j ] ); } /* Add prediction to LPC residual */ @@ -318,7 +316,7 @@ void SKP_Silk_PLC_conceal( /* Scale with Gain */ for( i = 0; i < psDec->frame_length; i++ ) { - signal[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( sig_Q10[ i ], psPLC->prevGain_Q16[ NB_SUBFR - 1 ] ), 10 ) ); + signal[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( sig_Q10[ i ], psPLC->prevGain_Q16[ psDec->nb_subfr - 1 ] ), 10 ) ); } /**************************************/ @@ -326,7 +324,7 @@ void SKP_Silk_PLC_conceal( /**************************************/ psPLC->rand_seed = rand_seed; psPLC->randScale_Q14 = rand_scale_Q14; - for( i = 0; i < NB_SUBFR; i++ ) { + for( i = 0; i < MAX_NB_SUBFR; i++ ) { psDecCtrl->pitchL[ i ] = lag; } } diff --git a/src/SKP_Silk_PLC.h b/src_common/SKP_Silk_PLC.h similarity index 95% rename from src/SKP_Silk_PLC.h rename to src_common/SKP_Silk_PLC.h index 0409a24bb..015a5fa80 100644 --- a/src/SKP_Silk_PLC.h +++ b/src_common/SKP_Silk_PLC.h @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef SKP_SILK_PLC_FIX_H #define SKP_SILK_PLC_FIX_H -#include "SKP_Silk_main_FIX.h" +#include "SKP_Silk_main.h" #define BWE_COEF_Q16 64880 /* 0.99 in Q16 */ #define V_PITCH_GAIN_START_MIN_Q14 11469 /* 0.7 in Q14 */ @@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define USE_SINGLE_TAP 1 #define RAND_BUF_SIZE 128 #define RAND_BUF_MASK (RAND_BUF_SIZE - 1) -#define LOG2_INV_LPC_GAIN_HIGH_THRES 4 /* 2^4 = 12 dB LPC gain */ +#define LOG2_INV_LPC_GAIN_HIGH_THRES 3 /* 2^3 = 8 dB LPC gain */ #define LOG2_INV_LPC_GAIN_LOW_THRES 8 /* 2^8 = 24 dB LPC gain */ #define PITCH_DRIFT_FAC_Q16 655 /* 0.01 in Q16 */ diff --git a/src/SKP_Silk_VAD.c b/src_common/SKP_Silk_VAD.c similarity index 83% rename from src/SKP_Silk_VAD.c rename to src_common/SKP_Silk_VAD.c index 30a5aa6bc..40091cc59 100644 --- a/src/SKP_Silk_VAD.c +++ b/src_common/SKP_Silk_VAD.c @@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdlib.h> #include "SKP_Silk_main.h" +#define SKP_SILK_VAD_HANDLE_10MS_FRAMES 1 + /**********************************/ /* Initialization of the Silk VAD */ /**********************************/ @@ -72,32 +74,37 @@ const static SKP_int32 tiltWeights[ VAD_N_BANDS ] = { 30000, 6000, -12000, -1200 /***************************************/ /* Get the speech activity level in Q8 */ /***************************************/ -SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Return value, 0 if success */ - SKP_Silk_VAD_state *psSilk_VAD, /* I/O Silk VAD state */ - SKP_int *pSA_Q8, /* O Speech activity level in Q8 */ - SKP_int *pSNR_dB_Q7, /* O SNR for current frame in Q7 */ - SKP_int pQuality_Q15[ VAD_N_BANDS ], /* O Smoothed SNR for each band */ - SKP_int *pTilt_Q15, /* O current frame's frequency tilt */ - const SKP_int16 pIn[], /* I PCM input [framelength] */ - const SKP_int framelength /* I Input frame length */ +SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Return value, 0 if success */ + SKP_Silk_VAD_state *psSilk_VAD, /* I/O Silk VAD state */ + SKP_int *pSA_Q8, /* O Speech activity level in Q8 */ + SKP_int pQuality_Q15[ VAD_N_BANDS ], /* O Smoothed SNR for each band */ + SKP_int *pTilt_Q15, /* O current frame's frequency tilt */ + const SKP_int16 pIn[], /* I PCM input [framelength] */ + const SKP_int framelength, /* I Input frame length */ + const SKP_int fs_kHz /* I Input frame sample frequency */ ) { SKP_int SA_Q15, input_tilt; SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH / 2 ]; SKP_int decimated_framelength, dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s; SKP_int32 sumSquared, smooth_coef_Q16; - SKP_int16 HPstateTmp; + SKP_int16 HPstateTmp, SNR_dB_Q7; SKP_int16 X[ VAD_N_BANDS ][ MAX_FRAME_LENGTH / 2 ]; SKP_int32 Xnrg[ VAD_N_BANDS ]; SKP_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ]; SKP_int32 speech_nrg, x_tmp; SKP_int ret = 0; + +#if SKP_SILK_VAD_HANDLE_10MS_FRAMES + SKP_int normalizer; +#endif /* Safety checks */ SKP_assert( VAD_N_BANDS == 4 ); SKP_assert( MAX_FRAME_LENGTH >= framelength ); SKP_assert( framelength <= 512 ); + SKP_assert( framelength == 8 * SKP_RSHIFT( framelength, 3 ) ); /***********************/ /* Filter and Decimate */ @@ -114,6 +121,7 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu /*********************************************/ /* HP filter on lowest band (differentiator) */ /*********************************************/ + // y( n ) = 0.5 * x( n ) - 0.5 * x( n - 1 ) decimated_framelength = SKP_RSHIFT( framelength, 3 ); X[ 0 ][ decimated_framelength - 1 ] = SKP_RSHIFT( X[ 0 ][ decimated_framelength - 1 ], 1 ); HPstateTmp = X[ 0 ][ decimated_framelength - 1 ]; @@ -141,7 +149,7 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) { sumSquared = 0; for( i = 0; i < dec_subframe_length; i++ ) { - /* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 )^2. */ + /* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 ) ^ 2. */ /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128) */ x_tmp = SKP_RSHIFT( X[ b ][ i + dec_subframe_offset ], 3 ); sumSquared = SKP_SMLABB( sumSquared, x_tmp, x_tmp ); @@ -150,11 +158,11 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu SKP_assert( sumSquared >= 0 ); } - /* add/saturate summed energy of current subframe */ + /* Add/saturate summed energy of current subframe */ if( s < VAD_INTERNAL_SUBFRAMES - 1 ) { Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], sumSquared ); } else { - /* look-ahead subframe */ + /* Look-ahead subframe */ Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], SKP_RSHIFT( sumSquared, 1 ) ); } @@ -201,15 +209,15 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu } /* Mean-of-squares */ - sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */ + sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */ /* Root-mean-square approximation, scale to dBs, and write to output pointer */ - *pSNR_dB_Q7 = ( SKP_int16 )( 3 * SKP_Silk_SQRT_APPROX( sumSquared ) ); /* Q7 */ + SNR_dB_Q7 = ( SKP_int16 )( 3 * SKP_Silk_SQRT_APPROX( sumSquared ) ); /* Q7 */ /*********************************/ /* Speech Probability Estimation */ /*********************************/ - SA_Q15 = SKP_Silk_sigm_Q15( SKP_SMULWB( VAD_SNR_FACTOR_Q16, *pSNR_dB_Q7 ) - VAD_NEGATIVE_OFFSET_Q5 ); + SA_Q15 = SKP_Silk_sigm_Q15( SKP_SMULWB( VAD_SNR_FACTOR_Q16, SNR_dB_Q7 ) - VAD_NEGATIVE_OFFSET_Q5 ); /**************************/ /* Frequency Tilt Measure */ @@ -229,8 +237,19 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu if( speech_nrg <= 0 ) { SA_Q15 = SKP_RSHIFT( SA_Q15, 1 ); } else if( speech_nrg < 32768 ) { + +#if SKP_SILK_VAD_HANDLE_10MS_FRAMES + /* Energy normalization of frames shorter than 320 samples */ + normalizer = 0; + while( SKP_LSHIFT( framelength, normalizer ) < 320 ) { + normalizer++; + } + speech_nrg = SKP_LSHIFT_SAT32( speech_nrg, 15 + normalizer ); +#else + speech_nrg = SKP_LSHIFT_SAT32( speech_nrg, 15 ); +#endif /* square-root */ - speech_nrg = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( speech_nrg, 15 ) ); + speech_nrg = SKP_Silk_SQRT_APPROX( speech_nrg ); SA_Q15 = SKP_SMULWB( 32768 + speech_nrg, SA_Q15 ); } @@ -240,8 +259,17 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu /***********************************/ /* Energy Level and SNR estimation */ /***********************************/ - /* smoothing coefficient */ + /* Smoothing coefficient */ smooth_coef_Q16 = SKP_SMULWB( VAD_SNR_SMOOTH_COEF_Q18, SKP_SMULWB( SA_Q15, SA_Q15 ) ); + +#if SKP_SILK_VAD_HANDLE_10MS_FRAMES + if( framelength == 10 * fs_kHz ) { + smooth_coef_Q16 >>= 1; + } else { + SKP_assert( framelength == 20 * fs_kHz ); + } +#endif + for( b = 0; b < VAD_N_BANDS; b++ ) { /* compute smoothed energy-to-noise ratio per band */ psSilk_VAD->NrgRatioSmth_Q8[ b ] = SKP_SMLAWB( psSilk_VAD->NrgRatioSmth_Q8[ b ], diff --git a/src/SKP_Silk_code_signs.c b/src_common/SKP_Silk_code_signs.c similarity index 92% rename from src/SKP_Silk_code_signs.c rename to src_common/SKP_Silk_code_signs.c index 007a6bf4b..aa076ed0e 100644 --- a/src/SKP_Silk_code_signs.c +++ b/src_common/SKP_Silk_code_signs.c @@ -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( SKP_Silk_range_coder_state *sRC, /* I/O Range coder state */ - const SKP_int q[], /* I Pulse signal */ + const SKP_int8 q[], /* I Pulse signal */ const SKP_int length, /* I Length of input */ const SKP_int sigtype, /* I Signal type */ const SKP_int QuantOffsetType, /* I Quantization offset type */ @@ -45,10 +45,12 @@ void SKP_Silk_encode_signs( { SKP_int i; SKP_int inData; - const SKP_uint16 *cdf; + SKP_uint16 cdf[ 3 ]; i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex; - cdf = SKP_Silk_sign_CDF[ i ]; + cdf[ 0 ] = 0; + cdf[ 1 ] = SKP_Silk_sign_CDF[ i ]; + cdf[ 2 ] = 65535; for( i = 0; i < length; i++ ) { if( q[ i ] != 0 ) { @@ -70,10 +72,12 @@ void SKP_Silk_decode_signs( { SKP_int i; SKP_int data; - const SKP_uint16 *cdf; + SKP_uint16 cdf[ 3 ]; i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex; - cdf = SKP_Silk_sign_CDF[ i ]; + cdf[ 0 ] = 0; + cdf[ 1 ] = SKP_Silk_sign_CDF[ i ]; + cdf[ 2 ] = 65535; for( i = 0; i < length; i++ ) { if( q[ i ] > 0 ) { diff --git a/src/SKP_Silk_create_init_destroy.c b/src_common/SKP_Silk_create_init_destroy.c similarity index 92% rename from src/SKP_Silk_create_init_destroy.c rename to src_common/SKP_Silk_create_init_destroy.c index 9669cf8b0..2fcd4cba6 100644 --- a/src/SKP_Silk_create_init_destroy.c +++ b/src_common/SKP_Silk_create_init_destroy.c @@ -35,9 +35,11 @@ SKP_int SKP_Silk_init_decoder( SKP_Silk_decoder_state *psDec /* I/O Decoder state pointer */ ) { + /* Clear the entire encoder state, except anything copied */ SKP_memset( psDec, 0, sizeof( SKP_Silk_decoder_state ) ); + /* Set sampling rate to 24 kHz, and init non-zero values */ - SKP_Silk_decoder_set_fs( psDec, 24 ); + SKP_Silk_decoder_set_fs( psDec, 24, MAX_NB_SUBFR ); /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */ psDec->first_frame_after_reset = 1; @@ -46,9 +48,8 @@ SKP_int SKP_Silk_init_decoder( /* Reset CNG state */ SKP_Silk_CNG_Reset( psDec ); + /* Reset PLC state */ SKP_Silk_PLC_Reset( psDec ); - - psDec->bitstream_v = USE_BIT_STREAM_V; return(0); } diff --git a/src_common/SKP_Silk_dec_SDK_API.c b/src_common/SKP_Silk_dec_SDK_API.c new file mode 100644 index 000000000..fddce1515 --- /dev/null +++ b/src_common/SKP_Silk_dec_SDK_API.c @@ -0,0 +1,234 @@ +#include "SKP_Silk_SDK_API.h" +#include "SKP_Silk_main.h" + +/*********************/ +/* Decoder functions */ +/*********************/ + +SKP_int SKP_Silk_SDK_Get_Decoder_Size( SKP_int32 *decSizeBytes ) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + *decSizeBytes = sizeof( SKP_Silk_decoder_state ); + + return ret; +} + +/* Reset decoder state */ +SKP_int SKP_Silk_SDK_InitDecoder( + void* decState /* I/O: State */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + SKP_Silk_decoder_state *struc; + + struc = (SKP_Silk_decoder_state *)decState; + + ret = SKP_Silk_init_decoder( struc ); + + return ret; +} + +/* Decode a frame */ +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 */ + const SKP_uint8 *inData, /* I: Encoded input vector */ + const SKP_int nBytesIn, /* I: Number of input Bytes */ + SKP_int16 *samplesOut, /* O: Decoded output speech vector */ + SKP_int16 *nSamplesOut /* I/O: Number of samples (vector/decoded) */ +) +{ + SKP_int ret = SKP_SILK_NO_ERROR, used_bytes, prev_fs_kHz; + SKP_Silk_decoder_state *psDec; + + psDec = (SKP_Silk_decoder_state *)decState; + + /**********************************/ + /* Test if first frame in payload */ + /**********************************/ + if( psDec->moreInternalDecoderFrames == 0 ) { + /* 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; + ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE; + } + + /* Save previous sample frequency */ + prev_fs_kHz = psDec->fs_kHz; + + /* Call decoder for one frame */ + ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn, + lostFlag, &used_bytes ); + + if( used_bytes ) { /* Only Call if not a packet loss */ + if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) { + /* We have more frames in the Payload */ + psDec->moreInternalDecoderFrames = 1; + } else { + /* Last frame in Payload */ + psDec->moreInternalDecoderFrames = 0; + psDec->nFramesInPacket = psDec->nFramesDecoded; + + /* Track inband FEC usage */ + if( psDec->vadFlag == VOICE_ACTIVITY ) { + if( psDec->FrameTermination == SKP_SILK_LAST_FRAME ) { + psDec->no_FEC_counter++; + if( psDec->no_FEC_counter > NO_LBRR_THRES ) { + psDec->inband_FEC_offset = 0; + } + } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER1 ) { + psDec->inband_FEC_offset = 1; /* FEC info with 1 packet delay */ + psDec->no_FEC_counter = 0; + } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER2 ) { + psDec->inband_FEC_offset = 2; /* FEC info with 2 packets delay */ + psDec->no_FEC_counter = 0; + } + } + } + } + + if( MAX_API_FS_KHZ * 1000 < decControl->API_sampleRate || + 8000 > decControl->API_sampleRate ) { + ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY; + return( ret ); + } + + /* Resample if needed */ + if( psDec->fs_kHz * 1000 != decControl->API_sampleRate ) { + SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * MAX_FRAME_LENGTH_MS ]; + SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ ); + + /* Copy to a tmp buffer as the resampling writes to samplesOut */ + SKP_memcpy( samplesOut_tmp, samplesOut, *nSamplesOut * sizeof( SKP_int16 ) ); + + /* (Re-)initialize resampler state when switching internal sampling frequency */ + if( prev_fs_kHz != psDec->fs_kHz || psDec->prev_API_sampleRate != decControl->API_sampleRate ) { + ret = SKP_Silk_resampler_init( &psDec->resampler_state, SKP_SMULBB( psDec->fs_kHz, 1000 ), decControl->API_sampleRate ); + } + + /* Resample the output to API_sampleRate */ + ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut ); + + /* Update the number of output samples */ + *nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, psDec->fs_kHz * 1000 ); + } + + psDec->prev_API_sampleRate = decControl->API_sampleRate; + + /* Copy all parameters that are needed out of internal structure to the control stucture */ + decControl->frameSize = ( SKP_int )psDec->frame_length; + decControl->framesPerPacket = ( SKP_int )psDec->nFramesInPacket; + decControl->inBandFECOffset = ( SKP_int )psDec->inband_FEC_offset; + decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames; + + return ret; +} + +/* 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 */ +) +{ + 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 ]; + + if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) { + /* No useful FEC in this packet */ + *nLBRRBytes = 0; + return; + } + + 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 ) ); + SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn ); + + /* Decode all parameter indices for the whole packet*/ + SKP_Silk_decode_indices_v4( &sDec ); + + /* 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_v4( &sDec, &sDecCtrl, 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 ) ); + } + } +} + +/* Getting type of content for a packet */ +void SKP_Silk_SDK_get_TOC( + const SKP_uint8 *inData, /* I: Encoded input vector */ + 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; + + sDec.nFramesDecoded = 0; + sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */ + SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn ); + + /* Decode all parameter indices for the whole packet*/ + SKP_Silk_decode_indices_v4( &sDec ); + + if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.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_LAST_FRAME ) { + Silk_TOC->inbandLBRR = sDec.FrameTermination; + } else { + Silk_TOC->inbandLBRR = sDec.FrameTermination - 1; + } + /* Copy data */ + for( i = 0; i < sDec.nFramesInPacket; i++ ) { + Silk_TOC->vadFlags[ i ] = sDec.vadFlagBuf[ i ]; + Silk_TOC->sigtypeFlags[ i ] = sDec.sigtype[ i ]; + } + } +} + +/**************************/ +/* Get the version number */ +/**************************/ +/* Return a pointer to string specifying the version */ +const char *SKP_Silk_SDK_get_version() +{ + static const char version[] = "1.0.4"; + return version; +} \ No newline at end of file diff --git a/src/SKP_Silk_decode_core.c b/src_common/SKP_Silk_decode_core.c similarity index 57% rename from src/SKP_Silk_decode_core.c rename to src_common/SKP_Silk_decode_core.c index fec15a2d4..36016a252 100644 --- a/src/SKP_Silk_decode_core.c +++ b/src_common/SKP_Silk_decode_core.c @@ -42,8 +42,10 @@ void SKP_Silk_decode_core( SKP_int16 sLTP[ MAX_FRAME_LENGTH ]; SKP_int32 Gain_Q16, *pred_lag_ptr, *pexc_Q10, *pres_Q10, LTP_pred_Q14, LPC_pred_Q10; SKP_int32 rand_seed, offset_Q10, dither; - SKP_int32 vec_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ], Atmp; + SKP_int32 vec_Q10[ MAX_SUB_FRAME_LENGTH ]; SKP_int32 inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, FiltState[ MAX_LPC_ORDER ]; + SKP_int j; + SKP_assert( psDec->prev_inv_gain_Q16 != 0 ); offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDecCtrl->sigtype ][ psDecCtrl->QuantOffsetType ]; @@ -54,6 +56,9 @@ void SKP_Silk_decode_core( NLSF_interpolation_flag = 0; } +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( q_dec.dat, q, psDec->frame_length * sizeof( SKP_int )); +#endif /* Decode excitation */ rand_seed = psDecCtrl->Seed; @@ -68,13 +73,18 @@ void SKP_Silk_decode_core( rand_seed += q[ i ]; } +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( exc_Q10.dat, psDec->exc_Q10, psDec->frame_length * sizeof( SKP_int32 )); + + /* Resync LTP state here after loss */ +#endif pexc_Q10 = psDec->exc_Q10; pres_Q10 = psDec->res_Q10; - pxq = &psDec->outBuf[ psDec->frame_length ]; - psDec->sLTP_buf_idx = psDec->frame_length; + pxq = &psDec->outBuf[ psDec->ltp_mem_length ]; + psDec->sLTP_buf_idx = psDec->ltp_mem_length; /* Loop over subframes */ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psDec->nb_subfr; k++ ) { A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ]; /* Preload LPC coeficients to array on stack. Gives small performance gain */ @@ -84,8 +94,8 @@ void SKP_Silk_decode_core( LTP_scale_Q14 = psDecCtrl->LTP_scale_Q14; sigtype = psDecCtrl->sigtype; - inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gain_Q16, 1 ) ); - inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX ); + inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gain_Q16, 1 ), 32 ); + inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX ); /* Calculate Gain adjustment factor */ gain_adj_Q16 = ( SKP_int32 )1 << 16; @@ -95,7 +105,7 @@ void SKP_Silk_decode_core( /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */ if( psDec->lossCnt && psDec->prev_sigtype == SIG_TYPE_VOICED && - psDecCtrl->sigtype == SIG_TYPE_UNVOICED && k < ( NB_SUBFR >> 1 ) ) { + psDecCtrl->sigtype == SIG_TYPE_UNVOICED && k < ( MAX_NB_SUBFR >> 1 ) ) { SKP_memset( B_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) ); B_Q14[ LTP_ORDER/2 ] = ( SKP_int16 )1 << 12; /* 0.25 */ @@ -104,6 +114,7 @@ void SKP_Silk_decode_core( psDecCtrl->pitchL[ k ] = psDec->lagPrev; LTP_scale_Q14 = ( SKP_int )1 << 14; } + if( sigtype == SIG_TYPE_VOICED ) { /* Voiced */ @@ -111,11 +122,12 @@ void SKP_Silk_decode_core( /* Re-whitening */ if( ( k & ( 3 - SKP_LSHIFT( NLSF_interpolation_flag, 1 ) ) ) == 0 ) { /* Rewhiten with new A coefs */ - start_idx = psDec->frame_length - lag - psDec->LPC_order - LTP_ORDER / 2; - start_idx = SKP_LIMIT( start_idx, 0, psDec->frame_length - psDec->LPC_order ); + start_idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2; + start_idx = SKP_LIMIT_int( start_idx, 0, psDec->ltp_mem_length - psDec->LPC_order ); - SKP_Silk_MA_Prediction( &psDec->outBuf[ start_idx + k * ( psDec->frame_length >> 2 ) ], - A_Q12, FiltState, sLTP + start_idx, psDec->frame_length - start_idx, psDec->LPC_order ); + SKP_memset( FiltState, 0, psDec->LPC_order * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind and Coverity will complain otherwise */ + 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 ); /* After rewhitening the LTP state is unscaled */ inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 ); @@ -124,7 +136,7 @@ void SKP_Silk_decode_core( inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, psDecCtrl->LTP_scale_Q14 ), 2 ); } for( i = 0; i < (lag + LTP_ORDER/2); i++ ) { - psDec->sLTP_Q16[ psDec->sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->frame_length - i - 1 ] ); + psDec->sLTP_Q16[ psDec->sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->ltp_mem_length - i - 1 ] ); } } else { /* Update LTP state when Gain changes */ @@ -145,7 +157,6 @@ void SKP_Silk_decode_core( SKP_assert( inv_gain_Q16 != 0 ); psDec->prev_inv_gain_Q16 = inv_gain_Q16; - /* Long-term prediction */ if( sigtype == SIG_TYPE_VOICED ) { /* Setup pointer */ @@ -170,72 +181,32 @@ void SKP_Silk_decode_core( SKP_memcpy( pres_Q10, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) ); } +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( res_Q10.dat, pres_Q10, psDec->subfr_length * sizeof( SKP_int32 ) ); +#endif - /* Short term prediction */ - /* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */ - /* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */ - /* loaded in reverse order and the code will give the wrong result. In that case swapping */ - /* the SMLAWB and SMLAWT instructions should solve the problem. */ - if( psDec->LPC_order == 16 ) { - for( i = 0; i < psDec->subfr_length; i++ ) { - /* unrolled */ - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 10 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 11 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 12 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 12 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 13 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 14 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 14 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 15 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 16 ], Atmp ); - - /* Add prediction to LPC residual */ - 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 ); - } - } else { - SKP_assert( psDec->LPC_order == 10 ); - for( i = 0; i < psDec->subfr_length; i++ ) { - /* unrolled */ - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */ - LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp ); - Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] ); - LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp ); - LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp ); - - /* Add prediction to LPC residual */ - 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 ); + for( i = 0; i < psDec->subfr_length; i++ ) { + /* Partially unrolled */ + LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] ); + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] ); + + for( j = 10; j < psDec->LPC_order; j ++ ) { + LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp[ j ] ); } + + /* Add prediction to LPC residual */ + 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 ); } /* Scale with Gain */ @@ -251,6 +222,10 @@ void SKP_Silk_decode_core( } /* Copy to output */ - SKP_memcpy( xq, &psDec->outBuf[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int16 ) ); + SKP_memcpy( xq, &psDec->outBuf[ psDec->ltp_mem_length ], psDec->frame_length * sizeof( SKP_int16 ) ); +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( LTP_buf_Q16.dat, &psDec->sLTP_Q16[psDec->frame_length], psDec->frame_length * sizeof( SKP_int32 )); + DEBUG_STORE_DATA( xq_dec.dat, xq, psDec->frame_length * sizeof( SKP_int16 ) ); +#endif } diff --git a/src/SKP_Silk_decode_frame.c b/src_common/SKP_Silk_decode_frame.c similarity index 79% rename from src/SKP_Silk_decode_frame.c rename to src_common/SKP_Silk_decode_frame.c index 279179b07..c3a5339e7 100644 --- a/src/SKP_Silk_decode_frame.c +++ b/src_common/SKP_Silk_decode_frame.c @@ -43,9 +43,11 @@ SKP_int SKP_Silk_decode_frame( ) { SKP_Silk_decoder_control sDecCtrl; - SKP_int L, fs_Khz_old, LPC_order_old, ret = 0; + SKP_int L, fs_Khz_old, nb_subfr_old, mv_len, ret = 0; SKP_int Pulses[ MAX_FRAME_LENGTH ]; + ec_byte_buffer range_dec_celt_buf; +TIC(decode_frame) L = psDec->frame_length; sDecCtrl.LTP_scale_Q14 = 0; @@ -62,45 +64,43 @@ SKP_int SKP_Silk_decode_frame( /* Initialize arithmetic coder */ /********************************************/ fs_Khz_old = psDec->fs_kHz; - LPC_order_old = psDec->LPC_order; + nb_subfr_old = psDec->nb_subfr; if( psDec->nFramesDecoded == 0 ) { /* Initialize range decoder state */ - SKP_Silk_range_dec_init( &psDec->sRC, pCode, nBytes ); - - if( psDec->bitstream_v == BIT_STREAM_V4 ) { - SKP_Silk_decode_indices_v4( psDec ); + /* check input */ + psDec->sRC.error = 0; + if( nBytes > MAX_ARITHM_BYTES ) { + psDec->sRC.error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG; } + ec_byte_writeinit_buffer( &range_dec_celt_buf, psDec->sRC.buffer, nBytes ); + SKP_memcpy( psDec->sRC.buffer, pCode, nBytes * sizeof( SKP_uint8 ) ); + ec_dec_init( &psDec->sRC.range_dec_celt_state, &range_dec_celt_buf ); + + SKP_Silk_decode_indices_v4( psDec ); } /********************************************/ /* Decode parameters and pulse signal */ /********************************************/ - if( psDec->bitstream_v == BIT_STREAM_V4 ) { - SKP_Silk_decode_parameters_v4( psDec, &sDecCtrl, Pulses, 1 ); - } else { - SKP_Silk_decode_parameters( psDec, &sDecCtrl, Pulses, 1 ); - } - +TIC(decode_params) + SKP_Silk_decode_parameters_v4( psDec, &sDecCtrl, Pulses, 1 ); +TOC(decode_params) if( psDec->sRC.error ) { psDec->nBytesLeft = 0; action = 1; /* PLC operation */ - psDec->fs_kHz = fs_Khz_old; /* revert fs if changed in decode_parameters */ - psDec->LPC_order = LPC_order_old; /* revert lpc_order if changed in decode_parameters */ - psDec->frame_length = fs_Khz_old * FRAME_LENGTH_MS; - psDec->subfr_length = fs_Khz_old * FRAME_LENGTH_MS / NB_SUBFR; + SKP_Silk_decoder_set_fs( psDec, fs_Khz_old, nb_subfr_old ); /* Avoid crashing */ - *decBytes = psDec->sRC.bufferLength; - + *decBytes = psDec->sRC.range_dec_celt_state.buf->storage; if( psDec->sRC.error == RANGE_CODER_DEC_PAYLOAD_TOO_LONG ) { ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE; } else { ret = SKP_SILK_DEC_PAYLOAD_ERROR; } } else { - *decBytes = psDec->sRC.bufferLength - psDec->nBytesLeft; + *decBytes = psDec->sRC.range_dec_celt_state.buf->storage - psDec->nBytesLeft; psDec->nFramesDecoded++; /* Update lengths. Sampling frequency could have changed */ @@ -109,7 +109,9 @@ SKP_int SKP_Silk_decode_frame( /********************************************************/ /* Run inverse NSQ */ /********************************************************/ +TIC(decode_core) SKP_Silk_decode_core( psDec, &sDecCtrl, pOut, Pulses ); +TOC(decode_core) /********************************************************/ /* Update PLC state */ @@ -124,19 +126,23 @@ SKP_int SKP_Silk_decode_frame( } } /*************************************************************/ - /* Generate Concealment Frame if packet is lost, or corrupt */ + /* Generate Concealment frame if packet is lost, or corrupt */ /*************************************************************/ if( action == 1 ) { /* Handle packet loss by extrapolation */ SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action ); psDec->lossCnt++; - } /*************************/ /* Update output buffer. */ /*************************/ - SKP_memcpy( psDec->outBuf, pOut, L * sizeof( SKP_int16 ) ); + SKP_assert( psDec->ltp_mem_length >= psDec->frame_length ); + mv_len = psDec->ltp_mem_length - psDec->frame_length; + SKP_memmove( psDec->outBuf, &psDec->outBuf[ psDec->ltp_mem_length - mv_len ], + mv_len * sizeof(SKP_int16) ); + SKP_memcpy( &psDec->outBuf[ mv_len ], pOut, + psDec->frame_length * sizeof( SKP_int16 ) ); /****************************************************************/ /* Ensure smooth connection of extrapolated and good frames */ @@ -153,7 +159,9 @@ SKP_int SKP_Silk_decode_frame( /********************************************/ SKP_assert( ( ( psDec->fs_kHz == 12 ) && ( L % 3 ) == 0 ) || ( ( psDec->fs_kHz != 12 ) && ( L % 2 ) == 0 ) ); +TIC(HP_out) SKP_Silk_biquad( pOut, psDec->HP_B, psDec->HP_A, psDec->HPState, pOut, L ); +TOC(HP_out) /********************************************/ /* set output frame length */ @@ -161,7 +169,8 @@ SKP_int SKP_Silk_decode_frame( *pN = ( SKP_int16 )L; /* Update some decoder state variables */ - psDec->lagPrev = sDecCtrl.pitchL[ NB_SUBFR - 1 ]; + psDec->lagPrev = sDecCtrl.pitchL[ MAX_NB_SUBFR - 1 ]; +TOC(decode_frame) return ret; } diff --git a/src/SKP_Silk_decode_indices_v4.c b/src_common/SKP_Silk_decode_indices_v4.c similarity index 91% rename from src/SKP_Silk_decode_indices_v4.c rename to src_common/SKP_Silk_decode_indices_v4.c index b86d1f57f..e41797ba4 100644 --- a/src/SKP_Silk_decode_indices_v4.c +++ b/src_common/SKP_Silk_decode_indices_v4.c @@ -32,7 +32,7 @@ void SKP_Silk_decode_indices_v4( SKP_Silk_decoder_state *psDec /* I/O State */ ) { - SKP_int i, k, Ix, fs_kHz_dec, FrameIndex = 0, FrameTermination; + SKP_int i, k, Ix, fs_kHz_dec, nb_subfr, FrameIndex = 0, FrameTermination; SKP_int sigtype, QuantOffsetType, seed_int, nBytesUsed; SKP_int decode_absolute_lagIndex, delta_lagIndex, prev_lagIndex = 0; const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL; @@ -50,7 +50,13 @@ void SKP_Silk_decode_indices_v4( return; } fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ]; - SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec ); + + /* Convert number of subframes to index */ + SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_NbSubframes_CDF, SKP_Silk_NbSubframes_offset ); + nb_subfr = (Ix + 1) << 1; + SKP_assert( nb_subfr == MAX_NB_SUBFR >> 1 || nb_subfr == MAX_NB_SUBFR ); + + SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec, nb_subfr ); FrameIndex = 0; FrameTermination = SKP_SILK_MORE_FRAMES; @@ -90,7 +96,7 @@ void SKP_Silk_decode_indices_v4( } /* remaining subframes */ - for( i = 1; i < NB_SUBFR; i++ ) { + for( i = 1; i < psDec->nb_subfr; i++ ) { SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset ); } @@ -154,7 +160,7 @@ void SKP_Silk_decode_indices_v4( /* Decode PERIndex value */ SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRC, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset ); - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psDec->nb_subfr; k++ ) { SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], SKP_Silk_LTP_gain_CDF_offsets[ psDec->PERIndex[ FrameIndex ] ] ); } @@ -184,8 +190,9 @@ void SKP_Silk_decode_indices_v4( /****************************************/ /* get number of bytes used so far */ /****************************************/ - SKP_Silk_range_coder_get_length( psRC, &nBytesUsed ); - psDec->nBytesLeft = psRC->bufferLength - nBytesUsed; + SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed ); + psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed; + if( psDec->nBytesLeft < 0 ) { psRC->error = RANGE_CODER_READ_BEYOND_BUFFER; } diff --git a/src/SKP_Silk_decode_parameters_v4.c b/src_common/SKP_Silk_decode_parameters_v4.c similarity index 89% rename from src/SKP_Silk_decode_parameters_v4.c rename to src_common/SKP_Silk_decode_parameters_v4.c index 2770b1b9d..67027422d 100644 --- a/src/SKP_Silk_decode_parameters_v4.c +++ b/src_common/SKP_Silk_decode_parameters_v4.c @@ -49,7 +49,8 @@ void SKP_Silk_decode_parameters_v4( psDecCtrl->Seed = psDec->Seed[ psDec->nFramesDecoded ]; /* Dequant Gains */ - SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->GainsIndices[ psDec->nFramesDecoded ], &psDec->LastGainIndex, psDec->nFramesDecoded ); + SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->GainsIndices[ psDec->nFramesDecoded ], + &psDec->LastGainIndex, psDec->nFramesDecoded, psDec->nb_subfr ); /****************/ /* Decode NLSFs */ /****************/ @@ -99,8 +100,8 @@ void SKP_Silk_decode_parameters_v4( /*********************/ /* Decode pitch values */ - SKP_Silk_decode_pitch( psDec->lagIndex[ psDec->nFramesDecoded ], - psDec->contourIndex[ psDec->nFramesDecoded ], psDecCtrl->pitchL, psDec->fs_kHz ); + SKP_Silk_decode_pitch( psDec->lagIndex[ psDec->nFramesDecoded ], psDec->contourIndex[ psDec->nFramesDecoded ], + psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr ); /********************/ /* Decode LTP gains */ @@ -110,7 +111,7 @@ void SKP_Silk_decode_parameters_v4( /* Decode Codebook Index */ cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psDec->nb_subfr; k++ ) { Ix = psDec->LTPIndex[ psDec->nFramesDecoded ][ k ]; for( i = 0; i < LTP_ORDER; i++ ) { psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( k, LTP_ORDER ) + i ] = cbk_ptr_Q14[ SKP_SMULBB( Ix, LTP_ORDER ) + i ]; @@ -123,8 +124,9 @@ void SKP_Silk_decode_parameters_v4( Ix = psDec->LTP_scaleIndex[ psDec->nFramesDecoded ]; psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ]; } else { - SKP_memset( psDecCtrl->pitchL, 0, NB_SUBFR * sizeof( SKP_int ) ); - SKP_memset( psDecCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) ); + SKP_assert( psDecCtrl->sigtype == SIG_TYPE_UNVOICED ); + SKP_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( SKP_int ) ); + SKP_memset( psDecCtrl->LTPCoef_Q14, 0, psDec->nb_subfr * LTP_ORDER * sizeof( SKP_int16 ) ); psDecCtrl->PERIndex = 0; psDecCtrl->LTP_scale_Q14 = 0; } @@ -132,13 +134,16 @@ void SKP_Silk_decode_parameters_v4( /*********************************************/ /* Decode quantization indices of excitation */ /*********************************************/ +TIC(decode_pulses) SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length ); +TOC(decode_pulses) /****************************************/ /* get number of bytes used so far */ /****************************************/ - SKP_Silk_range_coder_get_length( psRC, &nBytesUsed ); - psDec->nBytesLeft = psRC->bufferLength - nBytesUsed; + SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed ); + psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed; + if( psDec->nBytesLeft < 0 ) { psRC->error = RANGE_CODER_READ_BEYOND_BUFFER; } diff --git a/src/SKP_Silk_decode_pulses.c b/src_common/SKP_Silk_decode_pulses.c similarity index 92% rename from src/SKP_Silk_decode_pulses.c rename to src_common/SKP_Silk_decode_pulses.c index 402228ab8..bdcd37c56 100644 --- a/src/SKP_Silk_decode_pulses.c +++ b/src_common/SKP_Silk_decode_pulses.c @@ -49,8 +49,12 @@ void SKP_Silk_decode_pulses( SKP_Silk_rate_levels_CDF[ psDecCtrl->sigtype ], SKP_Silk_rate_levels_CDF_offset ); /* Calculate number of shell blocks */ - iter = frame_length / SHELL_CODEC_FRAME_LENGTH; - + SKP_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); + iter = SKP_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); + if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ){ + SKP_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */ + iter++; + } /***************************************************/ /* Sum-Weighted-Pulses Decoding */ /***************************************************/ diff --git a/src/SKP_Silk_decoder_set_fs.c b/src_common/SKP_Silk_decoder_set_fs.c similarity index 86% rename from src/SKP_Silk_decoder_set_fs.c rename to src_common/SKP_Silk_decoder_set_fs.c index 824a84b30..b0a94f44c 100644 --- a/src/SKP_Silk_decoder_set_fs.c +++ b/src_common/SKP_Silk_decoder_set_fs.c @@ -30,13 +30,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Set decoder sampling rate */ void SKP_Silk_decoder_set_fs( SKP_Silk_decoder_state *psDec, /* I/O Decoder state pointer */ - SKP_int fs_kHz /* I Sampling frequency (kHz) */ + SKP_int fs_kHz, /* I Sampling frequency (kHz) */ + SKP_int nb_subfr /* I Number of subframes */ ) { + psDec->nb_subfr = nb_subfr; + psDec->frame_length = SKP_SMULBB( psDec->nb_subfr, psDec->subfr_length ); if( psDec->fs_kHz != fs_kHz ) { psDec->fs_kHz = fs_kHz; - psDec->frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz ); - psDec->subfr_length = SKP_SMULBB( FRAME_LENGTH_MS / NB_SUBFR, fs_kHz ); + psDec->subfr_length = SKP_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz ); + psDec->frame_length = SKP_SMULBB( psDec->nb_subfr, psDec->subfr_length ); + psDec->ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); if( psDec->fs_kHz == 8 ) { psDec->LPC_order = MIN_LPC_ORDER; psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10; diff --git a/src/SKP_Silk_define.h b/src_common/SKP_Silk_define.h similarity index 77% rename from src/SKP_Silk_define.h rename to src_common/SKP_Silk_define.h index 27d20ca1a..9895c003e 100644 --- a/src/SKP_Silk_define.h +++ b/src_common/SKP_Silk_define.h @@ -36,12 +36,11 @@ extern "C" { #endif +#define MAX_FRAMES_PER_PACKET 3 -#define MAX_FRAMES_PER_PACKET 5 -#define BIT_STREAM_V3 3 -#define BIT_STREAM_V4 4 -#define USE_BIT_STREAM_V BIT_STREAM_V3 // Should be moved to a API call - +#ifndef FIXED_POINT +# define FIXED_POINT 0 +#endif /* MAX DELTA LAG used for multiframe packets */ #define MAX_DELTA_LAG 10 @@ -53,11 +52,10 @@ extern "C" #define MIN_TARGET_RATE_SWB_BPS 20000 /* Transition bitrates between modes */ -#define SWB2WB_BITRATE_BPS 30000 -#define SWB2WB_BITRATE_BPS_INITIAL 25000 -#define WB2SWB_BITRATE_BPS 35000 -#define WB2MB_BITRATE_BPS 15000 -#define MB2WB_BITRATE_BPS 20000 +#define SWB2WB_BITRATE_BPS 25000 +#define WB2SWB_BITRATE_BPS 30000 +#define WB2MB_BITRATE_BPS 14000 +#define MB2WB_BITRATE_BPS 18000 #define MB2NB_BITRATE_BPS 10000 #define NB2MB_BITRATE_BPS 14000 @@ -101,28 +99,17 @@ extern "C" #define WB_DETECT_ACTIVE_SPEECH_MS_THRES 15000 /* ms of active speech needed for WB detection */ /* Low complexity setting */ -#ifdef EMBEDDED_OPT -# define LOW_COMPLEXITY_ONLY 1 -#else -# define LOW_COMPLEXITY_ONLY 0 -#endif +#define LOW_COMPLEXITY_ONLY 0 /* Activate bandwidth transition filtering for mode switching */ -#ifdef EMBEDDED_OPT -# define SWITCH_TRANSITION_FILTERING 0 -#else -#ifndef FORCE_FS_KHZ -# define SWITCH_TRANSITION_FILTERING 1 -#else -# define SWITCH_TRANSITION_FILTERING 0 -#endif -#endif +# define SWITCH_TRANSITION_FILTERING 1 /* Decoder Parameters */ #define DEC_HP_ORDER 2 /* Maximum sampling frequency, should be 16 for embedded */ #define MAX_FS_KHZ 24 +#define MAX_API_FS_KHZ 48 /* Signal Types used by silk */ #define SIG_TYPE_VOICED 0 @@ -132,9 +119,15 @@ extern "C" #define NO_VOICE_ACTIVITY 0 #define VOICE_ACTIVITY 1 +/* Number of subframes */ +#define MAX_NB_SUBFR 4 + /* number of samples per frame */ -#define FRAME_LENGTH_MS 20 /* 20 ms */ -#define MAX_FRAME_LENGTH (FRAME_LENGTH_MS * MAX_FS_KHZ) +#define LTP_MEM_LENGTH_MS 20 +#define SUB_FRAME_LENGTH_MS 5 +#define MAX_SUB_FRAME_LENGTH ( SUB_FRAME_LENGTH_MS * MAX_FS_KHZ ) +#define MAX_FRAME_LENGTH_MS ( SUB_FRAME_LENGTH_MS * MAX_NB_SUBFR ) +#define MAX_FRAME_LENGTH ( MAX_FRAME_LENGTH_MS * MAX_FS_KHZ ) /* number of lookahead samples for pitch analysis */ #define LA_PITCH_MS 3 @@ -145,15 +138,16 @@ extern "C" #define LA_SHAPE_MAX (LA_SHAPE_MS * MAX_FS_KHZ) /* Order of LPC used in find pitch */ -#define FIND_PITCH_LPC_ORDER_MAX 16 +#define MAX_FIND_PITCH_LPC_ORDER 16 /* Length of LPC window used in find pitch */ #define FIND_PITCH_LPC_WIN_MS (30 + (LA_PITCH_MS << 1)) +#define FIND_PITCH_LPC_WIN_MS_2_SF (15 + (LA_PITCH_MS << 1)) #define FIND_PITCH_LPC_WIN_MAX (FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ) -#define PITCH_EST_COMPLEXITY_HC_MODE SigProc_PITCH_EST_MAX_COMPLEX -#define PITCH_EST_COMPLEXITY_MC_MODE SigProc_PITCH_EST_MID_COMPLEX -#define PITCH_EST_COMPLEXITY_LC_MODE SigProc_PITCH_EST_MIN_COMPLEX +#define PITCH_EST_COMPLEXITY_HC_MODE SKP_Silk_PE_MAX_COMPLEX +#define PITCH_EST_COMPLEXITY_MC_MODE SKP_Silk_PE_MID_COMPLEX +#define PITCH_EST_COMPLEXITY_LC_MODE SKP_Silk_PE_MIN_COMPLEX /* Max number of bytes in payload output buffer (may contain multiple frames) */ @@ -197,14 +191,11 @@ extern "C" /* LTP quantization settings */ #define NB_LTP_CBKS 3 -/* Number of subframes */ -#define NB_SUBFR 4 - /* Flag to use harmonic noise shaping */ #define USE_HARM_SHAPING 1 /* Max LPC order of noise shaping filters */ -#define SHAPE_LPC_ORDER_MAX 16 +#define MAX_SHAPE_LPC_ORDER 16 #define HARM_SHAPE_FIR_TAPS 3 @@ -215,7 +206,7 @@ extern "C" #define SHAPE_LPC_WIN_MAX (SHAPE_LPC_WIN_MS * MAX_FS_KHZ) /* Maximum number of delayed decision states */ -#define DEL_DEC_STATES_MAX 4 +#define MAX_DEL_DEC_STATES 4 #define LTP_BUF_LENGTH 512 #define LTP_MASK (LTP_BUF_LENGTH - 1) @@ -225,6 +216,7 @@ extern "C" /* number of subframes for excitation entropy coding */ #define SHELL_CODEC_FRAME_LENGTH 16 +#define LOG2_SHELL_CODEC_FRAME_LENGTH 4 #define MAX_NB_SHELL_BLOCKS (MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH) /* number of rate levels, for entropy coding of excitation */ @@ -249,7 +241,7 @@ extern "C" /***************************/ /* Voice activity detector */ /***************************/ -#define VAD_N_BANDS 4 /* 0-1, 1-2, 2-4, and 4-8 kHz */ +#define VAD_N_BANDS 4 #define VAD_INTERNAL_SUBFRAMES_LOG2 2 #define VAD_INTERNAL_SUBFRAMES (1 << VAD_INTERNAL_SUBFRAMES_LOG2) @@ -267,15 +259,9 @@ extern "C" /******************/ /* NLSF quantizer */ /******************/ -#ifdef NLSF_TRAINING -# define NLSF_MSVQ_MAX_CB_STAGES 30 -# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE 256 -# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END 128 -#else # define NLSF_MSVQ_MAX_CB_STAGES 10 /* Update manually when changing codebooks */ # define NLSF_MSVQ_MAX_VECTORS_IN_STAGE 128 /* Update manually when changing codebooks */ # define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END 16 /* Update manually when changing codebooks */ -#endif #define NLSF_MSVQ_FLUCTUATION_REDUCTION 1 #define MAX_NLSF_MSVQ_SURVIVORS 16 @@ -299,29 +285,30 @@ extern "C" /* Transition filtering for mode switching */ #if SWITCH_TRANSITION_FILTERING -# define TRANSITION_TIME_UP_MS 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4) -# define TRANSITION_TIME_DOWN_MS 2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(20*4) -# define TRANSITION_NB 3 /* Hardcoded in tables */ -# define TRANSITION_NA 2 /* Hardcoded in tables */ -# define TRANSITION_INT_NUM 5 /* Hardcoded in tables */ -# define TRANSITION_FRAMES_UP ( TRANSITION_TIME_UP_MS / FRAME_LENGTH_MS ) -# define TRANSITION_FRAMES_DOWN ( TRANSITION_TIME_DOWN_MS / FRAME_LENGTH_MS ) -# define TRANSITION_INT_STEPS_UP ( TRANSITION_FRAMES_UP / ( TRANSITION_INT_NUM - 1 ) ) -# define TRANSITION_INT_STEPS_DOWN ( TRANSITION_FRAMES_DOWN / ( TRANSITION_INT_NUM - 1 ) ) -#endif - -/* Row based */ -#define matrix_ptr(Matrix_base_adr, row, column, N) *(Matrix_base_adr + ((row)*(N)+(column))) -#define matrix_adr(Matrix_base_adr, row, column, N) (Matrix_base_adr + ((row)*(N)+(column))) - -/* Column based */ -#ifndef matrix_c_ptr -# define matrix_c_ptr(Matrix_base_adr, row, column, M) *(Matrix_base_adr + ((row)+(M)*(column))) +# define TRANSITION_TIME_UP_MS 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4) +# define TRANSITION_TIME_DOWN_MS 2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(20*4) +# define TRANSITION_NB 3 /* Hardcoded in tables */ +# define TRANSITION_NA 2 /* Hardcoded in tables */ +# define TRANSITION_INT_NUM 5 /* Hardcoded in tables */ +# define TRANSITION_FRAMES_UP ( TRANSITION_TIME_UP_MS / MAX_FRAME_LENGTH_MS ) // NB! needs to be made flexible for 10 ms frames +# define TRANSITION_FRAMES_DOWN ( TRANSITION_TIME_DOWN_MS / MAX_FRAME_LENGTH_MS ) // NB! needs to be made flexible for 10 ms frames +# define TRANSITION_INT_STEPS_UP ( TRANSITION_FRAMES_UP / ( TRANSITION_INT_NUM - 1 ) ) +# define TRANSITION_INT_STEPS_DOWN ( TRANSITION_FRAMES_DOWN / ( TRANSITION_INT_NUM - 1 ) ) #endif -#define matrix_c_adr(Matrix_base_adr, row, column, M) (Matrix_base_adr + ((row)+(M)*(column))) /* BWE factors to apply after packet loss */ -#define BWE_AFTER_LOSS_Q16 63570 +#define BWE_AFTER_LOSS_Q16 63570 + +/*************************/ +/* Perceptual parameters */ +/*************************/ +/* Amount of warping to apply */ +#define WARPING_MULTIPLIER_Q16 SKP_FIX_CONST( 0.02, 16 ) + +/* Defines for CN generation */ +#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */ +#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */ +#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */ #ifdef __cplusplus } diff --git a/src/SKP_Silk_detect_SWB_input.c b/src_common/SKP_Silk_detect_SWB_input.c similarity index 96% rename from src/SKP_Silk_detect_SWB_input.c rename to src_common/SKP_Silk_detect_SWB_input.c index c251cea8f..cbc34340f 100644 --- a/src/SKP_Silk_detect_SWB_input.c +++ b/src_common/SKP_Silk_detect_SWB_input.c @@ -37,9 +37,9 @@ void SKP_Silk_detect_SWB_input( SKP_int nSamplesIn /* (I) length of input */ ) { - SKP_int HP_8_kHz_len, i; + SKP_int HP_8_kHz_len, i, shift; SKP_int16 in_HP_8_kHz[ MAX_FRAME_LENGTH ]; - SKP_int32 energy_32, shift; + SKP_int32 energy_32; /* High pass filter with cutoff at 8 khz */ HP_8_kHz_len = SKP_min_int( nSamplesIn, MAX_FRAME_LENGTH ); diff --git a/src_common/SKP_Silk_enc_API.c b/src_common/SKP_Silk_enc_API.c new file mode 100644 index 000000000..79265273c --- /dev/null +++ b/src_common/SKP_Silk_enc_API.c @@ -0,0 +1,242 @@ +/*********************************************************************** +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. +***********************************************************************/ + + +#include "SKP_Silk_define.h" +#include "SKP_Silk_SDK_API.h" +#include "SKP_Silk_control.h" +#include "SKP_Silk_typedef.h" +#include "SKP_Silk_structs.h" +#if FIXED_POINT +#include "SKP_Silk_main_FIX.h" +#define SKP_Silk_encoder_state_Fxx SKP_Silk_encoder_state_FIX +#define SKP_Silk_init_encoder_Fxx SKP_Silk_init_encoder_FIX +#define SKP_Silk_control_encoder_Fxx SKP_Silk_control_encoder_FIX +#define SKP_Silk_encode_frame_Fxx SKP_Silk_encode_frame_FIX +#else +#include "SKP_Silk_main_FLP.h" +#define SKP_Silk_encoder_state_Fxx SKP_Silk_encoder_state_FLP +#define SKP_Silk_init_encoder_Fxx SKP_Silk_init_encoder_FLP +#define SKP_Silk_control_encoder_Fxx SKP_Silk_control_encoder_FLP +#define SKP_Silk_encode_frame_Fxx SKP_Silk_encode_frame_FLP +#endif +#define SKP_Silk_EncodeControlStruct SKP_SILK_SDK_EncControlStruct + + +/****************************************/ +/* Encoder functions */ +/****************************************/ + +SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes ) +{ + SKP_int ret = SKP_SILK_NO_ERROR; + + *encSizeBytes = sizeof( SKP_Silk_encoder_state_Fxx ); + + return ret; +} + + +/***************************************/ +/* Read control structure from encoder */ +/***************************************/ +SKP_int SKP_Silk_SDK_QueryEncoder( + const void *encState, /* I: State Vector */ + SKP_Silk_EncodeControlStruct *encStatus /* O: Control Structure */ +) +{ + SKP_Silk_encoder_state_Fxx *psEnc; + SKP_int ret = SKP_SILK_NO_ERROR; + + psEnc = ( SKP_Silk_encoder_state_Fxx* )encState; + + encStatus->API_sampleRate = psEnc->sCmn.API_fs_Hz; + encStatus->maxInternalSampleRate = SKP_SMULBB( psEnc->sCmn.maxInternal_fs_kHz, 1000 ); + encStatus->packetSize = ( SKP_int )SKP_DIV32_16( psEnc->sCmn.API_fs_Hz * psEnc->sCmn.PacketSize_ms, 1000 ); /* convert samples -> ms */ + encStatus->bitRate = psEnc->sCmn.TargetRate_bps; + encStatus->packetLossPercentage = psEnc->sCmn.PacketLoss_perc; + encStatus->complexity = psEnc->sCmn.Complexity; + encStatus->useInBandFEC = psEnc->sCmn.useInBandFEC; + encStatus->useDTX = psEnc->sCmn.useDTX; + return ret; +} + +/*************************/ +/* Init or Reset encoder */ +/*************************/ +SKP_int SKP_Silk_SDK_InitEncoder( + void *encState, /* I/O: State */ + SKP_Silk_EncodeControlStruct *encStatus /* O: Control structure */ +) +{ + SKP_Silk_encoder_state_Fxx *psEnc; + SKP_int ret = SKP_SILK_NO_ERROR; + + + psEnc = ( SKP_Silk_encoder_state_Fxx* )encState; + + /* Reset Encoder */ + if( ret += SKP_Silk_init_encoder_Fxx( psEnc ) ) { + SKP_assert( 0 ); + } + + /* Read control structure */ + if( ret += SKP_Silk_SDK_QueryEncoder( encState, encStatus ) ) { + SKP_assert( 0 ); + } + + + return ret; +} + +/**************************/ +/* Encode frame with Silk */ +/**************************/ +SKP_int SKP_Silk_SDK_Encode( + void *encState, /* I/O: State */ + const SKP_Silk_EncodeControlStruct *encControl, /* I: Control structure */ + const SKP_int16 *samplesIn, /* I: Speech sample input vector */ + SKP_int nSamplesIn, /* I: Number of samples in input vector */ + SKP_uint8 *outData, /* O: Encoded output vector */ + SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */ +) +{ + SKP_int max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = SKP_SILK_NO_ERROR; + SKP_int nSamplesToBuffer, Complexity, input_ms, nSamplesFromInput = 0; + SKP_int32 TargetRate_bps, API_fs_Hz; + SKP_int16 MaxBytesOut; + SKP_Silk_encoder_state_Fxx *psEnc = ( SKP_Silk_encoder_state_Fxx* )encState; + + SKP_assert( encControl != NULL ); + + /* Check sampling frequency first, to avoid divide by zero later */ + if( ( ( encControl->API_sampleRate != 8000 ) && + ( encControl->API_sampleRate != 12000 ) && + ( encControl->API_sampleRate != 16000 ) && + ( encControl->API_sampleRate != 24000 ) && + ( encControl->API_sampleRate != 32000 ) && + ( encControl->API_sampleRate != 44100 ) && + ( encControl->API_sampleRate != 48000 ) ) || + ( ( encControl->maxInternalSampleRate != 8000 ) && + ( encControl->maxInternalSampleRate != 12000 ) && + ( encControl->maxInternalSampleRate != 16000 ) && + ( encControl->maxInternalSampleRate != 24000 ) ) ) { + ret = SKP_SILK_ENC_FS_NOT_SUPPORTED; + SKP_assert( 0 ); + return( ret ); + } + + /* Set encoder parameters from control structure */ + API_fs_Hz = encControl->API_sampleRate; + max_internal_fs_kHz = SKP_DIV32_16( ( SKP_int )encControl->maxInternalSampleRate, 1000 ); /* convert Hz -> kHz */ + PacketSize_ms = SKP_DIV32( 1000 * ( SKP_int )encControl->packetSize, API_fs_Hz ); + TargetRate_bps = ( SKP_int32 )encControl->bitRate; + PacketLoss_perc = ( SKP_int )encControl->packetLossPercentage; + UseInBandFEC = ( SKP_int )encControl->useInBandFEC; + Complexity = ( SKP_int )encControl->complexity; + UseDTX = ( SKP_int )encControl->useDTX; + /* Save values in state */ + psEnc->sCmn.API_fs_Hz = API_fs_Hz; + psEnc->sCmn.maxInternal_fs_kHz = max_internal_fs_kHz; + psEnc->sCmn.useInBandFEC = UseInBandFEC; + + /* Only accept input lengths that are a multiplum of 10 ms */ + input_ms = SKP_DIV32( 1000 * nSamplesIn, API_fs_Hz ); + if( ( input_ms % 10) != 0 || nSamplesIn < 0 ) { + ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; + SKP_assert( 0 ); + return( ret ); + } + + /* Make sure no more than one packet can be produced */ + if( nSamplesIn > SKP_DIV32_16( psEnc->sCmn.PacketSize_ms * API_fs_Hz, 1000 ) ) { + ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; + SKP_assert( 0 ); + return( ret ); + } + if( ( ret = SKP_Silk_control_encoder_Fxx( psEnc, API_fs_Hz, max_internal_fs_kHz, PacketSize_ms, TargetRate_bps, + PacketLoss_perc, UseInBandFEC, UseDTX, input_ms, Complexity) ) != 0 ) { + SKP_assert( 0 ); + return( ret ); + } + + /* Detect energy above 8 kHz */ + if( SKP_min( API_fs_Hz, 1000 * max_internal_fs_kHz ) == 24000 && psEnc->sCmn.sSWBdetect.SWB_detected == 0 && psEnc->sCmn.sSWBdetect.WB_detected == 0 ) { + SKP_Silk_detect_SWB_input( &psEnc->sCmn.sSWBdetect, samplesIn, ( SKP_int )nSamplesIn ); + } + + /* 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 ) ) { + nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, nSamplesIn ); + nSamplesFromInput = nSamplesToBuffer; + /* Copy to buffer */ + SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput * sizeof( SKP_int16 ) ); + } else { + nSamplesToBuffer = SKP_min( nSamplesToBuffer, SKP_DIV32( ( SKP_int32 )nSamplesIn * psEnc->sCmn.fs_kHz * 1000, API_fs_Hz ) ); + nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 ); + /* Resample and write to buffer */ + ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput ); + } + samplesIn += nSamplesFromInput; + nSamplesIn -= nSamplesFromInput; + psEnc->sCmn.inputBufIx += nSamplesToBuffer; + + /* Silk encoder */ + if( 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, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) { + SKP_assert( 0 ); + } + } else { + /* outData already contains a payload */ + if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) { + SKP_assert( 0 ); + } + /* Check that no second payload was created */ + SKP_assert( *nBytesOut == 0 ); + } + psEnc->sCmn.inputBufIx = 0; + } else { + break; + } + } + + *nBytesOut = MaxBytesOut; + if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) { + /* DTX simulation */ + *nBytesOut = 0; + } + + return ret; +} + diff --git a/src/SKP_Silk_encode_parameters_v4.c b/src_common/SKP_Silk_encode_parameters_v4.c similarity index 71% rename from src/SKP_Silk_encode_parameters_v4.c rename to src_common/SKP_Silk_encode_parameters_v4.c index c6786b8c2..07c6e047c 100644 --- a/src/SKP_Silk_encode_parameters_v4.c +++ b/src_common/SKP_Silk_encode_parameters_v4.c @@ -40,17 +40,17 @@ void SKP_Silk_encode_parameters_v4( SKP_int encode_absolute_lagIndex, delta_lagIndex; const SKP_Silk_NLSF_CB_struct *psNLSF_CB; - - /************************/ - /* Encode sampling rate */ - /************************/ +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_int nBytes_lagIndex, nBytes_contourIndex, nBytes_LTP; + SKP_int nBytes_after, nBytes_before; +#endif + + /*************************************/ + /* Encode sampling rate and */ + /* number of subframes in each frame */ + /*************************************/ /* only done for first frame in packet */ if( psEncC->nFramesInPayloadBuf == 0 ) { - - /* Initialize arithmetic coder */ - SKP_Silk_range_enc_init( &psEncC->sRC ); - psEncC->nBytesInPayloadBuf = 0; - /* get sampling rate index */ for( i = 0; i < 3; i++ ) { if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) { @@ -58,6 +58,11 @@ void SKP_Silk_encode_parameters_v4( } } SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF ); + + /* Convert number of subframes to index */ + SKP_assert( psEncC->nb_subfr == MAX_NB_SUBFR >> 1 || psEncC->nb_subfr == MAX_NB_SUBFR ); + i = (psEncC->nb_subfr >> 1) - 1; + SKP_Silk_range_encoder( psRC, i, SKP_Silk_NbSubframes_CDF ); } /*********************************************/ @@ -81,6 +86,9 @@ void SKP_Silk_encode_parameters_v4( /****************/ /* Encode gains */ /****************/ +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /* first subframe */ if( psEncC->nFramesInPayloadBuf == 0 ) { /* first frame in packet: independent coding */ @@ -91,14 +99,22 @@ void SKP_Silk_encode_parameters_v4( } /* remaining subframes */ - for( i = 1; i < NB_SUBFR; i++ ) { + for( i = 1; i < psEncC->nb_subfr; i++ ) { SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF ); } +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); + nBytes_after -= nBytes_before; // bytes just added + DEBUG_STORE_DATA( nBytes_gains.dat, &nBytes_after, sizeof( SKP_int ) ); +#endif /****************/ /* Encode NLSFs */ /****************/ +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /* Range encoding of the NLSF path */ psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ]; SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages ); @@ -107,13 +123,19 @@ void SKP_Silk_encode_parameters_v4( SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) ); SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF ); +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); + nBytes_after -= nBytes_before; // bytes just added + DEBUG_STORE_DATA( nBytes_LSF.dat, &nBytes_after, sizeof( SKP_int ) ); +#endif if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) { /*********************/ /* Encode pitch lags */ /*********************/ - - +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /* lag index */ encode_absolute_lagIndex = 1; if( psEncC->nFramesInPayloadBuf > 0 && psEncC->prev_sigtype == SIG_TYPE_VOICED ) { @@ -143,7 +165,14 @@ void SKP_Silk_encode_parameters_v4( } psEncC->prev_lagIndex = psEncCtrlC->lagIndex; +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); + nBytes_lagIndex = nBytes_after - nBytes_before; // bytes just added +#endif +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /* countour index */ if( psEncC->fs_kHz == 8 ) { /* Less codevectors used in 8 khz mode */ @@ -152,16 +181,22 @@ void SKP_Silk_encode_parameters_v4( /* Joint for 12, 16, 24 khz */ SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF ); } +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); + nBytes_contourIndex = nBytes_after - nBytes_before; // bytes just added +#endif /********************/ /* Encode LTP gains */ /********************/ - +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /* PERIndex value */ SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF ); /* Codebook Indices */ - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < psEncC->nb_subfr; k++ ) { SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] ); } @@ -169,8 +204,26 @@ void SKP_Silk_encode_parameters_v4( /* Encode LTP scaling */ /**********************/ SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF ); +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); + nBytes_LTP = nBytes_after - nBytes_before; // bytes just added +#endif } - +#ifdef SAVE_ALL_INTERNAL_DATA + else { + // Unvoiced speech + nBytes_lagIndex = 0; + nBytes_contourIndex = 0; + nBytes_LTP = 0; + } + DEBUG_STORE_DATA( nBytes_lagIndex.dat, &nBytes_lagIndex, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( nBytes_contourIndex.dat, &nBytes_contourIndex, sizeof( SKP_int ) ); + DEBUG_STORE_DATA( nBytes_LTP.dat, &nBytes_LTP, sizeof( SKP_int ) ); +#endif + +#ifdef SAVE_ALL_INTERNAL_DATA + SKP_Silk_range_encoder_get_length( psRC, &nBytes_before ); +#endif /***************/ /* Encode seed */ diff --git a/src/SKP_Silk_encode_pulses.c b/src_common/SKP_Silk_encode_pulses.c similarity index 81% rename from src/SKP_Silk_encode_pulses.c rename to src_common/SKP_Silk_encode_pulses.c index d64900367..82923373f 100644 --- a/src/SKP_Silk_encode_pulses.c +++ b/src_common/SKP_Silk_encode_pulses.c @@ -27,6 +27,24 @@ 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 */ /*********************************************/ @@ -56,7 +74,7 @@ void SKP_Silk_encode_pulses( SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */ const SKP_int sigtype, /* I Sigtype */ const SKP_int QuantOffsetType,/* I QuantOffsetType */ - const SKP_int q[], /* I quantization indices */ + SKP_int8 q[], /* I quantization indices */ const SKP_int frame_length /* I Frame length */ ) { @@ -64,12 +82,13 @@ void SKP_Silk_encode_pulses( SKP_int32 abs_q, minSumBits_Q6, sumBits_Q6; SKP_int abs_pulses[ MAX_FRAME_LENGTH ]; SKP_int sum_pulses[ MAX_NB_SHELL_BLOCKS ]; - SKP_int nRshifts[ MAX_NB_SHELL_BLOCKS ]; + SKP_int nRshifts[ MAX_NB_SHELL_BLOCKS ]; SKP_int pulses_comb[ 8 ]; SKP_int *abs_pulses_ptr; - const SKP_int *pulses_ptr; + const SKP_int8 *pulses_ptr; const SKP_uint16 *cdf_ptr; const SKP_int16 *nBits_ptr; + //extern SKP_int nbits_extra; SKP_memset( pulses_comb, 0, 8 * sizeof( SKP_int ) ); // Fixing Valgrind reported problem @@ -77,10 +96,16 @@ void SKP_Silk_encode_pulses( /* Prepare for shell coding */ /****************************/ /* Calculate number of shell blocks */ - iter = frame_length / SHELL_CODEC_FRAME_LENGTH; - + SKP_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); + iter = SKP_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); + 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)); + } + /* Take the absolute value of the pulses */ - for( i = 0; i < frame_length; i+=4 ) { + 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 ] ); @@ -177,7 +202,7 @@ void SKP_Silk_encode_pulses( pulses_ptr = &q[ i * SHELL_CODEC_FRAME_LENGTH ]; nLS = nRshifts[ i ] - 1; for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { - abs_q = SKP_abs( pulses_ptr[ k ] ); + abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] ); for( j = nLS; j > 0; j-- ) { bit = SKP_RSHIFT( abs_q, j ) & 1; SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF ); @@ -188,8 +213,10 @@ void SKP_Silk_encode_pulses( } } +#if! USE_CELT_PVQ /****************/ /* Encode signs */ /****************/ SKP_Silk_encode_signs( psRC, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex ); +#endif } diff --git a/src/SKP_Silk_gain_quant.c b/src_common/SKP_Silk_gain_quant.c similarity index 71% rename from src/SKP_Silk_gain_quant.c rename to src_common/SKP_Silk_gain_quant.c index 6e1fb4bb4..de89e3e87 100644 --- a/src/SKP_Silk_gain_quant.c +++ b/src_common/SKP_Silk_gain_quant.c @@ -33,15 +33,16 @@ 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[ NB_SUBFR ], /* O gain indices */ - SKP_int32 gain_Q16[ NB_SUBFR ], /* I/O gains (quantized out) */ - SKP_int *prev_ind, /* I/O last index in previous frame */ - const SKP_int conditional /* I first gain is delta coded if 1 */ + SKP_int 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 */ + const SKP_int conditional, /* I first gain is delta coded if 1 */ + const SKP_int nb_subfr /* I number of subframes */ ) { SKP_int k; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { /* Add half of previous quantization error, convert to log scale, scale, floor() */ ind[ k ] = SKP_SMULWB( SCALE_Q16, SKP_Silk_lin2log( gain_Q16[ k ] ) - OFFSET ); @@ -53,12 +54,12 @@ void SKP_Silk_gains_quant( /* Compute delta indices and limit */ if( k == 0 && conditional == 0 ) { /* Full index */ - ind[ k ] = SKP_LIMIT( ind[ k ], 0, N_LEVELS_QGAIN - 1 ); + ind[ k ] = SKP_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 ); ind[ k ] = SKP_max_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANT ); *prev_ind = ind[ k ]; } else { /* Delta index */ - ind[ k ] = SKP_LIMIT( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT ); + ind[ k ] = SKP_LIMIT_int( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT ); /* Accumulate deltas */ *prev_ind += ind[ k ]; /* Shift to make non-negative */ @@ -72,15 +73,16 @@ void SKP_Silk_gains_quant( /* Gains scalar dequantization, uniform on log scale */ void SKP_Silk_gains_dequant( - SKP_int32 gain_Q16[ NB_SUBFR ], /* O quantized gains */ - const SKP_int ind[ NB_SUBFR ], /* I gain indices */ - SKP_int *prev_ind, /* I/O last index in previous frame */ - const SKP_int conditional /* I first gain is delta coded if 1 */ + 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_int conditional, /* I first gain is delta coded if 1 */ + const SKP_int nb_subfr /* I number of subframes */ ) { SKP_int k; - for( k = 0; k < NB_SUBFR; k++ ) { + for( k = 0; k < nb_subfr; k++ ) { if( k == 0 && conditional == 0 ) { *prev_ind = ind[ k ]; } else { diff --git a/src/SKP_Silk_interpolate.c b/src_common/SKP_Silk_interpolate.c similarity index 100% rename from src/SKP_Silk_interpolate.c rename to src_common/SKP_Silk_interpolate.c diff --git a/src/SKP_Silk_main.h b/src_common/SKP_Silk_main.h similarity index 78% rename from src/SKP_Silk_main.h rename to src_common/SKP_Silk_main.h index d5b0a7340..eddcddc72 100644 --- a/src/SKP_Silk_main.h +++ b/src_common/SKP_Silk_main.h @@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_structs.h" #include "SKP_Silk_tables.h" #include "SKP_Silk_PLC.h" +#include "SKP_debug.h" +#include "entenc.h" +#include "entdec.h" #ifdef __cplusplus extern "C" @@ -42,7 +45,7 @@ extern "C" /* Encodes signs of excitation */ void SKP_Silk_encode_signs( SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */ - const SKP_int q[], /* I pulse signal */ + const SKP_int8 q[], /* I pulse signal */ const SKP_int length, /* I length of input */ const SKP_int sigtype, /* I Signal type */ const SKP_int QuantOffsetType, /* I Quantization offset type */ @@ -68,7 +71,7 @@ void SKP_Silk_encode_pulses( SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */ const SKP_int sigtype, /* I Sigtype */ const SKP_int QuantOffsetType, /* I QuantOffsetType */ - const SKP_int q[], /* I quantization indices */ + SKP_int8 q[], /* I quantization indices */ const SKP_int frame_length /* I Frame length */ ); @@ -95,6 +98,13 @@ void SKP_Silk_range_encoder( const SKP_uint16 prob[] /* I cumulative density functions */ ); +/* Range encoder for one symbol, with uniform PDF*/ +void SKP_Silk_range_encode_uniform( + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int data, /* I uncompressed data */ + const SKP_int N /* I number of possible outcomes */ +); + /* Range encoder for multiple symbols */ void SKP_Silk_range_encoder_multi( SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ @@ -111,6 +121,13 @@ void SKP_Silk_range_decoder( SKP_int probIx /* I initial (middle) entry of cdf */ ); +/* Range decoder for one symbol, with uniform PDF*/ +void SKP_Silk_range_decode_uniform( + SKP_int data[], /* O uncompressed data */ + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int N /* I number of possible outcomes */ +); + /* Range decoder for multiple symbols */ void SKP_Silk_range_decoder_multi( SKP_int data[], /* O uncompressed data [nSymbols] */ @@ -133,14 +150,15 @@ void SKP_Silk_range_dec_init( ); /* Determine length of bitstream */ -SKP_int SKP_Silk_range_coder_get_length( /* O returns number of BITS in stream */ - const SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ +SKP_int SKP_Silk_range_encoder_get_length( /* O returns number of BITS in stream */ + SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ SKP_int *nBytes /* O number of BYTES in stream */ ); -/* Write decodable stream to buffer, and determine its length */ -void SKP_Silk_range_enc_wrap_up( - SKP_Silk_range_coder_state *psRC /* I/O compressed data structure */ +/* Determine length of bitstream */ +SKP_int SKP_Silk_range_decoder_get_length( /* O returns number of BITS in stream */ + SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ + SKP_int *nBytes /* O number of BYTES in stream */ ); /* Check that any remaining bits in the last byte are set to 1 */ @@ -150,18 +168,20 @@ void SKP_Silk_range_coder_check_after_decoding( /* Gain scalar quantization with hysteresis, uniform on log scale */ void SKP_Silk_gains_quant( - SKP_int ind[ NB_SUBFR ], /* O gain indices */ - SKP_int32 gain_Q16[ NB_SUBFR ], /* I/O gains (quantized out) */ - SKP_int *prev_ind, /* I/O last index in previous frame */ - const SKP_int conditional /* I first gain is delta coded if 1 */ + SKP_int 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 */ + const SKP_int conditional, /* I first gain is delta coded if 1 */ + const SKP_int nb_subfr /* I number of subframes */ ); /* Gains scalar dequantization, uniform on log scale */ void SKP_Silk_gains_dequant( - SKP_int32 gain_Q16[ NB_SUBFR ], /* O quantized gains */ - const SKP_int ind[ NB_SUBFR ], /* I gain indices */ - SKP_int *prev_ind, /* I/O last index in previous frame */ - const SKP_int conditional /* I first gain is delta coded if 1 */ + 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_int conditional, /* I first gain is delta coded if 1 */ + const SKP_int nb_subfr /* I number of subframes */ ); /* Convert NLSF parameters to stable AR prediction filter coefficients */ @@ -188,15 +208,15 @@ void SKP_Silk_NSQ( SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ const SKP_int16 x[], /* I prefiltered input signal */ - SKP_int q[], /* O quantized qulse signal */ + SKP_int8 q[], /* O quantized qulse signal */ const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I Long term prediction coefficients */ - const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */ - const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ 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 Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ); @@ -207,15 +227,15 @@ void SKP_Silk_NSQ_del_dec( SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */ SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */ const SKP_int16 x[], /* I Prefiltered input signal */ - SKP_int q[], /* O Quantized pulse signal */ + SKP_int8 q[], /* O Quantized pulse signal */ const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */ const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */ - const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I LT prediction coefs */ - const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */ - const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */ - const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */ - const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */ - const SKP_int32 Gains_Q16[ 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 Lambda_Q10, /* I */ const SKP_int LTP_scale_Q14 /* I LTP state scaling */ ); @@ -238,11 +258,11 @@ void SKP_Silk_VAD_GetNoiseLevels( SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Return value, 0 if success */ SKP_Silk_VAD_state *psSilk_VAD, /* I/O Silk VAD state */ SKP_int *pSA_Q8, /* O Speech activity level in Q8 */ - SKP_int *pSNR_dB_Q7, /* O SNR for current frame in Q7 */ SKP_int pQuality_Q15[ VAD_N_BANDS ], /* O Smoothed SNR for each band */ SKP_int *pTilt_Q15, /* O current frame's frequency tilt */ const SKP_int16 pIn[], /* I PCM input [framelength] */ - const SKP_int framelength /* I Input frame length */ + const SKP_int framelength, /* I Input frame length */ + const SKP_int fs_kHz /* I Input frame sample frequency */ ); /* Detect signal in 8 - 12 khz range */ @@ -281,8 +301,9 @@ SKP_int SKP_Silk_init_decoder( /* Set decoder sampling rate */ void SKP_Silk_decoder_set_fs( - SKP_Silk_decoder_state *psDec, /* I/O Decoder state pointer */ - SKP_int fs_kHz /* I Sampling frequency (kHz) */ + SKP_Silk_decoder_state *psDec, /* I/O Decoder state pointer */ + SKP_int fs_kHz, /* I Sampling frequency (kHz) */ + SKP_int nb_subfr /* I Number of subframes */ ); /****************/ @@ -298,14 +319,6 @@ SKP_int SKP_Silk_decode_frame( SKP_int *decBytes /* O Used bytes to decode this frame */ ); -/* 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 */ - SKP_int q[], /* O Excitation signal */ - const SKP_int fullDecoding /* I Flag to tell if only arithmetic decoding */ -); - /* Decode indices from payload v4 Bitstream */ void SKP_Silk_decode_indices_v4( SKP_Silk_decoder_state *psDec /* I/O State */ @@ -364,14 +377,6 @@ void SKP_Silk_CNG( SKP_int length /* I Length of residual */ ); -/* Encoding of various parameters */ -void SKP_Silk_encode_parameters( - SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ - SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */ - SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */ - const SKP_int *q /* I Quantization indices */ -); - /* Encoding of various parameters */ void SKP_Silk_encode_parameters_v4( SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */ @@ -395,7 +400,7 @@ void SKP_Silk_LBRR_reset( /* 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_int q[] /* I Pulse signal */ + SKP_int8 q[] /* I Pulse signal */ ); #ifdef __cplusplus diff --git a/src/SKP_Silk_perceptual_parameters_FIX.h b/src_common/SKP_Silk_perceptual_parameters.h similarity index 60% rename from src/SKP_Silk_perceptual_parameters_FIX.h rename to src_common/SKP_Silk_perceptual_parameters.h index dfa7c4537..1fcf718aa 100644 --- a/src/SKP_Silk_perceptual_parameters_FIX.h +++ b/src_common/SKP_Silk_perceptual_parameters.h @@ -25,8 +25,8 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -#ifndef SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H -#define SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H +#ifndef SKP_SILK_PERCEPTUAL_PARAMETERS_H +#define SKP_SILK_PERCEPTUAL_PARAMETERS_H #ifdef __cplusplus extern "C" @@ -34,88 +34,82 @@ extern "C" #endif /* reduction in coding SNR during low speech activity */ -#define BG_SNR_DECR_dB_Q7 (3<<7) +#define BG_SNR_DECR_dB 4.0f /* factor for reducing quantization noise during voiced speech */ -#define HARM_SNR_INCR_dB_Q7 (2<<7) +#define HARM_SNR_INCR_dB 2.0f /* factor for reducing quantization noise for unvoiced sparse signals */ -#define SPARSE_SNR_INCR_dB_Q7 (2<<7) +#define SPARSE_SNR_INCR_dB 2.0f /* threshold for sparseness measure above which to use lower quantization offset during unvoiced */ -#define SPARSENESS_THRESHOLD_QNT_OFFSET_Q8 (3<<6) // 0.75 +#define SPARSENESS_THRESHOLD_QNT_OFFSET 0.75f /* noise shaping filter chirp factor */ -#define BANDWIDTH_EXPANSION_Q16 61604 // 0.94 +#define BANDWIDTH_EXPANSION 0.95f /* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */ -#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA_Q16 655 //0.01f +#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA 0.01f -/* factor to reduce all bandwidth expansion coefficients for super wideband, relative to wideband */ -#define SWB_BANDWIDTH_EXPANSION_REDUCTION_Q16 (1<<16) // 1.0f; +/* factor to reduce all bandwdith expansion coefficients for super wideband, relative to wideband */ +#define SWB_BANDWIDTH_EXPANSION_REDUCTION 1.0f /* gain reduction for fricatives */ -#define DE_ESSER_COEF_SWB_dB_Q7 (2 << 7) -#define DE_ESSER_COEF_WB_dB_Q7 (1 << 7) - +#define DE_ESSER_COEF_SWB_dB 2.0f +#define DE_ESSER_COEF_WB_dB 1.0f /* extra harmonic boosting (signal shaping) at low bitrates */ -#define LOW_RATE_HARMONIC_BOOST_Q16 6554 // 0.1 +#define LOW_RATE_HARMONIC_BOOST 0.1f /* extra harmonic boosting (signal shaping) for noisy input signals */ -#define LOW_INPUT_QUALITY_HARMONIC_BOOST_Q16 6554 // 0.1 +#define LOW_INPUT_QUALITY_HARMONIC_BOOST 0.1f /* harmonic noise shaping */ -#define HARMONIC_SHAPING_Q16 19661 // 0.3 +#define HARMONIC_SHAPING 0.3f /* extra harmonic noise shaping for high bitrates or noisy input */ -#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING_Q16 13107 // 0.2 +#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING 0.2f /* parameter for shaping noise towards higher frequencies */ -#define HP_NOISE_COEF_Q16 19661 // 0.3 +#define HP_NOISE_COEF 0.3f /* parameter for shaping noise extra towards higher frequencies during voiced speech */ -#define HARM_HP_NOISE_COEF_Q24 7549747 // 0.45 +#define HARM_HP_NOISE_COEF 0.4f /* parameter for applying a high-pass tilt to the input signal */ -#define INPUT_TILT_Q26 2684355 // 0.04 +#define INPUT_TILT 0.04f /* parameter for extra high-pass tilt to the input signal at high rates */ -#define HIGH_RATE_INPUT_TILT_Q12 246 // 0.06 +#define HIGH_RATE_INPUT_TILT 0.04f /* parameter for reducing noise at the very low frequencies */ -#define LOW_FREQ_SHAPING_Q0 3 +#define LOW_FREQ_SHAPING 3.0f /* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */ -#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR_Q1 1 // 0.5_Q0 +#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR 0.5f /* fraction added to first autocorrelation value */ -#define SHAPE_WHITE_NOISE_FRACTION_Q20 50 // 50_Q20 = 4.7684e-5 +#define SHAPE_WHITE_NOISE_FRACTION 3.8147e-5f /* fraction of first autocorrelation value added to residual energy value; limits prediction gain */ -#define SHAPE_MIN_ENERGY_RATIO_Q24 256 +#define SHAPE_MIN_ENERGY_RATIO 1.526e-5f // 1.526e-5 = 1/65536 /* noise floor to put a low limit on the quantization step size */ -#define NOISE_FLOOR_dB_Q7 (4 << 7) +#define NOISE_FLOOR_dB 4.0f /* noise floor relative to active speech gain level */ -#define RELATIVE_MIN_GAIN_dB_Q7 -6400 // -50_Q0 = -6400_Q7 +#define RELATIVE_MIN_GAIN_dB -50.0f /* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */ -#define GAIN_SMOOTHING_COEF_Q10 1 // 1e-3_Q0 = 1.024_Q10 +#define GAIN_SMOOTHING_COEF 1e-3f /* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */ -#define SUBFR_SMTH_COEF_Q16 26214 // 0.4 - -#define NOISE_GAIN_VL_Q16 7864 -#define NOISE_GAIN_VH_Q16 7864 -#define NOISE_GAIN_UVL_Q16 6554 -#define NOISE_GAIN_UVH_Q16 9830 +#define SUBFR_SMTH_COEF 0.4f #ifdef __cplusplus } #endif -#endif //SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H +#endif diff --git a/src/SKP_Silk_pulses_to_bytes.c b/src_common/SKP_Silk_pulses_to_bytes.c similarity index 85% rename from src/SKP_Silk_pulses_to_bytes.c rename to src_common/SKP_Silk_pulses_to_bytes.c index 85c5e7e2d..1138e87ff 100644 --- a/src/SKP_Silk_pulses_to_bytes.c +++ b/src_common/SKP_Silk_pulses_to_bytes.c @@ -35,15 +35,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* 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 // ToDo better training with +#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_int q[] /* I Pulse signal */ + SKP_int8 q[] /* I Pulse signal */ ) { - SKP_int i, j, iter, *q_ptr; + 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; @@ -54,10 +55,10 @@ SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes for( j = 0; j < iter; j++ ) { sum_abs_val = 0; for(i = 0; i < SHELL_CODEC_FRAME_LENGTH; i+=4){ - sum_abs_val += SKP_abs( q_ptr[ i + 0 ] ); - sum_abs_val += SKP_abs( q_ptr[ i + 1 ] ); - sum_abs_val += SKP_abs( q_ptr[ i + 2 ] ); - sum_abs_val += SKP_abs( q_ptr[ i + 3 ] ); + 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 @@ -65,6 +66,9 @@ SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes 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 */ diff --git a/src_common/SKP_Silk_range_coder.c b/src_common/SKP_Silk_range_coder.c new file mode 100644 index 000000000..a9dcc7ed5 --- /dev/null +++ b/src_common/SKP_Silk_range_coder.c @@ -0,0 +1,290 @@ +/*********************************************************************** +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. +***********************************************************************/ + +#include "SKP_Silk_main.h" + +#define MAX_SIZE 10000 + +/* Range encoder for one symbol */ +void SKP_Silk_range_encoder( + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int data, /* I uncompressed data */ + const SKP_uint16 prob[] /* I cumulative density functions */ +) +{ + SKP_uint32 low_Q16, high_Q16; + + if( psRC->error ) { + return; + } + low_Q16 = prob[ data ]; + high_Q16 = prob[ data + 1 ]; + +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( enc_l.dat, &low_Q16, sizeof(SKP_uint32) ); + DEBUG_STORE_DATA( enc_h.dat, &high_Q16, sizeof(SKP_uint32) ); + DEBUG_STORE_DATA( enc.dat, &data, sizeof(SKP_int) ); +#endif + + if( prob[ 2 ] == 65535 ) { + /* Instead of detection, we could add a separate function and call when we know that input is a bit */ + ec_enc_bit_prob( &psRC->range_enc_celt_state, data, 65536 - prob[ 1 ] ); + } else { + ec_encode_bin( &psRC->range_enc_celt_state, low_Q16, high_Q16, 16 ); + } +} + +/* Range encoder for one symbol, with uniform PDF*/ +void SKP_Silk_range_encode_uniform( + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int data, /* I uncompressed data */ + const SKP_int N /* I number of possible outcomes */ +) +{ + SKP_int i; + SKP_uint16 delta, prob[ MAX_SIZE + 1 ]; + + SKP_assert( N < MAX_SIZE ); + + delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N ); + prob[ 0 ] = 0; + for( i = 0; i < N - 1; i++ ) { + prob[ i + 1 ] = prob[ i ] + delta; + } + prob[ N ] = 65535; + + SKP_Silk_range_encoder( psRC, data, prob ); +} + +/* Range encoder for multiple symbols */ +void SKP_Silk_range_encoder_multi( + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int data[], /* I uncompressed data [nSymbols] */ + const SKP_uint16 * const prob[], /* I cumulative density functions */ + const SKP_int nSymbols /* I number of data symbols */ +) +{ + SKP_int k; + for( k = 0; k < nSymbols; k++ ) { + SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] ); + } +} + +/* Range decoder for one symbol */ +void SKP_Silk_range_decoder( + SKP_int data[], /* O uncompressed data */ + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_uint16 prob[], /* I cumulative density function */ + SKP_int probIx /* I initial (middle) entry of cdf */ +) +{ + SKP_uint32 low_Q16, high_Q16; + + SKP_uint32 low_Q16_returned; + SKP_int temp; + + if( psRC->error ) { + /* Set output to zero */ + *data = 0; + return; + } + + if( prob[ 2 ] == 65535 ) { + /* Instead of detection, we could add a separate function and call when we know that output is a bit */ + *data = ec_dec_bit_prob( &psRC->range_dec_celt_state, 65536 - prob[ 1 ] ); + } else { + low_Q16_returned = ec_decode_bin( &psRC->range_dec_celt_state, 16 ); + } + + /* OPTIMIZE ME WITH BI-SECTION */ + if( prob[ 2 ] != 65535 ) { +#if 1 + temp = 0; + while( low_Q16_returned >= prob[ ++temp ] ) {} + *data = temp - 1; +#else + temp = probIx; + if( low_Q16_returned >= prob[ temp ] ){ + while( low_Q16_returned >= prob[ temp ] ) { + temp++; + } + temp = temp - 1; + } else { + /* search down */ + while( low_Q16_returned < prob[ temp ] ) { + temp--; + } + } + *data = temp; +#endif + + low_Q16 = prob[ *data ]; + high_Q16 = prob[ *data + 1 ]; + +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( dec_lr.dat, &low_Q16_returned, sizeof( SKP_uint32 ) ); + DEBUG_STORE_DATA( dec_l.dat, &low_Q16, sizeof( SKP_uint32 ) ); + DEBUG_STORE_DATA( dec_h.dat, &high_Q16, sizeof( SKP_uint32 ) ); +#endif + ec_dec_update( &psRC->range_dec_celt_state, low_Q16, high_Q16,( 1 << 16 ) ); + } +#ifdef SAVE_ALL_INTERNAL_DATA + DEBUG_STORE_DATA( dec.dat, data, sizeof( SKP_int ) ); +#endif +} + +/* Range decoder for one symbol, with uniform PDF*/ +void SKP_Silk_range_decode_uniform( + SKP_int data[], /* O uncompressed data */ + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_int N /* I number of possible outcomes */ +) +{ + SKP_int i; + SKP_uint16 delta, prob[ MAX_SIZE + 1 ]; + + SKP_assert( N < MAX_SIZE ); + + delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N ); + prob[ 0 ] = 0; + for( i = 0; i < N - 1; i++ ) { + prob[ i + 1 ] = prob[ i ] + delta; + } + prob[ N ] = 65535; + + SKP_Silk_range_decoder( data, psRC, prob, ( N >> 1 ) ); +} + +/* Range decoder for multiple symbols */ +void SKP_Silk_range_decoder_multi( + SKP_int data[], /* O uncompressed data [nSymbols] */ + SKP_Silk_range_coder_state *psRC, /* I/O compressor data structure */ + const SKP_uint16 * const prob[], /* I cumulative density functions */ + const SKP_int probStartIx[], /* I initial (middle) entries of cdfs [nSymbols] */ + const SKP_int nSymbols /* I number of data symbols */ +) +{ + SKP_int k; + for( k = 0; k < nSymbols; k++ ) { + SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] ); + } +} + +/* Initialize range encoder */ +void SKP_Silk_range_enc_init( + SKP_Silk_range_coder_state *psRC /* O compressor data structure */ +) +{ + psRC->error = 0; +} + +/* Initialize range decoder */ +void SKP_Silk_range_dec_init( + SKP_Silk_range_coder_state *psRC, /* O compressor data structure */ + const SKP_uint8 buffer[], /* I buffer for compressed data [bufferLength] */ + const SKP_int32 bufferLength /* I buffer length (in bytes) */ +) +{ + /* check input */ + if( bufferLength > MAX_ARITHM_BYTES ) { + psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG; + return; + } + /* Initialize structure */ + /* Copy to internal buffer */ + SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); + psRC->bufferLength = bufferLength; + psRC->bufferIx = 0; + psRC->base_Q32 = + SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 0 ], 24 ) | + SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 1 ], 16 ) | + SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 2 ], 8 ) | + ( SKP_uint32 )buffer[ 3 ]; + psRC->range_Q16 = 0x0000FFFF; + psRC->error = 0; +} + +/* Determine length of bitstream */ +SKP_int SKP_Silk_range_encoder_get_length( /* O returns number of BITS in stream */ + SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ + SKP_int *nBytes /* O number of BYTES in stream */ +) +{ + SKP_int nBits; + + /* Get number of bits in bitstream */ + nBits = ec_enc_tell( &psRC->range_enc_celt_state, 0 ); + + /* Round up to an integer number of bytes */ + *nBytes = SKP_RSHIFT( nBits + 7, 3 ); + + /* Return number of bits in bitstream */ + return nBits; +} + +/* Determine length of bitstream */ +SKP_int SKP_Silk_range_decoder_get_length( /* O returns number of BITS in stream */ + SKP_Silk_range_coder_state *psRC, /* I compressed data structure */ + SKP_int *nBytes /* O number of BYTES in stream */ +) +{ + SKP_int nBits; + + /* Get number of bits in bitstream */ + nBits = ec_dec_tell( &psRC->range_dec_celt_state, 0 ); + + /* Round up to an integer number of bytes */ + *nBytes = SKP_RSHIFT( nBits + 7, 3 ); + + /* Return number of bits in bitstream */ + return nBits; +} + +/* Check that any remaining bits in the last byte are set to 1 */ +void SKP_Silk_range_coder_check_after_decoding( + SKP_Silk_range_coder_state *psRC /* I/O compressed data structure */ +) +{ + SKP_int bits_in_stream, nBytes, mask; + + bits_in_stream = SKP_Silk_range_decoder_get_length( psRC, &nBytes ); + + /* Make sure not to read beyond buffer */ + if( nBytes - 1 >= psRC->range_dec_celt_state.buf->storage ) { + psRC->error = RANGE_CODER_DECODER_CHECK_FAILED; + return; + } + + /* Test any remaining bits in last byte */ + if( bits_in_stream & 7 ) { + mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 ); + if( ( psRC->range_dec_celt_state.buf->buf[ nBytes - 1 ] & mask ) != mask ) { + psRC->error = RANGE_CODER_DECODER_CHECK_FAILED; + return; + } + } +} diff --git a/src/SKP_Silk_shell_coder.c b/src_common/SKP_Silk_shell_coder.c similarity index 100% rename from src/SKP_Silk_shell_coder.c rename to src_common/SKP_Silk_shell_coder.c diff --git a/src/SKP_Silk_structs.h b/src_common/SKP_Silk_structs.h similarity index 84% rename from src/SKP_Silk_structs.h rename to src_common/SKP_Silk_structs.h index ce96e2202..cd6ed253a 100644 --- a/src/SKP_Silk_structs.h +++ b/src_common/SKP_Silk_structs.h @@ -31,6 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_typedef.h" #include "SKP_Silk_SigProc_FIX.h" #include "SKP_Silk_define.h" +#include "entenc.h" +#include "entdec.h" #ifdef __cplusplus extern "C" @@ -44,7 +46,8 @@ extern "C" 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 / NB_SUBFR + MAX_LPC_ORDER ]; + SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + MAX_LPC_ORDER ]; + SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; SKP_int32 sLF_AR_shp_Q12; SKP_int lagPrev; SKP_int sLTP_buf_idx; @@ -87,6 +90,9 @@ typedef struct { SKP_uint32 range_Q16; SKP_int32 error; SKP_uint8 buffer[ MAX_ARITHM_BYTES ]; /* Buffer containing payload */ + /* The CELT entropy encoder + decoder */ + ec_enc range_enc_celt_state; + ec_dec range_dec_celt_state; } SKP_Silk_range_coder_state; /* Input frequency range detection struct */ @@ -147,10 +153,15 @@ typedef struct { SKP_int typeOffsetPrev; /* Previous signal type and quantization offset */ SKP_int prevLag; SKP_int prev_lagIndex; - SKP_int fs_kHz; /* Sampling frequency (kHz) */ + 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 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) */ + SKP_int ltp_mem_length; /* Length of LTP memory */ SKP_int la_pitch; /* Look-ahead for pitch analysis (samples) */ SKP_int la_shape; /* Look-ahead for noise shape analysis (samples) */ SKP_int32 TargetRate_bps; /* Target bitrate (bps) */ @@ -182,28 +193,16 @@ typedef struct { /* Struct for Inband LBRR */ SKP_SILK_LBRR_struct LBRR_buffer[ MAX_LBRR_DELAY ]; SKP_int oldest_LBRR_idx; + 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 */ /* Bitrate control */ - SKP_int32 bitrateDiff; /* accumulated diff. between the target bitrate and the SWB/WB limits */ + 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 */ -#if LOW_COMPLEXITY_ONLY - /* state for downsampling from 24 to 16 kHz in low complexity mode */ - SKP_int16 resample24To16state[ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; -#else - SKP_int32 resample24To16state[ 11 ]; /* state for downsampling from 24 to 16 kHz */ -#endif - SKP_int32 resample24To12state[ 6 ]; /* state for downsampling from 24 to 12 kHz */ - SKP_int32 resample24To8state[ 7 ]; /* state for downsampling from 24 to 8 kHz */ - SKP_int32 resample16To12state[ 15 ]; /* state for downsampling from 16 to 12 kHz */ - SKP_int32 resample16To8state[ 6 ]; /* state for downsampling from 16 to 8 kHz */ -#if LOW_COMPLEXITY_ONLY - /* state for downsampling from 12 to 8 kHz in low complexity mode */ - SKP_int16 resample12To8state[ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ]; -#else - SKP_int32 resample12To8state[ 11 ]; /* state for downsampling from 12 to 8 kHz */ -#endif + SKP_Silk_resampler_state_struct resampler_state; /* DTX */ SKP_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */ @@ -215,15 +214,11 @@ typedef struct { SKP_Silk_detect_SWB_state sSWBdetect; - /********************************************/ - /* Buffers etc used by the new bitstream V4 */ - /********************************************/ - SKP_int q[ MAX_FRAME_LENGTH * MAX_FRAMES_PER_PACKET ]; /* pulse signal buffer */ - SKP_int q_LBRR[ MAX_FRAME_LENGTH * MAX_FRAMES_PER_PACKET ]; /* pulse signal buffer */ + /* 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 sigtype[ MAX_FRAMES_PER_PACKET ]; SKP_int QuantOffsetType[ MAX_FRAMES_PER_PACKET ]; - SKP_int extension_layer; /* Add extension layer */ - SKP_int bitstream_v; /* Holds bitstream version */ } SKP_Silk_encoder_state; @@ -235,10 +230,11 @@ typedef struct { SKP_int lagIndex; SKP_int contourIndex; SKP_int PERIndex; - SKP_int LTPIndex[ NB_SUBFR ]; + 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[ NB_SUBFR ]; + SKP_int GainsIndices[ MAX_NB_SUBFR ]; + SKP_int warping_Q16; SKP_int32 Seed; SKP_int LTP_scaleIndex; SKP_int RateLevelIndex; @@ -246,13 +242,14 @@ typedef struct { SKP_int sigtype; /* Prediction and coding parameters */ - SKP_int pitchL[ NB_SUBFR ]; + 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_int pitchL[ MAX_NB_SUBFR ]; /* Pitch lag per 5 ms for last 20 ms */ SKP_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */ SKP_int16 LTPCoef_Q14[ LTP_ORDER ]; /* LTP coeficients to use for voiced concealment */ SKP_int16 prevLPC_Q12[ MAX_LPC_ORDER ]; @@ -262,7 +259,7 @@ typedef struct { SKP_int32 conc_energy; SKP_int conc_energy_shift; SKP_int16 prevLTP_scale_Q14; - SKP_int32 prevGain_Q16[ NB_SUBFR ]; + SKP_int32 prevGain_Q16[ MAX_NB_SUBFR ]; SKP_int fs_kHz; } SKP_Silk_PLC_struct; @@ -283,7 +280,7 @@ 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 / NB_SUBFR + MAX_LPC_ORDER ]; + SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + MAX_LPC_ORDER ]; SKP_int32 exc_Q10[ MAX_FRAME_LENGTH ]; SKP_int32 res_Q10[ MAX_FRAME_LENGTH ]; SKP_int16 outBuf[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for output signal */ @@ -296,8 +293,11 @@ typedef struct { const SKP_int16 *HP_A; /* HP filter AR coefficients */ const SKP_int16 *HP_B; /* HP filter MA coefficients */ SKP_int fs_kHz; /* Sampling frequency in kHz */ + SKP_int32 prev_API_sampleRate; /* Previous API sample frequency (Hz) */ + 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) */ + SKP_int ltp_mem_length; /* Length of LTP memory */ SKP_int LPC_order; /* LPC order */ SKP_int prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */ SKP_int first_frame_after_reset; /* Flag for deactivating NLSF interp. and fluc. reduction after resets */ @@ -309,20 +309,20 @@ typedef struct { SKP_int moreInternalDecoderFrames; SKP_int FrameTermination; - SKP_int32 resampleState[ 15 ]; + SKP_Silk_resampler_state_struct resampler_state; const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */ SKP_int sigtype[ MAX_FRAMES_PER_PACKET ]; SKP_int QuantOffsetType[ MAX_FRAMES_PER_PACKET ]; - SKP_int GainsIndices[ MAX_FRAMES_PER_PACKET ][ NB_SUBFR ]; - SKP_int GainsIndices_EnhLayer[ MAX_FRAMES_PER_PACKET ][ NB_SUBFR ]; + 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 ][ NB_SUBFR ]; + 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 ]; SKP_int vadFlagBuf[ MAX_FRAMES_PER_PACKET ]; @@ -336,21 +336,11 @@ typedef struct { SKP_Silk_CNG_struct sCNG; /* Stuff used for PLC */ - SKP_Silk_PLC_struct sPLC; SKP_int lossCnt; SKP_int prev_sigtype; /* Previous sigtype */ -#ifdef USE_INTERPOLATION_PLC - SKP_int16 prevQuant[ MAX_FRAME_LENGTH ]; - SKP_int prevPitchL[ NB_SUBFR ]; /* Previous Lags used */ - SKP_int16 prevLTPCoef_Q14[ NB_SUBFR * LTP_ORDER ]; /* Previous LTCoefs used */ - SKP_int16 prevAR_Q12[ MAX_LPC_ORDER ]; - SKP_int interpolDistance; /* Number of frames between old and new recieved packet */ -#endif - - + SKP_Silk_PLC_struct sPLC; - SKP_int bitstream_v; /* Holds bitstream version */ } SKP_Silk_decoder_state; /************************/ @@ -358,12 +348,12 @@ typedef struct { /************************/ typedef struct { /* prediction and coding parameters */ - SKP_int pitchL[ NB_SUBFR ]; - SKP_int32 Gains_Q16[ NB_SUBFR ]; + 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_array_of_int16_4_byte_aligned( PredCoef_Q12[ 2 ], MAX_LPC_ORDER ); - SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ]; + SKP_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; SKP_int LTP_scale_Q14; /* quantization indices */ diff --git a/src/SKP_Silk_tables.h b/src_common/SKP_Silk_tables.h similarity index 95% rename from src/SKP_Silk_tables.h rename to src_common/SKP_Silk_tables.h index b23b8d95f..404820f5f 100644 --- a/src/SKP_Silk_tables.h +++ b/src_common/SKP_Silk_tables.h @@ -83,7 +83,7 @@ extern const SKP_uint16 SKP_Silk_shell_code_table_offsets[ 19 ]; extern const SKP_uint16 SKP_Silk_lsb_CDF[ 3 ]; /* 3 */ -extern const SKP_uint16 SKP_Silk_sign_CDF[ 36 ][ 3 ]; /* 108 */ +extern const SKP_uint16 SKP_Silk_sign_CDF[ 36 ]; /* 36 */ extern const SKP_uint16 SKP_Silk_LTP_per_index_CDF[ 4 ]; /* 4 */ extern const SKP_int SKP_Silk_LTP_per_index_CDF_offset; @@ -104,6 +104,9 @@ extern const SKP_int SKP_Silk_SamplingRates_table[ 4 ]; extern const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ]; /* 5 */ extern const SKP_int SKP_Silk_SamplingRates_offset; +extern const SKP_uint16 SKP_Silk_NbSubframes_CDF[ 3 ]; /* 3 */ +extern const SKP_int SKP_Silk_NbSubframes_offset; + extern const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ]; extern const SKP_int SKP_Silk_NLSF_interpolation_factor_offset; @@ -145,9 +148,6 @@ extern const SKP_int16 SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ]; extern const SKP_int16 SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ]; /* 3 */ /* Table for frame termination indication */ -extern const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ]; -extern const SKP_int SKP_Silk_FrameTermination_offset; - extern const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ]; extern const SKP_int SKP_Silk_FrameTermination_v4_offset; diff --git a/src/SKP_Silk_tables_LTP.c b/src_common/SKP_Silk_tables_LTP.c similarity index 100% rename from src/SKP_Silk_tables_LTP.c rename to src_common/SKP_Silk_tables_LTP.c diff --git a/src/SKP_Silk_tables_NLSF_CB0_10.c b/src_common/SKP_Silk_tables_NLSF_CB0_10.c similarity index 97% rename from src/SKP_Silk_tables_NLSF_CB0_10.c rename to src_common/SKP_Silk_tables_NLSF_CB0_10.c index 3f9cadbf2..3404a5a9e 100644 --- a/src/SKP_Silk_tables_NLSF_CB0_10.c +++ b/src_common/SKP_Silk_tables_NLSF_CB0_10.c @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /**********************************************/ /* This file has been automatically generated */ /* */ -/* ROM usage: 138+1331 Words */ +/* ROM usage: 0.29 + 2.66 kB */ /**********************************************/ #include "SKP_Silk_structs.h" diff --git a/src/SKP_Silk_tables_NLSF_CB0_10.h b/src_common/SKP_Silk_tables_NLSF_CB0_10.h similarity index 100% rename from src/SKP_Silk_tables_NLSF_CB0_10.h rename to src_common/SKP_Silk_tables_NLSF_CB0_10.h diff --git a/src/SKP_Silk_tables_NLSF_CB0_16.c b/src_common/SKP_Silk_tables_NLSF_CB0_16.c similarity index 98% rename from src/SKP_Silk_tables_NLSF_CB0_16.c rename to src_common/SKP_Silk_tables_NLSF_CB0_16.c index 895b34625..2ff1c82c0 100644 --- a/src/SKP_Silk_tables_NLSF_CB0_16.c +++ b/src_common/SKP_Silk_tables_NLSF_CB0_16.c @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /**********************************************/ /* This file has been automatically generated */ /* */ -/* ROM usage: 246+3689 Words */ +/* ROM usage: 0.51 + 7.38 kB */ /**********************************************/ #include "SKP_Silk_structs.h" diff --git a/src/SKP_Silk_tables_NLSF_CB0_16.h b/src_common/SKP_Silk_tables_NLSF_CB0_16.h similarity index 100% rename from src/SKP_Silk_tables_NLSF_CB0_16.h rename to src_common/SKP_Silk_tables_NLSF_CB0_16.h diff --git a/src/SKP_Silk_tables_NLSF_CB1_10.c b/src_common/SKP_Silk_tables_NLSF_CB1_10.c similarity index 96% rename from src/SKP_Silk_tables_NLSF_CB1_10.c rename to src_common/SKP_Silk_tables_NLSF_CB1_10.c index 8c9abe409..2682f37ce 100644 --- a/src/SKP_Silk_tables_NLSF_CB1_10.c +++ b/src_common/SKP_Silk_tables_NLSF_CB1_10.c @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /**********************************************/ /* This file has been automatically generated */ /* */ -/* ROM usage: 90+803 Words */ +/* ROM usage: 0.19 + 1.61 kB */ /**********************************************/ #include "SKP_Silk_structs.h" diff --git a/src/SKP_Silk_tables_NLSF_CB1_10.h b/src_common/SKP_Silk_tables_NLSF_CB1_10.h similarity index 100% rename from src/SKP_Silk_tables_NLSF_CB1_10.h rename to src_common/SKP_Silk_tables_NLSF_CB1_10.h diff --git a/src/SKP_Silk_tables_NLSF_CB1_16.c b/src_common/SKP_Silk_tables_NLSF_CB1_16.c similarity index 98% rename from src/SKP_Silk_tables_NLSF_CB1_16.c rename to src_common/SKP_Silk_tables_NLSF_CB1_16.c index 0780b2d04..b7415b537 100644 --- a/src/SKP_Silk_tables_NLSF_CB1_16.c +++ b/src_common/SKP_Silk_tables_NLSF_CB1_16.c @@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /**********************************************/ /* This file has been automatically generated */ /* */ -/* ROM usage: 134+1785 Words */ +/* ROM usage: 0.29 + 3.57 kB */ /**********************************************/ #include "SKP_Silk_structs.h" diff --git a/src/SKP_Silk_tables_NLSF_CB1_16.h b/src_common/SKP_Silk_tables_NLSF_CB1_16.h similarity index 100% rename from src/SKP_Silk_tables_NLSF_CB1_16.h rename to src_common/SKP_Silk_tables_NLSF_CB1_16.h diff --git a/src/SKP_Silk_tables_gain.c b/src_common/SKP_Silk_tables_gain.c similarity index 100% rename from src/SKP_Silk_tables_gain.c rename to src_common/SKP_Silk_tables_gain.c diff --git a/src/SKP_Silk_tables_other.c b/src_common/SKP_Silk_tables_other.c similarity index 95% rename from src/SKP_Silk_tables_other.c rename to src_common/SKP_Silk_tables_other.c index 48f57cbfd..b29c8dc96 100644 --- a/src/SKP_Silk_tables_other.c +++ b/src_common/SKP_Silk_tables_other.c @@ -96,14 +96,15 @@ const SKP_int SKP_Silk_SamplingRates_table[ 4 ] = {8, 12, 16, 24}; const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ] = {0, 16000, 32000, 48000, 65535}; const SKP_int SKP_Silk_SamplingRates_offset = 2; +/* tables for number of subframes */ +const SKP_uint16 SKP_Silk_NbSubframes_CDF[ 3 ] = {0, 40000, 65535}; +const SKP_int SKP_Silk_NbSubframes_offset = 1; + /* tables for NLSF interpolation factor */ const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ] = {0, 3706, 8703, 19226, 30926, 65535}; const SKP_int SKP_Silk_NLSF_interpolation_factor_offset = 4; /* Table for frame termination indication */ -const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ] = {0, 20000, 45000, 56000, 65535}; -const SKP_int SKP_Silk_FrameTermination_offset = 2; - const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ] = {0, 13107, 26214, 39321, 52428, 65535}; const SKP_int SKP_Silk_FrameTermination_v4_offset = 4; diff --git a/src/SKP_Silk_tables_pitch_lag.c b/src_common/SKP_Silk_tables_pitch_lag.c similarity index 100% rename from src/SKP_Silk_tables_pitch_lag.c rename to src_common/SKP_Silk_tables_pitch_lag.c diff --git a/src/SKP_Silk_tables_pulses_per_block.c b/src_common/SKP_Silk_tables_pulses_per_block.c similarity index 100% rename from src/SKP_Silk_tables_pulses_per_block.c rename to src_common/SKP_Silk_tables_pulses_per_block.c diff --git a/src/SKP_Silk_tables_sign.c b/src_common/SKP_Silk_tables_sign.c similarity index 57% rename from src/SKP_Silk_tables_sign.c rename to src_common/SKP_Silk_tables_sign.c index 5ada010c8..b84a30750 100644 --- a/src/SKP_Silk_tables_sign.c +++ b/src_common/SKP_Silk_tables_sign.c @@ -27,115 +27,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_tables.h" -const SKP_uint16 SKP_Silk_sign_CDF[ 36 ][ 3 ] = -{ -{ - 0, 37840, 65535 -}, -{ - 0, 36944, 65535 -}, -{ - 0, 36251, 65535 -}, -{ - 0, 35304, 65535 -}, -{ - 0, 34715, 65535 -}, -{ - 0, 35503, 65535 -}, -{ - 0, 34529, 65535 -}, -{ - 0, 34296, 65535 -}, -{ - 0, 34016, 65535 -}, -{ - 0, 47659, 65535 -}, -{ - 0, 44945, 65535 -}, -{ - 0, 42503, 65535 -}, -{ - 0, 40235, 65535 -}, -{ - 0, 38569, 65535 -}, -{ - 0, 40254, 65535 -}, -{ - 0, 37851, 65535 -}, -{ - 0, 37243, 65535 -}, -{ - 0, 36595, 65535 -}, -{ - 0, 43410, 65535 -}, -{ - 0, 44121, 65535 -}, -{ - 0, 43127, 65535 -}, -{ - 0, 40978, 65535 -}, -{ - 0, 38845, 65535 -}, -{ - 0, 40433, 65535 -}, -{ - 0, 38252, 65535 -}, -{ - 0, 37795, 65535 -}, -{ - 0, 36637, 65535 -}, -{ - 0, 59159, 65535 -}, -{ - 0, 55630, 65535 -}, -{ - 0, 51806, 65535 -}, -{ - 0, 48073, 65535 -}, -{ - 0, 45036, 65535 -}, -{ - 0, 48416, 65535 -}, -{ - 0, 43857, 65535 -}, -{ - 0, 42678, 65535 -}, -{ - 0, 41146, 65535 -} +const SKP_uint16 SKP_Silk_sign_CDF[ 36 ] = +{ + 37840, 36944, 36251, 35304, + 34715, 35503, 34529, 34296, + 34016, 47659, 44945, 42503, + 40235, 38569, 40254, 37851, + 37243, 36595, 43410, 44121, + 43127, 40978, 38845, 40433, + 38252, 37795, 36637, 59159, + 55630, 51806, 48073, 45036, + 48416, 43857, 42678, 41146, }; diff --git a/src/SKP_Silk_tables_type_offset.c b/src_common/SKP_Silk_tables_type_offset.c similarity index 100% rename from src/SKP_Silk_tables_type_offset.c rename to src_common/SKP_Silk_tables_type_offset.c diff --git a/src_common/Silk_Common.vcproj b/src_common/Silk_Common.vcproj new file mode 100644 index 000000000..2d51578f6 --- /dev/null +++ b/src_common/Silk_Common.vcproj @@ -0,0 +1,360 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="Silk_Common" + ProjectGUID="{0E29E502-AB22-4147-93A1-AC91528ED758}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories=""../../../celt-0.7.1/libcelt";../interface;../src_SigProc_FIX;../src_FIX" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;FIXED_POINT;HAVE_CONFIG_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_Common_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories=""../../../celt-0.7.1/libcelt";../interface;../src_SigProc_FIX;../src_FIX" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;FIXED_POINT;HAVE_CONFIG_H" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_Common_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_CNG.c" + > + </File> + <File + RelativePath=".\SKP_Silk_code_signs.c" + > + </File> + <File + RelativePath=".\SKP_Silk_create_init_destroy.c" + > + </File> + <File + RelativePath=".\SKP_Silk_dec_SDK_API.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_core.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_frame.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_indices_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_parameters_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_pulses.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decoder_set_fs.c" + > + </File> + <File + RelativePath=".\SKP_Silk_detect_SWB_input.c" + > + </File> + <File + RelativePath=".\SKP_Silk_enc_API.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_parameters_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_pulses.c" + > + </File> + <File + RelativePath=".\SKP_Silk_gain_quant.c" + > + </File> + <File + RelativePath=".\SKP_Silk_interpolate.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LBRR_reset.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LP_variable_cutoff.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF2A_stable.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_MSVQ_decode.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NSQ.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NSQ_del_dec.c" + > + </File> + <File + RelativePath=".\SKP_Silk_PLC.c" + > + </File> + <File + RelativePath=".\SKP_Silk_pulses_to_bytes.c" + > + </File> + <File + RelativePath=".\SKP_Silk_range_coder.c" + > + </File> + <File + RelativePath=".\SKP_Silk_shell_coder.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_gain.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_LTP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_other.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_pitch_lag.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_pulses_per_block.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_sign.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_type_offset.c" + > + </File> + <File + RelativePath=".\SKP_Silk_VAD.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_define.h" + > + </File> + <File + RelativePath=".\SKP_Silk_main.h" + > + </File> + <File + RelativePath=".\SKP_Silk_PLC.h" + > + </File> + <File + RelativePath=".\SKP_Silk_structs.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src_common/Silk_CommonFLP.vcproj b/src_common/Silk_CommonFLP.vcproj new file mode 100644 index 000000000..ca3216339 --- /dev/null +++ b/src_common/Silk_CommonFLP.vcproj @@ -0,0 +1,364 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="Silk_Common" + ProjectGUID="{0E29E502-AB22-4147-93A1-AC91528ED758}" + RootNamespace="Silk" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX;../src_SigProc_FLP;../src_FLP" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_CommonFLP_Win32_debug.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="0" + FavorSizeOrSpeed="0" + AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX;../src_SigProc_FLP;../src_FLP" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;HAVE_CONFIG_H" + GeneratePreprocessedFile="0" + RuntimeLibrary="0" + FloatingPointModel="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + OutputFile="SKP_Silk_CommonFLP_Win32_mt.lib" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + CommandLine="" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\SKP_Silk_CNG.c" + > + </File> + <File + RelativePath=".\SKP_Silk_code_signs.c" + > + </File> + <File + RelativePath=".\SKP_Silk_create_init_destroy.c" + > + </File> + <File + RelativePath=".\SKP_Silk_dec_SDK_API.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_core.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_frame.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_indices_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_parameters_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decode_pulses.c" + > + </File> + <File + RelativePath=".\SKP_Silk_decoder_set_fs.c" + > + </File> + <File + RelativePath=".\SKP_Silk_detect_SWB_input.c" + > + </File> + <File + RelativePath=".\SKP_Silk_enc_API.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_parameters_v4.c" + > + </File> + <File + RelativePath=".\SKP_Silk_encode_pulses.c" + > + </File> + <File + RelativePath=".\SKP_Silk_gain_quant.c" + > + </File> + <File + RelativePath=".\SKP_Silk_interpolate.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LBRR_reset.c" + > + </File> + <File + RelativePath=".\SKP_Silk_LP_variable_cutoff.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF2A_stable.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NLSF_MSVQ_decode.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NSQ.c" + > + </File> + <File + RelativePath=".\SKP_Silk_NSQ_del_dec.c" + > + </File> + <File + RelativePath=".\SKP_Silk_PLC.c" + > + </File> + <File + RelativePath=".\SKP_Silk_pulses_to_bytes.c" + > + </File> + <File + RelativePath=".\SKP_Silk_range_coder.c" + > + </File> + <File + RelativePath=".\SKP_Silk_shell_coder.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_gain.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_LTP.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_other.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_pitch_lag.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_pulses_per_block.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_sign.c" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_type_offset.c" + > + </File> + <File + RelativePath=".\SKP_Silk_VAD.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\SKP_Silk_define.h" + > + </File> + <File + RelativePath=".\SKP_Silk_main.h" + > + </File> + <File + RelativePath=".\SKP_Silk_perceptual_parameters.h" + > + </File> + <File + RelativePath=".\SKP_Silk_PLC.h" + > + </File> + <File + RelativePath=".\SKP_Silk_structs.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_10.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB0_16.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_10.h" + > + </File> + <File + RelativePath=".\SKP_Silk_tables_NLSF_CB1_16.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/test/Dec_SDK.vcproj b/test/Dec_SDK.vcproj index 131586b52..fecbc19f4 100644 --- a/test/Dec_SDK.vcproj +++ b/test/Dec_SDK.vcproj @@ -2,7 +2,7 @@ <VisualStudioProject ProjectType="Visual C++" Version="8,00" - Name="Dec_SDK" + Name="Dec" ProjectGUID="{82685D7F-0589-42BD-877C-31A952D53A8E}" RootNamespace="Test" Keyword="Win32Proj" @@ -40,7 +40,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="../interface;../src" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;COMPILE_SDK" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -121,7 +121,7 @@ /> <Tool Name="VCCLCompilerTool" - AdditionalIncludeDirectories="../interface;../src" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;COMPILE_SDK" RuntimeLibrary="0" FloatingPointModel="2" @@ -190,6 +190,10 @@ RelativePath=".\Decoder.c" > </File> + <File + RelativePath=".\SKP_debug.c" + > + </File> </Filter> <Filter Name="interface" diff --git a/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user new file mode 100644 index 000000000..64fb3c3a4 --- /dev/null +++ b/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioUserFile + ProjectType="Visual C++" + Version="8.00" + ShowAllFiles="false" + > + <Configurations> + <Configuration + Name="Debug|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + </Configurations> +</VisualStudioUserFile> diff --git a/test/Decoder.c b/test/Decoder.c index 6c0605e1e..1e0cbe806 100644 --- a/test/Decoder.c +++ b/test/Decoder.c @@ -25,6 +25,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ + /*****************************/ /* Silk decoder test program */ /*****************************/ @@ -38,42 +39,74 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <string.h> #include "SKP_Silk_SDK_API.h" #include "SKP_Silk_SigProc_FIX.h" +#include "SKP_debug.h" /* Define codec specific settings should be moved to h file */ #define MAX_BYTES_PER_FRAME 1024 #define MAX_INPUT_FRAMES 5 #define MAX_FRAME_LENGTH 480 +#define MAX_FRAME_LENGTH_MS 20 +#define MAX_API_FS_KHZ 48 #define MAX_LBRR_DELAY 2 +#ifdef _SYSTEM_IS_BIG_ENDIAN +/* Function to convert a little endian int16 to a */ +/* big endian int16 or vica verca */ +void swap_endian( + SKP_int16 vec[], + SKP_int len +) +{ + SKP_int i; + SKP_int16 tmp; + SKP_uint8 *p1, *p2; + + for( i = 0; i < len; i++ ){ + tmp = vec[ i ]; + p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp; + p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ]; + } +} +#endif + static void print_usage(char* argv[]) { printf( "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] ); - printf( "\nin.bit : Bitstream input to decoder" ); - printf( "\nout.pcm : Speech output from decoder" ); + printf( "\nin.bit : Bitstream input to decoder" ); + printf( "\nout.pcm : Speech output from decoder" ); printf( "\n settings:" ); - printf( "\n-fs <kHz> : Sampling rate of output signal in kHz; default: 24" ); - printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" ); + printf( "\n-Fs_API <Hz> : Sampling rate of output signal in Hz; default: 24000" ); + printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" ); printf( "\n" ); } +#ifdef SKP_MACRO_COUNT + varDefine /* Define and reset global counters */ +#endif + int main( int argc, char* argv[] ) { + unsigned long tottime, starttime; + double filetime; size_t counter; - SKP_int args, totPackets, i, k; + SKP_int32 args, totPackets, i, k; SKP_int16 ret, len, tot_len; SKP_int16 nBytes; SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ]; - SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr; SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL; + SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr; SKP_int16 nBytesFEC; SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes; - SKP_int16 out[ ( MAX_FRAME_LENGTH << 1 ) * MAX_INPUT_FRAMES ], *outPtr; + SKP_int16 out[ ( ( MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ ) << 1 ) * MAX_INPUT_FRAMES ], *outPtr; char speechOutFileName[ 150 ], bitInFileName[ 150 ]; FILE *bitInFile, *speechOutFile; - SKP_int Fs_kHz = 0; + SKP_int32 API_Fs_Hz = 0, packetSize_ms=0; SKP_int32 decSizeBytes; void *psDec; +#ifdef SKP_MACRO_COUNT + SKP_int64 Ops, maxOps = 0, totOps = 0; +#endif float loss_prob; - SKP_int frames, lost, quiet; + SKP_int32 frames, lost, quiet; SKP_SILK_SDK_DecControlStruct DecControl; if( argc < 3 ) { @@ -95,8 +128,8 @@ int main( int argc, char* argv[] ) if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) { sscanf( argv[ args + 1 ], "%f", &loss_prob ); args += 2; - } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) { - sscanf( argv[ args + 1 ], "%d", &Fs_kHz ); + } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) { + sscanf( argv[ args + 1 ], "%d", &API_Fs_Hz ); args += 2; } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) { quiet = 1; @@ -127,11 +160,11 @@ int main( int argc, char* argv[] ) exit( 0 ); } - /* Set the samplingrate that is requested for the output */ - if( Fs_kHz == 0 ) { - DecControl.sampleRate = 24000; + /* Set the samplingrate that is requested for the output */ + if( API_Fs_Hz == 0 ) { + DecControl.API_sampleRate = 24000; } else { - DecControl.sampleRate = Fs_kHz * 1000; + DecControl.API_sampleRate = API_Fs_Hz; } /* Create decoder */ @@ -147,6 +180,7 @@ int main( int argc, char* argv[] ) printf( "\nSKP_Silk_InitDecoder returned %d", ret ); } + tottime = 0; totPackets = 0; payloadEnd = payload; @@ -154,10 +188,13 @@ int main( int argc, char* argv[] ) for( i = 0; i < MAX_LBRR_DELAY; i++ ) { /* Read payload size */ counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile ); +#ifdef _SYSTEM_IS_BIG_ENDIAN + swap_endian( &nBytes, 1 ); +#endif /* Read payload */ counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile ); - if( (SKP_int16)counter < nBytes ) { + if( ( SKP_int16 )counter < nBytes ) { break; } nBytesPerPacket[ i ] = nBytes; @@ -167,13 +204,16 @@ int main( int argc, char* argv[] ) while( 1 ) { /* Read payload size */ counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile ); +#ifdef _SYSTEM_IS_BIG_ENDIAN + swap_endian( &nBytes, 1 ); +#endif if( nBytes < 0 || counter < 1 ) { break; } /* Read payload */ counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile ); - if( (SKP_int16)counter < nBytes ) { + if( ( SKP_int16 )counter < nBytes ) { break; } @@ -193,7 +233,9 @@ int main( int argc, char* argv[] ) payloadPtr = payload; for( i = 0; i < MAX_LBRR_DELAY; i++ ) { if( nBytesPerPacket[ i + 1 ] > 0 ) { - SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC ); + starttime = GetHighResolutionTime(); + SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC ); + tottime += GetHighResolutionTime() - starttime; if( nBytesFEC > 0 ) { payloadToDec = FECpayload; nBytes = nBytesFEC; @@ -218,11 +260,17 @@ int main( int argc, char* argv[] ) frames = 0; do { /* Decode 20 ms */ + starttime = GetHighResolutionTime(); ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len ); + tottime += GetHighResolutionTime() - starttime; if( ret ) { printf( "\nSKP_Silk_SDK_Decode returned %d", ret ); } - +#ifdef SKP_MACRO_COUNT + Ops = SKP_SaveResetCount(); + if( Ops > maxOps ){ maxOps = Ops; } + totOps += Ops; +#endif frames++; outPtr += len; tot_len += len; @@ -238,17 +286,28 @@ int main( int argc, char* argv[] ) /* Loss: Decode enough frames to cover one packet duration */ for( i = 0; i < DecControl.framesPerPacket; i++ ) { /* Generate 20 ms */ + starttime = GetHighResolutionTime(); ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len ); + tottime += GetHighResolutionTime() - starttime; if( ret ) { printf( "\nSKP_Silk_Decode returned %d", ret ); } +#ifdef SKP_MACRO_COUNT + Ops = SKP_SaveResetCount(); + if( Ops > maxOps ){ maxOps = Ops; } + totOps += Ops; +#endif outPtr += len; tot_len += len; } } totPackets++; + packetSize_ms = tot_len / ( DecControl.API_sampleRate / 1000 ); /* Write output to file */ +#ifdef _SYSTEM_IS_BIG_ENDIAN + swap_endian( out, tot_len ); +#endif fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile ); /* Update buffer */ @@ -261,7 +320,7 @@ int main( int argc, char* argv[] ) SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) ); if( !quiet ) { - fprintf( stderr, "\rFrames decoded: %d", totPackets ); + fprintf( stderr, "\rPackets decoded: %d", totPackets ); } } @@ -275,7 +334,9 @@ int main( int argc, char* argv[] ) payloadPtr = payload; for( i = 0; i < MAX_LBRR_DELAY; i++ ) { if( nBytesPerPacket[ i + 1 ] > 0 ) { - SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC ); + starttime = GetHighResolutionTime(); + SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC ); + tottime += GetHighResolutionTime() - starttime; if( nBytesFEC > 0 ) { payloadToDec = FECpayload; nBytes = nBytesFEC; @@ -300,7 +361,9 @@ int main( int argc, char* argv[] ) frames = 0; do { /* Decode 20 ms */ + starttime = GetHighResolutionTime(); ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len ); + tottime += GetHighResolutionTime() - starttime; if( ret ) { printf( "\nSKP_Silk_SDK_Decode returned %d", ret ); } @@ -321,7 +384,9 @@ int main( int argc, char* argv[] ) /* Generate 20 ms */ for( i = 0; i < DecControl.framesPerPacket; i++ ) { + starttime = GetHighResolutionTime(); ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len ); + tottime += GetHighResolutionTime() - starttime; if( ret ) { printf( "\nSKP_Silk_Decode returned %d", ret ); } @@ -332,6 +397,9 @@ int main( int argc, char* argv[] ) totPackets++; /* Write output to file */ +#ifdef _SYSTEM_IS_BIG_ENDIAN + swap_endian( out, tot_len ); +#endif fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile ); /* Update Buffer */ @@ -348,8 +416,27 @@ int main( int argc, char* argv[] ) } } + filetime = totPackets * 1e-3 * packetSize_ms; if( !quiet ) { - printf( "\nDecoding Finished \n" ); + printf("\nFile length: %.3f s", filetime); + printf("\nTime for decoding: %.3f s (%.3f%% of realtime)", 1e-6 * tottime, 1e-4 * tottime / filetime); + +#ifdef SKP_MACRO_COUNT + printf("\n \nWMOPS calculation"); + printf("\nMean: %.3f WMOPS", (float)totOps / ((float)packetSize_ms * (float)totPackets * 1e3)); + printf("\nMax: %.3f WMOPS", (float)maxOps / ((float)packetSize_ms * 1e3)); +#endif + printf("\n\n"); + } else { + /* print time and % of realtime */ + printf( "%.3f %.3f %d ", 1e-6 * tottime, 1e-4 * tottime / filetime, totPackets ); +#ifdef SKP_MACRO_COUNT + /* print average and max WMOPS */ + printf( "%.3f %.3f \n", (float)totOps / ((float)packetSize_ms * (float)totPackets * 1e3), + (float)maxOps / ((float)packetSize_ms * 1e3)); +#else + printf( "%.3f %.3f \n", 0, 0); +#endif } /* Free decoder */ @@ -359,5 +446,8 @@ int main( int argc, char* argv[] ) fclose( speechOutFile ); fclose( bitInFile ); + /* Save timing file if TIC/TOC used */ + SKP_TimerSave("decoder_timings.txt"); + return 0; } diff --git a/test/Enc_SDK.vcproj b/test/Enc_SDK.vcproj index 4415931c0..8d877f8fd 100644 --- a/test/Enc_SDK.vcproj +++ b/test/Enc_SDK.vcproj @@ -2,7 +2,7 @@ <VisualStudioProject ProjectType="Visual C++" Version="8,00" - Name="Enc_SDK" + Name="Enc" ProjectGUID="{6D97A8EF-5724-4D85-8BF4-C583714BBA78}" RootNamespace="Enc" Keyword="Win32Proj" @@ -40,7 +40,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="../interface" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -121,7 +121,7 @@ /> <Tool Name="VCCLCompilerTool" - AdditionalIncludeDirectories="../interface" + AdditionalIncludeDirectories="../interface;../src_SigProc_FIX" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="0" FloatingPointModel="2" @@ -190,6 +190,10 @@ RelativePath=".\Encoder.c" > </File> + <File + RelativePath=".\SKP_debug.c" + > + </File> </Filter> <Filter Name="interface" diff --git a/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user new file mode 100644 index 000000000..64fb3c3a4 --- /dev/null +++ b/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioUserFile + ProjectType="Visual C++" + Version="8.00" + ShowAllFiles="false" + > + <Configurations> + <Configuration + Name="Debug|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + </Configurations> +</VisualStudioUserFile> diff --git a/test/Encoder.c b/test/Encoder.c index 0e4dd1c6b..6a0dedaf2 100644 --- a/test/Encoder.c +++ b/test/Encoder.c @@ -25,6 +25,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ + /*****************************/ /* Silk encoder test program */ /*****************************/ @@ -38,49 +39,87 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <string.h> #include <math.h> #include "SKP_Silk_SDK_API.h" +#include "SKP_Silk_SigProc_FIX.h" +#include "SKP_debug.h" /* Define codec specific settings */ #define MAX_BYTES_PER_FRAME 250 // Equals peak bitrate of 100 kbps #define MAX_INPUT_FRAMES 5 #define MAX_LBRR_DELAY 2 #define MAX_FRAME_LENGTH 480 +#define MAX_FRAME_LENGTH_MS 20 +#define MAX_API_FS_KHZ 48 + +#ifdef SKP_MACRO_COUNT + varDefine /* Define and reset global counters */ +#endif + +#ifdef _SYSTEM_IS_BIG_ENDIAN +/* Function to convert a little endian int16 to a */ +/* big endian int16 or vica verca */ +void swap_endian( + SKP_int16 vec[], /* I/O array of */ + SKP_int len /* I length */ +) +{ + SKP_int i; + SKP_int16 tmp; + SKP_uint8 *p1, *p2; + + for( i = 0; i < len; i++ ){ + tmp = vec[ i ]; + p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp; + p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ]; + } +} +#endif static void print_usage( char* argv[] ) { printf( "\nusage: %s in.pcm out.bit [settings]\n", argv[ 0 ] ); - printf( "\nin.pcm : Speech input to encoder" ); - printf( "\nout.bit : Bitstream output from encoder" ); + printf( "\nin.pcm : Speech input to encoder" ); + printf( "\nout.bit : Bitstream output from encoder" ); printf( "\n settings:" ); - printf( "\n-fs <kHz> : Sampling rate in kHz, default: 24" ); - printf( "\n-packetlength <ms> : Packet interval in ms, default: 20" ); - printf( "\n-rate <bps> : Target bitrate; default: 25000" ); - printf( "\n-loss <perc> : Uplink loss estimate, in percent (0-100); default: 0" ); - printf( "\n-inbandFEC <flag> : Enable inband FEC usage (0/1); default: 0" ); - printf( "\n-complexity <comp> : Set complexity, 0: low, 1: medium, 2: high; default: 2" ); - printf( "\n-DTX <flag> : Enable DTX (0/1); default: 0" ); - printf( "\n-quiet : Print only some basic values" ); + printf( "\n-Fs_API <Hz> : API sampling rate in Hz, default: 24000" ); + printf( "\n-Fs_maxInternal <Hz> : Maximum internal sampling rate in Hz, default: 24000" ); + printf( "\n-packetlength <ms> : Packet interval in ms, default: 20" ); + printf( "\n-rate <bps> : Target bitrate; default: 25000" ); + printf( "\n-loss <perc> : Uplink loss estimate, in percent (0-100); default: 0" ); + printf( "\n-inbandFEC <flag> : Enable inband FEC usage (0/1); default: 0" ); + printf( "\n-complexity <comp> : Set complexity, 0: low, 1: medium, 2: high; default: 2" ); + printf( "\n-DTX <flag> : Enable DTX (0/1); default: 0" ); + printf( "\n-quiet : Print only some basic values" ); printf( "\n"); } int main( int argc, char* argv[] ) { + unsigned long tottime, starttime; + double filetime; size_t counter; - SKP_int k, args, totPackets, totActPackets, ret; + SKP_int32 k, args, totPackets, totActPackets, ret; SKP_int16 nBytes; - double sumBytes, sumWBytes, sumActBytes, avg_rate, act_rate, wght_rate, nrg; + double sumBytes, sumActBytes, avg_rate, act_rate, nrg; SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ]; - SKP_int16 in[ MAX_FRAME_LENGTH * MAX_INPUT_FRAMES ]; + SKP_int16 in[ MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES ]; char speechInFileName[ 150 ], bitOutFileName[ 150 ]; FILE *bitOutFile, *speechInFile; SKP_int32 encSizeBytes; void *psEnc; +#ifdef SKP_MACRO_COUNT + SKP_int64 Ops, maxOps = 0, totOps = 0; +#endif +#ifdef _SYSTEM_IS_BIG_ENDIAN + SKP_int16 nBytes_LE; +#endif /* default settings */ - SKP_int fs_kHz = 24; - SKP_int targetRate_bps = 25000; - SKP_int packetSize_ms = 20; - SKP_int frameSizeReadFromFile_ms = 20; - SKP_int packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket; - SKP_int INBandFec_enabled = 0, DTX_enabled = 0, quiet = 0; + SKP_int32 API_fs_Hz = 24000; + SKP_int32 max_internal_fs_Hz = 0; + SKP_int32 targetRate_bps = 25000; + SKP_int32 packetSize_ms = 20; + SKP_int32 frameSizeReadFromFile_ms = 10; + SKP_int32 packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket; + SKP_int32 INBandFEC_enabled = 0, DTX_enabled = 0, quiet = 0; SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder if( argc < 3 ) { @@ -95,8 +134,11 @@ int main( int argc, char* argv[] ) strcpy( bitOutFileName, argv[ args ] ); args++; while( args < argc ) { - if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) { - sscanf( argv[ args + 1 ], "%d", &fs_kHz ); + if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) { + sscanf( argv[ args + 1 ], "%d", &API_fs_Hz ); + args += 2; + } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_maxInternal" ) == 0 ) { + sscanf( argv[ args + 1 ], "%d", &max_internal_fs_Hz ); args += 2; } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-packetlength" ) == 0 ) { sscanf( argv[ args + 1 ], "%d", &packetSize_ms ); @@ -111,7 +153,7 @@ int main( int argc, char* argv[] ) sscanf( argv[ args + 1 ], "%d", &complexity_mode ); args += 2; } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandFEC" ) == 0 ) { - sscanf( argv[ args + 1 ], "%d", &INBandFec_enabled ); + sscanf( argv[ args + 1 ], "%d", &INBandFEC_enabled ); args += 2; } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-DTX") == 0 ) { sscanf( argv[ args + 1 ], "%d", &DTX_enabled ); @@ -126,18 +168,24 @@ int main( int argc, char* argv[] ) } } + /* If no max internal set set to API fs */ + if( max_internal_fs_Hz == 0 ) { + max_internal_fs_Hz = API_fs_Hz; + } + /* Print options */ if( !quiet ) { printf("******************* Silk Encoder v %s ****************\n", SKP_Silk_SDK_get_version()); printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 ); - printf( "Input: %s\n", speechInFileName ); - printf( "Output: %s\n", bitOutFileName ); - printf( "Sampling rate: %d kHz\n", fs_kHz); - printf( "Packet interval: %d ms\n", packetSize_ms); - printf( "Inband FEC used: %d\n", INBandFec_enabled); - printf( "DTX used: %d\n", DTX_enabled); - printf( "Complexity: %d\n", complexity_mode); - printf( "Target bitrate: %d bps\n", targetRate_bps); + printf( "Input: %s\n", speechInFileName ); + printf( "Output: %s\n", bitOutFileName ); + printf( "API sampling rate: %d Hz\n", API_fs_Hz ); + printf( "Maximum internal sampling rate: %d Hz\n", max_internal_fs_Hz ); + printf( "Packet interval: %d ms\n", packetSize_ms ); + printf( "Inband FEC used: %d\n", INBandFEC_enabled ); + printf( "DTX used: %d\n", DTX_enabled ); + printf( "Complexity: %d\n", complexity_mode ); + printf( "Target bitrate: %d bps\n", targetRate_bps ); } /* Open files */ @@ -159,7 +207,7 @@ int main( int argc, char* argv[] ) } psEnc = malloc( encSizeBytes ); - + /* Reset Encoder */ ret = SKP_Silk_SDK_InitEncoder( psEnc, &encControl ); if( ret ) { @@ -167,66 +215,83 @@ int main( int argc, char* argv[] ) } /* Set Encoder parameters */ - encControl.sampleRate = fs_kHz * 1000; - encControl.packetSize = packetSize_ms * fs_kHz; - encControl.packetLossPercentage = packetLoss_perc; - encControl.useInBandFEC = INBandFec_enabled; - encControl.useDTX = DTX_enabled; - encControl.complexity = complexity_mode; - encControl.bitRate = targetRate_bps; - - if( fs_kHz > 24 || fs_kHz < 0 ) { - printf( "\nError: Sampling rate = %d out of range, valid range 8 - 24 \n \n", fs_kHz ); + encControl.API_sampleRate = API_fs_Hz; + encControl.maxInternalSampleRate = max_internal_fs_Hz; + encControl.packetSize = ( packetSize_ms * API_fs_Hz ) / 1000; + encControl.packetLossPercentage = packetLoss_perc; + encControl.useInBandFEC = INBandFEC_enabled; + encControl.useDTX = DTX_enabled; + encControl.complexity = complexity_mode; + encControl.bitRate = ( targetRate_bps > 0 ? targetRate_bps : 0 ); + + if( API_fs_Hz > MAX_API_FS_KHZ * 1000 || API_fs_Hz < 0 ) { + printf( "\nError: API sampling rate = %d out of range, valid range 8000 - 48000 \n \n", API_fs_Hz ); exit( 0 ); } + tottime = 0; totPackets = 0; totActPackets = 0; smplsSinceLastPacket = 0; sumBytes = 0.0; sumActBytes = 0.0; - sumWBytes = 0.0; while( 1 ) { - /* Read input to file */ - counter = fread( in, sizeof( SKP_int16 ), frameSizeReadFromFile_ms * fs_kHz, speechInFile ); - if( (SKP_int)counter < frameSizeReadFromFile_ms * fs_kHz ) { + /* Read input from file */ + counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile ); +#ifdef _SYSTEM_IS_BIG_ENDIAN + swap_endian( in, counter ); +#endif + if( (SKP_int)counter < ( ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000 ) ) { break; } /* max payload size */ nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES; + starttime = GetHighResolutionTime(); /* Silk Encoder */ ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes ); if( ret ) { printf( "\nSKP_Silk_Encode returned %d", ret ); break; } + tottime += GetHighResolutionTime() - starttime; + +#ifdef SKP_MACRO_COUNT + Ops = SKP_SaveResetCount(); + if( Ops > maxOps ){ maxOps = Ops; } + totOps += Ops; +#endif /* Get packet size */ - packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate; + packetSize_ms = ( SKP_int )( ( 1000 * ( SKP_int32 )encControl.packetSize ) / encControl.API_sampleRate ); - smplsSinceLastPacket += (SKP_int)counter; + smplsSinceLastPacket += ( SKP_int )counter; - if( ( smplsSinceLastPacket / fs_kHz ) == packetSize_ms ) { + if( ( ( 1000 * smplsSinceLastPacket ) / API_fs_Hz ) == packetSize_ms ) { /* Sends a dummy zero size packet in case of DTX period */ /* to make it work with the decoder test program. */ /* In practice should be handled by RTP sequence numbers */ totPackets++; - sumBytes += nBytes; - sumWBytes += pow( (double)nBytes, 10.0 ); + sumBytes += nBytes; nrg = 0.0; - for( k = 0; k < (SKP_int)counter; k++ ) { + for( k = 0; k < ( SKP_int )counter; k++ ) { nrg += in[ k ] * (double)in[ k ]; } - if( ( nrg / (SKP_int)counter ) > 1e3 ) { + if( ( nrg / ( SKP_int )counter ) > 1e3 ) { sumActBytes += nBytes; totActPackets++; } /* Write payload size */ +#ifdef _SYSTEM_IS_BIG_ENDIAN + nBytes_LE = nBytes; + swap_endian( &nBytes_LE, 1 ); + fwrite( &nBytes_LE, sizeof( SKP_int16 ), 1, bitOutFile ); +#else fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile ); +#endif /* Write payload */ fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile ); @@ -244,26 +309,43 @@ int main( int argc, char* argv[] ) /* Write payload size */ fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile ); - /* Query encoder */ - packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate; - /* Free Encoder */ free( psEnc ); fclose( speechInFile ); fclose( bitOutFile ); + filetime = totPackets * 1e-3 * packetSize_ms; avg_rate = 8.0 / packetSize_ms * sumBytes / totPackets; act_rate = 8.0 / packetSize_ms * sumActBytes / totActPackets; - wght_rate = 8.0 / packetSize_ms * pow( sumWBytes / totPackets, 0.1 ); if( !quiet ) { + printf( "\nFile length: %.3f s", filetime ); + printf( "\nTime for encoding: %.3f s (%.3f%% of realtime)", 1e-6 * tottime, 1e-4 * tottime / filetime ); printf( "\nAverage bitrate: %.3f kbps", avg_rate ); printf( "\nActive bitrate: %.3f kbps", act_rate ); - printf( "\nWeighted bitrate: %.3f kbps", wght_rate ); +#ifdef SKP_MACRO_COUNT + printf( "\n \nWMOPS calculation"); + printf( "\nMean: %.3f WMOPS", (float)totOps / ((float)packetSize_ms * (float)totPackets * 1e3)); + printf( "\nMax: %.3f WMOPS", (float)maxOps / ((float)packetSize_ms * 1e3)); +#endif printf( "\n\n" ); } else { - /* print average and weighted bitrates */ - printf( "%.3f %.3f %.3f \n", avg_rate, act_rate, wght_rate ); + /* print time and % of realtime */ + printf("%.3f %.3f %d ", 1e-6 * tottime, 1e-4 * tottime / filetime, totPackets ); + + /* print average and active bitrates */ + printf( "%.3f %.3f ", avg_rate, act_rate ); +#ifdef SKP_MACRO_COUNT + /* print average and max WMOPS */ + printf( "%.3f %.3f \n", (float)totOps / ((float)packetSize_ms * (float)totPackets * 1e3), + (float)maxOps / ((float)packetSize_ms * 1e3)); +#else + printf( "%.3f %.3f \n", 0, 0); +#endif } + + /* Save timing file if TIC/TOC used */ + SKP_TimerSave("encoder_timings.txt"); + return 0; } diff --git a/test/SKP_debug.c b/test/SKP_debug.c new file mode 100644 index 000000000..31468f739 --- /dev/null +++ b/test/SKP_debug.c @@ -0,0 +1,169 @@ +/*********************************************************************** +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_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() /* 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() /* 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 */ diff --git a/test/SignalCompare.vcproj b/test/SignalCompare.vcproj index adf960acb..d708124ac 100644 --- a/test/SignalCompare.vcproj +++ b/test/SignalCompare.vcproj @@ -40,7 +40,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="..\interface;..\src" + AdditionalIncludeDirectories="..\interface;..\src_SigProc_FIX" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -121,7 +121,7 @@ /> <Tool Name="VCCLCompilerTool" - AdditionalIncludeDirectories="..\interface;..\src" + AdditionalIncludeDirectories="..\interface;..\src_SigProc_FIX" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="0" FloatingPointModel="2" diff --git a/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user b/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user new file mode 100644 index 000000000..64fb3c3a4 --- /dev/null +++ b/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioUserFile + ProjectType="Visual C++" + Version="8.00" + ShowAllFiles="false" + > + <Configurations> + <Configuration + Name="Debug|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + <Configuration + Name="Release|Win32" + > + <DebugSettings + Command="$(TargetPath)" + WorkingDirectory="" + CommandArguments="" + Attach="false" + DebuggerType="3" + Remote="1" + RemoteMachine="SKYPE-KOEN" + RemoteCommand="" + HttpUrl="" + PDBPath="" + SQLDebugging="" + Environment="" + EnvironmentMerge="true" + DebuggerFlavor="" + MPIRunCommand="" + MPIRunArguments="" + MPIRunWorkingDirectory="" + ApplicationCommand="" + ApplicationArguments="" + ShimCommand="" + MPIAcceptMode="" + MPIAcceptFilter="" + /> + </Configuration> + </Configurations> +</VisualStudioUserFile> diff --git a/test/signalCompare.c b/test/signalCompare.c index 044458489..f6025d914 100644 --- a/test/signalCompare.c +++ b/test/signalCompare.c @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef _WIN32 -#define _CRT_SECURE_NO_DEPRECATE 1 +#define _CRT_SECURE_NO_DEPRECATE 1 #endif #include <stdio.h> @@ -40,12 +40,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SKP_Silk_SigProc_FIX.h" -#define FRAME_LENGTH_MS 10 -#define WIN_LENGTH_MS 20 -#define BW_EXPANSION 0.7f +#define FRAME_LENGTH_MS 10 +#define WIN_LENGTH_MS 20 +#define BW_EXPANSION 0.7f -#define MAX_FS_KHZ 24 -#define LPC_ORDER 10 +#define MAX_FS_KHZ 24 +#define LPC_ORDER 10 #ifdef __cplusplus extern "C" @@ -53,30 +53,30 @@ extern "C" #endif /* Internally used functions */ void Autocorrelation( - SKP_float *results, /* o result (length correlationCount) */ - const SKP_float *inputData, /* i input data to correlate */ - SKP_int inputDataSize, /* i length of input */ - SKP_int correlationCount /* i number of correlation taps to compute */ + SKP_float *results, /* o result (length correlationCount) */ + const SKP_float *inputData, /* i input data to correlate */ + SKP_int inputDataSize, /* i length of input */ + SKP_int correlationCount /* i number of correlation taps to compute */ ); /* inner product of two SKP_float arrays, with result as double */ double Inner_product( - const SKP_float *data1, - const SKP_float *data2, - SKP_int dataSize + const SKP_float *data1, + const SKP_float *data2, + SKP_int dataSize ); /* Solve the normal equations using the Levinson-Durbin recursion */ -SKP_float Levinsondurbin( /* O prediction error energy */ - SKP_float A[], /* O prediction coefficients [order] */ - const SKP_float corr[], /* I input auto-correlations [order + 1] */ - const SKP_int order /* I prediction order */ +SKP_float Levinsondurbin( /* O prediction error energy */ + SKP_float A[], /* O prediction coefficients [order] */ + const SKP_float corr[], /* I input auto-correlations [order + 1] */ + const SKP_int order /* I prediction order */ ); /* Chirp (bw expand) LP AR filter */ void Bwexpander( - SKP_float *ar, /* io AR filter to be expanded (without leading 1) */ - const SKP_int d, /* i length of ar */ - const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */ + SKP_float *ar, /* io AR filter to be expanded (without leading 1) */ + const SKP_int d, /* i length of ar */ + const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */ ); #ifdef __cplusplus @@ -84,283 +84,290 @@ void Bwexpander( #endif static void print_usage(char* argv[]) { - printf("\nusage: %s ref.pcm test.pcm [settings]\n", argv[ 0 ]); - printf("\nref.pcm : Reference file"); - printf("\ntest.pcm : File to be tested, should be of same length as ref.pcm"); - printf("\n settings:"); - printf("\n-diff : Only determine bit-exactness"); - printf("\n-fs <kHz> : Sampling rate in kHz, max: %d; default: 24", MAX_FS_KHZ); - printf("\n"); + printf("\nusage: %s ref.pcm test.pcm [settings]\n", argv[ 0 ]); + printf("\nref.pcm : Reference file"); + printf("\ntest.pcm : File to be tested, should be of same length as ref.pcm"); + printf("\n settings:"); + printf("\n-diff : Only determine bit-exactness"); + printf("\n-fs <Hz> : Sampling rate in Hz, max: %d; default: 24000", MAX_FS_KHZ * 1000 ); + printf("\n"); } +#ifdef SKP_MACRO_COUNT + varDefine /* Define and reset global counters */ +#endif + int main(int argc, char* argv[]) { - SKP_int args, n, i, counterRef, counterTest; - char testInFileName[150], refInFileName[150]; - FILE *refInFile, *testInFile; - SKP_int nFrames = 0, isUnequal = 0; - SKP_int diff = 0, Fs_kHz = 24; /* defaults */ - SKP_float c, refWhtnd, testWhtnd, refNrg, diffNrg; - double SNR = 0.0; - SKP_int16 refIn[WIN_LENGTH_MS * MAX_FS_KHZ], testIn[WIN_LENGTH_MS * MAX_FS_KHZ]; - SKP_float refWin[WIN_LENGTH_MS * MAX_FS_KHZ], testWin[WIN_LENGTH_MS * MAX_FS_KHZ]; - SKP_float autoCorr[LPC_ORDER + 1], LPC_Coef[LPC_ORDER]; - - if (argc < 3) { - print_usage(argv); - exit(0); - } - - /* get arguments */ - args = 1; - strcpy(refInFileName, argv[args]); - args++; - strcpy(testInFileName, argv[args]); - args++; - while(args < argc ) { - if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-diff") == 0) { - diff = 1; - args++; - }else if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-fs") == 0) { - sscanf(argv[args+1], "%d", &Fs_kHz); - args += 2; - } else { - printf("Error: unrecognized setting: %s\n\n", argv[args]); - print_usage(argv); - exit(0); - } - } - - if( Fs_kHz > MAX_FS_KHZ ) { - printf("Error: sampling rate too high: %d\n\n", Fs_kHz); - print_usage(argv); - exit(0); - } - - printf("Reference: %s\n", refInFileName); - //printf("Test: %s\n", testInFileName); - - /* open files */ - refInFile = fopen(refInFileName, "rb"); - if (refInFile==NULL) { - printf("Error: could not open input file %s\n", refInFileName); - exit(0); - } - testInFile = fopen(testInFileName, "rb"); - if (testInFile==NULL) { - printf("Error: could not open input file %s\n", testInFileName); - exit(0); - } - - SKP_memset( refIn, 0, sizeof(refIn) ); - SKP_memset( testIn, 0, sizeof(testIn) ); - - while(1) { - /* Read inputs */ - counterRef = (SKP_int)fread(&refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], - sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, refInFile); - counterTest = (SKP_int)fread(&testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], - sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, testInFile); - if(counterRef != FRAME_LENGTH_MS * Fs_kHz || counterTest != FRAME_LENGTH_MS * Fs_kHz){ - break; - } - - /* test for bit-exactness */ - for( n = 0; n < FRAME_LENGTH_MS * Fs_kHz; n++ ) { - if( refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] != - testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] ) { - isUnequal = 1; - break; - } - } - - /* apply sine window */ - for( n = 0; n < WIN_LENGTH_MS * Fs_kHz; n++ ) { - c = (SKP_float)sin( 3.14159265 * (n + 1) / (WIN_LENGTH_MS * Fs_kHz + 1) ); - refWin[n] = refIn[n] * c; - testWin[n] = testIn[n] * c; - } - - /* LPC analysis on reference signal */ - - /* Calculate auto correlation */ - Autocorrelation(autoCorr, refWin, WIN_LENGTH_MS * Fs_kHz, LPC_ORDER + 1); - - /* Add white noise */ - autoCorr[ 0 ] += autoCorr[ 0 ] * 1e-6f + 1.0f; - - /* Convert correlations to prediction coefficients */ - Levinsondurbin(LPC_Coef, autoCorr, LPC_ORDER); - - /* Bandwdith expansion */ - Bwexpander(LPC_Coef, LPC_ORDER, BW_EXPANSION); - - /* Filter both signals */ - refNrg = 1.0f; - diffNrg = 1e-10f; - for( n = (WIN_LENGTH_MS - FRAME_LENGTH_MS) / 2 * Fs_kHz; - n < (WIN_LENGTH_MS + FRAME_LENGTH_MS) / 2 * Fs_kHz; n++ ) { - refWhtnd = refIn[n]; - testWhtnd = testIn[n]; - for( i = 0; i < LPC_ORDER; i++ ) { - refWhtnd -= LPC_Coef[ i ] * refIn[n - i - 1]; - testWhtnd -= LPC_Coef[ i ] * testIn[n - i - 1]; - } - refNrg += refWhtnd * refWhtnd; - diffNrg += (refWhtnd - testWhtnd) * (refWhtnd - testWhtnd); - } - - /* weighted SNR */ - if( refNrg > FRAME_LENGTH_MS * Fs_kHz ) { - SNR += 10.0 * log10( refNrg / diffNrg ); - nFrames++; - } - - /* Update Buffer */ - SKP_memmove( refIn, &refIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16)); - SKP_memmove( testIn, &testIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16)); - } - - if( diff ) { - if( isUnequal ) { - printf("Signals DIFFER\n"); - } else { - if(counterRef != counterTest){ - printf("Warning: signals differ in length\n"); - } - printf("Signals BIT-EXACT\n"); - } - } else { - if( nFrames == 0 ) { - printf("At least one signal too short or not loud enough\n"); - exit(0); - } - if(counterRef != counterTest){ - printf("Warning: signals differ in length\n"); - } - if( isUnequal == 0 ) { - printf("Signals BIT-EXACT\n"); - } else { - printf("AVERAGE WEIGHTED SNR: %4.1f dB\n", SNR / nFrames); - } - } - printf("\n"); - - /* Close Files */ - fclose(refInFile); - fclose(testInFile); - - return 0; + SKP_int args, n, i, counterRef, counterTest; + char testInFileName[150], refInFileName[150]; + FILE *refInFile, *testInFile; + SKP_int nFrames = 0, isUnequal = 0; + SKP_int diff = 0, Fs_kHz; + SKP_int32 Fs_Hz = 24000; + SKP_float c, refWhtnd, testWhtnd, refNrg, diffNrg; + double SNR = 0.0; + SKP_int16 refIn[WIN_LENGTH_MS * MAX_FS_KHZ], testIn[WIN_LENGTH_MS * MAX_FS_KHZ]; + SKP_float refWin[WIN_LENGTH_MS * MAX_FS_KHZ], testWin[WIN_LENGTH_MS * MAX_FS_KHZ]; + SKP_float autoCorr[LPC_ORDER + 1], LPC_Coef[LPC_ORDER]; + + if (argc < 3) { + print_usage(argv); + exit(0); + } + + /* get arguments */ + args = 1; + strcpy(refInFileName, argv[args]); + args++; + strcpy(testInFileName, argv[args]); + args++; + while(args < argc ) { + if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-diff") == 0) { + diff = 1; + args++; + }else if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-fs") == 0) { + sscanf(argv[args+1], "%d", &Fs_Hz); + args += 2; + } else { + printf("Error: unrecognized setting: %s\n\n", argv[args]); + print_usage(argv); + exit(0); + } + } + + Fs_kHz = SKP_DIV32_16( Fs_Hz, 1000 ); + + if( Fs_kHz > MAX_FS_KHZ ) { + printf("Error: sampling rate too high: %d\n\n", Fs_kHz); + print_usage(argv); + exit(0); + } + + printf("Reference: %s\n", refInFileName); + //printf("Test: %s\n", testInFileName); + + /* open files */ + refInFile = fopen(refInFileName, "rb"); + if (refInFile==NULL) { + printf("Error: could not open input file %s\n", refInFileName); + exit(0); + } + testInFile = fopen(testInFileName, "rb"); + if (testInFile==NULL) { + printf("Error: could not open input file %s\n", testInFileName); + exit(0); + } + + SKP_memset( refIn, 0, sizeof(refIn) ); + SKP_memset( testIn, 0, sizeof(testIn) ); + + while(1) { + /* Read inputs */ + counterRef = (SKP_int)fread(&refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], + sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, refInFile); + counterTest = (SKP_int)fread(&testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], + sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, testInFile); + if(counterRef != FRAME_LENGTH_MS * Fs_kHz || counterTest != FRAME_LENGTH_MS * Fs_kHz){ + break; + } + + /* test for bit-exactness */ + for( n = 0; n < FRAME_LENGTH_MS * Fs_kHz; n++ ) { + if( refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] != + testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] ) { + isUnequal = 1; + break; + } + } + + /* apply sine window */ + for( n = 0; n < WIN_LENGTH_MS * Fs_kHz; n++ ) { + c = (SKP_float)sin( 3.14159265 * (n + 1) / (WIN_LENGTH_MS * Fs_kHz + 1) ); + refWin[n] = refIn[n] * c; + testWin[n] = testIn[n] * c; + } + + /* LPC analysis on reference signal */ + + /* Calculate auto correlation */ + Autocorrelation(autoCorr, refWin, WIN_LENGTH_MS * Fs_kHz, LPC_ORDER + 1); + + /* Add white noise */ + autoCorr[ 0 ] += autoCorr[ 0 ] * 1e-6f + 1.0f; + + /* Convert correlations to prediction coefficients */ + Levinsondurbin(LPC_Coef, autoCorr, LPC_ORDER); + + /* Bandwdith expansion */ + Bwexpander(LPC_Coef, LPC_ORDER, BW_EXPANSION); + + /* Filter both signals */ + refNrg = 1.0f; + diffNrg = 1e-10f; + for( n = (WIN_LENGTH_MS - FRAME_LENGTH_MS) / 2 * Fs_kHz; + n < (WIN_LENGTH_MS + FRAME_LENGTH_MS) / 2 * Fs_kHz; n++ ) { + refWhtnd = refIn[n]; + testWhtnd = testIn[n]; + for( i = 0; i < LPC_ORDER; i++ ) { + refWhtnd -= LPC_Coef[ i ] * refIn[n - i - 1]; + testWhtnd -= LPC_Coef[ i ] * testIn[n - i - 1]; + } + refNrg += refWhtnd * refWhtnd; + diffNrg += (refWhtnd - testWhtnd) * (refWhtnd - testWhtnd); + } + + /* weighted SNR */ + if( refNrg > FRAME_LENGTH_MS * Fs_kHz ) { + SNR += 10.0 * log10( refNrg / diffNrg ); + nFrames++; + } + + /* Update Buffer */ + SKP_memmove( refIn, &refIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16)); + SKP_memmove( testIn, &testIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16)); + } + + if( diff ) { + if( isUnequal ) { + printf("Signals DIFFER\n"); + } else { + if(counterRef != counterTest){ + printf("Warning: signals differ in length\n"); + } + printf("Signals BIT-EXACT\n"); + } + } else { + if( nFrames == 0 ) { + printf("At least one signal too short or not loud enough\n"); + exit(0); + } + if(counterRef != counterTest){ + printf("Warning: signals differ in length\n"); + } + if( isUnequal == 0 ) { + printf("Signals BIT-EXACT\n"); + } else { + printf("AVERAGE WEIGHTED SNR: %4.1f dB\n", SNR / nFrames); + } + } + printf("\n"); + + /* Close Files */ + fclose(refInFile); + fclose(testInFile); + + return 0; } /* compute autocorrelation */ void Autocorrelation( - SKP_float *results, /* o result (length correlationCount) */ - const SKP_float *inputData, /* i input data to correlate */ - SKP_int inputDataSize, /* i length of input */ - SKP_int correlationCount /* i number of correlation taps to compute */ + SKP_float *results, /* o result (length correlationCount) */ + const SKP_float *inputData, /* i input data to correlate */ + SKP_int inputDataSize, /* i length of input */ + SKP_int correlationCount /* i number of correlation taps to compute */ ) { - SKP_int i; + SKP_int i; - if (correlationCount > inputDataSize) { - correlationCount = inputDataSize; - } + if (correlationCount > inputDataSize) { + correlationCount = inputDataSize; + } - for( i = 0; i < correlationCount; i++ ) { - results[ i ] = (SKP_float)Inner_product( inputData, inputData + i, inputDataSize - i ); - } + for( i = 0; i < correlationCount; i++ ) { + results[ i ] = (SKP_float)Inner_product( inputData, inputData + i, inputDataSize - i ); + } } /* inner product of two SKP_float arrays, with result as double */ double Inner_product( - const SKP_float *data1, - const SKP_float *data2, - SKP_int dataSize + const SKP_float *data1, + const SKP_float *data2, + 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 += data1[ i + 0 ] * data2[ i + 0 ] + - data1[ i + 1 ] * data2[ i + 1 ] + - data1[ i + 2 ] * data2[ i + 2 ] + - data1[ i + 3 ] * data2[ i + 3 ]; - } - - /* add any remaining products */ - for( ; i < dataSize; i++ ) { - result += data1[ i ] * data2[ i ]; - } - - return result; + SKP_int i, dataSize4; + double result; + + /* 4x unrolled loop */ + result = 0.0f; + dataSize4 = dataSize & 0xFFFC; + for( i = 0; i < dataSize4; i += 4 ) { + result += data1[ i + 0 ] * data2[ i + 0 ] + + data1[ i + 1 ] * data2[ i + 1 ] + + data1[ i + 2 ] * data2[ i + 2 ] + + data1[ i + 3 ] * data2[ i + 3 ]; + } + + /* add any remaining products */ + for( ; i < dataSize; i++ ) { + result += data1[ i ] * data2[ i ]; + } + + return result; } /* Solve the normal equations using the Levinson-Durbin recursion */ -SKP_float Levinsondurbin( /* O prediction error energy */ - SKP_float A[], /* O prediction coefficients [order] */ - const SKP_float corr[], /* I input auto-correlations [order + 1] */ - const SKP_int order /* I prediction order */ +SKP_float Levinsondurbin( /* O prediction error energy */ + SKP_float A[], /* O prediction coefficients [order] */ + const SKP_float corr[], /* I input auto-correlations [order + 1] */ + const SKP_int order /* I prediction order */ ) { - SKP_int i, mHalf, m; - SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2; - - min_nrg = 1e-12f * corr[ 0 ] + 1e-9f; - nrg = corr[ 0 ]; - nrg = SKP_max(min_nrg, nrg); - A[ 0 ] = corr[ 1 ] / nrg; - nrg -= A[ 0 ] * corr[ 1 ]; - nrg = SKP_max(min_nrg, nrg); - - for( m = 1; m < order; m++ ) - { - t = corr[ m + 1 ]; - for( i = 0; i < m; i++ ) { - t -= A[ i ] * corr[ m - i ]; - } - - /* reflection coefficient */ - km = t / nrg; - - /* residual energy */ - nrg -= km * t; - nrg = SKP_max(min_nrg, nrg); - - mHalf = m >> 1; - for( i = 0; i < mHalf; i++ ) { - Atmp1 = A[ i ]; - Atmp2 = A[ m - i - 1 ]; - A[ m - i - 1 ] -= km * Atmp1; - A[ i ] -= km * Atmp2; - } - if( m & 1 ) { - A[ mHalf ] -= km * A[ mHalf ]; - } - A[ m ] = km; - } - - /* return the residual energy */ - return nrg; + SKP_int i, mHalf, m; + SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2; + + min_nrg = 1e-12f * corr[ 0 ] + 1e-9f; + nrg = corr[ 0 ]; + nrg = SKP_max( min_nrg, nrg ); + A[ 0 ] = corr[ 1 ] / nrg; + nrg -= A[ 0 ] * corr[ 1 ]; + nrg = SKP_max(min_nrg, nrg); + + for( m = 1; m < order; m++ ) + { + t = corr[ m + 1 ]; + for( i = 0; i < m; i++ ) { + t -= A[ i ] * corr[ m - i ]; + } + + /* reflection coefficient */ + km = t / nrg; + + /* residual energy */ + nrg -= km * t; + nrg = SKP_max(min_nrg, nrg); + + mHalf = m >> 1; + for( i = 0; i < mHalf; i++ ) { + Atmp1 = A[ i ]; + Atmp2 = A[ m - i - 1 ]; + A[ m - i - 1 ] -= km * Atmp1; + A[ i ] -= km * Atmp2; + } + if( m & 1 ) { + A[ mHalf ] -= km * A[ mHalf ]; + } + A[ m ] = km; + } + + /* return the residual energy */ + return nrg; } /* Chirp (bw expand) LP AR filter */ void Bwexpander( - SKP_float *ar, /* io AR filter to be expanded (without leading 1) */ - const SKP_int d, /* i length of ar */ - const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */ + SKP_float *ar, /* io AR filter to be expanded (without leading 1) */ + const SKP_int d, /* i length of ar */ + const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */ ) { - SKP_int i; - SKP_float cfac = chirp; - - for( i = 0; i < d - 1; i++ ) { - ar[ i ] *= cfac; - cfac *= chirp; - } - ar[ d - 1 ] *= cfac; + SKP_int i; + SKP_float cfac = chirp; + + for( i = 0; i < d - 1; i++ ) { + ar[ i ] *= cfac; + cfac *= chirp; + } + ar[ d - 1 ] *= cfac; } -- GitLab