├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── silk ├── Makefile ├── interface │ ├── SKP_Silk_SDK_API.h │ ├── SKP_Silk_control.h │ ├── SKP_Silk_errors.h │ └── SKP_Silk_typedef.h └── src │ ├── SKP_Silk_A2NLSF.c │ ├── SKP_Silk_A2NLSF_arm.S │ ├── SKP_Silk_AsmHelper.h │ ├── SKP_Silk_AsmPreproc.h │ ├── SKP_Silk_CNG.c │ ├── SKP_Silk_HP_variable_cutoff_FIX.c │ ├── SKP_Silk_Inlines.h │ ├── SKP_Silk_LBRR_reset.c │ ├── SKP_Silk_LPC_inv_pred_gain.c │ ├── SKP_Silk_LPC_synthesis_filter.c │ ├── SKP_Silk_LPC_synthesis_order16.c │ ├── SKP_Silk_LP_variable_cutoff.c │ ├── SKP_Silk_LSF_cos_table.c │ ├── SKP_Silk_LTP_analysis_filter_FIX.c │ ├── SKP_Silk_LTP_scale_ctrl_FIX.c │ ├── SKP_Silk_MA.c │ ├── SKP_Silk_MA_arm.S │ ├── SKP_Silk_NLSF2A.c │ ├── SKP_Silk_NLSF2A_stable.c │ ├── SKP_Silk_NLSF_MSVQ_decode.c │ ├── SKP_Silk_NLSF_MSVQ_encode_FIX.c │ ├── SKP_Silk_NLSF_VQ_rate_distortion_FIX.c │ ├── SKP_Silk_NLSF_VQ_sum_error_FIX.c │ ├── SKP_Silk_NLSF_VQ_sum_error_FIX_arm.S │ ├── SKP_Silk_NLSF_VQ_weights_laroia.c │ ├── SKP_Silk_NLSF_stabilize.c │ ├── SKP_Silk_NSQ.c │ ├── SKP_Silk_NSQ_del_dec.c │ ├── SKP_Silk_PLC.c │ ├── SKP_Silk_PLC.h │ ├── SKP_Silk_SigProc_FIX.h │ ├── SKP_Silk_VAD.c │ ├── SKP_Silk_VQ_nearest_neighbor_FIX.c │ ├── SKP_Silk_allpass_int_arm.S │ ├── SKP_Silk_ana_filt_bank_1.c │ ├── SKP_Silk_ana_filt_bank_1_arm.S │ ├── SKP_Silk_apply_sine_window.c │ ├── SKP_Silk_array_maxabs.c │ ├── SKP_Silk_array_maxabs_arm.S │ ├── SKP_Silk_autocorr.c │ ├── SKP_Silk_biquad.c │ ├── SKP_Silk_biquad_alt.c │ ├── SKP_Silk_burg_modified.c │ ├── SKP_Silk_bwexpander.c │ ├── SKP_Silk_bwexpander_32.c │ ├── SKP_Silk_clz_arm.S │ ├── SKP_Silk_code_signs.c │ ├── SKP_Silk_common_pitch_est_defines.h │ ├── SKP_Silk_control_audio_bandwidth.c │ ├── SKP_Silk_control_codec_FIX.c │ ├── SKP_Silk_corrMatrix_FIX.c │ ├── SKP_Silk_create_init_destroy.c │ ├── SKP_Silk_dec_API.c │ ├── SKP_Silk_decode_core.c │ ├── SKP_Silk_decode_core_arm.S │ ├── SKP_Silk_decode_frame.c │ ├── SKP_Silk_decode_parameters.c │ ├── SKP_Silk_decode_pitch.c │ ├── SKP_Silk_decode_pulses.c │ ├── SKP_Silk_decoder_set_fs.c │ ├── SKP_Silk_define.h │ ├── SKP_Silk_detect_SWB_input.c │ ├── SKP_Silk_div_oabi.c │ ├── SKP_Silk_enc_API.c │ ├── SKP_Silk_encode_frame_FIX.c │ ├── SKP_Silk_encode_parameters.c │ ├── SKP_Silk_encode_pulses.c │ ├── SKP_Silk_find_LPC_FIX.c │ ├── SKP_Silk_find_LTP_FIX.c │ ├── SKP_Silk_find_pitch_lags_FIX.c │ ├── SKP_Silk_find_pred_coefs_FIX.c │ ├── SKP_Silk_gain_quant.c │ ├── SKP_Silk_init_encoder_FIX.c │ ├── SKP_Silk_inner_prod_aligned.c │ ├── SKP_Silk_inner_prod_aligned_arm.S │ ├── SKP_Silk_interpolate.c │ ├── SKP_Silk_k2a.c │ ├── SKP_Silk_k2a_Q16.c │ ├── SKP_Silk_lin2log.c │ ├── SKP_Silk_lin2log_arm.S │ ├── SKP_Silk_log2lin.c │ ├── SKP_Silk_macros.h │ ├── SKP_Silk_macros_arm.h │ ├── SKP_Silk_main.h │ ├── SKP_Silk_main_FIX.h │ ├── SKP_Silk_noise_shape_analysis_FIX.c │ ├── SKP_Silk_pitch_analysis_core.c │ ├── SKP_Silk_pitch_est_defines.h │ ├── SKP_Silk_pitch_est_tables.c │ ├── SKP_Silk_prefilter_FIX.c │ ├── SKP_Silk_prefilter_FIX_arm.S │ ├── SKP_Silk_process_NLSFs_FIX.c │ ├── SKP_Silk_process_gains_FIX.c │ ├── SKP_Silk_quant_LTP_gains_FIX.c │ ├── SKP_Silk_range_coder.c │ ├── SKP_Silk_regularize_correlations_FIX.c │ ├── SKP_Silk_resampler.c │ ├── SKP_Silk_resampler_down2.c │ ├── SKP_Silk_resampler_down2_3.c │ ├── SKP_Silk_resampler_down2_arm.S │ ├── SKP_Silk_resampler_down3.c │ ├── SKP_Silk_resampler_private.h │ ├── SKP_Silk_resampler_private_AR2.c │ ├── SKP_Silk_resampler_private_AR2_arm.S │ ├── SKP_Silk_resampler_private_ARMA4.c │ ├── SKP_Silk_resampler_private_ARMA4_arm.S │ ├── SKP_Silk_resampler_private_IIR_FIR.c │ ├── SKP_Silk_resampler_private_IIR_FIR_arm.S │ ├── SKP_Silk_resampler_private_copy.c │ ├── SKP_Silk_resampler_private_down4.c │ ├── SKP_Silk_resampler_private_down_FIR.c │ ├── SKP_Silk_resampler_private_down_FIR_arm.S │ ├── SKP_Silk_resampler_private_up2_HQ.c │ ├── SKP_Silk_resampler_private_up2_HQ_arm.S │ ├── SKP_Silk_resampler_private_up4.c │ ├── SKP_Silk_resampler_rom.c │ ├── SKP_Silk_resampler_rom.h │ ├── SKP_Silk_resampler_rom_arm.S │ ├── SKP_Silk_resampler_structs.h │ ├── SKP_Silk_resampler_up2.c │ ├── SKP_Silk_resampler_up2_arm.S │ ├── SKP_Silk_residual_energy16_FIX.c │ ├── SKP_Silk_residual_energy_FIX.c │ ├── SKP_Silk_scale_copy_vector16.c │ ├── SKP_Silk_scale_vector.c │ ├── SKP_Silk_schur.c │ ├── SKP_Silk_schur64.c │ ├── SKP_Silk_schur64_arm.S │ ├── SKP_Silk_setup_complexity.h │ ├── SKP_Silk_shell_coder.c │ ├── SKP_Silk_sigm_Q15.c │ ├── SKP_Silk_sigm_Q15_arm.S │ ├── SKP_Silk_solve_LS_FIX.c │ ├── SKP_Silk_sort.c │ ├── SKP_Silk_structs.h │ ├── SKP_Silk_structs_FIX.h │ ├── SKP_Silk_sum_sqr_shift.c │ ├── SKP_Silk_sum_sqr_shift_arm.S │ ├── SKP_Silk_tables.h │ ├── SKP_Silk_tables_LTP.c │ ├── SKP_Silk_tables_NLSF_CB0_10.c │ ├── SKP_Silk_tables_NLSF_CB0_10.h │ ├── SKP_Silk_tables_NLSF_CB0_16.c │ ├── SKP_Silk_tables_NLSF_CB0_16.h │ ├── SKP_Silk_tables_NLSF_CB1_10.c │ ├── SKP_Silk_tables_NLSF_CB1_10.h │ ├── SKP_Silk_tables_NLSF_CB1_16.c │ ├── SKP_Silk_tables_NLSF_CB1_16.h │ ├── SKP_Silk_tables_gain.c │ ├── SKP_Silk_tables_other.c │ ├── SKP_Silk_tables_pitch_lag.c │ ├── SKP_Silk_tables_pulses_per_block.c │ ├── SKP_Silk_tables_sign.c │ ├── SKP_Silk_tables_type_offset.c │ ├── SKP_Silk_tuning_parameters.h │ ├── SKP_Silk_warped_autocorrelation_FIX.c │ └── SKP_Silk_warped_autocorrelation_FIX_arm.S ├── src ├── bin │ └── main.rs ├── decode.rs ├── encode.rs ├── error.rs └── lib.rs └── wrapper.h /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | .idea 4 | *.o 5 | *.a 6 | silk/decoder 7 | test.sh 8 | *.mp3 9 | *.wav 10 | *.silk 11 | *.pcm -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "silk-rs" 3 | version = "0.2.0" 4 | edition = "2021" 5 | license = "MIT" 6 | description = "Rust bindings for silk" 7 | keywords = ["silk", "pcm", "audio"] 8 | repository = "https://github.com/lz1998/silk-rs" 9 | homepage = "https://github.com/lz1998/silk-rs" 10 | readme = "README.md" 11 | 12 | [dependencies] 13 | bytes = "1" 14 | thiserror = "1" 15 | 16 | [build-dependencies] 17 | bindgen = "0.59" 18 | cc = "1" 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 lz1998 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Silk-rs 2 | 3 | ## How to use 4 | 5 | **Encode** 6 | 7 | ```rust 8 | let input = std::fs::read("input.pcm").unwrap(); 9 | let output = encode_silk(input, 24000, 24000, true).unwrap(); 10 | std::fs::write("output.silk", output).unwrap(); 11 | ``` 12 | 13 | **Decode** 14 | 15 | ```rust 16 | let input = std::fs::read("input.silk").unwrap(); 17 | let output = decode_silk(input, 24000).unwrap(); 18 | std::fs::write("output.pcm", output).unwrap(); 19 | ``` -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | extern crate cc; 3 | 4 | use std::env; 5 | use std::path::{Path, PathBuf}; 6 | 7 | fn recursion>(v: &mut Vec, dir: P) -> std::io::Result<()> { 8 | let rd = std::fs::read_dir(dir)?; 9 | for x in rd { 10 | let de = x?; 11 | let path = de.path(); 12 | if path.is_dir() { 13 | recursion(v, path)?; 14 | } else { 15 | let path = path.into_os_string().into_string().unwrap(); 16 | if path.ends_with(".c") { 17 | v.push(path); 18 | } 19 | } 20 | } 21 | Ok(()) 22 | } 23 | 24 | fn main() { 25 | let mut files = Vec::new(); 26 | recursion(&mut files, "silk/interface").unwrap(); 27 | recursion(&mut files, "silk/src").unwrap(); 28 | println!("cargo:rustc-link-lib=static=silk"); 29 | println!("cargo:rerun-if-changed=wrapper.h"); 30 | cc::Build::new() 31 | .includes(["silk/src", "silk/interface"]) 32 | .files(files) 33 | .compile("silk"); 34 | 35 | let bindings = bindgen::Builder::default() 36 | .header("wrapper.h") 37 | .parse_callbacks(Box::new(bindgen::CargoCallbacks)) 38 | .generate() 39 | .expect("Unable to generate bindings"); 40 | 41 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 42 | bindings 43 | .write_to_file(out_path.join("bindings.rs")) 44 | .expect("Couldn't write bindings!"); 45 | } 46 | -------------------------------------------------------------------------------- /silk/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Silk SDK 3 | # 4 | # Copyright (c) 2012, Skype Limited 5 | # All rights reserved. 6 | # 7 | 8 | #Platform detection and settings 9 | 10 | BUILD_OS := $(shell uname | sed -e 's/^.*Darwin.*/MacOS-X/ ; s/^.*CYGWIN.*/Windows/') 11 | 12 | BUILD_ARCHITECTURE := $(shell uname -m | sed -e 's/i686/i386/') 13 | 14 | EXESUFFIX = 15 | LIBPREFIX = lib 16 | LIBSUFFIX = .a 17 | OBJSUFFIX = .o 18 | 19 | CC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) 20 | CXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX) 21 | AR = $(TOOLCHAIN_PREFIX)ar 22 | RANLIB = $(TOOLCHAIN_PREFIX)ranlib 23 | CP = $(TOOLCHAIN_PREFIX)cp 24 | 25 | cppflags-from-defines = $(addprefix -D,$(1)) 26 | cppflags-from-includes = $(addprefix -I,$(1)) 27 | ldflags-from-ldlibdirs = $(addprefix -L,$(1)) 28 | ldlibs-from-libs = $(addprefix -l,$(1)) 29 | 30 | ifneq (,$(TARGET_CPU)) 31 | CFLAGS += -mcpu=$(TARGET_CPU) 32 | ifneq (,$(TARGET_TUNE)) 33 | CFLAGS += -mtune=$(TARGET_TUNE) 34 | else 35 | CFLAGS += -mtune=$(TARGET_CPU) 36 | endif 37 | endif 38 | ifneq (,$(TARGET_FPU)) 39 | CFLAGS += -mfpu=$(TARGET_FPU) 40 | endif 41 | ifneq (,$(TARGET_ARCH)) 42 | CFLAGS += -march=$(TARGET_ARCH) 43 | endif 44 | # Helper to make NEON testing easier, when using USE_NEON=yes do not set TARGET_CPU or TARGET_FPU 45 | ifeq (yes,$(USE_NEON)) 46 | CFLAGS += -mcpu=cortex-a8 -mfloat-abi=softfp -mfpu=neon 47 | endif 48 | 49 | 50 | CFLAGS += -Wall -enable-threads -O3 51 | 52 | CFLAGS += $(call cppflags-from-defines,$(CDEFINES)) 53 | CFLAGS += $(call cppflags-from-defines,$(ADDED_DEFINES)) 54 | CFLAGS += $(call cppflags-from-includes,$(CINCLUDES)) 55 | LDFLAGS += $(call ldflags-from-ldlibdirs,$(LDLIBDIRS)) 56 | LDLIBS += $(call ldlibs-from-libs,$(LIBS)) 57 | 58 | COMPILE.c.cmdline = $(CC) -c $(CFLAGS) $(ADDED_CFLAGS) -o $@ $< 59 | COMPILE.S.cmdline = $(CC) -c $(CFLAGS) $(ADDED_CFLAGS) -o $@ $< 60 | COMPILE.cpp.cmdline = $(CXX) -c $(CFLAGS) $(ADDED_CFLAGS) -o $@ $< 61 | LINK.o = $(CXX) $(LDPREFLAGS) $(LDFLAGS) 62 | LINK.o.cmdline = $(LINK.o) $^ $(LDLIBS) -o $@$(EXESUFFIX) 63 | ARCHIVE.cmdline = $(AR) $(ARFLAGS) $@ $^ && $(RANLIB) $@ 64 | 65 | %$(OBJSUFFIX):%.c 66 | $(COMPILE.c.cmdline) 67 | 68 | %$(OBJSUFFIX):%.cpp 69 | $(COMPILE.cpp.cmdline) 70 | 71 | %$(OBJSUFFIX):%.S 72 | $(COMPILE.S.cmdline) 73 | 74 | # Directives 75 | 76 | CINCLUDES += interface src test 77 | 78 | # VPATH e.g. VPATH = src:../headers 79 | VPATH = ./ \ 80 | interface \ 81 | src \ 82 | test 83 | 84 | # Variable definitions 85 | LIB_NAME = SKP_SILK_SDK 86 | TARGET = $(LIBPREFIX)$(LIB_NAME)$(LIBSUFFIX) 87 | 88 | SRCS_C = $(wildcard src/*.c) 89 | ifneq (,$(TOOLCHAIN_PREFIX)) 90 | SRCS_S = $(wildcard src/*.S) 91 | OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C)) $(patsubst %.S,%$(OBJSUFFIX),$(SRCS_S)) 92 | else 93 | OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C)) 94 | endif 95 | 96 | ENCODER_SRCS_C = test/Encoder.c 97 | ENCODER_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(ENCODER_SRCS_C)) 98 | 99 | DECODER_SRCS_C = test/Decoder.c 100 | DECODER_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(DECODER_SRCS_C)) 101 | 102 | SIGNALCMP_SRCS_C = test/signalCompare.c 103 | SIGNALCMP_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SIGNALCMP_SRCS_C)) 104 | 105 | LIBS = \ 106 | $(LIB_NAME) 107 | 108 | LDLIBDIRS = ./ 109 | 110 | # Rules 111 | default: all 112 | 113 | all: $(TARGET) decoder 114 | 115 | lib: $(TARGET) 116 | 117 | $(TARGET): $(OBJS) 118 | $(ARCHIVE.cmdline) 119 | 120 | encoder$(EXESUFFIX): $(ENCODER_OBJS) 121 | $(LINK.o.cmdline) 122 | 123 | decoder$(EXESUFFIX): $(DECODER_OBJS) 124 | $(LINK.o.cmdline) 125 | 126 | signalcompare$(EXESUFFIX): $(SIGNALCMP_OBJS) 127 | $(LINK.o.cmdline) 128 | 129 | clean: 130 | $(RM) $(TARGET)* $(OBJS) $(ENCODER_OBJS) $(DECODER_OBJS) \ 131 | $(SIGNALCMP_OBJS) $(TEST_OBJS) \ 132 | encoder$(EXESUFFIX) decoder$(EXESUFFIX) signalcompare$(EXESUFFIX) 133 | 134 | -------------------------------------------------------------------------------- /silk/interface/SKP_Silk_control.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_CONTROL_H 29 | #define SKP_SILK_CONTROL_H 30 | 31 | #include "SKP_Silk_typedef.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" 35 | { 36 | #endif 37 | 38 | /***********************************************/ 39 | /* Structure for controlling encoder operation */ 40 | /***********************************************/ 41 | typedef struct { 42 | /* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000 */ 43 | SKP_int32 API_sampleRate; 44 | 45 | /* I: Maximum internal sampling rate in Hertz; 8000/12000/16000/24000 */ 46 | SKP_int32 maxInternalSampleRate; 47 | 48 | /* I: Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms */ 49 | SKP_int packetSize; 50 | 51 | /* I: Bitrate during active speech in bits/second; internally limited */ 52 | SKP_int32 bitRate; 53 | 54 | /* I: Uplink packet loss in percent (0-100) */ 55 | SKP_int packetLossPercentage; 56 | 57 | /* I: Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity */ 58 | SKP_int complexity; 59 | 60 | /* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */ 61 | SKP_int useInBandFEC; 62 | 63 | /* I: Flag to enable discontinuous transmission (DTX); 0/1 */ 64 | SKP_int useDTX; 65 | } SKP_SILK_SDK_EncControlStruct; 66 | 67 | /**************************************************************************/ 68 | /* Structure for controlling decoder operation and reading decoder status */ 69 | /**************************************************************************/ 70 | typedef struct { 71 | /* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000 */ 72 | SKP_int32 API_sampleRate; 73 | 74 | /* O: Number of samples per frame */ 75 | SKP_int frameSize; 76 | 77 | /* O: Frames per packet 1, 2, 3, 4, 5 */ 78 | SKP_int framesPerPacket; 79 | 80 | /* O: Flag to indicate that the decoder has remaining payloads internally */ 81 | SKP_int moreInternalDecoderFrames; 82 | 83 | /* O: Distance between main payload and redundant payload in packets */ 84 | SKP_int inBandFECOffset; 85 | } SKP_SILK_SDK_DecControlStruct; 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /silk/interface/SKP_Silk_errors.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_ERRORS_H 29 | #define SKP_SILK_ERRORS_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #endif 35 | 36 | /******************/ 37 | /* Error messages */ 38 | /******************/ 39 | #define SKP_SILK_NO_ERROR 0 40 | 41 | /**************************/ 42 | /* Encoder error messages */ 43 | /**************************/ 44 | 45 | /* Input length is not a multiplum of 10 ms, or length is longer than the packet length */ 46 | #define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -1 47 | 48 | /* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */ 49 | #define SKP_SILK_ENC_FS_NOT_SUPPORTED -2 50 | 51 | /* Packet size not 20, 40, 60, 80 or 100 ms */ 52 | #define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -3 53 | 54 | /* Allocated payload buffer too short */ 55 | #define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4 56 | 57 | /* Loss rate not between 0 and 100 percent */ 58 | #define SKP_SILK_ENC_INVALID_LOSS_RATE -5 59 | 60 | /* Complexity setting not valid, use 0, 1 or 2 */ 61 | #define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -6 62 | 63 | /* Inband FEC setting not valid, use 0 or 1 */ 64 | #define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -7 65 | 66 | /* DTX setting not valid, use 0 or 1 */ 67 | #define SKP_SILK_ENC_INVALID_DTX_SETTING -8 68 | 69 | /* Internal encoder error */ 70 | #define SKP_SILK_ENC_INTERNAL_ERROR -9 71 | 72 | /**************************/ 73 | /* Decoder error messages */ 74 | /**************************/ 75 | 76 | /* Output sampling frequency lower than internal decoded sampling frequency */ 77 | #define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -10 78 | 79 | /* Payload size exceeded the maximum allowed 1024 bytes */ 80 | #define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -11 81 | 82 | /* Payload has bit errors */ 83 | #define SKP_SILK_DEC_PAYLOAD_ERROR -12 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_A2NLSF_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | #if EMBEDDED_ARM>=6 32 | 33 | VARDEF y32, r3 34 | VARDEF pn1, r4 35 | VARDEF pn2, r5 36 | VARDEF lo, r6 37 | VARDEF hi, r8 38 | .globl SYM(SKP_Silk_A2NLSF_eval_poly) 39 | SYM(SKP_Silk_A2NLSF_eval_poly): 40 | stmdb sp!, {r4-r8, fp, ip, lr} 41 | add fp, sp, #28 42 | add r0, r0, r2, lsl #2 43 | ldr y32, [r0], #-4 44 | tst r2, #1 45 | beq LR(1, f) 46 | ldr pn1, [r0], #-4 47 | sub r2, r2, #1 48 | mov r1, r1, lsl #4 49 | L(0) 50 | smull lo, hi, y32, r1 51 | subs r2, r2, #1 52 | add y32, pn1, hi, lsl #16 53 | ldr pn1, [r0], #-4 54 | add y32, y32, lo, lsr #16 55 | bgt LR(0, b) 56 | smull lo, hi, y32, r1 57 | add y32, pn1, hi, lsl #16 58 | add r0, y32, lo, lsr #16 59 | ldmia sp!, {r4-r8, fp, ip, pc} 60 | 61 | L(1)/*EVEN:*/ 62 | add r0, r0, #4 63 | ldmdb r0!, {pn1, pn2} 64 | sub r2, r2, #2 65 | mov r1, r1, lsl #4 66 | L(0) 67 | smull lo, hi, y32, r1 68 | subs r2, r2, #2 69 | add y32, pn2, hi, lsl #16 70 | add y32, y32, lo, lsr #16 71 | smull lo, hi, y32, r1 72 | add y32, pn1, hi, lsl #16 73 | ldmdb r0!, {pn1, pn2} 74 | add y32, y32, lo, lsr #16 75 | bgt LR(0, b) 76 | smull lo, hi, y32, r1 77 | add y32, pn2, hi, lsl #16 78 | add y32, y32, lo, lsr #16 79 | smull lo, hi, y32, r1 80 | add y32, pn1, hi, lsl #16 81 | add r0, y32, lo, lsr #16 82 | ldmia sp!, {r4-r8, fp, ip, pc} 83 | END 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_LBRR_reset.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main.h" 29 | 30 | /* Resets LBRR buffer, used if packet size changes */ 31 | void SKP_Silk_LBRR_reset( 32 | SKP_Silk_encoder_state *psEncC /* I/O state */ 33 | ) 34 | { 35 | SKP_int i; 36 | 37 | for( i = 0; i < MAX_LBRR_DELAY; i++ ) { 38 | psEncC->LBRR_buffer[ i ].usage = SKP_SILK_NO_LBRR; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_LTP_analysis_filter_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main_FIX.h" 29 | 30 | void SKP_Silk_LTP_analysis_filter_FIX( 31 | SKP_int16 *LTP_res, /* O: LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length ) */ 32 | const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */ 33 | const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each NB_SUBFR subframe */ 34 | const SKP_int pitchL[ NB_SUBFR ], /* I: Pitch lag, one for each subframe */ 35 | const SKP_int32 invGains_Q16[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */ 36 | const SKP_int subfr_length, /* I: Length of each subframe */ 37 | const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */ 38 | ) 39 | { 40 | const SKP_int16 *x_ptr, *x_lag_ptr; 41 | SKP_int16 Btmp_Q14[ LTP_ORDER ]; 42 | SKP_int16 *LTP_res_ptr; 43 | SKP_int k, i, j; 44 | SKP_int32 LTP_est; 45 | 46 | x_ptr = x; 47 | LTP_res_ptr = LTP_res; 48 | for( k = 0; k < NB_SUBFR; k++ ) { 49 | 50 | x_lag_ptr = x_ptr - pitchL[ k ]; 51 | for( i = 0; i < LTP_ORDER; i++ ) { 52 | Btmp_Q14[ i ] = LTPCoef_Q14[ k * LTP_ORDER + i ]; 53 | } 54 | 55 | /* LTP analysis FIR filter */ 56 | for( i = 0; i < subfr_length + pre_length; i++ ) { 57 | LTP_res_ptr[ i ] = x_ptr[ i ]; 58 | 59 | /* Long-term prediction */ 60 | LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] ); 61 | for( j = 1; j < LTP_ORDER; j++ ) { 62 | LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] ); 63 | } 64 | LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0 65 | 66 | /* Subtract long-term prediction */ 67 | LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est ); 68 | 69 | /* Scale residual */ 70 | LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] ); 71 | 72 | x_lag_ptr++; 73 | } 74 | 75 | /* Update pointers */ 76 | LTP_res_ptr += subfr_length + pre_length; 77 | x_ptr += subfr_length; 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_LTP_scale_ctrl_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main_FIX.h" 29 | 30 | #define NB_THRESHOLDS 11 31 | 32 | /* Table containing trained thresholds for LTP scaling */ 33 | static const SKP_int16 LTPScaleThresholds_Q15[ NB_THRESHOLDS ] = 34 | { 35 | 31129, 26214, 16384, 13107, 9830, 6554, 36 | 4915, 3276, 2621, 2458, 0 37 | }; 38 | 39 | void SKP_Silk_LTP_scale_ctrl_FIX( 40 | SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state FIX */ 41 | SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control FIX */ 42 | ) 43 | { 44 | SKP_int round_loss, frames_per_packet; 45 | SKP_int g_out_Q5, g_limit_Q15, thrld1_Q15, thrld2_Q15; 46 | 47 | /* 1st order high-pass filter */ 48 | psEnc->HPLTPredCodGain_Q7 = SKP_max_int( psEncCtrl->LTPredCodGain_Q7 - psEnc->prevLTPredCodGain_Q7, 0 ) 49 | + SKP_RSHIFT_ROUND( psEnc->HPLTPredCodGain_Q7, 1 ); 50 | 51 | psEnc->prevLTPredCodGain_Q7 = psEncCtrl->LTPredCodGain_Q7; 52 | 53 | /* combine input and filtered input */ 54 | g_out_Q5 = SKP_RSHIFT_ROUND( SKP_RSHIFT( psEncCtrl->LTPredCodGain_Q7, 1 ) + SKP_RSHIFT( psEnc->HPLTPredCodGain_Q7, 1 ), 3 ); 55 | g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) ); 56 | 57 | /* Default is minimum scaling */ 58 | psEncCtrl->sCmn.LTP_scaleIndex = 0; 59 | 60 | /* Round the loss measure to whole pct */ 61 | round_loss = ( SKP_int )psEnc->sCmn.PacketLoss_perc; 62 | 63 | /* Only scale if first frame in packet 0% */ 64 | if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) { 65 | 66 | frames_per_packet = SKP_DIV32_16( psEnc->sCmn.PacketSize_ms, FRAME_LENGTH_MS ); 67 | 68 | round_loss += frames_per_packet - 1; 69 | thrld1_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss, NB_THRESHOLDS - 1 ) ]; 70 | thrld2_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ]; 71 | 72 | if( g_limit_Q15 > thrld1_Q15 ) { 73 | /* Maximum scaling */ 74 | psEncCtrl->sCmn.LTP_scaleIndex = 2; 75 | } else if( g_limit_Q15 > thrld2_Q15 ) { 76 | /* Medium scaling */ 77 | psEncCtrl->sCmn.LTP_scaleIndex = 1; 78 | } 79 | } 80 | psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ]; 81 | } 82 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_NLSF2A_stable.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main.h" 29 | 30 | /* Convert NLSF parameters to stable AR prediction filter coefficients */ 31 | void SKP_Silk_NLSF2A_stable( 32 | SKP_int16 pAR_Q12[ MAX_LPC_ORDER ], /* O Stabilized AR coefs [LPC_order] */ 33 | const SKP_int pNLSF[ MAX_LPC_ORDER ], /* I NLSF vector [LPC_order] */ 34 | const SKP_int LPC_order /* I LPC/LSF order */ 35 | ) 36 | { 37 | SKP_int i; 38 | SKP_int32 invGain_Q30; 39 | 40 | SKP_Silk_NLSF2A( pAR_Q12, pNLSF, LPC_order ); 41 | 42 | /* Ensure stable LPCs */ 43 | for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { 44 | if( SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, pAR_Q12, LPC_order ) == 1 ) { 45 | SKP_Silk_bwexpander( pAR_Q12, LPC_order, 65536 - SKP_SMULBB( 10 + i, i ) ); /* 10_Q16 = 0.00015 */ 46 | } else { 47 | break; 48 | } 49 | } 50 | 51 | /* Reached the last iteration */ 52 | if( i == MAX_LPC_STABILIZE_ITERATIONS ) { 53 | SKP_assert( 0 ); 54 | for( i = 0; i < LPC_order; i++ ) { 55 | pAR_Q12[ i ] = 0; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main_FIX.h" 29 | 30 | /* Rate-Distortion calculations for multiple input data vectors */ 31 | void SKP_Silk_NLSF_VQ_rate_distortion_FIX( 32 | SKP_int32 *pRD_Q20, /* O Rate-distortion values [psNLSF_CBS->nVectors*N] */ 33 | const SKP_Silk_NLSF_CBS *psNLSF_CBS, /* I NLSF codebook stage struct */ 34 | const SKP_int *in_Q15, /* I Input vectors to be quantized */ 35 | const SKP_int *w_Q6, /* I Weight vector */ 36 | const SKP_int32 *rate_acc_Q5, /* I Accumulated rates from previous stage */ 37 | const SKP_int mu_Q15, /* I Weight between weighted error and rate */ 38 | const SKP_int N, /* I Number of input vectors to be quantized */ 39 | const SKP_int LPC_order /* I LPC order */ 40 | ) 41 | { 42 | SKP_int i, n; 43 | SKP_int32 *pRD_vec_Q20; 44 | 45 | /* Compute weighted quantization errors for all input vectors over one codebook stage */ 46 | SKP_Silk_NLSF_VQ_sum_error_FIX( pRD_Q20, in_Q15, w_Q6, psNLSF_CBS->CB_NLSF_Q15, 47 | N, psNLSF_CBS->nVectors, LPC_order ); 48 | 49 | /* Loop over input vectors */ 50 | pRD_vec_Q20 = pRD_Q20; 51 | for( n = 0; n < N; n++ ) { 52 | /* Add rate cost to error for each codebook vector */ 53 | for( i = 0; i < psNLSF_CBS->nVectors; i++ ) { 54 | SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] >= 0 ); 55 | SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] <= SKP_int16_MAX ); 56 | pRD_vec_Q20[ i ] = SKP_SMLABB( pRD_vec_Q20[ i ], rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ], mu_Q15 ); 57 | SKP_assert( pRD_vec_Q20[ i ] >= 0 ); 58 | } 59 | pRD_vec_Q20 += psNLSF_CBS->nVectors; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_NLSF_VQ_weights_laroia.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_SigProc_FIX.h" 29 | 30 | /* 31 | R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP 32 | Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech, 33 | Signal Processing, pp. 641-644, 1991. 34 | */ 35 | 36 | #define Q_OUT 6 37 | #define MIN_NDELTA 3 38 | 39 | /* Laroia low complexity NLSF weights */ 40 | void SKP_Silk_NLSF_VQ_weights_laroia( 41 | SKP_int *pNLSFW_Q6, /* O: Pointer to input vector weights [D x 1] */ 42 | const SKP_int *pNLSF_Q15, /* I: Pointer to input vector [D x 1] */ 43 | const SKP_int D /* I: Input vector dimension (even) */ 44 | ) 45 | { 46 | SKP_int k; 47 | SKP_int32 tmp1_int, tmp2_int; 48 | 49 | /* Check that we are guaranteed to end up within the required range */ 50 | SKP_assert( D > 0 ); 51 | SKP_assert( ( D & 1 ) == 0 ); 52 | 53 | /* First value */ 54 | tmp1_int = SKP_max_int( pNLSF_Q15[ 0 ], MIN_NDELTA ); 55 | tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int ); 56 | tmp2_int = SKP_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], MIN_NDELTA ); 57 | tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int ); 58 | pNLSFW_Q6[ 0 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX ); 59 | SKP_assert( pNLSFW_Q6[ 0 ] > 0 ); 60 | 61 | /* Main loop */ 62 | for( k = 1; k < D - 1; k += 2 ) { 63 | tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], MIN_NDELTA ); 64 | tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int ); 65 | pNLSFW_Q6[ k ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX ); 66 | SKP_assert( pNLSFW_Q6[ k ] > 0 ); 67 | 68 | tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], MIN_NDELTA ); 69 | tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int ); 70 | pNLSFW_Q6[ k + 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX ); 71 | SKP_assert( pNLSFW_Q6[ k + 1 ] > 0 ); 72 | } 73 | 74 | /* Last value */ 75 | tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], MIN_NDELTA ); 76 | tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int ); 77 | pNLSFW_Q6[ D - 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX ); 78 | SKP_assert( pNLSFW_Q6[ D - 1 ] > 0 ); 79 | } 80 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_allpass_int_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM >= 5 33 | VARDEF A, r2 34 | VARDEF len, r4 35 | VARDEF S00, r5 36 | VARDEF ink1, r6 37 | VARDEF ink2, r8 38 | VARDEF Y2, sb 39 | VARDEF outk1, sl 40 | VARDEF outk2, ip 41 | 42 | .globl SYM(SKP_Silk_allpass_int) 43 | SYM(SKP_Silk_allpass_int): 44 | stmdb sp!, {r4-r10, fp, ip, lr} 45 | add fp, sp, #36 46 | .set len_offset, 40 47 | ldr len, [sp, #len_offset] 48 | ldr S00, [r1] 49 | movs A, A, lsl #17 50 | sub len, len, #1 51 | ldmia r0!, {ink1,ink2} 52 | bge LR(1, f)/*AgeZero*/ 53 | L(0) 54 | sub Y2, ink1, S00 55 | smlawt outk1, Y2, A, ink1 56 | add S00, Y2, outk1 57 | subs len, len, #2 58 | sub Y2, ink2, S00 59 | smlawt outk2, Y2, A, ink2 60 | #ifdef _WINRT 61 | ble LR(3, f) 62 | ldmia r0!, {ink1,ink2} 63 | L(3) 64 | #else 65 | ldmgtia r0!, {ink1,ink2} 66 | #endif 67 | add S00, Y2, outk2 68 | stmia r3!, {outk1, outk2} 69 | bgt LR(0, b) 70 | #ifdef _WINRT 71 | bne LR(2, f) 72 | ldr ink1, [r0], #4 73 | sub Y2, ink1, S00 74 | smlawt outk1, Y2, A, ink1 75 | add S00, Y2, outk1 76 | str outk1, [r3] 77 | L(2) 78 | #else 79 | ldreq ink1, [r0], #4 80 | subeq Y2, ink1, S00 81 | smlawteq outk1, Y2, A, ink1 82 | addeq S00, Y2, outk1 83 | streq outk1, [r3] 84 | #endif 85 | str S00, [r1] 86 | ldmia sp!, {r4-r10, fp, ip, pc} 87 | 88 | L(1)/*AgeZero:*/ 89 | sub Y2, ink1, S00 90 | smlawt outk1, Y2, A, S00 91 | add S00, Y2, outk1 92 | subs len, len, #2 93 | sub Y2, ink2, S00 94 | smlawt outk2, Y2, A, S00 95 | #ifdef _WINRT 96 | ble LR(3, f) 97 | ldmia r0!, {ink1,ink2} 98 | L(3) 99 | #else 100 | ldmgtia r0!, {ink1,ink2} 101 | #endif 102 | add S00, Y2, outk2 103 | stmia r3!, {outk1, outk2} 104 | bgt LR(1, b) 105 | #ifdef _WINRT 106 | bne LR(2, f) 107 | ldr ink1, [r0], #4 108 | sub Y2, ink1, S00 109 | smlawt outk1, Y2, A, S00 110 | add S00, Y2, outk1 111 | str outk1, [r3] 112 | L(2) 113 | #else 114 | ldreq ink1, [r0], #4 115 | subeq Y2, ink1, S00 116 | smlawteq outk1, Y2, A, S00 117 | addeq S00, Y2, outk1 118 | streq outk1, [r3] 119 | #endif 120 | str S00, [r1] 121 | ldmia sp!, {r4-r10, fp, ip, pc} 122 | END 123 | #endif 124 | #endif 125 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_array_maxabs.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_int16_array_maxabs.c * 30 | * * 31 | * Function that returns the maximum absolut value of * 32 | * the input vector * 33 | * * 34 | * Copyright 2006 (c), Skype Limited * 35 | * Date: 060221 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | 39 | /* Function that returns the maximum absolut value of the input vector */ 40 | #if (EMBEDDED_ARM<4) 41 | SKP_int16 SKP_Silk_int16_array_maxabs( /* O Maximum absolute value, max: 2^15-1 */ 42 | const SKP_int16 *vec, /* I Input vector [len] */ 43 | const SKP_int32 len /* I Length of input vector */ 44 | ) 45 | { 46 | SKP_int32 max = 0, i, lvl = 0, ind; 47 | if( len == 0 ) return 0; 48 | 49 | ind = len - 1; 50 | max = SKP_SMULBB( vec[ ind ], vec[ ind ] ); 51 | for( i = len - 2; i >= 0; i-- ) { 52 | lvl = SKP_SMULBB( vec[ i ], vec[ i ] ); 53 | if( lvl > max ) { 54 | max = lvl; 55 | ind = i; 56 | } 57 | } 58 | 59 | /* Do not return 32768, as it will not fit in an int16 so may lead to problems later on */ 60 | if( max >= 1073676289 ) { // (2^15-1)^2 = 1073676289 61 | return( SKP_int16_MAX ); 62 | } else { 63 | if( vec[ ind ] < 0 ) { 64 | return( -vec[ ind ] ); 65 | } else { 66 | return( vec[ ind ] ); 67 | } 68 | } 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_biquad.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_biquad.c * 30 | * * 31 | * Second order ARMA filter * 32 | * Can handle slowly varying filter coefficients * 33 | * * 34 | * Copyright 2006 (c), Skype Limited * 35 | * Date: 060221 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | 39 | /* Second order ARMA filter */ 40 | /* Can handle slowly varying filter coefficients */ 41 | void SKP_Silk_biquad( 42 | const SKP_int16 *in, /* I: input signal */ 43 | const SKP_int16 *B, /* I: MA coefficients, Q13 [3] */ 44 | const SKP_int16 *A, /* I: AR coefficients, Q13 [2] */ 45 | SKP_int32 *S, /* I/O: state vector [2] */ 46 | SKP_int16 *out, /* O: output signal */ 47 | const SKP_int32 len /* I: signal length */ 48 | ) 49 | { 50 | SKP_int k, in16; 51 | SKP_int32 A0_neg, A1_neg, S0, S1, out32, tmp32; 52 | 53 | S0 = S[ 0 ]; 54 | S1 = S[ 1 ]; 55 | A0_neg = -A[ 0 ]; 56 | A1_neg = -A[ 1 ]; 57 | for( k = 0; k < len; k++ ) { 58 | /* S[ 0 ], S[ 1 ]: Q13 */ 59 | in16 = in[ k ]; 60 | out32 = SKP_SMLABB( S0, in16, B[ 0 ] ); 61 | 62 | S0 = SKP_SMLABB( S1, in16, B[ 1 ] ); 63 | S0 += SKP_LSHIFT( SKP_SMULWB( out32, A0_neg ), 3 ); 64 | 65 | S1 = SKP_LSHIFT( SKP_SMULWB( out32, A1_neg ), 3 ); 66 | S1 = SKP_SMLABB( S1, in16, B[ 2 ] ); 67 | tmp32 = SKP_RSHIFT_ROUND( out32, 13 ) + 1; 68 | out[ k ] = (SKP_int16)SKP_SAT16( tmp32 ); 69 | } 70 | S[ 0 ] = S0; 71 | S[ 1 ] = S1; 72 | } 73 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_biquad_alt.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_biquad_alt.c * 30 | * * 31 | * Second order ARMA filter * 32 | * Can handle slowly varying filter coefficients * 33 | * */ 34 | #include "SKP_Silk_SigProc_FIX.h" 35 | 36 | 37 | /* Second order ARMA filter, alternative implementation */ 38 | void SKP_Silk_biquad_alt( 39 | const SKP_int16 *in, /* I: Input signal */ 40 | const SKP_int32 *B_Q28, /* I: MA coefficients [3] */ 41 | const SKP_int32 *A_Q28, /* I: AR coefficients [2] */ 42 | SKP_int32 *S, /* I/O: State vector [2] */ 43 | SKP_int16 *out, /* O: Output signal */ 44 | const SKP_int32 len /* I: Signal length (must be even) */ 45 | ) 46 | { 47 | /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ 48 | SKP_int k; 49 | SKP_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14; 50 | 51 | /* Negate A_Q28 values and split in two parts */ 52 | A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */ 53 | A0_U_Q28 = SKP_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */ 54 | A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */ 55 | A1_U_Q28 = SKP_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */ 56 | 57 | for( k = 0; k < len; k++ ) { 58 | /* S[ 0 ], S[ 1 ]: Q12 */ 59 | inval = in[ k ]; 60 | out32_Q14 = SKP_LSHIFT( SKP_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 ); 61 | 62 | S[ 0 ] = S[1] + SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A0_L_Q28 ), 14 ); 63 | S[ 0 ] = SKP_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 ); 64 | S[ 0 ] = SKP_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval); 65 | 66 | S[ 1 ] = SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A1_L_Q28 ), 14 ); 67 | S[ 1 ] = SKP_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 ); 68 | S[ 1 ] = SKP_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval ); 69 | 70 | /* Scale back to Q0 and saturate */ 71 | out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_bwexpander.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_SigProc_FIX.h" 29 | 30 | /* Chirp (bandwidth expand) LP AR filter */ 31 | void SKP_Silk_bwexpander( 32 | SKP_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */ 33 | const SKP_int d, /* I Length of ar */ 34 | SKP_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */ 35 | ) 36 | { 37 | SKP_int i; 38 | SKP_int32 chirp_minus_one_Q16; 39 | 40 | chirp_minus_one_Q16 = chirp_Q16 - 65536; 41 | 42 | /* NB: Dont use SKP_SMULWB, instead of SKP_RSHIFT_ROUND( SKP_MUL() , 16 ), below. */ 43 | /* Bias in SKP_SMULWB can lead to unstable filters */ 44 | for( i = 0; i < d - 1; i++ ) { 45 | ar[ i ] = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ i ] ), 16 ); 46 | chirp_Q16 += SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); 47 | } 48 | ar[ d - 1 ] = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ d - 1 ] ), 16 ); 49 | } 50 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_bwexpander_32.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_SigProc_FIX.h" 29 | 30 | /* Chirp (bandwidth expand) LP AR filter */ 31 | void SKP_Silk_bwexpander_32( 32 | SKP_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */ 33 | const SKP_int d, /* I Length of ar */ 34 | SKP_int32 chirp_Q16 /* I Chirp factor in Q16 */ 35 | ) 36 | { 37 | SKP_int i; 38 | SKP_int32 tmp_chirp_Q16; 39 | 40 | tmp_chirp_Q16 = chirp_Q16; 41 | for( i = 0; i < d - 1; i++ ) { 42 | ar[ i ] = SKP_SMULWW( ar[ i ], tmp_chirp_Q16 ); 43 | tmp_chirp_Q16 = SKP_SMULWW( chirp_Q16, tmp_chirp_Q16 ); 44 | } 45 | ar[ d - 1 ] = SKP_SMULWW( ar[ d - 1 ], tmp_chirp_Q16 ); 46 | } 47 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_clz_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | #if (EMBEDDED_ARM>0) && (EMBEDDED_ARM<5) 32 | 33 | .globl SYM(SKP_Silk_CLZ16) 34 | .globl SYM(SKP_Silk_CLZ32) 35 | 36 | SYM(SKP_Silk_CLZ16): 37 | str lr, [sp, #-4]! 38 | 39 | mov r2, r0 40 | mov r0, #0 41 | ands r1, r2, #0xF000 42 | movne r1, r2, asr #12 43 | bne 0f 44 | add r0, r0, #4 45 | ands r1, r2, #0xF00 46 | movne r1, r2, asr #8 47 | bne 0f 48 | add r0, r0, #4 49 | ands r1, r2, #0xF0 50 | movne r1, r2, asr #4 51 | bne 0f 52 | add r0, r0, #4 53 | mov r1, r2 54 | 0: 55 | ands r2, r1, #0x8 56 | bne 1f 57 | add r0, r0, #1 58 | ands r2, r1, #0x4 59 | bne 1f 60 | add r0, r0, #1 61 | ands r2, r1, #0x2 62 | bne 1f 63 | add r0, r0, #1 64 | ands r2, r1, #0x1 65 | bne 1f 66 | add r0, r0, #1 67 | 1: 68 | ldr pc, [sp], #4 69 | 70 | SYM(SKP_Silk_CLZ32): 71 | 72 | str lr, [sp, #-4]! 73 | 74 | mov r2, r0 75 | mov r0, #0 76 | ands r1, r2, #0xF0000000 77 | movne r1, r2, asr #28 78 | bne 0f 79 | add r0, r0, #4 80 | ands r1, r2, #0xF000000 81 | movne r1, r2, asr #24 82 | bne 0f 83 | add r0, r0, #4 84 | ands r1, r2, #0xF00000 85 | movne r1, r2, asr #20 86 | bne 0f 87 | add r0, r0, #4 88 | ands r1, r2, #0xF0000 89 | movne r1, r2, asr #16 90 | bne 0f 91 | add r0, r0, #4 92 | ands r1, r2, #0xF000 93 | movne r1, r2, asr #12 94 | bne 0f 95 | add r0, r0, #4 96 | ands r1, r2, #0xF00 97 | movne r1, r2, asr #8 98 | bne 0f 99 | add r0, r0, #4 100 | ands r1, r2, #0xF0 101 | movne r1, r2, asr #4 102 | bne 0f 103 | add r0, r0, #4 104 | mov r1, r2 105 | 0: 106 | ands r2, r1, #0x8 107 | bne 1f 108 | add r0, r0, #1 109 | ands r2, r1, #0x4 110 | bne 1f 111 | add r0, r0, #1 112 | ands r2, r1, #0x2 113 | bne 1f 114 | add r0, r0, #1 115 | ands r2, r1, #0x1 116 | bne 1f 117 | add r0, r0, #1 118 | 1: 119 | ldr pc, [sp], #4 120 | 121 | #endif 122 | #endif 123 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_common_pitch_est_defines.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SIGPROC_COMMON_PITCH_EST_DEFINES_H 29 | #define SIGPROC_COMMON_PITCH_EST_DEFINES_H 30 | 31 | #include "SKP_Silk_SigProc_FIX.h" 32 | 33 | /************************************************************/ 34 | /* Definitions For Fix pitch estimator */ 35 | /************************************************************/ 36 | 37 | #define PITCH_EST_MAX_FS_KHZ 24 /* Maximum sampling frequency used */ 38 | 39 | #define PITCH_EST_FRAME_LENGTH_MS 40 /* 40 ms */ 40 | 41 | #define PITCH_EST_MAX_FRAME_LENGTH (PITCH_EST_FRAME_LENGTH_MS * PITCH_EST_MAX_FS_KHZ) 42 | #define PITCH_EST_MAX_FRAME_LENGTH_ST_1 (PITCH_EST_MAX_FRAME_LENGTH >> 2) 43 | #define PITCH_EST_MAX_FRAME_LENGTH_ST_2 (PITCH_EST_MAX_FRAME_LENGTH >> 1) 44 | #define PITCH_EST_MAX_SF_FRAME_LENGTH (PITCH_EST_SUB_FRAME * PITCH_EST_MAX_FS_KHZ) 45 | 46 | #define PITCH_EST_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */ 47 | #define PITCH_EST_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */ 48 | #define PITCH_EST_MAX_LAG (PITCH_EST_MAX_LAG_MS * PITCH_EST_MAX_FS_KHZ) 49 | #define PITCH_EST_MIN_LAG (PITCH_EST_MIN_LAG_MS * PITCH_EST_MAX_FS_KHZ) 50 | 51 | #define PITCH_EST_NB_SUBFR 4 52 | 53 | #define PITCH_EST_D_SRCH_LENGTH 24 54 | 55 | #define PITCH_EST_MAX_DECIMATE_STATE_LENGTH 7 56 | 57 | #define PITCH_EST_NB_STAGE3_LAGS 5 58 | 59 | #define PITCH_EST_NB_CBKS_STAGE2 3 60 | #define PITCH_EST_NB_CBKS_STAGE2_EXT 11 61 | 62 | #define PITCH_EST_CB_mn2 1 63 | #define PITCH_EST_CB_mx2 2 64 | 65 | #define PITCH_EST_NB_CBKS_STAGE3_MAX 34 66 | #define PITCH_EST_NB_CBKS_STAGE3_MID 24 67 | #define PITCH_EST_NB_CBKS_STAGE3_MIN 16 68 | 69 | extern const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT]; 70 | extern const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX]; 71 | extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ]; 72 | extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ]; 73 | extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ]; 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_create_init_destroy.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main.h" 29 | 30 | 31 | /************************/ 32 | /* Init Decoder State */ 33 | /************************/ 34 | SKP_int SKP_Silk_init_decoder( 35 | SKP_Silk_decoder_state *psDec /* I/O Decoder state pointer */ 36 | ) 37 | { 38 | SKP_memset( psDec, 0, sizeof( SKP_Silk_decoder_state ) ); 39 | /* Set sampling rate to 24 kHz, and init non-zero values */ 40 | SKP_Silk_decoder_set_fs( psDec, 24 ); 41 | 42 | /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */ 43 | psDec->first_frame_after_reset = 1; 44 | psDec->prev_inv_gain_Q16 = 65536; 45 | 46 | /* Reset CNG state */ 47 | SKP_Silk_CNG_Reset( psDec ); 48 | 49 | SKP_Silk_PLC_Reset( psDec ); 50 | 51 | return(0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_decode_pitch.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /*********************************************************** 29 | * Pitch analyser function 30 | ********************************************************** */ 31 | #include "SKP_Silk_SigProc_FIX.h" 32 | #include "SKP_Silk_common_pitch_est_defines.h" 33 | 34 | void SKP_Silk_decode_pitch( 35 | SKP_int lagIndex, /* I */ 36 | SKP_int contourIndex, /* O */ 37 | SKP_int pitch_lags[], /* O 4 pitch values */ 38 | SKP_int Fs_kHz /* I sampling frequency (kHz) */ 39 | ) 40 | { 41 | SKP_int lag, i, min_lag; 42 | 43 | min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz ); 44 | 45 | /* Only for 24 / 16 kHz version for now */ 46 | lag = min_lag + lagIndex; 47 | if( Fs_kHz == 8 ) { 48 | /* Only a small codebook for 8 khz */ 49 | for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) { 50 | pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ]; 51 | } 52 | } else { 53 | for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) { 54 | pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ]; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_decoder_set_fs.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main.h" 29 | 30 | /* Set decoder sampling rate */ 31 | void SKP_Silk_decoder_set_fs( 32 | SKP_Silk_decoder_state *psDec, /* I/O Decoder state pointer */ 33 | SKP_int fs_kHz /* I Sampling frequency (kHz) */ 34 | ) 35 | { 36 | if( psDec->fs_kHz != fs_kHz ) { 37 | psDec->fs_kHz = fs_kHz; 38 | psDec->frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz ); 39 | psDec->subfr_length = SKP_SMULBB( FRAME_LENGTH_MS / NB_SUBFR, fs_kHz ); 40 | if( psDec->fs_kHz == 8 ) { 41 | psDec->LPC_order = MIN_LPC_ORDER; 42 | psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10; 43 | psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10; 44 | } else { 45 | psDec->LPC_order = MAX_LPC_ORDER; 46 | psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16; 47 | psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16; 48 | } 49 | /* Reset part of the decoder state */ 50 | SKP_memset( psDec->sLPC_Q14, 0, MAX_LPC_ORDER * sizeof( SKP_int32 ) ); 51 | SKP_memset( psDec->outBuf, 0, MAX_FRAME_LENGTH * sizeof( SKP_int16 ) ); 52 | SKP_memset( psDec->prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) ); 53 | 54 | psDec->lagPrev = 100; 55 | psDec->LastGainIndex = 1; 56 | psDec->prev_sigtype = 0; 57 | psDec->first_frame_after_reset = 1; 58 | 59 | if( fs_kHz == 24 ) { 60 | psDec->HP_A = SKP_Silk_Dec_A_HP_24; 61 | psDec->HP_B = SKP_Silk_Dec_B_HP_24; 62 | } else if( fs_kHz == 16 ) { 63 | psDec->HP_A = SKP_Silk_Dec_A_HP_16; 64 | psDec->HP_B = SKP_Silk_Dec_B_HP_16; 65 | } else if( fs_kHz == 12 ) { 66 | psDec->HP_A = SKP_Silk_Dec_A_HP_12; 67 | psDec->HP_B = SKP_Silk_Dec_B_HP_12; 68 | } else if( fs_kHz == 8 ) { 69 | psDec->HP_A = SKP_Silk_Dec_A_HP_8; 70 | psDec->HP_B = SKP_Silk_Dec_B_HP_8; 71 | } else { 72 | /* unsupported sampling rate */ 73 | SKP_assert( 0 ); 74 | } 75 | } 76 | 77 | /* Check that settings are valid */ 78 | SKP_assert( psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH ); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_detect_SWB_input.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* 29 | * Detect SWB input by measuring energy above 8 kHz. 30 | */ 31 | 32 | #include "SKP_Silk_main.h" 33 | 34 | void SKP_Silk_detect_SWB_input( 35 | SKP_Silk_detect_SWB_state *psSWBdetect, /* (I/O) encoder state */ 36 | const SKP_int16 samplesIn[], /* (I) input to encoder */ 37 | SKP_int nSamplesIn /* (I) length of input */ 38 | ) 39 | { 40 | SKP_int HP_8_kHz_len, i, shift; 41 | SKP_int16 in_HP_8_kHz[ MAX_FRAME_LENGTH ]; 42 | SKP_int32 energy_32; 43 | 44 | /* High pass filter with cutoff at 8 khz */ 45 | HP_8_kHz_len = SKP_min_int( nSamplesIn, MAX_FRAME_LENGTH ); 46 | HP_8_kHz_len = SKP_max_int( HP_8_kHz_len, 0 ); 47 | 48 | /* Cutoff around 9 khz */ 49 | /* A = conv(conv([8192,14613, 6868], [8192,12883, 7337]), [8192,11586, 7911]); */ 50 | /* B = conv(conv([575, -948, 575], [575, -221, 575]), [575, 104, 575]); */ 51 | SKP_Silk_biquad( samplesIn, SKP_Silk_SWB_detect_B_HP_Q13[ 0 ], SKP_Silk_SWB_detect_A_HP_Q13[ 0 ], 52 | psSWBdetect->S_HP_8_kHz[ 0 ], in_HP_8_kHz, HP_8_kHz_len ); 53 | for( i = 1; i < NB_SOS; i++ ) { 54 | SKP_Silk_biquad( in_HP_8_kHz, SKP_Silk_SWB_detect_B_HP_Q13[ i ], SKP_Silk_SWB_detect_A_HP_Q13[ i ], 55 | psSWBdetect->S_HP_8_kHz[ i ], in_HP_8_kHz, HP_8_kHz_len ); 56 | } 57 | 58 | /* Calculate energy in HP signal */ 59 | SKP_Silk_sum_sqr_shift( &energy_32, &shift, in_HP_8_kHz, HP_8_kHz_len ); 60 | 61 | /* Count concecutive samples above threshold, after adjusting threshold for number of input samples and shift */ 62 | if( energy_32 > SKP_RSHIFT( SKP_SMULBB( HP_8_KHZ_THRES, HP_8_kHz_len ), shift ) ) { 63 | psSWBdetect->ConsecSmplsAboveThres += nSamplesIn; 64 | if( psSWBdetect->ConsecSmplsAboveThres > CONCEC_SWB_SMPLS_THRES ) { 65 | psSWBdetect->SWB_detected = 1; 66 | } 67 | } else { 68 | psSWBdetect->ConsecSmplsAboveThres -= nSamplesIn; 69 | psSWBdetect->ConsecSmplsAboveThres = SKP_max( psSWBdetect->ConsecSmplsAboveThres, 0 ); 70 | } 71 | 72 | /* If sufficient speech activity and no SWB detected, we detect the signal as being WB */ 73 | if( ( psSWBdetect->ActiveSpeech_ms > WB_DETECT_ACTIVE_SPEECH_MS_THRES ) && ( psSWBdetect->SWB_detected == 0 ) ) { 74 | psSWBdetect->WB_detected = 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_div_oabi.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_typedef.h" 29 | 30 | SKP_int32 SKP_DIV32_arm( SKP_int32 a32, SKP_int32 b32 ) { 31 | return ( ( SKP_int32 )( ( a32 ) / ( b32 ) ) ); 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_init_encoder_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main_FIX.h" 29 | 30 | /*********************************/ 31 | /* Initialize Silk Encoder state */ 32 | /*********************************/ 33 | SKP_int SKP_Silk_init_encoder_FIX( 34 | SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */ 35 | ) { 36 | SKP_int ret = 0; 37 | /* Clear the entire encoder state */ 38 | SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) ); 39 | 40 | #if HIGH_PASS_INPUT 41 | psEnc->variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */ 42 | psEnc->variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */ 43 | #endif 44 | 45 | /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */ 46 | psEnc->sCmn.first_frame_after_reset = 1; 47 | 48 | /* Initialize Silk VAD */ 49 | ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD ); 50 | 51 | /* Initialize NSQ */ 52 | psEnc->sCmn.sNSQ.prev_inv_gain_Q16 = 65536; 53 | psEnc->sCmn.sNSQ_LBRR.prev_inv_gain_Q16 = 65536; 54 | 55 | return( ret ); 56 | } 57 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_inner_prod_aligned.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_inner_prod_aligned.c * 30 | * * 31 | * * 32 | * Copyright 2008-2010 (c), Skype Limited * 33 | * Date: 080601 * 34 | * */ 35 | #include "SKP_Silk_SigProc_FIX.h" 36 | 37 | /* sum= for(i=0;i6, memory access can be reduced by half. */ 42 | 43 | #if (EMBEDDED_ARM<5) 44 | SKP_int32 SKP_Silk_inner_prod_aligned( 45 | const SKP_int16* const inVec1, /* I input vector 1 */ 46 | const SKP_int16* const inVec2, /* I input vector 2 */ 47 | const SKP_int len /* I vector lengths */ 48 | ) 49 | { 50 | SKP_int i; 51 | SKP_int32 sum = 0; 52 | for( i = 0; i < len; i++ ) { 53 | sum = SKP_SMLABB( sum, inVec1[ i ], inVec2[ i ] ); 54 | } 55 | return sum; 56 | } 57 | #endif 58 | 59 | #if (EMBEDDED_ARM<5) 60 | SKP_int64 SKP_Silk_inner_prod16_aligned_64( 61 | const SKP_int16 *inVec1, /* I input vector 1 */ 62 | const SKP_int16 *inVec2, /* I input vector 2 */ 63 | const SKP_int len /* I vector lengths */ 64 | ) 65 | { 66 | SKP_int i; 67 | SKP_int64 sum = 0; 68 | for( i = 0; i < len; i++ ) { 69 | sum = SKP_SMLALBB( sum, inVec1[ i ], inVec2[ i ] ); 70 | } 71 | return sum; 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_interpolate.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main.h" 29 | 30 | /* Interpolate two vectors */ 31 | void SKP_Silk_interpolate( 32 | SKP_int xi[ MAX_LPC_ORDER ], /* O interpolated vector */ 33 | const SKP_int x0[ MAX_LPC_ORDER ], /* I first vector */ 34 | const SKP_int x1[ MAX_LPC_ORDER ], /* I second vector */ 35 | const SKP_int ifact_Q2, /* I interp. factor, weight on 2nd vector */ 36 | const SKP_int d /* I number of parameters */ 37 | ) 38 | { 39 | SKP_int i; 40 | 41 | SKP_assert( ifact_Q2 >= 0 ); 42 | SKP_assert( ifact_Q2 <= ( 1 << 2 ) ); 43 | 44 | for( i = 0; i < d; i++ ) { 45 | xi[ i ] = ( SKP_int )( ( SKP_int32 )x0[ i ] + SKP_RSHIFT( SKP_MUL( ( SKP_int32 )x1[ i ] - ( SKP_int32 )x0[ i ], ifact_Q2 ), 2 ) ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_k2a.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_k2a.c * 30 | * * 31 | * Step up function, converts reflection coefficients to prediction * 32 | * coefficients * 33 | * * 34 | * Copyright 2008 (c), Skype Limited * 35 | * Date: 080103 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | 39 | /* Step up function, converts reflection coefficients to prediction coefficients */ 40 | void SKP_Silk_k2a( 41 | SKP_int32 *A_Q24, /* O: Prediction coefficients [order] Q24 */ 42 | const SKP_int16 *rc_Q15, /* I: Reflection coefficients [order] Q15 */ 43 | const SKP_int32 order /* I: Prediction order */ 44 | ) 45 | { 46 | SKP_int k, n; 47 | SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ]; 48 | 49 | for( k = 0; k < order; k++ ) { 50 | for( n = 0; n < k; n++ ) { 51 | Atmp[ n ] = A_Q24[ n ]; 52 | } 53 | for( n = 0; n < k; n++ ) { 54 | A_Q24[ n ] = SKP_SMLAWB( A_Q24[ n ], SKP_LSHIFT( Atmp[ k - n - 1 ], 1 ), rc_Q15[ k ] ); 55 | } 56 | A_Q24[ k ] = -SKP_LSHIFT( (SKP_int32)rc_Q15[ k ], 9 ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_k2a_Q16.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_k2a.c * 30 | * * 31 | * Step up function, converts reflection coefficients to prediction * 32 | * coefficients * 33 | * * 34 | * Copyright 2008 (c), Skype Limited * 35 | * Date: 080103 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | 39 | /* Step up function, converts reflection coefficients to prediction coefficients */ 40 | void SKP_Silk_k2a_Q16( 41 | SKP_int32 *A_Q24, /* O: Prediction coefficients [order] Q24 */ 42 | const SKP_int32 *rc_Q16, /* I: Reflection coefficients [order] Q16 */ 43 | const SKP_int32 order /* I: Prediction order */ 44 | ) 45 | { 46 | SKP_int k, n; 47 | SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ]; 48 | 49 | for( k = 0; k < order; k++ ) { 50 | for( n = 0; n < k; n++ ) { 51 | Atmp[ n ] = A_Q24[ n ]; 52 | } 53 | for( n = 0; n < k; n++ ) { 54 | A_Q24[ n ] = SKP_SMLAWW( A_Q24[ n ], Atmp[ k - n - 1 ], rc_Q16[ k ] ); 55 | } 56 | A_Q24[ k ] = -SKP_LSHIFT( rc_Q16[ k ], 8 ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_lin2log.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_lin2log.c * 30 | * * 31 | * Convert input to a log scale * 32 | * Approximation of 128 * log2() * 33 | * * 34 | * Copyright 2006 (c), Skype Limited * 35 | * Date: 060221 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | #if EMBEDDED_ARM<4 39 | /* Approximation of 128 * log2() (very close inverse of approx 2^() below) */ 40 | /* Convert input to a log scale */ 41 | SKP_int32 SKP_Silk_lin2log( const SKP_int32 inLin ) /* I: Input in linear scale */ 42 | { 43 | SKP_int32 lz, frac_Q7; 44 | 45 | SKP_Silk_CLZ_FRAC( inLin, &lz, &frac_Q7 ); 46 | 47 | /* Piece-wise parabolic approximation */ 48 | return( SKP_LSHIFT( 31 - lz, 7 ) + SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 ) ); 49 | } 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_lin2log_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | #if EMBEDDED_ARM>=5 32 | 33 | VARDEF val_lz, r1 34 | VARDEF val_shift, r2 35 | VARDEF val_frac, r3 36 | 37 | VARDEF val_ret1, r1 38 | VARDEF val_128minfrac, r2 39 | VARDEF val_mul_ret, r0 40 | VARDEF val_add_ret, r3 41 | VARDEF const1, r1 42 | 43 | .globl SYM(SKP_Silk_lin2log) 44 | SYM(SKP_Silk_lin2log): 45 | stmdb sp!, {r4-r5, fp, ip, lr} 46 | add fp, sp, #16 47 | 48 | clz val_lz, r0 /*lz*/ 49 | cmp val_lz, #24 50 | sub val_shift, val_lz, #24 51 | #ifdef _WINRT 52 | bge LR(0, f) 53 | rsb val_shift, val_lz, #24 54 | mov val_frac, r0, asr val_shift 55 | b LR(1, f) 56 | L(0) 57 | mov val_frac, r0, lsl val_shift 58 | L(1) 59 | #else 60 | rsblt val_shift, val_lz, #24 61 | movlt val_frac, r0, asr val_shift 62 | movge val_frac, r0, lsl val_shift 63 | #endif 64 | and val_frac, val_frac, #0x7F /*frac_Q7*/ 65 | 66 | rsb val_ret1, val_lz, #31 /*31-lz*/ 67 | rsb val_128minfrac, val_frac, #128 /*128-frac_Q7*/ 68 | mov val_ret1, val_ret1, lsl #7 69 | mul val_mul_ret, val_frac, val_128minfrac /*SKP_MUL(frac_Q7, 128 - frac_Q7)*/ 70 | add val_add_ret, val_ret1, val_frac 71 | mov const1, #179 72 | smlawb r0, val_mul_ret, const1, val_add_ret 73 | 74 | ldmia sp!, {r4-r5, fp, ip, pc} 75 | 76 | #elif EMBEDDED_ARM>=4 77 | VARDEF val_lz, r0 78 | VARDEF val_in, r4 79 | VARDEF val_shift, r1 80 | VARDEF val_frac, r2 81 | VARDEF val_ret1, r1 82 | VARDEF val_128minfrac, r3 83 | VARDEF val_mul_ret, r3 84 | VARDEF tmp0, r4 85 | VARDEF const1, r2 86 | VARDEF val_ret, r0 87 | 88 | .globl SYM(SKP_Silk_lin2log) 89 | SYM(SKP_Silk_lin2log): 90 | stmdb sp!, {r4-r5, fp, ip, lr} 91 | add fp, sp, #16 92 | 93 | mov val_in, r0 94 | bl SYM(SKP_Silk_CLZ32) 95 | cmp val_lz, #24 96 | sub val_shift, val_lz, #24 97 | rsblt val_shift, val_lz, #24 98 | movlt val_frac, val_in, asr val_shift 99 | movge val_frac, val_in, lsl val_shift 100 | and val_frac, val_frac, #0x7F /*frac_Q7*/ 101 | 102 | rsb val_ret1, val_lz, #31 /*31-lz*/ 103 | rsb val_128minfrac, val_frac, #128 /*128-frac_Q7*/ 104 | mov val_ret1, val_ret1, lsl #7 105 | mul val_mul_ret, val_frac, val_128minfrac /*SKP_MUL(frac_Q7, 128 - frac_Q7)*/ 106 | add val_ret, val_ret1, val_frac 107 | mov tmp0, #0 108 | mov const1, #0xB30000 109 | smlal tmp0, val_ret, val_mul_ret, const1 110 | 111 | ldmia sp!, {r4-r5, fp, ip, pc} 112 | #endif 113 | END 114 | #endif 115 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_log2lin.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_log2lin.c * 30 | * * 31 | * Convert input to a linear scale * 32 | * * 33 | * Copyright 2006 (c), Skype Limited * 34 | * Date: 060221 * 35 | * */ 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | 38 | /* Approximation of 2^() (very close inverse of SKP_Silk_lin2log()) */ 39 | /* Convert input to a linear scale */ 40 | SKP_int32 SKP_Silk_log2lin( const SKP_int32 inLog_Q7 ) /* I: Input on log scale */ 41 | { 42 | SKP_int32 out, frac_Q7; 43 | 44 | if( inLog_Q7 < 0 ) { 45 | return( 0 ); 46 | } else if( inLog_Q7 >= ( 31 << 7 ) ) { 47 | /* Saturate, and prevent wrap-around */ 48 | return( SKP_int32_MAX ); 49 | } 50 | 51 | out = SKP_LSHIFT( 1, SKP_RSHIFT( inLog_Q7, 7 ) ); 52 | frac_Q7 = inLog_Q7 & 0x7F; 53 | if( inLog_Q7 < 2048 ) { 54 | /* Piece-wise parabolic approximation */ 55 | out = SKP_ADD_RSHIFT( out, SKP_MUL( out, SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 ); 56 | } else { 57 | /* Piece-wise parabolic approximation */ 58 | out = SKP_MLA( out, SKP_RSHIFT( out, 7 ), SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) ); 59 | } 60 | return out; 61 | } 62 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_pitch_est_defines.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SIGPROCFIX_PITCH_EST_DEFINES_H 29 | #define SIGPROCFIX_PITCH_EST_DEFINES_H 30 | 31 | /************************************************************/ 32 | /* Definitions For Fix pitch estimator */ 33 | /************************************************************/ 34 | 35 | #define PITCH_EST_SHORTLAG_BIAS_Q15 6554 /* 0.2f. for logarithmic weighting */ 36 | #define PITCH_EST_PREVLAG_BIAS_Q15 6554 /* Prev lag bias */ 37 | #define PITCH_EST_FLATCONTOUR_BIAS_Q20 52429 /* 0.05f */ 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_pitch_est_tables.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_typedef.h" 29 | #include "SKP_Silk_common_pitch_est_defines.h" 30 | 31 | /********************************************************/ 32 | /* Auto Generated File from generate_pitch_est_tables.m */ 33 | /********************************************************/ 34 | 35 | const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT] = 36 | { 37 | {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1}, 38 | {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, 39 | {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, 40 | {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1} 41 | }; 42 | 43 | const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX] = 44 | { 45 | {-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}, 46 | {-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}, 47 | { 3, 3, 2, 2, 2, 2, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,-1, 0, 0,-1,-1,-1,-1,-1,-2,-2,-2}, 48 | { 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} 49 | }; 50 | 51 | const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] = 52 | { 53 | /* Lags to search for low number of stage3 cbks */ 54 | { 55 | {-2,6}, 56 | {-1,5}, 57 | {-1,5}, 58 | {-2,7} 59 | }, 60 | /* Lags to search for middle number of stage3 cbks */ 61 | { 62 | {-4,8}, 63 | {-1,6}, 64 | {-1,6}, 65 | {-4,9} 66 | }, 67 | /* Lags to search for max number of stage3 cbks */ 68 | { 69 | {-9,12}, 70 | {-3,7}, 71 | {-2,7}, 72 | {-7,13} 73 | } 74 | }; 75 | 76 | const SKP_int16 SKP_Silk_cbk_sizes_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = 77 | { 78 | PITCH_EST_NB_CBKS_STAGE3_MIN, 79 | PITCH_EST_NB_CBKS_STAGE3_MID, 80 | PITCH_EST_NB_CBKS_STAGE3_MAX 81 | }; 82 | 83 | const SKP_int16 SKP_Silk_cbk_offsets_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = 84 | { 85 | ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MIN) >> 1), 86 | ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MID) >> 1), 87 | 0 88 | }; 89 | 90 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_regularize_correlations_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_main_FIX.h" 29 | 30 | /* Add noise to matrix diagonal */ 31 | void SKP_Silk_regularize_correlations_FIX( 32 | SKP_int32 *XX, /* I/O Correlation matrices */ 33 | SKP_int32 *xx, /* I/O Correlation values */ 34 | SKP_int32 noise, /* I Noise to add */ 35 | SKP_int D /* I Dimension of XX */ 36 | ) 37 | { 38 | SKP_int i; 39 | for( i = 0; i < D; i++ ) { 40 | matrix_ptr( &XX[ 0 ], i, i, D ) = SKP_ADD32( matrix_ptr( &XX[ 0 ], i, i, D ), noise ); 41 | } 42 | xx[ 0 ] += noise; 43 | } 44 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_down2.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_down2.c * 30 | * * 31 | * Downsample by a factor 2, mediocre quality * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_rom.h" 38 | 39 | #if (EMBEDDED_ARM<5) 40 | /* Downsample by a factor 2, mediocre quality */ 41 | void SKP_Silk_resampler_down2( 42 | SKP_int32 *S, /* I/O: State vector [ 2 ] */ 43 | SKP_int16 *out, /* O: Output signal [ len ] */ 44 | const SKP_int16 *in, /* I: Input signal [ floor(len/2) ] */ 45 | SKP_int32 inLen /* I: Number of input samples */ 46 | ) 47 | { 48 | SKP_int32 k, len2 = SKP_RSHIFT32( inLen, 1 ); 49 | SKP_int32 in32, out32, Y, X; 50 | 51 | SKP_assert( SKP_Silk_resampler_down2_0 > 0 ); 52 | SKP_assert( SKP_Silk_resampler_down2_1 < 0 ); 53 | 54 | /* Internal variables and state are in Q10 format */ 55 | for( k = 0; k < len2; k++ ) { 56 | /* Convert to Q10 */ 57 | in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 ); 58 | 59 | /* All-pass section for even input sample */ 60 | Y = SKP_SUB32( in32, S[ 0 ] ); 61 | X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 ); 62 | out32 = SKP_ADD32( S[ 0 ], X ); 63 | S[ 0 ] = SKP_ADD32( in32, X ); 64 | 65 | /* Convert to Q10 */ 66 | in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 ); 67 | 68 | /* All-pass section for odd input sample, and add to output of previous section */ 69 | Y = SKP_SUB32( in32, S[ 1 ] ); 70 | X = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 ); 71 | out32 = SKP_ADD32( out32, S[ 1 ] ); 72 | out32 = SKP_ADD32( out32, X ); 73 | S[ 1 ] = SKP_ADD32( in32, X ); 74 | 75 | /* Add, convert back to int16 and store to output */ 76 | out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) ); 77 | } 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_down2_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM>=5 33 | #define SKP_Silk_resampler_down2_0 0x2690 34 | #define SKP_Silk_resampler_down2_1 0x9B81 35 | 36 | VARDEF xy0, r4 37 | VARDEF xy1, r5 38 | VARDEF down2_coefs, _r7 39 | VARDEF S_0, r6 40 | VARDEF S_1, r8 41 | VARDEF in0, sb 42 | VARDEF in1, sl 43 | VARDEF out32, r0 44 | 45 | .set sp_S, 0 46 | .globl SYM(SKP_Silk_resampler_down2) 47 | SYM(SKP_Silk_resampler_down2): 48 | stmdb sp!, {r4-r10, fp, ip, lr} 49 | add fp, sp, #36 50 | sub sp, sp, #4 51 | ldrsh in0, [r2], #2 // Avoid un-aligned access 52 | ldrsh in1, [r2], #2 53 | str r0, [sp, #sp_S] 54 | ldmia r0, {S_0, S_1} 55 | mov down2_coefs, #0x26000000 56 | add down2_coefs, down2_coefs, #0x900000 57 | add down2_coefs, down2_coefs, #0x9B00 58 | add down2_coefs, down2_coefs, #0x81 59 | mov r3, r3, asr #1 60 | mov ip, #1024 61 | L(0) 62 | add out32, S_0, S_1 63 | rsb xy0, S_0, in0, lsl #10 64 | rsb xy1, S_1, in1, lsl #10 65 | smlawb xy0, xy0, down2_coefs, xy0 66 | smulwt xy1, xy1, down2_coefs 67 | add out32, out32, xy0 68 | add S_0, xy0, in0, lsl #10 69 | add out32, out32, xy1 70 | add S_1, xy1, in1, lsl #10 71 | #if EMBEDDED_ARM>=6 72 | qadd out32, out32, ip 73 | subs r3, r3, #1 74 | ssat out32, #16, out32, asr #11 75 | #ifdef _WINRT 76 | ble LR(1, f) 77 | ldrsh in0, [r2], #2 78 | ldrsh in1, [r2], #2 79 | L(1) 80 | #else 81 | ldrgtsh in0, [r2], #2 82 | ldrgtsh in1, [r2], #2 83 | #endif 84 | #else 85 | qadd out32, out32, ip 86 | cmp out32, #0x4000000 87 | movge out32, #0x4000000 88 | subge out32, out32, #1 89 | cmn out32, #0x4000000 90 | movlt out32, #0x4000000 91 | subs r3, r3, #1 92 | mov out32, out32, asr #11 93 | ldrgtsh in0, [r2], #2 94 | ldrgtsh in1, [r2], #2 95 | #endif 96 | 97 | strh out32, [r1], #2 98 | bgt LR(0, b) 99 | 100 | ldr r0, [sp, #sp_S] 101 | stmia r0, {S_0, S_1} 102 | 103 | add sp, sp, #4 104 | ldmia sp!, {r4-r10, fp, ip, pc} 105 | END 106 | #endif 107 | #endif 108 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_AR2.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_private_AR2. c * 30 | * * 31 | * Second order AR filter with single delay elements * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_private.h" 38 | 39 | #if (EMBEDDED_ARM<5) 40 | /* Second order AR filter with single delay elements */ 41 | void SKP_Silk_resampler_private_AR2( 42 | SKP_int32 S[], /* I/O: State vector [ 2 ] */ 43 | SKP_int32 out_Q8[], /* O: Output signal */ 44 | const SKP_int16 in[], /* I: Input signal */ 45 | const SKP_int16 A_Q14[], /* I: AR coefficients, Q14 */ 46 | SKP_int32 len /* I: Signal length */ 47 | ) 48 | { 49 | SKP_int32 k; 50 | SKP_int32 out32; 51 | 52 | for( k = 0; k < len; k++ ) { 53 | out32 = SKP_ADD_LSHIFT32( S[ 0 ], (SKP_int32)in[ k ], 8 ); 54 | out_Q8[ k ] = out32; 55 | out32 = SKP_LSHIFT( out32, 2 ); 56 | S[ 0 ] = SKP_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] ); 57 | S[ 1 ] = SKP_SMULWB( out32, A_Q14[ 1 ] ); 58 | } 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_AR2_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM>=5 33 | 34 | VARDEF len, r4 35 | VARDEF S_0, r5 36 | VARDEF S_1, r6 37 | VARDEF in0, _r7 38 | VARDEF out32, r8 39 | VARDEF A_Q140, sb 40 | VARDEF A_Q141, sl 41 | 42 | .set sp_S, 0 43 | .globl SYM(SKP_Silk_resampler_private_AR2) 44 | SYM(SKP_Silk_resampler_private_AR2): 45 | stmdb sp!, {r4-r10, fp, ip, lr} 46 | add fp, sp, #36 47 | sub sp, sp, #4 48 | .set sp_len, 44 49 | 50 | str r0, [sp, #sp_S] 51 | ldr S_0, [r0], #4 52 | ldr S_1, [r0], #-4 53 | ldr len, [sp, #sp_len] 54 | ldrsh A_Q140, [r3], #2 55 | ldrsh A_Q141, [r3] 56 | cmp len, #0 57 | beq LR(1, f) 58 | 59 | L(0) 60 | ldrsh in0, [r2], #2 61 | add out32, S_0, in0, lsl #8 62 | str out32, [r1], #4 63 | subs len, len, #1 64 | mov out32, out32, lsl #2 65 | smlawb S_0, out32, A_Q140, S_1 66 | smulwb S_1, out32, A_Q141 67 | bgt LR(0, b) 68 | 69 | str S_0, [r0], #4 70 | str S_1, [r0] 71 | L(1) 72 | add sp, sp, #4 73 | ldmia sp!, {r4-r10, fp, ip, pc} 74 | END 75 | #endif 76 | #endif 77 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_ARMA4.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_private_ARMA4.c * 30 | * * 31 | * Fourth order ARMA filter, applies 64x gain * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_private.h" 38 | 39 | /* Fourth order ARMA filter */ 40 | /* Internally operates as two biquad filters in sequence. */ 41 | 42 | /* Coeffients are stored in a packed format: */ 43 | /* { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 } */ 44 | /* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384 */ 45 | #if (EMBEDDED_ARM<5) 46 | void SKP_Silk_resampler_private_ARMA4( 47 | SKP_int32 S[], /* I/O: State vector [ 4 ] */ 48 | SKP_int16 out[], /* O: Output signal */ 49 | const SKP_int16 in[], /* I: Input signal */ 50 | const SKP_int16 Coef[], /* I: ARMA coefficients [ 7 ] */ 51 | SKP_int32 len /* I: Signal length */ 52 | ) 53 | { 54 | SKP_int32 k; 55 | SKP_int32 in_Q8, out1_Q8, out2_Q8, X; 56 | 57 | for( k = 0; k < len; k++ ) { 58 | in_Q8 = SKP_LSHIFT32( (SKP_int32)in[ k ], 8 ); 59 | 60 | /* Outputs of first and second biquad */ 61 | out1_Q8 = SKP_ADD_LSHIFT32( in_Q8, S[ 0 ], 2 ); 62 | out2_Q8 = SKP_ADD_LSHIFT32( out1_Q8, S[ 2 ], 2 ); 63 | 64 | /* Update states, which are stored in Q6. Coefficients are in Q14 here */ 65 | X = SKP_SMLAWB( S[ 1 ], in_Q8, Coef[ 0 ] ); 66 | S[ 0 ] = SKP_SMLAWB( X, out1_Q8, Coef[ 2 ] ); 67 | 68 | X = SKP_SMLAWB( S[ 3 ], out1_Q8, Coef[ 1 ] ); 69 | S[ 2 ] = SKP_SMLAWB( X, out2_Q8, Coef[ 4 ] ); 70 | 71 | S[ 1 ] = SKP_SMLAWB( SKP_RSHIFT32( in_Q8, 2 ), out1_Q8, Coef[ 3 ] ); 72 | S[ 3 ] = SKP_SMLAWB( SKP_RSHIFT32( out1_Q8, 2 ), out2_Q8, Coef[ 5 ] ); 73 | 74 | /* Apply gain and store to output. The coefficient is in Q16 */ 75 | out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( SKP_SMLAWB( 128, out2_Q8, Coef[ 6 ] ), 8 ) ); 76 | } 77 | } 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_ARMA4_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM>=5 33 | 34 | VARDEF len, r0 35 | VARDEF S_0, r3 36 | VARDEF S_1, r4 37 | VARDEF S_2, r5 38 | VARDEF S_3, r6 39 | VARDEF in, _r7 40 | VARDEF out1, r8 41 | VARDEF coef01, sb 42 | VARDEF coef23, sl 43 | VARDEF coef45, ip 44 | VARDEF coef6, r8 45 | VARDEF coef_tmp, _r7 46 | VARDEF out2, lr 47 | 48 | .set sp_S, 0 49 | .set sp_coef, 4 50 | .globl SYM(SKP_Silk_resampler_private_ARMA4) 51 | SYM(SKP_Silk_resampler_private_ARMA4): 52 | stmdb sp!, {r4-r10, fp, ip, lr} 53 | add fp, sp, #36 54 | sub sp, sp, #8 55 | .set sp_len, 48 56 | 57 | ldr lr, [sp, #sp_len] 58 | ldrh coef01, [r3], #2 59 | ldrh S_1, [r3], #2 60 | ldrh coef23, [r3], #2 61 | ldrh S_2, [r3], #2 62 | ldrh coef45, [r3], #2 63 | ldrh S_3, [r3], #2 64 | ldrh coef6, [r3], #2 65 | cmp lr, #0 66 | str r0, [sp, #sp_S] 67 | beq LR(1, f) // if len==0 68 | 69 | str coef6, [sp, #sp_coef] 70 | ldrsh in, [r2], #2 71 | add coef01, coef01, S_1, lsl #16 72 | add coef23, coef23, S_2, lsl #16 73 | add coef45, coef45, S_3, lsl #16 74 | ldmia r0, {S_0, S_1, S_2, S_3} 75 | mov len, lr 76 | 77 | L(0) 78 | mov in, in, lsl #8 79 | add out1, in, S_0, lsl #2 80 | add out2, out1, S_2, lsl #2 81 | 82 | smlawb S_0, in, coef01, S_1 83 | smlawb S_0, out1, coef23, S_0 84 | smlawt S_2, out1, coef01, S_3 85 | smlawb S_2, out2, coef45, S_2 86 | smulwt S_1, out1, coef23 87 | smulwt S_3, out2, coef45 88 | add S_1, S_1, in, asr #2 89 | ldr coef_tmp, [sp, #sp_coef] 90 | add S_3, S_3, out1, asr #2 91 | 92 | mov out1, #128 93 | smlawb out1, out2, coef_tmp, out1 94 | #if EMBEDDED_ARM<6 95 | cmp out1, #0x800000 96 | movge out1, #0x800000 97 | subge out1, out1, #1 98 | cmn out1, #0x800000 99 | movlt out1, #0x800000 100 | mov out1, out1, asr #8 101 | #else 102 | ssat out1, #16, out1, asr #8 103 | #endif 104 | subs len, len, #1 105 | strh out1, [r1], #2 106 | #ifdef _WINRT 107 | ble LR(1, f) 108 | ldrsh in, [r2], #2 109 | b LR(0, b) 110 | L(1) 111 | #else 112 | ldrgtsh in, [r2], #2 113 | bgt LR(0, b) 114 | #endif 115 | 116 | ldr r0, [sp, #sp_S] 117 | stmia r0, {S_0, S_1, S_2, S_3} 118 | L(1) 119 | add sp, sp, #8 120 | ldmia sp!, {r4-r10, fp, ip, pc} 121 | END 122 | #endif 123 | #endif 124 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_IIR_FIR_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM>=5 33 | 34 | VARDEF ind, r4 35 | VARDEF tab1, r5 36 | VARDEF tab2, r6 37 | VARDEF tab3, _r7 38 | VARDEF val1, r8 39 | VARDEF val2, sb 40 | VARDEF val3, r2 41 | VARDEF val4, r3 42 | VARDEF tmp1, sl 43 | VARDEF tmp2, r2 44 | VARDEF tmp3, r3 45 | VARDEF tmp4, ip 46 | VARDEF out, sl 47 | 48 | .set sp_max_i, 0 49 | .set sp_inc, 4 50 | 51 | EXTERN SYM(SKP_Silk_resampler_frac_FIR_144_alt) 52 | .globl SYM(SKP_Silk_resampler_private_IIR_FIR_INTERPOL) 53 | SYM(SKP_Silk_resampler_private_IIR_FIR_INTERPOL): 54 | stmdb sp!, {r4-r10, fp, ip, lr} 55 | add fp, sp, #36 56 | sub sp, sp, #8 57 | str r2, [sp, #sp_max_i] 58 | str r3, [sp, #sp_inc] 59 | cmp r2, #0 60 | mov tmp3, #0xFF00 61 | mov ind, #0 62 | ble LR(1, f) 63 | add tmp3, tmp3, #0xFF 64 | L(0) 65 | ldr tmp1, TABLE(L0, =SKP_Silk_resampler_frac_FIR_144_alt) 66 | and tmp3, ind, tmp3 67 | mov tmp2, #144 68 | mov tmp4, ind, asr #16 69 | smulwb tmp2, tmp3, tmp2 70 | add tmp1, tmp1, tmp2, lsl #3 71 | add tmp1, tmp1, tmp2, lsl #2 72 | add tmp4, r1, tmp4, lsl #1 73 | 74 | ldmia tmp1, {tab1, tab2, tab3} 75 | ldrsh val1, [tmp4], #2 76 | ldrsh val2, [tmp4], #2 77 | ldrsh val3, [tmp4], #2 78 | ldrsh val4, [tmp4], #2 79 | smulbb out, val1, tab1 80 | smlabt out, val2, tab1, out 81 | ldrsh val1, [tmp4], #2 82 | ldrsh val2, [tmp4] 83 | smlabb out, val3, tab2, out 84 | smlabt out, val4, tab2, out 85 | ldr r2, [sp, #sp_max_i] 86 | ldr r3, [sp, #sp_inc] 87 | smlabb out, val1, tab3, out 88 | smlabt out, val2, tab3, out 89 | add ind, ind, r3 90 | adds out, out, #1<<14 91 | mov tmp3, #0xFF00 92 | #ifdef _WINRT 93 | bvc LR(2, f) 94 | mvn out, #0x80000000 95 | b LR(3, f) 96 | L(2) 97 | qadd out, out, out 98 | L(3) 99 | #else 100 | mvnvs out, #0x80000000 101 | qaddvc out, out, out 102 | #endif 103 | add tmp3, tmp3, #0xFF 104 | mov out, out, asr #16 105 | cmp ind, r2 106 | strh out, [r0], #2 107 | blt LR(0, b) 108 | L(1) 109 | add sp, sp, #8 110 | ldmia sp!, {r4-r10, fp, ip, pc} 111 | 112 | L(L0) 113 | DCD SYM(SKP_Silk_resampler_frac_FIR_144_alt) 114 | END 115 | #endif 116 | #endif 117 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_copy.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * File Name: SKP_Silk_resampler_private_copy.c * 30 | * * 31 | * Description: Copy. * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * All rights reserved. * 35 | * */ 36 | 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | #include "SKP_Silk_resampler_private.h" 39 | 40 | /* Copy */ 41 | void SKP_Silk_resampler_private_copy( 42 | void *SS, /* I/O: Resampler state (unused) */ 43 | SKP_int16 out[], /* O: Output signal */ 44 | const SKP_int16 in[], /* I: Input signal */ 45 | SKP_int32 inLen /* I: Number of input samples */ 46 | ) 47 | { 48 | SKP_memcpy( out, in, inLen * sizeof( SKP_int16 ) ); 49 | } 50 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_down4.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_private_down4.c * 30 | * * 31 | * Downsample by a factor 4 * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_private.h" 38 | 39 | /* Downsample by a factor 4. Note: very low quality, only use with input sampling rates above 96 kHz. */ 40 | void SKP_Silk_resampler_private_down4( 41 | SKP_int32 *S, /* I/O: State vector [ 2 ] */ 42 | SKP_int16 *out, /* O: Output signal [ floor(len/2) ] */ 43 | const SKP_int16 *in, /* I: Input signal [ len ] */ 44 | SKP_int32 inLen /* I: Number of input samples */ 45 | ) 46 | { 47 | SKP_int32 k, len4 = SKP_RSHIFT32( inLen, 2 ); 48 | SKP_int32 in32, out32, Y, X; 49 | 50 | SKP_assert( SKP_Silk_resampler_down2_0 > 0 ); 51 | SKP_assert( SKP_Silk_resampler_down2_1 < 0 ); 52 | 53 | /* Internal variables and state are in Q10 format */ 54 | for( k = 0; k < len4; k++ ) { 55 | /* Add two input samples and convert to Q10 */ 56 | in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k ], (SKP_int32)in[ 4 * k + 1 ] ), 9 ); 57 | 58 | /* All-pass section for even input sample */ 59 | Y = SKP_SUB32( in32, S[ 0 ] ); 60 | X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 ); 61 | out32 = SKP_ADD32( S[ 0 ], X ); 62 | S[ 0 ] = SKP_ADD32( in32, X ); 63 | 64 | /* Add two input samples and convert to Q10 */ 65 | in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k + 2 ], (SKP_int32)in[ 4 * k + 3 ] ), 9 ); 66 | 67 | /* All-pass section for odd input sample */ 68 | Y = SKP_SUB32( in32, S[ 1 ] ); 69 | X = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 ); 70 | out32 = SKP_ADD32( out32, S[ 1 ] ); 71 | out32 = SKP_ADD32( out32, X ); 72 | S[ 1 ] = SKP_ADD32( in32, X ); 73 | 74 | /* Add, convert back to int16 and store to output */ 75 | out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_private_up4.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_private_up4.c * 30 | * * 31 | * Upsample by a factor 4, low quality * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_private.h" 38 | 39 | /* Upsample by a factor 4, Note: very low quality, only use with output sampling rates above 96 kHz. */ 40 | void SKP_Silk_resampler_private_up4( 41 | SKP_int32 *S, /* I/O: State vector [ 2 ] */ 42 | SKP_int16 *out, /* O: Output signal [ 4 * len ] */ 43 | const SKP_int16 *in, /* I: Input signal [ len ] */ 44 | SKP_int32 len /* I: Number of INPUT samples */ 45 | ) 46 | { 47 | SKP_int32 k; 48 | SKP_int32 in32, out32, Y, X; 49 | SKP_int16 out16; 50 | 51 | SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 ); 52 | SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 ); 53 | 54 | /* Internal variables and state are in Q10 format */ 55 | for( k = 0; k < len; k++ ) { 56 | /* Convert to Q10 */ 57 | in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); 58 | 59 | /* All-pass section for even output sample */ 60 | Y = SKP_SUB32( in32, S[ 0 ] ); 61 | X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 ); 62 | out32 = SKP_ADD32( S[ 0 ], X ); 63 | S[ 0 ] = SKP_ADD32( in32, X ); 64 | 65 | /* Convert back to int16 and store to output */ 66 | out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); 67 | out[ 4 * k ] = out16; 68 | out[ 4 * k + 1 ] = out16; 69 | 70 | /* All-pass section for odd output sample */ 71 | Y = SKP_SUB32( in32, S[ 1 ] ); 72 | X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 ); 73 | out32 = SKP_ADD32( S[ 1 ], X ); 74 | S[ 1 ] = SKP_ADD32( in32, X ); 75 | 76 | /* Convert back to int16 and store to output */ 77 | out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); 78 | out[ 4 * k + 2 ] = out16; 79 | out[ 4 * k + 3 ] = out16; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_structs.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * File Name: SKP_Silk_resampler_structs.h * 30 | * * 31 | * Description: Structs for IIR/FIR resamplers * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * All rights reserved. * 35 | * * 36 | * */ 37 | 38 | #ifndef SKP_Silk_RESAMPLER_STRUCTS_H 39 | #define SKP_Silk_RESAMPLER_STRUCTS_H 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Flag to enable support for input/output sampling rates above 48 kHz. Turn off for embedded devices */ 46 | #define RESAMPLER_SUPPORT_ABOVE_48KHZ 1 47 | 48 | #define SKP_Silk_RESAMPLER_MAX_FIR_ORDER 16 49 | #define SKP_Silk_RESAMPLER_MAX_IIR_ORDER 6 50 | 51 | 52 | typedef struct _SKP_Silk_resampler_state_struct{ 53 | SKP_int32 sIIR[ SKP_Silk_RESAMPLER_MAX_IIR_ORDER ]; /* this must be the first element of this struct */ 54 | SKP_int32 sFIR[ SKP_Silk_RESAMPLER_MAX_FIR_ORDER ]; 55 | SKP_int32 sDown2[ 2 ]; 56 | void (*resampler_function)( void *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); 57 | void (*up2_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); 58 | SKP_int32 batchSize; 59 | SKP_int32 invRatio_Q16; 60 | SKP_int32 FIR_Fracs; 61 | SKP_int32 input2x; 62 | const SKP_int16 *Coefs; 63 | #if RESAMPLER_SUPPORT_ABOVE_48KHZ 64 | SKP_int32 sDownPre[ 2 ]; 65 | SKP_int32 sUpPost[ 2 ]; 66 | void (*down_pre_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); 67 | void (*up_post_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 ); 68 | SKP_int32 batchSizePrePost; 69 | SKP_int32 ratio_Q16; 70 | SKP_int32 nPreDownsamplers; 71 | SKP_int32 nPostUpsamplers; 72 | #endif 73 | SKP_int32 magic_number; 74 | } SKP_Silk_resampler_state_struct; 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | #endif /* SKP_Silk_RESAMPLER_STRUCTS_H */ 80 | 81 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_up2.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_resampler_up2.c * 30 | * * 31 | * Upsample by a factor 2, low quality * 32 | * * 33 | * Copyright 2010 (c), Skype Limited * 34 | * */ 35 | 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #include "SKP_Silk_resampler_rom.h" 38 | 39 | /* Upsample by a factor 2, low quality */ 40 | #if EMBEDDED_ARM<5 41 | void SKP_Silk_resampler_up2( 42 | SKP_int32 *S, /* I/O: State vector [ 2 ] */ 43 | SKP_int16 *out, /* O: Output signal [ 2 * len ] */ 44 | const SKP_int16 *in, /* I: Input signal [ len ] */ 45 | SKP_int32 len /* I: Number of input samples */ 46 | ) 47 | { 48 | SKP_int32 k; 49 | SKP_int32 in32, out32, Y, X; 50 | 51 | SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 ); 52 | SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 ); 53 | /* Internal variables and state are in Q10 format */ 54 | for( k = 0; k < len; k++ ) { 55 | /* Convert to Q10 */ 56 | in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 ); 57 | 58 | /* All-pass section for even output sample */ 59 | Y = SKP_SUB32( in32, S[ 0 ] ); 60 | X = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 ); 61 | out32 = SKP_ADD32( S[ 0 ], X ); 62 | S[ 0 ] = SKP_ADD32( in32, X ); 63 | 64 | /* Convert back to int16 and store to output */ 65 | out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); 66 | 67 | /* All-pass section for odd output sample */ 68 | Y = SKP_SUB32( in32, S[ 1 ] ); 69 | X = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 ); 70 | out32 = SKP_ADD32( S[ 1 ], X ); 71 | S[ 1 ] = SKP_ADD32( in32, X ); 72 | 73 | /* Convert back to int16 and store to output */ 74 | out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) ); 75 | } 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_resampler_up2_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | 32 | #if EMBEDDED_ARM>=5 33 | #define SKP_Silk_resampler_up2_lq_0 0x1FA6 34 | #define SKP_Silk_resampler_up2_lq_1 0x8FAF 35 | 36 | VARDEF xy0, r4 37 | VARDEF xy1, r5 38 | VARDEF up2_coefs, _r7 39 | VARDEF S_0, r6 40 | VARDEF S_1, r8 41 | VARDEF in, sb 42 | VARDEF out0, sl 43 | VARDEF out1, r0 44 | 45 | .set sp_S, 0 46 | .globl SYM(SKP_Silk_resampler_up2) 47 | SYM(SKP_Silk_resampler_up2): 48 | stmdb sp!, {r4-r10, fp, ip, lr} 49 | add fp, sp, #36 50 | sub sp, sp, #4 51 | mov up2_coefs, #0x1F000000 52 | ldrsh in, [r2], #2 53 | add up2_coefs, up2_coefs, #0xA60000 54 | str r0, [sp, #sp_S] 55 | add up2_coefs, up2_coefs, #0x8F00 56 | ldmia r0, {S_0, S_1} 57 | add up2_coefs, up2_coefs, #0xAF 58 | mov ip, #512 59 | cmp r3, #0 60 | beq LR(1, f) 61 | L(0) 62 | mov in, in, lsl #10 63 | sub xy0, in, S_0 64 | sub xy1, in, S_1 65 | smulwt xy0, xy0, up2_coefs 66 | smlawb xy1, xy1, up2_coefs, xy1 67 | add out0, S_0, xy0 68 | add out1, S_1, xy1 69 | add S_0, in, xy0 70 | add S_1, in, xy1 71 | qadd out0, out0, ip 72 | qadd out1, out1, ip 73 | #if EMBEDDED_ARM<6 74 | cmp out0, #0x2000000 75 | movge out0, #0x2000000 76 | subge out0, out0, #1 77 | cmn out0, #0x2000000 78 | movlt out0, #0x2000000 79 | cmp out1, #0x2000000 80 | movge out1, #0x2000000 81 | subge out1 ,out1, #1 82 | cmn out1, #0x2000000 83 | movlt out1, #0x2000000 84 | mov out0, out0, asr #10 85 | mov out1, out1, asr #10 86 | #else 87 | ssat out0, #16, out0, asr #10 88 | ssat out1, #16, out1, asr #10 89 | #endif 90 | subs r3, r3, #1 91 | #ifdef _WINRT 92 | ble LR(2, f) 93 | ldrsh in, [r2], #2 94 | strh out0, [r1], #2 95 | strh out1, [r1], #2 96 | b LR(0, b) 97 | L(2) 98 | strh out0, [r1], #2 99 | strh out1, [r1], #2 100 | #else 101 | ldrgtsh in, [r2], #2 102 | strh out0, [r1], #2 103 | strh out1, [r1], #2 104 | bgt LR(0, b) 105 | #endif 106 | 107 | ldr r0, [sp, #sp_S] 108 | stmia r0, {S_0, S_1} 109 | L(1) 110 | add sp, sp, #4 111 | ldmia sp!, {r4-r10, fp, ip, pc} 112 | END 113 | #endif 114 | #endif 115 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_scale_copy_vector16.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_SigProc_FIX.h" 29 | 30 | /* Copy and multiply a vector by a constant */ 31 | void SKP_Silk_scale_copy_vector16( 32 | SKP_int16 *data_out, 33 | const SKP_int16 *data_in, 34 | SKP_int32 gain_Q16, /* (I): gain in Q16 */ 35 | const SKP_int dataSize /* (I): length */ 36 | ) 37 | { 38 | SKP_int i; 39 | SKP_int32 tmp32; 40 | 41 | for( i = 0; i < dataSize; i++ ) { 42 | tmp32 = SKP_SMULWB( gain_Q16, data_in[ i ] ); 43 | data_out[ i ] = (SKP_int16)SKP_CHECK_FIT16( tmp32 ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_scale_vector.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_SigProc_FIX.h" 29 | 30 | /* Multiply a vector by a constant */ 31 | void SKP_Silk_scale_vector32_Q26_lshift_18( 32 | SKP_int32 *data1, /* (I/O): Q0/Q18 */ 33 | SKP_int32 gain_Q26, /* (I): Q26 */ 34 | SKP_int dataSize /* (I): length */ 35 | ) 36 | { 37 | SKP_int i; 38 | 39 | for( i = 0; i < dataSize; i++ ) { 40 | data1[ i ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_SMULL( data1[ i ], gain_Q26 ), 8 ) );// OUTPUT: Q18 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_schur64.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_Silk_schur64.c * 30 | * * 31 | * Calculates the reflection coefficients from the correlation sequence * 32 | * using extra precision * 33 | * * 34 | * Copyright 2008 (c), Skype Limited * 35 | * Date: 080103 * 36 | * */ 37 | #include "SKP_Silk_SigProc_FIX.h" 38 | 39 | /* Slower than schur(), but more accurate. */ 40 | /* Uses SMULL(), available on armv4 */ 41 | #if EMBEDDED_ARM<6 42 | SKP_int32 SKP_Silk_schur64( /* O: Returns residual energy */ 43 | SKP_int32 rc_Q16[], /* O: Reflection coefficients [order] Q16 */ 44 | const SKP_int32 c[], /* I: Correlations [order+1] */ 45 | SKP_int32 order /* I: Prediction order */ 46 | ) 47 | { 48 | SKP_int k, n; 49 | SKP_int32 C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ]; 50 | SKP_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31; 51 | 52 | /* Check for invalid input */ 53 | if( c[ 0 ] <= 0 ) { 54 | SKP_memset( rc_Q16, 0, order * sizeof( SKP_int32 ) ); 55 | return 0; 56 | } 57 | 58 | for( k = 0; k < order + 1; k++ ) { 59 | C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ]; 60 | } 61 | 62 | for( k = 0; k < order; k++ ) { 63 | /* Get reflection coefficient: divide two Q30 values and get result in Q31 */ 64 | rc_tmp_Q31 = SKP_DIV32_varQ( -C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31 ); 65 | 66 | /* Save the output */ 67 | rc_Q16[ k ] = SKP_RSHIFT_ROUND( rc_tmp_Q31, 15 ); 68 | 69 | /* Update correlations */ 70 | for( n = 0; n < order - k; n++ ) { 71 | Ctmp1_Q30 = C[ n + k + 1 ][ 0 ]; 72 | Ctmp2_Q30 = C[ n ][ 1 ]; 73 | 74 | /* Multiply and add the highest int32 */ 75 | C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp2_Q30, 1 ), rc_tmp_Q31 ); 76 | C[ n ][ 1 ] = Ctmp2_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp1_Q30, 1 ), rc_tmp_Q31 ); 77 | } 78 | } 79 | 80 | return C[ 0 ][ 1 ]; 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_sigm_Q15.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | /* * 29 | * SKP_sigm_Q15.c * 30 | * * 31 | * Approximate sigmoid function * 32 | * * 33 | * Copyright 2006 (c), Skype Limited * 34 | * Date: 060221 * 35 | * */ 36 | #include "SKP_Silk_SigProc_FIX.h" 37 | #if EMBEDDED_ARM<4 38 | /********************************/ 39 | /* approximate sigmoid function */ 40 | /********************************/ 41 | /* fprintf(1, '%d, ', round(1024 * ([1 ./ (1 + exp(-(1:5))), 1] - 1 ./ (1 + exp(-(0:5)))))); */ 42 | static const SKP_int32 sigm_LUT_slope_Q10[ 6 ] = { 43 | 237, 153, 73, 30, 12, 7 44 | }; 45 | /* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp(-(0:5))))); */ 46 | static const SKP_int32 sigm_LUT_pos_Q15[ 6 ] = { 47 | 16384, 23955, 28861, 31213, 32178, 32548 48 | }; 49 | /* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp((0:5))))); */ 50 | static const SKP_int32 sigm_LUT_neg_Q15[ 6 ] = { 51 | 16384, 8812, 3906, 1554, 589, 219 52 | }; 53 | 54 | SKP_int SKP_Silk_sigm_Q15( SKP_int in_Q5 ) 55 | { 56 | SKP_int ind; 57 | 58 | if( in_Q5 < 0 ) { 59 | /* Negative input */ 60 | in_Q5 = -in_Q5; 61 | if( in_Q5 >= 6 * 32 ) { 62 | return 0; /* Clip */ 63 | } else { 64 | /* Linear interpolation of look up table */ 65 | ind = SKP_RSHIFT( in_Q5, 5 ); 66 | return( sigm_LUT_neg_Q15[ ind ] - SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) ); 67 | } 68 | } else { 69 | /* Positive input */ 70 | if( in_Q5 >= 6 * 32 ) { 71 | return 32767; /* clip */ 72 | } else { 73 | /* Linear interpolation of look up table */ 74 | ind = SKP_RSHIFT( in_Q5, 5 ); 75 | return( sigm_LUT_pos_Q15[ ind ] + SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) ); 76 | } 77 | } 78 | } 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_sigm_Q15_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | #if EMBEDDED_ARM>=4 32 | 33 | VARDEF ptr_slope, r6 34 | VARDEF ptr_LUT, _r7 35 | VARDEF in_Q5, r1 36 | VARDEF ind, r2 37 | VARDEF val_slope, r5 38 | VARDEF val_PUT, r4 39 | VARDEF in_Q5_tmp, r3 40 | 41 | .globl SYM(SKP_Silk_sigm_Q15) 42 | SYM(SKP_Silk_sigm_Q15): 43 | stmdb sp!, {r4-r7, fp, ip, lr} 44 | add fp, sp, #24 45 | cmp r0, #0 46 | ldr ptr_slope, TABLE(L0, =SKP_Silk_sigm_tab) 47 | 48 | mov in_Q5, r0 49 | rsblt in_Q5, r0, #0 50 | mov r0, #32768 51 | addlt ptr_slope, ptr_slope, #24 52 | movlt r0, #1 53 | add ptr_LUT, ptr_slope, #12 /*sigm_LUT_pos_Q15*/ 54 | cmp in_Q5, #192 /*6*32*/ 55 | sub r0, r0, #1 56 | 57 | bge LR(1, f) 58 | mov ind, in_Q5, asr #5 /*ind*/ 59 | mov ind, ind, lsl #1 60 | and in_Q5_tmp, in_Q5, #0x1F 61 | ldrsh val_slope, [ptr_slope, ind] /*sigm_LUT_slope_Q10*/ 62 | ldrsh val_PUT, [ptr_LUT, ind] /*sigm_LUT_pos/neg_Q15*/ 63 | mla r0, val_slope, in_Q5_tmp, val_PUT 64 | L(1) 65 | ldmia sp!, {r4-r7, fp, ip, pc} 66 | 67 | L(L0) 68 | DCD SYM(SKP_Silk_sigm_tab) 69 | 70 | SKP_TABLE SKP_Silk_sigm_tab, 2 71 | DCW 237, 153, 73, 30, 12, 7, \ 72 | 16384, 23955, 28861, 31213, 32178, 32548, \ 73 | -237, -153, -73, -30, -12, -7, \ 74 | 16384, 8812, 3906, 1554, 589, 219 75 | END 76 | #endif 77 | #endif 78 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_sum_sqr_shift_arm.S: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #if defined(__arm__) 29 | 30 | #include "SKP_Silk_AsmPreproc.h" 31 | #if EMBEDDED_ARM>=5 32 | 33 | VARDEF x0, r4 34 | VARDEF nrg_tmp, r5 35 | VARDEF shift, r6 36 | VARDEF nrg, _r7 37 | VARDEF idx, r8 38 | 39 | .globl SYM(SKP_Silk_sum_sqr_shift) 40 | SYM(SKP_Silk_sum_sqr_shift): 41 | stmdb sp!, {r4-r8, fp, ip, lr} 42 | add fp, sp, #28 43 | mov idx, r3 44 | ands nrg_tmp, r2, #2 45 | mov nrg, #0 46 | #ifdef _WINRT 47 | beq LR(6, f) 48 | ldrh x0, [r2], #2 49 | smulbb nrg, x0, x0 50 | sub idx, idx, #1 51 | L(6) 52 | #else 53 | ldrneh x0, [r2], #2 54 | smulbbne nrg, x0, x0 55 | subne idx, idx, #1 56 | #endif 57 | 58 | ldr r4, [r2], #4 59 | mov shift, #0 60 | sub idx, idx, #1 61 | L(0) 62 | subs idx, idx, #2 63 | SKP_SMLAD nrg, x0, x0, nrg 64 | #ifdef _WINRT 65 | ldrgt x0, [r2] 66 | addgt r2, r2, #4 67 | #else 68 | ldrgt x0, [r2], #4 69 | #endif 70 | cmp nrg, #0 71 | blt LR(1, f) 72 | cmp idx, #0 73 | bgt LR(0, b) 74 | beq LR(4, f) 75 | b LR(5, f) 76 | L(1) 77 | mov nrg, nrg, lsr #2 78 | mov shift, #2 79 | cmp idx, #0 80 | beq LR(4, f) 81 | blt LR(5, f) 82 | L(3) 83 | subs idx, idx, #2 84 | SKP_SMUAD nrg_tmp, x0, x0 85 | #ifdef _WINRT 86 | ldrgt x0, [r2] 87 | addgt r2, r2, #4 88 | mov nrg_tmp, nrg_tmp, lsr shift 89 | adds nrg, nrg, nrg_tmp 90 | #else 91 | ldrgt x0, [r2], #4 92 | add nrg, nrg, nrg_tmp, lsr shift 93 | cmp nrg, #0 94 | #endif 95 | movlt nrg, nrg, lsr #2 96 | addlt shift, shift, #2 97 | cmp idx, #0 98 | bgt LR(3, b) 99 | blt LR(5, f) 100 | L(4) 101 | ldrh x0, [r2] 102 | smulbb nrg_tmp, x0, x0 103 | #ifdef _WINRT 104 | mov nrg_tmp, nrg_tmp, lsr shift 105 | add nrg, nrg, nrg_tmp 106 | #else 107 | add nrg, nrg, nrg_tmp, lsr shift 108 | #endif 109 | L(5) 110 | ands nrg_tmp, nrg, #0xC0000000 111 | movne nrg, nrg, lsr #2 112 | addne shift, shift, #2 113 | str shift, [r1] 114 | str nrg, [r0] 115 | 116 | ldmia sp!, {r4-r8, fp, ip, pc} 117 | END 118 | #endif 119 | #endif 120 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_NLSF_CB0_10.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_TABLES_NLSF_CB0_10_H 29 | #define SKP_SILK_TABLES_NLSF_CB0_10_H 30 | 31 | #include "SKP_Silk_define.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" 35 | { 36 | #endif 37 | 38 | #define NLSF_MSVQ_CB0_10_STAGES 6 39 | #define NLSF_MSVQ_CB0_10_VECTORS 120 40 | 41 | /* NLSF codebook entropy coding tables */ 42 | extern const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ NLSF_MSVQ_CB0_10_VECTORS + NLSF_MSVQ_CB0_10_STAGES ]; 43 | extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr[ NLSF_MSVQ_CB0_10_STAGES ]; 44 | extern const SKP_int SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx[ NLSF_MSVQ_CB0_10_STAGES ]; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_NLSF_CB0_16.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_TABLES_NLSF_CB0_16_H 29 | #define SKP_SILK_TABLES_NLSF_CB0_16_H 30 | 31 | #include "SKP_Silk_define.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" 35 | { 36 | #endif 37 | 38 | #define NLSF_MSVQ_CB0_16_STAGES 10 39 | #define NLSF_MSVQ_CB0_16_VECTORS 216 40 | 41 | /* NLSF codebook entropy coding tables */ 42 | extern const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ NLSF_MSVQ_CB0_16_VECTORS + NLSF_MSVQ_CB0_16_STAGES ]; 43 | extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr[ NLSF_MSVQ_CB0_16_STAGES ]; 44 | extern const SKP_int SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx[ NLSF_MSVQ_CB0_16_STAGES ]; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_NLSF_CB1_10.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_TABLES_NLSF_CB1_10_H 29 | #define SKP_SILK_TABLES_NLSF_CB1_10_H 30 | 31 | #include "SKP_Silk_define.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" 35 | { 36 | #endif 37 | 38 | #define NLSF_MSVQ_CB1_10_STAGES 6 39 | #define NLSF_MSVQ_CB1_10_VECTORS 72 40 | 41 | /* NLSF codebook entropy coding tables */ 42 | extern const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_10_CDF[ NLSF_MSVQ_CB1_10_VECTORS + NLSF_MSVQ_CB1_10_STAGES ]; 43 | extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr[ NLSF_MSVQ_CB1_10_STAGES ]; 44 | extern const SKP_int SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx[ NLSF_MSVQ_CB1_10_STAGES ]; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_NLSF_CB1_16.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SKP_SILK_TABLES_NLSF_CB1_16_H 29 | #define SKP_SILK_TABLES_NLSF_CB1_16_H 30 | 31 | #include "SKP_Silk_define.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" 35 | { 36 | #endif 37 | 38 | #define NLSF_MSVQ_CB1_16_STAGES 10 39 | #define NLSF_MSVQ_CB1_16_VECTORS 104 40 | 41 | /* NLSF codebook entropy coding tables */ 42 | extern const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ NLSF_MSVQ_CB1_16_VECTORS + NLSF_MSVQ_CB1_16_STAGES ]; 43 | extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr[ NLSF_MSVQ_CB1_16_STAGES ]; 44 | extern const SKP_int SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx[ NLSF_MSVQ_CB1_16_STAGES ]; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_gain.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_tables.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" 32 | { 33 | #endif 34 | 35 | const SKP_uint16 SKP_Silk_gain_CDF[ 2 ][ 65 ] = 36 | { 37 | { 38 | 0, 18, 45, 94, 181, 320, 519, 777, 39 | 1093, 1468, 1909, 2417, 2997, 3657, 4404, 5245, 40 | 6185, 7228, 8384, 9664, 11069, 12596, 14244, 16022, 41 | 17937, 19979, 22121, 24345, 26646, 29021, 31454, 33927, 42 | 36438, 38982, 41538, 44068, 46532, 48904, 51160, 53265, 43 | 55184, 56904, 58422, 59739, 60858, 61793, 62568, 63210, 44 | 63738, 64165, 64504, 64769, 64976, 65133, 65249, 65330, 45 | 65386, 65424, 65451, 65471, 65487, 65501, 65513, 65524, 46 | 65535 47 | }, 48 | { 49 | 0, 214, 581, 1261, 2376, 3920, 5742, 7632, 50 | 9449, 11157, 12780, 14352, 15897, 17427, 18949, 20462, 51 | 21957, 23430, 24889, 26342, 27780, 29191, 30575, 31952, 52 | 33345, 34763, 36200, 37642, 39083, 40519, 41930, 43291, 53 | 44602, 45885, 47154, 48402, 49619, 50805, 51959, 53069, 54 | 54127, 55140, 56128, 57101, 58056, 58979, 59859, 60692, 55 | 61468, 62177, 62812, 63368, 63845, 64242, 64563, 64818, 56 | 65023, 65184, 65306, 65391, 65447, 65482, 65505, 65521, 57 | 65535 58 | } 59 | }; 60 | 61 | const SKP_int SKP_Silk_gain_CDF_offset = 32; 62 | 63 | 64 | const SKP_uint16 SKP_Silk_delta_gain_CDF[ 46 ] = { 65 | 0, 2358, 3856, 7023, 15376, 53058, 59135, 61555, 66 | 62784, 63498, 63949, 64265, 64478, 64647, 64783, 64894, 67 | 64986, 65052, 65113, 65169, 65213, 65252, 65284, 65314, 68 | 65338, 65359, 65377, 65392, 65403, 65415, 65424, 65432, 69 | 65440, 65448, 65455, 65462, 65470, 65477, 65484, 65491, 70 | 65499, 65506, 65513, 65521, 65528, 65535 71 | }; 72 | 73 | const SKP_int SKP_Silk_delta_gain_CDF_offset = 5; 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_sign.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_tables.h" 29 | 30 | const SKP_uint16 SKP_Silk_sign_CDF[ 36 ] = 31 | { 32 | 37840, 36944, 36251, 35304, 33 | 34715, 35503, 34529, 34296, 34 | 34016, 47659, 44945, 42503, 35 | 40235, 38569, 40254, 37851, 36 | 37243, 36595, 43410, 44121, 37 | 43127, 40978, 38845, 40433, 38 | 38252, 37795, 36637, 59159, 39 | 55630, 51806, 48073, 45036, 40 | 48416, 43857, 42678, 41146, 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /silk/src/SKP_Silk_tables_type_offset.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2012, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, (subject to the limitations in the disclaimer below) 5 | are permitted provided that the following conditions are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Skype Limited, nor the names of specific 12 | contributors, may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #include "SKP_Silk_tables.h" 29 | 30 | const SKP_uint16 SKP_Silk_type_offset_CDF[ 5 ] = { 31 | 0, 37522, 41030, 44212, 65535 32 | }; 33 | 34 | const SKP_int SKP_Silk_type_offset_CDF_offset = 2; 35 | 36 | 37 | const SKP_uint16 SKP_Silk_type_offset_joint_CDF[ 4 ][ 5 ] = 38 | { 39 | { 40 | 0, 57686, 61230, 62358, 65535 41 | }, 42 | { 43 | 0, 18346, 40067, 43659, 65535 44 | }, 45 | { 46 | 0, 22694, 24279, 35507, 65535 47 | }, 48 | { 49 | 0, 6067, 7215, 13010, 65535 50 | } 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /src/bin/main.rs: -------------------------------------------------------------------------------- 1 | use silk_rs::{decode_silk, encode_silk}; 2 | 3 | fn main() { 4 | let input = std::fs::read("test.pcm").unwrap(); 5 | let output = encode_silk(input, 24000, 24000, true).unwrap(); 6 | std::fs::write("output.silk", output).unwrap(); 7 | 8 | let input = std::fs::read("output.silk").unwrap(); 9 | let output = decode_silk(input, 24000).unwrap(); 10 | std::fs::write("output.pcm", output).unwrap(); 11 | } 12 | -------------------------------------------------------------------------------- /src/decode.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::c_void; 2 | 3 | use bytes::Buf; 4 | 5 | use crate::{fast_check, sdk, SilkError}; 6 | 7 | pub fn decode_silk(src: impl AsRef<[u8]>, sample_rate: i32) -> Result, SilkError> { 8 | unsafe { _decode_silk(src.as_ref(), sample_rate) } 9 | } 10 | 11 | unsafe fn _decode_silk(mut src: &[u8], sample_rate: i32) -> Result, SilkError> { 12 | // skip tencent flag 13 | if src.starts_with(b"\x02") { 14 | src.advance(1); 15 | }; 16 | 17 | const SILK_HEADER: &[u8] = b"#!SILK_V3"; 18 | if src.starts_with(SILK_HEADER) { 19 | src.advance(SILK_HEADER.len()); 20 | } else { 21 | return Err(SilkError::Invalid); 22 | }; 23 | 24 | let mut dec_control = sdk::SKP_SILK_SDK_DecControlStruct { 25 | API_sampleRate: sample_rate, 26 | frameSize: 0, 27 | framesPerPacket: 1, 28 | moreInternalDecoderFrames: 0, 29 | inBandFECOffset: 0, 30 | }; 31 | 32 | let mut decoder_size = 0; 33 | fast_check!(sdk::SKP_Silk_SDK_Get_Decoder_Size(&mut decoder_size)); 34 | 35 | let mut decoder = vec![0u8; decoder_size as usize]; 36 | fast_check!(sdk::SKP_Silk_SDK_InitDecoder( 37 | decoder.as_mut_ptr() as *mut c_void 38 | )); 39 | 40 | let mut result = vec![]; 41 | let frame_size = sample_rate as usize / 1000 * 40; 42 | let mut buf = vec![0u8; frame_size]; 43 | loop { 44 | if src.remaining() < 2 { 45 | break; 46 | } 47 | let input_size = src.get_i16_le(); 48 | if input_size > frame_size as i16 { 49 | return Err(SilkError::Invalid); 50 | } 51 | if src.remaining() < input_size as usize { 52 | return Err(SilkError::Invalid); 53 | } 54 | 55 | let input; 56 | (input, src) = src.split_at(input_size as usize); 57 | 58 | let mut output_size = 0i16; 59 | fast_check!(sdk::SKP_Silk_SDK_Decode( 60 | decoder.as_mut_ptr() as *mut c_void, 61 | &mut dec_control, 62 | 0, 63 | input.as_ptr(), 64 | input_size as i32, 65 | buf.as_mut_ptr() as *mut i16, 66 | &mut output_size, 67 | )); 68 | 69 | result.extend_from_slice(&buf[0..output_size as usize * 2]) 70 | } 71 | Ok(result) 72 | } 73 | -------------------------------------------------------------------------------- /src/encode.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::c_void; 2 | 3 | use bytes::BufMut; 4 | 5 | use crate::{fast_check, sdk, SilkError}; 6 | 7 | pub fn encode_silk( 8 | src: impl AsRef<[u8]>, 9 | sample_rate: i32, 10 | bit_rate: i32, 11 | tencent: bool, 12 | ) -> Result, SilkError> { 13 | unsafe { _encode_silk(src.as_ref(), sample_rate, bit_rate, tencent) } 14 | } 15 | 16 | unsafe fn _encode_silk( 17 | src: &[u8], 18 | sample_rate: i32, 19 | bit_rate: i32, 20 | tencent: bool, 21 | ) -> Result, SilkError> { 22 | let enc_control = sdk::SKP_SILK_SDK_EncControlStruct { 23 | API_sampleRate: sample_rate, 24 | maxInternalSampleRate: 24000, 25 | packetSize: (20 * sample_rate) / 1000, 26 | bitRate: bit_rate, 27 | packetLossPercentage: 0, 28 | complexity: 2, 29 | useInBandFEC: 0, 30 | useDTX: 0, 31 | }; 32 | 33 | let mut enc_status = sdk::SKP_SILK_SDK_EncControlStruct { 34 | API_sampleRate: 0, 35 | maxInternalSampleRate: 0, 36 | packetSize: 0, 37 | bitRate: bit_rate, 38 | packetLossPercentage: 0, 39 | complexity: 0, 40 | useInBandFEC: 0, 41 | useDTX: 0, 42 | }; 43 | 44 | let mut encoder_size = 0; 45 | fast_check!(sdk::SKP_Silk_SDK_Get_Encoder_Size(&mut encoder_size)); 46 | 47 | let mut encoder = vec![0u8; encoder_size as usize]; 48 | 49 | fast_check!(sdk::SKP_Silk_SDK_InitEncoder( 50 | encoder.as_mut_ptr() as *mut c_void, 51 | &mut enc_status, 52 | )); 53 | 54 | let mut result = vec![]; 55 | if tencent { 56 | result.put_u8(b'\x02'); 57 | } 58 | result.extend_from_slice(b"#!SILK_V3"); 59 | 60 | let frame_size = sample_rate as usize / 1000 * 40; 61 | let mut output_size = 1250i16; 62 | let mut buf = vec![0u8; output_size as usize]; 63 | for chunk in src.chunks(frame_size) { 64 | output_size = 1250; 65 | if chunk.len() < frame_size { 66 | break; 67 | } 68 | fast_check!(sdk::SKP_Silk_SDK_Encode( 69 | encoder.as_mut_ptr() as *mut c_void, 70 | &enc_control, 71 | chunk.as_ptr() as *const i16, 72 | chunk.len() as i32 / 2, 73 | buf.as_mut_ptr(), 74 | &mut output_size, 75 | )); 76 | result.put_i16_le(output_size); 77 | result.extend_from_slice(&buf[0..output_size as usize]); 78 | } 79 | 80 | Ok(result) 81 | } 82 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | use thiserror::Error; 2 | 3 | #[derive(Error, Debug)] 4 | pub enum SilkError { 5 | #[error("Invalid")] 6 | Invalid, 7 | #[error("EncInputInvalidNoOfSamples")] 8 | EncInputInvalidNoOfSamples, 9 | #[error("EncFsNotSupported")] 10 | EncFsNotSupported, 11 | #[error("EncPacketSizeNotSupported")] 12 | EncPacketSizeNotSupported, 13 | #[error("EncPayloadBufTooShort")] 14 | EncPayloadBufTooShort, 15 | #[error("EncInvalidLossRate")] 16 | EncInvalidLossRate, 17 | #[error("EncInvalidComplexitySetting")] 18 | EncInvalidComplexitySetting, 19 | #[error("EncInvalidInbandFecSetting")] 20 | EncInvalidInbandFecSetting, 21 | #[error("EncInvalidDtxSetting")] 22 | EncInvalidDtxSetting, 23 | #[error("EncInternalError")] 24 | EncInternalError, 25 | #[error("DecInvalidSamplingFrequency")] 26 | DecInvalidSamplingFrequency, 27 | #[error("DecPayloadTooLarge")] 28 | DecPayloadTooLarge, 29 | #[error("DecPayloadError")] 30 | DecPayloadError, 31 | #[error("OTHER {0}")] 32 | Other(i32), 33 | } 34 | 35 | impl From for SilkError { 36 | fn from(code: i32) -> Self { 37 | match code { 38 | -1 => Self::EncInputInvalidNoOfSamples, 39 | -2 => Self::EncFsNotSupported, 40 | -3 => Self::EncPacketSizeNotSupported, 41 | -4 => Self::EncPayloadBufTooShort, 42 | -5 => Self::EncInvalidLossRate, 43 | -6 => Self::EncInvalidComplexitySetting, 44 | -7 => Self::EncInvalidInbandFecSetting, 45 | -8 => Self::EncInvalidDtxSetting, 46 | -9 => Self::EncInternalError, 47 | -10 => Self::DecInvalidSamplingFrequency, 48 | -11 => Self::DecPayloadTooLarge, 49 | -12 => Self::DecPayloadError, 50 | _ => Self::Other(code), 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | pub use decode::decode_silk; 2 | pub use encode::encode_silk; 3 | pub use error::SilkError; 4 | 5 | mod decode; 6 | mod encode; 7 | mod error; 8 | 9 | macro_rules! fast_check { 10 | ($call:expr) => {{ 11 | let code = $call; 12 | if code != 0 { 13 | return Err(SilkError::from(code)); 14 | } 15 | }}; 16 | } 17 | 18 | pub(crate) use fast_check; 19 | 20 | #[allow(dead_code)] 21 | #[allow(non_camel_case_types)] 22 | #[allow(non_snake_case)] 23 | #[allow(non_upper_case_globals)] 24 | pub(crate) mod sdk { 25 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 26 | } 27 | 28 | #[cfg(test)] 29 | mod tests { 30 | use crate::decode_silk; 31 | use crate::encode_silk; 32 | 33 | #[test] 34 | fn test_encode() { 35 | let input = std::fs::read("input.pcm").unwrap(); 36 | let output = encode_silk(input, 24000, 24000, true).unwrap(); 37 | std::fs::write("output.silk", output).unwrap(); 38 | } 39 | 40 | #[test] 41 | fn test_decode() { 42 | let input = std::fs::read("input.silk").unwrap(); 43 | let output = decode_silk(input, 24000).unwrap(); 44 | std::fs::write("output.pcm", output).unwrap(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /wrapper.h: -------------------------------------------------------------------------------- 1 | #include "./silk/interface/SKP_Silk_SDK_API.h" 2 | #include "./silk/interface/SKP_Silk_control.h" 3 | #include "./silk/interface/SKP_Silk_errors.h" 4 | #include "./silk/interface/SKP_Silk_typedef.h" --------------------------------------------------------------------------------