diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:44:24 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:44:24 +0900 |
commit | e28f3aee8eca3cc7a10935f63899d5c4f6ba1ede (patch) | |
tree | 3e9da8eb6a913278403e100d0bbe0b9231a4b6ac /opencore/codecs_v2/audio/gsm_amr/amr_nb/common | |
parent | 54f90e8fa8d02c96e2c6d0a5bd71603dc016cf70 (diff) | |
download | opencore-amr-e28f3aee8eca3cc7a10935f63899d5c4f6ba1ede.tar.gz opencore-amr-e28f3aee8eca3cc7a10935f63899d5c4f6ba1ede.tar.bz2 opencore-amr-e28f3aee8eca3cc7a10935f63899d5c4f6ba1ede.zip |
Tizen 2.1 base
Diffstat (limited to 'opencore/codecs_v2/audio/gsm_amr/amr_nb/common')
148 files changed, 31959 insertions, 0 deletions
diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/Android.mk b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/Android.mk new file mode 100644 index 0000000..550e5fe --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/Android.mk @@ -0,0 +1,77 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + src/add.cpp \ + src/az_lsp.cpp \ + src/bitno_tab.cpp \ + src/bitreorder_tab.cpp \ + src/c2_9pf_tab.cpp \ + src/div_s.cpp \ + src/gains_tbl.cpp \ + src/gc_pred.cpp \ + src/get_const_tbls.cpp \ + src/gmed_n.cpp \ + src/grid_tbl.cpp \ + src/gray_tbl.cpp \ + src/int_lpc.cpp \ + src/inv_sqrt.cpp \ + src/inv_sqrt_tbl.cpp \ + src/l_shr_r.cpp \ + src/log2.cpp \ + src/log2_norm.cpp \ + src/log2_tbl.cpp \ + src/lsfwt.cpp \ + src/lsp.cpp \ + src/lsp_az.cpp \ + src/lsp_lsf.cpp \ + src/lsp_lsf_tbl.cpp \ + src/lsp_tab.cpp \ + src/mult_r.cpp \ + src/norm_l.cpp \ + src/norm_s.cpp \ + src/overflow_tbl.cpp \ + src/ph_disp_tab.cpp \ + src/pow2.cpp \ + src/pow2_tbl.cpp \ + src/pred_lt.cpp \ + src/q_plsf.cpp \ + src/q_plsf_3.cpp \ + src/q_plsf_3_tbl.cpp \ + src/q_plsf_5.cpp \ + src/q_plsf_5_tbl.cpp \ + src/qua_gain_tbl.cpp \ + src/reorder.cpp \ + src/residu.cpp \ + src/round.cpp \ + src/shr.cpp \ + src/shr_r.cpp \ + src/sqrt_l.cpp \ + src/sqrt_l_tbl.cpp \ + src/sub.cpp \ + src/syn_filt.cpp \ + src/weight_a.cpp \ + src/window_tab.cpp + + +LOCAL_MODULE := libpv_amr_nb_common_lib + +LOCAL_CFLAGS := $(PV_CFLAGS) + +LOCAL_ARM_MODE := arm + +LOCAL_STATIC_LIBRARIES := + +LOCAL_SHARED_LIBRARIES := + +LOCAL_C_INCLUDES := \ + $(PV_TOP)/codecs_v2/audio/gsm_amr/amr_nb/common/src \ + $(PV_TOP)/codecs_v2/audio/gsm_amr/amr_nb/common/include \ + $(PV_INCLUDES) + +LOCAL_COPY_HEADERS_TO := $(PV_COPY_HEADERS_TO) + +LOCAL_COPY_HEADERS := \ + + +include $(BUILD_STATIC_LIBRARY) diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/build/make/local.mk b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/build/make/local.mk new file mode 100644 index 0000000..92b3f5e --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/build/make/local.mk @@ -0,0 +1,68 @@ +# Get the current local path as the first operation +LOCAL_PATH := $(call get_makefile_dir) + +# Clear out the variables used in the local makefiles +include $(MK)/clear.mk + +TARGET := pv_amr_nb_common_lib + + +OPTIMIZE_FOR_PERFORMANCE_OVER_SIZE := true + +SRCDIR := ../../src +INCSRCDIR := ../../include + +SRCS := add.cpp \ + az_lsp.cpp \ + bitno_tab.cpp \ + bitreorder_tab.cpp \ + c2_9pf_tab.cpp \ + div_s.cpp \ + gains_tbl.cpp \ + gc_pred.cpp \ + get_const_tbls.cpp \ + gmed_n.cpp \ + grid_tbl.cpp \ + gray_tbl.cpp \ + int_lpc.cpp \ + inv_sqrt.cpp \ + inv_sqrt_tbl.cpp \ + l_shr_r.cpp \ + log2.cpp \ + log2_norm.cpp \ + log2_tbl.cpp \ + lsfwt.cpp \ + lsp.cpp \ + lsp_az.cpp \ + lsp_lsf.cpp \ + lsp_lsf_tbl.cpp \ + lsp_tab.cpp \ + mult_r.cpp \ + norm_l.cpp \ + norm_s.cpp \ + overflow_tbl.cpp \ + ph_disp_tab.cpp \ + pow2.cpp \ + pow2_tbl.cpp \ + pred_lt.cpp \ + q_plsf.cpp \ + q_plsf_3.cpp \ + q_plsf_3_tbl.cpp \ + q_plsf_5.cpp \ + q_plsf_5_tbl.cpp \ + qua_gain_tbl.cpp \ + reorder.cpp \ + residu.cpp \ + round.cpp \ + shr.cpp \ + shr_r.cpp \ + sqrt_l.cpp \ + sqrt_l_tbl.cpp \ + sub.cpp \ + syn_filt.cpp \ + weight_a.cpp \ + window_tab.cpp + +include $(MK)/library.mk + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/abs_s.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/abs_s.h new file mode 100644 index 0000000..04e383a --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/abs_s.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: abs_s.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the abs_s function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef ABS_S_H +#define ABS_S_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word16 abs_s(Word16 var1); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* ABS_S_H */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/add.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/add.h new file mode 100644 index 0000000..18fdcee --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/add.h @@ -0,0 +1,97 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: add.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the add function. + +------------------------------------------------------------------------------ +*/ + +#ifndef ADD_H +#define ADD_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 add_16(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _ADD_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/az_lsp.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/az_lsp.h new file mode 100644 index 0000000..cd2e91f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/az_lsp.h @@ -0,0 +1,105 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: az_lsp.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the function Az_lsp() + +------------------------------------------------------------------------------ +*/ + +#ifndef AZ_LSP_H +#define AZ_LSP_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define grid_points 60 + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 grid[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void Az_lsp( + Word16 a[], /* (i) : predictor coefficients (MP1) */ + Word16 lsp[], /* (o) : line spectral pairs (M) */ + Word16 old_lsp[], /* (i) : old lsp[] (in case not found 10 roots) (M) */ + Flag *pOverflow /* (i/o): overflow flag */ + ); + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _AZ_LSP_H */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op.h new file mode 100644 index 0000000..d38f953 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op.h @@ -0,0 +1,425 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: basic_op.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file includes all the basicop2.c functions' header files. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BASIC_OP_H +#define BASIC_OP_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +#if defined(PV_ARM_V5) +#include "basic_op_arm_v5.h" + +#elif defined(PV_ARM_GCC_V5) +#include "basic_op_arm_gcc_v5.h" + +#else +#include "basic_op_c_equivalent.h" + +#endif + + + +#include "add.h" +#include "div_s.h" +#include "l_shr_r.h" +#include "mult_r.h" +#include "norm_l.h" +#include "norm_s.h" +#include "round.h" +#include "shr_r.h" +#include "sub.h" +#include "shr.h" +#include "l_negate.h" +#include "l_extract.h" +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: mac_32 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + L_var1_hi = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + L_var1_lo = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + L_var2_hi = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + L_var2_lo = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit mac operation resulted in overflow + + Returns: + L_var3 = 32-bit result of L_var3 + (L_var1 * L_var2)(Word32) + + */ + static inline Word32 Mac_32(Word32 L_var3, + Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + { + Word16 product; + + L_var3 = L_mac(L_var3, L_var1_hi, L_var2_hi, pOverflow); + + product = mult(L_var1_hi, L_var2_lo, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + product = mult(L_var1_lo, L_var2_hi, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + return (L_var3); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: mac_32_16 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + L_var1_hi = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + L_var1_lo = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + var2= 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit mac operation resulted in overflow + + Returns: + L_var3 = 32-bit result of L_var3 + (L_var1 * var2)(Word32) + */ + + static inline Word32 Mac_32_16(Word32 L_var3, + Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + Word16 product; + + L_var3 = L_mac(L_var3, L_var1_hi, var2, pOverflow); + + product = mult(L_var1_lo, var2, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + return (L_var3); + } + + + /*---------------------------------------------------------------------------- + Function Name : negate + + Negate var1 with saturation, saturate in the case where input is -32768: + negate(var1) = sub(0,var1). + + Inputs : + var1 + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var1 <= 0x7fff. + + Outputs : + none + + Return Value : + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var_out <= 0x7fff. + ----------------------------------------------------------------------------*/ + + static inline Word16 negate(Word16 var1) + { + return (((var1 == MIN_16) ? MAX_16 : -var1)); + } + + /*---------------------------------------------------------------------------- + + Function Name : shl + + Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill + the var2 LSB of the result. If var2 is negative, arithmetically shift + var1 right by -var2 with sign extension. Saturate the result in case of + underflows or overflows. + + Inputs : + var1 + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var1 <= 0x7fff. + + var2 + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var1 <= 0x7fff. + + pOverflow : pointer to overflow (Flag) + + Return Value : + var_out + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var_out <= 0x7fff. + ----------------------------------------------------------------------------*/ + + static inline Word16 shl(Word16 var1, Word16 var2, Flag *pOverflow) + { + Word16 var_out = 0; + + OSCL_UNUSED_ARG(pOverflow); + + if (var2 < 0) + { + var2 = -var2; + if (var2 < 15) + { + var_out = var1 >> var2; + } + + } + else + { + var_out = var1 << var2; + if (var_out >> var2 != var1) + { + var_out = (var1 >> 15) ^ MAX_16; + } + } + return (var_out); + } + + + /*---------------------------------------------------------------------------- + + Function Name : L_shl + + Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero + fill the var2 LSB of the result. If var2 is negative, arithmetically + shift L_var1 right by -var2 with sign extension. Saturate the result in + case of underflows or overflows. + + Inputs : + L_var1 32 bit long signed integer (Word32) whose value falls in the + range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + var2 + 16 bit short signed integer (Word16) whose value falls in the + range : 8000 <= var2 <= 7fff. + + pOverflow : pointer to overflow (Flag) + + Return Value : + 32 bit long signed integer (Word32) whose value falls in the + range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. + + ----------------------------------------------------------------------------*/ + + static inline Word32 L_shl(Word32 L_var1, Word16 var2, Flag *pOverflow) + { + Word32 L_var_out = 0; + + OSCL_UNUSED_ARG(pOverflow); + + if (var2 > 0) + { + L_var_out = L_var1 << var2; + if (L_var_out >> var2 != L_var1) + { + L_var_out = (L_var1 >> 31) ^ MAX_32; + } + } + else + { + var2 = -var2; + if (var2 < 31) + { + L_var_out = L_var1 >> var2; + } + + } + + return (L_var_out); + } + + + /*---------------------------------------------------------------------------- + + Function Name : L_shr + + Arithmetically shift the 32 bit input L_var1 right var2 positions with + sign extension. If var2 is negative, arithmetically shift L_var1 left + by -var2 and zero fill the -var2 LSB of the result. Saturate the result + in case of underflows or overflows. + + Inputs : + L_var1 32 bit long signed integer (Word32) whose value falls in the + range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + var2 + 16 bit short signed integer (Word16) whose value falls in the + range : 8000 <= var2 <= 7fff. + + pOverflow : pointer to overflow (Flag) + + Return Value : + 32 bit long signed integer (Word32) whose value falls in the + range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. + + ----------------------------------------------------------------------------*/ + + static inline Word32 L_shr(Word32 L_var1, Word16 var2, Flag *pOverflow) + { + Word32 L_var_out = 0; + + OSCL_UNUSED_ARG(pOverflow); + + if (var2 > 0) + { + if (var2 < 31) + { + L_var_out = L_var1 >> var2; + } + } + else + { + var2 = -var2; + + L_var_out = L_var1 << (var2) ; + if ((L_var_out >> (var2)) != L_var1) + { + L_var_out = (L_var1 >> 31) ^ MAX_32; + } + + } + + return (L_var_out); + } + + /*---------------------------------------------------------------------------- + + Function Name : abs_s + + Absolute value of var1; abs_s(-32768) = 32767. + + Inputs : + var1 + 16 bit short signed integer (Word16) whose value falls in the + range : 0x8000 <= var1 <= 0x7fff. + + pOverflow : pointer to overflow (Flag) + + Outputs : + none + + Return Value : + 16 bit short signed integer (Word16) whose value falls in the + range : 0x0000 <= var_out <= 0x7fff. + + ----------------------------------------------------------------------------*/ + + static inline Word16 abs_s(Word16 var1) + { + + Word16 y = var1 - (var1 < 0); + y = y ^(y >> 15); + return (y); + + } + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + + +#endif /* BASIC_OP_H */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_arm_gcc_v5.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_arm_gcc_v5.h new file mode 100644 index 0000000..1abc4fa --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_arm_gcc_v5.h @@ -0,0 +1,537 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: basic_op_arm_gcc_v5.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file includes all the GCC-ARM V5 basicop.c functions. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BASIC_OP_ARM_GCC_V5_H +#define BASIC_OP_ARM_GCC_V5_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_add + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + L_var2 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_sum = 32-bit sum of L_var1 and L_var2 (Word32) + */ + + __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow) + { + register Word32 ra = L_var1; + register Word32 rb = L_var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("qadd %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(rb) + ); + return (result); + + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_sub + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + L_var2 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_diff = 32-bit difference of L_var1 and L_var2 (Word32) + */ + __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow) +{ + register Word32 ra = L_var1; + register Word32 rb = L_var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("qsub %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(rb) + ); + + return (result); + } + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_mac + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + result = 32-bit result of L_var3 + (var1 * var2)(Word32) + */ + static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) +{ + register Word32 ra = L_var3; + register Word32 rb = var1; + register Word32 rc = var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(result) + : "r"(rb), "r"(rc) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(rc) + : "r"(ra), "r"(result) + ); + + return (rc); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_mult + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + L_var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_product = 32-bit product of L_var1 and L_var2 (Word32) + */ + + __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow) +{ + register Word32 ra = var1; + register Word32 rb = var2; + Word32 result; + Word32 product; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product) + : "r"(ra), "r"(rb) + ); + + asm volatile("qadd %0, %1, %2" + : "=r"(result) + : "r"(product), "r"(product) + ); + + return(result); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_msu + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit operation resulted in overflow + + Returns: + result = 32-bit result of L_var3 - (var1 * var2) + */ + __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) +{ + register Word32 ra = L_var3; + register Word32 rb = var1; + register Word32 rc = var2; + Word32 product; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product) + : "r"(rb), "r"(rc) + ); + + asm volatile("qdsub %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(product) + ); + + return (result); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: Mpy_32 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1_hi = most significant word of first input (Word16). + L_var1_lo = least significant word of first input (Word16). + L_var2_hi = most significant word of second input (Word16). + L_var2_lo = least significant word of second input (Word16). + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit multiply operation resulted in overflow + + Returns: + L_product = 32-bit product of L_var1 and L_var2 (Word32) + */ + static inline Word32 Mpy_32(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) +{ + register Word32 product32; + register Word32 L_sum; + register Word32 L_product, result; + register Word32 ra = L_var1_hi; + register Word32 rb = L_var1_lo; + register Word32 rc = L_var2_hi; + register Word32 rd = L_var2_lo; + + + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(L_product) + : "r"(ra), "r"(rc) + ); + asm volatile("mov %0, #0" + : "=r"(result) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_sum) + : "r"(result), "r"(L_product) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product32) + : "r"(ra), "r"(rd) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(ra) + : "r"(product32) + ); + asm volatile("qdadd %0, %1, %2" + : "=r"(L_product) + : "r"(L_sum), "r"(ra) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product32) + : "r"(rb), "r"(rc) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(rb) + : "r"(product32) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_sum) + : "r"(L_product), "r"(rb) + ); + + return (L_sum); + } + + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: Mpy_32_16 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1_hi = most significant 16 bits of 32-bit input (Word16). + L_var1_lo = least significant 16 bits of 32-bit input (Word16). + var2 = 16-bit signed integer (Word16). + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit product operation resulted in overflow + + Returns: + product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32) + */ + static inline Word32 Mpy_32_16(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) +{ + + register Word32 ra = L_var1_hi; + register Word32 rb = L_var1_lo; + register Word32 rc = var2; + Word32 result, L_product; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(L_product) + : "r"(ra), "r"(rc) + ); + asm volatile("mov %0, #0" + : "=r"(result) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_product) + : "r"(result), "r"(L_product) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(result) + : "r"(rb), "r"(rc) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(ra) + : "r"(result) + ); + asm volatile("qdadd %0, %1, %2" + : "=r"(result) + : "r"(L_product), "r"(ra) + ); + + return (result); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: mult + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the add operation resulted in overflow + + Returns: + product = 16-bit limited product of var1 and var2 (Word16) + */ + __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) +{ + register Word32 ra = var1; + register Word32 rb = var2; + Word32 product; + Word32 temp; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile( + "smulbb %0, %1, %2" + : "=r"(temp) + : "r"(ra), "r"(rb) + ); + asm volatile( + "qadd %0, %1, %2\n\t" + "mov %0, %0, asr #16" + : "=&r*i"(product) + : "r"(temp), "r"(temp) + ); + + return ((Word16) product); + } + + __inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3) +{ + register Word32 ra = L_var1; + register Word32 rb = L_var2; + register Word32 rc = L_var3; + Word32 result; + + asm volatile("smlabb %0, %1, %2, %3" + : "=r"(result) + : "r"(ra), "r"(rb), "r"(rc) + ); + return (result); + } + + __inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3) +{ + register Word32 ra = L_var1; + register Word32 rb = L_var2; + register Word32 rc = L_var3; + Word32 result; + + asm volatile("rsb %0, %1, #0" + : "=r"(ra) + : "r"(ra) + ); + + asm volatile("smlabb %0, %1, %2, %3" + : "=r"(result) + : "r"(ra), "r"(rb), "r"(rc) + ); + return (result); + } + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* BASIC_OP_ARM_GCC_V5_H */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_c_equivalent.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_c_equivalent.h new file mode 100644 index 0000000..eb91049 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_c_equivalent.h @@ -0,0 +1,499 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: basic_op_c_equivalent.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file includes all the C-Equivalent basicop.c functions. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BASIC_OP_C_EQUIVALENT_H +#define BASIC_OP_C_EQUIVALENT_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_add + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + L_var2 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_sum = 32-bit sum of L_var1 and L_var2 (Word32) + */ + static inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow) + { + Word32 L_sum; + + L_sum = L_var1 + L_var2; + + if ((L_var1 ^ L_var2) >= 0) + { + if ((L_sum ^ L_var1) < 0) + { + L_sum = (L_var1 < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + + return (L_sum); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_sub + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + L_var2 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_diff = 32-bit difference of L_var1 and L_var2 (Word32) + */ + static inline Word32 L_sub(register Word32 L_var1, register Word32 L_var2, + register Flag *pOverflow) + { + Word32 L_diff; + + L_diff = L_var1 - L_var2; + + if ((L_var1 ^ L_var2) < 0) + { + if ((L_diff ^ L_var1) & MIN_32) + { + L_diff = (L_var1 < 0L) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + + return (L_diff); + } + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_mac + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + result = 32-bit result of L_var3 + (var1 * var2)(Word32) + */ + static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + Word32 L_sum; + result = (Word32) var1 * var2; + if (result != (Word32) 0x40000000L) + { + L_sum = (result << 1) + L_var3; + + /* Check if L_sum and L_var_3 share the same sign */ + if ((L_var3 ^ result) > 0) + { + if ((L_sum ^ L_var3) < 0) + { + L_sum = (L_var3 < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + } + else + { + *pOverflow = 1; + L_sum = MAX_32; + } + return (L_sum); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_mult + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + L_var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit add operation resulted in overflow + + Returns: + L_product = 32-bit product of L_var1 and L_var2 (Word32) + */ + static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 L_product; + + L_product = (Word32) var1 * var2; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; /* Multiply by 2 */ + } + else + { + *pOverflow = 1; + L_product = MAX_32; + } + + return (L_product); + } + + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: L_msu + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var3 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. + + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit operation resulted in overflow + + Returns: + result = 32-bit result of L_var3 - (var1 * var2) + */ + + static inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + + result = L_mult(var1, var2, pOverflow); + result = L_sub(L_var3, result, pOverflow); + + return (result); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: Mpy_32 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1_hi = most significant word of first input (Word16). + L_var1_lo = least significant word of first input (Word16). + L_var2_hi = most significant word of second input (Word16). + L_var2_lo = least significant word of second input (Word16). + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit multiply operation resulted in overflow + + Returns: + L_product = 32-bit product of L_var1 and L_var2 (Word32) + */ + static inline Word32 Mpy_32(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + { + Word32 L_product; + Word32 L_sum; + Word32 product32; + + OSCL_UNUSED_ARG(pOverflow); + L_product = (Word32) L_var1_hi * L_var2_hi; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; + } + else + { + L_product = MAX_32; + } + + /* result = mult (L_var1_hi, L_var2_lo, pOverflow); */ + product32 = ((Word32) L_var1_hi * L_var2_lo) >> 15; + + /* L_product = L_mac (L_product, result, 1, pOverflow); */ + L_sum = L_product + (product32 << 1); + + if ((L_product ^ product32) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + } + } + + L_product = L_sum; + + /* result = mult (L_var1_lo, L_var2_hi, pOverflow); */ + product32 = ((Word32) L_var1_lo * L_var2_hi) >> 15; + + /* L_product = L_mac (L_product, result, 1, pOverflow); */ + L_sum = L_product + (product32 << 1); + + if ((L_product ^ product32) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + } + } + return (L_sum); + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: Mpy_32_16 + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1_hi = most significant 16 bits of 32-bit input (Word16). + L_var1_lo = least significant 16 bits of 32-bit input (Word16). + var2 = 16-bit signed integer (Word16). + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit product operation resulted in overflow + + Returns: + product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32) + */ + + static inline Word32 Mpy_32_16(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + + Word32 L_product; + Word32 L_sum; + Word32 result; + L_product = (Word32) L_var1_hi * var2; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; + } + else + { + *pOverflow = 1; + L_product = MAX_32; + } + + result = ((Word32)L_var1_lo * var2) >> 15; + + L_sum = L_product + (result << 1); + + if ((L_product ^ result) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + return (L_sum); + + } + + /* + ------------------------------------------------------------------------------ + FUNCTION NAME: mult + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the add operation resulted in overflow + + Returns: + product = 16-bit limited product of var1 and var2 (Word16) + */ + static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 product; + + product = ((Word32) var1 * var2) >> 15; + + /* Saturate result (if necessary). */ + /* var1 * var2 >0x00007fff is the only case */ + /* that saturation occurs. */ + + if (product > 0x00007fffL) + { + *pOverflow = 1; + product = (Word32) MAX_16; + } + + + /* Return the product as a 16 bit value by type casting Word32 to Word16 */ + + return ((Word16) product); + } + + + static inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3) + { + Word32 result; + + result = L_var3 + L_var1 * L_var2; + + return result; + } + + static inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3) + { + Word32 result; + + result = L_var3 - L_var1 * L_var2; + + return result; + } + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* BASIC_OP_C_EQUIVALENT_H */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basicop_malloc.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basicop_malloc.h new file mode 100644 index 0000000..4d94c4c --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basicop_malloc.h @@ -0,0 +1,107 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: basicop_malloc.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains constant definitions and external references to the stores + used by any arithmetic function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BASICOP_MALLOC_H +#define BASICOP_MALLOC_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define MAX_32 (Word32)0x7fffffffL +#define MIN_32 (Word32)0x80000000L + +#define MAX_16 (Word16)0x7fff +#define MIN_16 (Word16)0x8000 + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern Flag Overflow; + extern Flag Carry; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitno_tab.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitno_tab.h new file mode 100644 index 0000000..b071c71 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitno_tab.h @@ -0,0 +1,134 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bitno_tab.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares a tables in bitno_tab.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BITNO_TAB_H +#define BITNO_TAB_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define BIT_0 0 +#define BIT_1 1 + +#define PRMNO_MR475 17 +#define PRMNO_MR515 19 +#define PRMNO_MR59 19 +#define PRMNO_MR67 19 +#define PRMNO_MR74 19 +#define PRMNO_MR795 23 +#define PRMNO_MR102 39 +#define PRMNO_MR122 57 +#define PRMNO_MRDTX 5 + + /* number of parameters to first subframe */ +#define PRMNOFSF_MR475 7 +#define PRMNOFSF_MR515 7 +#define PRMNOFSF_MR59 7 +#define PRMNOFSF_MR67 7 +#define PRMNOFSF_MR74 7 +#define PRMNOFSF_MR795 8 +#define PRMNOFSF_MR102 12 +#define PRMNOFSF_MR122 18 + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 prmno[]; + extern const Word16 prmnofsf[]; + extern const Word16 bitno_MR475[]; + extern const Word16 bitno_MR515[]; + extern const Word16 bitno_MR59[]; + extern const Word16 bitno_MR67[]; + extern const Word16 bitno_MR74[]; + extern const Word16 bitno_MR95[]; + extern const Word16 bitno_MR102[]; + extern const Word16 bitno_MR122[]; + extern const Word16 bitno_MRDTX[]; + extern const Word16 *const bitno[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitreorder_tab.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitreorder_tab.h new file mode 100644 index 0000000..48d8e08 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bitreorder_tab.h @@ -0,0 +1,112 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bitreorder_tab.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares a tables in bitreorder.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BITREORDER_H +#define BITREORDER_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 numOfBits[]; + extern const Word16 reorderBits_MR475[]; + extern const Word16 reorderBits_MR515[]; + extern const Word16 reorderBits_MR59[]; + extern const Word16 reorderBits_MR67[]; + extern const Word16 reorderBits_MR74[]; + extern const Word16 reorderBits_MR795[]; + extern const Word16 reorderBits_MR102[]; + extern const Word16 reorderBits_MR122[]; + + extern const Word16 *const reorderBits[]; + extern const Word16 numCompressedBytes[]; + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bytesused.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bytesused.h new file mode 100644 index 0000000..f97beae --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/bytesused.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bytesused.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares a table BytesUsed. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef BYTESUSED_H +#define BYTESUSED_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const short BytesUsed[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst.h new file mode 100644 index 0000000..b648eb7 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst.h @@ -0,0 +1,129 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + INCLUDE DESCRIPTION + + This file contains the Speech code (encoder, decoder, and postfilter) + constant parameters. + + NOTE: This file must be synchronized with /gsm-amr/asm/include/cnst.inc file. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef _CNST_H_ +#define _CNST_H_ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define L_TOTAL 320 /* Total size of speech buffer. */ +#define L_WINDOW 240 /* Window size in LP analysis */ +#define L_FRAME 160 /* Frame size */ +#define L_FRAME_BY2 80 /* Frame size divided by 2 */ +#define L_SUBFR 40 /* Subframe size */ +#define L_CODE 40 /* codevector length */ +#define NB_TRACK 5 /* number of tracks */ +#define STEP 5 /* codebook step size */ +#define NB_TRACK_MR102 4 /* number of tracks mode mr102 */ +#define STEP_MR102 4 /* codebook step size mode mr102 */ +#define M 10 /* Order of LP filter */ +#define MP1 (M+1) /* Order of LP filter + 1 */ +#define LSF_GAP 205 /* Minimum distance between LSF after quan- */ + /* tization; 50 Hz = 205 */ +#define LSP_PRED_FAC_MR122 21299 /* MR122 LSP prediction factor (0.65 Q15) */ +#define AZ_SIZE (4*M+4) /* Size of array of LP filters in 4 subfr.s */ +#define PIT_MIN_MR122 18 /* Minimum pitch lag (MR122 mode) */ +#define PIT_MIN 20 /* Minimum pitch lag (all other modes) */ +#define PIT_MAX 143 /* Maximum pitch lag */ +#define L_INTERPOL (10+1) /* Length of filter for interpolation */ +#define L_INTER_SRCH 4 /* Length of filter for CL LTP search */ + /* interpolation */ + +#define MU 26214 /* Factor for tilt compensation filter 0.8 */ +#define AGC_FAC 29491 /* Factor for automatic gain control 0.9 */ + +#define L_NEXT 40 /* Overhead in LP analysis */ +#define SHARPMAX 13017 /* Maximum value of pitch sharpening */ +#define SHARPMIN 0 /* Minimum value of pitch sharpening */ + + +#define MAX_PRM_SIZE 57 /* max. num. of params */ +#define MAX_SERIAL_SIZE 244 /* max. num. of serial bits */ + +#define GP_CLIP 15565 /* Pitch gain clipping = 0.95 */ +#define N_FRAME 7 /* old pitch gains in average calculation */ + +#define EHF_MASK 0x0008 /* encoder homing frame pattern */ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _CNST_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst_vad.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst_vad.h new file mode 100644 index 0000000..6877a1b --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/cnst_vad.h @@ -0,0 +1,133 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +**-------------------------------------------------------------------------** +** ** +** GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 ** +** R99 Version 3.2.0 ** +** REL-4 Version 4.0.0 ** +** ** +**-------------------------------------------------------------------------** +******************************************************************************** +* +* File : cnst_vad.h +* Purpose : Constants and definitions for VAD +* +******************************************************************************** +*/ +#ifndef cnst_vad_h +#define cnst_vad_h "$Id $" + +#define FRAME_LEN 160 /* Length (samples) of the input frame */ +#define COMPLEN 9 /* Number of sub-bands used by VAD */ +#define INV_COMPLEN 3641 /* 1.0/COMPLEN*2^15 */ +#define LOOKAHEAD 40 /* length of the lookahead used by speech coder */ + +#define UNITY 512 /* Scaling used with SNR calculation */ +#define UNIRSHFT 6 /* = log2(MAX_16/UNITY) */ + +#define TONE_THR (Word16)(0.65*MAX_16) /* Threshold for tone detection */ + +/* Constants for background spectrum update */ +#define ALPHA_UP1 (Word16)((1.0 - 0.95)*MAX_16) /* Normal update, upwards: */ +#define ALPHA_DOWN1 (Word16)((1.0 - 0.936)*MAX_16) /* Normal update, downwards */ +#define ALPHA_UP2 (Word16)((1.0 - 0.985)*MAX_16) /* Forced update, upwards */ +#define ALPHA_DOWN2 (Word16)((1.0 - 0.943)*MAX_16) /* Forced update, downwards */ +#define ALPHA3 (Word16)((1.0 - 0.95)*MAX_16) /* Update downwards */ +#define ALPHA4 (Word16)((1.0 - 0.9)*MAX_16) /* For stationary estimation */ +#define ALPHA5 (Word16)((1.0 - 0.5)*MAX_16) /* For stationary estimation */ + +/* Constants for VAD threshold */ +#define VAD_THR_HIGH 1260 /* Highest threshold */ +#define VAD_THR_LOW 720 /* Lowest threshold */ +#define VAD_P1 0 /* Noise level for highest threshold */ +#define VAD_P2 6300 /* Noise level for lowest threshold */ +#define VAD_SLOPE (Word16)(MAX_16*(float)(VAD_THR_LOW-VAD_THR_HIGH)/(float)(VAD_P2-VAD_P1)) + +/* Parameters for background spectrum recovery function */ +#define STAT_COUNT 20 /* threshold of stationary detection counter */ +#define STAT_COUNT_BY_2 10 /* threshold of stationary detection counter */ +#define CAD_MIN_STAT_COUNT 5 /* threshold of stationary detection counter */ + +#define STAT_THR_LEVEL 184 /* Threshold level for stationarity detection */ +#define STAT_THR 1000 /* Threshold for stationarity detection */ + +/* Limits for background noise estimate */ +#define NOISE_MIN 40 /* minimum */ +#define NOISE_MAX 16000 /* maximum */ +#define NOISE_INIT 150 /* initial */ + +/* Constants for VAD hangover addition */ +#define HANG_NOISE_THR 100 +#define BURST_LEN_HIGH_NOISE 4 +#define HANG_LEN_HIGH_NOISE 7 +#define BURST_LEN_LOW_NOISE 5 +#define HANG_LEN_LOW_NOISE 4 + +/* Thresholds for signal power */ +#define VAD_POW_LOW (Word32)15000 /* If input power is lower, */ +/* VAD is set to 0 */ +#define POW_PITCH_THR (Word32)343040 /* If input power is lower, pitch */ +/* detection is ignored */ + +#define POW_COMPLEX_THR (Word32)15000 /* If input power is lower, complex */ +/* flags value for previous frame is un-set */ + + +/* Constants for the filter bank */ +#define LEVEL_SHIFT 0 /* scaling */ +#define COEFF3 13363 /* coefficient for the 3rd order filter */ +#define COEFF5_1 21955 /* 1st coefficient the for 5th order filter */ +#define COEFF5_2 6390 /* 2nd coefficient the for 5th order filter */ + +/* Constants for pitch detection */ +#define LTHRESH 4 +#define NTHRESH 4 + +/* Constants for complex signal VAD */ +#define CVAD_THRESH_ADAPT_HIGH (Word16)(0.6 * MAX_16) /* threshold for adapt stopping high */ +#define CVAD_THRESH_ADAPT_LOW (Word16)(0.5 * MAX_16) /* threshold for adapt stopping low */ +#define CVAD_THRESH_IN_NOISE (Word16)(0.65 * MAX_16) /* threshold going into speech on */ +/* a short term basis */ + +#define CVAD_THRESH_HANG (Word16)(0.70 * MAX_16) /* threshold */ +#define CVAD_HANG_LIMIT (Word16)(100) /* 2 second estimation time */ +#define CVAD_HANG_LENGTH (Word16)(250) /* 5 second hangover */ + +#define CVAD_LOWPOW_RESET (Word16) (0.40 * MAX_16) /* init in low power segment */ +#define CVAD_MIN_CORR (Word16) (0.40 * MAX_16) /* lowest adaptation value */ + +#define CVAD_BURST 20 /* speech burst length for speech reset */ +#define CVAD_ADAPT_SLOW (Word16)(( 1.0 - 0.98) * MAX_16) /* threshold for slow adaption */ +#define CVAD_ADAPT_FAST (Word16)((1.0 - 0.92) * MAX_16) /* threshold for fast adaption */ +#define CVAD_ADAPT_REALLY_FAST (Word16)((1.0 - 0.80) * MAX_16) /* threshold for really fast */ +/* adaption */ + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_c.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_c.h new file mode 100644 index 0000000..99c2540 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_c.h @@ -0,0 +1,118 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: d_gain_c.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + File : d_gain_c.h + Purpose : Decode the fixed codebook gain using the received index. + +------------------------------------------------------------------------------ +*/ + +#ifndef _D_GAIN_C_H_ +#define _D_GAIN_C_H_ +#define d_gain_c_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "mode.h" +#include "gc_pred.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here.] + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; [Declare variables used in this module but defined elsewhere] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + /* + * Function : d_gain_code + * Purpose : Decode the fixed codebook gain using the received index. + * Description : The received index gives the gain correction factor + * gamma. The quantized gain is given by g_q = g0 * gamma + * where g0 is the predicted gain. To find g0, 4th order + * MA prediction is applied to the mean-removed innovation + * energy in dB. + * Returns : void + */ + void d_gain_code( + gc_predState *pred_state, /* i/o : MA predictor state */ + enum Mode mode, /* i : AMR mode */ + Word16 index, /* i : received quantization index */ + Word16 code[], /* i : innovation codevector */ + const Word16* qua_gain_code_ptr, /* i : Pointer to read-only table */ + Word16 *gain_code, /* o : decoded innovation gain */ + Flag *pOverflow + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _D_GAIN_C_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_p.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_p.h new file mode 100644 index 0000000..04babd9 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_gain_p.h @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : d_gain_p.h +* Purpose : Decodes the pitch gain using the received index. +* +******************************************************************************** +*/ +#ifndef d_gain_p_h +#define d_gain_p_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "mode.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ************************************************************************** + * + * Function : d_gain_pitch + * Purpose : Decodes the pitch gain using the received index. + * Description : In case of no frame erasure, the gain is obtained + * from the quantization table at the given index; + * otherwise, a downscaled past gain is used. + * Returns : Quantized pitch gain + * + ************************************************************************** + */ + Word16 d_gain_pitch( /* return value: gain (Q14) */ + enum Mode mode, /* i : AMR mode */ + Word16 index, /* i : index of quantization */ + const Word16* qua_gain_pitch_ptr /* i : pointer to read-only tables */ + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_plsf.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_plsf.h new file mode 100644 index 0000000..dbefcba --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/d_plsf.h @@ -0,0 +1,190 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: d_plsf.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the d_plsf_3.c and d_plsf_5.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef d_plsf_h +#define d_plsf_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" +#include "mode.h" +#include "get_const_tbls.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + typedef struct + { + Word16 past_r_q[M]; /* Past quantized prediction error, Q15 */ + Word16 past_lsf_q[M]; /* Past dequantized lsfs, Q15 */ + } D_plsfState; + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /* + ************************************************************************** + * + * Function : D_plsf_reset + * Purpose : Resets state memory + * Returns : 0 on success + * + ************************************************************************** + */ + Word16 D_plsf_reset(D_plsfState *st, const Word16* mean_lsf_5_ptr); + + /* + ************************************************************************** + * + * Function : D_plsf_exit + * Purpose : The memory used for state memory is freed + * Description : Stores NULL in *st + * Returns : void + * + ************************************************************************** + */ + void D_plsf_exit(D_plsfState **st); + + /* + ************************************************************************** + * + * Function : D_plsf_5 + * Purpose : Decodes the 2 sets of LSP parameters in a frame + * using the received quantization indices. + * Description : The two sets of LSFs are quantized using split by + * 5 matrix quantization (split-MQ) with 1st order MA + * prediction. + * See "q_plsf_5.c" for more details about the + * quantization procedure + * Returns : 0 + * + ************************************************************************** + */ + void D_plsf_5( + D_plsfState *st, /* i/o: State variables */ + Word16 bfi, /* i : bad frame indicator (set to 1 if a bad + frame is received) */ + Word16 *indice, /* i : quantization indices of 5 submatrices, Q0 */ + CommonAmrTbls* common_amr_tbls, /* i : structure containing ptrs to read-only tables */ + Word16 *lsp1_q, /* o : quantized 1st LSP vector (M) Q15 */ + Word16 *lsp2_q, /* o : quantized 2nd LSP vector (M) Q15 */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ); + + /************************************************************************* + * + * FUNCTION: D_plsf_3() + * + * PURPOSE: Decodes the LSP parameters using the received quantization + * indices.1st order MA prediction and split by 3 matrix + * quantization (split-MQ) + * + *************************************************************************/ + + void D_plsf_3( + D_plsfState *st, /* i/o: State struct */ + enum Mode mode, /* i : coder mode */ + Word16 bfi, /* i : bad frame indicator (set to 1 if a */ + /* bad frame is received) */ + Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */ + CommonAmrTbls* common_amr_tbls, /* i : structure containing ptrs to read-only tables */ + Word16 * lsp1_q, /* o : quantized 1st LSP vector, Q15 */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ); + + /************************************************************************* + * + * FUNCTION: Init_D_plsf_3() + * + * PURPOSE: Set the past_r_q[M] vector to one of the eight + * past_rq_init vectors. + * + *************************************************************************/ + void Init_D_plsf_3(D_plsfState *st, /* i/o: State struct */ + Word16 index, /* i : past_rq_init[] index [0, 7] */ + const Word16* past_rq_init_ptr /* ptr to read-only table */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _Q_PLSF_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/div_s.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/div_s.h new file mode 100644 index 0000000..98aa0f9 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/div_s.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: div_s.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the div_s function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef DIV_S_H +#define DIV_S_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 div_s(Word16 var1, Word16 var2); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/dtx_common_def.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/dtx_common_def.h new file mode 100644 index 0000000..0daa965 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/dtx_common_def.h @@ -0,0 +1,96 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: dtx_common_def.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + File : dtx_common_def.h + Purpose : DTX definitions common to encoder and decoder + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef DTX_COMMON_DEF_H +#define DTX_COMMON_DEF_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define DTX_MAX_EMPTY_THRESH 50 +#define DTX_HIST_SIZE 8 +#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1) +#define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* DTX_COMMON_DEF_H */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame.h new file mode 100644 index 0000000..1d0c6c1 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame.h @@ -0,0 +1,114 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +***************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +***************************************************************************** +* +* File : frame.h +* Purpose : Declaration of received and transmitted frame types +* +***************************************************************************** +*/ +#ifndef frame_h +#define frame_h "$Id $" + +/* +***************************************************************************** +* INCLUDE FILES +***************************************************************************** +*/ + + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ***************************************************************************** + * DEFINITION OF DATA TYPES + ***************************************************************************** + * Note: The order of the TX and RX_Type identifiers has been chosen in + * the way below to be compatible to an earlier version of the + * AMR-NB C reference program. + ***************************************************************************** + */ + + enum RXFrameType { RX_SPEECH_GOOD = 0, + RX_SPEECH_DEGRADED, + RX_ONSET, + RX_SPEECH_BAD, + RX_SID_FIRST, + RX_SID_UPDATE, + RX_SID_BAD, + RX_NO_DATA, + RX_N_FRAMETYPES /* number of frame types */ + }; + + enum TXFrameType { TX_SPEECH_GOOD = 0, + TX_SID_FIRST, + TX_SID_UPDATE, + TX_NO_DATA, + TX_SPEECH_DEGRADED, + TX_SPEECH_BAD, + TX_SID_BAD, + TX_ONSET, + TX_N_FRAMETYPES /* number of frame types */ + }; + + + /* Channel decoded frame type */ + enum CHDECFrameType { CHDEC_SID_FIRST = 0, + CHDEC_SID_FIRST_INCOMPLETE, + CHDEC_SID_UPDATE_INCOMPLETE, + CHDEC_SID_UPDATE, + CHDEC_SPEECH, + CHDEC_SPEECH_ONSET, + CHDEC_ESCAPE_MARKER, + CHDEC_ESCAPE_DATA, + CHDEC_NO_DATA + }; + + /* Channel decoded frame quality */ + enum CHDECFrameQuality { CHDEC_GOOD = 0, + CHDEC_PROBABLY_DEGRADED, + CHDEC_PROBABLY_BAD, + CHDEC_BAD + }; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame_type_3gpp.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame_type_3gpp.h new file mode 100644 index 0000000..f82ec46 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/frame_type_3gpp.h @@ -0,0 +1,113 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: frame_type_3gpp.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains the definition of the 3GPP frame types. + +------------------------------------------------------------------------------ +*/ + +#ifndef FRAME_TYPE_3GPP_H +#define FRAME_TYPE_3GPP_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + enum Frame_Type_3GPP + { + AMR_475 = 0, + AMR_515, + AMR_59, + AMR_67, + AMR_74, + AMR_795, + AMR_102, + AMR_122, + AMR_SID, + GSM_EFR_SID, + TDMA_EFR_SID, + PDC_EFR_SID, + FOR_FUTURE_USE1, + FOR_FUTURE_USE2, + FOR_FUTURE_USE3, + AMR_NO_DATA + }; + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + + +#endif /* _FRAME_TYPE_3GPP_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gc_pred.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gc_pred.h new file mode 100644 index 0000000..f2c1f55 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gc_pred.h @@ -0,0 +1,166 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: gc_pred.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + File : gc_pred.h + Purpose : codebook gain MA prediction + +------------------------------------------------------------------------------ +*/ + +#ifndef _GC_PRED_H_ +#define _GC_PRED_H_ +#define gc_pred_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "mode.h" + + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; [Declare variables used in this module but defined elsewhere] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + typedef struct + { + Word16 past_qua_en[4]; /* normal MA predictor memory, Q10 */ + /* (contains 20*log10(qua_err)) */ + Word16 past_qua_en_MR122[4]; /* MA predictor memory for MR122 mode, Q10 */ + /* (contains log2(qua_err)) */ + } gc_predState; + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + OSCL_IMPORT_REF Word16 gc_pred_reset(gc_predState *st); + /* reset of codebook gain MA predictor state (i.e. set state memory to zero) + returns 0 on success + */ + void gc_pred_exit(gc_predState **st); + /* de-initialize codebook gain MA predictor state (i.e. free state struct) + stores NULL in *st + */ + + void + gc_pred_copy( + gc_predState *st_src, /* i : State struct */ + gc_predState *st_dest /* o : State struct */ + ); + + /* + * FUNCTION: gc_pred() + * PURPOSE: MA prediction of the innovation energy + * (in dB/(20*log10(2))) with mean removed). + */ + OSCL_IMPORT_REF void gc_pred( + gc_predState *st, /* i/o: State struct */ + enum Mode mode, /* i : AMR mode */ + Word16 *code, /* i : innovative codebook vector (L_SUBFR) */ + /* MR122: Q12, other modes: Q13 */ + Word16 *exp_gcode0, /* o : exponent of predicted gain factor, Q0 */ + Word16 *frac_gcode0,/* o : fraction of predicted gain factor Q15 */ + Word16 *exp_en, /* o : exponent of innovation energy, Q0 */ + /* (only calculated for MR795) */ + Word16 *frac_en, /* o : fraction of innovation energy, Q15 */ + /* (only calculated for MR795) */ + Flag *pOverflow + ); + + /* + * FUNCTION: gc_pred_update() + * PURPOSE: update MA predictor with last quantized energy + */ + OSCL_IMPORT_REF void gc_pred_update( + gc_predState *st, /* i/o: State struct */ + Word16 qua_ener_MR122, /* i : quantized energy for update, Q10 */ + /* (log2(qua_err)) */ + Word16 qua_ener /* i : quantized energy for update, Q10 */ + /* (20*log10(qua_err)) */ + ); + + /* + * FUNCTION: gc_pred_average_limited() + * PURPOSE: get average of MA predictor state values (with a lower limit) + * [used in error concealment] + */ + OSCL_IMPORT_REF void gc_pred_average_limited( + gc_predState *st, /* i: State struct */ + Word16 *ener_avg_MR122, /* o: averaged quantized energy, Q10 */ + /* (log2(qua_err)) */ + Word16 *ener_avg, /* o: averaged quantized energy, Q10 */ + /* (20*log10(qua_err)) */ + Flag *pOverflow + ); + + +#ifdef __cplusplus +} +#endif + +#endif /* _GC_PRED_H_ */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/get_const_tbls.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/get_const_tbls.h new file mode 100644 index 0000000..cb617b5 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/get_const_tbls.h @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +#ifndef GET_CONST_TBLS_H +#define GET_CONST_TBLS_H + +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct + { + const Word16* dgray_ptr; + const Word16* dico1_lsf_3_ptr; + const Word16* dico1_lsf_5_ptr; + const Word16* dico2_lsf_3_ptr; + const Word16* dico2_lsf_5_ptr; + const Word16* dico3_lsf_3_ptr; + const Word16* dico3_lsf_5_ptr; + const Word16* dico4_lsf_5_ptr; + const Word16* dico5_lsf_5_ptr; + const Word16* gray_ptr; + const Word16* lsp_init_data_ptr; + const Word16* mean_lsf_3_ptr; + const Word16* mean_lsf_5_ptr; + const Word16* mr515_3_lsf_ptr; + const Word16* mr795_1_lsf_ptr; + const Word16* past_rq_init_ptr; + const Word16* pred_fac_3_ptr; + const Word16* qua_gain_code_ptr; + const Word16* qua_gain_pitch_ptr; + const Word16* startPos_ptr; + const Word16* table_gain_lowrates_ptr; + const Word16* table_gain_highrates_ptr; + const Word16* prmno_ptr; + const Word16* const* bitno_ptr; + const Word16* numOfBits_ptr; + const Word16* const* reorderBits_ptr; + const Word16* numCompressedBytes_ptr; + const Word16* window_200_40_ptr; + const Word16* window_160_80_ptr; + const Word16* window_232_8_ptr; + const Word16* ph_imp_low_MR795_ptr; + const Word16* ph_imp_mid_MR795_ptr; + const Word16* ph_imp_low_ptr; + const Word16* ph_imp_mid_ptr; + } CommonAmrTbls; + + OSCL_IMPORT_REF void get_const_tbls(CommonAmrTbls* tbl_struct_ptr); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gmed_n.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gmed_n.h new file mode 100644 index 0000000..49f4c51 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gmed_n.h @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : gmed_n.h +* Purpose : calculates N-point median. +* +******************************************************************************** +*/ +#ifndef gmed_n_h +#define gmed_n_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + + /* + ******************************************************************************** + * DECLARATION OF PROTOTYPES + ******************************************************************************** + */ + OSCL_IMPORT_REF Word16 gmed_n( /* o : index of the median value (0...N-1) */ + Word16 ind[], /* i : Past gain values */ + Word16 n /* i : The number of gains; this routine */ + /* is only valid for a odd number of gains */ + ); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gsm_amr_typedefs.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gsm_amr_typedefs.h new file mode 100644 index 0000000..465e705 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/gsm_amr_typedefs.h @@ -0,0 +1,147 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: gsm_amr_typedefs.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains the definition of the amr codec types. + +------------------------------------------------------------------------------ +*/ +#ifndef GSM_AMR_TYPEDEFS_H +#define GSM_AMR_TYPEDEFS_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +#include "oscl_base.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL VARIABLES REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; SIMPLE TYPEDEF'S +----------------------------------------------------------------------------*/ + +#ifndef Word8 +typedef int8 Word8; +#endif + +#ifndef UWord8 +typedef uint8 UWord8; +#endif + + +/*---------------------------------------------------------------------------- +; Define 16 bit signed and unsigned words +----------------------------------------------------------------------------*/ + +#ifndef Word16 +typedef int16 Word16; + +#endif + +#ifndef UWord16 +typedef uint16 UWord16; + +#endif + +/*---------------------------------------------------------------------------- +; Define 32 bit signed and unsigned words +----------------------------------------------------------------------------*/ + +#ifndef Word32 +typedef int32 Word32; +#endif + +#ifndef UWord32 +typedef uint32 UWord32; +#endif + + +/*---------------------------------------------------------------------------- +; Define boolean type +----------------------------------------------------------------------------*/ +#ifndef Bool +typedef int Bool; +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef OFF +#define OFF 0 +#endif + +#ifndef ON +#define ON 1 +#endif + +#ifndef NO +#define NO 0 +#endif + +#ifndef YES +#define YES 1 +#endif + +#ifndef SUCCESS +#define SUCCESS 0 +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef Flag +typedef int32 Flag; +#endif + +#endif /* GSM_AMR_TYPEDEFS_H */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lpc.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lpc.h new file mode 100644 index 0000000..3f241cb --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lpc.h @@ -0,0 +1,201 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: int_lpc.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the lsp_avg.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef int_lpc_h +#define int_lpc_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /* + ************************************************************************** + * + * Function : Int_lpc_1and3 + * Purpose : Interpolates the LSPs and converts to LPC parameters + * to get a different LP filter in each subframe. + * Description : The 20 ms speech frame is divided into 4 subframes. + * The LSPs are quantized and transmitted at the 2nd and + * 4th subframes (twice per frame) and interpolated at the + * 1st and 3rd subframe. + * + * |------|------|------|------| + * sf1 sf2 sf3 sf4 + * F0 Fm F1 + * + * sf1: 1/2 Fm + 1/2 F0 sf3: 1/2 F1 + 1/2 Fm + * sf2: Fm sf4: F1 + * Returns : void + * + ************************************************************************** + */ + OSCL_IMPORT_REF void Int_lpc_1and3( + Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */ + Word16 lsp_mid[], /* i : LSP vector at the 2nd subfr. of + present frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th subfr. of + present frame (M) */ + Word16 Az[], /* o : interpolated LP parameters in all subfr. + (AZ_SIZE) */ + Flag *pOverflow + ); + + /* + ************************************************************************** + * + * Function : Int_lpc_1and3_2 + * Purpose : Interpolation of the LPC parameters. Same as the Int_lpc + * function but we do not recompute Az() for subframe 2 and + * 4 because it is already available. + * Returns : void + * + ************************************************************************** + */ + void Int_lpc_1and3_2( + Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */ + Word16 lsp_mid[], /* i : LSP vector at the 2nd subframe of + present frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th subframe of + present frame (M) */ + Word16 Az[], /* o :interpolated LP parameters + in subframes 1 and 3 (AZ_SIZE) */ + Flag *pOverflow + ); + + /* + ************************************************************************** + * + * Function : Int_lpc_1to3 + * Purpose : Interpolates the LSPs and converts to LPC parameters + * to get a different LP filter in each subframe. + * Description : The 20 ms speech frame is divided into 4 subframes. + * The LSPs are quantized and transmitted at the 4th + * subframes (once per frame) and interpolated at the + * 1st, 2nd and 3rd subframe. + * + * |------|------|------|------| + * sf1 sf2 sf3 sf4 + * F0 F1 + * + * sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1 + * sf2: 1/2 F0 + 1/2 F1 sf4: F1 + * Returns : void + * + ************************************************************************** + */ + OSCL_IMPORT_REF void Int_lpc_1to3( + Word16 lsp_old[], /* i : LSP vector at the 4th SF of past frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th SF of present frame (M) */ + Word16 Az[], /* o : interpolated LP parameters in all SFs (AZ_SIZE) */ + Flag *pOverflow + ); + + /* + ************************************************************************** + * + * Function : Int_lpc_1to3_2 + * Purpose : Interpolation of the LPC parameters. Same as the Int_lpc + * function but we do not recompute Az() for subframe 4 + * because it is already available. + * Returns : void + * + ************************************************************************** + */ + void Int_lpc_1to3_2( + Word16 lsp_old[], /* i : LSP vector at the 4th SF of past frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th SF present frame (M) */ + Word16 Az[], /* o :interpolated LP parameters in SFs 1, 2, 3 + (AZ_SIZE) */ + Flag *pOverflow + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _INT_LPC_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lsf.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lsf.h new file mode 100644 index 0000000..2ee9e71 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/int_lsf.h @@ -0,0 +1,105 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: int_lsf.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the int_lsf function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef int_lsf_h +#define int_lsf_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void Int_lsf( + Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame */ + Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame */ + Word16 i_subfr, /* i : Current sf (equal to 0,40,80 or 120) */ + Word16 lsf_out[], /* o : interpolated LSF parameters for current sf */ + Flag *pOverflow /* o : flag set if overflow occurs */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _INT_LSF_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/inv_sqrt.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/inv_sqrt.h new file mode 100644 index 0000000..937a417 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/inv_sqrt.h @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: inv_sqrt.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the inv_sqrt() function. + +------------------------------------------------------------------------------ +*/ + +#ifndef INV_SQRT_H +#define INV_SQRT_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 inv_sqrt_tbl[]; + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word32 Inv_sqrt( /* (o) : output value */ + Word32 L_x, /* (i) : input value */ + Flag *pOverflow /* (i) : pointer to overflow flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _INV_SQRT_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add.h new file mode 100644 index 0000000..8fceb9d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add.h @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_add.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_add function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_ADD_H +#define L_ADD_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow) + { + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + __asm + { + QADD result, L_var1, L_var2 + } + return(result); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow) + { + register Word32 ra = L_var1; + register Word32 rb = L_var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("qadd %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(rb) + ); + return (result); + + } + +#else /* C EQUIVALENT */ + + + static inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow) + { + Word32 L_sum; + + L_sum = L_var1 + L_var2; + + if ((L_var1 ^ L_var2) >= 0) + { + if ((L_sum ^ L_var1) < 0) + { + L_sum = (L_var1 < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + + return (L_sum); + } + +#endif + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_ADD_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add_c.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add_c.h new file mode 100644 index 0000000..7af7cdc --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add_c.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_add_c.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_add_c function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_ADD_C_H +#define L_ADD_C_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word32 L_add_c(Word32 L_var1, Word32 L_var2, Flag *pOverflow, Flag *pCarry); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_ADD_C_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_comp.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_comp.h new file mode 100644 index 0000000..7738ad2 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_comp.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_comp.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_comp function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_COMP_H +#define L_COMP_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word32 L_Comp(Word16 hi, Word16 lo, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_extract.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_extract.h new file mode 100644 index 0000000..2816f83 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_extract.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_extract.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_extract function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_EXTRACT_H +#define L_EXTRACT_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void L_Extract(Word32 L_var, + Word16 *pL_var_hi, + Word16 *pL_var_lo, + Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_EXTRACT_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mac.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mac.h new file mode 100644 index 0000000..865f043 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mac.h @@ -0,0 +1,166 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_mac.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_mac function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_MAC_H +#define L_MAC_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + Word32 L_sum; + + OSCL_UNUSED_ARG(pOverflow); + + __asm {SMULBB result, var1, var2} + __asm {QDADD L_sum, L_var3, result} + return (L_sum); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 ra = L_var3; + register Word32 rb = var1; + register Word32 rc = var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(result) + : "r"(rb), "r"(rc) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(rc) + : "r"(ra), "r"(result) + ); + + return (rc); + } + +#else /* C_EQUIVALENT */ + + __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + Word32 L_sum; + result = (Word32) var1 * var2; + if (result != (Word32) 0x40000000L) + { + L_sum = (result << 1) + L_var3; + + /* Check if L_sum and L_var_3 share the same sign */ + if ((L_var3 ^ result) > 0) + { + if ((L_sum ^ L_var3) < 0) + { + L_sum = (L_var3 < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + } + else + { + *pOverflow = 1; + L_sum = MAX_32; + } + return (L_sum); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_MAC_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_msu.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_msu.h new file mode 100644 index 0000000..b1a51ba --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_msu.h @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_msu.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_msu function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_MSU_H +#define L_MSU_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" +#include "l_mult.h" +#include "l_sub.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 product; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + __asm + { + SMULBB product, var1, var2 + QDSUB result, L_var3, product + } + + return (result); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 ra = L_var3; + register Word32 rb = var1; + register Word32 rc = var2; + Word32 product; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product) + : "r"(rb), "r"(rc) + ); + + asm volatile("qdsub %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(product) + ); + + return (result); + } + +#else /* C EQUIVALENT */ + + static inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + + result = L_mult(var1, var2, pOverflow); + result = L_sub(L_var3, result, pOverflow); + + return (result); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _L_MSU_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mult.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mult.h new file mode 100644 index 0000000..2aaea47 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mult.h @@ -0,0 +1,162 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_mult.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_mult function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_MULT_H +#define L_MULT_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 result; + Word32 product; + + OSCL_UNUSED_ARG(pOverflow); + + __asm + { + SMULBB product, var1, var2 + QADD result, product, product + } + + return (result); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 ra = var1; + register Word32 rb = var2; + Word32 result; + Word32 product; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product) + : "r"(ra), "r"(rb) + ); + + asm volatile("qadd %0, %1, %2" + : "=r"(result) + : "r"(product), "r"(product) + ); + + return(result); + } + +#else /* C EQUIVALENT */ + + static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 L_product; + + L_product = (Word32) var1 * var2; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; /* Multiply by 2 */ + } + else + { + *pOverflow = 1; + L_product = MAX_32; + } + + return (L_product); + } +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_MULT_H */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_negate.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_negate.h new file mode 100644 index 0000000..e406bb8 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_negate.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_negate.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_negate function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_NEGATE_H +#define L_NEGATE_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word32 L_negate(Word32 L_var1); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shl.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shl.h new file mode 100644 index 0000000..5430bc7 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shl.h @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_shl.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_shl function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_SHL_H +#define L_SHL_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word32 L_shl(Word32 L_var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_SHL_H_ */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr.h new file mode 100644 index 0000000..424c948 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_shr.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_shr function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_SHR_H +#define L_SHR_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word32 L_shr(Word32 L_var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_SHR_H_ */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr_r.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr_r.h new file mode 100644 index 0000000..29d99da --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_shr_r.h @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_shr_r.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_shr_r function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_SHR_R_H +#define L_SHR_R_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word32 L_shr_r(Word32 L_var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_SHR_R_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_sub.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_sub.h new file mode 100644 index 0000000..a9b0732 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_sub.h @@ -0,0 +1,157 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: l_sub.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the L_sub function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef L_SUB_H +#define L_SUB_H + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow) + { + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + __asm + { + QSUB result, L_var1, L_var2 + } + + return(result); + + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow) + { + register Word32 ra = L_var1; + register Word32 rb = L_var2; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("qsub %0, %1, %2" + : "=r"(result) + : "r"(ra), "r"(rb) + ); + + return (result); + } + +#else /* C EQUIVALENT */ + + static inline Word32 L_sub(register Word32 L_var1, register Word32 L_var2, + register Flag *pOverflow) + { + Word32 L_diff; + + L_diff = L_var1 - L_var2; + + if ((L_var1 ^ L_var2) < 0) + { + if ((L_diff ^ L_var1) & MIN_32) + { + L_diff = (L_var1 < 0L) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + + return (L_diff); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _L_SUB_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2.h new file mode 100644 index 0000000..ce27dba --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2.h @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: log2.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains the function prototype definition for Log2 function. + +------------------------------------------------------------------------------ +*/ +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef LOG2_H +#define LOG2_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +#include "log2_norm.h" /* Used by legacy files */ + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF void Log2( + Word32 L_x, /* (i) : input value */ + Word16 *pExponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/ + Word16 *pFraction, /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Flag *pOverflow /* (i/o) : overflow flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LOG2_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2_norm.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2_norm.h new file mode 100644 index 0000000..3b06244 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/log2_norm.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: log2_norm.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains the prototype declaration for Log2_norm function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef LOG2_NORM_H +#define LOG2_NORM_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 log2_tbl[]; + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void Log2_norm( + Word32 L_x, /* (i) : input value (normalized) */ + Word16 exp, /* (i) : norm_l (L_x) */ + Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ + Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LOG2_NORM_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsfwt.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsfwt.h new file mode 100644 index 0000000..cca36d4 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsfwt.h @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsfwt.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the lsfwt.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef lsfwt_h +#define lsfwt_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void Lsf_wt( + Word16 *lsf, /* input : LSF vector */ + Word16 *wf, /* output: square of weighting factors */ + Flag * pOverflow); /* o : Flag set when overflow occurs */ + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LSF_WT_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp.h new file mode 100644 index 0000000..99b6151 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp.h @@ -0,0 +1,173 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsp.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the lsp.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef lsp_h +#define lsp_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "q_plsf.h" +#include "mode.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + typedef struct + { + + /* Past LSPs */ + Word16 lsp_old[M]; + Word16 lsp_old_q[M]; + + /* Quantization state */ + Q_plsfState *qSt; + + } lspState; + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + /* + ************************************************************************** + * + * Function : lsp_init + * Purpose : Allocates memory and initializes state variables + * Description : Stores pointer to filter status struct in *st. This + * pointer has to be passed to lsp in each call. + * Returns : 0 on success + * + ************************************************************************** + */ + OSCL_IMPORT_REF Word16 lsp_init(lspState **st); + + /* + ************************************************************************** + * + * Function : lsp_reset + * Purpose : Resets state memory + * Returns : 0 on success + * + ************************************************************************** + */ + OSCL_IMPORT_REF Word16 lsp_reset(lspState *st); + + /* + ************************************************************************** + * + * Function : lsp_exit + * Purpose : The memory used for state memory is freed + * Description : Stores NULL in *st + * + ************************************************************************** + */ + OSCL_IMPORT_REF void lsp_exit(lspState **st); + + /* + ************************************************************************** + * + * Function : lsp + * Purpose : Conversion from LP coefficients to LSPs. + * Quantization of LSPs. + * Description : Generates 2 sets of LSPs from 2 sets of + * LP coefficients for mode 12.2. For the other + * modes 1 set of LSPs is generated from 1 set of + * LP coefficients. These LSPs are quantized with + * Matrix/Vector quantization (depending on the mode) + * and interpolated for the subframes not yet having + * their own LSPs. + * + ************************************************************************** + */ + OSCL_IMPORT_REF void lsp(lspState *st, /* i/o : State struct */ + enum Mode req_mode, /* i : requested coder mode */ + enum Mode used_mode,/* i : used coder mode */ + Word16 az[], /* i/o : interpolated LP parameters Q12 */ + Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/ + Word16 lsp_new[], /* o : new lsp vector */ + Word16 **anap, /* o : analysis parameters */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LSP_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_az.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_az.h new file mode 100644 index 0000000..fb3d248 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_az.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsp_az.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the lsp_az function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef LSP_AZ_H +#define LSP_AZ_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF void Lsp_Az( + Word16 lsp[], /* (i) : line spectral frequencies */ + Word16 a[], /* (o) : predictor coefficients (order = 10) */ + Flag *pOverflow /* (o) : overflow flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LSP_AZ_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_lsf.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_lsf.h new file mode 100644 index 0000000..ac7fca0 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_lsf.h @@ -0,0 +1,111 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: lsp_lsf.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the lsp_lsf.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef lsp_lsf_h +#define lsp_lsf_h + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + OSCL_IMPORT_REF void Lsf_lsp( + Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */ + Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */ + Word16 m, /* (i) : LPC order */ + Flag *pOverflow /* (o) : Flag set when overflow occurs */ + ); + OSCL_IMPORT_REF void Lsp_lsf( + Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */ + Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */ + Word16 m, /* (i) : LPC order */ + Flag *pOverflow /* (o) : Flag set when overflow occurs */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _LSP_LSF_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_tab.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_tab.h new file mode 100644 index 0000000..db3cd52 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/lsp_tab.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsp_tab.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares a table lsp_init_data. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef LSP_TAB_H +#define LSP_TAB_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 lsp_init_data[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mac_32.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mac_32.h new file mode 100644 index 0000000..b79a84f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mac_32.h @@ -0,0 +1,136 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mac_32.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the Mac_32 and Mac_32_16 functions + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef MAC_32_H +#define MAC_32_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + static inline Word32 Mac_32(Word32 L_var3, + Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + { + Word16 product; + + L_var3 = L_mac(L_var3, L_var1_hi, L_var2_hi, pOverflow); + + product = mult(L_var1_hi, L_var2_lo, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + product = mult(L_var1_lo, L_var2_hi, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + return (L_var3); + } + + static inline Word32 Mac_32_16(Word32 L_var3, + Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + Word16 product; + + L_var3 = L_mac(L_var3, L_var1_hi, var2, pOverflow); + + product = mult(L_var1_lo, var2, pOverflow); + L_var3 = L_mac(L_var3, product, 1, pOverflow); + + return (L_var3); + } + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _MAC_32_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mode.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mode.h new file mode 100644 index 0000000..75f86cb --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mode.h @@ -0,0 +1,82 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : mode.h +* Purpose : Declaration of mode type +* +******************************************************************************** +*/ +#ifndef mode_h +#define mode_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ + + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + enum Mode { MR475 = 0, + MR515, + MR59, + MR67, + MR74, + MR795, + MR102, + MR122, + + MRDTX, + + N_MODES /* number of (SPC) modes */ + + }; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32.h new file mode 100644 index 0000000..f2cb7cf --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32.h @@ -0,0 +1,258 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mpy_32.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the Mpy_32 function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef MPY_32_H +#define MPY_32_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 Mpy_32(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + + { + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + Word32 L_product; + Word32 L_sum; + Word32 product32; + + OSCL_UNUSED_ARG(pOverflow); + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + /* L_product = L_mult (L_var1_hi, L_var2_hi, pOverflow);*/ + + __asm {SMULBB L_product, L_var1_hi, L_var2_hi} + __asm {QDADD L_product, 0, L_product} + __asm {SMULBB product32, L_var1_hi, L_var2_lo} + product32 >>= 15; + __asm {QDADD L_sum, L_product, product32} + L_product = L_sum; + __asm {SMULBB product32, L_var1_lo, L_var2_hi} + product32 >>= 15; + __asm {QDADD L_sum, L_product, product32} + return (L_sum); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + static inline Word32 Mpy_32(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + { + register Word32 product32; + register Word32 L_sum; + register Word32 L_product, result; + register Word32 ra = L_var1_hi; + register Word32 rb = L_var1_lo; + register Word32 rc = L_var2_hi; + register Word32 rd = L_var2_lo; + + + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(L_product) + : "r"(ra), "r"(rc) + ); + asm volatile("mov %0, #0" + : "=r"(result) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_sum) + : "r"(result), "r"(L_product) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product32) + : "r"(ra), "r"(rd) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(ra) + : "r"(product32) + ); + asm volatile("qdadd %0, %1, %2" + : "=r"(L_product) + : "r"(L_sum), "r"(ra) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product32) + : "r"(rb), "r"(rc) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(rb) + : "r"(product32) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_sum) + : "r"(L_product), "r"(rb) + ); + + return (L_sum); + } + +#else /* C_EQUIVALENT */ + + __inline Word32 Mpy_32(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 L_var2_hi, + Word16 L_var2_lo, + Flag *pOverflow) + { + Word32 L_product; + Word32 L_sum; + Word32 product32; + + OSCL_UNUSED_ARG(pOverflow); + L_product = (Word32) L_var1_hi * L_var2_hi; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; + } + else + { + L_product = MAX_32; + } + + /* result = mult (L_var1_hi, L_var2_lo, pOverflow); */ + product32 = ((Word32) L_var1_hi * L_var2_lo) >> 15; + + /* L_product = L_mac (L_product, result, 1, pOverflow); */ + L_sum = L_product + (product32 << 1); + + if ((L_product ^ product32) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + } + } + + L_product = L_sum; + + /* result = mult (L_var1_lo, L_var2_hi, pOverflow); */ + product32 = ((Word32) L_var1_lo * L_var2_hi) >> 15; + + /* L_product = L_mac (L_product, result, 1, pOverflow); */ + L_sum = L_product + (product32 << 1); + + if ((L_product ^ product32) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + } + } + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return (L_sum); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _MPY_32_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32_16.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32_16.h new file mode 100644 index 0000000..33ade51 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32_16.h @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mpy_32_16.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the Mpy_32_16 function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef MPY_32_16_H +#define MPY_32_16_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/ + + __inline Word32 Mpy_32_16(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + + Word32 L_product; + Word32 L_sum; + Word32 result; + + OSCL_UNUSED_ARG(pOverflow); + + __asm {SMULBB L_product, L_var1_hi, var2} + __asm {QDADD L_product, 0, L_product} + __asm {SMULBB result, L_var1_lo, var2} + result >>= 15; + __asm {QDADD L_sum, L_product, result} + return (L_sum); + } + +#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/ + + static inline Word32 Mpy_32_16(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + + register Word32 ra = L_var1_hi; + register Word32 rb = L_var1_lo; + register Word32 rc = var2; + Word32 result, L_product; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(L_product) + : "r"(ra), "r"(rc) + ); + asm volatile("mov %0, #0" + : "=r"(result) + ); + + asm volatile("qdadd %0, %1, %2" + : "=r"(L_product) + : "r"(result), "r"(L_product) + ); + + asm volatile("smulbb %0, %1, %2" + : "=r"(result) + : "r"(rb), "r"(rc) + ); + + asm volatile("mov %0, %1, ASR #15" + : "=r"(ra) + : "r"(result) + ); + asm volatile("qdadd %0, %1, %2" + : "=r"(result) + : "r"(L_product), "r"(ra) + ); + + return (result); + } + +#else /* C_EQUIVALENT */ + static inline Word32 Mpy_32_16(Word16 L_var1_hi, + Word16 L_var1_lo, + Word16 var2, + Flag *pOverflow) + { + + Word32 L_product; + Word32 L_sum; + Word32 result; + L_product = (Word32) L_var1_hi * var2; + + if (L_product != (Word32) 0x40000000L) + { + L_product <<= 1; + } + else + { + *pOverflow = 1; + L_product = MAX_32; + } + + result = ((Word32)L_var1_lo * var2) >> 15; + + L_sum = L_product + (result << 1); + + if ((L_product ^ result) > 0) + { + if ((L_sum ^ L_product) < 0) + { + L_sum = (L_product < 0) ? MIN_32 : MAX_32; + *pOverflow = 1; + } + } + return (L_sum); + + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _MPY_32_16_H_ */ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult.h new file mode 100644 index 0000000..eac2004 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult.h @@ -0,0 +1,171 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mult.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the mult function. + +------------------------------------------------------------------------------ +*/ + +#ifndef MULT_H +#define MULT_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if defined(PV_ARM_V5) + + __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + Word32 product; + + OSCL_UNUSED_ARG(pOverflow); + + __asm + { + SMULBB product, var1, var2 + MOV product, product, ASR #15 + CMP product, 0x7FFF + MOVGE product, 0x7FFF + } + + return ((Word16) product); + } + +#elif defined(PV_ARM_GCC_V5) + + __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 ra = var1; + register Word32 rb = var2; + Word32 product; + Word32 temp = 0x7FFF; + + OSCL_UNUSED_ARG(pOverflow); + + asm volatile("smulbb %0, %1, %2" + : "=r"(product) + : "r"(ra), "r"(rb) + ); + asm volatile("mov %0, %1, ASR #15" + : "=r"(product) + : "r"(product) + ); + asm volatile("cmp %0, %1" + : "=r"(product) + : "r"(temp) + ); + asm volatile("movge %0, %1" + : "=r"(product) + : "r"(temp) + ); + + return ((Word16) product); + } + +#else /* C EQUIVALENT */ + + static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) + { + register Word32 product; + + product = ((Word32) var1 * var2) >> 15; + + /* Saturate result (if necessary). */ + /* var1 * var2 >0x00007fff is the only case */ + /* that saturation occurs. */ + + if (product > 0x00007fffL) + { + *pOverflow = 1; + product = (Word32) MAX_16; + } + + + /* Return the product as a 16 bit value by type casting Word32 to Word16 */ + + return ((Word16) product); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _MULT_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult_r.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult_r.h new file mode 100644 index 0000000..90f7e83 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult_r.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mult_r.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the mult_r function. + +------------------------------------------------------------------------------ +*/ + +#ifndef MULT_R__H +#define MULT_R__H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ + +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 mult_r(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + + +#endif /* _MULT_R_H_ */ + + + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/n_proc.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/n_proc.h new file mode 100644 index 0000000..e5738c1 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/n_proc.h @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* $Id $ */ + +void proc_head(char *mes); diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/negate.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/negate.h new file mode 100644 index 0000000..2b77f77 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/negate.h @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/***************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +**************************************************************************/ +/* + Filename: negate.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the negate function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef NEGATE_H +#define NEGATE_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word16 negate(register Word16 var1); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_l.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_l.h new file mode 100644 index 0000000..faea591 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_l.h @@ -0,0 +1,138 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: norm_l.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the norm_l function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef NORM_L_H +#define NORM_L_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) ) + + /* C EQUIVALENT */ + OSCL_IMPORT_REF Word16 norm_l(Word32 L_var1); + +#elif defined(PV_ARM_V5) + + __inline Word16 norm_l(Word32 L_var1) + { + register Word32 var_out = 0; + + __asm + { + CMP L_var1, #0 + EORNE L_var1, L_var1, L_var1, LSL #1 + CLZNE var_out, L_var1 + } + + return ((Word16)var_out); + } + +#elif defined(PV_ARM_GCC_V5) + + static inline Word16 norm_l(Word32 L_var1) + { + register Word32 var_out = 0; + register Word32 ra = L_var1; + if (L_var1) + { + ra ^= (ra << 1); + asm volatile( + "clz %0, %1" + : "=r"(var_out) + : "r"(ra) + ); + } + return (var_out); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_s.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_s.h new file mode 100644 index 0000000..955903a --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_s.h @@ -0,0 +1,140 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: norm_s.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the norm_s function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef NORM_S_H +#define NORM_S_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ +#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) ) + + /* C EQUIVALENT */ + + OSCL_IMPORT_REF Word16 norm_s(Word16 var1); + +#elif defined(PV_ARM_V5) + + __inline Word16 norm_s(Word16 var) + { + register Word32 var_out = 0; + Word32 var1 = var << 16; + + __asm + { + CMP var1, #0 + EORNE var1, var1, var1, LSL #1 + CLZNE var_out, var1 + } + + return ((Word16)var_out); + } + +#elif defined(PV_ARM_GCC_V5) + + static inline Word16 norm_s(Word16 var1) + { + register Word32 var_out = 0; + register Word32 ra = var1 << 16; + if (ra) + { + ra ^= (ra << 1); + asm volatile( + "clz %0, %1" + : "=r"(var_out) + : "r"(ra) + ); + } + return (var_out); + } + +#endif + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/oper_32b.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/oper_32b.h new file mode 100644 index 0000000..c2ef975 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/oper_32b.h @@ -0,0 +1,92 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: oper_32b.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file includes all the oper_32b.c functions' header files. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef OPER_32B_H +#define OPER_32B_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +#include "l_comp.h" +#include "l_extract.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL VARIABLES REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; SIMPLE TYPEDEF'S +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; ENUMERATED TYPEDEF'S +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; STRUCTURES TYPEDEF'S +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; GLOBAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; END +----------------------------------------------------------------------------*/ +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/p_ol_wgh.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/p_ol_wgh.h new file mode 100644 index 0000000..f07ea36 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/p_ol_wgh.h @@ -0,0 +1,134 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: p_ol_wgh.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + File : p_ol_wgh.h + Purpose : Compute the open loop pitch lag with weighting. + +------------------------------------------------------------------------------ +*/ + +#ifndef P_OL_WGH_H +#define P_OL_WGH_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "mode.h" +#include "vad.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; [Declare variables used in this module but defined elsewhere] + ----------------------------------------------------------------------------*/ + extern const Word16 corrweight[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + /* state variable */ + + typedef struct + { + Word16 old_T0_med; + Word16 ada_w; + Word16 wght_flg; + } pitchOLWghtState; + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + Word16 p_ol_wgh_init(pitchOLWghtState **st); + /* initialize one instance of the pre processing state. + Stores pointer to filter status struct in *st. This pointer has to + be passed to p_ol_wgh in each call. + returns 0 on success + */ + + Word16 p_ol_wgh_reset(pitchOLWghtState *st); + /* reset of pre processing state (i.e. set state memory to zero) + returns 0 on success + */ + + void p_ol_wgh_exit(pitchOLWghtState **st); + /* de-initialize pre processing state (i.e. free status struct) + stores NULL in *st + */ + + Word16 Pitch_ol_wgh( /* o : open loop pitch lag */ + pitchOLWghtState *st, /* i/o : State struct */ + vadState *vadSt, /* i/o : VAD state struct */ + Word16 signal[], /* i : signal used to compute the open loop pitch */ + /* signal[-pit_max] to signal[-1] should be known */ + Word16 pit_min, /* i : minimum pitch lag */ + Word16 pit_max, /* i : maximum pitch lag */ + Word16 L_frame, /* i : length of frame to compute pitch */ + Word16 old_lags[], /* i : history with old stored Cl lags */ + Word16 ol_gain_flg[], /* i : OL gain flag */ + Word16 idx, /* i : index */ + Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */ + Flag *pOverflow /* o : overflow flag */ + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _P_OL_WGH_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pow2.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pow2.h new file mode 100644 index 0000000..ba83477 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pow2.h @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: pow2.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains the prototype declaration for Pow2() function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef POW2_H +#define POW2_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 pow2_tbl[]; + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + OSCL_IMPORT_REF Word32 Pow2( + /* (o) : result (range: 0<=val<=0x7fffffff) */ + Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ + Word16 fraction, /* (i) : Fractional part. (range: 0.0<=val<1.0) */ + Flag *pOverflow /* (i/o) : overflow flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _POW2_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pred_lt.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pred_lt.h new file mode 100644 index 0000000..28a0dd8 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pred_lt.h @@ -0,0 +1,105 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: pred_lt.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the pred_lt function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef pred_lt_h +#define pred_lt_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF void Pred_lt_3or6( + Word16 exc[], /* in/out: excitation buffer */ + Word16 T0, /* input : integer pitch lag */ + Word16 frac, /* input : fraction of lag */ + Word16 L_subfr, /* input : subframe size */ + Word16 flag3, /* input : if set, upsampling rate = 3 (6 otherwise) */ + Flag *pOverflow /* output: if set, overflow occurred in this function */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* PRED_LT_H */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pvgsmamr.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pvgsmamr.h new file mode 100644 index 0000000..b697524 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/pvgsmamr.h @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +#ifndef __PVGSMAMR_H +#define __PVGSMAMR_H + + +// includes +#include <e32std.h> +#include <e32base.h> + +#include "sp_dec.h" +#include "pvglobals.h" + + +// PVGsmDecoder AO +class CPVGsmDecoder : public CBase +{ + public: + IMPORT_C static CPVGsmDecoder* NewL(void); + IMPORT_C ~CPVGsmDecoder(); + IMPORT_C TInt StartL(void); + + // only port the API's used in PVPlayer 2.0 + IMPORT_C TInt DecodeFrame(enum Mode mode, unsigned char* compressedBlock, unsigned char* audioBuffer); + IMPORT_C TInt InitDecoder(void); + IMPORT_C void ExitDecoder(void); + + private: + CPVGsmDecoder(); + void ConstructL(void); + + Speech_Decode_FrameState* decState; + enum RXFrameType rx_type; + struct globalDataStruct *gds; +}; + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf.h new file mode 100644 index 0000000..9298d09 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf.h @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the q_plsf_3.c and q_plsf_5.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef q_plsf_h +#define q_plsf_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" +#include "mode.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define MR795_1_SIZE 512 +#define PAST_RQ_INIT_SIZE 8 + +#define DICO1_SIZE 256 +#define DICO2_SIZE 512 +#define DICO3_SIZE 512 + +#define DICO1_5_SIZE 128 +#define DICO2_5_SIZE 256 +#define DICO3_5_SIZE 256 +#define DICO4_5_SIZE 256 +#define DICO5_5_SIZE 64 + +#define MR515_3_SIZE 128 + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + typedef struct + { + Word16 past_rq[M]; /* Past quantized prediction error, Q15 */ + + } Q_plsfState; + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + Word16 Q_plsf_init(Q_plsfState **st); + /* initialize one instance of the state. + Stores pointer to filter status struct in *st. This pointer has to + be passed to Q_plsf_5 / Q_plsf_3 in each call. + returns 0 on success + */ + + Word16 Q_plsf_reset(Q_plsfState *st); + /* reset of state (i.e. set state memory to zero) + returns 0 on success + */ + + void Q_plsf_exit(Q_plsfState **st); + /* de-initialize state (i.e. free status struct) + stores NULL in *st + */ + + OSCL_IMPORT_REF void Q_plsf_3( + Q_plsfState *st, /* i/o: state struct */ + enum Mode mode, /* i : coder mode */ + Word16 *lsp1, /* i : 1st LSP vector Q15 */ + Word16 *lsp1_q, /* o : quantized 1st LSP vector Q15 */ + Word16 *indice, /* o : quantization indices of 3 vectors Q0 */ + Word16 *pred_init_i,/* o : init index for MA prediction in DTX mode */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ); + + OSCL_IMPORT_REF void Q_plsf_5( + Q_plsfState *st, + Word16 *lsp1, /* i : 1st LSP vector, Q15 */ + Word16 *lsp2, /* i : 2nd LSP vector, Q15 */ + Word16 *lsp1_q, /* o : quantized 1st LSP vector, Q15 */ + Word16 *lsp2_q, /* o : quantized 2nd LSP vector, Q15 */ + Word16 *indice, /* o : quantization indices of 5 matrices, Q0 */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ); + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _Q_PLSF_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_3_tbl.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_3_tbl.h new file mode 100644 index 0000000..8bf7047 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_3_tbl.h @@ -0,0 +1,123 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf_3_tbl.h + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ +#define MR795_1_SIZE 512 +#define PAST_RQ_INIT_SIZE 8 + +#define DICO1_SIZE 256 +#define DICO2_SIZE 512 +#define DICO3_SIZE 512 + +#define MR515_3_SIZE 128 + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /* Codebooks of LSF prediction residual */ + extern const Word16 mean_lsf_3[]; + + extern const Word16 pred_fac_3[]; + + extern const Word16 dico1_lsf_3[]; + extern const Word16 dico2_lsf_3[]; + extern const Word16 dico3_lsf_3[]; + + extern const Word16 mr515_3_lsf[]; + extern const Word16 mr795_1_lsf[]; + + extern const Word16 past_rq_init[]; + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +} +#endif + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_5_tbl.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_5_tbl.h new file mode 100644 index 0000000..e495c4a --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/q_plsf_5_tbl.h @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf_5_tbl.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares tables defined in q_plsf_5_tbl.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef Q_PLSF_5_TBL_H +#define Q_PLSF_5_TBL_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 mean_lsf_5[]; + extern const Word16 dico1_lsf_5[]; + extern const Word16 dico2_lsf_5[]; + extern const Word16 dico3_lsf_5[]; + extern const Word16 dico4_lsf_5[]; + extern const Word16 dico5_lsf_5[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qgain475_tab.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qgain475_tab.h new file mode 100644 index 0000000..cfa5dee --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qgain475_tab.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: qgain475_tab.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares tables defined in qgain475_tab.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef QGAIN475_TAB_H +#define QGAIN475_TAB_H + +#define MR475_VQ_SIZE 256 + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 table_gain_MR475[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain.h new file mode 100644 index 0000000..951a2c4 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain.h @@ -0,0 +1,126 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: qua_gain.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the file, qua_gain.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef qua_gain_h +#define qua_gain_h "$Id $" + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "gc_pred.h" +#include "mode.h" +#include "get_const_tbls.h" + + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ +#define VQ_SIZE_HIGHRATES 128 +#define VQ_SIZE_LOWRATES 64 + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + Word16 + Qua_gain( /* o : index of quantization. */ + enum Mode mode, /* i : AMR mode */ + Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */ + Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */ + Word16 frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */ + Word16 exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */ + /* (frac_coeff and exp_coeff computed in */ + /* calc_filt_energies()) */ + Word16 gp_limit, /* i : pitch gain limit */ + Word16 *gain_pit, /* o : Pitch gain, Q14 */ + Word16 *gain_cod, /* o : Code gain, Q1 */ + Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */ + /* (for MR122 MA predictor update) */ + Word16 *qua_ener, /* o : quantized energy error, Q10 */ + /* (for other MA predictor update) */ + CommonAmrTbls* common_amr_tbls, /* i : ptr to struct of table ptrs */ + Flag *pOverflow /* o : overflow indicator */ + ); + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* qua_gain_h */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain_tbl.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain_tbl.h new file mode 100644 index 0000000..b3d2c01 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/qua_gain_tbl.h @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: qua_gain_tbl.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares tables defined in qua_gain_tbl.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef QUA_GAIN_TBL_H +#define QUA_GAIN_TBL_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 table_gain_highrates[]; + extern const Word16 table_gain_lowrates[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reorder.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reorder.h new file mode 100644 index 0000000..231bc9a --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reorder.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: reorder.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the Reorder_lsf() function. + +------------------------------------------------------------------------------ +*/ + +#ifndef REORDER_H +#define REORDER_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF void Reorder_lsf( + Word16 *lsf, /* (i/o) : vector of LSFs (range: 0<=val<=0.5) */ + Word16 min_dist, /* (i) : minimum required distance */ + Word16 n, /* (i) : LPC order */ + Flag *pOverflow /* (i/o) : overflow Flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _REORDER_H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/residu.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/residu.h new file mode 100644 index 0000000..2c6d430 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/residu.h @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : residu.h +* Purpose : Computes the LP residual. +* Description : The LP residual is computed by filtering the input +* : speech through the LP inverse filter A(z). +* +* +******************************************************************************** +*/ +#ifndef residu_h +#define residu_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + + /* + ******************************************************************************** + * DECLARATION OF PROTOTYPES + ******************************************************************************** + */ + OSCL_IMPORT_REF void Residu( + Word16 a[], /* (i) : prediction coefficients */ + Word16 x[], /* (i) : speech signal */ + Word16 y[], /* (o) : residual signal */ + Word16 lg /* (i) : size of filtering */ + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reverse_bits.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reverse_bits.h new file mode 100644 index 0000000..5933e15 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/reverse_bits.h @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: reverse_bits.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the reverse_bits function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef REVERSE_BITS_H +#define REVERSE_BITS_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "mode.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + void reverse_bits(enum Mode mode, unsigned char *pCompressedBlock); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/round.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/round.h new file mode 100644 index 0000000..f4f8072 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/round.h @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: round.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the pv_round function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef ROUND_H +#define ROUND_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 pv_round(Word32 L_var1, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _ROUND_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/set_zero.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/set_zero.h new file mode 100644 index 0000000..debd223 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/set_zero.h @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : set_zero.h +* Description : Set vector x[] to zero +* +* +******************************************************************************** +*/ +#ifndef set_zero_h +#define set_zero_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + + /* + ******************************************************************************** + * DECLARATION OF PROTOTYPES + ******************************************************************************** + */ + void Set_zero( + Word16 x[], /* (o) : vector to clear */ + Word16 L /* (i) : length of vector */ + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shl.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shl.h new file mode 100644 index 0000000..ca09201 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shl.h @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: shl.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the shl function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef SHL_H +#define SHL_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + Word16 shl(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _SHL_H_ */ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr.h new file mode 100644 index 0000000..b3149a0 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr.h @@ -0,0 +1,99 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: shr.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the shr function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef SHR_H +#define SHR_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 shr(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _SHR_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr_r.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr_r.h new file mode 100644 index 0000000..30ccf29 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/shr_r.h @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: shr_r.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the shr_r function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef SHR_R_H +#define SHR_R_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 shr_r(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sqrt_l.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sqrt_l.h new file mode 100644 index 0000000..368e9f9 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sqrt_l.h @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: sqrt_l.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the sqrt_l() function. + +------------------------------------------------------------------------------ +*/ + +#ifndef SQRT_L_H +#define SQRT_L_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 sqrt_l_tbl[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + OSCL_IMPORT_REF Word32 sqrt_l_exp( /* o : output value, Q31 */ + Word32 L_x, /* i : input value, Q31 */ + Word16 *pExp, /* o : right shift to be applied to result, Q1 */ + Flag *pOverflow /* i : pointer to overflow flag */ + ); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _SQRT_L__H_ */ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sub.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sub.h new file mode 100644 index 0000000..b28d686 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/sub.h @@ -0,0 +1,99 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: sub.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the sub function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef SUB_H +#define SUB_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basicop_malloc.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + OSCL_IMPORT_REF Word16 sub(Word16 var1, Word16 var2, Flag *pOverflow); + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif /* _SUB_H_ */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/syn_filt.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/syn_filt.h new file mode 100644 index 0000000..4d8cd13 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/syn_filt.h @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : syn_filt.h +* Purpose : Perform synthesis filtering through 1/A(z). +* +* +******************************************************************************** +*/ +#ifndef syn_filt_h +#define syn_filt_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + + /* + ******************************************************************************** + * DECLARATION OF PROTOTYPES + ******************************************************************************** + */ + OSCL_IMPORT_REF void Syn_filt( + Word16 a[], /* (i) : a[m+1] prediction coefficients (m=10) */ + Word16 x[], /* (i) : input signal */ + Word16 y[], /* (o) : output signal */ + Word16 lg, /* (i) : size of filtering */ + Word16 mem[], /* (i/o): memory associated with this filtering. */ + Word16 update /* (i) : 0=no update, 1=update of memory. */ + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/typedef.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/typedef.h new file mode 100644 index 0000000..ee4d732 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/typedef.h @@ -0,0 +1,73 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : typedef.c +* Purpose : Basic types. +* +******************************************************************************** +*/ +#ifndef typedef_h +#define typedef_h "$Id $" + +#undef ORIGINAL_TYPEDEF_H /* CHANGE THIS TO #define to get the */ +/* "original" ETSI version of typedef.h */ +/* CHANGE TO #undef for PV version */ + +#ifdef ORIGINAL_TYPEDEF_H +/* + * this is the original code from the ETSI file typedef.h + */ + +#if defined(__unix__) || defined(__unix) +typedef signed char Word8; +typedef short Word16; +typedef int Word32; +typedef int Flag; + +#else +#error No System recognized +#endif +#else /* not original typedef.h */ + +/* + * use (improved) type definition file typdefs.h + */ +#include "gsm_amr_typedefs.h" + +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/vad.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/vad.h new file mode 100644 index 0000000..b9ee89f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/vad.h @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +**-------------------------------------------------------------------------** +** ** +** GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 ** +** R99 Version 3.2.0 ** +** REL-4 Version 4.0.0 ** +** ** +**-------------------------------------------------------------------------** +******************************************************************************** +* +* File : vad.h +* Purpose : Voice Activity Detection (VAD) for AMR +* +******************************************************************************** +*/ +#ifndef vad_h +#define vad_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ + +#include "vad1.h" /* for VAD option 1 */ +#include "vad2.h" /* for VAD option 2 */ + +/* +******************************************************************************** +* LOCAL VARIABLES AND TABLES +******************************************************************************** +*/ + +/* +******************************************************************************** +* DEFINITION OF DATA TYPES +******************************************************************************** +*/ + +#ifndef VAD2 +#define vadState vadState1 +#else +#define vadState vadState2 +#endif + + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/weight_a.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/weight_a.h new file mode 100644 index 0000000..cede607 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/weight_a.h @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : weight_a.h +* Purpose : Spectral expansion of LP coefficients. (order==10) +* Description : a_exp[i] = a[i] * fac[i-1] ,i=1,10 +* +* +******************************************************************************** +*/ +#ifndef weight_a_h +#define weight_a_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + ******************************************************************************** + * DEFINITION OF DATA TYPES + ******************************************************************************** + */ + + /* + ******************************************************************************** + * DECLARATION OF PROTOTYPES + ******************************************************************************** + */ + OSCL_IMPORT_REF void Weight_Ai( + Word16 a[], /* (i) : a[m+1] LPC coefficients (m=10) */ + const Word16 fac[],/* (i) : Spectral expansion factors. */ + Word16 a_exp[] /* (o) : Spectral expanded LPC coefficients */ + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/window_tab.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/window_tab.h new file mode 100644 index 0000000..5928c54 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/window_tab.h @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: window_tab.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file declares a tables in window_tab.c used in lpc.c. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef WINDOW_TAB_H +#define WINDOW_TAB_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + extern const Word16 window_200_40[]; + extern const Word16 window_160_80[]; + extern const Word16 window_232_8[]; + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/wmf_to_ets.h b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/wmf_to_ets.h new file mode 100644 index 0000000..c005f52 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/wmf_to_ets.h @@ -0,0 +1,108 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: wmf_to_ets.h + +------------------------------------------------------------------------------ + INCLUDE DESCRIPTION + + This file contains all the constant definitions and prototype definitions + needed by the wmf_to_ets function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; CONTINUE ONLY IF NOT ALREADY DEFINED +----------------------------------------------------------------------------*/ +#ifndef WMF_TO_ETS_H +#define WMF_TO_ETS_H + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "frame_type_3gpp.h" +#include "typedef.h" +#include "get_const_tbls.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL VARIABLES REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; SIMPLE TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; ENUMERATED TYPEDEF'S + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; STRUCTURES TYPEDEF'S + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; GLOBAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + void wmf_to_ets(enum Frame_Type_3GPP frame_type_3gpp, + UWord8 *wmf_input_ptr, + Word16 *ets_output_ptr, + CommonAmrTbls* common_amr_tbls); + + + + /*---------------------------------------------------------------------------- + ; END + ----------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/add.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/add.cpp new file mode 100644 index 0000000..8085ac2 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/add.cpp @@ -0,0 +1,171 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: add.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + Summation function with overflow control + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: add +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the add operation resulted in overflow + + Returns: + sum = 16-bit limited sum of var1 and var2 (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the addition (var1+var2) with overflow control and + saturation; the 16 bit result is set at +32767 when overflow occurs or at + -32768 when underflow occurs. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] add.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + Word16 add (Word16 var1, Word16 var2) +{ + Word16 var_out; + Word32 sum; + + sum = (Word32) var1 + var2; + +* The reference ETSI code uses a global flag for Overflow inside the function +* saturate(). In the actual implementation a pointer to Overflow flag is passed in +* as a parameter to the function + + var_out = saturate (sum); +#if (WMOPS) + multiCounter[currCounter].add++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word16 add_16(Word16 var1, Word16 var2, Flag *pOverflow) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + Word32 sum; + sum = (Word32) var1 + var2; + + /* Saturate result (if necessary). */ + /* Replaced function call with in-line code */ + /* to conserve MIPS, i.e., var_out = saturate (sum) */ + + if (sum > 0X00007fffL) + { + *pOverflow = 1; + sum = MAX_16; + } + else if (sum < (Word32) 0xffff8000L) + { + *pOverflow = 1; + sum = MIN_16; + } + + /* Return the sum as a 16 bit value by type casting Word32 to Word16 */ + + return ((Word16) sum); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/az_lsp.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/az_lsp.cpp new file mode 100644 index 0000000..6f6bf4d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/az_lsp.cpp @@ -0,0 +1,665 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: az_lsp.cpp + Funtions: Chebps + Chebps_Wrapper + Az_lsp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + These modules compute the LSPs from the LP coefficients. + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "az_lsp.h" +#include "cnst.h" +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ +#define NC M/2 /* M = LPC order, NC = M/2 */ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Chebps +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + x = input value (Word16) + f = polynomial (Word16) + n = polynomial order (Word16) + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the operations in the function resulted in saturation. + + Returns: + cheb = Chebyshev polynomial for the input value x.(Word16) + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This module evaluates the Chebyshev polynomial series. + - The polynomial order is n = m/2 = 5 + - The polynomial F(z) (F1(z) or F2(z)) is given by + F(w) = 2 exp(-j5w) C(x) + where + C(x) = T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2 + and T_m(x) = cos(mw) is the mth order Chebyshev + polynomial ( x=cos(w) ) + - C(x) for the input x is returned. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + az_lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +static Word16 Chebps (Word16 x, + Word16 f[], // (n) + Word16 n) +{ + Word16 i, cheb; + Word16 b0_h, b0_l, b1_h, b1_l, b2_h, b2_l; + Word32 t0; + +// The reference ETSI code uses a global flag for Overflow. However, in the +// actual implementation a pointer to Overflow flag is passed in as a +// parameter to the function. This pointer is passed into all the basic math +// functions invoked + + b2_h = 256; // b2 = 1.0 + b2_l = 0; + + t0 = L_mult (x, 512); // 2*x + t0 = L_mac (t0, f[1], 8192); // + f[1] + L_Extract (t0, &b1_h, &b1_l); // b1 = 2*x + f[1] + + for (i = 2; i < n; i++) + { + t0 = Mpy_32_16 (b1_h, b1_l, x); // t0 = 2.0*x*b1 + t0 = L_shl (t0, 1); + t0 = L_mac (t0, b2_h, (Word16) 0x8000); // t0 = 2.0*x*b1 - b2 + t0 = L_msu (t0, b2_l, 1); + t0 = L_mac (t0, f[i], 8192); // t0 = 2.0*x*b1 - b2 + f[i] + + L_Extract (t0, &b0_h, &b0_l); // b0 = 2.0*x*b1 - b2 + f[i] + + b2_l = b1_l; // b2 = b1; + b2_h = b1_h; + b1_l = b0_l; // b1 = b0; + b1_h = b0_h; + } + + t0 = Mpy_32_16 (b1_h, b1_l, x); // t0 = x*b1; + t0 = L_mac (t0, b2_h, (Word16) 0x8000); // t0 = x*b1 - b2 + t0 = L_msu (t0, b2_l, 1); + t0 = L_mac (t0, f[i], 4096); // t0 = x*b1 - b2 + f[i]/2 + + t0 = L_shl (t0, 6); + + cheb = extract_h (t0); + + return (cheb); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 Chebps(Word16 x, + Word16 f[], /* (n) */ + Word16 n, + Flag *pOverflow) +{ + Word16 i; + Word16 cheb; + Word16 b1_h; + Word16 b1_l; + Word32 t0; + Word32 L_temp; + Word16 *p_f = &f[1]; + + OSCL_UNUSED_ARG(pOverflow); + + /* L_temp = 1.0 */ + + L_temp = 0x01000000L; + + t0 = ((Word32) x << 10) + ((Word32) * (p_f++) << 14); + + /* b1 = t0 = 2*x + f[1] */ + + b1_h = (Word16)(t0 >> 16); + b1_l = (Word16)((t0 >> 1) - (b1_h << 15)); + + + for (i = 2; i < n; i++) + { + /* t0 = 2.0*x*b1 */ + t0 = ((Word32) b1_h * x); + t0 += ((Word32) b1_l * x) >> 15; + t0 <<= 2; + + /* t0 = 2.0*x*b1 - b2 */ + t0 -= L_temp; + + /* t0 = 2.0*x*b1 - b2 + f[i] */ + t0 += (Word32) * (p_f++) << 14; + + L_temp = ((Word32) b1_h << 16) + ((Word32) b1_l << 1); + + /* b0 = 2.0*x*b1 - b2 + f[i]*/ + b1_h = (Word16)(t0 >> 16); + b1_l = (Word16)((t0 >> 1) - (b1_h << 15)); + + } + + /* t0 = x*b1; */ + t0 = ((Word32) b1_h * x); + t0 += ((Word32) b1_l * x) >> 15; + t0 <<= 1; + + + /* t0 = x*b1 - b2 */ + t0 -= L_temp; + + /* t0 = x*b1 - b2 + f[i]/2 */ + t0 += (Word32) * (p_f) << 13; + + + if ((UWord32)(t0 - 0xfe000000L) < (UWord32)0x03ffffffL) + { + cheb = (Word16)(t0 >> 10); + } + else + { + if (t0 > (Word32) 0x01ffffffL) + { + cheb = MAX_16; + + } + else + { + cheb = MIN_16; + } + } + + return (cheb); +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Az_lsp +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS FOR Az_lsp + + Inputs: + a = predictor coefficients (Word16) + lsp = line spectral pairs (Word16) + old_lsp = old line spectral pairs (Word16) + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the operations in the function resulted in saturation. + + Returns: + None. + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes the LSPs from the LP coefficients. + + The sum and difference filters are computed and divided by 1+z^{-1} and + 1-z^{-1}, respectively. + + f1[i] = a[i] + a[11-i] - f1[i-1] ; i=1,...,5 + f2[i] = a[i] - a[11-i] + f2[i-1] ; i=1,...,5 + + The roots of F1(z) and F2(z) are found using Chebyshev polynomial evaluation. + The polynomials are evaluated at 60 points regularly spaced in the + frequency domain. The sign change interval is subdivided 4 times to better + track the root. The LSPs are found in the cosine domain [1,-1]. + + If less than 10 roots are found, the LSPs from the past frame are used. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + az_lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Az_lsp ( + Word16 a[], // (i) : predictor coefficients (MP1) + Word16 lsp[], // (o) : line spectral pairs (M) + Word16 old_lsp[] // (i) : old lsp[] (in case not found 10 roots) (M) +) +{ + Word16 i, j, nf, ip; + Word16 xlow, ylow, xhigh, yhigh, xmid, ymid, xint; + Word16 x, y, sign, exp; + Word16 *coef; + Word16 f1[M / 2 + 1], f2[M / 2 + 1]; + Word32 t0; + + *-------------------------------------------------------------* + * find the sum and diff. pol. F1(z) and F2(z) * + * F1(z) <--- F1(z)/(1+z**-1) & F2(z) <--- F2(z)/(1-z**-1) * + * * + * f1[0] = 1.0; * + * f2[0] = 1.0; * + * * + * for (i = 0; i< NC; i++) * + * { * + * f1[i+1] = a[i+1] + a[M-i] - f1[i] ; * + * f2[i+1] = a[i+1] - a[M-i] + f2[i] ; * + * } * + *-------------------------------------------------------------* + + f1[0] = 1024; // f1[0] = 1.0 + f2[0] = 1024; // f2[0] = 1.0 + +// The reference ETSI code uses a global flag for Overflow. However, in the +// actual implementation a pointer to Overflow flag is passed in as a +// parameter to the function. This pointer is passed into all the basic math +// functions invoked + + for (i = 0; i < NC; i++) + { + t0 = L_mult (a[i + 1], 8192); // x = (a[i+1] + a[M-i]) >> 2 + t0 = L_mac (t0, a[M - i], 8192); + x = extract_h (t0); + // f1[i+1] = a[i+1] + a[M-i] - f1[i] + f1[i + 1] = sub (x, f1[i]); + + t0 = L_mult (a[i + 1], 8192); // x = (a[i+1] - a[M-i]) >> 2 + t0 = L_msu (t0, a[M - i], 8192); + x = extract_h (t0); + // f2[i+1] = a[i+1] - a[M-i] + f2[i] + f2[i + 1] = add (x, f2[i]); + } + + *-------------------------------------------------------------* + * find the LSPs using the Chebychev pol. evaluation * + *-------------------------------------------------------------* + + nf = 0; // number of found frequencies + ip = 0; // indicator for f1 or f2 + + coef = f1; + + xlow = grid[0]; + ylow = Chebps (xlow, coef, NC); + + j = 0; + // while ( (nf < M) && (j < grid_points) ) + while ((sub (nf, M) < 0) && (sub (j, grid_points) < 0)) + { + j++; + xhigh = xlow; + yhigh = ylow; + xlow = grid[j]; + ylow = Chebps (xlow, coef, NC); + + if (L_mult (ylow, yhigh) <= (Word32) 0L) + { + + // divide 4 times the interval + + for (i = 0; i < 4; i++) + { + // xmid = (xlow + xhigh)/2 + xmid = add (shr (xlow, 1), shr (xhigh, 1)); + ymid = Chebps (xmid, coef, NC); + + if (L_mult (ylow, ymid) <= (Word32) 0L) + { + yhigh = ymid; + xhigh = xmid; + } + else + { + ylow = ymid; + xlow = xmid; + } + } + + *-------------------------------------------------------------* + * Linear interpolation * + * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); * + *-------------------------------------------------------------* + + x = sub (xhigh, xlow); + y = sub (yhigh, ylow); + + if (y == 0) + { + xint = xlow; + } + else + { + sign = y; + y = abs_s (y); + exp = norm_s (y); + y = shl (y, exp); + y = div_s ((Word16) 16383, y); + t0 = L_mult (x, y); + t0 = L_shr (t0, sub (20, exp)); + y = extract_l (t0); // y= (xhigh-xlow)/(yhigh-ylow) + + if (sign < 0) + y = negate (y); + + t0 = L_mult (ylow, y); + t0 = L_shr (t0, 11); + xint = sub (xlow, extract_l (t0)); // xint = xlow - ylow*y + } + + lsp[nf] = xint; + xlow = xint; + nf++; + + if (ip == 0) + { + ip = 1; + coef = f2; + } + else + { + ip = 0; + coef = f1; + } + ylow = Chebps (xlow, coef, NC); + + } + } + + // Check if M roots found + + if (sub (nf, M) < 0) + { + for (i = 0; i < M; i++) + { + lsp[i] = old_lsp[i]; + } + + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void Az_lsp( + Word16 a[], /* (i) : predictor coefficients (MP1) */ + Word16 lsp[], /* (o) : line spectral pairs (M) */ + Word16 old_lsp[], /* (i) : old lsp[] (in case not found 10 roots) (M) */ + Flag *pOverflow /* (i/o): overflow flag */ +) +{ + register Word16 i; + register Word16 j; + register Word16 nf; + register Word16 ip; + Word16 xlow; + Word16 ylow; + Word16 xhigh; + Word16 yhigh; + Word16 xmid; + Word16 ymid; + Word16 xint; + Word16 x; + Word16 y; + Word16 sign; + Word16 exp; + Word16 *coef; + Word16 f1[NC + 1]; + Word16 f2[NC + 1]; + Word32 L_temp1; + Word32 L_temp2; + Word16 *p_f1 = f1; + Word16 *p_f2 = f2; + + /*-------------------------------------------------------------* + * find the sum and diff. pol. F1(z) and F2(z) * + * F1(z) <--- F1(z)/(1+z**-1) & F2(z) <--- F2(z)/(1-z**-1) * + * * + * f1[0] = 1.0; * + * f2[0] = 1.0; * + * * + * for (i = 0; i< NC; i++) * + * { * + * f1[i+1] = a[i+1] + a[M-i] - f1[i] ; * + * f2[i+1] = a[i+1] - a[M-i] + f2[i] ; * + * } * + *-------------------------------------------------------------*/ + + *p_f1 = 1024; /* f1[0] = 1.0 */ + *p_f2 = 1024; /* f2[0] = 1.0 */ + + for (i = 0; i < NC; i++) + { + L_temp1 = (Word32) * (a + i + 1); + L_temp2 = (Word32) * (a + M - i); + /* x = (a[i+1] + a[M-i]) >> 2 */ + x = (Word16)((L_temp1 + L_temp2) >> 2); + /* y = (a[i+1] - a[M-i]) >> 2 */ + y = (Word16)((L_temp1 - L_temp2) >> 2); + /* f1[i+1] = a[i+1] + a[M-i] - f1[i] */ + x -= *(p_f1++); + *(p_f1) = x; + /* f2[i+1] = a[i+1] - a[M-i] + f2[i] */ + y += *(p_f2++); + *(p_f2) = y; + } + + /*-------------------------------------------------------------* + * find the LSPs using the Chebychev pol. evaluation * + *-------------------------------------------------------------*/ + + nf = 0; /* number of found frequencies */ + ip = 0; /* indicator for f1 or f2 */ + + coef = f1; + + xlow = *(grid); + ylow = Chebps(xlow, coef, NC, pOverflow); + + j = 0; + + while ((nf < M) && (j < grid_points)) + { + j++; + xhigh = xlow; + yhigh = ylow; + xlow = *(grid + j); + ylow = Chebps(xlow, coef, NC, pOverflow); + + if (((Word32)ylow*yhigh) <= 0) + { + /* divide 4 times the interval */ + for (i = 4; i != 0; i--) + { + /* xmid = (xlow + xhigh)/2 */ + x = xlow >> 1; + y = xhigh >> 1; + xmid = x + y; + + ymid = Chebps(xmid, coef, NC, pOverflow); + + if (((Word32)ylow*ymid) <= 0) + { + yhigh = ymid; + xhigh = xmid; + } + else + { + ylow = ymid; + xlow = xmid; + } + } + + /*-------------------------------------------------------------* + * Linear interpolation * + * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); * + *-------------------------------------------------------------*/ + + x = xhigh - xlow; + y = yhigh - ylow; + + if (y == 0) + { + xint = xlow; + } + else + { + sign = y; + y = abs_s(y); + exp = norm_s(y); + y <<= exp; + y = div_s((Word16) 16383, y); + + y = ((Word32)x * y) >> (19 - exp); + + if (sign < 0) + { + y = -y; + } + + /* xint = xlow - ylow*y */ + xint = xlow - (((Word32) ylow * y) >> 10); + } + + *(lsp + nf) = xint; + xlow = xint; + nf++; + + if (ip == 0) + { + ip = 1; + coef = f2; + } + else + { + ip = 0; + coef = f1; + } + + ylow = Chebps(xlow, coef, NC, pOverflow); + + } + } + + /* Check if M roots found */ + + if (nf < M) + { + for (i = NC; i != 0 ; i--) + { + *lsp++ = *old_lsp++; + *lsp++ = *old_lsp++; + } + } + +} + +Word16 Chebps_Wrapper(Word16 x, + Word16 f[], /* (n) */ + Word16 n, + Flag *pOverflow) +{ + return Chebps(x, f, n, pOverflow); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitno_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitno_tab.cpp new file mode 100644 index 0000000..d0ecd39 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitno_tab.cpp @@ -0,0 +1,273 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bitno_tab.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + None + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + File : bitno.tab + Purpose : Tables for bit2prm and prm2bit + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + None + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" /* parameter sizes: MAX_PRM_SIZE */ +#include "mode.h" /* N_MODES */ +#include "bitno_tab.h" + + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; LOCAL STORE/BUFFER/POINTER DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + /* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */ + const Word16 prmno[N_MODES] = + { + PRMNO_MR475, + PRMNO_MR515, + PRMNO_MR59, + PRMNO_MR67, + PRMNO_MR74, + PRMNO_MR795, + PRMNO_MR102, + PRMNO_MR122, + PRMNO_MRDTX + }; + + /* number of parameters to first subframe per modes */ + const Word16 prmnofsf[N_MODES - 1] = + { + PRMNOFSF_MR475, + PRMNOFSF_MR515, + PRMNOFSF_MR59, + PRMNOFSF_MR67, + PRMNOFSF_MR74, + PRMNOFSF_MR795, + PRMNOFSF_MR102, + PRMNOFSF_MR122 + }; + + /* parameter sizes (# of bits), one table per mode */ + const Word16 bitno_MR475[PRMNO_MR475] = + { + 8, 8, 7, /* LSP VQ */ + 8, 7, 2, 8, /* first subframe */ + 4, 7, 2, /* second subframe */ + 4, 7, 2, 8, /* third subframe */ + 4, 7, 2, /* fourth subframe */ + }; + + const Word16 bitno_MR515[PRMNO_MR515] = + { + 8, 8, 7, /* LSP VQ */ + 8, 7, 2, 6, /* first subframe */ + 4, 7, 2, 6, /* second subframe */ + 4, 7, 2, 6, /* third subframe */ + 4, 7, 2, 6, /* fourth subframe */ + }; + + const Word16 bitno_MR59[PRMNO_MR59] = + { + 8, 9, 9, /* LSP VQ */ + 8, 9, 2, 6, /* first subframe */ + 4, 9, 2, 6, /* second subframe */ + 8, 9, 2, 6, /* third subframe */ + 4, 9, 2, 6, /* fourth subframe */ + }; + + const Word16 bitno_MR67[PRMNO_MR67] = + { + 8, 9, 9, /* LSP VQ */ + 8, 11, 3, 7, /* first subframe */ + 4, 11, 3, 7, /* second subframe */ + 8, 11, 3, 7, /* third subframe */ + 4, 11, 3, 7, /* fourth subframe */ + }; + + const Word16 bitno_MR74[PRMNO_MR74] = + { + 8, 9, 9, /* LSP VQ */ + 8, 13, 4, 7, /* first subframe */ + 5, 13, 4, 7, /* second subframe */ + 8, 13, 4, 7, /* third subframe */ + 5, 13, 4, 7, /* fourth subframe */ + }; + + const Word16 bitno_MR795[PRMNO_MR795] = + { + 9, 9, 9, /* LSP VQ */ + 8, 13, 4, 4, 5, /* first subframe */ + 6, 13, 4, 4, 5, /* second subframe */ + 8, 13, 4, 4, 5, /* third subframe */ + 6, 13, 4, 4, 5, /* fourth subframe */ + }; + + const Word16 bitno_MR102[PRMNO_MR102] = + { + 8, 9, 9, /* LSP VQ */ + 8, 1, 1, 1, 1, 10, 10, 7, 7, /* first subframe */ + 5, 1, 1, 1, 1, 10, 10, 7, 7, /* second subframe */ + 8, 1, 1, 1, 1, 10, 10, 7, 7, /* third subframe */ + 5, 1, 1, 1, 1, 10, 10, 7, 7, /* fourth subframe */ + }; + + const Word16 bitno_MR122[PRMNO_MR122] = + { + 7, 8, 9, 8, 6, /* LSP VQ */ + 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* first subframe */ + 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* second subframe */ + 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* third subframe */ + 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5 /* fourth subframe */ + }; + + const Word16 bitno_MRDTX[PRMNO_MRDTX] = + { + 3, + 8, 9, 9, + 6 + }; + + /* overall table with all parameter sizes for all modes */ + const Word16 * const bitno[N_MODES] = + { + bitno_MR475, + bitno_MR515, + bitno_MR59, + bitno_MR67, + bitno_MR74, + bitno_MR795, + bitno_MR102, + bitno_MR122, + bitno_MRDTX + }; + /*---------------------------------------------------------------------------- + ; EXTERNAL FUNCTION REFERENCES + ; Declare functions defined elsewhere and referenced in this module + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; Define all local variables +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Function body here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Return nothing or data or data pointer +----------------------------------------------------------------------------*/ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitreorder_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitreorder_tab.cpp new file mode 100644 index 0000000..3245cdb --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bitreorder_tab.cpp @@ -0,0 +1,381 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bitreorder_tab.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + None + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function contains tables needed to reformat the encoded speech bits + into IF2, WMF, and ETS. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + AMR Speech Codec Frame Structure, + 3GPP TS 26.101 version 4.1.0 Release 4, June 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "bitreorder_tab.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ +#define NUM_MODES 16 +#define NUMBIT_MR475 95 +#define NUMBIT_MR515 103 +#define NUMBIT_MR59 118 +#define NUMBIT_MR67 134 +#define NUMBIT_MR74 148 +#define NUMBIT_MR795 159 +#define NUMBIT_MR102 204 +#define NUMBIT_MR122 244 +#define NUMBIT_AMR_SID 39 +#define NUMBIT_GSMEFR_SID 43 +#define NUMBIT_TDMAEFR_SID 38 +#define NUMBIT_PDCEFR_SID 37 +#define NUMBIT_UNUSED1 0 +#define NUMBIT_UNUSED2 0 +#define NUMBIT_UNUSED3 0 +#define NUMBIT_NO_DATA 0 + +#define MAX_NUM_BITS 244 + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; LOCAL STORE/BUFFER/POINTER DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + /* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */ + const Word16 numOfBits[NUM_MODES] = + { + NUMBIT_MR475, + NUMBIT_MR515, + NUMBIT_MR59, + NUMBIT_MR67, + NUMBIT_MR74, + NUMBIT_MR795, + NUMBIT_MR102, + NUMBIT_MR122, + NUMBIT_AMR_SID, + NUMBIT_GSMEFR_SID, + NUMBIT_TDMAEFR_SID, + NUMBIT_PDCEFR_SID, + NUMBIT_UNUSED1, + NUMBIT_UNUSED2, + NUMBIT_UNUSED3, + NUMBIT_NO_DATA + }; + + const Word16 reorderBits_MR475[NUMBIT_MR475] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 23, 24, 25, 26, + 27, 28, 48, 49, 61, 62, 82, 83, 47, 46, + 45, 44, 81, 80, 79, 78, 17, 18, 20, 22, + 77, 76, 75, 74, 29, 30, 43, 42, 41, 40, + 38, 39, 16, 19, 21, 50, 51, 59, 60, 63, + 64, 72, 73, 84, 85, 93, 94, 32, 33, 35, + 36, 53, 54, 56, 57, 66, 67, 69, 70, 87, + 88, 90, 91, 34, 55, 68, 89, 37, 58, 71, + 92, 31, 52, 65, 86 + }; + + const Word16 reorderBits_MR515[NUMBIT_MR515] = + { + 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, + 13, 12, 11, 10, 9, 8, 23, 24, 25, 26, + 27, 46, 65, 84, 45, 44, 43, 64, 63, 62, + 83, 82, 81, 102, 101, 100, 42, 61, 80, 99, + 28, 47, 66, 85, 18, 41, 60, 79, 98, 29, + 48, 67, 17, 20, 22, 40, 59, 78, 97, 21, + 30, 49, 68, 86, 19, 16, 87, 39, 38, 58, + 57, 77, 35, 54, 73, 92, 76, 96, 95, 36, + 55, 74, 93, 32, 51, 33, 52, 70, 71, 89, + 90, 31, 50, 69, 88, 37, 56, 75, 94, 34, + 53, 72, 91 + }; + + const Word16 reorderBits_MR59[NUMBIT_MR59] = + { + 0, 1, 4, 5, 3, 6, 7, 2, 13, 15, + 8, 9, 11, 12, 14, 10, 16, 28, 74, 29, + 75, 27, 73, 26, 72, 30, 76, 51, 97, 50, + 71, 96, 117, 31, 77, 52, 98, 49, 70, 95, + 116, 53, 99, 32, 78, 33, 79, 48, 69, 94, + 115, 47, 68, 93, 114, 46, 67, 92, 113, 19, + 21, 23, 22, 18, 17, 20, 24, 111, 43, 89, + 110, 64, 65, 44, 90, 25, 45, 66, 91, 112, + 54, 100, 40, 61, 86, 107, 39, 60, 85, 106, + 36, 57, 82, 103, 35, 56, 81, 102, 34, 55, + 80, 101, 42, 63, 88, 109, 41, 62, 87, 108, + 38, 59, 84, 105, 37, 58, 83, 104 + }; + + const Word16 reorderBits_MR67[NUMBIT_MR67] = + { + 0, 1, 4, 3, 5, 6, 13, 7, 2, 8, + 9, 11, 15, 12, 14, 10, 28, 82, 29, 83, + 27, 81, 26, 80, 30, 84, 16, 55, 109, 56, + 110, 31, 85, 57, 111, 48, 73, 102, 127, 32, + 86, 51, 76, 105, 130, 52, 77, 106, 131, 58, + 112, 33, 87, 19, 23, 53, 78, 107, 132, 21, + 22, 18, 17, 20, 24, 25, 50, 75, 104, 129, + 47, 72, 101, 126, 54, 79, 108, 133, 46, 71, + 100, 125, 128, 103, 74, 49, 45, 70, 99, 124, + 42, 67, 96, 121, 39, 64, 93, 118, 38, 63, + 92, 117, 35, 60, 89, 114, 34, 59, 88, 113, + 44, 69, 98, 123, 43, 68, 97, 122, 41, 66, + 95, 120, 40, 65, 94, 119, 37, 62, 91, 116, + 36, 61, 90, 115 + }; + + const Word16 reorderBits_MR74[NUMBIT_MR74] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 26, 87, 27, + 88, 28, 89, 29, 90, 30, 91, 51, 80, 112, + 141, 52, 81, 113, 142, 54, 83, 115, 144, 55, + 84, 116, 145, 58, 119, 59, 120, 21, 22, 23, + 17, 18, 19, 31, 60, 92, 121, 56, 85, 117, + 146, 20, 24, 25, 50, 79, 111, 140, 57, 86, + 118, 147, 49, 78, 110, 139, 48, 77, 53, 82, + 114, 143, 109, 138, 47, 76, 108, 137, 32, 33, + 61, 62, 93, 94, 122, 123, 41, 42, 43, 44, + 45, 46, 70, 71, 72, 73, 74, 75, 102, 103, + 104, 105, 106, 107, 131, 132, 133, 134, 135, 136, + 34, 63, 95, 124, 35, 64, 96, 125, 36, 65, + 97, 126, 37, 66, 98, 127, 38, 67, 99, 128, + 39, 68, 100, 129, 40, 69, 101, 130 + }; + + const Word16 reorderBits_MR795[NUMBIT_MR795] = + { + 8, 7, 6, 5, 4, 3, 2, 14, 16, 9, + 10, 12, 13, 15, 11, 17, 20, 22, 24, 23, + 19, 18, 21, 56, 88, 122, 154, 57, 89, 123, + 155, 58, 90, 124, 156, 52, 84, 118, 150, 53, + 85, 119, 151, 27, 93, 28, 94, 29, 95, 30, + 96, 31, 97, 61, 127, 62, 128, 63, 129, 59, + 91, 125, 157, 32, 98, 64, 130, 1, 0, 25, + 26, 33, 99, 34, 100, 65, 131, 66, 132, 54, + 86, 120, 152, 60, 92, 126, 158, 55, 87, 121, + 153, 117, 116, 115, 46, 78, 112, 144, 43, 75, + 109, 141, 40, 72, 106, 138, 36, 68, 102, 134, + 114, 149, 148, 147, 146, 83, 82, 81, 80, 51, + 50, 49, 48, 47, 45, 44, 42, 39, 35, 79, + 77, 76, 74, 71, 67, 113, 111, 110, 108, 105, + 101, 145, 143, 142, 140, 137, 133, 41, 73, 107, + 139, 37, 69, 103, 135, 38, 70, 104, 136 + }; + + const Word16 reorderBits_MR102[NUMBIT_MR102] = + { + 7, 6, 5, 4, 3, 2, 1, 0, 16, 15, + 14, 13, 12, 11, 10, 9, 8, 26, 27, 28, + 29, 30, 31, 115, 116, 117, 118, 119, 120, 72, + 73, 161, 162, 65, 68, 69, 108, 111, 112, 154, + 157, 158, 197, 200, 201, 32, 33, 121, 122, 74, + 75, 163, 164, 66, 109, 155, 198, 19, 23, 21, + 22, 18, 17, 20, 24, 25, 37, 36, 35, 34, + 80, 79, 78, 77, 126, 125, 124, 123, 169, 168, + 167, 166, 70, 67, 71, 113, 110, 114, 159, 156, + 160, 202, 199, 203, 76, 165, 81, 82, 92, 91, + 93, 83, 95, 85, 84, 94, 101, 102, 96, 104, + 86, 103, 87, 97, 127, 128, 138, 137, 139, 129, + 141, 131, 130, 140, 147, 148, 142, 150, 132, 149, + 133, 143, 170, 171, 181, 180, 182, 172, 184, 174, + 173, 183, 190, 191, 185, 193, 175, 192, 176, 186, + 38, 39, 49, 48, 50, 40, 52, 42, 41, 51, + 58, 59, 53, 61, 43, 60, 44, 54, 194, 179, + 189, 196, 177, 195, 178, 187, 188, 151, 136, 146, + 153, 134, 152, 135, 144, 145, 105, 90, 100, 107, + 88, 106, 89, 98, 99, 62, 47, 57, 64, 45, + 63, 46, 55, 56 + }; + + const Word16 reorderBits_MR122[NUMBIT_MR122] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 23, 15, 16, 17, 18, + 19, 20, 21, 22, 24, 25, 26, 27, 28, 38, + 141, 39, 142, 40, 143, 41, 144, 42, 145, 43, + 146, 44, 147, 45, 148, 46, 149, 47, 97, 150, + 200, 48, 98, 151, 201, 49, 99, 152, 202, 86, + 136, 189, 239, 87, 137, 190, 240, 88, 138, 191, + 241, 91, 194, 92, 195, 93, 196, 94, 197, 95, + 198, 29, 30, 31, 32, 33, 34, 35, 50, 100, + 153, 203, 89, 139, 192, 242, 51, 101, 154, 204, + 55, 105, 158, 208, 90, 140, 193, 243, 59, 109, + 162, 212, 63, 113, 166, 216, 67, 117, 170, 220, + 36, 37, 54, 53, 52, 58, 57, 56, 62, 61, + 60, 66, 65, 64, 70, 69, 68, 104, 103, 102, + 108, 107, 106, 112, 111, 110, 116, 115, 114, 120, + 119, 118, 157, 156, 155, 161, 160, 159, 165, 164, + 163, 169, 168, 167, 173, 172, 171, 207, 206, 205, + 211, 210, 209, 215, 214, 213, 219, 218, 217, 223, + 222, 221, 73, 72, 71, 76, 75, 74, 79, 78, + 77, 82, 81, 80, 85, 84, 83, 123, 122, 121, + 126, 125, 124, 129, 128, 127, 132, 131, 130, 135, + 134, 133, 176, 175, 174, 179, 178, 177, 182, 181, + 180, 185, 184, 183, 188, 187, 186, 226, 225, 224, + 229, 228, 227, 232, 231, 230, 235, 234, 233, 238, + 237, 236, 96, 199 + }; + + /* overall table with all parameter sizes for all modes */ + const Word16 * const reorderBits[NUM_MODES-1] = + { + reorderBits_MR475, + reorderBits_MR515, + reorderBits_MR59, + reorderBits_MR67, + reorderBits_MR74, + reorderBits_MR795, + reorderBits_MR102, + reorderBits_MR122 + }; + + /* Number of Frames (16-bit segments sent for each mode */ + const Word16 numCompressedBytes[16] = + { + 13, /*4.75*/ + 14, /*5.15*/ + 16, /*5.90*/ + 18, /*6.70*/ + 19, /*7.40*/ + 21, /*7.95*/ + 26, /*10.2*/ + 31, /*12.2*/ + 6, /*GsmAmr comfort noise*/ + 6, /*Gsm-Efr comfort noise*/ + 6, /*IS-641 comfort noise*/ + 6, /*Pdc-Efr comfort noise*/ + 0, /*future use*/ + 0, /*future use*/ + 0, /*future use*/ + 1 /*No transmission*/ + }; + /*---------------------------------------------------------------------------- + ; EXTERNAL FUNCTION REFERENCES + ; Declare functions defined elsewhere and referenced in this module + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; Define all local variables +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Function body here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Return nothing or data or data pointer +----------------------------------------------------------------------------*/ + + + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bits2prm.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bits2prm.cpp new file mode 100644 index 0000000..3901545 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bits2prm.cpp @@ -0,0 +1,249 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bits2prm.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "bits2prm.h" +#include "typedef.h" +#include "mode.h" +#include "bitno_tab.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Bin2int +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + no_of_bits = number of bits associated with value + bitstream = pointer to buffer where bits are read + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Function : Bin2int + Purpose : Read "no_of_bits" bits from the array bitstream[] + and convert to integer. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +static Word16 Bin2int ( // Reconstructed parameter + Word16 no_of_bits, // input : number of bits associated with value + Word16 *bitstream // output: address where bits are written +) +{ + Word16 value, i, bit; + + value = 0; + for (i = 0; i < no_of_bits; i++) + { + value = shl (value, 1); + bit = *bitstream++; + if (sub (bit, BIT_1) == 0) + value = add (value, 1); + } + return (value); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +static Word16 Bin2int( /* Reconstructed parameter */ + Word16 no_of_bits, /* input : number of bits associated with value */ + Word16 *bitstream /* input: address where bits are read from */ +) +{ + Word16 value; + Word16 i; + Word16 single_bit; + + value = 0; + for (i = 0; i < no_of_bits; i++) + { + value <<= 1; + single_bit = *(bitstream++); + value |= single_bit; + } + return (value); +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: bits2prm +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + mode = AMR mode of type enum Mode + bits[] = pointer to serial bits of type Word16 + prm[] = pointer to analysis parameters of type Word16 + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Function : Bits2prm + Purpose : Retrieves the vector of encoder parameters from + the received serial bits in a frame. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Bits2prm ( + enum Mode mode, // i : AMR mode + Word16 bits[], // i : serial bits (size <= MAX_SERIAL_SIZE) + Word16 prm[] // o : analysis parameters (size <= MAX_PRM_SIZE) +) +{ + Word16 i; + + for (i = 0; i < prmno[mode]; i++) + { + prm[i] = Bin2int (bitno[mode][i], bits); + bits += bitno[mode][i]; + add(0,0); // account for above pointer update + } + + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF void Bits2prm( + enum Mode mode, /* i : AMR mode */ + Word16 bits[], /* i : serial bits (size <= MAX_SERIAL_SIZE) */ + Word16 prm[] /* o : analysis parameters (size <= MAX_PRM_SIZE) */ +) +{ + Word16 i; + + for (i = 0; i < prmno[mode]; i++) + { + prm[i] = Bin2int(bitno[mode][i], bits); + bits += bitno[mode][i]; + } + + return; +} + + + + + + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bytesused.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bytesused.cpp new file mode 100644 index 0000000..4893542 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/bytesused.cpp @@ -0,0 +1,171 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: bytesused.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + None + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function creates a table called BytesUsed that holds the value that + describes the number of bytes required to hold one frame worth of data in + the WMF (non-IF2) frame format. Each table entry is the sum of the frame + type byte and the number of bytes used up by the core speech data for each + 3GPP frame type. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] "AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 + Release 4, June 2001, page 13. + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; LOCAL STORE/BUFFER/POINTER DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + const short BytesUsed[16] = + { + 13, /* 4.75 */ + 14, /* 5.15 */ + 16, /* 5.90 */ + 18, /* 6.70 */ + 20, /* 7.40 */ + 21, /* 7.95 */ + 27, /* 10.2 */ + 32, /* 12.2 */ + 6, /* GsmAmr comfort noise */ + 7, /* Gsm-Efr comfort noise */ + 6, /* IS-641 comfort noise */ + 6, /* Pdc-Efr comfort noise */ + 0, /* future use */ + 0, /* future use */ + 0, /* future use */ + 1 /* No transmission */ + }; + /*---------------------------------------------------------------------------- + ; EXTERNAL FUNCTION REFERENCES + ; Declare functions defined elsewhere and referenced in this module + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; Define all local variables +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Function body here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Return nothing or data or data pointer +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/c2_9pf_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/c2_9pf_tab.cpp new file mode 100644 index 0000000..4db7e9b --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/c2_9pf_tab.cpp @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: c2_9pf_tab.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for startPos[] used by the functions + c2_9pf.c and d2_9pf.c + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "get_const_tbls.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + extern const Word16 startPos[]; + const Word16 startPos[2*4*2] = + { + 0, 2, 0, 3, + 0, 2, 0, 3, + 1, 3, 2, 4, + 1, 4, 1, 4 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] c2_9pf.c UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/copy.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/copy.cpp new file mode 100644 index 0000000..1dec39d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/copy.cpp @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* File : copy.h +* +******************************************************************************** +*/ + +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "copy.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "oscl_mem.h" + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: Copy + * + * PURPOSE: Copy vector x[] to y[] + * + * + *************************************************************************/ +/* +************************************************************************** +* +* Function : Copy +* Purpose : Copy vector x[] to y[] +* +************************************************************************** +*/ +void Copy( + const Word16 x[], /* i : input vector (L) */ + Word16 y[], /* o : output vector (L) */ + Word16 L /* i : vector length */ +) +{ + oscl_memmove(y, x, L*sizeof(*x)); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_32.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_32.cpp new file mode 100644 index 0000000..ea02926 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_32.cpp @@ -0,0 +1,172 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: div_32.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: div_32 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_num = 32 bit signed integer (Word32) whose value falls in the + range : 0x0000 0000 < L_num < L_denom + L_denom_hi = 16 bit positive normalized integer whose value falls in + the range : 0x4000 < hi < 0x7fff + L_denom_lo = 16 bit positive integer whose value falls in the range : + 0 < lo < 0x7fff + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit divide operation resulted in overflow + + Returns: + result = 32-bit quotient of of the division of two 32 bit integers + L_num / L_denom (Word32) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function is a fractional integer division of two 32 bit numbers, the + numerator L_num and the denominator L_denom. The denominator is formed by + combining denom_hi and denom_lo. Note that denom_hi is a normalized numbers. + The numerator and denominator must be positive and the numerator must be + less than the denominator. + + The division is done as follows: + 1. Find 1/L_denom by first approximating: approx = 1 / denom_hi. + 2. 1/L_denom = approx * (2.0 - L_denom * approx ). + 3. result = L_num * (1/L_denom). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] div_32() function in oper_32b.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word32 Div_32(Word32 L_num, + Word16 L_denom_hi, + Word16 L_denom_lo, + Flag *pOverflow) +{ + + Word16 approx; + Word16 hi; + Word16 lo; + Word16 n_hi; + Word16 n_lo; + Word32 result; + + /* First approximation: 1 / L_denom = 1/L_denom_hi */ + + approx = div_s((Word16) 0x3fff, L_denom_hi); + + /* 1/L_denom = approx * (2.0 - L_denom * approx) */ + + result = Mpy_32_16(L_denom_hi, L_denom_lo, approx, pOverflow); + /* result is > 0 , and less than 1.0 */ + result = 0x7fffffffL - result; + + hi = (Word16)(result >> 16); + lo = (result >> 1) - (hi << 15); + + result = Mpy_32_16(hi, lo, approx, pOverflow); + + /* L_num * (1/L_denom) */ + + hi = (Word16)(result >> 16); + lo = (result >> 1) - (hi << 15); + + n_hi = (Word16)(L_num >> 16); + n_lo = (L_num >> 1) - (n_hi << 15); + + result = Mpy_32(n_hi, n_lo, hi, lo, pOverflow); + result = L_shl(result, 2, pOverflow); + + return (result); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_s.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_s.cpp new file mode 100644 index 0000000..f60f18b --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/div_s.cpp @@ -0,0 +1,235 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: div_s.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit signed integer (Word16) whose value falls in + the range : 0x0000 <= var1 <= 0x7fff. + var2 = 16 bit signed integer (Word16) whose value falls in + the range : 0x0000 <= var1 <= 0x7fff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var_out = quotient of var1 divided by var2 (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function produces a result which is the fractional integer division of + var1 by var2; var1 and var2 must be positive and var2 must be greater or equal + to var1; the result is positive (leading bit equal to 0) and truncated to 16 + bits. If var1 = var2 then div(var1,var2) = 32767. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 div_s (Word16 var1, Word16 var2) +{ + Word16 var_out = 0; + Word16 iteration; + Word32 L_num; + Word32 L_denom; + Word16 abort_flag = 0; + + if ((var1 > var2) || (var1 < 0)) + { + printf ("Division Error var1=%d var2=%d\n", var1, var2); + abort_flag = 1; + exit(0); + } + if ((var1 != 0) && (abort_flag == 0)) + { + if (var1 == var2) + { + var_out = MAX_16; + } + else + { + L_num = (Word32) var1; + L_denom = (Word32) var2; + + for (iteration = 15; iteration > 0; iteration--) + { + var_out <<= 1; + L_num <<= 1; + + if (L_num >= L_denom) + { + L_num -= L_denom; + var_out += 1; + } + } + } + } + +#if (WMOPS) + multiCounter[currCounter].div_s++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word16 div_s(register Word16 var1, register Word16 var2) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + Word16 var_out = 0; + register Word16 iteration; + Word32 L_num; + Word32 L_denom; + Word32 L_denom_by_2; + Word32 L_denom_by_4; + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + if ((var1 > var2) || (var1 < 0)) + { + return 0; // used to exit(0); + } + if (var1) + { + if (var1 != var2) + { + + L_num = (Word32) var1; + L_denom = (Word32) var2; + L_denom_by_2 = (L_denom << 1); + L_denom_by_4 = (L_denom << 2); + for (iteration = 5; iteration > 0; iteration--) + { + var_out <<= 3; + L_num <<= 3; + + if (L_num >= L_denom_by_4) + { + L_num -= L_denom_by_4; + var_out |= 4; + } + + if (L_num >= L_denom_by_2) + { + L_num -= L_denom_by_2; + var_out |= 2; + } + + if (L_num >= (L_denom)) + { + L_num -= (L_denom); + var_out |= 1; + } + + } + } + else + { + var_out = MAX_16; + } + } + +#if (WMOPS) + multiCounter[currCounter].div_s++; +#endif + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return (var_out); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_h.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_h.cpp new file mode 100644 index 0000000..54d0dee --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_h.cpp @@ -0,0 +1,144 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: extract_h.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32 ) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + L_var1 = Most significant word of input (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function returns the 16 MSB of the input, L_var1. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 extract_h (Word32 L_var1) +{ + Word16 var_out; + + var_out = (Word16) (L_var1 >> 16); +#if (WMOPS) + multiCounter[currCounter].extract_h++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word16 extract_h(Word32 L_var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return ((Word16)(L_var1 >> 16)); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_l.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_l.cpp new file mode 100644 index 0000000..a96519b --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/extract_l.cpp @@ -0,0 +1,143 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: extract_l.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32 ) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + L_var1 = Most significant word of input (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function returns the 16 LSB of the input, L_var1. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 extract_l (Word32 L_var1) +{ + Word16 var_out; + + var_out = (Word16) L_var1; +#if (WMOPS) + multiCounter[currCounter].extract_l++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word16 extract_l(Word32 L_var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return ((Word16) L_var1); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gains_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gains_tbl.cpp new file mode 100644 index 0000000..925c1dc --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gains_tbl.cpp @@ -0,0 +1,188 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: gains_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ +#define NB_QUA_PITCH 16 +#define NB_QUA_CODE 32 + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + + extern const Word16 qua_gain_pitch[]; + const Word16 qua_gain_pitch[NB_QUA_PITCH] = + { + 0, 3277, 6556, 8192, 9830, 11469, 12288, 13107, + 13926, 14746, 15565, 16384, 17203, 18022, 18842, 19661 + }; + + + extern const Word16 qua_gain_code[]; + const Word16 qua_gain_code[(NB_QUA_CODE+1)*3] = + { + /* gain factor (g_fac) and quantized energy error (qua_ener_MR122, qua_ener) + * are stored: + * + * qua_ener_MR122 = log2(g_fac) (not the rounded floating point value, but + * the value the original EFR algorithm + * calculates from g_fac [using Log2]) + * qua_ener = 20*log10(g_fac); (rounded floating point value) + * + * + * g_fac (Q11), qua_ener_MR122 (Q10), qua_ener (Q10) + */ + 159, -3776, -22731, + 206, -3394, -20428, + 268, -3005, -18088, + 349, -2615, -15739, + 419, -2345, -14113, + 482, -2138, -12867, + 554, -1932, -11629, + 637, -1726, -10387, + 733, -1518, -9139, + 842, -1314, -7906, + 969, -1106, -6656, + 1114, -900, -5416, + 1281, -694, -4173, + 1473, -487, -2931, + 1694, -281, -1688, + 1948, -75, -445, + 2241, 133, 801, + 2577, 339, 2044, + 2963, 545, 3285, + 3408, 752, 4530, + 3919, 958, 5772, + 4507, 1165, 7016, + 5183, 1371, 8259, + 5960, 1577, 9501, + 6855, 1784, 10745, + 7883, 1991, 11988, + 9065, 2197, 13231, + 10425, 2404, 14474, + 12510, 2673, 16096, + 16263, 3060, 18429, + 21142, 3448, 20763, + 27485, 3836, 23097, + 27485, 3836, 23097 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] gains.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gc_pred.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gc_pred.cpp new file mode 100644 index 0000000..9179fe4 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gc_pred.cpp @@ -0,0 +1,982 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: gc_pred.cpp + Functions: + gc_pred_reset + gc_pred + gc_pred_update + gc_pred_average_limited + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the functions that perform codebook gain MA prediction. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "gc_pred.h" +#include "basicop_malloc.h" +#include "basic_op.h" +#include "cnst.h" +#include "log2.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ +#define NPRED 4 /* number of prediction taps */ + +/* average innovation energy. */ +/* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */ +#define MEAN_ENER_MR122 783741L /* 36/(20*log10(2)) (Q17) */ + +/* minimum quantized energy: -14 dB */ +#define MIN_ENERGY -14336 /* 14 Q10 */ +#define MIN_ENERGY_MR122 -2381 /* 14 / (20*log10(2)) Q10 */ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/* MA prediction coefficients (Q13) */ +static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556}; + +/* MA prediction coefficients (Q6) */ +static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12}; + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: gc_pred_reset +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state = pointer to a structure of type gc_predState + + Outputs: + past_qua_en field in the structure pointed to by state is initialized + to MIN_ENERGY + past_qua_en_MR122 field in the structure pointed to by state is + initialized to MIN_ENERGY_MR122 + + Returns: + return_value = 0, if reset was successful; -1, otherwise (int) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function initializes the state memory used by gc_pred to zero. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +int gc_pred_reset (gc_predState *state) +{ + Word16 i; + + if (state == (gc_predState *) NULL){ + fprintf(stderr, "gc_pred_reset: invalid parameter\n"); + return -1; + } + + for(i = 0; i < NPRED; i++) + { + state->past_qua_en[i] = MIN_ENERGY; + state->past_qua_en_MR122[i] = MIN_ENERGY_MR122; + } + return 0; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF Word16 gc_pred_reset(gc_predState *state) +{ + Word16 i; + + if (state == (gc_predState *) NULL) + { + /* fprintf(stderr, "gc_pred_reset: invalid parameter\n"); */ + return -1; + } + + for (i = 0; i < NPRED; i++) + { + state->past_qua_en[i] = MIN_ENERGY; + state->past_qua_en_MR122[i] = MIN_ENERGY_MR122; + } + + return(0); +} + +/****************************************************************************/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: gc_pred +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = pointer to a structure of type gc_predState + mode = AMR mode (enum Mode) + code = pointer to the innovative codebook vector; Q12 in MR122 mode, + otherwise, Q13 (Word16) + exp_gcode0 = pointer to the exponent part of predicted gain factor + (Q0) (Word16) + frac_gcode0 = pointer to the fractional part of predicted gain factor + (Q15) (Word16) + exp_en = pointer to the exponent part of the innovation energy; this + is calculated for MR795 mode, Q0 (Word16) + frac_en = pointer to the fractional part of the innovation energy; + this is calculated for MR795 mode, Q15 (Word16) + pOverflow = pointer to overflow (Flag) + + Outputs: + store pointed to by exp_gcode0 contains the exponent part of the + recently calculated predicted gain factor + store pointed to by frac_gcode0 contains the fractional part of the + recently calculated predicted gain factor + store pointed to by exp_en contains the exponent part of the + recently calculated innovation energy + store pointed to by frac_en contains the fractional part of the + recently calculated innovation energy + pOverflow = 1 if the math functions called by gc_pred + results in overflow else zero. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + pred = table of MA prediction coefficients (Q13) (Word16) + pred_MR122 = table of MA prediction coefficients (Q6) (Word16) + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the MA prediction of the innovation energy (in + dB/(20*log10(2))), with the mean removed. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +The original etsi reference code uses a global flag Overflow. However, in the +actual implementation a pointer to a the overflow flag is passed in. + +void +gc_pred( + gc_predState *st, // i/o: State struct + enum Mode mode, // i : AMR mode + Word16 *code, // i : innovative codebook vector (L_SUBFR) + // MR122: Q12, other modes: Q13 + Word16 *exp_gcode0, // o : exponent of predicted gain factor, Q0 + Word16 *frac_gcode0,// o : fraction of predicted gain factor Q15 + Word16 *exp_en, // o : exponent of innovation energy, Q0 + // (only calculated for MR795) + Word16 *frac_en // o : fraction of innovation energy, Q15 + // (only calculated for MR795) +) +{ + Word16 i; + Word32 ener_code; + Word16 exp, frac; + + *-------------------------------------------------------------------* + * energy of code: * + * ~~~~~~~~~~~~~~~ * + * ener_code = sum(code[i]^2) * + *-------------------------------------------------------------------* + ener_code = L_mac((Word32) 0, code[0], code[0]); + // MR122: Q12*Q12 -> Q25 + // others: Q13*Q13 -> Q27 + for (i = 1; i < L_SUBFR; i++) + ener_code = L_mac(ener_code, code[i], code[i]); + + if (sub (mode, MR122) == 0) + { + Word32 ener; + + // ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20 + ener_code = L_mult (pv_round (ener_code), 26214); // Q9 * Q20 -> Q30 + + *-------------------------------------------------------------------* + * energy of code: * + * ~~~~~~~~~~~~~~~ * + * ener_code(Q17) = 10 * Log10(energy) / constant * + * = 1/2 * Log2(energy) * + * constant = 20*Log10(2) * + *-------------------------------------------------------------------* + // ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30 + Log2(ener_code, &exp, &frac); + ener_code = L_Comp (sub (exp, 30), frac); // Q16 for log() + // ->Q17 for 1/2 log() + + *-------------------------------------------------------------------* + * predicted energy: * + * ~~~~~~~~~~~~~~~~~ * + * ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant * + * = MEAN_ENER + sum(pred[i]*past_qua_en[i]) * + * constant = 20*Log10(2) * + *-------------------------------------------------------------------* + + ener = MEAN_ENER_MR122; // Q24 (Q17) + for (i = 0; i < NPRED; i++) + { + ener = L_mac (ener, st->past_qua_en_MR122[i], pred_MR122[i]); + // Q10 * Q13 -> Q24 + // Q10 * Q6 -> Q17 + } + + *-------------------------------------------------------------------* + * predicted codebook gain * + * ~~~~~~~~~~~~~~~~~~~~~~~ * + * gc0 = Pow10( (ener*constant - ener_code*constant) / 20 ) * + * = Pow2(ener-ener_code) * + * = Pow2(int(d)+frac(d)) * + * * + * (store exp and frac for pow2()) * + *-------------------------------------------------------------------* + + ener = L_shr (L_sub (ener, ener_code), 1); // Q16 + L_Extract(ener, exp_gcode0, frac_gcode0); + } + else // all modes except 12.2 + { + Word32 L_tmp; + Word16 exp_code, gcode0; + + *-----------------------------------------------------------------* + * Compute: means_ener - 10log10(ener_code/ L_sufr) * + *-----------------------------------------------------------------* + + exp_code = norm_l (ener_code); + ener_code = L_shl (ener_code, exp_code); + + // Log2 = log2 + 27 + Log2_norm (ener_code, exp_code, &exp, &frac); + + // fact = 10/log2(10) = 3.01 = 24660 Q13 + L_tmp = Mpy_32_16(exp, frac, -24660); // Q0.Q15 * Q13 -> Q14 + + * L_tmp = means_ener - 10log10(ener_code/L_SUBFR) + * = means_ener - 10log10(ener_code) + 10log10(L_SUBFR) + * = K - fact * Log2(ener_code) + * = K - fact * log2(ener_code) - fact*27 + * + * ==> K = means_ener + fact*27 + 10log10(L_SUBFR) + * + * means_ener = 33 = 540672 Q14 (MR475, MR515, MR59) + * means_ener = 28.75 = 471040 Q14 (MR67) + * means_ener = 30 = 491520 Q14 (MR74) + * means_ener = 36 = 589824 Q14 (MR795) + * means_ener = 33 = 540672 Q14 (MR102) + * 10log10(L_SUBFR) = 16.02 = 262481.51 Q14 + * fact * 27 = 1331640 Q14 + * ----------------------------------------- + * (MR475, MR515, MR59) K = 2134793.51 Q14 ~= 16678 * 64 * 2 + * (MR67) K = 2065161.51 Q14 ~= 32268 * 32 * 2 + * (MR74) K = 2085641.51 Q14 ~= 32588 * 32 * 2 + * (MR795) K = 2183945.51 Q14 ~= 17062 * 64 * 2 + * (MR102) K = 2134793.51 Q14 ~= 16678 * 64 * 2 + + + if (sub (mode, MR102) == 0) + { + // mean = 33 dB + L_tmp = L_mac(L_tmp, 16678, 64); // Q14 + } + else if (sub (mode, MR795) == 0) + { + // ener_code = <xn xn> * 2^27*2^exp_code + // frac_en = ener_code / 2^16 + // = <xn xn> * 2^11*2^exp_code + // <xn xn> = <xn xn>*2^11*2^exp * 2^exp_en + // := frac_en * 2^exp_en + + // ==> exp_en = -11-exp_code; + + *frac_en = extract_h (ener_code); + *exp_en = sub (-11, exp_code); + + // mean = 36 dB + L_tmp = L_mac(L_tmp, 17062, 64); // Q14 + } + else if (sub (mode, MR74) == 0) + { + // mean = 30 dB + L_tmp = L_mac(L_tmp, 32588, 32); // Q14 + } + else if (sub (mode, MR67) == 0) + { + // mean = 28.75 dB + L_tmp = L_mac(L_tmp, 32268, 32); // Q14 + } + else // MR59, MR515, MR475 + { + // mean = 33 dB + L_tmp = L_mac(L_tmp, 16678, 64); // Q14 + } + + *-----------------------------------------------------------------* + * Compute gcode0. * + * = Sum(i=0,3) pred[i]*past_qua_en[i] - ener_code + mean_ener * + *-----------------------------------------------------------------* + + L_tmp = L_shl(L_tmp, 10); // Q24 + for (i = 0; i < 4; i++) + L_tmp = L_mac(L_tmp, pred[i], st->past_qua_en[i]); + // Q13 * Q10 -> Q24 + + gcode0 = extract_h(L_tmp); // Q8 + + *-----------------------------------------------------------------* + * gcode0 = pow(10.0, gcode0/20) * + * = pow(2, 3.3219*gcode0/20) * + * = pow(2, 0.166*gcode0) * + *-----------------------------------------------------------------* + + // 5439 Q15 = 0.165985 + // (correct: 1/(20*log10(2)) 0.166096 = 5443 Q15) + if (sub (mode, MR74) == 0) // For IS641 bitexactness + L_tmp = L_mult(gcode0, 5439); // Q8 * Q15 -> Q24 + else + L_tmp = L_mult(gcode0, 5443); // Q8 * Q15 -> Q24 + + L_tmp = L_shr(L_tmp, 8); // -> Q16 + L_Extract(L_tmp, exp_gcode0, frac_gcode0); // -> Q0.Q15 + } +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void gc_pred( + gc_predState *st, /* i/o: State struct */ + enum Mode mode, /* i : AMR mode */ + Word16 *code, /* i : innovative codebook vector (L_SUBFR) */ + /* MR122: Q12, other modes: Q13 */ + Word16 *exp_gcode0, /* o : exponent of predicted gain factor, Q0 */ + Word16 *frac_gcode0,/* o : fraction of predicted gain factor Q15 */ + Word16 *exp_en, /* o : exponent of innovation energy, Q0 */ + /* (only calculated for MR795) */ + Word16 *frac_en, /* o : fraction of innovation energy, Q15 */ + /* (only calculated for MR795) */ + Flag *pOverflow +) +{ + register Word16 i; + register Word32 L_temp1, L_temp2; + register Word32 L_tmp; + Word32 ener_code; + Word32 ener; + Word16 exp, frac; + Word16 exp_code, gcode0; + Word16 tmp; + Word16 *p_code = &code[0]; + + /*-------------------------------------------------------------------* + * energy of code: * + * ~~~~~~~~~~~~~~~ * + * ener_code = sum(code[i]^2) * + *-------------------------------------------------------------------*/ + ener_code = 0; + + /* MR122: Q12*Q12 -> Q25 */ + /* others: Q13*Q13 -> Q27 */ + + for (i = L_SUBFR >> 2; i != 0; i--) + { + tmp = *(p_code++); + ener_code += ((Word32) tmp * tmp) >> 3; + tmp = *(p_code++); + ener_code += ((Word32) tmp * tmp) >> 3; + tmp = *(p_code++); + ener_code += ((Word32) tmp * tmp) >> 3; + tmp = *(p_code++); + ener_code += ((Word32) tmp * tmp) >> 3; + } + + ener_code <<= 4; + + if (ener_code < 0) /* Check for saturation */ + { + ener_code = MAX_32; + } + + if (mode == MR122) + { + /* ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20 */ + /* Q9 * Q20 -> Q30 */ + + ener_code = ((Word32)(pv_round(ener_code, pOverflow) * 26214)) << 1; + + /*-------------------------------------------------------------* + * energy of code: * + * ~~~~~~~~~~~~~~~ * + * ener_code(Q17) = 10 * Log10(energy) / constant * + * = 1/2 * Log2(energy) * + * constant = 20*Log10(2) * + *-------------------------------------------------------------*/ + /* ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30 */ + Log2(ener_code, &exp, &frac, pOverflow); + + /* Q16 for log() */ + /* ->Q17 for 1/2 log()*/ + + L_temp1 = (Word32)(exp - 30) << 16; + ener_code = L_temp1 + ((Word32)frac << 1); + + /*-------------------------------------------------------------* + * predicted energy: * + * ~~~~~~~~~~~~~~~~~ * + * ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant * + * = MEAN_ENER + sum(pred[i]*past_qua_en[i]) * + * constant = 20*Log10(2) * + *-------------------------------------------------------------*/ + + ener = MEAN_ENER_MR122; /* Q24 (Q17) */ + for (i = 0; i < NPRED; i++) + { + L_temp1 = (((Word32) st->past_qua_en_MR122[i]) * + pred_MR122[i]) << 1; + ener = L_add(ener, L_temp1, pOverflow); + + /* Q10 * Q13 -> Q24 */ + /* Q10 * Q6 -> Q17 */ + } + + /*---------------------------------------------------------------* + * predicted codebook gain * + * ~~~~~~~~~~~~~~~~~~~~~~~ * + * gc0 = Pow10( (ener*constant - ener_code*constant) / 20 ) * + * = Pow2(ener-ener_code) * + * = Pow2(int(d)+frac(d)) * + * * + * (store exp and frac for pow2()) * + *---------------------------------------------------------------*/ + /* Q16 */ + + L_temp1 = L_sub(ener, ener_code, pOverflow); + + + *exp_gcode0 = (Word16)(L_temp1 >> 17); + + L_temp2 = (Word32) * exp_gcode0 << 15; + L_temp1 >>= 2; + + *frac_gcode0 = (Word16)(L_temp1 - L_temp2); + + } + else /* all modes except 12.2 */ + { + /*-----------------------------------------------------------------* + * Compute: means_ener - 10log10(ener_code/ L_sufr) * + *-----------------------------------------------------------------*/ + + exp_code = norm_l(ener_code); + ener_code = L_shl(ener_code, exp_code, pOverflow); + + /* Log2 = log2 + 27 */ + Log2_norm(ener_code, exp_code, &exp, &frac); + + /* fact = 10/log2(10) = 3.01 = 24660 Q13 */ + /* Q0.Q15 * Q13 -> Q14 */ + + L_temp2 = (((Word32) exp) * -24660) << 1; + L_tmp = (((Word32) frac) * -24660) >> 15; + + /* Sign-extend resulting product */ + if (L_tmp & (Word32) 0x00010000L) + { + L_tmp = L_tmp | (Word32) 0xffff0000L; + } + + L_tmp = L_tmp << 1; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); + + + /* L_tmp = means_ener - 10log10(ener_code/L_SUBFR) + * = means_ener - 10log10(ener_code) + 10log10(L_SUBFR) + * = K - fact * Log2(ener_code) + * = K - fact * log2(ener_code) - fact*27 + * + * ==> K = means_ener + fact*27 + 10log10(L_SUBFR) + * + * means_ener = 33 = 540672 Q14 (MR475, MR515, MR59) + * means_ener = 28.75 = 471040 Q14 (MR67) + * means_ener = 30 = 491520 Q14 (MR74) + * means_ener = 36 = 589824 Q14 (MR795) + * means_ener = 33 = 540672 Q14 (MR102) + * 10log10(L_SUBFR) = 16.02 = 262481.51 Q14 + * fact * 27 = 1331640 Q14 + * ----------------------------------------- + * (MR475, MR515, MR59) K = 2134793.51 Q14 ~= 16678 * 64 * 2 + * (MR67) K = 2065161.51 Q14 ~= 32268 * 32 * 2 + * (MR74) K = 2085641.51 Q14 ~= 32588 * 32 * 2 + * (MR795) K = 2183945.51 Q14 ~= 17062 * 64 * 2 + * (MR102) K = 2134793.51 Q14 ~= 16678 * 64 * 2 + */ + + if (mode == MR102) + { + /* mean = 33 dB */ + L_temp2 = (Word32) 16678 << 7; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */ + } + else if (mode == MR795) + { + /* ener_code = <xn xn> * 2^27*2^exp_code + frac_en = ener_code / 2^16 + = <xn xn> * 2^11*2^exp_code + <xn xn> = <xn xn>*2^11*2^exp * 2^exp_en + : = frac_en * 2^exp_en + ==> exp_en = -11-exp_code; */ + *frac_en = (Word16)(ener_code >> 16); + *exp_en = -11 - exp_code; + + /* mean = 36 dB */ + L_temp2 = (Word32) 17062 << 7; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */ + } + else if (mode == MR74) + { + /* mean = 30 dB */ + L_temp2 = (Word32) 32588 << 6; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */ + } + else if (mode == MR67) + { + /* mean = 28.75 dB */ + L_temp2 = (Word32) 32268 << 6; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */ + } + else /* MR59, MR515, MR475 */ + { + /* mean = 33 dB */ + L_temp2 = (Word32) 16678 << 7; + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */ + } + + /*-------------------------------------------------------------* + * Compute gcode0. * + * = Sum(i=0,3) pred[i]*past_qua_en[i] - ener_code + mean_ener * + *--------------------------------------------------------------*/ + /* Q24 */ + if (L_tmp > (Word32) 0X001fffffL) + { + *pOverflow = 1; + L_tmp = MAX_32; + } + else if (L_tmp < (Word32) 0xffe00000L) + { + *pOverflow = 1; + L_tmp = MIN_32; + } + else + { + L_tmp = L_tmp << 10; + } + + for (i = 0; i < 4; i++) + { + L_temp2 = ((((Word32) pred[i]) * st->past_qua_en[i]) << 1); + L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q13 * Q10 -> Q24 */ + } + + gcode0 = (Word16)(L_tmp >> 16); /* Q8 */ + + /*-----------------------------------------------------------* + * gcode0 = pow(10.0, gcode0/20) * + * = pow(2, 3.3219*gcode0/20) * + * = pow(2, 0.166*gcode0) * + *-----------------------------------------------------------*/ + + /* 5439 Q15 = 0.165985 */ + /* (correct: 1/(20*log10(2)) 0.166096 = 5443 Q15) */ + + if (mode == MR74) /* For IS641 bitexactness */ + { + L_tmp = (((Word32) gcode0) * 5439) << 1; /* Q8 * Q15 -> Q24 */ + } + else + { + L_tmp = (((Word32) gcode0) * 5443) << 1; /* Q8 * Q15 -> Q24 */ + } + + if (L_tmp < 0) + { + L_tmp = ~((~L_tmp) >> 8); + } + else + { + L_tmp = L_tmp >> 8; /* -> Q16 */ + } + + *exp_gcode0 = (Word16)(L_tmp >> 16); + if (L_tmp < 0) + { + L_temp1 = ~((~L_tmp) >> 1); + } + else + { + L_temp1 = L_tmp >> 1; + } + L_temp2 = (Word32) * exp_gcode0 << 15; + *frac_gcode0 = (Word16)(L_sub(L_temp1, L_temp2, pOverflow)); + /* -> Q0.Q15 */ + } + + return; +} + +/****************************************************************************/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: gc_pred_update +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = pointer to a structure of type gc_predState + qua_ener_MR122 = quantized energy for update (Q10); calculated as + (log2(qua_err)) (Word16) + qua_ener = quantized energy for update (Q10); calculated as + (20*log10(qua_err)) (Word16) + + Outputs: + structure pointed to by st contains the calculated quantized energy + for update + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function updates the MA predictor with the last quantized energy. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void gc_pred_update( + gc_predState *st, // i/o: State struct + Word16 qua_ener_MR122, // i : quantized energy for update, Q10 + // (log2(qua_err)) + Word16 qua_ener // i : quantized energy for update, Q10 + // (20*log10(qua_err)) +) +{ + Word16 i; + + for (i = 3; i > 0; i--) + { + st->past_qua_en[i] = st->past_qua_en[i - 1]; + st->past_qua_en_MR122[i] = st->past_qua_en_MR122[i - 1]; + } + + st->past_qua_en_MR122[0] = qua_ener_MR122; // log2 (qua_err), Q10 + + st->past_qua_en[0] = qua_ener; // 20*log10(qua_err), Q10 + +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void gc_pred_update( + gc_predState *st, /* i/o: State struct */ + Word16 qua_ener_MR122, /* i : quantized energy for update, Q10 */ + /* (log2(qua_err)) */ + Word16 qua_ener /* i : quantized energy for update, Q10 */ + /* (20*log10(qua_err)) */ +) +{ + st->past_qua_en[3] = st->past_qua_en[2]; + st->past_qua_en_MR122[3] = st->past_qua_en_MR122[2]; + + st->past_qua_en[2] = st->past_qua_en[1]; + st->past_qua_en_MR122[2] = st->past_qua_en_MR122[1]; + + st->past_qua_en[1] = st->past_qua_en[0]; + st->past_qua_en_MR122[1] = st->past_qua_en_MR122[0]; + + st->past_qua_en_MR122[0] = qua_ener_MR122; /* log2 (qua_err), Q10 */ + + st->past_qua_en[0] = qua_ener; /* 20*log10(qua_err), Q10 */ + + return; +} + +/****************************************************************************/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: gc_pred_average_limited +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = pointer to a structure of type gc_predState + ener_avg_MR122 = pointer to the averaged quantized energy (Q10); + calculated as (log2(qua_err)) (Word16) + ener_avg = pointer to the averaged quantized energy (Q10); calculated + as (20*log10(qua_err)) (Word16) + pOverflow = pointer to overflow (Flag) + + Outputs: + store pointed to by ener_avg_MR122 contains the new averaged quantized + energy + store pointed to by ener_avg contains the new averaged quantized + energy + pOverflow = 1 if the math functions called by gc_pred_average_limited + results in overflow else zero. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calculates the average of MA predictor state values (with a + lower limit) used in error concealment. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +The original etsi reference code uses a global flag Overflow. However, in the +actual implementation a pointer to a the overflow flag is passed in. + +void gc_pred_average_limited( + gc_predState *st, // i: State struct + Word16 *ener_avg_MR122, // o: everaged quantized energy, Q10 + // (log2(qua_err)) + Word16 *ener_avg // o: averaged quantized energy, Q10 + // (20*log10(qua_err)) +) +{ + Word16 av_pred_en; + Word16 i; + + // do average in MR122 mode (log2() domain) + av_pred_en = 0; + for (i = 0; i < NPRED; i++) + { + av_pred_en = add (av_pred_en, st->past_qua_en_MR122[i]); + } + + // av_pred_en = 0.25*av_pred_en + av_pred_en = mult (av_pred_en, 8192); + + // if (av_pred_en < -14/(20Log10(2))) av_pred_en = .. + + if (sub (av_pred_en, MIN_ENERGY_MR122) < 0) + { + av_pred_en = MIN_ENERGY_MR122; + } + *ener_avg_MR122 = av_pred_en; + + // do average for other modes (20*log10() domain) + av_pred_en = 0; + for (i = 0; i < NPRED; i++) + { + av_pred_en = add (av_pred_en, st->past_qua_en[i]); + } + + // av_pred_en = 0.25*av_pred_en + av_pred_en = mult (av_pred_en, 8192); + + // if (av_pred_en < -14) av_pred_en = .. + + if (sub (av_pred_en, MIN_ENERGY) < 0) + { + av_pred_en = MIN_ENERGY; + } + *ener_avg = av_pred_en; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void gc_pred_average_limited( + gc_predState *st, /* i: State struct */ + Word16 *ener_avg_MR122, /* o: everaged quantized energy, Q10 */ + /* (log2(qua_err)) */ + Word16 *ener_avg, /* o: averaged quantized energy, Q10 */ + /* (20*log10(qua_err)) */ + Flag *pOverflow +) +{ + Word16 av_pred_en; + register Word16 i; + + /* do average in MR122 mode (log2() domain) */ + av_pred_en = 0; + for (i = 0; i < NPRED; i++) + { + av_pred_en = + add_16(av_pred_en, st->past_qua_en_MR122[i], pOverflow); + } + + /* av_pred_en = 0.25*av_pred_en (with sign-extension)*/ + if (av_pred_en < 0) + { + av_pred_en = (av_pred_en >> 2) | 0xc000; + } + else + { + av_pred_en >>= 2; + } + + /* if (av_pred_en < -14/(20Log10(2))) av_pred_en = .. */ + if (av_pred_en < MIN_ENERGY_MR122) + { + av_pred_en = MIN_ENERGY_MR122; + } + *ener_avg_MR122 = av_pred_en; + + /* do average for other modes (20*log10() domain) */ + av_pred_en = 0; + for (i = 0; i < NPRED; i++) + { + av_pred_en = add_16(av_pred_en, st->past_qua_en[i], pOverflow); + } + + /* av_pred_en = 0.25*av_pred_en (with sign-extension)*/ + if (av_pred_en < 0) + { + av_pred_en = (av_pred_en >> 2) | 0xc000; + } + else + { + av_pred_en >>= 2; + } + + /* if (av_pred_en < -14) av_pred_en = .. */ + if (av_pred_en < MIN_ENERGY) + { + av_pred_en = MIN_ENERGY; + } + *ener_avg = av_pred_en; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/get_const_tbls.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/get_const_tbls.cpp new file mode 100644 index 0000000..87ecb86 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/get_const_tbls.cpp @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +#ifndef GET_CONST_TBLS_H +#include "get_const_tbls.h" +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + extern const Word16 dgray[]; + extern const Word16 dico1_lsf_3[]; + extern const Word16 dico1_lsf_5[]; + extern const Word16 dico2_lsf_3[]; + extern const Word16 dico2_lsf_5[]; + extern const Word16 dico3_lsf_3[]; + extern const Word16 dico3_lsf_5[]; + extern const Word16 dico4_lsf_5[]; + extern const Word16 dico5_lsf_5[]; + extern const Word16 gray[]; + extern const Word16 lsp_init_data[]; + extern const Word16 mean_lsf_3[]; + extern const Word16 mean_lsf_5[]; + extern const Word16 mr515_3_lsf[]; + extern const Word16 mr795_1_lsf[]; + extern const Word16 past_rq_init[]; + extern const Word16 pred_fac_3[]; + extern const Word16 qua_gain_code[]; + extern const Word16 qua_gain_pitch[]; + extern const Word16 startPos[]; + extern const Word16 table_gain_lowrates[]; + extern const Word16 table_gain_highrates[]; + extern const Word16 prmno[]; + extern const Word16* const bitno[]; + extern const Word16 numOfBits[]; + extern const Word16* const reorderBits[]; + extern const Word16 numCompressedBytes[]; + extern const Word16 window_200_40[]; + extern const Word16 window_160_80[]; + extern const Word16 window_232_8[]; + extern const Word16 ph_imp_low_MR795[]; + extern const Word16 ph_imp_mid_MR795[]; + extern const Word16 ph_imp_low[]; + extern const Word16 ph_imp_mid[]; + +#ifdef __cplusplus +} +#endif + +OSCL_EXPORT_REF void get_const_tbls(CommonAmrTbls* tbl_struct_ptr) +{ + tbl_struct_ptr->dgray_ptr = dgray; + tbl_struct_ptr->dico1_lsf_3_ptr = dico1_lsf_3; + tbl_struct_ptr->dico1_lsf_5_ptr = dico1_lsf_5; + tbl_struct_ptr->dico2_lsf_3_ptr = dico2_lsf_3; + tbl_struct_ptr->dico2_lsf_5_ptr = dico2_lsf_5; + tbl_struct_ptr->dico3_lsf_3_ptr = dico3_lsf_3; + tbl_struct_ptr->dico3_lsf_5_ptr = dico3_lsf_5; + tbl_struct_ptr->dico4_lsf_5_ptr = dico4_lsf_5; + tbl_struct_ptr->dico5_lsf_5_ptr = dico5_lsf_5; + tbl_struct_ptr->gray_ptr = gray; + tbl_struct_ptr->lsp_init_data_ptr = lsp_init_data; + tbl_struct_ptr->mean_lsf_3_ptr = mean_lsf_3; + tbl_struct_ptr->mean_lsf_5_ptr = mean_lsf_5; + tbl_struct_ptr->mr515_3_lsf_ptr = mr515_3_lsf; + tbl_struct_ptr->mr795_1_lsf_ptr = mr795_1_lsf; + tbl_struct_ptr->past_rq_init_ptr = past_rq_init; + tbl_struct_ptr->pred_fac_3_ptr = pred_fac_3; + tbl_struct_ptr->qua_gain_code_ptr = qua_gain_code; + tbl_struct_ptr->qua_gain_pitch_ptr = qua_gain_pitch; + tbl_struct_ptr->startPos_ptr = startPos; + tbl_struct_ptr->table_gain_lowrates_ptr = table_gain_lowrates; + tbl_struct_ptr->table_gain_highrates_ptr = table_gain_highrates; + tbl_struct_ptr->prmno_ptr = prmno; + tbl_struct_ptr->bitno_ptr = bitno; + tbl_struct_ptr->numOfBits_ptr = numOfBits; + tbl_struct_ptr->reorderBits_ptr = reorderBits; + tbl_struct_ptr->numCompressedBytes_ptr = numCompressedBytes; + tbl_struct_ptr->window_200_40_ptr = window_200_40; + tbl_struct_ptr->window_160_80_ptr = window_160_80; + tbl_struct_ptr->window_232_8_ptr = window_232_8; + tbl_struct_ptr->ph_imp_low_MR795_ptr = ph_imp_low_MR795; + tbl_struct_ptr->ph_imp_mid_MR795_ptr = ph_imp_mid_MR795; + tbl_struct_ptr->ph_imp_low_ptr = ph_imp_low; + tbl_struct_ptr->ph_imp_mid_ptr = ph_imp_mid; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gmed_n.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gmed_n.cpp new file mode 100644 index 0000000..a723ce4 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gmed_n.cpp @@ -0,0 +1,184 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: gmed_n.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "gmed_n.h" +#include "typedef.h" +#include "oscl_mem.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ +#define NMAX 9 /* largest N used in median calculation */ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: gmed_n +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + ind = input values (Word16) + n = number of inputs to find the median (Word16) + + Returns: + median value. + + Outputs: + None. + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calculates N-point median of a data set. This routine is only + valid for a odd number of gains (n <= NMAX). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + gmed_n.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 gmed_n ( // o : The median value (0...N-1) + Word16 ind[], // i : Past gain values + Word16 n // i : The number of gains; this routine + // is only valid for a odd number of gains + // (n <= NMAX) +) +{ + Word16 i, j, ix = 0; + Word16 max; + Word16 medianIndex; + Word16 tmp[NMAX]; + Word16 tmp2[NMAX]; + + for (i = 0; i < n; i++) + { + tmp2[i] = ind[i]; + } + + for (i = 0; i < n; i++) + { + max = -32767; + for (j = 0; j < n; j++) + { + if (sub (tmp2[j], max) >= 0) + { + max = tmp2[j]; + ix = j; + } + } + tmp2[ix] = -32768; + tmp[i] = ix; + } + + medianIndex=tmp[ shr(n,1) ]; // account for complex addressing + return (ind[medianIndex]); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF Word16 gmed_n( /* o : the median value */ + Word16 ind[], /* i : input values */ + Word16 n /* i : number of inputs */ +) +{ + register Word16 i, j, ix = 0; + register Word16 max; + register Word16 medianIndex; + Word16 tmp[NMAX]; + Word16 tmp2[NMAX]; + + oscl_memmove(tmp2, ind, n*sizeof(*ind)); + + for (i = 0; i < n; i++) + { + max = -32767; + for (j = 0; j < n; j++) + { + if (*(tmp2 + j) >= max) + { + max = *(tmp2 + j); + ix = j; + } + } + *(tmp2 + ix) = -32768; + *(tmp + i) = ix; + } + + medianIndex = *(tmp + (n >> 1)); /* account for complex addressing */ + + return (*(ind + medianIndex)); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gray_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gray_tbl.cpp new file mode 100644 index 0000000..8b192f2 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/gray_tbl.cpp @@ -0,0 +1,135 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: gray_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for the gray encoding and decoding tables, + gray_tbl[] and dgray_tbl[] used by the c1035pf and d1035pf module + respectively. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + extern const Word16 gray[]; + extern const Word16 dgray[]; + const Word16 gray[8] = {0, 1, 3, 2, 6, 4, 5, 7}; + const Word16 dgray[8] = {0, 1, 3, 2, 5, 6, 4, 7}; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] gray.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/grid_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/grid_tbl.cpp new file mode 100644 index 0000000..48bab68 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/grid_tbl.cpp @@ -0,0 +1,153 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: grid_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for grid_tbl[] used by the az_lsp() + function. + + // Table for az_lsp() + // + // grid[0] = 1.0; + // grid[grid_points+1] = -1.0; + // for (i = 1; i < grid_points; i++) + // grid[i] = cos((6.283185307*i)/(2.0*grid_points)); + // + // + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "az_lsp.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ +#define grid_points 60 + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + const Word16 grid[grid_points + 1] = + { + 32760, 32723, 32588, 32364, 32051, 31651, + 31164, 30591, 29935, 29196, 28377, 27481, + 26509, 25465, 24351, 23170, 21926, 20621, + 19260, 17846, 16384, 14876, 13327, 11743, + 10125, 8480, 6812, 5126, 3425, 1714, + 0, -1714, -3425, -5126, -6812, -8480, + -10125, -11743, -13327, -14876, -16384, -17846, + -19260, -20621, -21926, -23170, -24351, -25465, + -26509, -27481, -28377, -29196, -29935, -30591, + -31164, -31651, -32051, -32364, -32588, -32723, + -32760 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] grid.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/int_lpc.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/int_lpc.cpp new file mode 100644 index 0000000..dc08c11 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/int_lpc.cpp @@ -0,0 +1,515 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: int_lpc.cpp + Functions: + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "int_lpc.h" +#include "typedef.h" +#include "cnst.h" +#include "lsp_az.h" +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Int_lpc_1and3 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp_old -- array of type Word16 -- LSP vector at the + 4th subfr. of past frame (M) + lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of + present frame (M) + lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of + present frame (M) + + Outputs: + Az -- array of type Word16 -- interpolated LP parameters in all subfr. + (AZ_SIZE) + pOverflow -- pointer to type Flag -- Overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Interpolates the LSPs and converts to LPC parameters + to get a different LP filter in each subframe. + Description : The 20 ms speech frame is divided into 4 subframes. + The LSPs are quantized and transmitted at the 2nd and + 4th subframes (twice per frame) and interpolated at the + 1st and 3rd subframe. + + |------|------|------|------| + sf1 sf2 sf3 sf4 + F0 Fm F1 + + sf1: 1/2 Fm + 1/2 F0 sf3: 1/2 F1 + 1/2 Fm + sf2: Fm sf4: F1 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Int_lpc_1and3( + Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */ + Word16 lsp_mid[], /* i : LSP vector at the 2nd subfr. of + present frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th subfr. of + present frame (M) */ + Word16 Az[], /* o : interpolated LP parameters in all subfr. + (AZ_SIZE) */ + Flag *pOverflow +) +{ + Word16 i; + Word16 lsp[M]; + Word16 *p_lsp_old = &lsp_old[0]; + Word16 *p_lsp_mid = &lsp_mid[0]; + Word16 *p_lsp_new = &lsp_new[0]; + Word16 *p_lsp = &lsp[0]; + + /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */ + + for (i = M >> 1; i != 0; i--) + { + *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1); + *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1); + } + + Lsp_Az( + lsp, + Az, + pOverflow); /* Subframe 1 */ + + Az += MP1; + + Lsp_Az( + lsp_mid, + Az, + pOverflow); /* Subframe 2 */ + + Az += MP1; + + p_lsp_mid = &lsp_mid[0]; + p_lsp = &lsp[0]; + + for (i = M >> 1; i != 0; i--) + { + *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1); + *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1); + } + + Lsp_Az( + lsp, + Az, + pOverflow); /* Subframe 3 */ + + Az += MP1; + + Lsp_Az( + lsp_new, + Az, + pOverflow); /* Subframe 4 */ + + return; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Int_lpc_1and3_2 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp_old -- array of type Word16 -- LSP vector at the + 4th subfr. of past frame (M) + lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of + present frame (M) + lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of + present frame (M) + + Outputs: + Az -- array of type Word16 -- interpolated LP parameters in. + subfr 1 and 2. + pOverflow -- pointer to type Flag -- Overflow indicator + + Returns: + None + + Global Variables Used: + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Interpolation of the LPC parameters. Same as the Int_lpc + function but we do not recompute Az() for subframe 2 and + 4 because it is already available. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void Int_lpc_1and3_2( + Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */ + Word16 lsp_mid[], /* i : LSP vector at the 2nd subframe of + present frame (M) */ + Word16 lsp_new[], /* i : LSP vector at the 4th subframe of + present frame (M) */ + Word16 Az[], /* o :interpolated LP parameters + in subframes 1 and 3 (AZ_SIZE) */ + Flag *pOverflow +) +{ + Word16 i; + Word16 lsp[M]; + Word16 *p_lsp_old = &lsp_old[0]; + Word16 *p_lsp_mid = &lsp_mid[0]; + Word16 *p_lsp_new = &lsp_new[0]; + Word16 *p_lsp = &lsp[0]; + + /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */ + + for (i = M >> 1; i != 0; i--) + { + *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1); + *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1); + } + Lsp_Az(lsp, Az, pOverflow); /* Subframe 1 */ + Az += MP1 * 2; + + p_lsp_mid = &lsp_mid[0]; + p_lsp = &lsp[0]; + + for (i = M >> 1; i != 0; i--) + { + *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1); + *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1); + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 3 */ + + return; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: lsp +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp_old -- array of type Word16 -- LSP vector at the + 4th subfr. of past frame (M) + lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of + present frame (M) + + Outputs: + Az -- array of type Word16 -- interpolated LP parameters in. + all subframes. + pOverflow -- pointer to type Flag -- Overflow indicator + + Returns: + None + + Global Variables Used: + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + PURPOSE: Interpolates the LSPs and convert to LP parameters to get + a different LP filter in each subframe. + + DESCRIPTION: + The 20 ms speech frame is divided into 4 subframes. + The LSPs are quantized and transmitted at the 4th subframe + (once per frame) and interpolated at the 1st, 2nd and 3rd subframe. + + |------|------|------|------| + sf1 sf2 sf3 sf4 + F0 F1 + + sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1 + sf2: 1/2 F0 + 1/2 F1 sf4: F1 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Int_lpc_1to3( + Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */ + Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */ + Word16 Az[], /* output: interpolated LP parameters in all SFs */ + Flag *pOverflow +) +{ + Word16 i; + Word16 temp; + + Word16 lsp[M]; + + for (i = 0; i < M; i++) + { + temp = lsp_old[i] - (lsp_old[i] >> 2); + lsp[i] = temp + (lsp_new[i] >> 2); + } + + Lsp_Az( + lsp, + Az, + pOverflow); /* Subframe 1 */ + + Az += MP1; + + + for (i = 0; i < M; i++) + { + lsp[i] = (lsp_new[i] >> 1) + (lsp_old[i] >> 1); + + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 2 */ + + Az += MP1; + + for (i = 0; i < M; i++) + { + + temp = lsp_new[i] - (lsp_new[i] >> 2); + lsp[i] = temp + (lsp_old[i] >> 2); + + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 3 */ + + Az += MP1; + + Lsp_Az(lsp_new, Az, pOverflow); /* Subframe 4 */ + + return; +} +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Int_lpc_1to3_2 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp_old -- array of type Word16 -- LSP vector at the + 4th subfr. of past frame (M) + lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of + present frame (M) + + Outputs: + Az -- array of type Word16 -- interpolated LP parameters in. + subfr 1, 2, and 3. + pOverflow -- pointer to type Flag -- Overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Interpolation of the LPC parameters. + Same as the previous function but we do not recompute Az() for + subframe 4 because it is already available. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void Int_lpc_1to3_2( + Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */ + Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */ + Word16 Az[], /* output: interpolated LP parameters in SFs 1,2,3 */ + Flag *pOverflow +) +{ + Word16 i; + Word16 temp; + Word16 lsp[M]; + + for (i = 0; i < M; i++) + { + temp = lsp_old[i] - (lsp_old[i] >> 2); + lsp[i] = temp + (lsp_new[i] >> 2); + + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 1 */ + + Az += MP1; + + for (i = 0; i < M; i++) + { + lsp[i] = (lsp_new[i] >> 1) + (lsp_old[i] >> 1); + + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 2 */ + + Az += MP1; + + for (i = 0; i < M; i++) + { + temp = lsp_new[i] - (lsp_new[i] >> 2); + lsp[i] = temp + (lsp_old[i] >> 2); + + } + + Lsp_Az(lsp, Az, pOverflow); /* Subframe 3 */ + + return; +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt.cpp new file mode 100644 index 0000000..0125dd4 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt.cpp @@ -0,0 +1,220 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: inv_sqrt.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "inv_sqrt.h" +#include "typedef.h" +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Inv_sqrt +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_x = input value (Word32) + pOverflow = pointer to overflow flag + + Outputs: + pOverflow -> if the Inv_sqrt operation resulted in an overflow. + + Returns: + L_y = inverse squareroot of L_x (Word32) + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes 1/sqrt(L_x), where L_x is positive. + If L_x is negative or zero, the result is 1 (3fff ffff). + + The function 1/sqrt(L_x) is approximated by a table and linear + interpolation. The inverse square root is computed using the + following steps: + 1- Normalization of L_x. + 2- If (30-exponent) is even then shift right once. + 3- exponent = (30-exponent)/2 +1 + 4- i = bit25-b31 of L_x; 16<=i<=63 because of normalization. + 5- a = bit10-b24 + 6- i -=16 + 7- L_y = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + 8- L_y >>= exponent + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + inv_sqrt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 Inv_sqrt ( // (o) : output value + Word32 L_x // (i) : input value +) +{ + Word16 exp, i, a, tmp; + Word32 L_y; + +* The reference ETSI code uses a global Overflow flag. In the actual +* implementation a pointer to the overflow flag is passed into the function. +* This pointer is in turn passed into the basic math functions such as add(), +* L_shl(), L_shr(), sub() called by this module. + + if (L_x <= (Word32) 0) + return ((Word32) 0x3fffffffL); + + exp = norm_l (L_x); + L_x = L_shl (L_x, exp); // L_x is normalize + + exp = sub (30, exp); + + if ((exp & 1) == 0) // If exponent even -> shift right + { + L_x = L_shr (L_x, 1); + } + exp = shr (exp, 1); + exp = add (exp, 1); + + L_x = L_shr (L_x, 9); + i = extract_h (L_x); // Extract b25-b31 + L_x = L_shr (L_x, 1); + a = extract_l (L_x); // Extract b10-b24 + a = a & (Word16) 0x7fff; + + i = sub (i, 16); + + L_y = L_deposit_h (table[i]); // table[i] << 16 + tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1]) + L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2 + + L_y = L_shr (L_y, exp); // denormalization + + return (L_y); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF Word32 Inv_sqrt( /* (o) : output value */ + Word32 L_x, /* (i) : input value */ + Flag * pOverflow /* (i) : pointer to overflow flag */ +) +{ + Word16 exp; + Word16 i; + Word16 a; + Word16 tmp; + Word32 L_y; + OSCL_UNUSED_ARG(pOverflow); + + if (L_x <= (Word32) 0) + { + return ((Word32) 0x3fffffffL); + } + + exp = norm_l(L_x); + L_x <<= exp; /* L_x is normalize */ + + exp = 30 - exp; + + if ((exp & 1) == 0) /* If exponent even -> shift right */ + { + L_x >>= 1; + } + exp >>= 1; + exp += 1; + + L_x >>= 9; + i = (Word16)(L_x >> 16); /* Extract b25-b31 */ + a = (Word16)(L_x >> 1); /* Extract b10-b24 */ + a &= (Word16) 0x7fff; + + i -= 16; + + L_y = (Word32)inv_sqrt_tbl[i] << 16; /* inv_sqrt_tbl[i] << 16 */ + + /* inv_sqrt_tbl[i] - inv_sqrt_tbl[i+1]) */ + tmp = inv_sqrt_tbl[i] - inv_sqrt_tbl[i + 1]; + /* always a positive number less than 200 */ + + L_y -= ((Word32)tmp * a) << 1; /* L_y -= tmp*a*2 */ + /* always a positive minus a small negative number */ + + L_y >>= exp; /* denormalization, exp always 0< exp < 31 */ + + return (L_y); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt_tbl.cpp new file mode 100644 index 0000000..3ae066a --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/inv_sqrt_tbl.cpp @@ -0,0 +1,138 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: inv_sqrt_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for table[] used by the inv_sqrt function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "inv_sqrt.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + const Word16 inv_sqrt_tbl[49] = + { + + 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214, + 25705, 25225, 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155, + 21845, 21548, 21263, 20988, 20724, 20470, 20225, 19988, 19760, 19539, + 19326, 19119, 18919, 18725, 18536, 18354, 18176, 18004, 17837, 17674, + 17515, 17361, 17211, 17064, 16921, 16782, 16646, 16514, 16384 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] inv_sqrt.tab file, UMTS GSM AMR speech codec, R99 - Version 3.2.0, + March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_abs.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_abs.cpp new file mode 100644 index 0000000..e436006 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_abs.cpp @@ -0,0 +1,160 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_abs.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32 ) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + L_var1 = absolute value of input (Word32) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calculates the absolute value of L_var1; saturate in case + where the input is -214783648. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 L_abs (Word32 L_var1) +{ + Word32 L_var_out; + + if (L_var1 == MIN_32) + { + L_var_out = MAX_32; + } + else + { + if (L_var1 < 0) + { + L_var_out = -L_var1; + } + else + { + L_var_out = L_var1; + } + } + +#if (WMOPS) + multiCounter[currCounter].L_abs++; +#endif + return (L_var_out); +} + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word32 L_abs(register Word32 L_var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + Word32 y = L_var1 - (L_var1 < 0); + y = y ^(y >> 31); + return (y); + +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_h.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_h.cpp new file mode 100644 index 0000000..2a8ad2f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_h.cpp @@ -0,0 +1,144 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_deposit_h.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var1 = deposit of var1 into MSWord of 32 bit value (Word32) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function deposits the 16 bit var1 into the 16 MS bits of the 32 bit + output. The 16 LS bits of the output are zeroed. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 L_deposit_h (Word16 var1) +{ + Word32 L_var_out; + + L_var_out = (Word32) var1 << 16; +#if (WMOPS) + multiCounter[currCounter].L_deposit_h++; +#endif + return (L_var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word32 L_deposit_h(Word16 var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return ((Word32) var1 << 16); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_l.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_l.cpp new file mode 100644 index 0000000..1f5f1fb --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_deposit_l.cpp @@ -0,0 +1,144 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_deposit_l.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var1 = deposit of var1 into LSWord of 32 bit value (Word32) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function deposits the 16 bit var1 into the 16 LS bits of the 32 bit + output. The 16 MS bits of the output are sign extended. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 L_deposit_l (Word16 var1) +{ + Word32 L_var_out; + + L_var_out = (Word32) var1; +#if (WMOPS) + multiCounter[currCounter].L_deposit_l++; +#endif + return (L_var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word32 L_deposit_l(Word16 var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return ((Word32) var1); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_shr_r.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_shr_r.cpp new file mode 100644 index 0000000..0a07135 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/l_shr_r.cpp @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: l_shr_r.cpp + +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: L_shr_r +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32 ) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the 32 bit shift operation resulted in overflow + + Returns: + result = Shifted result w/ rounding (Word32) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function arithmetically shifts the 32 bit input L_var1 right var2 + positions with rounding. If var2 is negative, the function + arithmetically shifts L_var1 left by -var2 and zero fills the -var2 LSB of + the result. The result is saturated in case of underflows or overflows, i.e., + + - If var2 is greater than zero : + if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1)))) + is equal to zero + then + L_shr_r(L_var1,var2) = L_shr(L_var1,var2) + else + L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1) + - If var2 is less than or equal to zero : + L_shr_r(L_var1,var2) = L_shr(L_var1,var2). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] L_shr_r() function in basic_op2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 L_shr_r (Word32 L_var1, Word16 var2) +{ + Word32 L_var_out; + +* The reference ETSI code uses a global flag for Overflow. In the actual +* implementation a pointer to Overflow flag is passed in as a parameter to the +* function L_shr() + + if (var2 > 31) + { + L_var_out = 0; + } + else + { + L_var_out = L_shr (L_var1, var2); +#if (WMOPS) + multiCounter[currCounter].L_shr--; +#endif + if (var2 > 0) + { + if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0) + { + L_var_out++; + } + } + } +#if (WMOPS) + multiCounter[currCounter].L_shr_r++; +#endif + return (L_var_out); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word32 L_shr_r(register Word32 L_var1, register Word16 var2, Flag *pOverflow) +{ + Word32 result; + + if (var2 > 31) + { + result = 0; + } + else + { + result = L_shr(L_var1, var2, pOverflow); + + if (var2 > 0) + { + if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0) + { + result++; + } + } + } + return (result); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2.cpp new file mode 100644 index 0000000..d08543f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2.cpp @@ -0,0 +1,142 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: log2.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "log2.h" +#include "basic_op.h" +#include "log2_norm.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: log2() +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_x = input value of type Word32 + pExponent = pointer to the integer part of Log2 of type Word16 whose + valid range is: 0 <= value <= 30 + pFraction = pointer to the fractional part of Log2 of type Word16 + whose valid range is: 0 <= value < 1 + pOverflow = pointer to overflow flag + + + Outputs: + pExponent -> integer part of the newly calculated Log2 + pFraction -> fractional part of the newly calculated Log2 + pOverflow -> 1 if the log2() operation resulted in saturation + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes logarithm (base2) of the input L_x, where L_x is + positive. If L_x is negative or zero, the result is 0. + + This function first normalizes the input L_x and calls the function Log2_norm + to calculate the logarithm. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] log2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF void Log2( + Word32 L_x, /* (i) : input value */ + Word16 *pExponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/ + Word16 *pFraction, /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Flag *pOverflow /* (i/o) : overflow flag */ +) +{ + Word16 exp; + Word32 result; + OSCL_UNUSED_ARG(pOverflow); + + exp = norm_l(L_x); + result = L_x << exp; + Log2_norm(result, exp, pExponent, pFraction); + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_norm.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_norm.cpp new file mode 100644 index 0000000..174d57f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_norm.cpp @@ -0,0 +1,202 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: log2_norm.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "log2_norm.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Log2_norm +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_x = normalized input value of type Word32 + exp = number of shifts required to normalize L_x; it is of type Word16 + exponent = pointer to the integer part of Log2 (of type Word16) + whose valid range is: 0 <= value <= 30 + fraction = pointer to the fractional part of Log2 (of type Word16) + whose valid range is: 0 <= value < 1 + + Outputs: + exponent points to the newly calculated integer part of Log2 + fraction points to the newly calculated fractional part of Log2 + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + table = Log2 table of constants of type Word16 + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + The function Log2(L_x) calculates the logarithm of the normalized input + buffer L_x. The logarithm is approximated by a table and linear + interpolation. The following steps are used to compute Log2(L_x): + + 1. exponent = 30 - norm_exponent + 2. i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). + 3. a = bit10-b24 + 4. i = i - 32 + 5. fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + log2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Log2_norm ( + Word32 L_x, // (i) : input value (normalized) + Word16 exp, // (i) : norm_l (L_x) + Word16 *exponent, // (o) : Integer part of Log2. (range: 0<=val<=30) + Word16 *fraction // (o) : Fractional part of Log2. (range: 0<=val<1) +) +{ + Word16 i, a, tmp; + Word32 L_y; + + if (L_x <= (Word32) 0) + { + *exponent = 0; + *fraction = 0; + return; + } + + *exponent = sub (30, exp); + + L_x = L_shr (L_x, 9); + i = extract_h (L_x); // Extract b25-b31 + L_x = L_shr (L_x, 1); + a = extract_l (L_x); // Extract b10-b24 of fraction + a = a & (Word16) 0x7fff; + + i = sub (i, 32); + + L_y = L_deposit_h (table[i]); // table[i] << 16 + tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1] + L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2 + + *fraction = extract_h (L_y); + + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void Log2_norm( + Word32 L_x, /* (i) : input value (normalized) */ + Word16 exp, /* (i) : norm_l (L_x) */ + Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/ + Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ +) +{ + Word16 i, a, tmp; + Word32 L_y; + + if (L_x <= (Word32) 0) + { + *exponent = 0; + *fraction = 0; + } + else + { + /* Calculate exponent portion of Log2 */ + *exponent = 30 - exp; + + /* At this point, L_x > 0 */ + /* Shift L_x to the right by 10 to extract bits 10-31, */ + /* which is needed to calculate fractional part of Log2 */ + L_x >>= 10; + i = (Word16)(L_x >> 15); /* Extract b25-b31 */ + a = L_x & 0x7fff; /* Extract b10-b24 of fraction */ + + /* Calculate table index -> subtract by 32 is done for */ + /* proper table indexing, since 32<=i<=63 (due to normalization) */ + i -= 32; + + /* Fraction part of Log2 is approximated by using table[] */ + /* and linear interpolation, i.e., */ + /* fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 */ + L_y = (Word32) log2_tbl[i] << 16; /* table[i] << 16 */ + tmp = log2_tbl[i] - log2_tbl[i + 1]; /* table[i] - table[i+1] */ + L_y -= (((Word32) tmp) * a) << 1; /* L_y -= tmp*a*2 */ + + *fraction = (Word16)(L_y >> 16); + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_tbl.cpp new file mode 100644 index 0000000..76f66b0 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/log2_tbl.cpp @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: log2_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for log2_tbl[] used by the log2() and + log2_norm() function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "log2_norm.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + const Word16 log2_tbl[33] = + { + 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, 10549, 11716, + 12855, 13967, 15054, 16117, 17156, 18172, 19167, 20142, 21097, 22033, + 22951, 23852, 24735, 25603, 26455, 27291, 28113, 28922, 29716, 30497, + 31266, 32023, 32767 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] log2.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsfwt.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsfwt.cpp new file mode 100644 index 0000000..310ba3c --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsfwt.cpp @@ -0,0 +1,202 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: lsfwt.cpp + Functions: Lsf_wt + + ------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf -- Pointer to Word16 -- LSF vector + + Outputs: + wf -- Pointer to Word16 -- square of weighting factors + pOverflow -- Pointer to type Flag -- Flag set when overflow occurs + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + +Compute LSF weighting factors + + d[i] = lsf[i+1] - lsf[i-1] + + The weighting factors are approximated by two line segment + + First segment passes by the following 2 points: + + d[i] = 0Hz wf[i] = 3.347 + d[i] = 450Hz wf[i] = 1.8 + + Second segment passes by the following 2 points: + + d[i] = 450Hz wf[i] = 1.8 + d[i] = 1500Hz wf[i] = 1.0 + + if( d[i] < 450Hz ) + wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) * d[i] + else + wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) * (d[i] - 450) + + + if( d[i] < 1843) + wf[i] = 3427 - (28160*d[i])>>15 + else + wf[i] = 1843 - (6242*(d[i]-1843))>>15 + +------------------------------------------------------------------------------ + REQUIREMENTS + + + +------------------------------------------------------------------------------ + REFERENCES + + lsfwt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "lsfwt.h" +#include "cnst.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +void Lsf_wt( + Word16 *lsf, /* input : LSF vector */ + Word16 *wf, /* output: square of weighting factors */ + Flag *pOverflow +) +{ + Word16 temp; + Word16 wgt_fct; + Word16 i; + Word16 *p_wf = wf; + Word16 *p_lsf = &lsf[0]; + Word16 *p_lsf_2 = &lsf[1]; + + OSCL_UNUSED_ARG(pOverflow); + + /* wf[0] = lsf[1] - 0 */ + *(p_wf++) = *(p_lsf_2++); + + for (i = 4; i != 0 ; i--) + { + *(p_wf++) = *(p_lsf_2++) - *(p_lsf++); + *(p_wf++) = *(p_lsf_2++) - *(p_lsf++); + } + /* + * wf[9] = 4000 - lsf[8] + */ + *(p_wf) = 16384 - *(p_lsf); + + p_wf = wf; + + for (i = 10; i != 0; i--) + { + /* + * (wf[i] - 450); + * 1843 == 450 Hz (Q15 considering 7FFF = 8000 Hz) + */ + wgt_fct = *p_wf; + temp = wgt_fct - 1843; + + if (temp > 0) + { + temp = (Word16)(((Word32)temp * 6242) >> 15); + wgt_fct = 1843 - temp; + } + else + { + temp = (Word16)(((Word32)wgt_fct * 28160) >> 15); + wgt_fct = 3427 - temp; + } + + *(p_wf++) = wgt_fct << 3; + + } /* for (i = 10; i != 0; i--) */ + + return; + +} /* Lsf_wt() */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp.cpp new file mode 100644 index 0000000..d5c1d27 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp.cpp @@ -0,0 +1,440 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: lsp.cpp + Functions: + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "lsp.h" +#include "typedef.h" +#include "q_plsf.h" +#include "az_lsp.h" +#include "int_lpc.h" +#include "lsp_tab.h" +#include "oscl_mem.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: lsp_init (lspState **st) +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = Pointer to type lspState + + Outputs: + st = Pointer to type lspState -- values are initialized. + + Returns: + None + + Global Variables Used: + lsp_init_data = Word16 array. + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Initializes lsp state data. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF Word16 lsp_init(lspState **st) +{ + lspState* s; + + if (st == (lspState **) NULL) + { + /* fprintf(stderr, "lsp_init: invalid parameter\n"); */ + return -1; + } + + *st = NULL; + + /* allocate memory */ + if ((s = (lspState *) oscl_malloc(sizeof(lspState))) == NULL) + { + /* fprintf(stderr, "lsp_init: can not malloc state structure\n"); */ + return -1; + } + + /* Initialize quantization state */ + if (0 != Q_plsf_init(&s->qSt)) + { + return -1; + } + + if (0 != lsp_reset(s)) + { + return -1; + } + + *st = s; + + return 0; +} + + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: lsp_reset +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = Pointer to type lspState + + Outputs: + st = Pointer to type lspState -- values are reset. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + resets lsp_state data +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ +OSCL_EXPORT_REF Word16 lsp_reset(lspState *st) +{ + + if (st == (lspState *) NULL) + { + /* fprintf(stderr, "lsp_reset: invalid parameter\n"); */ + return -1; + } + + /* Init lsp_old[] */ + oscl_memcpy(st->lsp_old, lsp_init_data, M*sizeof(Word16)); + + /* Initialize lsp_old_q[] */ + oscl_memcpy(st->lsp_old_q, st->lsp_old, M*sizeof(Word16)); + + /* Reset quantization state */ + Q_plsf_reset(st->qSt); + + return 0; +} + + + + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: lsp_exit +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = Pointer to type lspState + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Frees memory used by lspState. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ +OSCL_EXPORT_REF void lsp_exit(lspState **st) +{ + if (st == NULL || *st == NULL) + return; + + /* Deallocate members */ + Q_plsf_exit(&(*st)->qSt); + + /* deallocate memory */ + oscl_free(*st); + *st = NULL; + + return; +} + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: lsp +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + + + Inputs: + st = Pointer to type lspState -- State struct + req_mode = enum Mode -- requested coder mode + used_mode = enum Mode -- used coder mode + az = array of type Word16 -- interpolated LP parameters Q12 + + Outputs: + azQ = array of type Word16 -- quantization interpol. LP parameters Q12 + lsp_new = array of type Word16 -- new lsp vector + anap = Double pointer of type Word16 -- analysis parameters + pOverflow = Pointer to type Flag -- Flag set when overflow occurs + st = Pointer to type lspState -- State struct + az = array of type Word16 -- interpolated LP parameters Q12 + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ +OSCL_EXPORT_REF void lsp(lspState *st, /* i/o : State struct */ + enum Mode req_mode, /* i : requested coder mode */ + enum Mode used_mode,/* i : used coder mode */ + Word16 az[], /* i/o : interpolated LP parameters Q12 */ + Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/ + Word16 lsp_new[], /* o : new lsp vector */ + Word16 **anap, /* o : analysis parameters */ + Flag *pOverflow) /* o : Flag set when overflow occurs */ + +{ + Word16 lsp_new_q[M]; /* LSPs at 4th subframe */ + Word16 lsp_mid[M], lsp_mid_q[M]; /* LSPs at 2nd subframe */ + + Word16 pred_init_i; /* init index for MA prediction in DTX mode */ + + if (req_mode == MR122) + { + Az_lsp(&az[MP1], lsp_mid, st->lsp_old, pOverflow); + Az_lsp(&az[MP1 * 3], lsp_new, lsp_mid, pOverflow); + + /*--------------------------------------------------------------------* + * Find interpolated LPC parameters in all subframes (both quantized * + * and unquantized). * + * The interpolated parameters are in array A_t[] of size (M+1)*4 * + * and the quantized interpolated parameters are in array Aq_t[] * + *--------------------------------------------------------------------*/ + Int_lpc_1and3_2(st->lsp_old, lsp_mid, lsp_new, az, pOverflow); + + if (used_mode != MRDTX) + { + /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */ + Q_plsf_5( + st->qSt, + lsp_mid, + lsp_new, + lsp_mid_q, + lsp_new_q, + *anap, + pOverflow); + + Int_lpc_1and3(st->lsp_old_q, lsp_mid_q, lsp_new_q, azQ, pOverflow); + + /* Advance analysis parameters pointer */ + (*anap) += 5; + } + } + else + { + Az_lsp(&az[MP1 * 3], lsp_new, st->lsp_old, pOverflow); /* From A(z) to lsp */ + + /*--------------------------------------------------------------------* + * Find interpolated LPC parameters in all subframes (both quantized * + * and unquantized). * + * The interpolated parameters are in array A_t[] of size (M+1)*4 * + * and the quantized interpolated parameters are in array Aq_t[] * + *--------------------------------------------------------------------*/ + + Int_lpc_1to3_2(st->lsp_old, lsp_new, az, pOverflow); + + if (used_mode != MRDTX) + { + /* LSP quantization */ + Q_plsf_3( + st->qSt, + req_mode, + lsp_new, + lsp_new_q, + *anap, + &pred_init_i, + pOverflow); + + Int_lpc_1to3( + st->lsp_old_q, + lsp_new_q, + azQ, + pOverflow); + + /* Advance analysis parameters pointer */ + (*anap) += 3; + } + } + + /* update the LSPs for the next frame */ + oscl_memcpy(st->lsp_old, lsp_new, M*sizeof(Word16)); + + if (used_mode != MRDTX) + { + oscl_memcpy(st->lsp_old_q, lsp_new_q, M*sizeof(Word16)); + } +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_az.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_az.cpp new file mode 100644 index 0000000..c41f614 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_az.cpp @@ -0,0 +1,376 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsp_az.cpp + Functions: Get_lsp_pol + Lsp_Az + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains functions that convert line spectral pairs (LSP) to + linear predictive (LP) coefficients (filter order = 10). The functions + included in this file include Get_lsp_pol, which finds the coefficients of + F1(z) and F2(z), and Lsp_Az, which converts LSP to LPC by multiplying + F1(z) by 1+z^(-1) and F2(z) by 1-z^(-1), then calculating A(z) = (F1(z) + + F2(z))/2. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "lsp_az.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Get_lsp_pol +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp = pointer to the buffer containing the line spectral pairs (LSP) + of type Word16 + f = pointer to the polynomial of type Word32 to be generated + + pOverflow = pointer set in case where one of the operations overflows. + [data type Pointer to Flag] + + Outputs: + buffer pointed to by f contains the polynomial generated + + pOverflow = pointer set in case where one of the operations overflows. + [data type Pointer to Flag] + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function finds the polynomial F1(z) or F2(z) from the LSPs. If the LSP + vector is passed at address 0, F1(z) is computed and if it is passed at + address 1, F2(z) is computed. + + This is performed by expanding the product polynomials: + + F1(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 ) + i=0,2,4,6,8 + F2(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 ) + i=1,3,5,7,9 + + where lsp[] is the LSP vector in the cosine domain. + + The expansion is performed using the following recursion: + + f[0] = 1 + b = -2.0 * lsp[0] + f[1] = b + for i=2 to 5 do + b = -2.0 * lsp[2*i-2]; + for j=i-1 down to 2 do + f[j] = f[j] + b*f[j-1] + f[j-2]; + f[1] = f[1] + b; + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +static void Get_lsp_pol (Word16 *lsp, Word32 *f) +{ + Word16 i, j, hi, lo; + Word32 t0; + + // f[0] = 1.0; + *f = L_mult (4096, 2048); + f++; + *f = L_msu ((Word32) 0, *lsp, 512); // f[1] = -2.0 * lsp[0]; + f++; + lsp += 2; // Advance lsp pointer + + for (i = 2; i <= 5; i++) + { + *f = f[-2]; + + for (j = 1; j < i; j++, f--) + { + L_Extract (f[-1], &hi, &lo); + t0 = Mpy_32_16 (hi, lo, *lsp); // t0 = f[-1] * lsp + t0 = L_shl (t0, 1); + *f = L_add (*f, f[-2]); // *f += f[-2] + *f = L_sub (*f, t0); // *f -= t0 + } + *f = L_msu (*f, *lsp, 512); // *f -= lsp<<9 + f += i; // Advance f pointer + lsp += 2; // Advance lsp pointer + } + + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void Get_lsp_pol( + Word16 *lsp, + Word32 *f, + Flag *pOverflow) +{ + register Word16 i; + register Word16 j; + + Word16 hi; + Word16 lo; + Word32 t0; + OSCL_UNUSED_ARG(pOverflow); + + /* f[0] = 1.0; */ + *f++ = (Word32) 0x01000000; + *f++ = (Word32) - *(lsp++) << 10; /* f[1] = -2.0 * lsp[0]; */ + lsp++; /* Advance lsp pointer */ + + for (i = 2; i <= 5; i++) + { + *f = *(f - 2); + + for (j = 1; j < i; j++) + { + hi = (Word16)(*(f - 1) >> 16); + + lo = (Word16)((*(f - 1) >> 1) - ((Word32) hi << 15)); + + t0 = ((Word32)hi * *lsp); + t0 += ((Word32)lo * *lsp) >> 15; + + *(f) += *(f - 2); /* *f += f[-2] */ + *(f--) -= t0 << 2; /* *f -= t0 */ + + } + + *f -= (Word32)(*lsp++) << 10; + + f += i; + lsp++; + } + + return; +} + +/****************************************************************************/ + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Lsp_Az +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp = pointer to the buffer containing the line spectral pairs (LSP) + of type Word16 + + a = pointer to the buffer containing Linear Predictive (LP) + coefficients of type Word16 to be generated + + pOverflow = pointer set in case where one of the operations overflows. + [data type Pointer to Flag] + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + pOverflow = pointer set in case where one of the operations overflows. + [data type Pointer to Flag] + + Pointers and Buffers Modified: + a buffer contains the generated Linear Predictive (LP) coefficients + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function converts from the line spectral pairs (LSP) to LP coefficients + for a 10th order filter. + + This is done by: + (1) Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol) + (2) Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1} + (3) A(z) = ( F1(z) + F2(z) ) / 2 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Lsp_Az ( + Word16 lsp[], // (i) : line spectral frequencies + Word16 a[] // (o) : predictor coefficients (order = 10) +) +{ + Word16 i, j; + Word32 f1[6], f2[6]; + Word32 t0; + + Get_lsp_pol (&lsp[0], f1); + Get_lsp_pol (&lsp[1], f2); + + for (i = 5; i > 0; i--) + { + f1[i] = L_add (f1[i], f1[i - 1]); // f1[i] += f1[i-1]; + f2[i] = L_sub (f2[i], f2[i - 1]); // f2[i] -= f2[i-1]; + } + + a[0] = 4096; + for (i = 1, j = 10; i <= 5; i++, j--) + { + t0 = L_add (f1[i], f2[i]); // f1[i] + f2[i] + a[i] = extract_l (L_shr_r (t0, 13)); + t0 = L_sub (f1[i], f2[i]); // f1[i] - f2[i] + a[j] = extract_l (L_shr_r (t0, 13)); + } + + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Lsp_Az( + Word16 lsp[], /* (i) : line spectral frequencies */ + Word16 a[], /* (o) : predictor coefficients (order = 10) */ + Flag *pOverflow /* (o) : overflow flag */ +) +{ + register Word16 i; + register Word16 j; + + Word32 f1[6]; + Word32 f2[6]; + Word32 t0; + Word32 t1; + Word16 *p_a = &a[0]; + Word32 *p_f1; + Word32 *p_f2; + + Get_lsp_pol(&lsp[0], f1, pOverflow); + + Get_lsp_pol(&lsp[1], f2, pOverflow); + + p_f1 = &f1[5]; + p_f2 = &f2[5]; + + for (i = 5; i > 0; i--) + { + *(p_f1--) += f1[i-1]; + *(p_f2--) -= f2[i-1]; + } + + *(p_a++) = 4096; + p_f1 = &f1[1]; + p_f2 = &f2[1]; + + for (i = 1, j = 10; i <= 5; i++, j--) + { + t0 = *(p_f1) + *(p_f2); /* f1[i] + f2[i] */ + t1 = *(p_f1++) - *(p_f2++); /* f1[i] - f2[i] */ + + t0 = t0 + ((Word32) 1 << 12); + t1 = t1 + ((Word32) 1 << 12); + + *(p_a++) = (Word16)(t0 >> 13); + a[j] = (Word16)(t1 >> 13); + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf.cpp new file mode 100644 index 0000000..f315f5f --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf.cpp @@ -0,0 +1,318 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: lsp_lsf.cpp + Functions: Lsp_lsf + Lsf_lsp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the functions that convert line spectral pairs (LSP) to + line spectral frequencies (LSF) and vice-versa. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "lsp_lsf.h" +#include "basicop_malloc.h" +#include "basic_op.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + + extern const Word16 table[]; + extern const Word16 slope[]; + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Lsf_lsp +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf = buffer containing normalized line spectral frequencies; valid + range is between 0 and 0.5 (Word16) + lsp = buffer containing line spectral pairs; valid range is between + -1 and 1 (Word16) + m = LPC order (Word16) + + Outputs: + lsp contains the newly calculated line spectral pairs + + Returns: + None + + Global Variables Used: + table = cosine table + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the LSF to LSP transformation using the equation: + + lsf[i] = arccos(lsp[i])/(2*pi) + + The transformation from lsp[i] to lsf[i] is approximated by a look-up table + and interpolation. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Lsf_lsp ( + Word16 lsf[], // (i) : lsf[m] normalized (range: 0.0<=val<=0.5) + Word16 lsp[], // (o) : lsp[m] (range: -1<=val<1) + Word16 m // (i) : LPC order +) +{ + Word16 i, ind, offset; + Word32 L_tmp; + + for (i = 0; i < m; i++) + { + ind = shr (lsf[i], 8); // ind = b8-b15 of lsf[i] + offset = lsf[i] & 0x00ff; // offset = b0-b7 of lsf[i] + + // lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 + + L_tmp = L_mult (sub (table[ind + 1], table[ind]), offset); + lsp[i] = add (table[ind], extract_l (L_shr (L_tmp, 9))); + + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Lsf_lsp( + Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */ + Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */ + Word16 m, /* (i) : LPC order */ + Flag *pOverflow /* (o) : Flag set when overflow occurs */ +) +{ + Word16 i, ind, offset; + Word32 L_tmp; + + for (i = 0; i < m; i++) + { + ind = lsf[i] >> 8; /* ind = b8-b15 of lsf[i] */ + offset = lsf[i] & 0x00ff; /* offset = b0-b7 of lsf[i] */ + + /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */ + + L_tmp = ((Word32)(table[ind + 1] - table[ind]) * offset) >> 8; + lsp[i] = table[ind] + (Word16) L_tmp; + + } + + return; +} + +/****************************************************************************/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Lsp_lsf +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsp = buffer containing line spectral pairs; valid range is between + -1 and 1 (Word16) + lsf = buffer containing normalized line spectral frequencies; valid + range is between 0 and 0.5 (Word16) + m = LPC order (Word16) + + Outputs: + lsf contains the newly calculated normalized line spectral frequencies + + Returns: + None + + Global Variables Used: + table = cosine table + slope = table to used to calculate inverse cosine + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the LSP to LSF transformation using the equation: + + lsp[i] = cos(2*pi*lsf[i]) + + The transformation from lsf[i] to lsp[i] is approximated by a look-up table + and interpolation. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Lsp_lsf ( + Word16 lsp[], // (i) : lsp[m] (range: -1<=val<1) + Word16 lsf[], // (o) : lsf[m] normalized (range: 0.0<=val<=0.5) + Word16 m // (i) : LPC order +) +{ + Word16 i, ind; + Word32 L_tmp; + + ind = 63; // begin at end of table -1 + + for (i = m - 1; i >= 0; i--) + { + // find value in table that is just greater than lsp[i] + + while (sub (table[ind], lsp[i]) < 0) + { + ind--; + + } + + // acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) * + slope[ind] )/4096 + + L_tmp = L_mult (sub (lsp[i], table[ind]), slope[ind]); + //(lsp[i]-table[ind])*slope[ind])>>12 + lsf[i] = pv_round (L_shl (L_tmp, 3)); + lsf[i] = add (lsf[i], shl (ind, 8)); + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Lsp_lsf( + Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */ + Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */ + Word16 m, /* (i) : LPC order */ + Flag *pOverflow /* (o) : Flag set when overflow occurs */ +) +{ + Word16 i; + Word16 ind; + Word16 temp; + Word32 L_tmp; + Word16 *p_lsp = &lsp[m-1]; + Word16 *p_lsf = &lsf[m-1]; + OSCL_UNUSED_ARG(pOverflow); + + ind = 63; /* begin at end of table -1 */ + + for (i = m - 1; i >= 0; i--) + { + /* find value in table that is just greater than lsp[i] */ + temp = *(p_lsp--); + while (table[ind] < temp) + { + ind--; + } + + /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) * + slope[ind] )/4096 */ + + L_tmp = (Word32)(temp - table[ind]) * slope[ind]; + + /*(lsp[i]-table[ind])*slope[ind])>>12*/ + L_tmp = (L_tmp + 0x00000800) >> 12; + + *(p_lsf--) = (Word16)(L_tmp) + (ind << 8); + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf_tbl.cpp new file mode 100644 index 0000000..f44aabf --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_lsf_tbl.cpp @@ -0,0 +1,105 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: lsp_lsf_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + extern const Word16 table[]; + const Word16 table[65] = + { + 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, + 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, + 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, + 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, + 0, -1608, -3212, -4808, -6393, -7962, -9512, -11039, + -12540, -14010, -15447, -16846, -18205, -19520, -20788, -22006, + -23170, -24279, -25330, -26320, -27246, -28106, -28899, -29622, + -30274, -30853, -31357, -31786, -32138, -32413, -32610, -32729, + (Word16) 0x8000 + }; + + /* 0x8000 = -32768 (used to silence the compiler) */ + + /* slope used to compute y = acos(x) */ + + extern const Word16 slope[]; + const Word16 slope[64] = + { + -26887, -8812, -5323, -3813, -2979, -2444, -2081, -1811, + -1608, -1450, -1322, -1219, -1132, -1059, -998, -946, + -901, -861, -827, -797, -772, -750, -730, -713, + -699, -687, -677, -668, -662, -657, -654, -652, + -652, -654, -657, -662, -668, -677, -687, -699, + -713, -730, -750, -772, -797, -827, -861, -901, + -946, -998, -1059, -1132, -1219, -1322, -1450, -1608, + -1811, -2081, -2444, -2979, -3813, -5323, -8812, -26887 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_tab.cpp new file mode 100644 index 0000000..d236137 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/lsp_tab.cpp @@ -0,0 +1,154 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: lsp_tab.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + None + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + File : lsp.tab + Purpose : Table for lsp init + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + None + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "lsp_tab.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; LOCAL STORE/BUFFER/POINTER DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + const Word16 lsp_init_data[M] = + { + 30000, 26000, 21000, 15000, 8000, + 0, -8000, -15000, -21000, -26000 + }; + + /*---------------------------------------------------------------------------- + ; EXTERNAL FUNCTION REFERENCES + ; Declare functions defined elsewhere and referenced in this module + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; Define all local variables +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Function body here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Return nothing or data or data pointer +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/mult_r.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/mult_r.cpp new file mode 100644 index 0000000..6ee82b2 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/mult_r.cpp @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: mult_r.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + Multiplication function with rounding and overflow control + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: mult_r +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the add operation resulted in overflow + + Returns: + L_product_arr = 16-bit limited product of var1 and var2 (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the multiplication of var1 by var2 with rounding, and + gives a 16 bit result which is scaled, i.e.: + mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and | + mult_r(-32768,-32768) = 32767 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] mult_r() function in basicop2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 mult_r (Word16 var1, Word16 var2) +{ + Word16 var_out; + Word32 L_product_arr; + + L_product_arr = (Word32) var1 *(Word32) var2; + L_product_arr += (Word32) 0x00004000L; + L_product_arr &= (Word32) 0xffff8000L; + L_product_arr >>= 15; + + if (L_product_arr & (Word32) 0x00010000L) + { + L_product_arr |= (Word32) 0xffff0000L; + } +* The reference ETSI code uses a global flag for Overflow inside the function +* saturate(). In the actual implementation a pointer to Overflow flag is passed in +* as a parameter to the function + + var_out = saturate (L_product_arr); + +#if (WMOPS) + multiCounter[currCounter].mult_r++; +#endif + + return (var_out); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +OSCL_EXPORT_REF Word16 mult_r(Word16 var1, Word16 var2, Flag *pOverflow) +{ + + register Word32 L_product_arr; + + L_product_arr = ((Word32) var1) * var2; /* product */ + L_product_arr += (Word32) 0x00004000L; /* round */ + L_product_arr >>= 15; /* shift */ + + /* sign extend when necessary */ + L_product_arr |= (Word32) - (L_product_arr & (Word32) 0x00010000L); + + /* Saturate result (if necessary). */ + /* Replaced function call with in-line code to conserve MIPS, */ + /* i.e., var_out = saturate (L_product_arr) */ + + if (L_product_arr > 0X00007fffL) + { + *pOverflow = 1; + L_product_arr = MAX_16; + } + else if (L_product_arr < (Word32) 0xffff8000L) + { + *pOverflow = 1; + L_product_arr = MIN_16; + } + + return ((Word16) L_product_arr); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/negate.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/negate.cpp new file mode 100644 index 0000000..3db2458 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/negate.cpp @@ -0,0 +1,146 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: negate.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var1 = negated value of input (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function negates var1 with saturation; saturate in the case where input + is -32768: negate(var1) = sub(0,var1). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 negate (Word16 var1) +{ + Word16 var_out; + + var_out = (var1 == MIN_16) ? MAX_16 : -var1; +#if (WMOPS) + multiCounter[currCounter].negate++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "negate.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +Word16 negate(register Word16 var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + var1 = (var1 == MIN_16) ? MAX_16 : -var1; + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return (var1); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_l.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_l.cpp new file mode 100644 index 0000000..e690246 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_l.cpp @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: norm_l.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit long signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= var1 <= 0x7fff ffff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var_out = number of left shifts need to normalize input (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function produces the number of left shifts needed to normalize the 32 + bit variable L_var1 for positive values on the interval with minimum of + 0x40000000 and maximum of 0x7fffffff, and for negative values on the interval + with minimum of 0x80000000 and maximum of 0xc0000000. Note that when L_var1 + is equal to zero, the output var_out is set to zero. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 norm_l (Word32 L_var1) +{ + Word16 var_out; + + if (L_var1 == 0) + { + var_out = 0; + } + else + { + if (L_var1 == (Word32) 0xffffffffL) + { + var_out = 31; + } + else + { + if (L_var1 < 0) + { + L_var1 = ~L_var1; + } + for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++) + { + L_var1 <<= 1; + } + } + } + +#if (WMOPS) + multiCounter[currCounter].norm_l++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) ) +OSCL_EXPORT_REF Word16 norm_l(register Word32 L_var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + register Word16 var_out = 0; + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + if (L_var1) + { + + Word32 y = L_var1 - (L_var1 < 0); + L_var1 = y ^(y >> 31); + + + while (!(0x40000000L & L_var1)) + { + var_out++; + if ((0x20000000L & L_var1)) + { + break; + } + var_out++; + if ((0x10000000L & L_var1)) + { + break; + } + var_out++; + if ((0x08000000L & L_var1)) + { + break; + } + var_out++; + L_var1 <<= 4; + } + } + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + + + return (var_out); +} +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_s.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_s.cpp new file mode 100644 index 0000000..892d06e --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/norm_s.cpp @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: norm_s.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit signed integer of type Word16, whose value falls + in the range: 0x8000 <= var1 <= 0x7fff + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var_out = number of left shifts need to normalize var1 (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function produces the number of left shifts needed to normalize the 16 + bit variable var1 for positive values on the interval with minimum of 0x4000 + and maximum of 0x7fff, and for negative values on the interval with minimum + of 0x8000 and maximum of 0xc000. Note that when var1 is zero, the resulting + output var_out is set to zero. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 norm_s (Word16 var1) +{ + Word16 var_out; + + if (var1 == 0) + { + var_out = 0; + } + else + { + if (var1 == (Word16) 0xffff) + { + var_out = 15; + } + else + { + if (var1 < 0) + { + var1 = ~var1; + } + for (var_out = 0; var1 < 0x4000; var_out++) + { + var1 <<= 1; + } + } + } + +#if (WMOPS) + multiCounter[currCounter].norm_s++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) ) + +OSCL_EXPORT_REF Word16 norm_s(register Word16 var1) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + + register Word16 var_out = 0; + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + + if (var1) + { + Word16 y = var1 - (var1 < 0); + var1 = y ^(y >> 15); + + while (!(0x4000 & var1)) + { + var_out++; + if ((0x2000 & var1)) + { + break; + } + var_out++; + if ((0x1000 & var1)) + { + break; + } + var_out++; + if ((0x0800 & var1)) + { + break; + } + var_out++; + var1 <<= 4; + } + } + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return (var_out); +} + +#endif diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/overflow_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/overflow_tbl.cpp new file mode 100644 index 0000000..d78d627 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/overflow_tbl.cpp @@ -0,0 +1,147 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: overflow_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for overflow_tbl[] used by the l_shl() + and l_shr() functions. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + const Word32 overflow_tbl [32] = {0x7fffffffL, 0x3fffffffL, + 0x1fffffffL, 0x0fffffffL, + 0x07ffffffL, 0x03ffffffL, + 0x01ffffffL, 0x00ffffffL, + 0x007fffffL, 0x003fffffL, + 0x001fffffL, 0x000fffffL, + 0x0007ffffL, 0x0003ffffL, + 0x0001ffffL, 0x0000ffffL, + 0x00007fffL, 0x00003fffL, + 0x00001fffL, 0x00000fffL, + 0x000007ffL, 0x000003ffL, + 0x000001ffL, 0x000000ffL, + 0x0000007fL, 0x0000003fL, + 0x0000001fL, 0x0000000fL, + 0x00000007L, 0x00000003L, + 0x00000001L, 0x00000000L + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] l_shl() function in basic_op2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/ph_disp_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/ph_disp_tab.cpp new file mode 100644 index 0000000..f9e7faa --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/ph_disp_tab.cpp @@ -0,0 +1,165 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: ph_disp_tab.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the table of impulse responses of the phase dispersion + filters. All impulse responses are in Q15 + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + extern const Word16 ph_imp_low_MR795[]; + const Word16 ph_imp_low_MR795[40] = + { + 26777, 801, 2505, -683, -1382, 582, 604, -1274, 3511, -5894, + 4534, -499, -1940, 3011, -5058, 5614, -1990, -1061, -1459, 4442, + -700, -5335, 4609, 452, -589, -3352, 2953, 1267, -1212, -2590, + 1731, 3670, -4475, -975, 4391, -2537, 949, -1363, -979, 5734 + }; + extern const Word16 ph_imp_mid_MR795[]; + const Word16 ph_imp_mid_MR795[40] = + { + 30274, 3831, -4036, 2972, -1048, -1002, 2477, -3043, 2815, -2231, + 1753, -1611, 1714, -1775, 1543, -1008, 429, -169, 472, -1264, + 2176, -2706, 2523, -1621, 344, 826, -1529, 1724, -1657, 1701, + -2063, 2644, -3060, 2897, -1978, 557, 780, -1369, 842, 655 + }; + + extern const Word16 ph_imp_low[]; + const Word16 ph_imp_low[40] = + { + 14690, 11518, 1268, -2761, -5671, 7514, -35, -2807, -3040, 4823, + 2952, -8424, 3785, 1455, 2179, -8637, 8051, -2103, -1454, 777, + 1108, -2385, 2254, -363, -674, -2103, 6046, -5681, 1072, 3123, + -5058, 5312, -2329, -3728, 6924, -3889, 675, -1775, 29, 10145 + }; + extern const Word16 ph_imp_mid[]; + const Word16 ph_imp_mid[40] = + { + 30274, 3831, -4036, 2972, -1048, -1002, 2477, -3043, 2815, -2231, + 1753, -1611, 1714, -1775, 1543, -1008, 429, -169, 472, -1264, + 2176, -2706, 2523, -1621, 344, 826, -1529, 1724, -1657, 1701, + -2063, 2644, -3060, 2897, -1978, 557, 780, -1369, 842, 655 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] ph_disp.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2.cpp new file mode 100644 index 0000000..637f92d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2.cpp @@ -0,0 +1,176 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: pow2.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "pow2.h" +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Pow2 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + exponent = Integer part whose valid range is: 0 <= value <= 30 (Word16) + fraction = Fractional part whose valid range is 0 <= value < 1 + + pOverflow = pointer to overflow flag + + Outputs: + L_x = Result of the Pow2() computation (Word32) + pOverflow -> 1 if the Pow2() function results in saturation + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes L_x = pow(2.0, exponent.fraction) + + The function Pow2(L_x) is approximated by a table and linear interpolation. + + 1- i = bit10-b15 of fraction, 0 <= i <= 31 + 2- a = bit0-b9 of fraction + 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + 4- L_x = L_x >> (30-exponent) (with rounding) + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + pow2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 Pow2 ( // (o) : result (range: 0<=val<=0x7fffffff) + Word16 exponent, // (i) : Integer part. (range: 0<=val<=30) + Word16 fraction // (i) : Fractional part. (range: 0.0<=val<1.0) +) +{ + Word16 exp, i, a, tmp; + Word32 L_x; + + L_x = L_mult (fraction, 32); // L_x = fraction<<6 + i = extract_h (L_x); // Extract b10-b16 of fraction + L_x = L_shr (L_x, 1); + a = extract_l (L_x); // Extract b0-b9 of fraction + a = a & (Word16) 0x7fff; + + L_x = L_deposit_h (table[i]); // table[i] << 16 + tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1] + L_x = L_msu (L_x, tmp, a); // L_x -= tmp*a*2 + + exp = sub (30, exponent); + L_x = L_shr_r (L_x, exp); + + return (L_x); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +OSCL_EXPORT_REF Word32 Pow2( /* (o) : result (range: 0<=val<=0x7fffffff) */ + Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ + Word16 fraction, /* (i) : Fractional part. (range: 0.0<=val<1.0) */ + Flag *pOverflow +) +{ + Word16 exp, i, a, tmp; + Word32 L_x; + + L_x = L_mult(fraction, 32, pOverflow); /* L_x = fraction<<6 */ + + /* Extract b0-b16 of fraction */ + + i = ((Word16)(L_x >> 16)) & 31; /* ensure index i is bounded */ + a = (Word16)((L_x >> 1) & 0x7fff); + + L_x = ((Word32) pow2_tbl[i] << 16); /* pow2_tbl[i] << 16 */ + + /* pow2_tbl[i] - pow2_tbl[i+1] */ + tmp = pow2_tbl[i] - pow2_tbl[i + 1]; + L_x = L_msu(L_x, tmp, a, pOverflow); /* L_x -= tmp*a*2 */ + + exp = 30 - exponent; + L_x = L_shr_r(L_x, exp, pOverflow); + + return (L_x); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2_tbl.cpp new file mode 100644 index 0000000..e49a89d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pow2_tbl.cpp @@ -0,0 +1,136 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: pow2_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for log2_tbl[] used by the Pow2() function. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "pow2.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + const Word16 pow2_tbl[33] = + { + 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, + 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, + 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, + 31379, 32066, 32767 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] pow2.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pred_lt.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pred_lt.cpp new file mode 100644 index 0000000..fd51242 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/pred_lt.cpp @@ -0,0 +1,291 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: pred_lt.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "pred_lt.h" +#include "cnst.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ +#define UP_SAMP_MAX 6 +#define L_INTER10 (L_INTERPOL-1) +#define FIR_SIZE (UP_SAMP_MAX*L_INTER10+1) + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */ +/* Note: the 1/3 resolution filter is simply a subsampled + * version of the 1/6 resolution filter, i.e. it uses + * every second coefficient: + * + * inter_3l[k] = inter_6[2*k], 0 <= k <= 3*L_INTER10 + */ + +const Word16 inter_6_pred_lt[FIR_SIZE] = +{ + 29443, + 28346, 25207, 20449, 14701, 8693, 3143, + -1352, -4402, -5865, -5850, -4673, -2783, + -672, 1211, 2536, 3130, 2991, 2259, + 1170, 0, -1001, -1652, -1868, -1666, + -1147, -464, 218, 756, 1060, 1099, + 904, 550, 135, -245, -514, -634, + -602, -451, -231, 0, 191, 308, + 340, 296, 198, 78, -36, -120, + -163, -165, -132, -79, -19, 34, + 73, 91, 89, 70, 38, 0 +}; + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Pred_lt_3or6 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + exc = buffer containing the excitation (Word16) + T0 = integer pitch lag (Word16) + frac = fraction of lag (Word16) + L_subfr = number of samples per subframe (Word16) + flag3 = flag to indicate the upsampling rate; if set, upsampling + rate is 3, otherwise, upsampling rate is 6 (Word16) + + pOverflow = pointer to overflow (Flag) + + Returns: + None + + Outputs: + exc buffer contains the newly formed adaptive codebook excitation + pOverflow -> 1 if the add operation resulted in overflow + + Global Variables Used: + inter_6_pred_lt = (1/6) resolution interpolation filter table (Word16) + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes the result of long term prediction with fractional + interpolation of resolution 1/3 or 1/6. (Interpolated past excitation). + + The past excitation signal at the given delay is interpolated at + the given fraction to build the adaptive codebook excitation. + On return exc[0..L_subfr-1] contains the interpolated signal + (adaptive codebook excitation). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + pred_lt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Pred_lt_3or6 ( + Word16 exc[], // in/out: excitation buffer + Word16 T0, // input : integer pitch lag + Word16 frac, // input : fraction of lag + Word16 L_subfr, // input : subframe size + Word16 flag3 // input : if set, upsampling rate = 3 (6 otherwise) +) +{ + Word16 i, j, k; + Word16 *pX0, *pX1, *pX2; + const Word16 *pC1, *pC2; + Word32 s; + + pX0 = &exc[-T0]; + + frac = negate (frac); + if (flag3 != 0) + { + frac = shl (frac, 1); // inter_3l[k] = inter_6[2*k] -> k' = 2*k + } + + if (frac < 0) + { + frac = add (frac, UP_SAMP_MAX); + pX0--; + } + + for (j = 0; j < L_subfr; j++) + { + pX1 = pX0++; + pX2 = pX0; + pC1 = &inter_6[frac]; + pC2 = &inter_6[sub (UP_SAMP_MAX, frac)]; + + s = 0; + for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP_MAX) + { + s = L_mac (s, pX1[-i], pC1[k]); + s = L_mac (s, pX2[i], pC2[k]); + } + + exc[j] = pv_round (s); + } + + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Pred_lt_3or6( + Word16 exc[], /* in/out: excitation buffer */ + Word16 T0, /* input : integer pitch lag */ + Word16 frac, /* input : fraction of lag */ + Word16 L_subfr, /* input : subframe size */ + Word16 flag3, /* input : if set, upsampling rate = 3 (6 otherwise) */ + Flag *pOverflow /* output: if set, overflow occurred in this function */ +) +{ + register Word16 i; + register Word16 j; + register Word16 k; + + Word16 *pX0; + Word16 *pX2; + Word16 *pX3; + Word16 *p_exc; + Word16 *pC1; + const Word16 *pC1_ref; + const Word16 *pC2_ref; + + Word16 Coeff_1[(L_INTER10<<1)]; + + Word32 s1; + Word32 s2; + OSCL_UNUSED_ARG(pOverflow); + + pX0 = &(exc[-T0]); + + /* frac goes between -3 and 3 */ + + frac = -frac; + + if (flag3 != 0) + { + frac <<= 1; /* inter_3l[k] = inter_6[2*k] -> k' = 2*k */ + } + + if (frac < 0) + { + frac += UP_SAMP_MAX; + pX0--; + } + + pC1_ref = &inter_6_pred_lt[frac]; + pC2_ref = &inter_6_pred_lt[UP_SAMP_MAX-frac]; + + + pC1 = Coeff_1; + + k = 0; + + for (i = L_INTER10 >> 1; i > 0; i--) + { + *(pC1++) = pC1_ref[k]; + *(pC1++) = pC2_ref[k]; + k += UP_SAMP_MAX; + *(pC1++) = pC1_ref[k]; + *(pC1++) = pC2_ref[k]; + k += UP_SAMP_MAX; + + } + + p_exc = exc; + + for (j = (L_subfr >> 1); j != 0 ; j--) + { + pX0++; + pX2 = pX0; + pX3 = pX0++; + + pC1 = Coeff_1; + + s1 = 0x00004000L; + s2 = 0x00004000L; + + for (i = L_INTER10 >> 1; i > 0; i--) + { + s2 += ((Word32) * (pX3--)) * *(pC1); + s1 += ((Word32) * (pX3)) * *(pC1++); + s1 += ((Word32) * (pX2++)) * *(pC1); + s2 += ((Word32) * (pX2)) * *(pC1++); + s2 += ((Word32) * (pX3--)) * *(pC1); + s1 += ((Word32) * (pX3)) * *(pC1++); + s1 += ((Word32) * (pX2++)) * *(pC1); + s2 += ((Word32) * (pX2)) * *(pC1++); + + } /* for (i = L_INTER10>>1; i > 0; i--) */ + + *(p_exc++) = (Word16)(s1 >> 15); + *(p_exc++) = (Word16)(s2 >> 15); + + } /* for (j = (L_subfr>>1); j != 0 ; j--) */ + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf.cpp new file mode 100644 index 0000000..75392e9 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf.cpp @@ -0,0 +1,142 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : q_plsf.c +* Purpose : common part (init, exit, reset) of LSF quantization +* module (rest in q_plsf_3.c and q_plsf_5.c) +* +******************************************************************************** +*/ + +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "q_plsf.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "oscl_mem.h" + + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ + +/* +************************************************************************** +* +* Function : Q_plsf_init +* Purpose : Allocates memory and initializes state variables +* +************************************************************************** +*/ +Word16 Q_plsf_init(Q_plsfState **state) +{ + Q_plsfState* s; + + if (state == (Q_plsfState **) NULL) + { + /* fprintf(stderr, "Q_plsf_init: invalid parameter\n"); */ + return -1; + } + *state = NULL; + + /* allocate memory */ + if ((s = (Q_plsfState *) oscl_malloc(sizeof(Q_plsfState))) == NULL) + { + /* fprintf(stderr, "Q_plsf_init: can not malloc state structure\n"); */ + return -1; + } + + Q_plsf_reset(s); + *state = s; + + return 0; +} + +/* +************************************************************************** +* +* Function : Q_plsf_reset +* Purpose : Resets state memory +* +************************************************************************** +*/ +Word16 Q_plsf_reset(Q_plsfState *state) +{ + Word16 i; + + if (state == (Q_plsfState *) NULL) + { + /* fprintf(stderr, "Q_plsf_reset: invalid parameter\n"); */ + return -1; + } + + for (i = 0; i < M; i++) + state->past_rq[i] = 0; + + return 0; +} + +/* +************************************************************************** +* +* Function : Q_plsf_exit +* Purpose : The memory used for state memory is freed +* +************************************************************************** +*/ +void Q_plsf_exit(Q_plsfState **state) +{ + if (state == NULL || *state == NULL) + return; + + /* deallocate memory */ + oscl_free(*state); + *state = NULL; + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3.cpp new file mode 100644 index 0000000..2c5446b --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3.cpp @@ -0,0 +1,1097 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf_3.cpp + Funtions: Vq_subvec4 + Test_Vq_subvec4 + Vq_subvec3 + Test_Vq_subvec3 + Q_plsf_3 + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the functions that perform the quantization of LSF + parameters with first order MA prediction and split by 3 vector + quantization (split-VQ). + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "q_plsf.h" +#include "typedef.h" +#include "lsp_lsf.h" +#include "reorder.h" +#include "lsfwt.h" +#include "oscl_mem.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ +#define PAST_RQ_INIT_SIZE 8 + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + /* Codebooks of LSF prediction residual */ + extern const Word16 mean_lsf_3[]; + + extern const Word16 pred_fac_3[]; + + extern const Word16 dico1_lsf_3[]; + extern const Word16 dico2_lsf_3[]; + extern const Word16 dico3_lsf_3[]; + + extern const Word16 mr515_3_lsf[]; + extern const Word16 mr795_1_lsf[]; + + extern const Word16 past_rq_init[]; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Vq_subvec4 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) + dico = pointer to the quantization codebook (Q15) (const Word16) + wf1 = pointer to the first LSF weighting factor (Q13) (Word16) + dico_size = size of quantization codebook (Q0) (Word16) + + Outputs: + buffer pointed to by lsf_r1 contains the selected vector + pOverflow -- pointer to Flag -- Flag set when overflow occurs + + Returns: + index = quantization index (Q0) (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the quantization of a 4-dimensional subvector. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +static Word16 +Vq_subvec4( // o: quantization index, Q0 + Word16 * lsf_r1, // i: 1st LSF residual vector, Q15 + Word16 * dico, // i: quantization codebook, Q15 + Word16 * wf1, // i: 1st LSF weighting factors, Q13 + Word16 dico_size) // i: size of quantization codebook, Q0 +{ + Word16 i, index = 0; + Word16 *p_dico, temp; + Word32 dist_min, dist; + + dist_min = MAX_32; + p_dico = dico; + + for (i = 0; i < dico_size; i++) + { + temp = sub (lsf_r1[0], *p_dico++); + temp = mult (wf1[0], temp); + dist = L_mult (temp, temp); + + temp = sub (lsf_r1[1], *p_dico++); + temp = mult (wf1[1], temp); + dist = L_mac (dist, temp, temp); + + temp = sub (lsf_r1[2], *p_dico++); + temp = mult (wf1[2], temp); + dist = L_mac (dist, temp, temp); + + temp = sub (lsf_r1[3], *p_dico++); + temp = mult (wf1[3], temp); + dist = L_mac (dist, temp, temp); + + + if (L_sub (dist, dist_min) < (Word32) 0) + { + dist_min = dist; + index = i; + } + } + + // Reading the selected vector + + p_dico = &dico[shl (index, 2)]; + lsf_r1[0] = *p_dico++; + lsf_r1[1] = *p_dico++; + lsf_r1[2] = *p_dico++; + lsf_r1[3] = *p_dico; + + return index; + +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 Vq_subvec4( /* o: quantization index, Q0 */ + Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */ + const Word16 * dico, /* i: quantization codebook, Q15 */ + Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */ + Word16 dico_size, /* i: size of quantization codebook, Q0 */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + register Word16 i; + Word16 temp; + const Word16 *p_dico; + Word16 index = 0; + Word32 dist_min; + Word32 dist; + + Word16 lsf_r1_0; + Word16 lsf_r1_1; + Word16 lsf_r1_2; + Word16 lsf_r1_3; + + Word16 wf1_0; + Word16 wf1_1; + Word16 wf1_2; + Word16 wf1_3; + + OSCL_UNUSED_ARG(pOverflow); + + dist_min = MAX_32; + p_dico = dico; + + lsf_r1_0 = lsf_r1[0]; + lsf_r1_1 = lsf_r1[1]; + lsf_r1_2 = lsf_r1[2]; + lsf_r1_3 = lsf_r1[3]; + + wf1_0 = wf1[0]; + wf1_1 = wf1[1]; + wf1_2 = wf1[2]; + wf1_3 = wf1[3]; + + for (i = 0; i < dico_size; i++) + { + temp = lsf_r1_0 - (*p_dico++); + temp = (Word16)((((Word32) wf1_0) * temp) >> 15); + dist = ((Word32) temp) * temp; + + temp = lsf_r1_1 - (*p_dico++); + temp = (Word16)((((Word32) wf1_1) * temp) >> 15); + dist += ((Word32) temp) * temp; + + temp = lsf_r1_2 - (*p_dico++); + temp = (Word16)((((Word32) wf1_2) * temp) >> 15); + dist += ((Word32) temp) * temp; + + temp = lsf_r1_3 - (*p_dico++); + temp = (Word16)((((Word32) wf1_3) * temp) >> 15); + dist += ((Word32) temp) * temp; + + if (dist < dist_min) + { + dist_min = dist; + index = i; + } + } + + /* Reading the selected vector */ + + p_dico = dico + (index << 2); + *lsf_r1++ = *p_dico++; + *lsf_r1++ = *p_dico++; + *lsf_r1++ = *p_dico++; + *lsf_r1 = *p_dico; + + return(index); + +} + +/****************************************************************************/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Test_Vq_subvec4 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) + dico = pointer to the quantization codebook (Q15) (const Word16) + wf1 = pointer to the first LSF weighting factor (Q13) (Word16) + dico_size = size of quantization codebook (Q0) (Word16) + + Outputs: + buffer pointed to by lsf_r1 contains the selected vector + pOverflow -- pointer to Flag -- Flag set when overflow occurs + + Returns: + index = quantization index (Q0) (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calls the static function Vq_subvec4. It is used for testing + purposes only + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + None + +------------------------------------------------------------------------------ + PSEUDO-CODE + + + CALL Vq_subvec4(lsf_r1 = lsf_r1 + dico = dico + wf1 = wf1 + dico_size = dico_size) + MODIFYING(nothing) + RETURNING(index = tst_index4) + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 Test_Vq_subvec4( + Word16 * lsf_r1, + const Word16 * dico, + Word16 * wf1, + Word16 dico_size, + Flag *pOverflow) +{ + Word16 tst_index4 = 0; + + /*------------------------------------------------------------------------ + CALL Vq_subvec4(lsf_r1 = lsf_r1 + dico = dico + wf1 = wf1 + dico_size = dico_size) + MODIFYING(nothing) + RETURNING(index = index) + ------------------------------------------------------------------------*/ + tst_index4 = + Vq_subvec4( + lsf_r1, + dico, + wf1, + dico_size, + pOverflow); + + return(tst_index4); + +} + +/****************************************************************************/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Vq_subvec3 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) + dico = pointer to the quantization codebook (Q15) (const Word16) + wf1 = pointer to the first LSF weighting factor (Q13) (Word16) + dico_size = size of quantization codebook (Q0) (Word16) + use_half = flag to indicate use of every second entry in the + codebook (Flag) + + Outputs: + buffer pointed to by lsf_r1 contains the selected vector + pOverflow -- pointer to Flag -- Flag set when overflow occurs + + Returns: + index = quantization index (Q0) (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the quantization of a 3 dimensional subvector. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +static Word16 +Vq_subvec3( // o: quantization index, Q0 + Word16 * lsf_r1, // i: 1st LSF residual vector, Q15 + Word16 * dico, // i: quantization codebook, Q15 + Word16 * wf1, // i: 1st LSF weighting factors, Q13 + Word16 dico_size, // i: size of quantization codebook, Q0 + Flag use_half) // i: use every second entry in codebook +{ + Word16 i, index = 0; + Word16 *p_dico, temp; + Word32 dist_min, dist; + + dist_min = MAX_32; + p_dico = dico; + + if (use_half == 0) { + for (i = 0; i < dico_size; i++) + { + temp = sub(lsf_r1[0], *p_dico++); + temp = mult(wf1[0], temp); + dist = L_mult(temp, temp); + + temp = sub(lsf_r1[1], *p_dico++); + temp = mult(wf1[1], temp); + dist = L_mac(dist, temp, temp); + + temp = sub(lsf_r1[2], *p_dico++); + temp = mult(wf1[2], temp); + dist = L_mac(dist, temp, temp); + + if (L_sub(dist, dist_min) < (Word32) 0) { + dist_min = dist; + index = i; + } + } + p_dico = &dico[add(index, add(index, index))]; + } + else + { + for (i = 0; i < dico_size; i++) + { + temp = sub(lsf_r1[0], *p_dico++); + temp = mult(wf1[0], temp); + dist = L_mult(temp, temp); + + temp = sub(lsf_r1[1], *p_dico++); + temp = mult(wf1[1], temp); + dist = L_mac(dist, temp, temp); + + temp = sub(lsf_r1[2], *p_dico++); + temp = mult(wf1[2], temp); + dist = L_mac(dist, temp, temp); + + if (L_sub(dist, dist_min) < (Word32) 0) + { + dist_min = dist; + index = i; + } + p_dico = p_dico + 3; add(0,0); + } + p_dico = &dico[shl(add(index, add(index, index)),1)]; + } + + + // Reading the selected vector + lsf_r1[0] = *p_dico++; + lsf_r1[1] = *p_dico++; + lsf_r1[2] = *p_dico++; + + return index; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 Vq_subvec3( /* o: quantization index, Q0 */ + Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */ + const Word16 * dico, /* i: quantization codebook, Q15 */ + Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */ + Word16 dico_size, /* i: size of quantization codebook, Q0 */ + Flag use_half, /* i: use every second entry in codebook */ + Flag *pOverflow) /* o : Flag set when overflow occurs */ +{ + register Word16 i; + Word16 temp; + + const Word16 *p_dico; + + Word16 p_dico_index = 0; + Word16 index = 0; + + Word32 dist_min; + Word32 dist; + + Word16 lsf_r1_0; + Word16 lsf_r1_1; + Word16 lsf_r1_2; + + Word16 wf1_0; + Word16 wf1_1; + Word16 wf1_2; + + OSCL_UNUSED_ARG(pOverflow); + + dist_min = MAX_32; + p_dico = dico; + + lsf_r1_0 = lsf_r1[0]; + lsf_r1_1 = lsf_r1[1]; + lsf_r1_2 = lsf_r1[2]; + + wf1_0 = wf1[0]; + wf1_1 = wf1[1]; + wf1_2 = wf1[2]; + + if (use_half != 0) + { + p_dico_index = 3; + } + + for (i = 0; i < dico_size; i++) + { + temp = lsf_r1_0 - (*p_dico++); + temp = (Word16)((((Word32) wf1_0) * temp) >> 15); + dist = ((Word32) temp) * temp; + + temp = lsf_r1_1 - (*p_dico++); + temp = (Word16)((((Word32) wf1_1) * temp) >> 15); + dist += ((Word32) temp) * temp; + + temp = lsf_r1_2 - (*p_dico++); + temp = (Word16)((((Word32) wf1_2) * temp) >> 15); + dist += ((Word32) temp) * temp; + + if (dist < dist_min) + { + dist_min = dist; + index = i; + } + + p_dico = p_dico + p_dico_index; + } + + p_dico = dico + (3 * index); + + if (use_half != 0) + { + p_dico += (3 * index); + } + + /* Reading the selected vector */ + *lsf_r1++ = *p_dico++; + *lsf_r1++ = *p_dico++; + *lsf_r1 = *p_dico; + + return(index); +} + +/****************************************************************************/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Test_Vq_subvec3 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) + dico = pointer to the quantization codebook (Q15) (const Word16) + wf1 = pointer to the first LSF weighting factor (Q13) (Word16) + dico_size = size of quantization codebook (Q0) (Word16) + use_half = flag to indicate use of every second entry in the + codebook (Flag) + + Outputs: + buffer pointed to by lsf_r1 contains the selected vector + pOverflow -- pointer to Flag -- Flag set when overflow occurs + + Returns: + index = quantization index (Q0) (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calls the static function Vq_subvec3. It is used for testing + purposes only + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + None + +------------------------------------------------------------------------------ + PSEUDO-CODE + + CALL Vq_subvec3(lsf_r1 = lsf_r1 + dico = dico + wf1 = wf1 + dico_size = dico_size + use_half = use_half) + MODIFYING(nothing) + RETURNING(index = tst_index3) + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 Test_Vq_subvec3( + Word16 * lsf_r1, + const Word16 * dico, + Word16 * wf1, + Word16 dico_size, + Flag use_half, + Flag *pOverflow) +{ + Word16 tst_index3 = 0; + + /*------------------------------------------------------------------------ + CALL Vq_subvec3(lsf_r1 = lsf_r1 + dico = dico + wf1 = wf1 + dico_size = dico_size + use_half = use_half) + MODIFYING(nothing) + RETURNING(index = index) + ------------------------------------------------------------------------*/ + tst_index3 = + Vq_subvec3( + lsf_r1, + dico, + wf1, + dico_size, + use_half, + pOverflow); + + return(tst_index3); + +} + +/****************************************************************************/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Q_plsf_3 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st = pointer to structures of type Q_plsfState (Q_plsfState) + mode = coder mode (enum) + lsp1 = pointer to the first LSP vector (Word16) + lsp1_q = pointer to the quantized first LSP vector (Word16) + indice = pointer to the quantization indices of 3 vectors (Word16) + pred_init_i = pointer to the index of the initial value for + MA prediction in DTX mode (Word16) + + Outputs: + lsp1_q points to a vector containing the new quantized LSPs + indice points to the new quantization indices of 3 vectors + pred_init_i points to the new initial index for MA prediction + in DTX mode + past_rq field of structure pointed to by st contains the current + quantized LSF parameters + pOverflow -- pointer to Flag -- Flag set when overflow occurs + + Returns: + None + + Global Variables Used: + pred_fac = table containing prediction factors (const Word16) + dico1_lsf = quantization table for split_MQ of 2 sets of LSFs + in a 20 ms frame (const Word16) + dico2_lsf = quantization table for split_MQ of 2 sets of LSFs + in a 20 ms frame (const Word16) + dico3_lsf = quantization table for split_MQ of 2 sets of LSFs + in a 20 ms frame (const Word16) + mr515_3_lsf = third codebook for MR475 and MR515 modes (const Word16) + mr795_1_lsf = first codebook for MR795 mode (const Word16) + mean_lsf = table of mean LSFs (const Word16) + past_rq_init = initalization table for MA predictor in DTX mode + (const Word16) + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs quantization of LSF parameters with 1st order MA + prediction and split by 3 vector quantization (split-VQ) + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Q_plsf_3( + Q_plsfState *st, // i/o: state struct + enum Mode mode, // i : coder mode + Word16 *lsp1, // i : 1st LSP vector Q15 + Word16 *lsp1_q, // o : quantized 1st LSP vector Q15 + Word16 *indice, // o : quantization indices of 3 vectors Q0 + Word16 *pred_init_i // o : init index for MA prediction in DTX mode +) +{ + Word16 i, j; + Word16 lsf1[M], wf1[M], lsf_p[M], lsf_r1[M]; + Word16 lsf1_q[M]; + + Word32 L_pred_init_err; + Word32 L_min_pred_init_err; + Word16 temp_r1[M]; + Word16 temp_p[M]; + + // convert LSFs to normalize frequency domain 0..16384 + + Lsp_lsf(lsp1, lsf1, M); + + // compute LSF weighting factors (Q13) + + Lsf_wt(lsf1, wf1); + + // Compute predicted LSF and prediction error + if (test(), sub(mode, MRDTX) != 0) + { + for (i = 0; i < M; i++) + { + lsf_p[i] = add(mean_lsf[i], + mult(st->past_rq[i], + pred_fac[i])); + lsf_r1[i] = sub(lsf1[i], lsf_p[i]); + } + } + else + { + // DTX mode, search the init vector that yields + // lowest prediction resuidual energy + *pred_init_i = 0; + L_min_pred_init_err = 0x7fffffff; // 2^31 - 1 + for (j = 0; j < PAST_RQ_INIT_SIZE; j++) + { + L_pred_init_err = 0; + for (i = 0; i < M; i++) + { + temp_p[i] = add(mean_lsf[i], past_rq_init[j*M+i]); + temp_r1[i] = sub(lsf1[i],temp_p[i]); + L_pred_init_err = L_mac(L_pred_init_err, temp_r1[i], temp_r1[i]); + } // next i + + + if (L_sub(L_pred_init_err, L_min_pred_init_err) < (Word32) 0) + { + L_min_pred_init_err = L_pred_init_err; + Copy(temp_r1, lsf_r1, M); + Copy(temp_p, lsf_p, M); + // Set zerom + Copy(&past_rq_init[j*M], st->past_rq, M); + *pred_init_i = j; + } // endif + } // next j + } // endif MRDTX + + //---- Split-VQ of prediction error ---- + if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0) + { // MR475, MR515 + + + indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0); + + indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE/2, 1); + + indice[2] = Vq_subvec4(&lsf_r1[6], mr515_3_lsf, &wf1[6], MR515_3_SIZE); + + } + else if (sub (mode, MR795) == 0) + { // MR795 + + + indice[0] = Vq_subvec3(&lsf_r1[0], mr795_1_lsf, &wf1[0], MR795_1_SIZE, 0); + + indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0); + + indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE); + + } + else + { // MR59, MR67, MR74, MR102 , MRDTX + + + indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0); + + indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0); + + indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE); + + } + + + // Compute quantized LSFs and update the past quantized residual + + for (i = 0; i < M; i++) + { + lsf1_q[i] = add(lsf_r1[i], lsf_p[i]); + st->past_rq[i] = lsf_r1[i]; + } + + // verification that LSFs has mimimum distance of LSF_GAP Hz + + Reorder_lsf(lsf1_q, LSF_GAP, M); + + // convert LSFs to the cosine domain + + Lsf_lsp(lsf1_q, lsp1_q, M); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Q_plsf_3( + Q_plsfState *st, /* i/o: state struct */ + enum Mode mode, /* i : coder mode */ + Word16 *lsp1, /* i : 1st LSP vector Q15 */ + Word16 *lsp1_q, /* o : quantized 1st LSP vector Q15 */ + Word16 *indice, /* o : quantization indices of 3 vectors Q0 */ + Word16 *pred_init_i,/* o : init index for MA prediction in DTX mode */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + register Word16 i, j; + Word16 lsf1[M]; + Word16 wf1[M]; + Word16 lsf_p[M]; + Word16 lsf_r1[M]; + Word16 lsf1_q[M]; + + Word32 L_pred_init_err; + Word32 L_min_pred_init_err; + Word32 L_temp; + Word16 temp_r1[M]; + Word16 temp_p[M]; + Word16 temp; + + /* convert LSFs to normalize frequency domain 0..16384 */ + + Lsp_lsf( + lsp1, + lsf1, + M, + pOverflow); + + /* compute LSF weighting factors (Q13) */ + + Lsf_wt( + lsf1, + wf1, + pOverflow); + + /* Compute predicted LSF and prediction error */ + if (mode != MRDTX) + { + for (i = 0; i < M; i++) + { + temp = (Word16)((((Word32) st->past_rq[i]) * + (*(pred_fac_3 + i))) >> 15); + + *(lsf_p + i) = *(mean_lsf_3 + i) + temp; + + *(lsf_r1 + i) = *(lsf1 + i) - *(lsf_p + i); + } + } + else + { + /* DTX mode, search the init vector that yields */ + /* lowest prediction resuidual energy */ + *pred_init_i = 0; + L_min_pred_init_err = 0x7fffffff; /* 2^31 - 1 */ + + for (j = 0; j < PAST_RQ_INIT_SIZE; j++) + { + L_pred_init_err = 0; + for (i = 0; i < M; i++) + { + *(temp_p + i) = *(mean_lsf_3 + i) + *(past_rq_init + j * M + i); + + *(temp_r1 + i) = *(lsf1 + i) - *(temp_p + i); + + L_temp = ((Word32) * (temp_r1 + i)) * *(temp_r1 + i); + + L_pred_init_err = L_pred_init_err + (L_temp << 1); + + } /* next i */ + + + if (L_pred_init_err < L_min_pred_init_err) + { + L_min_pred_init_err = L_pred_init_err; + + oscl_memcpy( + lsf_r1, + temp_r1, + M*sizeof(Word16)); + + oscl_memcpy( + lsf_p, + temp_p, + M*sizeof(Word16)); + + /* Set zerom */ + oscl_memcpy( + st->past_rq, + &past_rq_init[j*M], + M*sizeof(Word16)); + + *pred_init_i = j; + + } /* endif */ + } /* next j */ + } /* endif MRDTX */ + + /*---- Split-VQ of prediction error ----*/ + if ((mode == MR475) || (mode == MR515)) + { /* MR475, MR515 */ + + *indice = + Vq_subvec3( + lsf_r1, + dico1_lsf_3, + wf1, + DICO1_SIZE, + 0, + pOverflow); + + *(indice + 1) = + Vq_subvec3( + lsf_r1 + 3, + dico2_lsf_3, + wf1 + 3, + DICO2_SIZE / 2, + 1, + pOverflow); + + *(indice + 2) = + Vq_subvec4( + lsf_r1 + 6, + mr515_3_lsf, + wf1 + 6, + MR515_3_SIZE, + pOverflow); + + } + else if (mode == MR795) + { /* MR795 */ + + *indice = + Vq_subvec3( + lsf_r1, + mr795_1_lsf, + wf1, + MR795_1_SIZE, + 0, + pOverflow); + + *(indice + 1) = + Vq_subvec3( + lsf_r1 + 3, + dico2_lsf_3, + wf1 + 3, + DICO2_SIZE, + 0, + pOverflow); + + *(indice + 2) = + Vq_subvec4( + lsf_r1 + 6, + dico3_lsf_3, + wf1 + 6, + DICO3_SIZE, + pOverflow); + + } + else + { /* MR59, MR67, MR74, MR102 , MRDTX */ + + *indice = + Vq_subvec3( + lsf_r1, + dico1_lsf_3, + wf1, + DICO1_SIZE, + 0, + pOverflow); + + *(indice + 1) = + Vq_subvec3( + lsf_r1 + 3, + dico2_lsf_3, + wf1 + 3, + DICO2_SIZE, + 0, + pOverflow); + + *(indice + 2) = + Vq_subvec4( + lsf_r1 + 6, + dico3_lsf_3, + wf1 + 6, + DICO3_SIZE, + pOverflow); + + } + + + /* Compute quantized LSFs and update the past quantized residual */ + + for (i = 0; i < M; i++) + { + *(lsf1_q + i) = *(lsf_r1 + i) + *(lsf_p + i); + st->past_rq[i] = *(lsf_r1 + i); + } + + /* verification that LSFs has mimimum distance of LSF_GAP Hz */ + + Reorder_lsf( + lsf1_q, + LSF_GAP, + M, + pOverflow); + + /* convert LSFs to the cosine domain */ + + Lsf_lsp( + lsf1_q, + lsp1_q, + M, + pOverflow); + + return; + +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3_tbl.cpp new file mode 100644 index 0000000..8714fcd --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_3_tbl.cpp @@ -0,0 +1,2083 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf_3_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "q_plsf_3_tbl.h" + +/*--------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : q_plsf_3.tab +* Purpose : Table for routine LSF VQ. +* $Id $ +* +******************************************************************************** +*/ + + +/* initalization table for MA predictor in dtx mode */ +const Word16 past_rq_init[80] = +{ + -258, -318, -439, -634, -656, -773, -711, -502, -268, -193, + -2, 125, 122, -39, -9, 105, 129, 283, 372, 575, + -277, -324, -197, -487, -445, -362, -292, -27, 177, 543, + 342, 517, 516, 130, 27, -104, -120, -140, -74, -56, + -564, -943, -1520, -965, -814, -526, -322, -2, 159, 657, + -312, -284, -386, -597, -493, -526, -418, -229, 105, 449, + -557, -870, -1075, -919, -950, -752, -709, -316, 62, 486, + -314, -191, -203, -330, -160, -103, -51, 131, 338, 515 +}; + + +const Word16 mean_lsf_3[10] = +{ + 1546, + 2272, + 3778, + 5488, + 6972, + 8382, + 10047, + 11229, + 12766, + 13714 +}; + + +const Word16 pred_fac_3[10] = +{ + 9556, + 10769, + 12571, + 13292, + 14381, + 11651, + 10588, + 9767, + 8593, + 6484 +}; + + + +/* first codebook from IS641 */ + +const Word16 dico1_lsf_3[DICO1_SIZE*3] = +{ + 6, 82, -131, + 154, -56, -735, + 183, -65, -265, + 9, -210, -361, + 113, 718, 1817, + 1010, 1214, 1573, + 857, 1333, 2276, + 827, 1568, 1933, + 717, 1989, 2206, + 838, 1172, 1823, + 721, 1000, 2154, + 286, 476, 1509, + -247, -531, 230, + 147, -82, 569, + 26, -177, -944, + -27, -273, 692, + -164, -264, -183, + 224, 790, 1039, + 899, 946, 601, + 485, 771, 1150, + 524, 677, 903, + -140, 375, 778, + 410, 676, 429, + 301, 530, 1009, + 719, 646, 38, + 226, 367, 40, + 145, -45, -505, + 290, 121, -121, + 302, 127, 166, + -124, -383, -956, + -358, -455, -977, + 715, 878, 894, + 978, 923, 211, + 477, 272, 64, + 188, -78, 17, + -143, -65, 38, + 643, 586, 621, + -134, -426, -651, + 347, 545, 2820, + 1188, 2726, 2442, + 142, -80, 1735, + 283, 130, 461, + -262, -399, -1145, + -411, 155, 430, + 329, 375, 779, + 53, -226, -139, + -129, -236, 1682, + 285, 744, 1327, + 738, 697, 1664, + 312, 409, 266, + 325, 720, 135, + 1, 221, 453, + 8, 203, 145, + 299, 640, 760, + 29, 468, 638, + 103, 429, 379, + 420, 954, 932, + 1326, 1210, 1258, + 704, 1012, 1152, + -166, -444, -266, + -316, -130, -376, + 191, 1151, 1904, + -240, -543, -1260, + -112, 268, 1207, + 70, 1062, 1583, + 278, 1360, 1574, + -258, -272, -768, + 19, 563, 2240, + -3, -265, 135, + -295, -591, -388, + 140, 354, -206, + -260, -504, -795, + -433, -718, -1319, + 109, 331, 962, + -429, -87, 652, + -296, 426, 1019, + -239, 775, 851, + 489, 1334, 1073, + -334, -332, 25, + 543, 1206, 1807, + 326, 61, 727, + 578, 849, 1405, + -208, -277, 329, + -152, 64, 669, + -434, -678, -727, + -454, -71, 251, + 605, 480, 254, + -482, 11, 996, + -289, 395, 486, + 722, 1049, 1440, + -30, -316, -786, + -106, -115, -619, + 861, 1474, 1412, + 1055, 1366, 1184, + 812, 1237, 925, + 42, -251, -576, + 342, 141, -454, + -168, -80, 1359, + -342, -656, -1763, + 100, 821, 725, + 990, 747, 800, + 332, 440, 568, + 663, 379, 852, + 112, 165, -369, + 597, 910, 282, + -8, 834, 1281, + -352, 572, 695, + 462, 2246, 1806, + 345, 190, 1374, + 416, 915, 2166, + 168, -82, 280, + -516, -446, 840, + 47, 533, 44, + -362, -711, -1143, + 22, 193, 1472, + -85, 233, 1813, + -62, 579, 1504, + 550, 944, 1749, + 723, 650, 1148, + 972, 884, 1395, + -425, 643, 0, + 1000, 952, 1098, + 249, 1446, 672, + -334, -87, 2172, + -554, 1882, 2672, + 140, 1826, 1853, + 920, 1749, 2590, + 1076, 1933, 2038, + -137, -443, -1555, + 1269, 1174, 468, + -493, -122, 1521, + -451, 1033, 1214, + 482, 1695, 1118, + 815, 649, 384, + -446, -692, 107, + -319, -605, -118, + -207, -505, 525, + -468, -12, 2736, + 75, 1934, 1305, + 880, 2358, 2267, + 1285, 1575, 2004, + -48, -304, -1186, + -435, -461, -251, + -366, -404, -547, + -289, -605, -597, + -538, -810, -165, + -120, 3, 356, + 639, 1241, 1502, + 96, 177, 750, + -435, -585, -1174, + -356, 109, -79, + -485, 288, 2005, + 9, 1116, 731, + 880, 2134, 946, + -265, 1585, 1065, + 1157, 1210, 843, + -498, -668, 431, + 374, 321, -229, + 1440, 2101, 1381, + 449, 461, 1155, + -105, 39, -384, + -263, 367, 182, + -371, -660, 773, + -188, 1151, 971, + 1333, 1632, 1435, + 774, 1267, 1221, + -482, -832, -1489, + -237, -210, 860, + 890, 1615, 1064, + 472, 1062, 1192, + 185, 1077, 989, + -568, -992, -1704, + -449, -902, -2043, + -142, -377, -458, + -210, -554, -1029, + -11, 1133, 2265, + -329, -675, -893, + -250, 657, 1187, + 519, 1510, 1779, + 520, 539, 1403, + 527, 1421, 1302, + -563, -871, -1248, + -147, -463, 879, + -76, 2334, 2840, + 563, 2573, 2385, + 632, 1926, 2920, + 719, 2023, 1840, + -545, -723, 1108, + 129, -125, 884, + 1417, 1632, 925, + -94, 1566, 1751, + -341, 1533, 1551, + 591, 395, -274, + -76, 981, 2831, + 153, 2985, 1844, + 1032, 2565, 2749, + 1508, 2832, 1879, + 791, 1199, 538, + -190, -453, 1489, + -278, -548, 1158, + -245, 1941, 2044, + 1024, 1560, 1650, + 512, 253, 466, + -62, -323, 1151, + -473, -376, 507, + -433, 1380, 2162, + 899, 1943, 1445, + 134, 704, 440, + 460, 525, -28, + -450, 279, 1338, + 0, 971, 252, + -445, -627, -991, + -348, -602, -1424, + 398, 712, 1656, + -107, 314, -178, + 93, 2226, 2238, + 518, 849, 656, + -462, -711, -447, + 174, -34, 1191, + -119, 42, 1005, + -372, 274, 758, + 1036, 2352, 1838, + 675, 1724, 1498, + 430, 1286, 2133, + -129, -439, 0, + -373, 800, 2144, + 6, 1587, 2478, + 478, 596, 2128, + -428, -736, 1505, + 385, 178, 980, + 139, 449, 1225, + -526, -842, -982, + 145, 1554, 1242, + 623, 1448, 656, + 349, 1016, 1482, + 31, -280, 415, + -316, 724, 1641, + 360, 1058, 556, + -436, -358, 1201, + -355, 1123, 1939, + 401, 1584, 2248, + -527, -1012, 355, + 233, 238, 2233, + -550, -897, -639, + -365, -501, 1957, + 389, 1860, 1621, + 162, 1132, 1264, + -237, 1174, 1390, + -640, -411, 116, + -228, 1694, 2298, + 1639, 2186, 2267, + 562, 1273, 2658, + 323, 338, 1774, + 578, 1107, 852, + 22, 594, 934, + -143, 718, 446 +}; + + +/* second codebook from IS641 */ + +const Word16 dico2_lsf_3[DICO2_SIZE*3] = +{ + 50, 71, -9, + -338, -698, -1407, + 102, -138, -820, + -310, -469, -1147, + 414, 67, -267, + 1060, 814, 1441, + 1548, 1360, 1272, + 1754, 1895, 1661, + 2019, 2133, 1820, + 1808, 2318, 1845, + 644, -93, 454, + 858, 329, -136, + 489, -258, -128, + -198, -745, -41, + -52, -265, -985, + 346, 137, 479, + -1741, -748, -684, + -1163, -1725, -367, + -895, -1145, -784, + -488, -946, -968, + -85, -390, -725, + 215, -340, -171, + 1020, 916, 1969, + 564, 179, 746, + 662, 977, 1734, + 887, 622, 914, + 939, 856, 1165, + 309, 688, 803, + 917, 161, 570, + 118, -20, -283, + -816, -42, 204, + -1228, -325, -462, + -963, -202, -143, + -988, -484, -361, + -702, -978, -477, + -302, -790, -1188, + -100, -786, -1088, + -1054, -947, -1684, + -202, -843, -782, + -1039, -1378, -901, + -624, -110, -85, + 356, 213, -10, + -493, 364, 774, + 425, 822, 479, + -83, 557, 520, + -992, -1560, -572, + -603, -741, -26, + -502, -638, -903, + 209, 306, 147, + -316, -593, -596, + -85, -211, -225, + -918, -529, 117, + 233, -439, -738, + 1101, 751, 633, + 1457, 1716, 1511, + 1765, 1457, 910, + 1122, 1156, 849, + 1354, 868, 470, + -871, -1150, -1796, + -871, -861, -992, + -118, 155, 212, + -1051, -849, -606, + -1117, -1849, -2750, + -1019, -1427, -1869, + 370, -184, -414, + 959, 493, 104, + 958, 1039, 543, + 154, 653, 201, + 1249, 507, 150, + 663, 503, 230, + 623, 777, 675, + 659, 88, -110, + 843, 244, 224, + 382, 541, 302, + 724, 433, 666, + 1166, 734, 341, + -138, 20, -397, + -1183, -424, -46, + -321, -352, -124, + 1333, 1021, 1080, + 262, 366, 723, + 922, 283, -551, + 31, -636, -611, + -689, -697, -415, + -952, -779, -201, + -1329, -598, -359, + -953, -1285, 166, + 493, 305, 221, + 846, 703, 610, + 840, 936, 774, + -723, -1324, -1261, + -357, -1025, -1388, + -1096, -1376, -365, + -1416, -1881, -608, + -1798, -1727, -674, + -545, -1173, -703, + 678, 786, 148, + -123, 696, 1288, + 644, 350, -10, + 414, 614, 15, + 137, 344, -211, + -814, -1512, -819, + -391, -930, -588, + 47, -591, -898, + -909, -1097, -163, + -1272, -1167, -157, + -1464, -1525, -389, + -1274, -1188, -624, + 671, 213, 454, + 124, -274, -525, + -729, -496, -152, + -1344, 122, 135, + -2905, -589, -394, + -1728, 441, -50, + 1476, 904, 787, + 316, 236, -440, + -347, 217, 413, + -911, -917, 121, + -455, -932, 202, + -92, -465, -375, + 488, 390, 474, + 876, 729, 316, + -1815, -1312, -669, + 87, 962, 432, + 563, -249, -1058, + 250, 285, 1105, + 1141, 427, 696, + -1038, -1664, -1582, + -948, 346, 160, + -309, -272, -858, + 670, 624, 1250, + -944, -408, -666, + -606, -320, -384, + -492, 230, 65, + 334, -50, -16, + -16, -690, -1397, + 1791, 1716, 1399, + 2478, 2063, 1404, + 1245, 1471, 1426, + -382, -1037, -2, + 173, -398, 1145, + 1491, 2024, 1801, + 772, 1274, 1506, + 1429, 1735, 2001, + 1079, 1218, 1273, + -1154, -1851, -1329, + -808, -1133, -1096, + -451, -1033, -1722, + 65, 578, -84, + -1476, -2434, -1778, + -765, -1366, -494, + -218, -594, -931, + 337, -236, 562, + 2357, 2662, 1938, + 1489, 1276, 874, + 189, 358, 374, + -1519, -2281, -2346, + -967, -1271, -2095, + -628, -1188, -1542, + 1661, 1043, 546, + 565, 1061, 732, + -64, -836, -434, + -436, -96, 203, + 1078, 1216, 1636, + 907, 1534, 986, + 326, 965, 845, + 142, -84, 197, + 470, 2379, 1570, + 1133, 470, 1214, + 395, 1376, 1200, + 1125, 1042, 348, + -543, -1234, -376, + -215, -181, 481, + -1947, -1621, -210, + -750, -1185, 390, + 29, -399, 27, + 820, 1236, 755, + 695, 979, 409, + -174, 1197, 1035, + 912, 1356, 1846, + -992, -1437, 484, + -1485, -1700, 208, + -412, 1204, 1432, + -271, 896, 1144, + -416, 1777, 1434, + -1696, -2644, -204, + -1789, -1551, 1033, + -1656, -1559, 1303, + -1253, -1589, 1081, + -669, -1095, -66, + -682, 320, -345, + 659, 305, 1069, + -1292, -804, -19, + -1635, -1291, 29, + -1683, -497, 71, + -287, -7, -100, + -494, -962, -237, + 852, 1881, 1740, + -1217, -1387, 227, + -660, 302, 373, + 96, 1087, 1257, + -1074, -1669, 160, + 485, 2076, 1798, + -934, -220, 552, + -596, -612, 237, + 336, 1720, 879, + 643, 629, 434, + 1267, 522, 1633, + 15, 244, -441, + 1475, 717, 184, + 1819, 1590, 1709, + 988, 261, 937, + 2093, 2345, 1520, + 2139, 1858, 1606, + -577, -579, -1203, + -956, 135, -488, + -464, 51, -338, + -629, -348, -723, + 1146, 2073, 1442, + 2192, 1466, 911, + -1444, -1572, -2278, + 1400, 710, 1297, + 1335, 633, 928, + 1434, 2194, 2594, + 2422, 2204, 1881, + 982, 2242, 1854, + 380, 792, 1145, + -63, -539, 414, + -252, -964, -314, + -1261, -683, -780, + -831, -526, -1005, + -1666, -1135, -424, + -1611, -452, -299, + 1268, 1048, 642, + 1147, 853, 856, + -675, -336, 139, + 2268, 1343, 1418, + 29, 768, 797, + -1224, 423, 564, + -1318, -1082, 245, + -1302, -812, 573, + -1298, -1617, 646, + -968, 834, 723, + 993, 1652, 2027, + -191, -817, 432, + 662, 60, 198, + 626, 997, 1330, + 1648, 1963, 1289, + -1597, -93, -45, + -1088, 37, -84, + 1653, 2607, 2337, + 1065, 2040, 2377, + 1139, 2326, 2118, + 859, 357, 1510, + 664, 1227, 1099, + 479, 1360, 912, + 1897, 1754, 2019, + 1168, 1909, 1784, + 399, 34, 256, + -593, -304, -1053, + 547, 1694, 1407, + 647, -99, -341, + 1492, 1647, 1190, + 38, -644, -212, + 395, 846, 222, + -704, -765, -716, + -724, -1964, -2804, + -150, 291, -82, + 1233, 1459, 1007, + -140, -155, 153, + 439, 297, 1568, + -1529, -410, -636, + 1536, 455, -237, + -1328, -139, -260, + 531, 554, 868, + 269, 1264, 606, + -233, 883, 463, + 742, 600, -120, + -73, 421, 212, + -439, -58, 804, + -1286, -1241, 728, + 294, -490, 50, + -591, -905, -1254, + 42, -687, 147, + -25, 273, 596, + -311, 1213, 601, + -754, 849, 584, + 429, 607, 587, + -602, -166, 461, + -796, -823, 777, + 1380, 910, 1755, + 119, 1417, 972, + -219, -880, -1596, + -1049, -1010, 438, + -713, -1379, 78, + 0, -447, -1179, + -1136, -1319, -1573, + 2248, 1767, 1309, + 946, 1583, 1432, + 1150, 482, 436, + -469, -1108, 618, + -447, -966, 1088, + -1252, -1515, -114, + -1104, -2008, -579, + 210, 613, 497, + -1975, -1437, 642, + -1269, -856, 1011, + -1646, -1185, 1063, + -1555, -672, 1204, + -1692, -1114, 623, + -979, -1326, -1277, + 539, -147, 894, + -1354, -897, -434, + 888, 475, 428, + 153, -384, 338, + -1492, -511, 359, + -974, -1115, -470, + 105, -550, 677, + -937, -1145, 877, + 380, -260, 210, + 1685, 924, 1256, + 1775, 1190, 1095, + 1419, 631, 533, + 627, 299, -347, + -411, -534, 647, + -650, 29, -595, + -378, -1367, 1563, + 1402, 1121, 1465, + 1089, 1410, 648, + -2096, -1090, -6, + 311, -194, -869, + -639, -831, 416, + -1162, -1224, 1349, + -1247, -941, 1813, + -2193, -1987, 453, + -619, -1367, -956, + -1606, -1972, -1507, + -1175, -1057, -1104, + -377, 601, 201, + 1876, 825, 374, + -430, -1323, 29, + -1397, -1249, -1331, + -1007, -1504, 960, + -1401, -2009, 197, + -1379, -1949, -236, + -1077, 123, 422, + 615, 1269, 546, + -306, 1526, 904, + 1194, 1788, 1177, + -626, -884, -1526, + 199, 766, 1504, + -1065, 862, 197, + -1034, -1773, -887, + -800, 145, 599, + -1134, -519, 626, + -1205, -1926, 500, + -910, -1041, -1395, + -1476, -1567, -969, + -523, 842, 34, + 1794, 646, 862, + -1207, -1888, -1002, + -78, -9, -672, + 1044, 759, 80, + -600, 1139, 1019, + 57, 2000, 1422, + -833, 1414, 1121, + -1202, 1630, 1260, + -461, 1420, 1244, + 1537, 975, 253, + -283, 324, -359, + 599, -195, 106, + 588, 62, -587, + -757, 645, 205, + 51, 1201, 758, + -1209, 673, -390, + -624, 1581, 941, + -151, 1023, 735, + 2820, 1301, 690, + -302, 524, -99, + -900, -1588, -1189, + 1084, 251, 238, + 2014, 1792, 1010, + 1245, 1633, 1741, + -1227, -1540, -1208, + -621, 456, -109, + 40, -65, 788, + -805, -699, -1350, + -583, 904, 832, + -801, 532, 594, + 1972, 1408, 1351, + -1177, -1880, -2114, + -773, 568, 948, + -1015, 1079, 1260, + -1111, 482, -130, + 1778, 1044, 780, + -1491, 245, 912, + -316, -1141, -917, + -536, -1442, -2346, + -785, -1546, -1988, + -2003, 257, 909, + -1849, -633, -1209, + -1538, -1918, -1054, + 1606, 2239, 1576, + -567, -1500, -1544, + -1279, 195, 1369, + -817, 293, 1219, + -525, 630, 1197, + -1698, -2425, -1840, + -303, 731, 747, + -1169, -251, 269, + -950, -75, 1684, + -1182, -453, 1005, + -1599, 585, 378, + -2075, -571, -427, + -529, -1159, -1171, + -283, -205, -564, + -796, 1246, 717, + 2277, 927, 539, + -454, 559, 440, + -717, 1460, 1615, + -1030, 1052, 1610, + -1169, -138, 847, + 226, 39, -612, + -1251, -106, -729, + -651, 968, 1302, + -714, -636, 1727, + 353, 1069, 410, + -798, -156, 1099, + -574, 918, 446, + -1310, 1012, 466, + 1408, 1591, 765, + 1429, 1380, 1757, + 1949, 1956, 2378, + 1578, 2047, 2148, + 916, 98, -7, + 1893, 1418, 2141, + 348, 1405, 1579, + 152, 1134, 1801, + -267, 154, 1395, + -1166, 469, 1054, + -1142, -405, -1073, + -1341, -2264, -1581, + -364, 869, 1706, + -1162, 549, 1550, + -1225, -1932, -1666, + -1485, -1977, -2055, + -1727, -906, -98, + -1897, 233, 1492, + 892, 108, -331, + -1728, -1170, -1700, + -1060, 1980, 1790, + -1070, -1741, -1909, + -11, 1539, 1317, + -1600, 94, 497, + 421, 443, -197, + -1578, -349, -994, + -599, -539, 1140, + -965, -1419, -129, + -1341, 175, -447, + -375, 1311, 2055, + -371, -650, -307, + -1073, 605, 365, + -2057, -113, 430, + 652, 914, 967, + -1012, -1586, -2323, + 1505, 1248, 559, + 262, -486, -401, + -1727, 1342, 1546, + 50, 56, 432, + -330, 119, -604, + -1517, -1080, -810, + 946, 1127, 1055, + -1400, -1703, -1712, + -1270, -704, -1317, + 807, 1821, 1143, + 2760, 1606, 2171, + 1120, 409, -150, + -147, 404, 959, + 2439, 1911, 2189, + -906, -141, -866, + -904, -142, -458, + -557, -708, -1679, + -830, -1431, -1583, + -1842, -1346, -1086, + -1604, -272, 915, + -1196, 772, 1056, + -638, -1234, -1897, + -500, -81, -822, + -1289, -1613, -735, + -117, 785, 168, + -1090, 1133, 922, + -1096, -746, 1384, + 287, -547, -1063, + -1376, -2201, -1204, + -2176, -1570, -1757, + -1511, -2241, -771, + -1737, 1099, 830, + -1588, 724, 1243, + -1542, 693, 805, + -1690, -240, 1665, + -1700, -4, -668, + 2149, 816, 1042, + -818, -1841, 22, + -764, -507, 449, + -1151, -617, 289, + -843, -1596, -240, + 498, -234, -657, + -752, 480, 1678, + -319, -481, 193, + -811, 171, -119, + -2128, -202, -848, + 1717, 1140, 1700 +}; + + +/* third codebook from IS641 */ + +const Word16 dico3_lsf_3[DICO3_SIZE*4] = +{ + 67, -17, 66, -12, + -1690, -581, -104, -272, + -1076, -1186, -1845, -376, + -1140, -926, -420, -58, + -259, -656, -1134, -553, + 1788, 1227, 455, 129, + 462, 441, -240, -528, + 840, 514, 130, -75, + 1114, 623, 153, 216, + 1068, 564, -6, -276, + 1119, 727, 190, -68, + 704, 306, 119, -264, + 329, 61, -100, 156, + 364, 123, 183, -208, + -171, -123, 220, -65, + -306, -62, 402, 17, + -660, -938, -266, 0, + 385, 235, 276, 285, + 320, 268, -336, -200, + -724, 17, -84, 381, + -544, 429, 494, 519, + -117, 288, 304, 329, + 643, 157, 701, 508, + 1200, 625, 796, 608, + 998, 421, 492, 632, + 1204, 780, 446, 132, + 1257, 844, 547, 449, + 829, 658, 541, 470, + 1132, 1258, 918, 639, + 547, 51, 423, 279, + 9, 392, 83, 94, + 542, 543, 229, -147, + -198, 129, 194, -185, + -863, -1321, -302, 30, + -597, -629, -19, 114, + -900, -1081, 466, 353, + -1483, -1573, 15, -143, + -1708, -2059, -751, 196, + -1876, -2067, -642, -258, + -2335, -1470, -450, -564, + -584, -186, -872, -414, + -1805, -988, -1125, -1310, + -726, -1129, 28, 169, + -1039, -864, -718, -246, + 484, 36, -233, -49, + 265, 67, 289, 467, + 178, 543, 810, 540, + 84, 282, 672, 703, + -975, -777, 129, 287, + -938, -227, 955, 595, + -1617, -289, 836, 649, + -1847, -215, 1106, 718, + -2034, -1085, 650, 440, + -2101, -529, 907, 575, + -2011, -336, 670, 204, + -2389, -692, 360, 137, + -2156, -2204, -9, 280, + -266, 119, 39, 193, + 78, -59, -120, 226, + -975, -858, -781, -1095, + -619, -413, -451, -842, + -1216, -1321, -813, -883, + -1376, -1615, -394, -428, + -737, -1113, -549, -790, + -880, -975, -967, -642, + -985, -886, -1273, -1361, + -473, -804, -1401, -1407, + 160, -265, -919, -275, + -248, -250, -718, -380, + 97, -103, -375, -229, + -415, -193, -135, -555, + 628, 361, 119, 216, + 579, 364, 391, 209, + 634, 522, -154, -148, + 526, 389, 170, 33, + 105, 267, 64, 380, + -1503, -1000, -30, -369, + -1070, 58, 647, 223, + -1520, -291, 621, 307, + -1531, 156, 762, 404, + -2029, 141, 734, 499, + -1849, -650, 306, 512, + -187, -104, -59, 438, + 134, -230, 156, -186, + -61, -260, -16, 10, + -569, -3, -421, -297, + -1725, -521, -346, 178, + -1362, -59, -44, 157, + -2146, -461, -470, -349, + -2170, -1, -369, -121, + -1579, -373, -900, -1015, + -1117, -591, -613, -784, + -561, 122, -75, -449, + -4, -171, -123, -372, + 192, 168, -76, -132, + 252, -107, 340, 210, + 392, 509, 272, 181, + -109, 145, 218, 119, + -416, -263, 485, 265, + -181, -8, -286, 226, + -244, -218, 69, -290, + -158, 191, -1, -64, + -592, -90, 213, -96, + 255, 435, 178, -80, + -369, -18, -33, -80, + -42, 415, 140, -222, + 1143, 651, 649, 329, + 767, 556, 249, 235, + 948, 413, 442, 279, + 141, 339, 356, 557, + -470, -170, 99, 237, + -569, -800, 352, 565, + 282, 473, 470, 332, + -199, -690, -1284, -917, + -193, -426, -800, -1122, + -26, -371, -490, -193, + 637, 595, 519, 330, + 408, -115, 79, 12, + 477, 87, -103, -376, + -666, -347, -277, -291, + -510, -481, 169, 297, + -829, -738, -205, -171, + -320, -540, 328, 283, + -859, -958, 442, -2, + 556, 686, 130, 56, + 1383, 1012, 755, 427, + 612, 741, 628, 553, + -339, -796, 134, 277, + -633, -1085, -2, -246, + -880, -1035, -1607, -1064, + -994, -474, -1138, -488, + -414, -795, 73, -206, + -8, -139, 439, 204, + -176, -578, 23, 131, + -269, -757, -191, 245, + -109, -338, 112, 316, + 120, -406, -118, 611, + -180, -186, -645, 115, + -173, 34, -518, -489, + -151, 61, -583, -844, + 220, -138, -681, -1020, + 391, -17, -598, -321, + 157, -295, 129, 155, + -926, -875, -987, 285, + 241, -83, -125, -125, + 620, 597, 432, 92, + 393, 78, 409, 61, + -393, -739, -413, -748, + 83, 54, 361, 27, + -1084, 130, -337, -694, + -1565, 297, 318, -19, + -1873, 36, 51, -317, + -2323, -246, 231, -84, + -2306, -783, 40, -179, + -2233, -930, -474, -462, + -754, -86, -288, -626, + -2411, -455, -63, 171, + -1099, -1094, -26, -143, + -1193, -455, -406, -381, + -605, -210, -96, -51, + -580, -476, -276, -15, + -1195, -634, -1203, -881, + -378, -221, -669, -952, + 594, 178, -403, -676, + 763, 327, 601, 290, + 172, 300, 203, 157, + -56, -336, 356, 24, + -228, -296, -259, -29, + -186, 263, 416, 14, + -353, 373, -12, -216, + 257, 96, 174, 57, + -1526, -616, -954, -499, + -497, -152, -333, 125, + 105, 200, 179, -97, + -331, -224, 765, 697, + 760, 256, 301, 59, + 455, -85, 204, 288, + -514, 240, 251, -109, + 256, 417, -34, -413, + 101, 430, 384, 156, + -31, -10, 206, 426, + 589, 145, 143, 71, + 808, 906, 333, 349, + 986, 938, 589, 331, + 1300, 824, 187, 509, + 1062, 653, 379, 466, + 1462, 937, 401, 274, + 787, 861, 265, 2, + 609, 553, 28, 305, + 926, 340, 106, 386, + 241, -267, -147, 225, + -178, -534, 347, 502, + -643, -381, 397, 30, + -651, -733, -435, 398, + -407, -726, -484, -248, + -789, -914, -438, -476, + -498, -390, 75, -295, + -964, -590, -606, 150, + -121, -49, -155, -78, + 935, 550, 389, 38, + -321, 127, 424, 315, + -285, -113, 283, 259, + 658, 203, 322, 486, + 903, 505, 748, 417, + 611, 423, 555, 512, + 239, -83, -578, -19, + -339, -731, 349, 13, + -934, -1399, -114, -360, + 107, 692, 182, 90, + -1243, -1538, -1551, -725, + -568, -903, -1363, -525, + -517, -853, -861, -1004, + -168, -690, -835, 63, + -137, -556, -547, 144, + -286, -817, 485, 319, + -147, -408, 526, 246, + -347, -434, 297, -28, + -290, -471, -1110, -1285, + -460, -359, -988, -794, + 1347, 1299, 690, 523, + 1216, 1068, 1094, 757, + 825, 1140, 752, 494, + 1252, 1365, 1195, 898, + 521, 1053, 532, 432, + -334, -216, -313, -263, + -160, 52, -472, -155, + 127, 136, -380, 44, + 851, 410, -162, -489, + 123, -255, -796, -667, + 1090, 917, 789, 493, + 1397, 1197, 558, 202, + -51, -118, -342, -701, + 83, 108, -42, -441, + 61, 95, 287, 256, + -27, 89, 524, 531, + 351, 227, 592, 545, + 697, 155, -164, 307, + 638, 274, -489, -50, + 754, 240, -166, -124, + -116, -579, -1212, -63, + 190, -295, -1040, -1296, + 147, -376, -177, -113, + 841, 1241, 1051, 668, + 2, 293, 551, 304, + -1096, -953, -248, 376, + -750, -965, 87, 516, + -275, -516, 689, 391, + -379, -643, 876, 594, + -390, -1013, -645, 573, + -107, -568, -689, -826, + -1025, -27, -328, -203, + 861, 749, 548, 233, + -1660, -1043, 451, 108, + -660, -620, 430, 236, + 21, -396, -1158, -631, + 1372, 1298, 967, 577, + 1125, 1125, 589, 454, + -323, -865, -467, 153, + -468, -699, -804, -509, + -392, -718, -204, -35, + -603, -1093, -567, -162, + -505, -1004, -102, 350, + 219, 224, 423, 252, + 395, 591, 608, 363, + -746, -96, 373, 172, + 171, 295, 714, 339, + 233, 77, 107, 277, + 157, 153, -499, -356, + 1547, 1073, 576, 494, + -292, -339, -504, -592, + -903, -72, -619, -481, + -1594, -1117, -567, -254, + -793, -507, -564, -291, + -492, -532, 502, 560, + -382, 427, 600, 230, + -227, 477, 251, 75, + 285, 842, 813, 476, + -1310, -1333, 186, 377, + -587, -917, 643, 381, + -1186, -553, 411, 82, + -1127, -820, -174, -540, + -604, 119, 543, 205, + -380, 657, 909, 567, + 112, -298, -374, 114, + -857, -251, 56, 159, + 401, 345, -34, -140, + -111, -607, 41, 614, + 355, -114, -77, 474, + 578, 56, 1450, 924, + 1098, 1420, 741, 400, + 246, 22, 588, 313, + -121, 327, 831, 472, + -1138, -608, 856, 552, + -1241, -1072, 638, 600, + -358, 254, -333, -303, + -646, 739, 358, 74, + 1226, 1671, 1221, 849, + 2241, 1624, 983, 636, + 1841, 1477, 749, 384, + 350, 263, 87, 128, + -1902, -941, -144, -64, + -1734, -255, 288, -31, + -2644, -1238, 366, 235, + -1643, -1092, -1344, -304, + -541, -1075, -1116, 123, + -1178, -252, -816, -180, + -1016, 533, 565, 233, + -487, -430, -188, 334, + 867, 1236, 534, 171, + -1590, -1607, 635, 630, + -2196, 310, 924, 412, + -2358, -328, 956, 529, + -2639, -377, 630, 278, + -2602, 317, 799, 299, + -2406, 133, 340, 31, + -2156, -1468, 131, 125, + -1184, -490, -139, 46, + -744, 447, 891, 564, + 67, -451, 646, 604, + -553, -429, -876, 396, + 162, -66, 1305, 915, + 479, 579, 1088, 794, + 450, 278, 566, 324, + -1057, -154, 148, -177, + -2545, 168, 1070, 592, + -2351, -42, 819, 345, + -2344, -707, 721, 250, + -2175, -1497, -309, 122, + -78, -73, 120, 173, + -4, 262, -263, -261, + -431, -64, -405, -732, + -2609, 116, -83, -193, + -1525, -944, -477, -725, + -508, 307, 170, 172, + 832, 417, 832, 686, + -225, 177, 894, 818, + -482, -389, 1279, 1039, + -383, 201, -350, 40, + 730, 635, 226, 526, + 503, 462, 338, 398, + 535, 714, 40, -282, + 1482, 1471, 1085, 731, + 1561, 1072, 909, 693, + 1419, 1282, 889, 879, + 1153, 728, 1186, 840, + -226, 1130, 949, 689, + -494, -986, -1556, -128, + -568, -721, -713, -26, + 317, 524, 70, 135, + -405, -865, -1766, -652, + -174, -801, 885, 773, + -153, -91, 1099, 751, + -506, -1149, 853, 646, + 241, 782, 519, 539, + 1853, 1700, 1101, 684, + -1249, -1486, -464, 188, + -893, -1409, -1312, -341, + -135, 438, -175, 18, + 1111, 976, 319, 208, + -1430, -1768, 83, 458, + -530, -1000, 307, 129, + -840, -15, -29, -356, + -911, -924, -1147, -242, + -119, -528, 127, -133, + -761, -765, 190, -83, + -315, 895, 522, 231, + -222, 102, -63, -428, + 316, 699, 379, 70, + 25, 716, 314, -108, + 507, 874, 566, 238, + 108, 941, 519, 195, + 425, -60, -427, 257, + 139, -103, -630, 446, + 334, 370, 412, 48, + -172, -690, -283, 557, + 187, -286, 158, 483, + 140, 270, -344, -631, + 924, 579, -116, 132, + 142, 466, -68, -64, + 230, -145, -302, -542, + -803, -912, 1018, 737, + -773, 1015, 630, 297, + -2596, 95, 445, 336, + -2122, 491, 510, 191, + -1253, 161, -2, -324, + -1450, -633, -712, -105, + -842, -254, -411, 100, + -640, -290, 1010, 763, + -650, 313, 1169, 730, + 140, 505, 1030, 766, + 772, 287, 1067, 823, + 495, 749, 305, 323, + -164, 462, 78, 399, + -342, -874, 69, 597, + -16, 620, 621, 337, + -138, -444, -265, 218, + 84, -450, 953, 666, + -222, -803, 541, 604, + -921, -1376, 244, 116, + -841, -723, 630, 588, + 140, 663, 294, 368, + 935, 1046, 881, 759, + 1746, 1464, 916, 628, + 436, 963, 281, 1, + -119, 74, 542, 213, + 1, -567, 301, 241, + 260, 435, 222, 396, + 936, 957, 1108, 703, + 510, 506, 808, 478, + 601, 694, 960, 620, + 972, 741, 980, 600, + 834, 717, 767, 684, + 643, 972, 935, 638, + 501, 661, 720, 851, + -105, -632, -303, -117, + -429, 130, 789, 442, + -522, -188, 704, 373, + -759, 42, 814, 523, + -531, -1137, 373, 578, + -682, -1203, -455, 285, + -1163, -1577, -1098, 44, + 81, -82, 712, 363, + 477, 246, 954, 622, + 1604, 1622, 1277, 891, + 1409, 859, 924, 892, + 774, 1041, 947, 1142, + 40, -546, -75, 288, + -616, -106, -697, -26, + -169, -160, -891, -739, + -279, -384, -1029, -350, + 1781, 1308, 1046, 816, + 1580, 1533, 1472, 1178, + 1505, 1076, 1216, 899, + 890, 904, 564, 654, + 920, 692, 1021, 856, + -493, 132, 177, 505, + 71, 195, -28, 97, + 456, 351, -164, 88, + 439, 278, -40, 350, + 1395, 949, 234, -95, + -805, -472, 38, -163, + 367, -98, 489, 523, + 1025, 1178, 1212, 906, + 319, 1314, 814, 461, + -123, -543, -804, 447, + -748, -324, -897, -1127, + -737, -501, -789, -713, + 715, 777, 1239, 922, + 1949, 1939, 1368, 865, + 730, 880, 758, 388, + -871, 454, 17, -251, + -381, -810, -1583, 239, + -521, -966, -792, 259, + -890, -1358, -770, -73, + 166, 349, -212, 323, + -840, -301, 473, 435, + -679, -464, 728, 351, + -156, -199, 667, 432, + 29, -252, 415, 480, + -731, -379, 145, 559, + -528, -631, -1158, -159, + 445, 273, 123, 639, + 373, -126, 800, 568, + 84, -162, 720, 712, + -830, -536, -185, 222, + 408, 452, 501, 771, + -897, -1355, -67, 442, + -792, -1406, 566, 602, + 167, -326, 509, 330, + -95, -626, -730, -344, + 1668, 1217, 779, 455, + 1316, 828, 584, 719, + 404, -31, 1013, 789, + 89, 107, 891, 549, + 871, 1581, 917, 671, + 866, 1479, 1289, 854, + 391, 1068, 1122, 812, + 78, -562, 345, 563, + 429, -103, 417, 787, + -122, -437, 411, 788, + -913, -417, 602, 754, + -226, -16, 151, 760, + -700, 118, -104, -14, + -1128, 48, 284, 393, + -390, -419, -639, -116, + -910, 306, 316, -13, + 1207, 984, 821, 669, + -1195, -693, 140, -213, + -884, -416, -199, -558, + -616, 245, -404, -664, + 262, 56, -617, -724, + -85, -491, -320, -656, + -570, -831, -129, -528, + -1506, -63, -367, -385, + -358, -321, 4, 51, + -366, -214, 319, 511, + 146, 671, -17, -291, + -110, 464, -139, -496, + -202, 220, -312, -631, + -660, -73, -655, -820, + -662, -653, -1288, -857, + -430, -953, -959, -264, + -49, -468, -72, -381, + -350, -563, -193, -407, + 55, -408, -803, 11, + -309, 649, 188, -198, + -512, 461, -79, -458, + -1318, -263, -134, -523, + -1657, -435, -495, -765, + 57, -347, -414, 434, + -1141, -242, -664, -857, + 34, -68, -707, -338 +}; + + + +/* third codebook for MR475, MR515 */ + +const Word16 mr515_3_lsf[MR515_3_SIZE*4] = +{ + 419, 163, -30, -262, + -455, -789, -1430, -721, + 1006, 664, 269, 25, + 619, 260, 183, 96, + -968, -1358, -388, 135, + -693, 835, 456, 154, + 1105, 703, 569, 363, + 1625, 1326, 985, 748, + -220, 219, 76, -208, + -1455, -1662, 49, 149, + -964, -172, -752, -336, + 625, 209, -250, -66, + -1017, -838, -2, 317, + -2168, -1485, -138, 123, + -1876, -2099, -521, 85, + -967, -366, -695, -881, + -921, -1011, -763, -949, + -124, -256, -352, -660, + 178, 463, 354, 304, + -1744, -591, -282, 79, + -2249, 175, 867, 499, + -138, -180, -181, -21, + -2291, -1241, -460, -520, + -771, 451, -10, -308, + 271, -65, 4, 214, + -279, -435, -43, -348, + -670, 35, -65, -211, + 806, 535, 85, 297, + 57, 239, 722, 493, + 225, 661, 840, 547, + -540, -376, 14, 349, + 469, 721, 331, 162, + -544, -752, -62, -10, + 398, -88, 724, 701, + -19, -533, -94, 601, + 136, -71, -681, -747, + -166, -344, 261, -50, + 161, -52, 485, 337, + -1675, 50, 190, -93, + -2282, -231, -194, -82, + -95, -595, -154, 128, + 894, 501, 588, 457, + -345, 206, 122, 110, + -631, -227, -569, 3, + 408, 239, 397, 226, + -197, -2, 128, 491, + 1281, 904, 292, 215, + 538, 306, 259, 509, + -677, -1047, 13, 321, + -679, -588, -358, -212, + -558, 243, 646, 479, + 486, 342, 634, 532, + 107, 802, 331, 136, + -112, -398, -1031, -286, + -326, -705, 288, 272, + 1299, 1144, 1178, 860, + -423, 121, -385, -148, + -295, -302, -834, -819, + 16, -24, -201, -476, + 555, 91, -245, 294, + -38, -379, -962, -1221, + -1191, -1518, -273, -395, + -390, -1013, -645, 573, + -1843, -1030, 505, 468, + 744, 947, 609, 493, + -689, -1172, -628, -135, + -1026, 195, 411, 196, + 1582, 1147, 575, 337, + -1239, -777, -648, -142, + 595, 825, 967, 735, + -1206, -970, -81, -342, + -745, 13, -72, 375, + 454, 19, 1407, 921, + -1647, -172, 861, 562, + 928, 1537, 1063, 740, + -2472, -952, 264, 82, + -502, -965, -1334, 123, + 867, 1236, 534, 171, + -2320, -460, 780, 363, + -1190, -617, 252, -61, + -174, 34, 1011, 788, + -2333, 247, 423, 153, + -16, -355, 262, 449, + -1576, -1073, -544, -371, + -615, -305, 1051, 805, + 687, 528, 6, -182, + 935, 875, 1002, 809, + 199, 257, 126, 76, + -584, -1138, 599, 556, + -1105, -1391, -1591, -519, + -977, -1325, 108, 347, + -722, -975, 365, 101, + -145, 681, 249, -153, + 0, -334, -570, 159, + 412, 285, -336, -617, + -953, -966, 887, 689, + -1251, 84, -185, -398, + -592, 433, 1044, 653, + 85, 329, -40, 361, + -433, -705, 466, 574, + -154, 654, 592, 290, + -167, 72, 349, 175, + 674, 297, 977, 720, + 1235, 1204, 757, 488, + -400, -269, 538, 372, + -1350, -1387, -1194, -91, + 1262, 876, 775, 700, + -599, -38, -430, -722, + 1976, 1630, 991, 608, + 111, 276, -226, -96, + -947, -388, -11, -7, + -303, -531, -839, 338, + 1734, 1710, 1405, 1013, + -516, -855, -645, 210, + -688, -416, 513, 230, + -822, -637, -1146, -320, + -952, -658, -694, 183, + -114, -623, 818, 674, + -191, -204, 731, 635, + 51, 1221, 883, 576, + -954, -431, 826, 598, + -342, -755, -900, -407, + -1126, -354, -206, -512, + -547, -810, -357, -620, + 66, 515, -73, -410, + -872, -945, -1444, -1227, + 191, -17, -544, -231, + -1540, -544, -901, -886 +}; + +/* first codebook for MR795 */ + +const Word16 mr795_1_lsf[MR795_1_SIZE*3] = +{ + -890, -1550, -2541, + -819, -970, 175, + -826, -1234, -762, + -599, -22, 634, + -811, -987, -902, + -323, 203, 26, + -383, -235, -781, + -399, 1262, 906, + -932, -1399, -1380, + -624, 93, 87, + -414, -539, -691, + 37, 633, 510, + -387, -476, -1330, + 399, 66, 263, + -407, -49, -335, + -417, 1041, 1865, + -779, -1089, -1440, + -746, -858, 832, + -581, -759, -371, + -673, -506, 2088, + -560, -634, -1179, + 271, 241, 14, + -438, -244, -397, + 463, 1202, 1047, + -606, -797, -1438, + -51, -323, 481, + -224, -584, -527, + 494, 881, 682, + -433, -306, -1002, + 554, 659, 222, + 171, -160, -353, + 681, 1798, 1565, + -852, -1181, -1695, + -336, -666, 114, + -581, -756, -744, + -195, 375, 497, + -465, -804, -1098, + 154, 282, -131, + -50, -191, -719, + 323, 732, 1542, + -722, -819, -1404, + 105, -250, 185, + -178, -502, -742, + 321, 510, 1111, + -323, -567, -966, + 127, 484, 338, + -160, 52, -338, + 732, 1367, 1554, + -626, -802, -1696, + -286, -586, 676, + -695, -343, -370, + -490, 295, 1893, + -630, -574, -1014, + -80, 645, -69, + -6, -318, -364, + 782, 1450, 1038, + -313, -733, -1395, + 120, 60, 477, + -264, -585, -123, + 711, 1245, 633, + -91, -355, -1016, + 771, 758, 261, + 253, 81, -474, + 930, 2215, 1720, + -808, -1099, -1925, + -560, -782, 169, + -804, -1074, -188, + -626, -55, 1405, + -694, -716, -1194, + -660, 354, 329, + -514, -55, -543, + 366, 1033, 1182, + -658, -959, -1357, + -55, -184, 93, + -605, -286, -662, + 404, 449, 827, + -286, -350, -1263, + 628, 306, 227, + -16, 147, -623, + 186, 923, 2146, + -674, -890, -1606, + -443, -228, 339, + -369, -790, -409, + 231, 86, 1469, + -448, -581, -1061, + 594, 450, -177, + -124, -170, -447, + 671, 1159, 1404, + -476, -667, -1511, + -77, -138, 716, + -177, -372, -381, + 451, 934, 915, + -250, -432, -822, + 272, 828, 446, + 26, 19, -31, + 698, 1692, 2168, + -646, -977, -1924, + -179, -473, 268, + -379, -745, -691, + 11, 127, 1033, + -488, -917, -825, + 61, 323, 135, + 147, -145, -686, + 685, 786, 1682, + -506, -848, -1297, + 35, 90, 222, + -23, -346, -670, + 455, 591, 1287, + -203, -593, -1086, + 652, 352, 437, + 39, 63, -457, + 841, 1265, 2105, + -520, -882, -1584, + -328, -711, 1421, + -596, -342, -70, + 209, 173, 1928, + -423, -598, -921, + 421, 605, -38, + -2, -245, -127, + 896, 1969, 1135, + -379, -518, -1579, + 173, 118, 753, + -55, -381, -52, + 985, 1021, 753, + -2, -291, -891, + 753, 992, 423, + 264, 131, -196, + 895, 2274, 2543, + -635, -1088, -2499, + -529, -982, 526, + -764, -830, -548, + -436, 316, 599, + -675, -940, -746, + -57, 236, -11, + -201, -81, -798, + 16, 845, 1558, + -737, -985, -1212, + -468, 17, 290, + -279, -584, -700, + 183, 822, 705, + -265, -492, -1187, + 421, 152, 468, + -390, 166, -268, + 39, 1550, 1868, + -635, -966, -1571, + -453, -492, 910, + -284, -1027, -75, + -181, -133, 1852, + -445, -624, -1174, + 420, 367, -49, + -389, -212, -169, + 707, 1073, 1208, + -539, -710, -1449, + 83, -163, 484, + -236, -543, -355, + 338, 1175, 814, + -246, -309, -958, + 606, 760, 60, + 166, -8, -163, + -306, 1849, 2563, + -747, -1025, -1783, + -419, -446, 209, + -718, -566, -534, + -506, 693, 857, + -463, -697, -1082, + 325, 431, -206, + -15, -8, -763, + 545, 919, 1518, + -611, -783, -1313, + 256, -55, 208, + -165, -348, -662, + 321, 680, 930, + -326, -429, -951, + 484, 446, 570, + -197, 72, -73, + 909, 1455, 1741, + -563, -737, -1974, + -124, -416, 718, + -478, -404, -314, + -16, 446, 1636, + -551, -537, -750, + -58, 638, 214, + 55, -185, -271, + 1148, 1301, 1212, + -483, -671, -1264, + 117, 285, 543, + -204, -391, -111, + 513, 1538, 854, + -114, -190, -978, + 877, 595, 464, + 260, 260, -311, + 748, 2283, 2216, + -517, -945, -2171, + -326, -708, 378, + -812, -691, -232, + -560, 687, 1409, + -732, -690, -836, + -359, 645, 386, + -265, 62, -678, + 145, 1644, 1208, + -555, -988, -1233, + -78, 14, 114, + -327, -358, -489, + 392, 677, 697, + -201, -236, -1140, + 693, 449, 178, + -243, 256, -433, + 611, 1385, 2456, + -612, -901, -1464, + -307, -17, 499, + -315, -667, -254, + 256, 428, 1463, + -486, -422, -1056, + 655, 370, 18, + -102, -185, -276, + 755, 1578, 1335, + -488, -603, -1418, + 182, -93, 870, + -73, -458, -348, + 835, 862, 957, + -282, -333, -746, + 547, 839, 428, + 273, -89, 13, + 940, 1708, 2576, + -418, -1084, -1758, + -44, -358, 259, + -497, -643, -560, + 99, 557, 961, + -421, -766, -917, + 295, 326, 184, + 175, 15, -626, + 532, 878, 1981, + -443, -768, -1275, + 221, 156, 268, + 39, -363, -505, + 695, 772, 1140, + -162, -459, -912, + 709, 444, 658, + 25, 303, -312, + 1268, 1410, 1715, + -297, -766, -1836, + -263, -108, 1070, + -406, -13, -129, + 57, 438, 2734, + -374, -487, -835, + 304, 696, 164, + 104, -235, 5, + 1611, 1900, 1399, + -229, -582, -1325, + 405, 192, 817, + -87, -438, 111, + 1028, 1199, 993, + 68, -175, -934, + 1033, 1117, 451, + 478, 200, -248, + 2127, 2696, 2042, + -835, -1323, -2131, + -799, -692, 466, + -812, -1032, -469, + -622, 288, 920, + -701, -841, -1070, + -411, 512, 8, + -390, -91, -744, + -30, 1043, 1161, + -822, -1148, -1156, + -294, -46, 110, + -411, -374, -678, + 214, 531, 668, + -406, -420, -1194, + 487, 232, 303, + -318, 91, -472, + 123, 1232, 2445, + -722, -952, -1495, + -738, -675, 1332, + -543, -606, -211, + -95, -98, 1508, + -549, -514, -1193, + 473, 211, 73, + -288, -112, -389, + 537, 1332, 1258, + -567, -755, -1545, + 71, -283, 632, + -170, -481, -493, + 681, 1002, 817, + -356, -331, -877, + 419, 706, 346, + 241, -34, -326, + 377, 1950, 1883, + -727, -1075, -1625, + -233, -543, 116, + -524, -806, -585, + -73, 478, 729, + -288, -925, -1143, + 173, 447, -52, + 68, -229, -606, + 449, 529, 1797, + -591, -875, -1363, + 183, -144, 324, + -103, -452, -666, + 623, 488, 1176, + -238, -511, -1004, + 326, 552, 458, + 136, 108, -319, + 626, 1343, 1883, + -490, -646, -1730, + -186, -449, 984, + -738, -76, -170, + -550, 755, 2560, + -496, -510, -947, + 210, 694, -52, + 84, -322, -199, + 1090, 1625, 1224, + -376, -603, -1396, + 343, 74, 632, + -175, -502, -32, + 972, 1332, 734, + 52, -295, -1113, + 1065, 918, 160, + 393, 107, -397, + 1214, 2649, 1741, + -632, -1201, -1891, + -719, -277, 353, + -651, -880, -122, + -211, 209, 1338, + -562, -714, -1059, + -208, 388, 159, + -320, -61, -551, + 293, 1092, 1443, + -648, -865, -1253, + -49, -143, 305, + -401, -227, -585, + 561, 532, 927, + -117, -443, -1188, + 507, 436, 292, + -79, 233, -458, + 671, 1025, 2396, + -633, -842, -1525, + -308, -286, 640, + -373, -621, -407, + 418, 253, 1305, + -315, -581, -1137, + 572, 685, -281, + 61, -68, -371, + 991, 1101, 1498, + -493, -683, -1362, + -47, 164, 704, + -256, -314, -268, + 631, 949, 1052, + -118, -348, -833, + 68, 1180, 568, + 152, 117, 34, + 1113, 1902, 2239, + -601, -959, -1706, + -143, -489, 480, + -332, -655, -574, + 54, 353, 1192, + -462, -652, -796, + 150, 549, 112, + 195, -111, -515, + 679, 1108, 1647, + -558, -749, -1217, + -9, 272, 341, + -53, -265, -535, + 489, 843, 1298, + -120, -482, -1032, + 632, 543, 408, + 179, 306, -526, + 1124, 1464, 2244, + -417, -786, -1562, + -224, -384, 1364, + -377, -459, -25, + 385, 489, 2174, + -332, -651, -829, + 544, 553, 61, + 22, -113, -89, + 1128, 1725, 1524, + -216, -373, -1653, + 161, 316, 908, + -165, -222, -67, + 1362, 1175, 789, + 73, -252, -767, + 738, 932, 616, + 362, 246, -126, + 787, 2654, 3027, + -691, -1106, -2190, + -565, -588, 524, + -590, -979, -490, + -263, 397, 982, + -577, -837, -945, + -22, 435, -49, + -190, -118, -629, + -88, 1240, 1513, + -636, -1051, -1019, + -291, 189, 259, + -257, -470, -629, + 145, 945, 894, + -326, -364, -1094, + 543, 260, 630, + -202, 189, -209, + 357, 1379, 2091, + -569, -1075, -1449, + -714, -239, 919, + -420, -705, -84, + -109, -114, 2407, + -413, -529, -1177, + 482, 368, 131, + -186, -72, -131, + 861, 1255, 1220, + -611, -658, -1341, + 227, -121, 631, + -176, -489, -218, + 745, 1175, 957, + -321, -148, -936, + 671, 966, 216, + 340, -3, -143, + 469, 1848, 2437, + -729, -961, -1683, + -213, -254, 321, + -511, -438, -521, + -126, 725, 903, + -340, -685, -1032, + 316, 480, 20, + 23, -89, -551, + 353, 1051, 1789, + -544, -757, -1364, + 298, -25, 436, + -100, -392, -519, + 467, 754, 1078, + -210, -398, -1078, + 620, 658, 630, + 33, 147, -178, + 921, 1687, 1921, + -325, -528, -1978, + 2, -285, 910, + -371, -490, -230, + 0, 597, 2010, + -496, -395, -834, + 37, 945, 245, + 181, -160, -144, + 1481, 1373, 1357, + -355, -601, -1270, + 298, 322, 672, + -193, -336, 77, + 1089, 1533, 922, + 177, -39, -1125, + 996, 781, 536, + 456, 366, -432, + 1415, 2440, 2279, + -466, -758, -2325, + -303, -509, 387, + -727, -557, 66, + -145, 643, 1248, + -544, -676, -916, + -225, 862, 588, + -152, 40, -533, + 423, 1423, 1558, + -572, -843, -1145, + -128, 85, 461, + -238, -257, -584, + 605, 748, 861, + 24, -202, -1409, + 797, 487, 303, + -181, 364, -182, + 616, 1378, 2942, + -494, -852, -1441, + -292, 61, 812, + -84, -723, -182, + 555, 532, 1506, + -365, -493, -1057, + 822, 588, 11, + -14, -18, -230, + 1001, 1401, 1451, + -474, -569, -1292, + 302, 62, 1062, + -70, -376, -222, + 982, 974, 1149, + -196, -234, -795, + 479, 1098, 499, + 362, 58, 70, + 1147, 2069, 2857, + -487, -878, -1824, + 73, -288, 348, + -358, -500, -508, + 199, 721, 1242, + -78, -697, -795, + 361, 536, 196, + 374, 110, -735, + 847, 1051, 1896, + -366, -713, -1182, + 315, 320, 429, + 72, -215, -450, + 759, 886, 1363, + -30, -428, -834, + 861, 627, 796, + 118, 468, -279, + 1355, 1883, 1893, + -188, -642, -1612, + 63, -175, 1198, + -418, -211, 51, + 414, 587, 2601, + -234, -557, -858, + 424, 889, 222, + 136, -101, 83, + 1413, 2278, 1383, + -84, -445, -1389, + 414, 313, 1045, + 29, -343, 65, + 1552, 1647, 980, + 183, -91, -829, + 1273, 1413, 360, + 553, 272, -107, + 1587, 3149, 2603 +}; + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5.cpp new file mode 100644 index 0000000..10d514d --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5.cpp @@ -0,0 +1,600 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: q_plsf_5.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "q_plsf.h" +#include "typedef.h" +#include "basic_op.h" +#include "lsp_lsf.h" +#include "reorder.h" +#include "lsfwt.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + /* Codebooks of LSF prediction residual */ + extern const Word16 mean_lsf_5[]; + + extern const Word16 dico1_lsf_5[]; + extern const Word16 dico2_lsf_5[]; + extern const Word16 dico3_lsf_5[]; + extern const Word16 dico4_lsf_5[]; + extern const Word16 dico5_lsf_5[]; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Vq_subvec +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15 + lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15 + dico -- pointer to const Word16 -- quantization codebook, Q15 + wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13 + wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13 + dico_size -- Word16 -- size of quantization codebook, Q0 + Outputs: + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + Word16 -- quantization index, Q0 + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the quantization of a 4-dimensional subvector. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ +/* Quantization of a 4 dimensional subvector */ + +static Word16 Vq_subvec( /* o : quantization index, Q0 */ + Word16 *lsf_r1, /* i : 1st LSF residual vector, Q15 */ + Word16 *lsf_r2, /* i : 2nd LSF residual vector, Q15 */ + const Word16 *dico, /* i : quantization codebook, Q15 */ + Word16 *wf1, /* i : 1st LSF weighting factors Q13 */ + Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */ + Word16 dico_size, /* i : size of quantization codebook, Q0 */ + Flag *pOverflow /* o : overflow indicator */ +) +{ + Word16 index = 0; /* initialization only needed to keep gcc silent */ + Word16 i; + Word16 temp; + const Word16 *p_dico; + Word32 dist_min; + Word32 dist; + Word16 wf1_0; + Word16 wf1_1; + Word16 wf2_0; + Word16 wf2_1; + Word32 aux1; + Word32 aux2; + Word32 aux3; + Word32 aux4; + + OSCL_UNUSED_ARG(pOverflow); + + dist_min = MAX_32; + p_dico = dico; + + wf1_0 = wf1[0]; + wf1_1 = wf1[1]; + wf2_0 = wf2[0]; + wf2_1 = wf2[1]; + + aux1 = ((Word32) lsf_r1[0] * wf1_0); + aux2 = ((Word32) lsf_r1[1] * wf1_1); + aux3 = ((Word32) lsf_r2[0] * wf2_0); + aux4 = ((Word32) lsf_r2[1] * wf2_1); + + for (i = 0; i < dico_size; i++) + { + temp = (aux1 - ((Word32)wf1_0 * *(p_dico++))) >> 15; + dist = ((Word32)temp * temp); + + if (dist >= dist_min) + { + p_dico += 3; + continue; + } + + temp = (aux2 - ((Word32)wf1_1 * *(p_dico++))) >> 15; + dist += ((Word32)temp * temp); + + if (dist >= dist_min) + { + p_dico += 2; + continue; + } + + temp = (aux3 - ((Word32)wf2_0 * *(p_dico++))) >> 15; + dist += ((Word32)temp * temp); + + if (dist >= dist_min) + { + p_dico += 1; + continue; + } + + temp = (aux4 - ((Word32)wf2_1 * *(p_dico++))) >> 15; + dist += ((Word32)temp * temp); + + + if (dist < dist_min) + { + dist_min = dist; + index = i; + } + } + + + + /* Reading the selected vector */ + + p_dico = &dico[ index<<2]; + lsf_r1[0] = *p_dico++; + lsf_r1[1] = *p_dico++; + lsf_r2[0] = *p_dico++; + lsf_r2[1] = *p_dico; + + return index; + +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Vq_subvec_s +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15 + lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15 + dico -- pointer to const Word16 -- quantization codebook, Q15 + wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13 + wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13 + dico_size -- Word16 -- size of quantization codebook, Q0 + + Outputs: + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + Word16 -- quantization index, Q0 + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the quantization of a 4-dimensional subvector. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + + +/* Quantization of a 4 dimensional subvector with a signed codebook */ + +static Word16 Vq_subvec_s( /* o : quantization index Q0 */ + Word16 *lsf_r1, /* i : 1st LSF residual vector Q15 */ + Word16 *lsf_r2, /* i : and LSF residual vector Q15 */ + const Word16 *dico, /* i : quantization codebook Q15 */ + Word16 *wf1, /* i : 1st LSF weighting factors Q13 */ + Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */ + Word16 dico_size, /* i : size of quantization codebook Q0 */ + Flag *pOverflow) /* o : overflow indicator */ +{ + Word16 index = 0; /* initialization only needed to keep gcc silent */ + Word16 sign = 0; /* initialization only needed to keep gcc silent */ + Word16 i; + Word16 temp; + Word16 temp1; + Word16 temp2; + const Word16 *p_dico; + Word32 dist_min; + Word32 dist1; + Word32 dist2; + + Word16 lsf_r1_0; + Word16 lsf_r1_1; + Word16 lsf_r2_0; + Word16 lsf_r2_1; + + Word16 wf1_0; + Word16 wf1_1; + Word16 wf2_0; + Word16 wf2_1; + + OSCL_UNUSED_ARG(pOverflow); + + dist_min = MAX_32; + p_dico = dico; + + + lsf_r1_0 = lsf_r1[0]; + lsf_r1_1 = lsf_r1[1]; + lsf_r2_0 = lsf_r2[0]; + lsf_r2_1 = lsf_r2[1]; + + wf1_0 = wf1[0]; + wf1_1 = wf1[1]; + wf2_0 = wf2[0]; + wf2_1 = wf2[1]; + + for (i = 0; i < dico_size; i++) + { + /* test positive */ + temp = *p_dico++; + temp1 = lsf_r1_0 - temp; + temp2 = lsf_r1_0 + temp; + temp1 = ((Word32)wf1_0 * temp1) >> 15; + temp2 = ((Word32)wf1_0 * temp2) >> 15; + dist1 = ((Word32)temp1 * temp1); + dist2 = ((Word32)temp2 * temp2); + + temp = *p_dico++; + temp1 = lsf_r1_1 - temp; + temp2 = lsf_r1_1 + temp; + temp1 = ((Word32)wf1_1 * temp1) >> 15; + temp2 = ((Word32)wf1_1 * temp2) >> 15; + dist1 += ((Word32)temp1 * temp1); + dist2 += ((Word32)temp2 * temp2); + + if ((dist1 >= dist_min) && (dist2 >= dist_min)) + { + p_dico += 2; + continue; + } + + temp = *p_dico++; + temp1 = lsf_r2_0 - temp; + temp2 = lsf_r2_0 + temp; + temp1 = ((Word32)wf2_0 * temp1) >> 15; + temp2 = ((Word32)wf2_0 * temp2) >> 15; + dist1 += ((Word32)temp1 * temp1); + dist2 += ((Word32)temp2 * temp2); + + temp = *p_dico++; + temp1 = lsf_r2_1 - temp; + temp2 = lsf_r2_1 + temp; + temp1 = ((Word32)wf2_1 * temp1) >> 15; + temp2 = ((Word32)wf2_1 * temp2) >> 15; + dist1 += ((Word32)temp1 * temp1); + dist2 += ((Word32)temp2 * temp2); + + if (dist1 < dist_min) + { + dist_min = dist1; + index = i; + sign = 0; + } + + /* test negative */ + + if (dist2 < dist_min) + { + dist_min = dist2; + index = i; + sign = 1; + } + } + + /* Reading the selected vector */ + + p_dico = &dico[index<<2]; + index <<= 1; + if (sign) + { + lsf_r1[0] = - (*p_dico++); + lsf_r1[1] = - (*p_dico++); + lsf_r2[0] = - (*p_dico++); + lsf_r2[1] = - (*p_dico); + index += 1; + } + else + { + lsf_r1[0] = *p_dico++; + lsf_r1[1] = *p_dico++; + lsf_r2[0] = *p_dico++; + lsf_r2[1] = *p_dico; + } + + return index; + +} + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Q_plsf_5 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + + Inputs: + st -- pointer to Q_plsfState -- state information + lsp1 -- array of type Word16 -- 1st LSP vector, Q15 + lsp2 -- array of type Word16 -- 2nd LSP vector, Q15 + + Outputs: + lps1_q -- array of type Word16 -- quantized 1st LSP vector, Q15 + lps2_q -- array of type Word16 -- quantized 2nd LSP vector, Q15 + indices -- array of type Word16 -- quantization indices of 5 matrics, Q0 + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + mean_lsf_5[]; + + dico1_lsf_5[]; + dico2_lsf_5[]; + dico3_lsf_5[]; + dico4_lsf_5[]; + dico5_lsf_5[]; + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + PURPOSE: Quantization of 2 sets of LSF parameters using 1st order MA + prediction and split by 5 matrix quantization (split-MQ) + + DESCRIPTION: + + p[i] = pred_factor*past_rq[i]; i=0,...,m-1 + r1[i]= lsf1[i] - p[i]; i=0,...,m-1 + r2[i]= lsf2[i] - p[i]; i=0,...,m-1 + where: + lsf1[i] 1st mean-removed LSF vector. + lsf2[i] 2nd mean-removed LSF vector. + r1[i] 1st residual prediction vector. + r2[i] 2nd residual prediction vector. + past_r2q[i] Past quantized residual (2nd vector). + + The residual vectors r1[i] and r2[i] are jointly quantized using + split-MQ with 5 codebooks. Each 4th dimension submatrix contains 2 + elements from each residual vector. The 5 submatrices are as follows: + {r1[0], r1[1], r2[0], r2[1]}; {r1[2], r1[3], r2[2], r2[3]}; + {r1[4], r1[5], r2[4], r2[5]}; {r1[6], r1[7], r2[6], r2[7]}; + {r1[8], r1[9], r2[8], r2[9]} + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Q_plsf_5( + Q_plsfState *st, + Word16 *lsp1, /* i : 1st LSP vector, Q15 */ + Word16 *lsp2, /* i : 2nd LSP vector, Q15 */ + Word16 *lsp1_q, /* o : quantized 1st LSP vector, Q15 */ + Word16 *lsp2_q, /* o : quantized 2nd LSP vector, Q15 */ + Word16 *indice, /* o : quantization indices of 5 matrices, Q0 */ + Flag *pOverflow /* o : overflow indicator */ +) +{ + Word16 i; + Word16 lsf1[M]; + Word16 lsf2[M]; + Word16 wf1[M]; + Word16 wf2[M]; + Word16 lsf_p[M]; + Word16 lsf_r1[M]; + Word16 lsf_r2[M]; + Word16 lsf1_q[M]; + Word16 lsf2_q[M]; + + Word16 *p_lsf_p; + Word16 *p_lsf1; + Word16 *p_lsf2; + Word16 *p_lsf_r1; + Word16 *p_lsf_r2; + + /* convert LSFs to normalize frequency domain 0..16384 */ + + Lsp_lsf(lsp1, lsf1, M, pOverflow); + Lsp_lsf(lsp2, lsf2, M, pOverflow); + + /* Compute LSF weighting factors (Q13) */ + + Lsf_wt(lsf1, wf1, pOverflow); + Lsf_wt(lsf2, wf2, pOverflow); + + /* Compute predicted LSF and prediction error */ + + p_lsf_p = &lsf_p[0]; + p_lsf1 = &lsf1[0]; + p_lsf2 = &lsf2[0]; + p_lsf_r1 = &lsf_r1[0]; + p_lsf_r2 = &lsf_r2[0]; + + for (i = 0; i < M; i++) + { + *(p_lsf_p) = mean_lsf_5[i] + + (((Word32)st->past_rq[i] * LSP_PRED_FAC_MR122) >> 15); + + *(p_lsf_r1++) = *(p_lsf1++) - *(p_lsf_p); + *(p_lsf_r2++) = *(p_lsf2++) - *(p_lsf_p++); + } + + /*---- Split-MQ of prediction error ----*/ + + indice[0] = Vq_subvec(&lsf_r1[0], &lsf_r2[0], dico1_lsf_5, + &wf1[0], &wf2[0], DICO1_5_SIZE, pOverflow); + + indice[1] = Vq_subvec(&lsf_r1[2], &lsf_r2[2], dico2_lsf_5, + &wf1[2], &wf2[2], DICO2_5_SIZE, pOverflow); + + indice[2] = Vq_subvec_s(&lsf_r1[4], &lsf_r2[4], dico3_lsf_5, + &wf1[4], &wf2[4], DICO3_5_SIZE, pOverflow); + + indice[3] = Vq_subvec(&lsf_r1[6], &lsf_r2[6], dico4_lsf_5, + &wf1[6], &wf2[6], DICO4_5_SIZE, pOverflow); + + indice[4] = Vq_subvec(&lsf_r1[8], &lsf_r2[8], dico5_lsf_5, + &wf1[8], &wf2[8], DICO5_5_SIZE, pOverflow); + + /* Compute quantized LSFs and update the past quantized residual */ + + p_lsf_r1 = &lsf_r1[0]; + p_lsf_r2 = &lsf_r2[0]; + p_lsf_p = &lsf_p[0]; + p_lsf1 = &lsf1_q[0]; + p_lsf2 = &lsf2_q[0]; + + + for (i = 0; i < M; i++) + { + *(p_lsf1++) = *(p_lsf_r1++) + *(p_lsf_p); + *(p_lsf2++) = *(p_lsf_r2) + *(p_lsf_p++); + st->past_rq[i] = *(p_lsf_r2++); + } + + /* verification that LSFs has minimum distance of LSF_GAP */ + + Reorder_lsf(lsf1_q, LSF_GAP, M, pOverflow); + Reorder_lsf(lsf2_q, LSF_GAP, M, pOverflow); + + /* convert LSFs to the cosine domain */ + + Lsf_lsp(lsf1_q, lsp1_q, M, pOverflow); + Lsf_lsp(lsf2_q, lsp2_q, M, pOverflow); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5_tbl.cpp new file mode 100644 index 0000000..42f37a1 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/q_plsf_5_tbl.cpp @@ -0,0 +1,1131 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: q_plsf_5_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "q_plsf_5_tbl.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ +#define NB_QUA_PITCH 16 +#define NB_QUA_CODE 32 + + +#define DICO1_5_SIZE 128 +#define DICO2_5_SIZE 256 +#define DICO3_5_SIZE 256 +#define DICO4_5_SIZE 256 +#define DICO5_5_SIZE 64 + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + /* LSF means ->normalize frequency domain */ + + const Word16 mean_lsf_5[10] = + { + 1384, + 2077, + 3420, + 5108, + 6742, + 8122, + 9863, + 11092, + 12714, + 13701 + }; + + const Word16 dico1_lsf_5[DICO1_5_SIZE * 4] = + { + -451, -1065, -529, -1305, + -450, -756, -497, -863, + -384, -619, -413, -669, + -317, -538, -331, -556, + -414, -508, -424, -378, + -274, -324, -434, -614, + -226, -500, -232, -514, + -263, -377, -298, -410, + -151, -710, -174, -818, + -149, -412, -156, -429, + -288, -462, -186, -203, + -170, -302, -191, -321, + -131, -147, -297, -395, + -228, -214, -245, -192, + -67, -316, -71, -327, + -104, -205, -94, -183, + -143, -38, -193, -95, + 16, -76, -124, -248, + 23, -237, 24, -244, + 18, -136, 44, -111, + -33, -24, -25, 0, + 149, 19, 23, -143, + 158, -169, 174, -181, + 133, -55, 165, -26, + 111, 84, 98, 75, + 87, 183, -115, -11, + -8, 130, 11, 170, + 254, 77, 205, 17, + 183, 112, 262, 194, + 202, 287, 95, 189, + -42, -105, 234, 179, + 39, 186, 163, 345, + 332, 199, 299, 161, + -54, 285, -78, 281, + -133, 141, -182, 111, + 249, 341, 271, 364, + 93, 403, 75, 391, + 92, 510, -138, 220, + -185, -29, -34, 361, + -115, 320, 3, 554, + 99, 286, 218, 591, + -245, 406, -268, 453, + 0, 580, 25, 606, + 275, 532, 148, 450, + -73, 739, -285, 518, + -288, 94, -203, 674, + -140, -74, 205, 714, + -114, 299, 176, 923, + 182, 557, 240, 705, + -16, 513, 485, 593, + 293, 384, 451, 617, + -38, 50, 563, 529, + 303, 209, 459, 363, + 433, 452, 450, 454, + 367, 606, 477, 741, + 432, 353, 368, 267, + 361, 716, 273, 583, + 453, 166, 510, 172, + 201, 629, 274, 191, + 568, 639, 302, 298, + 634, 387, 643, 350, + 587, 560, 612, 565, + 600, 788, 487, 672, + 512, 1015, 321, 333, + 357, 854, -125, 413, + 474, 712, 17, -151, + 564, 285, 270, -241, + 971, 889, 489, 220, + 510, 896, 549, 924, + 327, 825, 290, 911, + 540, 1108, 158, 805, + 199, 957, 511, 730, + 100, 874, 13, 791, + 435, 632, 676, 972, + 249, 900, 467, 1218, + 781, 1074, 585, 785, + -23, 669, 267, 1043, + 619, 1084, 615, 1145, + 622, 905, 916, 1049, + 80, 331, 584, 1075, + 89, 639, 988, 961, + 770, 720, 798, 699, + 492, 447, 899, 627, + 271, 1188, 725, 1333, + 87, 603, 832, 1603, + 616, 1127, 890, 1505, + 1000, 1156, 866, 1009, + 995, 827, 1149, 858, + 817, 1450, 773, 1320, + 500, 1389, 312, 1153, + -20, 1084, 64, 1283, + 2, 1172, 399, 1869, + 514, 1706, 502, 1636, + 886, 1522, 416, 600, + 1131, 1350, 1275, 1390, + 889, 1795, 914, 1766, + 227, 1183, 1250, 1826, + 505, 1854, 919, 2353, + -199, 431, 152, 1735, + -213, -28, 392, 1334, + -153, -52, 978, 1151, + -323, -400, 813, 1703, + -136, 84, 1449, 2015, + -331, -143, -137, 1192, + -256, 534, -157, 1031, + -307, -439, 542, 731, + -329, -420, -97, 616, + -362, -168, -322, 366, + -247, -110, -211, 89, + -196, -309, 20, 59, + -364, -463, -286, 89, + -336, 175, -432, 141, + -379, -190, -434, -196, + -79, 150, -278, -227, + -280, 166, -555, -422, + -155, 541, -366, 54, + -29, -83, -301, -774, + 186, 628, -397, -264, + 242, 293, -197, -585, + 124, 410, 53, -133, + 10, 340, -570, -1065, + 65, -446, 68, -493, + 383, 937, -357, -711, + -359, -250, -677, -1068, + 292, -26, 363, 6, + 607, 1313, -127, -10, + 1513, 1886, 713, 972, + 1469, 2181, 1443, 2016 + }; + + const Word16 dico2_lsf_5[DICO2_5_SIZE * 4] = + { + -1631, -1600, -1796, -2290, + -1027, -1770, -1100, -2025, + -1277, -1388, -1367, -1534, + -947, -1461, -972, -1524, + -999, -1222, -1020, -1172, + -815, -987, -992, -1371, + -1216, -1006, -1289, -1094, + -744, -1268, -755, -1293, + -862, -923, -905, -984, + -678, -1051, -685, -1050, + -1087, -985, -1062, -679, + -989, -641, -1127, -976, + -762, -654, -890, -806, + -833, -1091, -706, -629, + -621, -806, -640, -812, + -775, -634, -779, -543, + -996, -565, -1075, -580, + -546, -611, -572, -619, + -760, -290, -879, -526, + -823, -462, -795, -253, + -553, -415, -589, -439, + -533, -340, -692, -935, + -505, -772, -702, -1131, + -263, -306, -971, -483, + -445, -74, -555, -548, + -614, -129, -693, -234, + -396, -246, -475, -250, + -265, -404, -376, -514, + -417, -510, -300, -313, + -334, -664, -463, -814, + -386, -704, -337, -615, + -234, -201, -233, -239, + -167, -567, -203, -619, + -147, -415, -115, -352, + -166, -750, -171, -761, + -270, -879, -264, -903, + -367, -744, 43, -475, + 14, -653, 43, -670, + 11, -448, -59, -521, + -126, -119, -155, -613, + -42, -863, -27, -931, + 136, -483, 183, -468, + 55, -298, 55, -304, + 313, -609, 313, -720, + 322, -167, 100, -541, + -3, -119, -111, -187, + 233, -236, 260, -234, + 26, -165, 134, -45, + -40, -549, 360, -203, + 378, -388, 450, -383, + 275, 20, 182, -103, + 246, -111, 431, 37, + 462, -146, 487, -157, + -284, -59, 503, -184, + 24, 53, -3, 54, + 122, 259, 333, 66, + 484, 104, 436, 68, + 195, 116, 190, 206, + 269, -9, 482, 352, + 382, 285, 399, 277, + 452, 256, 69, 186, + 13, 297, -13, 259, + -95, 30, 56, 394, + 196, 425, 205, 456, + 281, 577, 15, 191, + 375, 290, 407, 576, + -56, 227, 544, 405, + 0, 549, -92, 528, + -229, 351, -245, 338, + -362, 435, 167, 527, + -75, 302, 91, 824, + 129, 599, 496, 679, + 186, 749, 153, 737, + -281, 600, -348, 615, + -236, 769, 41, 881, + 38, 890, -220, 841, + -357, 883, -393, 903, + -634, 474, -444, 850, + -175, 678, -493, 242, + -519, 785, -714, 582, + -541, 366, -543, 434, + -597, 500, -765, 222, + -702, 917, -743, 962, + -869, 501, -899, 548, + -379, 200, -435, 157, + -819, 214, -861, 157, + -614, 40, -632, 94, + -883, -54, -741, 516, + -501, 298, -614, -171, + -870, -161, -865, -23, + -818, 93, -1015, -267, + -662, -359, -549, 2, + -442, -121, -377, 0, + -227, 33, -414, -126, + -129, 212, -934, 34, + -1082, -282, -1119, -268, + -710, -825, -420, -191, + -1076, -928, -917, -93, + -628, -358, 97, 7, + -206, -393, -101, 24, + -203, 38, -168, 83, + -599, -423, -279, 426, + -700, 118, -75, 206, + -981, -673, -680, 417, + -367, 37, -279, 474, + -129, -318, 319, 296, + -626, -39, 343, 602, + -696, -39, -303, 940, + 104, 233, -380, 137, + -36, 269, -75, -214, + 120, 43, -529, -477, + 459, 164, -202, -229, + -49, -167, 609, 792, + 98, -220, 915, 148, + 293, 283, 869, 91, + 575, 394, 326, -78, + 717, 67, 365, -323, + 616, -36, 731, 27, + 619, 238, 632, 273, + 448, 99, 801, 476, + 869, 273, 685, 64, + 789, 72, 1021, 217, + 793, 459, 734, 360, + 646, 480, 360, 322, + 429, 464, 638, 430, + 756, 363, 1000, 404, + 683, 528, 602, 615, + 655, 413, 946, 687, + 937, 602, 904, 604, + 555, 737, 786, 662, + 467, 654, 362, 589, + 929, 710, 498, 478, + 415, 420, 693, 883, + 813, 683, 781, 925, + 913, 939, 726, 732, + 491, 853, 531, 948, + 734, 963, 315, 808, + 761, 755, 1144, 760, + 655, 1076, 826, 1057, + 1091, 838, 1003, 808, + 1047, 1133, 659, 1101, + 992, 1050, 1074, 1075, + 971, 694, 1226, 1054, + 571, 841, 884, 1404, + 1379, 1096, 1080, 861, + 1231, 735, 1284, 760, + 1272, 991, 1367, 1053, + 1257, 700, 1050, 534, + 988, 453, 1264, 599, + 1140, 679, 1621, 815, + 1384, 521, 1317, 393, + 1564, 805, 1448, 686, + 1068, 648, 875, 307, + 1083, 361, 1047, 317, + 1417, 964, 675, 571, + 1152, 79, 1114, -47, + 1530, 311, 1721, 314, + 1166, 689, 514, -94, + 349, 282, 1412, 328, + 1025, 487, -65, 57, + 805, 970, 36, 62, + 769, -263, 791, -346, + 637, 699, -137, 620, + 534, 541, -735, 194, + 711, 300, -268, -863, + 926, 769, -708, -428, + 506, 174, -892, -630, + 435, 547, -1435, -258, + 621, 471, -1018, -1368, + -393, 521, -920, -686, + -25, 20, -982, -1156, + 340, 9, -1558, -1135, + -352, 48, -1579, -402, + -887, 6, -1156, -888, + -548, -352, -1643, -1168, + -159, 610, -2024, -963, + -225, 193, -1656, -1960, + -245, -493, -964, -1680, + -936, -635, -1299, -1744, + -1388, -604, -1540, -835, + -1397, -135, -1588, -290, + -1670, -712, -2011, -1632, + -1663, -27, -2258, -811, + -1157, 184, -1265, 189, + -1367, 586, -2011, 201, + -790, 712, -1210, 3, + -1033, 808, -1251, 830, + -111, 635, -1636, 447, + -463, -949, -445, -928, + -504, -1162, -501, -1211, + 144, -351, -372, -1052, + -283, -1059, -279, -1123, + -575, -1438, -587, -1614, + -935, -984, 229, 690, + -921, -719, -403, 1362, + -685, -465, 874, 397, + -509, -46, 317, 1334, + -485, 456, 813, 439, + -411, 339, 898, 1067, + -425, 46, 1441, 497, + -909, -800, 1465, 1046, + -254, -321, 1430, 1165, + 68, 350, 1034, 666, + 370, 11, 1311, 790, + 143, 232, 1041, 1562, + -114, 663, 1616, 1078, + 454, 579, 1275, 1040, + -76, 909, 752, 1067, + 153, 512, 348, 1214, + 614, 385, 1843, 808, + 269, 1034, 203, 1086, + 652, 1017, 1783, 1130, + 429, 1327, 387, 1384, + -49, 1183, -72, 1215, + -416, 1001, 544, 1749, + -352, 1223, -502, 1199, + -589, 569, -227, 1630, + -142, 1578, -230, 1715, + -714, 1288, -838, 1398, + 1131, 1357, -208, 1232, + 437, 965, -929, 818, + 811, 1410, 859, 1507, + 164, 1212, 1387, 1793, + 484, 1874, 456, 2063, + 996, 1170, 1326, 1402, + 1316, 1360, 1135, 1262, + 1234, 1618, 1361, 1768, + 1421, 1227, 1584, 1347, + 854, 672, 1685, 1566, + 1139, 1270, 2016, 1825, + 1773, 1581, 1532, 1460, + 1487, 946, 1659, 1021, + 1744, 1212, 1392, 977, + 1772, 1161, 1826, 1164, + 1718, 1429, 1973, 1591, + 1185, 864, 2132, 1061, + 1799, 814, 1838, 757, + 2104, 1315, 2054, 1258, + 2113, 915, 2331, 930, + 1467, 1147, 2590, 1439, + 2245, 1744, 2090, 1620, + 2358, 1454, 2666, 1506, + 1876, 1837, 2070, 1975, + 1739, 1577, 682, 1289, + 1584, 2045, 1454, 2098, + 2498, 2004, 2711, 2066, + 726, 1588, 2756, 2336, + 228, 847, 2456, 1659, + 36, 301, 1942, 1957, + -446, -96, 2154, 1396, + 1533, 1101, 14, 608, + -923, -732, 1383, 1982, + 1345, 952, -680, 321, + 1281, 1268, -1594, 365, + 941, 946, -1737, -822, + 2374, 2787, 1821, 2788 + }; + + const Word16 dico3_lsf_5[DICO3_5_SIZE * 4] = + { + -1812, -2275, -1879, -2537, + -1640, -1848, -1695, -2004, + -1220, -1912, -1221, -2106, + -1559, -1588, -1573, -1556, + -1195, -1615, -1224, -1727, + -1359, -1151, -1616, -1948, + -1274, -1391, -1305, -1403, + -1607, -1179, -1676, -1311, + -1443, -1478, -1367, -898, + -1256, -1059, -1331, -1134, + -982, -1133, -1149, -1504, + -1080, -1308, -1020, -1183, + -980, -1486, -967, -1495, + -988, -922, -1047, -1077, + -838, -1179, -858, -1222, + -1131, -1041, -1064, -767, + -872, -1157, -701, -880, + -706, -906, -774, -1016, + -578, -1080, -801, -1478, + -591, -1111, -592, -1146, + -713, -1388, -640, -1376, + -597, -1059, -416, -903, + -686, -832, -661, -708, + -444, -868, -490, -921, + -374, -776, -619, -1170, + -585, -549, -769, -795, + -435, -659, -530, -741, + -498, -837, -357, -597, + -279, -871, -243, -887, + -282, -665, -280, -667, + -165, -560, -394, -903, + -362, -410, -448, -583, + -409, -574, -313, -357, + -637, -548, -570, -436, + -896, -504, -382, -757, + -58, -481, -165, -618, + -191, -374, -234, -382, + -222, -683, -25, -480, + -418, -359, -730, -353, + -324, -157, -432, -322, + -394, -303, -284, -104, + -601, -289, -556, -196, + -588, -150, -659, -608, + -473, -24, -68, -448, + -474, -8, -506, -45, + -748, -184, -844, -252, + -901, -91, -584, -97, + -652, 138, -764, -131, + -678, -12, -670, 165, + -259, -3, -840, -107, + -909, 37, -992, 44, + -854, -415, -839, 13, + -1001, -271, -1026, -309, + -798, -478, -832, -488, + -943, 168, -1112, -387, + -1185, -101, -1183, -40, + -941, -316, -1030, -770, + -1044, -625, -1081, -538, + -1224, -299, -1312, -436, + -1197, -663, -1167, -161, + -1216, -690, -1237, -831, + -1432, -720, -1403, -493, + -898, -740, -922, -801, + -1102, -402, -1579, -964, + -1061, -638, -1269, -1438, + -1499, -934, -1502, -895, + -1598, -564, -1723, -717, + -606, -597, -1166, -1085, + -1369, -468, -1946, -1493, + -1838, -953, -1932, -931, + -1499, -188, -1635, -421, + -1457, -338, -1448, -22, + -1942, -422, -2006, -249, + -496, -114, -1910, -755, + -1289, 174, -1451, -109, + -482, -257, -1221, -508, + -1617, 151, -1694, 208, + -654, 107, -1651, 29, + -1141, 279, -1215, 306, + -1228, -506, -730, -175, + -1236, -101, -969, 551, + -870, 278, -823, 315, + -563, 376, -1051, 228, + -507, 280, -599, 281, + -758, 253, -305, 379, + -755, -134, -611, 660, + -824, 536, -817, 646, + -413, 49, -341, 177, + -453, 526, -482, 589, + -71, 339, -657, 264, + -244, 295, -237, 315, + -387, 569, -506, -9, + -377, 14, -160, 661, + -216, 40, -308, -46, + 95, 214, -242, 167, + -86, 192, -56, 27, + -76, 31, 36, 309, + -106, -182, -113, 74, + -441, -22, 23, 139, + 81, -11, 44, 15, + -87, -137, -118, -207, + -158, -58, 272, -92, + -156, -441, 8, -136, + 128, -221, 101, -218, + 40, -197, -76, -456, + 9, -445, 33, -423, + 226, 60, 73, -222, + 156, -399, 280, -318, + 245, -341, 166, -499, + 339, -190, 327, -219, + 325, -137, -89, -596, + 100, -627, 144, -677, + 487, 28, 252, -391, + 214, -41, 282, -28, + 99, -286, 331, 49, + 459, -388, 565, -369, + 436, 28, 336, -9, + 397, -167, 618, 34, + 596, -17, 561, -140, + 299, 79, 522, 125, + 203, 2, 244, 288, + 255, 211, 175, 82, + 596, 187, 517, 108, + 381, 255, 365, 297, + 497, 352, 327, -82, + 25, 210, 371, 245, + 261, 3, 545, 449, + 140, 294, 44, 295, + 212, 347, 244, 494, + 331, 528, 201, 307, + 349, 411, 613, 284, + 614, 413, 464, 322, + 624, 397, 97, 200, + -160, 384, 149, 362, + 495, 525, 269, 585, + 33, 491, -121, 433, + 427, 611, 498, 516, + 171, 443, 497, 666, + 440, 275, 566, 575, + 146, 639, 155, 670, + -33, 173, 212, 696, + -166, 601, -191, 695, + -489, 503, 175, 742, + 214, 476, 372, 1083, + 578, 530, 586, 777, + 425, 874, 315, 841, + 374, 848, -165, 565, + 35, 991, -39, 1062, + 329, 712, 786, 840, + 645, 795, 661, 676, + 571, 918, 632, 1079, + 673, 817, 318, 388, + 874, 1012, 564, 848, + 880, 620, 557, 479, + 671, 453, 692, 468, + 840, 642, 844, 645, + 506, 428, 897, 567, + 837, 387, 962, 499, + 691, 561, 939, 926, + 783, 296, 790, 268, + 1028, 530, 874, 329, + 548, 143, 675, 291, + 503, 66, 1041, 359, + 786, 97, 805, 33, + 837, 470, 511, 49, + 1092, 327, 1174, 323, + 3, 242, 872, 474, + 689, 429, 1329, 678, + 1042, 620, 1109, 664, + 321, 193, 889, 950, + 1153, 874, 893, 635, + 877, 862, 948, 913, + 1293, 665, 1320, 639, + 997, 793, 1402, 1030, + 1176, 1012, 1110, 959, + 1410, 925, 1403, 915, + 543, 862, 1116, 1222, + 835, 1190, 835, 1190, + 959, 1148, 1147, 1376, + 1300, 1193, 1415, 1231, + 1335, 1341, 746, 1092, + 1711, 1283, 1389, 1073, + 1334, 1566, 1153, 1475, + 1645, 1137, 1825, 1220, + 1056, 1382, 1521, 1730, + 1632, 1545, 1620, 1542, + 855, 1596, 865, 1667, + 693, 885, 1716, 1519, + 1167, 1296, 2209, 1760, + 1952, 1493, 2020, 1482, + 1534, 1866, 1694, 2008, + 1566, 748, 1761, 825, + 294, 1392, 1084, 2058, + 621, 1315, 365, 1287, + 198, 1028, 488, 1408, + 249, 403, 1014, 1561, + 324, 363, 1645, 1044, + 193, 367, 2034, 1859, + -251, 579, 750, 994, + -243, 30, 1325, 879, + -28, -169, 624, 917, + -453, 159, 186, 1370, + -614, 6, 537, 392, + -94, -291, 781, 229, + -128, -298, 245, 491, + -701, -648, 972, 789, + -501, -640, 178, 255, + -365, -390, -255, 317, + -958, -294, -191, 228, + -775, -447, 157, -237, + -657, -720, -407, 92, + -117, -611, 334, -230, + -679, -1084, -144, -317, + -901, -861, -738, -360, + -85, -727, -90, -787, + 100, -22, -391, -263, + -56, -73, -337, -754, + 5, -189, -706, -624, + 89, -344, -135, -1113, + -353, -237, -684, -1135, + -275, -1102, -269, -1203, + 152, 145, -722, -1232, + 49, 80, -1248, -776, + -248, 391, -732, -547, + 469, 218, -255, -864, + 69, 366, -166, -485, + -688, 191, -1212, -1196, + -170, -169, -1308, -1631, + 321, 470, -1419, -1243, + -64, 272, -1361, -248, + 492, 565, -721, -609, + 195, 485, -573, -133, + 427, 202, -171, -118, + 199, 575, 2, -31, + 694, 755, -1366, -39, + 552, 557, -489, 271, + 680, 537, 13, -453, + 855, 954, -133, -52, + -81, 738, -1169, 637, + 1055, 1059, -95, 676, + 1259, 1081, 489, 305, + -449, 954, -534, 996, + -969, 866, -1058, 1059, + -1294, 618, -1416, 617, + -458, 1366, -159, 1821, + -774, -528, -14, 1110, + -1202, -901, -772, 433, + -1256, -1255, -1011, -302, + -602, -585, -759, -1618, + -760, -1549, -840, -1921, + -816, -539, -1769, -2235, + -227, -36, -2034, -1831, + -2107, -1126, -2471, -1816, + -1470, 252, -2701, -415, + -571, -467, 1509, 1554, + 2180, 1975, 2326, 2020 + }; + + const Word16 dico4_lsf_5[DICO4_5_SIZE * 4] = + { + -1857, -1681, -1857, -1755, + -2056, -1150, -2134, -1654, + -1619, -1099, -1704, -1131, + -1345, -1608, -1359, -1638, + -1338, -1293, -1325, -1265, + -1664, -1649, -1487, -851, + -1346, -1832, -1413, -2188, + -1282, -681, -1785, -1649, + -966, -1082, -1183, -1676, + -1054, -1073, -1142, -1158, + -1207, -744, -1274, -997, + -934, -1383, -927, -1416, + -1010, -1305, -783, -955, + -1049, -900, -993, -817, + -737, -823, -972, -1189, + -738, -1094, -738, -1154, + -784, -801, -810, -786, + -892, -520, -1000, -818, + -644, -965, -577, -882, + -541, -694, -671, -917, + -595, -642, -646, -615, + -956, -621, -925, -515, + -727, -483, -815, -485, + -840, -578, -440, -713, + -578, -325, -657, -670, + -386, -570, -441, -666, + -514, -787, -392, -529, + -522, -453, -487, -423, + -616, -585, -617, -157, + -662, -268, -680, -348, + -322, -323, -632, -444, + -304, -430, -332, -458, + -277, -468, -659, -793, + -319, -636, -227, -554, + -373, -347, -334, -210, + -456, -192, -530, -242, + -216, -198, -366, -370, + -338, -161, -409, -748, + -107, -380, -294, -643, + -223, -665, -234, -741, + -141, -496, -130, -510, + -139, -327, -172, -305, + -306, -580, -164, -263, + -262, -172, -67, -402, + 31, -366, -10, -436, + -86, -527, 71, -377, + -22, -609, -12, -678, + -67, -319, 63, -191, + 35, -181, -39, -242, + 126, -167, -140, -544, + 155, -297, 174, -297, + 38, -8, 117, -380, + 197, -452, 240, -522, + 223, -103, 110, -187, + 87, -155, 169, -47, + 157, 26, -83, -100, + 128, 80, 209, -62, + 6, 7, 22, 5, + 318, -20, 248, -45, + -200, -63, 156, -69, + 250, -183, 369, -126, + -113, -76, -142, -122, + -64, -254, -31, 35, + -177, -71, -7, 171, + 93, 27, 108, 212, + -330, -209, -123, -70, + -279, 95, -96, 20, + -188, -61, -314, 87, + -300, -78, -354, -134, + 11, 122, -140, 122, + -275, 152, -293, 140, + -82, 138, -321, -111, + -480, -156, -359, 76, + -254, -40, -635, -96, + -522, 79, -507, 8, + -268, 303, -539, 68, + -446, 61, -522, 306, + 111, 189, -435, 122, + -379, 166, -571, -398, + -632, -74, -747, -95, + -455, 194, -952, 83, + -798, 192, -755, 192, + -781, -162, -619, 234, + -663, -297, -488, -109, + -964, -132, -838, -68, + -843, 58, -1112, -86, + -805, -299, -944, -253, + -778, -50, -965, -549, + -352, -98, -992, -343, + -1117, -315, -1117, -307, + -1155, -374, -637, -230, + -1166, -43, -1299, -100, + -925, -393, -1274, -600, + -689, -130, -1479, -312, + -1321, -254, -1464, -442, + -1292, -613, -1261, -503, + -1501, -368, -1322, 26, + -1432, -66, -1743, -161, + -1644, -467, -1760, -548, + -1393, -568, -1556, -871, + -1495, -1034, -1387, -571, + -1917, -528, -1783, -123, + -1897, -231, -2054, -323, + -2052, -906, -1976, -567, + -1917, -620, -2047, -989, + -1077, -370, -2031, -704, + -2355, -749, -2740, -1089, + -1909, 159, -2012, 248, + -626, -123, -2339, -962, + -669, -408, -1379, -1174, + -452, -364, -1044, -735, + -132, 183, -1620, -752, + -547, -307, -777, -1261, + -98, 41, -880, -1091, + -257, 97, -1602, -1833, + 31, -26, -644, -561, + -180, -546, -385, -1095, + -410, -802, -414, -827, + -457, -970, -490, -1109, + -215, -916, -144, -937, + -493, -1269, -517, -1507, + 181, 101, -332, -889, + -836, -937, -559, -429, + -629, -547, -183, -337, + -545, -82, -250, -286, + 5, -132, -348, -252, + -293, -472, -158, 100, + -29, 197, -236, -424, + -861, -213, -140, -7, + -427, -443, 187, -97, + -684, -736, -293, 258, + -368, -152, -150, 392, + -609, 175, -142, 299, + -138, 152, -119, 329, + -486, -52, 293, 198, + -183, 117, 175, 331, + -58, -274, 231, 300, + -288, 330, -305, 372, + -111, 409, -9, 423, + 83, 256, 67, 367, + -19, 248, 91, 113, + -35, 406, -191, 154, + 238, 296, 5, 197, + 141, 221, 313, 198, + 211, 421, 244, 334, + 88, 426, -243, 454, + 202, 552, -5, 403, + 291, 185, 219, 301, + 251, 138, 128, 69, + 197, 288, -140, -61, + 188, 361, 197, 598, + 442, 273, 290, 143, + 472, 482, 157, 370, + 415, 321, 372, 385, + 402, 552, 155, 24, + 550, 263, -11, 21, + 360, 227, 147, -254, + 424, 97, 366, -13, + 375, 141, 449, 232, + 396, 507, 474, 272, + 701, 324, 362, -47, + 587, 148, 543, 69, + 400, -51, 561, 59, + 220, -10, 352, 147, + 206, 211, 653, 185, + 563, 297, 565, 284, + 594, 121, 766, 192, + 398, 118, 642, 434, + 233, 264, 481, 467, + 129, -165, 699, 239, + 90, 26, 342, 474, + -55, 27, 388, 94, + -172, 0, 725, 379, + -60, 337, 370, 465, + 95, 319, 806, 595, + 78, 260, 497, 851, + 210, 560, 458, 574, + -464, 202, 497, 625, + -202, 152, 48, 712, + -20, 566, 100, 715, + 455, 468, 411, 605, + 319, 646, 195, 615, + 401, 538, 680, 739, + 201, 667, 434, 954, + 454, 425, 646, 491, + 606, 681, 416, 508, + 497, 822, 426, 815, + 660, 647, 628, 716, + 697, 466, 618, 457, + 685, 460, 365, 309, + 721, 567, 836, 601, + 609, 300, 825, 459, + 943, 687, 681, 533, + 915, 598, 591, 243, + 876, 451, 874, 420, + 786, 317, 732, 220, + 922, 317, 1108, 367, + 531, 466, 1028, 649, + 1053, 615, 1034, 553, + 829, 602, 1021, 799, + 927, 803, 878, 763, + 799, 496, 1373, 773, + 585, 770, 803, 930, + 1099, 793, 1222, 862, + 1209, 895, 1025, 727, + 772, 845, 1172, 1115, + 867, 1021, 830, 1013, + 841, 910, 506, 703, + 1239, 1077, 620, 819, + 1196, 1083, 1155, 1081, + 1142, 907, 1547, 1121, + 1309, 648, 1343, 612, + 1484, 988, 1479, 937, + 985, 1328, 955, 1341, + 429, 910, 841, 1338, + 564, 1179, 412, 1156, + 1427, 1320, 1434, 1330, + 640, 760, 1726, 1410, + 190, 555, 1073, 1005, + 426, 257, 839, 980, + 235, 231, 1520, 1167, + 109, 293, 1014, 1569, + 305, 142, 1148, 539, + -291, -108, 1213, 972, + 22, -216, 667, 828, + -482, 438, 453, 1431, + -581, -422, 789, 387, + -358, -454, 174, 780, + -36, -372, 390, -134, + -629, 160, -306, 751, + -1258, -331, 177, 522, + -248, 574, -251, 639, + -531, 407, -596, 394, + -419, 789, -617, 801, + -986, 399, -857, 727, + -7, 518, -703, 310, + -1143, -24, -1002, 287, + -960, 363, -1299, 312, + -1534, 245, -1557, 305, + 28, 153, -859, -175, + -33, 332, -1398, -154, + 212, 410, -593, -197, + -1092, -704, -904, -65, + 282, 367, -918, -686, + 345, 93, -258, -357, + 696, 644, -693, -28, + 448, 493, -273, 193, + 527, 546, -243, -513, + 384, -136, 273, -353, + 512, -142, 537, -198, + 941, 750, 83, 248, + 578, 861, -56, 592, + 842, 44, 892, 24, + 33, 890, -16, 982, + 831, 1398, 1535, 1898, + 1716, 1376, 1948, 1465 + }; + + const Word16 dico5_lsf_5[DICO5_5_SIZE * 4] = + { + -1002, -929, -1096, -1203, + -641, -931, -604, -961, + -779, -673, -835, -788, + -416, -664, -458, -766, + -652, -521, -662, -495, + -1023, -509, -1023, -428, + -444, -552, -368, -449, + -479, -211, -1054, -903, + -316, -249, -569, -591, + -569, -275, -541, -191, + -716, -188, -842, -264, + -333, -248, -318, -228, + -275, 1, -567, -228, + -115, -221, -238, -374, + -197, -507, -222, -579, + -258, -432, -61, -244, + -345, 2, -338, 39, + -215, -169, -58, 0, + -56, -6, -203, -131, + 1, -186, -5, -211, + 6, -380, 11, -418, + -116, 131, -134, 113, + 89, -4, 71, -2, + -19, -192, 262, 24, + 189, 151, -133, -109, + 186, -153, 166, -219, + 37, 139, 193, 171, + 337, 124, 158, -61, + 141, 226, -13, 190, + 231, 34, 354, 109, + 316, 201, 244, 164, + 330, -85, 390, -84, + 254, 327, 257, 335, + 491, 147, 476, 105, + 54, 77, 437, 370, + 421, 314, 449, 342, + 329, 126, 673, 292, + 571, 388, 243, 193, + 653, 320, 621, 280, + 194, 380, 517, 581, + 45, 323, 111, 422, + 489, 395, 734, 534, + 622, 546, 486, 502, + 318, 572, 189, 550, + 385, 422, -157, 153, + -125, 382, -197, 386, + -263, 334, 228, 697, + -188, 1, 51, 297, + -507, 213, -376, 397, + -24, 255, -547, 89, + -502, -94, 387, 179, + -620, 68, -684, 112, + -642, -350, -260, 172, + -438, -324, 264, 648, + -964, -4, -1121, 7, + -134, 134, -1133, -306, + 143, 96, -420, -497, + -1221, -350, -1527, -685, + -161, 72, 873, 691, + 732, 283, 921, 353, + 334, 475, 1095, 821, + 864, 524, 843, 497, + 714, 711, 788, 750, + 1076, 714, 1204, 753 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] q_plsf_5.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/qua_gain_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/qua_gain_tbl.cpp new file mode 100644 index 0000000..c0470b7 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/qua_gain_tbl.cpp @@ -0,0 +1,361 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: qua_gain_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "qua_gain_tbl.h" +#include "qua_gain.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + + /* The tables contains the following data: + * + * g_pitch (Q14), + * g_fac (Q12), (g_code = g_code0*g_fac), + * qua_ener_MR122 (Q10), (log2(g_fac)) + * qua_ener (Q10) (20*log10(g_fac)) + * + * The log2() and log10() values are calculated on the fixed point value + * (g_fac Q12) and not on the original floating point value of g_fac + * to make the quantizer/MA predictdor use corresponding values. + */ + + /* table used in 'high' rates: MR67 MR74 */ + + const Word16 table_gain_highrates[VQ_SIZE_HIGHRATES*4] = + { + + /* + * Note: column 4 (qua_ener) contains the original values from IS641 + * to ensure bit-exactness; however, they are not exactly the + * rounded value of (20*log10(g_fac)) + * + */ + + /*g_pit, g_fac, qua_ener_MR122, qua_ener */ + 577, 662, -2692, -16214, + 806, 1836, -1185, -7135, + 3109, 1052, -2008, -12086, + 4181, 1387, -1600, -9629, + 2373, 1425, -1560, -9394, + 3248, 1985, -1070, -6442, + 1827, 2320, -840, -5056, + 941, 3314, -313, -1885, + 2351, 2977, -471, -2838, + 3616, 2420, -777, -4681, + 3451, 3096, -414, -2490, + 2955, 4301, 72, 434, + 1848, 4500, 139, 836, + 3884, 5416, 413, 2484, + 1187, 7210, 835, 5030, + 3083, 9000, 1163, 7002, + 7384, 883, -2267, -13647, + 5962, 1506, -1478, -8900, + 5155, 2134, -963, -5800, + 7944, 2009, -1052, -6335, + 6507, 2250, -885, -5327, + 7670, 2752, -588, -3537, + 5952, 3016, -452, -2724, + 4898, 3764, -125, -751, + 6989, 3588, -196, -1177, + 8174, 3978, -43, -260, + 6064, 4404, 107, 645, + 7709, 5087, 320, 1928, + 5523, 6021, 569, 3426, + 7769, 7126, 818, 4926, + 6060, 7938, 977, 5885, + 5594, 11487, 1523, 9172, + 10581, 1356, -1633, -9831, + 9049, 1597, -1391, -8380, + 9794, 2035, -1033, -6220, + 8946, 2415, -780, -4700, + 10296, 2584, -681, -4099, + 9407, 2734, -597, -3595, + 8700, 3218, -356, -2144, + 9757, 3395, -277, -1669, + 10177, 3892, -75, -454, + 9170, 4528, 148, 891, + 10152, 5004, 296, 1781, + 9114, 5735, 497, 2993, + 10500, 6266, 628, 3782, + 10110, 7631, 919, 5534, + 8844, 8727, 1117, 6728, + 8956, 12496, 1648, 9921, + 12924, 976, -2119, -12753, + 11435, 1755, -1252, -7539, + 12138, 2328, -835, -5024, + 11388, 2368, -810, -4872, + 10700, 3064, -429, -2580, + 12332, 2861, -530, -3192, + 11722, 3327, -307, -1848, + 11270, 3700, -150, -904, + 10861, 4413, 110, 663, + 12082, 4533, 150, 902, + 11283, 5205, 354, 2132, + 11960, 6305, 637, 3837, + 11167, 7534, 900, 5420, + 12128, 8329, 1049, 6312, + 10969, 10777, 1429, 8604, + 10300, 17376, 2135, 12853, + 13899, 1681, -1316, -7921, + 12580, 2045, -1026, -6179, + 13265, 2439, -766, -4610, + 14033, 2989, -465, -2802, + 13452, 3098, -413, -2482, + 12396, 3658, -167, -1006, + 13510, 3780, -119, -713, + 12880, 4272, 62, 374, + 13533, 4861, 253, 1523, + 12667, 5457, 424, 2552, + 13854, 6106, 590, 3551, + 13031, 6483, 678, 4084, + 13557, 7721, 937, 5639, + 12957, 9311, 1213, 7304, + 13714, 11551, 1532, 9221, + 12591, 15206, 1938, 11667, + 15113, 1540, -1445, -8700, + 15072, 2333, -832, -5007, + 14527, 2511, -723, -4352, + 14692, 3199, -365, -2197, + 15382, 3560, -207, -1247, + 14133, 3960, -50, -300, + 15102, 4236, 50, 298, + 14332, 4824, 242, 1454, + 14846, 5451, 422, 2542, + 15306, 6083, 584, 3518, + 14329, 6888, 768, 4623, + 15060, 7689, 930, 5602, + 14406, 9426, 1231, 7413, + 15387, 9741, 1280, 7706, + 14824, 14271, 1844, 11102, + 13600, 24939, 2669, 16067, + 16396, 1969, -1082, -6517, + 16817, 2832, -545, -3283, + 15713, 2843, -539, -3248, + 16104, 3336, -303, -1825, + 16384, 3963, -49, -294, + 16940, 4579, 165, 992, + 15711, 4599, 171, 1030, + 16222, 5448, 421, 2537, + 16832, 6382, 655, 3945, + 15745, 7141, 821, 4944, + 16326, 7469, 888, 5343, + 16611, 8624, 1100, 6622, + 17028, 10418, 1379, 8303, + 15905, 11817, 1565, 9423, + 16878, 14690, 1887, 11360, + 16515, 20870, 2406, 14483, + 18142, 2083, -999, -6013, + 19401, 3178, -375, -2257, + 17508, 3426, -264, -1589, + 20054, 4027, -25, -151, + 18069, 4249, 54, 326, + 18952, 5066, 314, 1890, + 17711, 5402, 409, 2461, + 19835, 6192, 610, 3676, + 17950, 7014, 795, 4784, + 21318, 7877, 966, 5816, + 17910, 9289, 1210, 7283, + 19144, 9290, 1210, 7284, + 20517, 11381, 1510, 9089, + 18075, 14485, 1866, 11234, + 19999, 17882, 2177, 13108, + 18842, 32764, 3072, 18494 + }; + + + /* table used in 'low' rates: MR475, MR515, MR59 */ + + const Word16 table_gain_lowrates[VQ_SIZE_LOWRATES*4] = + { + /*g_pit, g_fac, qua_ener_MR122, qua_ener */ + 10813, 28753, 2879, 17333, + 20480, 2785, -570, -3431, + 18841, 6594, 703, 4235, + 6225, 7413, 876, 5276, + 17203, 10444, 1383, 8325, + 21626, 1269, -1731, -10422, + 21135, 4423, 113, 683, + 11304, 1556, -1430, -8609, + 19005, 12820, 1686, 10148, + 17367, 2498, -731, -4398, + 17858, 4833, 244, 1472, + 9994, 2498, -731, -4398, + 17530, 7864, 964, 5802, + 14254, 1884, -1147, -6907, + 15892, 3153, -387, -2327, + 6717, 1802, -1213, -7303, + 18186, 20193, 2357, 14189, + 18022, 3031, -445, -2678, + 16711, 5857, 528, 3181, + 8847, 4014, -30, -180, + 15892, 8970, 1158, 6972, + 18022, 1392, -1594, -9599, + 16711, 4096, 0, 0, + 8192, 655, -2708, -16305, + 15237, 13926, 1808, 10884, + 14254, 3112, -406, -2444, + 14090, 4669, 193, 1165, + 5406, 2703, -614, -3697, + 13434, 6553, 694, 4180, + 12451, 901, -2237, -13468, + 12451, 2662, -637, -3833, + 3768, 655, -2708, -16305, + 14745, 23511, 2582, 15543, + 19169, 2457, -755, -4546, + 20152, 5079, 318, 1913, + 6881, 4096, 0, 0, + 20480, 8560, 1089, 6556, + 19660, 737, -2534, -15255, + 19005, 4259, 58, 347, + 7864, 2088, -995, -5993, + 11468, 12288, 1623, 9771, + 15892, 1474, -1510, -9090, + 15728, 4628, 180, 1086, + 9175, 1433, -1552, -9341, + 16056, 7004, 793, 4772, + 14827, 737, -2534, -15255, + 15073, 2252, -884, -5321, + 5079, 1228, -1780, -10714, + 13271, 17326, 2131, 12827, + 16547, 2334, -831, -5002, + 15073, 5816, 518, 3118, + 3932, 3686, -156, -938, + 14254, 8601, 1096, 6598, + 16875, 778, -2454, -14774, + 15073, 3809, -107, -646, + 6062, 614, -2804, -16879, + 9338, 9256, 1204, 7251, + 13271, 1761, -1247, -7508, + 13271, 3522, -223, -1343, + 2457, 1966, -1084, -6529, + 11468, 5529, 443, 2668, + 10485, 737, -2534, -15255, + 11632, 3194, -367, -2212, + 1474, 778, -2454, -14774 + }; + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] qua_gain.tab, UMTS GSM AMR speech codec, + R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + + + + + + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/r_fft.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/r_fft.cpp new file mode 100644 index 0000000..a528838 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/r_fft.cpp @@ -0,0 +1,570 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: r_fft.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" +#include "oper_32b.h" +#include "vad2.h" +#include "sub.h" +#include "add.h" +#include "shr.h" +#include "shl.h" +#include "l_mult.h" +#include "l_mac.h" +#include "l_msu.h" +#include "round.h" +#include "l_negate.h" +#include "l_deposit_h.h" +#include "l_shr.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ +#define SIZE 128 +#define SIZE_BY_TWO 64 +#define NUM_STAGE 6 +#define TRUE 1 +#define FALSE 0 + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +const Word16 phs_tbl[] = +{ + + 32767, 0, 32729, -1608, 32610, -3212, 32413, -4808, + 32138, -6393, 31786, -7962, 31357, -9512, 30853, -11039, + 30274, -12540, 29622, -14010, 28899, -15447, 28106, -16846, + 27246, -18205, 26320, -19520, 25330, -20788, 24279, -22006, + 23170, -23170, 22006, -24279, 20788, -25330, 19520, -26320, + 18205, -27246, 16846, -28106, 15447, -28899, 14010, -29622, + 12540, -30274, 11039, -30853, 9512, -31357, 7962, -31786, + 6393, -32138, 4808, -32413, 3212, -32610, 1608, -32729, + 0, -32768, -1608, -32729, -3212, -32610, -4808, -32413, + -6393, -32138, -7962, -31786, -9512, -31357, -11039, -30853, + -12540, -30274, -14010, -29622, -15447, -28899, -16846, -28106, + -18205, -27246, -19520, -26320, -20788, -25330, -22006, -24279, + -23170, -23170, -24279, -22006, -25330, -20788, -26320, -19520, + -27246, -18205, -28106, -16846, -28899, -15447, -29622, -14010, + -30274, -12540, -30853, -11039, -31357, -9512, -31786, -7962, + -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 + +}; + +const Word16 ii_table[] = + {SIZE / 2, SIZE / 4, SIZE / 8, SIZE / 16, SIZE / 32, SIZE / 64}; + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: c_fft +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + farray_ptr = pointer to complex array that the FFT operates on of type + Word16. + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow = 1 if the math functions called by cor_h_x2 result in overflow + else zero. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This is an implementation of decimation-in-time FFT algorithm for + real sequences. The techniques used here can be found in several + books, e.g., i) Proakis and Manolakis, "Digital Signal Processing", + 2nd Edition, Chapter 9, and ii) W.H. Press et. al., "Numerical + Recipes in C", 2nd Ediiton, Chapter 12. + + Input - There is one input to this function: + + 1) An integer pointer to the input data array + + Output - There is no return value. + The input data are replaced with transformed data. If the + input is a real time domain sequence, it is replaced with + the complex FFT for positive frequencies. The FFT value + for DC and the foldover frequency are combined to form the + first complex number in the array. The remaining complex + numbers correspond to increasing frequencies. If the input + is a complex frequency domain sequence arranged as above, + it is replaced with the corresponding time domain sequence. + + Notes: + + 1) This function is designed to be a part of a VAD + algorithm that requires 128-point FFT of real + sequences. This is achieved here through a 64-point + complex FFT. Consequently, the FFT size information is + not transmitted explicitly. However, some flexibility + is provided in the function to change the size of the + FFT by specifying the size information through "define" + statements. + + 2) The values of the complex sinusoids used in the FFT + algorithm are stored in a ROM table. + + 3) In the c_fft function, the FFT values are divided by + 2 after each stage of computation thus dividing the + final FFT values by 64. This is somewhat different + from the usual definition of FFT where the factor 1/N, + i.e., 1/64, used for the IFFT and not the FFT. No factor + is used in the r_fft function. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + r_fft.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +The original etsi reference code uses a global flag Overflow. However, in the +actual implementation a pointer to a the overflow flag is passed in. + +void c_fft(Word16 * farray_ptr) +{ + Word16 i, j, k, ii, jj, kk, ji, kj, ii2; + Word32 ftmp, ftmp_real, ftmp_imag; + Word16 tmp, tmp1, tmp2; + + // Rearrange the input array in bit reversed order + for (i = 0, j = 0; i < SIZE - 2; i = i + 2) + { + if (sub(j, i) > 0) + { + ftmp = *(farray_ptr + i); + *(farray_ptr + i) = *(farray_ptr + j); + *(farray_ptr + j) = ftmp; + + ftmp = *(farray_ptr + i + 1); + *(farray_ptr + i + 1) = *(farray_ptr + j + 1); + *(farray_ptr + j + 1) = ftmp; + } + + k = SIZE_BY_TWO; + while (sub(j, k) >= 0) + { + j = sub(j, k); + k = shr(k, 1); + } + j = add(j, k); + } + + // The FFT part + for (i = 0; i < NUM_STAGE; i++) + { // i is stage counter + jj = shl(2, i); // FFT size + kk = shl(jj, 1); // 2 * FFT size + ii = ii_table[i]; // 2 * number of FFT's + ii2 = shl(ii, 1); + ji = 0; // ji is phase table index + + for (j = 0; j < jj; j = j + 2) + { // j is sample counter + + for (k = j; k < SIZE; k = k + kk) + { // k is butterfly top + kj = add(k, jj); // kj is butterfly bottom + + // Butterfly computations + ftmp_real = L_mult(*(farray_ptr + kj), phs_tbl[ji]); + ftmp_real = L_msu(ftmp_real, *(farray_ptr + kj + 1), phs_tbl[ji + 1]); + + ftmp_imag = L_mult(*(farray_ptr + kj + 1), phs_tbl[ji]); + ftmp_imag = L_mac(ftmp_imag, *(farray_ptr + kj), phs_tbl[ji + 1]); + + tmp1 = pv_round(ftmp_real); + tmp2 = pv_round(ftmp_imag); + + tmp = sub(*(farray_ptr + k), tmp1); + *(farray_ptr + kj) = shr(tmp, 1); + + tmp = sub(*(farray_ptr + k + 1), tmp2); + *(farray_ptr + kj + 1) = shr(tmp, 1); + + tmp = add(*(farray_ptr + k), tmp1); + *(farray_ptr + k) = shr(tmp, 1); + + tmp = add(*(farray_ptr + k + 1), tmp2); + *(farray_ptr + k + 1) = shr(tmp, 1); + } + + ji = add(ji, ii2); + } + } +} // end of c_fft () + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/* FFT function for complex sequences */ +/* + * The decimation-in-time complex FFT is implemented below. + * The input complex numbers are presented as real part followed by + * imaginary part for each sample. The counters are therefore + * incremented by two to access the complex valued samples. + */ + +void c_fft(Word16 * farray_ptr, Flag *pOverflow) +{ + + Word16 i; + Word16 j; + Word16 k; + Word16 ii; + Word16 jj; + Word16 kk; + Word16 ji; + Word16 kj; + Word16 ii2; + Word32 ftmp; + Word32 ftmp_real; + Word32 ftmp_imag; + Word16 tmp; + Word16 tmp1; + Word16 tmp2; + + /* Rearrange the input array in bit reversed order */ + for (i = 0, j = 0; i < SIZE - 2; i = i + 2) + { + if (j > i) + { + ftmp = *(farray_ptr + i); + *(farray_ptr + i) = *(farray_ptr + j); + *(farray_ptr + j) = (Word16)ftmp; + + ftmp = *(farray_ptr + i + 1); + *(farray_ptr + i + 1) = *(farray_ptr + j + 1); + *(farray_ptr + j + 1) = (Word16)ftmp; + } + + k = SIZE_BY_TWO; + while (j >= k) + { + j = sub(j, k, pOverflow); + k = shr(k, 1, pOverflow); + } + j = add(j, k, pOverflow); + } + + /* The FFT part */ + for (i = 0; i < NUM_STAGE; i++) + { /* i is stage counter */ + jj = shl(2, i, pOverflow); /* FFT size */ + kk = shl(jj, 1, pOverflow); /* 2 * FFT size */ + ii = ii_table[i]; /* 2 * number of FFT's */ + ii2 = shl(ii, 1, pOverflow); + ji = 0; /* ji is phase table index */ + + for (j = 0; j < jj; j = j + 2) + { /* j is sample counter */ + + for (k = j; k < SIZE; k = k + kk) + { /* k is butterfly top */ + kj = add(k, jj, pOverflow); /* kj is butterfly bottom */ + + /* Butterfly computations */ + ftmp_real = L_mult(*(farray_ptr + kj), phs_tbl[ji], pOverflow); + ftmp_real = L_msu(ftmp_real, *(farray_ptr + kj + 1), + phs_tbl[ji + 1], pOverflow); + + ftmp_imag = L_mult(*(farray_ptr + kj + 1), + phs_tbl[ji], pOverflow); + ftmp_imag = L_mac(ftmp_imag, *(farray_ptr + kj), + phs_tbl[ji + 1], pOverflow); + + tmp1 = pv_round(ftmp_real, pOverflow); + tmp2 = pv_round(ftmp_imag, pOverflow); + + tmp = sub(*(farray_ptr + k), tmp1, pOverflow); + *(farray_ptr + kj) = shr(tmp, 1, pOverflow); + + tmp = sub(*(farray_ptr + k + 1), tmp2, pOverflow); + *(farray_ptr + kj + 1) = shr(tmp, 1, pOverflow); + + tmp = add(*(farray_ptr + k), tmp1, pOverflow); + *(farray_ptr + k) = shr(tmp, 1, pOverflow); + + tmp = add(*(farray_ptr + k + 1), tmp2, pOverflow); + *(farray_ptr + k + 1) = shr(tmp, 1, pOverflow); + } + + ji = add(ji, ii2, pOverflow); + } + } +} /* end of c_fft () */ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: r_fft +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + farray_ptr = pointer to complex array that the FFT operates on of type + Word16. + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow = 1 if the math functions called by cor_h_x2 result in overflow + else zero. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This is an implementation of decimation-in-time FFT algorithm for + real sequences. The techniques used here can be found in several + books, e.g., i) Proakis and Manolakis, "Digital Signal Processing", + 2nd Edition, Chapter 9, and ii) W.H. Press et. al., "Numerical + Recipes in C", 2nd Ediiton, Chapter 12. + + Input - There is one input to this function: + + 1) An integer pointer to the input data array + + Output - There is no return value. + The input data are replaced with transformed data. If the + input is a real time domain sequence, it is replaced with + the complex FFT for positive frequencies. The FFT value + for DC and the foldover frequency are combined to form the + first complex number in the array. The remaining complex + numbers correspond to increasing frequencies. If the input + is a complex frequency domain sequence arranged as above, + it is replaced with the corresponding time domain sequence. + + Notes: + + 1) This function is designed to be a part of a VAD + algorithm that requires 128-point FFT of real + sequences. This is achieved here through a 64-point + complex FFT. Consequently, the FFT size information is + not transmitted explicitly. However, some flexibility + is provided in the function to change the size of the + FFT by specifying the size information through "define" + statements. + + 2) The values of the complex sinusoids used in the FFT + algorithm are stored in a ROM table. + + 3) In the c_fft function, the FFT values are divided by + 2 after each stage of computation thus dividing the + final FFT values by 64. This is somewhat different + from the usual definition of FFT where the factor 1/N, + i.e., 1/64, used for the IFFT and not the FFT. No factor + is used in the r_fft function. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + r_fft.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +The original etsi reference code uses a global flag Overflow. However, in the +actual implementation a pointer to a the overflow flag is passed in. + +void r_fft(Word16 * farray_ptr) +{ + + Word16 ftmp1_real, ftmp1_imag, ftmp2_real, ftmp2_imag; + Word32 Lftmp1_real, Lftmp1_imag; + Word16 i, j; + Word32 Ltmp1; + + // Perform the complex FFT + c_fft(farray_ptr); + + // First, handle the DC and foldover frequencies + ftmp1_real = *farray_ptr; + ftmp2_real = *(farray_ptr + 1); + *farray_ptr = add(ftmp1_real, ftmp2_real); + *(farray_ptr + 1) = sub(ftmp1_real, ftmp2_real); + + // Now, handle the remaining positive frequencies + for (i = 2, j = SIZE - i; i <= SIZE_BY_TWO; i = i + 2, j = SIZE - i) + { + ftmp1_real = add(*(farray_ptr + i), *(farray_ptr + j)); + ftmp1_imag = sub(*(farray_ptr + i + 1), *(farray_ptr + j + 1)); + ftmp2_real = add(*(farray_ptr + i + 1), *(farray_ptr + j + 1)); + ftmp2_imag = sub(*(farray_ptr + j), *(farray_ptr + i)); + + Lftmp1_real = L_deposit_h(ftmp1_real); + Lftmp1_imag = L_deposit_h(ftmp1_imag); + + Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[i]); + Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[i + 1]); + *(farray_ptr + i) = pv_round(L_shr(Ltmp1, 1)); + + Ltmp1 = L_mac(Lftmp1_imag, ftmp2_imag, phs_tbl[i]); + Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[i + 1]); + *(farray_ptr + i + 1) = pv_round(L_shr(Ltmp1, 1)); + + Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[j]); + Ltmp1 = L_mac(Ltmp1, ftmp2_imag, phs_tbl[j + 1]); + *(farray_ptr + j) = pv_round(L_shr(Ltmp1, 1)); + + Ltmp1 = L_negate(Lftmp1_imag); + Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[j]); + Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[j + 1]); + *(farray_ptr + j + 1) = pv_round(L_shr(Ltmp1, 1)); + + } +} // end r_fft () + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/* FFT function for complex sequences */ +/* + * The decimation-in-time complex FFT is implemented below. + * The input complex numbers are presented as real part followed by + * imaginary part for each sample. The counters are therefore + * incremented by two to access the complex valued samples. + */ +void r_fft(Word16 * farray_ptr, Flag *pOverflow) +{ + + Word16 ftmp1_real; + Word16 ftmp1_imag; + Word16 ftmp2_real; + Word16 ftmp2_imag; + Word32 Lftmp1_real; + Word32 Lftmp1_imag; + Word16 i; + Word16 j; + Word32 Ltmp1; + + /* Perform the complex FFT */ + c_fft(farray_ptr, pOverflow); + + /* First, handle the DC and foldover frequencies */ + ftmp1_real = *farray_ptr; + ftmp2_real = *(farray_ptr + 1); + *farray_ptr = add(ftmp1_real, ftmp2_real, pOverflow); + *(farray_ptr + 1) = sub(ftmp1_real, ftmp2_real, pOverflow); + + /* Now, handle the remaining positive frequencies */ + for (i = 2, j = SIZE - i; i <= SIZE_BY_TWO; i = i + 2, j = SIZE - i) + { + ftmp1_real = add(*(farray_ptr + i), *(farray_ptr + j), pOverflow); + ftmp1_imag = sub(*(farray_ptr + i + 1), + *(farray_ptr + j + 1), pOverflow); + ftmp2_real = add(*(farray_ptr + i + 1), + *(farray_ptr + j + 1), pOverflow); + ftmp2_imag = sub(*(farray_ptr + j), + *(farray_ptr + i), pOverflow); + + Lftmp1_real = L_deposit_h(ftmp1_real); + Lftmp1_imag = L_deposit_h(ftmp1_imag); + + Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[i], pOverflow); + Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[i + 1], pOverflow); + *(farray_ptr + i) = pv_round(L_shr(Ltmp1, 1, pOverflow), pOverflow); + + Ltmp1 = L_mac(Lftmp1_imag, ftmp2_imag, phs_tbl[i], pOverflow); + Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[i + 1], pOverflow); + *(farray_ptr + i + 1) = pv_round(L_shr(Ltmp1, 1, pOverflow), pOverflow); + + Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[j], pOverflow); + Ltmp1 = L_mac(Ltmp1, ftmp2_imag, phs_tbl[j + 1], pOverflow); + *(farray_ptr + j) = pv_round(L_shr(Ltmp1, 1, pOverflow), pOverflow); + + Ltmp1 = L_negate(Lftmp1_imag); + Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[j], pOverflow); + Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[j + 1], pOverflow); + *(farray_ptr + j + 1) = pv_round(L_shr(Ltmp1, 1, pOverflow), pOverflow); + + } +} /* end r_fft () */ diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/reorder.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/reorder.cpp new file mode 100644 index 0000000..0f932e5 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/reorder.cpp @@ -0,0 +1,168 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: reorder.cpp + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "reorder.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Reorder_lsf +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + lsf = vector of LSFs (range: 0<=val<=0.5)(Word16) + min_dist = minimum required distance (Word16) + n = LPC order (Word16) + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the add operation called by Reorder_lsf() results in + overflow + lsf -> reordered vector of LSFs (Word16) + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function makes sure that the LSFs are properly ordered keeps a certain + minimum distance between adjacent LSFs. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] reorder.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Reorder_lsf ( + Word16 *lsf, // (i/o) : vector of LSFs (range: 0<=val<=0.5) + Word16 min_dist, // (i) : minimum required distance + Word16 n // (i) : LPC order +) +{ + Word16 i; + Word16 lsf_min; + +// The reference ETSI code uses a global flag for Overflow. In the actual +// implementation a pointer to Overflow flag is passed into the function +// for use by the math functions add() and sub() + + lsf_min = min_dist; + for (i = 0; i < n; i++) + { + if (sub (lsf[i], lsf_min) < 0) + { + lsf[i] = lsf_min; + } + lsf_min = add (lsf[i], min_dist); + } +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF void Reorder_lsf( + Word16 *lsf, /* (i/o) : vector of LSFs (range: 0<=val<=0.5) */ + Word16 min_dist, /* (i) : minimum required distance */ + Word16 n, /* (i) : LPC order */ + Flag *pOverflow /* (i/o) : Overflow flag */ +) +{ + Word16 i; + Word16 lsf_min; + Word16 *p_lsf = &lsf[0]; + OSCL_UNUSED_ARG(pOverflow); + + lsf_min = min_dist; + for (i = 0; i < n; i++) + { + if (*(p_lsf) < lsf_min) + { + *(p_lsf++) = lsf_min; + lsf_min += min_dist; + } + else + { + lsf_min = *(p_lsf++) + min_dist; + } + } +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/residu.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/residu.cpp new file mode 100644 index 0000000..787e043 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/residu.cpp @@ -0,0 +1,205 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: residu.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "residu.h" +#include "typedef.h" +#include "cnst.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Residu +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + coef_ptr = pointer to buffer containing the prediction coefficients + input_ptr = pointer to buffer containing the speech signal + input_len = filter order + residual_ptr = pointer to buffer of residual signal + + Outputs: + residual_ptr buffer contains the newly calculated the residual signal + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes the LP residual by filtering the input speech through + the LP inverse filter A(z). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + residu.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + Note: Input argument names were changed to be more descriptive. Shown below + are the original names. Shown below are the name changes: + a[] <--> coef_ptr[] + x[] <--> input_ptr[] + y[] <--> residual_ptr[] + lg <--> input_len + + +void Residu ( + Word16 a[], // (i) : prediction coefficients + Word16 x[], // (i) : speech signal + Word16 y[], // (o) : residual signal + Word16 lg // (i) : size of filtering +) +{ + Word16 i, j; + Word32 s; + + for (i = 0; i < lg; i++) + { + s = L_mult (x[i], a[0]); + for (j = 1; j <= M; j++) + { + s = L_mac (s, a[j], x[i - j]); + } + s = L_shl (s, 3); + y[i] = pv_round (s); + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Residu( + Word16 coef_ptr[], /* (i) : prediction coefficients*/ + Word16 input_ptr[], /* (i) : speech signal */ + Word16 residual_ptr[], /* (o) : residual signal */ + Word16 input_len /* (i) : size of filtering */ +) +{ + + + register Word16 i, j; + Word32 s1; + Word32 s2; + Word32 s3; + Word32 s4; + Word16 *p_input1; + Word16 *p_input2; + Word16 *p_input3; + Word16 *p_input4; + Word16 *p_coef; + Word16 *p_residual_ptr = &residual_ptr[input_len-1]; + Word16 *p_input_ptr = &input_ptr[input_len-1-M]; + + for (i = input_len >> 2; i != 0; i--) + { + s1 = 0x0000800L; + s2 = 0x0000800L; + s3 = 0x0000800L; + s4 = 0x0000800L; + p_coef = &coef_ptr[M]; + p_input1 = p_input_ptr--; + p_input2 = p_input_ptr--; + p_input3 = p_input_ptr--; + p_input4 = p_input_ptr--; + + for (j = M >> 1; j != 0; j--) + { + s1 += ((Word32) * (p_coef) * *(p_input1++)); + s2 += ((Word32) * (p_coef) * *(p_input2++)); + s3 += ((Word32) * (p_coef) * *(p_input3++)); + s4 += ((Word32) * (p_coef--) * *(p_input4++)); + s1 += ((Word32) * (p_coef) * *(p_input1++)); + s2 += ((Word32) * (p_coef) * *(p_input2++)); + s3 += ((Word32) * (p_coef) * *(p_input3++)); + s4 += ((Word32) * (p_coef--) * *(p_input4++)); + } + + s1 += (((Word32) * (p_coef)) * *(p_input1)); + s2 += (((Word32) * (p_coef)) * *(p_input2)); + s3 += (((Word32) * (p_coef)) * *(p_input3)); + s4 += (((Word32) * (p_coef)) * *(p_input4)); + + *(p_residual_ptr--) = (Word16)(s1 >> 12); + *(p_residual_ptr--) = (Word16)(s2 >> 12); + *(p_residual_ptr--) = (Word16)(s3 >> 12); + *(p_residual_ptr--) = (Word16)(s4 >> 12); + + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/round.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/round.cpp new file mode 100644 index 0000000..9fd4abb --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/round.cpp @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: round.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + Rounding function with saturation. + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: pv_round +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_var1 = 32 bit signed integer (Word32) whose value falls + in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + None + + Returns: + result = MS 16 bits of rounded input L_var1. + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function rounds the lower 16 bits of the 32 bit input number into the + MS 16 bits with saturation. Shift the resulting bits right by 16 and return + the 16 bit number: + pv_round(L_var1) = extract_h(L_add(L_var1,32768)) + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] round() function in basic_op2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 pv_round (Word32 L_var1) +{ + Word16 var_out; + Word32 L_rounded; + +* The reference ETSI code uses a global flag for Overflow in the L_add() function. +* In the actual implementation a pointer to Overflow flag is passed in as a +* parameter to the function. + + L_rounded = L_add (L_var1, (Word32) 0x00008000L); +#if (WMOPS) + multiCounter[currCounter].L_add--; +#endif + var_out = extract_h (L_rounded); +#if (WMOPS) + multiCounter[currCounter].extract_h--; + multiCounter[currCounter].round++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word16 pv_round(register Word32 L_var1, Flag *pOverflow) +{ + Word16 result; + + L_var1 = L_add(L_var1, (Word32) 0x00008000L, pOverflow); + result = (Word16)(L_var1 >> 16); + + return (result); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/set_zero.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/set_zero.cpp new file mode 100644 index 0000000..be23b25 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/set_zero.cpp @@ -0,0 +1,74 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* +******************************************************************************** +* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 +* R99 Version 3.2.0 +* REL-4 Version 4.0.0 +* +******************************************************************************** +* +* File : set_zero.h +* +******************************************************************************** +*/ +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "set_zero.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +void Set_zero( + Word16 x[], /* (o) : vector to clear */ + Word16 L /* (i) : length of vector */ +) +{ + Word16 i; + + for (i = 0; i < L; i++) + { + x[i] = 0; + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr.cpp new file mode 100644 index 0000000..a0fbd35 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr.cpp @@ -0,0 +1,201 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: shr.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + Shift right function with overflow control +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: shr +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the shift operation resulted in overflow + + Returns: + product = Shifted result limited to 16 bits (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function arithmetically shifts the 16 bit input var1 right var2 positions + with sign extension. If var2 is negative, arithmetically shift var1 left by + -var2 with sign extension. Saturate the result in case of underflows or + overflows. + +------------------------------------------------------------------------------ + REQUIREMENTS + None +------------------------------------------------------------------------------ + REFERENCES + + [1] shr() function in basic_op2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 shr_std (Word16 var1, Word16 var2) +{ + Word16 var_out; + + if (var2 < 0) + { + if (var2 < -16) + var2 = -16; + var_out = shl_std (var1, -var2); +#if (WMOPS) + mult_stdiCounter[currCounter].shl_std--; +#endif + } + else + { + if (var2 >= 15) + { + var_out = (var1 < 0) ? -1 : 0; + } + else + { + if (var1 < 0) + { + var_out = ~((~var1) >> var2); + } + else + { + var_out = var1 >> var2; + } + } + } + +#if (WMOPS) + mult_stdiCounter[currCounter].shr_std++; +#endif + return (var_out); +} +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word16 shr(register Word16 var1, register Word16 var2, Flag *pOverflow) +{ + register Word16 result; + + if (var2 != 0) + { + if (var2 > 0) + { + if (var2 > 15) + { + var2 = 15; + } + + result = var1 >> var2; + + } + else + { + var2 = -var2; /* Shift right negative is equivalent */ + + if (var2 > 15) + { + var2 = 15; + } + + result = (var1 << var2); + if ((result >> var2) != var1) + { + *pOverflow = 1; + result = ((var1 > 0) ? MAX_16 : MIN_16); + } + } + + } + else + { + result = var1; + } + + return (result); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr_r.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr_r.cpp new file mode 100644 index 0000000..b403885 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/shr_r.cpp @@ -0,0 +1,193 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: shr_r.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + var_out = shifted input w/ rounding (Word16) + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function arithmetically shifts the 16 bit input var1 right var2 positions + with rounding. If var2 is negative, arithmetically shift var1 left by + -var2 with rounding. Saturate the result in case of underflows or + overflows. + + - If var2 is greater than zero : + if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1)))) + is equal to zero + then + shr_r(var1,var2) = shr(var1,var2) + else + shr_r(var1,var2) = add(shr(var1,var2),1) + - If var2 is less than or equal to zero : + shr_r(var1,var2) = shr(var1,var2). + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] basicop2.c, ETS Version 2.0.0, February 8, 1999 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word16 shr_r (Word16 var1, Word16 var2) +{ + Word16 var_out; + + if (var2 > 15) + { + var_out = 0; + } + else + { + var_out = shr (var1, var2); +#if (WMOPS) + multiCounter[currCounter].shr--; +#endif + + if (var2 > 0) + { + if ((var1 & ((Word16) 1 << (var2 - 1))) != 0) + { + var_out++; + } + } + } +#if (WMOPS) + multiCounter[currCounter].shr_r++; +#endif + return (var_out); +} + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL FUNCTION REFERENCES +; Declare functions defined elsewhere and referenced in this module +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES +; Declare variables used in this module but defined elsewhere +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ +OSCL_EXPORT_REF Word16 shr_r(register Word16 var1, register Word16 var2, Flag *pOverflow) +{ + /*---------------------------------------------------------------------------- + ; Define all local variables + ----------------------------------------------------------------------------*/ + Word16 var_out; + + /*---------------------------------------------------------------------------- + ; Function body here + ----------------------------------------------------------------------------*/ + if (var2 > 15) + { + var_out = 0; + } + else + { + var_out = shr(var1, var2, pOverflow); + if (var2 > 0) + { + if ((var1 & ((Word16) 1 << (var2 - 1))) != 0) + { + var_out++; + } + } + } + + /*---------------------------------------------------------------------------- + ; Return nothing or data or data pointer + ----------------------------------------------------------------------------*/ + return (var_out); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l.cpp new file mode 100644 index 0000000..6038388 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l.cpp @@ -0,0 +1,235 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: sqrt_l.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "sqrt_l.h" +#include "typedef.h" +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: sqrt_l_exp +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_x = input value (Word32) + pExp = pointer to right shift to be applied to result + pOverflow = pointer to overflow flag + + Outputs: + pOverflow -> if the Inv_sqrt operation resulted in an overflow. + + Returns: + L_y = squareroot of L_x (Word32) + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function computes sqrt(L_x), where L_x is positive. + If L_var is negative or zero, the result is 0 + + The function sqrt(L_x) is approximated by a table and linear + interpolation. The square root is computed using the + following steps: + 1- Normalization of L_x. + 2- If exponent is even then shift right once. + 3- exponent = exponent/2 + 4- i = bit25-b31 of L_x; 16<=i<=63 because of normalization. + 5- a = bit10-b24 + 6- i -=16 + 7- L_y = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + 8- return L_y and exponent so caller can do denormalization + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + sqrt_l.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +Word32 sqrt_l_exp ( // o : output value + Word32 L_x, // i : input value + Word16 *exp // o : right shift to be applied to result +) +{ + +// y = sqrt(x) +// x = f * 2^-e, 0.5 <= f < 1 (normalization) +// y = sqrt(f) * 2^(-e/2) +// +// a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2, +// 0.707 <= sqrt(f) < 1) +// b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2, + 0.5 <= sqrt(f/2) < 0.707) + + + Word16 e, i, a, tmp; + Word32 L_y; + + if (L_x <= (Word32) 0) + { + *exp = 0; + return (Word32) 0; + } + +* The reference ETSI code uses a global Overflow flag. In the actual +* implementation a pointer to the overflow flag is passed into the function. +* This pointer is in turn passed into the basic math functions such as add(), +* L_shl(), L_shr(), sub() called by this module. + + e = norm_l (L_x) & 0xFFFE; // get next lower EVEN norm. exp + L_x = L_shl (L_x, e); // L_x is normalized to [0.25..1) + *exp = e; // return 2*exponent (or Q1) + + L_x = L_shr (L_x, 9); + i = extract_h (L_x); // Extract b25-b31, 16 <= i <= 63 + because of normalization + L_x = L_shr (L_x, 1); + a = extract_l (L_x); // Extract b10-b24 + a = a & (Word16) 0x7fff; + + i = sub (i, 16); // 0 <= i <= 47 + + L_y = L_deposit_h (table[i]); // table[i] << 16 + tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1]) + L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2 + + return (L_y); +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF Word32 sqrt_l_exp( /* o : output value, Q31 */ + Word32 L_x, /* i : input value, Q31 */ + Word16 *pExp, /* o : right shift to be applied to result, Q1 */ + Flag *pOverflow /* i : pointer to overflow flag */ +) + +{ + Word16 e; + Word16 i; + Word16 a; + Word16 tmp; + Word32 L_y; + + /* + y = sqrt(x) + x = f * 2^-e, 0.5 <= f < 1 (normalization) + y = sqrt(f) * 2^(-e/2) + a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2, + 0.707 <= sqrt(f) < 1) + b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2, + 0.5 <= sqrt(f/2) < 0.707) + */ + + if (L_x <= (Word32) 0) + { + *pExp = 0; + return (Word32) 0; + } + + e = norm_l(L_x) & 0xFFFE; /* get next lower EVEN norm. exp */ + L_x = L_shl(L_x, e, pOverflow); /* L_x is normalized to [0.25..1) */ + *pExp = e; /* return 2*exponent (or Q1) */ + + L_x >>= 10; + i = (Word16)(L_x >> 15) & 63; /* Extract b25-b31, 16<= i <=63 */ + /* because of normalization */ + + a = (Word16)(L_x); /* Extract b10-b24 */ + a &= (Word16) 0x7fff; + + if (i > 15) + { + i -= 16; /* 0 <= i <= 47 */ + } + + L_y = ((Word32) sqrt_l_tbl[i] << 16); /* sqrt_l_tbl[i] << 16 */ + + /* sqrt_l_tbl[i] - sqrt_l_tbl[i+1]) */ + tmp = sqrt_l_tbl[i] - sqrt_l_tbl[i + 1]; + + L_y = L_msu(L_y, tmp, a, pOverflow); /* L_y -= tmp*a*2 */ + + /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */ + + return (L_y); +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l_tbl.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l_tbl.cpp new file mode 100644 index 0000000..8b91771 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sqrt_l_tbl.cpp @@ -0,0 +1,141 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: sqrt_l_tbl.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + This file contains the declaration for sqrt_l_table[] used by the sqrt_l_exp + function. + + sqrt_l_tbl[i] = sqrt((i+16)*2^-6) * 2^15, i.e. sqrt(x) scaled Q15 + + ------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "sqrt_l.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; [Define module specific macros here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; DEFINES + ; [Include all pre-processor statements here. Include conditional + ; compile variables also.] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; [List function prototypes here] + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL VARIABLE DEFINITIONS + ; [Variable declaration - defined here and used outside this module] + ----------------------------------------------------------------------------*/ + const Word16 sqrt_l_tbl[50] = + { + 16384, 16888, 17378, 17854, 18318, 18770, 19212, 19644, 20066, 20480, + 20886, 21283, 21674, 22058, 22435, 22806, 23170, 23530, 23884, 24232, + 24576, 24915, 25249, 25580, 25905, 26227, 26545, 26859, 27170, 27477, + 27780, 28081, 28378, 28672, 28963, 29251, 29537, 29819, 30099, 30377, + 30652, 30924, 31194, 31462, 31727, 31991, 32252, 32511, 32767, 32767 + }; + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + None + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] inv_sqrt.tab file, UMTS GSM AMR speech codec, R99 - Version 3.2.0, + March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sub.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sub.cpp new file mode 100644 index 0000000..ed9fccc --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/sub.cpp @@ -0,0 +1,176 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: sub.cpp + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + Subtraction function with overflow control + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; [Define module specific macros here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; [Include all pre-processor statements here. Include conditional +; compile variables also.] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; [List function prototypes here] +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; [Variable declaration - defined here and used outside this module] +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: sub +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + var1 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var1 <= 0x0000 7fff. + + var2 = 16 bit short signed integer (Word16) whose value falls in + the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + + pOverflow = pointer to overflow (Flag) + + Outputs: + pOverflow -> 1 if the subtract operation resulted in overflow + + Returns: + diff = 16-bit limited difference between var1 and var2 (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function performs the subtraction (var1-var2) with overflow control and + saturation; the 16 bit result is set at +32767 when overflow occurs or at + -32768 when underflow occurs. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + [1] sub() function in basicop2.c, UMTS GSM AMR speech codec, R99 - + Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + + PSEUDO-CODE + + Word16 sub (Word16 var1, Word16 var2) + { + Word16 var_out; + Word32 diff; + + diff = (Word32) var1 - var2; + +* The reference ETSI code uses a global flag for Overflow inside the function +* saturate(). In the actual implementation a pointer to Overflow flag is passed +* in as a parameter to the function + + var_out = saturate (diff); + + #if (WMOPS) + multiCounter[currCounter].sub++; + #endif + + return (var_out); + } + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +OSCL_EXPORT_REF Word16 sub(Word16 var1, Word16 var2, Flag *pOverflow) +{ + + Word32 diff; + + diff = (Word32) var1 - var2; + + /* Saturate result (if necessary). */ + /* Replaced function call with in-line code */ + /* to conserve MIPS, i.e., var_out = saturate (diff) */ + + + if ((UWord32)(diff - 0xFFFF8000L) > 0x000FFFF) + { + if (diff > (Word32) 0x0007FFFL) + { + diff = MAX_16; + } + else + { + diff = MIN_16; + } + + *pOverflow = 1; + } + + + return ((Word16) diff); +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/syn_filt.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/syn_filt.cpp new file mode 100644 index 0000000..221f4dc --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/syn_filt.cpp @@ -0,0 +1,325 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: syn_filt.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "syn_filt.h" +#include "cnst.h" +#include "basic_op.h" +#include "oscl_mem.h" + +#include "basic_op.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Syn_filt +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + a = buffer containing the prediction coefficients (Word16) max 2^12 + x = input signal buffer (Word16) max 2^15 + y = output signal buffer (Word16) + lg = size of filtering (Word16) + mem = memory buffer associated with this filtering (Word16) + update = flag to indicate memory update; 0=no update, 1=update memory + (Word16) + + Outputs: + mem buffer is changed to be the last M data points of the output signal + if update was set to 1 + y buffer contains the newly calculated filter output + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Perform synthesis filtering through 1/A(z) + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + syn_filt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Syn_filt ( + Word16 a[], // (i) : a[M+1] prediction coefficients (M=10) + Word16 x[], // (i) : input signal + Word16 y[], // (o) : output signal + Word16 lg, // (i) : size of filtering + Word16 mem[], // (i/o) : memory associated with this filtering. + Word16 update // (i) : 0=no update, 1=update of memory. +) +{ + Word16 i, j; + Word32 s; + Word16 tmp[80]; // This is usually done by memory allocation (lg+M) + Word16 *yy; + + // Copy mem[] to yy[] + + yy = tmp; + + for (i = 0; i < M; i++) + { + *yy++ = mem[i]; + } + + // Do the filtering. + + for (i = 0; i < lg; i++) + { + s = L_mult (x[i], a[0]); + for (j = 1; j <= M; j++) + { + s = L_msu (s, a[j], yy[-j]); + } + s = L_shl (s, 3); + *yy++ = pv_round (s); + } + + for (i = 0; i < lg; i++) + { + y[i] = tmp[i + M]; + } + + // Update of memory if update==1 + + if (update != 0) + { + for (i = 0; i < M; i++) + { + mem[i] = y[lg - M + i]; + } + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Syn_filt( + Word16 a[], /* (i) : a[M+1] prediction coefficients (M=10) */ + Word16 x[], /* (i) : input signal */ + Word16 y[], /* (o) : output signal */ + Word16 lg, /* (i) : size of filtering (40) */ + Word16 mem[], /* (i/o) : memory associated with this filtering. */ + Word16 update /* (i) : 0=no update, 1=update of memory. */ +) +{ + Word16 i, j; + Word32 s1; + Word32 s2; + Word16 tmp[2*M]; /* This is usually done by memory allocation (lg+M) */ + Word16 *yy; + + Word16 *p_a; + Word16 *p_yy1; + Word16 *p_y; + Word16 *p_x; + Word16 temp; + /* Copy mem[] to yy[] */ + + yy = tmp; + + oscl_memcpy(yy, mem, M*sizeof(Word16)); + + yy = yy + M; + + /* Do the filtering. */ + + p_y = y; + p_x = x; + p_yy1 = &yy[-1]; + + for (i = M >> 1; i != 0; i--) + { + p_a = a; + + s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a), 0x00000800L); + s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a++), 0x00000800L); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + + for (j = (M >> 1) - 2; j != 0; j--) + { + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + } + + /* check for overflow on s1 */ + if ((UWord32)(s1 - 0xf8000000L) < 0x0fffffffL) + { + temp = (Word16)(s1 >> 12); + } + else if (s1 > 0x07ffffffL) + { + temp = MAX_16; + } + else + { + temp = MIN_16; + } + + s2 = amrnb_fxp_msu_16_by_16bb((Word32)a[1], (Word32)temp, s2); + + *(yy++) = temp; + *(p_y++) = temp; + + p_yy1 = yy; + + /* check for overflow on s2 */ + if ((UWord32)(s2 - 0xf8000000L) < 0x0fffffffL) + { + temp = (Word16)(s2 >> 12); + } + else if (s2 > 0x07ffffffL) + { + temp = MAX_16; + } + else + { + temp = MIN_16; + } + + *(yy++) = temp; + *(p_y++) = temp; + } + + p_yy1 = &y[M-1]; + + for (i = (lg - M) >> 1; i != 0; i--) + { + p_a = a; + + s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a), 0x00000800L); + s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a++), 0x00000800L); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + + for (j = (M >> 1) - 2; j != 0; j--) + { + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2); + s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1); + } + + if ((UWord32)(s1 - 0xf8000000L) < 0x0fffffffL) + { + temp = (Word16)(s1 >> 12); + } + else if (s1 > 0x07ffffffL) + { + temp = MAX_16; + } + else + { + temp = MIN_16; + } + + s2 = amrnb_fxp_msu_16_by_16bb((Word32)a[1], (Word32)temp, s2); + + *(p_y++) = temp; + p_yy1 = p_y; + + if ((UWord32)(s2 - 0xf8000000L) < 0x0fffffffL) + { + *(p_y++) = (Word16)(s2 >> 12); + } + else if (s2 > 0x07ffffffL) + { + *(p_y++) = MAX_16; + } + else + { + *(p_y++) = MIN_16; + } + } + + /* Update of memory if update==1 */ + if (update != 0) + { + oscl_memcpy(mem, &y[lg-M], M*sizeof(Word16)); + } + + return; +} diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad1.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad1.cpp new file mode 100644 index 0000000..d5c42dc --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad1.cpp @@ -0,0 +1,2001 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: vad1.cpp + Functions: + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "vad.h" +#include "typedef.h" +#include "shr.h" +#include "basic_op.h" +#include "cnst_vad.h" +#include "oscl_mem.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: first_filter_stage +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + data -- array of type Word16 -- filter memory + in -- array of type Word16 -- input signal + + Outputs: + data -- array of type Word16 -- filter memory + out -- array of type Word16 -- output values, every other + output is low-pass part and + other is high-pass part every + + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Scale input down by one bit. Calculate 5th order + half-band lowpass/highpass filter pair with + decimation. +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void first_filter_stage( + Word16 in[], /* i : input signal */ + Word16 out[], /* o : output values, every other */ + /* output is low-pass part and */ + /* other is high-pass part every */ + Word16 data[], /* i/o : filter memory */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 temp0; + Word16 temp1; + Word16 temp2; + Word16 temp3; + Word16 i; + Word16 data0; + Word16 data1; + + data0 = data[0]; + data1 = data[1]; + + for (i = 0; i < FRAME_LEN / 4; i++) + { + temp0 = mult(COEFF5_1, data0, pOverflow); + temp1 = shr(in[4*i+0], 2, pOverflow); + temp0 = sub(temp1, temp0, pOverflow); + + temp1 = mult(COEFF5_1, temp0, pOverflow); + temp1 = add(data0, temp1, pOverflow); + + temp3 = mult(COEFF5_2, data1, pOverflow); + temp2 = shr(in[4*i+1], 2, pOverflow); + + temp3 = sub(temp2, temp3, pOverflow); + + temp2 = mult(COEFF5_2, temp3, pOverflow); + temp2 = add(data1, temp2, pOverflow); + + out[4*i+0] = add(temp1, temp2, pOverflow); + out[4*i+1] = sub(temp1, temp2, pOverflow); + + temp1 = mult(COEFF5_1, temp0, pOverflow); + temp2 = shr(in[4*i+2], 2, pOverflow); + data0 = sub(temp2, temp1, pOverflow); + + temp1 = mult(COEFF5_1, data0, pOverflow); + temp1 = add(temp0, temp1, pOverflow); + + data1 = mult(COEFF5_2, temp3, pOverflow); + temp2 = shr(in[4*i+3], 2, pOverflow); + data1 = sub(temp2, data1, pOverflow); + + temp2 = mult(COEFF5_2, data1, pOverflow); + temp2 = add(temp3, temp2, pOverflow); + + out[4*i+2] = add(temp1, temp2, pOverflow); + out[4*i+3] = sub(temp1, temp2, pOverflow); + } + + data[0] = data0; + data[1] = data1; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: filter5 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + in0 -- array of type Word16 -- input values; output low-pass part + in1 -- array of type Word16 -- input values; output high-pass part + data -- array of type Word16 -- updated filter memory + + Outputs: + in0 -- array of type Word16 -- input values; output low-pass part + in1 -- array of type Word16 -- input values; output high-pass part + data -- array of type Word16 -- updated filter memory + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Fifth-order half-band lowpass/highpass filter pair with + decimation. +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void filter5(Word16 *in0, /* i/o : input values; output low-pass part */ + Word16 *in1, /* i/o : input values; output high-pass part */ + Word16 data[], /* i/o : updated filter memory */ + Flag *pOverflow /* o : Flag set when overflow occurs */ + ) +{ + Word16 temp0; + Word16 temp1; + Word16 temp2; + + temp0 = mult(COEFF5_1, data[0], pOverflow); + temp0 = sub(*in0, temp0, pOverflow); + + temp1 = mult(COEFF5_1, temp0, pOverflow); + temp1 = add(data[0], temp1, pOverflow); + data[0] = temp0; + + temp0 = mult(COEFF5_2, data[1], pOverflow); + temp0 = sub(*in1, temp0, pOverflow); + + temp2 = mult(COEFF5_2, temp0, pOverflow); + temp2 = add(data[1], temp2, pOverflow); + + data[1] = temp0; + + temp0 = add(temp1, temp2, pOverflow); + *in0 = shr(temp0, 1, pOverflow); + + temp0 = sub(temp1, temp2, pOverflow); + *in1 = shr(temp0, 1, pOverflow); +} + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: filter3 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + + Inputs: + in0 -- array of type Word16 -- input values; output low-pass part + in1 -- array of type Word16 -- input values; output high-pass part + data -- array of type Word16 -- updated filter memory + + Outputs: + in0 -- array of type Word16 -- input values; output low-pass part + in1 -- array of type Word16 -- input values; output high-pass part + data -- array of type Word16 -- updated filter memory + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Third-order half-band lowpass/highpass filter pair with + decimation. +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void filter3( + Word16 *in0, /* i/o : input values; output low-pass part */ + Word16 *in1, /* i/o : input values; output high-pass part */ + Word16 *data, /* i/o : updated filter memory */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 temp1; + Word16 temp2; + + temp1 = mult(COEFF3, *data, pOverflow); + temp1 = sub(*in1, temp1, pOverflow); + + temp2 = mult(COEFF3, temp1, pOverflow); + temp2 = add(*data, temp2, pOverflow); + + *data = temp1; + + temp1 = sub(*in0, temp2, pOverflow); + + *in1 = shr(temp1, 1, pOverflow); + + temp1 = add(*in0, temp2, pOverflow); + + *in0 = shr(temp1, 1, pOverflow); +} + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: level_calculation +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + data -- array of type Word16 -- signal buffer + sub_level -- pointer to type Word16 -- level calculated at the end of + the previous frame + + count1 -- Word16 -- number of samples to be counted + count2 -- Word16 -- number of samples to be counted + ind_m -- Word16 -- step size for the index of the data buffer + ind_a -- Word16 -- starting index of the data buffer + scale -- Word16 -- scaling for the level calculation + + Outputs: + sub_level -- pointer to tyep Word16 -- level of signal calculated from the + last (count2 - count1) samples. + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + signal level + + Global Variables Used: + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Calculate signal level in a sub-band. Level is calculated + by summing absolute values of the input data. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 level_calculation( + Word16 data[], /* i : signal buffer */ + Word16 *sub_level, /* i : level calculate at the end of */ + /* the previous frame */ + /* o : level of signal calculated from the last */ + /* (count2 - count1) samples */ + Word16 count1, /* i : number of samples to be counted */ + Word16 count2, /* i : number of samples to be counted */ + Word16 ind_m, /* i : step size for the index of the data buffer */ + Word16 ind_a, /* i : starting index of the data buffer */ + Word16 scale, /* i : scaling for the level calculation */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word32 l_temp1; + Word32 l_temp2; + Word16 level; + Word16 i; + + l_temp1 = 0L; + + for (i = count1; i < count2; i++) + { + l_temp1 = L_mac(l_temp1, 1, abs_s(data[ind_m*i+ind_a]), pOverflow); + } + + l_temp2 = L_add(l_temp1, L_shl(*sub_level, sub(16, scale, pOverflow), pOverflow), pOverflow); + *sub_level = extract_h(L_shl(l_temp1, scale, pOverflow)); + + for (i = 0; i < count1; i++) + { + l_temp2 = L_mac(l_temp2, 1, abs_s(data[ind_m*i+ind_a]), pOverflow); + } + level = extract_h(L_shl(l_temp2, scale, pOverflow)); + + return level; +} + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: filter_bank +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + in -- array of type Word16 -- input frame + + Outputs: + level -- array of type Word16 -- signal levels at each band + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Divides input signal into 9-bands and calculas level of + the signal in each band + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void filter_bank( + vadState1 *st, /* i/o : State struct */ + Word16 in[], /* i : input frame */ + Word16 level[], /* 0 : signal levels at each band */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 i; + Word16 tmp_buf[FRAME_LEN]; + + /* calculate the filter bank */ + + first_filter_stage(in, tmp_buf, st->a_data5[0], pOverflow); + + for (i = 0; i < FRAME_LEN / 4; i++) + { + filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1], pOverflow); + filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2], pOverflow); + } + for (i = 0; i < FRAME_LEN / 8; i++) + { + filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0], pOverflow); + filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1], pOverflow); + filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4], pOverflow); + } + + for (i = 0; i < FRAME_LEN / 16; i++) + { + filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2], pOverflow); + filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3], pOverflow); + } + + /* calculate levels in each frequency band */ + + /* 3000 - 4000 Hz*/ + level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN / 4 - 8, + FRAME_LEN / 4, 4, 1, 15, pOverflow); + /* 2500 - 3000 Hz*/ + level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN / 8 - 4, + FRAME_LEN / 8, 8, 7, 16, pOverflow); + /* 2000 - 2500 Hz*/ + level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN / 8 - 4, + FRAME_LEN / 8, 8, 3, 16, pOverflow); + /* 1500 - 2000 Hz*/ + level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN / 8 - 4, + FRAME_LEN / 8, 8, 2, 16, pOverflow); + /* 1000 - 1500 Hz*/ + level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN / 8 - 4, + FRAME_LEN / 8, 8, 6, 16, pOverflow); + /* 750 - 1000 Hz*/ + level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN / 16 - 2, + FRAME_LEN / 16, 16, 4, 16, pOverflow); + /* 500 - 750 Hz*/ + level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN / 16 - 2, + FRAME_LEN / 16, 16, 12, 16, pOverflow); + /* 250 - 500 Hz*/ + level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN / 16 - 2, + FRAME_LEN / 16, 16, 8, 16, pOverflow); + /* 0 - 250 Hz*/ + level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN / 16 - 2, + FRAME_LEN / 16, 16, 0, 16, pOverflow); +} + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: update_cntrl +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + level -- array of type Word16 -- sub-band levels of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Control update of the background noise estimate. + Inputs : pitch: flags for pitch detection + stat_count: stationary counter + tone: flags indicating presence of a tone + complex: flags for complex detection + vadreg: intermediate VAD flags + Output : stat_count: stationary counter + + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void update_cntrl( + vadState1 *st, /* i/o : State struct */ + Word16 level[], /* i : sub-band levels of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 i; + Word16 temp; + Word16 stat_rat; + Word16 exp; + Word16 num; + Word16 denom; + Word16 alpha; + + /* handle highband complex signal input separately */ + /* if ther has been highband correlation for some time */ + /* make sure that the VAD update speed is low for a while */ + if (st->complex_warning != 0) + { + if (st->stat_count < CAD_MIN_STAT_COUNT) + { + st->stat_count = CAD_MIN_STAT_COUNT; + } + } + /* NB stat_count is allowed to be decreased by one below again */ + /* deadlock in speech is not possible unless the signal is very */ + /* complex and need a high rate */ + + /* if fullband pitch or tone have been detected for a while, initialize stat_count */ + if (((Word16)(st->pitch & 0x6000) == 0x6000) || + ((Word16)(st->tone & 0x7c00) == 0x7c00)) + { + st->stat_count = STAT_COUNT; + } + else + { + /* if 8 last vad-decisions have been "0", reinitialize stat_count */ + if ((st->vadreg & 0x7f80) == 0) + { + st->stat_count = STAT_COUNT; + } + else + { + stat_rat = 0; + for (i = 0; i < COMPLEN; i++) + { + if (level[i] > st->ave_level[i]) + { + num = level[i]; + denom = st->ave_level[i]; + } + else + { + num = st->ave_level[i]; + denom = level[i]; + } + /* Limit nimimum value of num and denom to STAT_THR_LEVEL */ + if (num < STAT_THR_LEVEL) + { + num = STAT_THR_LEVEL; + } + if (denom < STAT_THR_LEVEL) + { + denom = STAT_THR_LEVEL; + } + + exp = norm_s(denom); + + denom = shl(denom, exp, pOverflow); + + /* stat_rat = num/denom * 64 */ + temp = shr(num, 1, pOverflow); + temp = div_s(temp, denom); + + stat_rat = add(stat_rat, shr(temp, sub(8, exp, pOverflow), pOverflow), pOverflow); + } + + /* compare stat_rat with a threshold and update stat_count */ + if (stat_rat > STAT_THR) + { + st->stat_count = STAT_COUNT; + } + else + { + if ((st->vadreg & 0x4000) != 0) + { + if (st->stat_count != 0) + { + st->stat_count = sub(st->stat_count, 1, pOverflow); + } + } + } + } + } + + /* Update average amplitude estimate for stationarity estimation */ + alpha = ALPHA4; + if (st->stat_count == STAT_COUNT) + { + alpha = 32767; + } + else if ((st->vadreg & 0x4000) == 0) + { + alpha = ALPHA5; + } + + for (i = 0; i < COMPLEN; i++) + { + temp = sub(level[i], st->ave_level[i], pOverflow); + temp = mult_r(alpha, temp, pOverflow); + + st->ave_level[i] = + add( + st->ave_level[i], + temp, + pOverflow); + } +} + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: hangover_addition +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + noise_level -- Word16 -- average level of the noise estimates + low_power -- Word16 -- flag power of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicato + + Returns: + VAD_flag indicating final VAD decision (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Function : hangover_addition + Purpose : Add hangover for complex signal or after speech bursts + Inputs : burst_count: counter for the length of speech bursts + hang_count: hangover counter + vadreg: intermediate VAD decision + Outputs : burst_count: counter for the length of speech bursts + hang_count: hangover counter + Return value : VAD_flag indicating final VAD decision + + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 hangover_addition( + vadState1 *st, /* i/o : State struct */ + Word16 noise_level, /* i : average level of the noise */ + /* estimates */ + Word16 low_power, /* i : flag power of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 hang_len; + Word16 burst_len; + + /* + Calculate burst_len and hang_len + burst_len: number of consecutive intermediate vad flags with "1"-decision + required for hangover addition + hang_len: length of the hangover + */ + + if (noise_level > HANG_NOISE_THR) + { + burst_len = BURST_LEN_HIGH_NOISE; + hang_len = HANG_LEN_HIGH_NOISE; + } + else + { + burst_len = BURST_LEN_LOW_NOISE; + hang_len = HANG_LEN_LOW_NOISE; + } + + /* if the input power (pow_sum) is lower than a threshold, clear + counters and set VAD_flag to "0" "fast exit" */ + if (low_power != 0) + { + st->burst_count = 0; + st->hang_count = 0; + st->complex_hang_count = 0; + st->complex_hang_timer = 0; + return 0; + } + + if (st->complex_hang_timer > CVAD_HANG_LIMIT) + { + if (st->complex_hang_count < CVAD_HANG_LENGTH) + { + st->complex_hang_count = CVAD_HANG_LENGTH; + } + } + + /* long time very complex signal override VAD output function */ + if (st->complex_hang_count != 0) + { + st->burst_count = BURST_LEN_HIGH_NOISE; + st->complex_hang_count = sub(st->complex_hang_count, 1, pOverflow); + return 1; + } + else + { + /* let hp_corr work in from a noise_period indicated by the VAD */ + if (((st->vadreg & 0x3ff0) == 0) && + (st->corr_hp_fast > CVAD_THRESH_IN_NOISE)) + { + return 1; + } + } + + /* update the counters (hang_count, burst_count) */ + if ((st->vadreg & 0x4000) != 0) + { + st->burst_count = add(st->burst_count, 1, pOverflow); + + if (st->burst_count >= burst_len) + { + st->hang_count = hang_len; + } + return 1; + } + else + { + st->burst_count = 0; + if (st->hang_count > 0) + { + st->hang_count = sub(st->hang_count, 1, pOverflow); + return 1; + } + } + return 0; +} + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: noise_estimate_update +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + level -- array of type Word16 -- sub-band levels of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Update of background noise estimate + Inputs : bckr_est: background noise estimate + pitch: flags for pitch detection + stat_count: stationary counter + Outputs : bckr_est: background noise estimate + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void noise_estimate_update( + vadState1 *st, /* i/o : State struct */ + Word16 level[], /* i : sub-band levels of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 i; + Word16 alpha_up; + Word16 alpha_down; + Word16 bckr_add; + + /* Control update of bckr_est[] */ + update_cntrl(st, level, pOverflow); + + /* Choose update speed */ + bckr_add = 2; + + if (((0x7800 & st->vadreg) == 0) && + ((st->pitch & 0x7800) == 0) + && (st->complex_hang_count == 0)) + { + alpha_up = ALPHA_UP1; + alpha_down = ALPHA_DOWN1; + } + else + { + if ((st->stat_count == 0) + && (st->complex_hang_count == 0)) + { + alpha_up = ALPHA_UP2; + alpha_down = ALPHA_DOWN2; + } + else + { + alpha_up = 0; + alpha_down = ALPHA3; + bckr_add = 0; + } + } + + /* Update noise estimate (bckr_est) */ + for (i = 0; i < COMPLEN; i++) + { + Word16 temp; + + temp = sub(st->old_level[i], st->bckr_est[i], pOverflow); + + if (temp < 0) + { /* update downwards*/ + temp = mult_r(alpha_down, temp, pOverflow); + temp = add(st->bckr_est[i], temp, pOverflow); + + st->bckr_est[i] = add(-2, temp, pOverflow); + + /* limit minimum value of the noise estimate to NOISE_MIN */ + if (st->bckr_est[i] < NOISE_MIN) + { + st->bckr_est[i] = NOISE_MIN; + } + } + else + { /* update upwards */ + temp = mult_r(alpha_up, temp, pOverflow); + temp = add(st->bckr_est[i], temp, pOverflow); + st->bckr_est[i] = add(bckr_add, temp, pOverflow); + + /* limit maximum value of the noise estimate to NOISE_MAX */ + if (st->bckr_est[i] > NOISE_MAX) + { + st->bckr_est[i] = NOISE_MAX; + } + } + } + + /* Update signal levels of the previous frame (old_level) */ + for (i = 0; i < COMPLEN; i++) + { + st->old_level[i] = level[i]; + } +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: complex_estimate_adapt +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + low_power -- Word16 -- very low level flag of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Function : complex_estimate_adapt + Purpose : Update/adapt of complex signal estimate + Inputs : low_power: low signal power flag + Outputs : st->corr_hp_fast: long term complex signal estimate + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static void complex_estimate_adapt( + vadState1 *st, /* i/o : VAD state struct */ + Word16 low_power, /* i : very low level flag of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 alpha; /* Q15 */ + Word32 L_tmp; /* Q31 */ + + + /* adapt speed on own state */ + if (st->best_corr_hp < st->corr_hp_fast) /* decrease */ + { + if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH) + { /* low state */ + alpha = CVAD_ADAPT_FAST; + } + else + { /* high state */ + alpha = CVAD_ADAPT_REALLY_FAST; + } + } + else /* increase */ + { + if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH) + { + alpha = CVAD_ADAPT_FAST; + } + else + { + alpha = CVAD_ADAPT_SLOW; + } + } + + L_tmp = L_deposit_h(st->corr_hp_fast); + L_tmp = L_msu(L_tmp, alpha, st->corr_hp_fast, pOverflow); + L_tmp = L_mac(L_tmp, alpha, st->best_corr_hp, pOverflow); + st->corr_hp_fast = pv_round(L_tmp, pOverflow); /* Q15 */ + + if (st->corr_hp_fast < CVAD_MIN_CORR) + { + st->corr_hp_fast = CVAD_MIN_CORR; + } + + if (low_power != 0) + { + st->corr_hp_fast = CVAD_MIN_CORR; + } +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: complex_vad +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + low_power -- Word16 -- flag power of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + + Returns: + the complex background decision + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : complex background decision + Return value : the complex background decision + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 complex_vad( + vadState1 *st, /* i/o : VAD state struct */ + Word16 low_power, /* i : flag power of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + st->complex_high = shr(st->complex_high, 1, pOverflow); + st->complex_low = shr(st->complex_low, 1, pOverflow); + + if (low_power == 0) + { + if (st->corr_hp_fast > CVAD_THRESH_ADAPT_HIGH) + { + st->complex_high |= 0x4000; + } + + if (st->corr_hp_fast > CVAD_THRESH_ADAPT_LOW) + { + st->complex_low |= 0x4000; + } + } + + if (st->corr_hp_fast > CVAD_THRESH_HANG) + { + st->complex_hang_timer = add(st->complex_hang_timer, 1, pOverflow); + } + else + { + st->complex_hang_timer = 0; + } + + return ((Word16)(st->complex_high & 0x7f80) == 0x7f80 || + (Word16)(st->complex_low & 0x7fff) == 0x7fff); +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad_decision +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + level -- array of type Word16 -- sub-band levels of the input frame + pow_sum -- Word32 -- power of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + VAD_flag (Word16) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Calculates VAD_flag + Inputs : bckr_est: background noise estimate + vadreg: intermediate VAD flags + Outputs : noise_level: average level of the noise estimates + vadreg: intermediate VAD flags + Return value : VAD_flag + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +static Word16 vad_decision( + vadState1 *st, /* i/o : State struct */ + Word16 level[COMPLEN], /* i : sub-band levels of the input frame */ + Word32 pow_sum, /* i : power of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 i; + Word16 snr_sum; + Word32 L_temp; + Word16 vad_thr; + Word16 temp; + Word16 noise_level; + Word16 low_power_flag; + Word16 temp1; + + /* + Calculate squared sum of the input levels (level) + divided by the background noise components (bckr_est). + */ + L_temp = 0; + + for (i = 0; i < COMPLEN; i++) + { + Word16 exp; + + exp = norm_s(st->bckr_est[i]); + temp = shl(st->bckr_est[i], exp, pOverflow); + temp = div_s(shr(level[i], 1, pOverflow), temp); + temp = shl(temp, sub(exp, UNIRSHFT - 1, pOverflow), pOverflow); + L_temp = L_mac(L_temp, temp, temp, pOverflow); + } + + snr_sum = extract_h(L_shl(L_temp, 6, pOverflow)); + snr_sum = mult(snr_sum, INV_COMPLEN, pOverflow); + + /* Calculate average level of estimated background noise */ + L_temp = 0; + for (i = 0; i < COMPLEN; i++) + { + L_temp = L_add(L_temp, st->bckr_est[i], pOverflow); + } + + noise_level = extract_h(L_shl(L_temp, 13, pOverflow)); + + /* Calculate VAD threshold */ + temp1 = sub(noise_level, VAD_P1, pOverflow); + temp1 = mult(VAD_SLOPE, temp1, pOverflow); + vad_thr = add(temp1, VAD_THR_HIGH, pOverflow); + + if (vad_thr < VAD_THR_LOW) + { + vad_thr = VAD_THR_LOW; + } + + /* Shift VAD decision register */ + st->vadreg = shr(st->vadreg, 1, pOverflow); + + /* Make intermediate VAD decision */ + if (snr_sum > vad_thr) + { + st->vadreg |= 0x4000; + } + /* primary vad decsion made */ + + /* check if the input power (pow_sum) is lower than a threshold" */ + if (L_sub(pow_sum, VAD_POW_LOW, pOverflow) < 0) + { + low_power_flag = 1; + } + else + { + low_power_flag = 0; + } + + /* update complex signal estimate st->corr_hp_fast and hangover reset timer using */ + /* low_power_flag and corr_hp_fast and various adaptation speeds */ + complex_estimate_adapt(st, low_power_flag, pOverflow); + + /* check multiple thresholds of the st->corr_hp_fast value */ + st->complex_warning = complex_vad(st, low_power_flag, pOverflow); + + /* Update speech subband vad background noise estimates */ + noise_estimate_update(st, level, pOverflow); + + /* Add speech and complex hangover and return speech VAD_flag */ + /* long term complex hangover may be added */ + st->speech_vad_decision = hangover_addition(st, noise_level, low_power_flag, pOverflow); + + return (st->speech_vad_decision); +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad1_init +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- double pointer to type vadState1 -- pointer to memory to + be initialized. + + Outputs: + state -- points to initalized area in memory. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Allocates state memory and initializes state memory + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 vad1_init(vadState1 **state) +{ + vadState1* s; + + if (state == (vadState1 **) NULL) + { + return -1; + } + *state = NULL; + + /* allocate memory */ + if ((s = (vadState1 *) oscl_malloc(sizeof(vadState1))) == NULL) + { + return -1; + } + + vad1_reset(s); + + *state = s; + + return 0; +} + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad1_reset +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- pointer to type vadState1 -- State struct + + Outputs: + state -- pointer to type vadState1 -- State struct + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose: Resets state memory to zero + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 vad1_reset(vadState1 *state) +{ + Word16 i; + Word16 j; + + if (state == (vadState1 *) NULL) + { + return -1; + } + + /* Initialize pitch detection variables */ + state->oldlag_count = 0; + state->oldlag = 0; + state->pitch = 0; + state->tone = 0; + + state->complex_high = 0; + state->complex_low = 0; + state->complex_hang_timer = 0; + + state->vadreg = 0; + + state->stat_count = 0; + state->burst_count = 0; + state->hang_count = 0; + state->complex_hang_count = 0; + + /* initialize memory used by the filter bank */ + for (i = 0; i < 3; i++) + { + for (j = 0; j < 2; j++) + { + state->a_data5[i][j] = 0; + } + } + + for (i = 0; i < 5; i++) + { + state->a_data3[i] = 0; + } + + /* initialize the rest of the memory */ + for (i = 0; i < COMPLEN; i++) + { + state->bckr_est[i] = NOISE_INIT; + state->old_level[i] = NOISE_INIT; + state->ave_level[i] = NOISE_INIT; + state->sub_level[i] = 0; + } + + state->best_corr_hp = CVAD_LOWPOW_RESET; + + state->speech_vad_decision = 0; + state->complex_warning = 0; + state->sp_burst_count = 0; + + state->corr_hp_fast = CVAD_LOWPOW_RESET; + + return 0; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad1_exit +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- pointer to type vadState1 -- State struct + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + The memory used for state memory is freed + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad1_exit(vadState1 **state) +{ + if (state == NULL || *state == NULL) + return; + + /* deallocate memory */ + oscl_free(*state); + *state = NULL; + + return; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad_complex_detection_update +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + best_corr_hp -- Word16 -- best Corr + state -- pointer to type vadState1 -- State struct + + Outputs: + state -- pointer to type vadState1 -- State struct + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : update vad->bestCorr_hp complex signal feature state +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad_complex_detection_update( + vadState1 *st, /* i/o : State struct */ + Word16 best_corr_hp) /* i : best Corr */ +{ + st->best_corr_hp = best_corr_hp; +} + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad_tone_detection +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + t0 -- Word32 -- autocorrelation maxima + t1 -- Word32 -- energy + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Set tone flag if pitch gain is high. This is used to detect + signaling tones and other signals with high pitch gain. + Inputs : tone: flags indicating presence of a tone + Outputs : tone: flags indicating presence of a tone +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad_tone_detection( + vadState1 *st, /* i/o : State struct */ + Word32 t0, /* i : autocorrelation maxima */ + Word32 t1, /* i : energy */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 temp; + /* + if (t0 > TONE_THR * t1) + set tone flag + */ + temp = pv_round(t1, pOverflow); + + if ((temp > 0) && (L_msu(t0, temp, TONE_THR, pOverflow) > 0)) + { + st->tone |= 0x4000; + } +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad_tone_detection_update +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + one_lag_per_frame -- Word16 -- 1 if one open-loop lag is calculated per + each frame, otherwise 0 + st -- pointer to type vadState1 -- State struct + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Update the tone flag register. Tone flags are shifted right + by one bit. This function should be called from the speech + encoder before call to Vad_tone_detection() function. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad_tone_detection_update( + vadState1 *st, /* i/o : State struct */ + Word16 one_lag_per_frame, /* i : 1 if one open-loop lag */ + /* is calculated per each */ + /* frame, otherwise 0 */ + Flag *pOverflow /* o : Flags overflow */ +) +{ + /* Shift tone flags right by one bit */ + st->tone = shr(st->tone, 1, pOverflow); + + /* If open-loop lag is calculated only once in each frame, do extra update + and assume that the other tone flag of the frame is one. */ + if (one_lag_per_frame != 0) + { + st->tone = shr(st->tone, 1, pOverflow); + st->tone |= 0x2000; + } +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad_pitch_detection +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + T_op -- array of type Word16 -- speech encoder open loop lags + st -- pointer to type vadState1 -- State struct + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Test whether signal contains pitch or other periodic + component. + Return value : Boolean voiced / unvoiced decision in state variable + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad_pitch_detection( + vadState1 *st, /* i/o : State struct */ + Word16 T_op[], /* i : speech encoder open loop lags */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 lagcount; + Word16 i; + Word16 temp; + + lagcount = 0; + + for (i = 0; i < 2; i++) + { + temp = sub(st->oldlag, T_op[i], pOverflow); + temp = abs_s(temp); + + if (temp < LTHRESH) + { + lagcount = add(lagcount, 1, pOverflow); + } + + /* Save the current LTP lag */ + st->oldlag = T_op[i]; + } + + /* Make pitch decision. + Save flag of the pitch detection to the variable pitch. + */ + st->pitch = shr(st->pitch, 1, pOverflow); + + temp = + add( + st->oldlag_count, + lagcount, + pOverflow); + + if (temp >= NTHRESH) + { + st->pitch |= 0x4000; + } + + /* Update oldlagcount */ + st->oldlag_count = lagcount; +} + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad1 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + st -- pointer to type vadState1 -- State struct + in_buf -- array of type Word16 -- samples of the input frame + + Outputs: + st -- pointer to type vadState1 -- State struct + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + VAD Decision, 1 = speech, 0 = noise + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose : Main program for Voice Activity Detection (VAD) for AMR + Return value : VAD Decision, 1 = speech, 0 = noise + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 vad1( + vadState1 *st, /* i/o : State struct */ + Word16 in_buf[], /* i : samples of the input frame */ + Flag *pOverflow /* o : Flag set when overflow occurs */ +) +{ + Word16 level[COMPLEN]; + Word32 pow_sum; + Word16 i; + + /* Calculate power of the input frame. */ + pow_sum = 0L; + + for (i = 0; i < FRAME_LEN; i++) + { + pow_sum = L_mac(pow_sum, in_buf[i-LOOKAHEAD], in_buf[i-LOOKAHEAD], pOverflow); + } + + /* + If input power is very low, clear pitch flag of the current frame + */ + if (L_sub(pow_sum, POW_PITCH_THR, pOverflow) < 0) + { + st->pitch = st->pitch & 0x3fff; + } + + /* + If input power is very low, clear complex flag of the "current" frame + */ + if (L_sub(pow_sum, POW_COMPLEX_THR, pOverflow) < 0) + { + st->complex_low = st->complex_low & 0x3fff; + } + + /* + Run the filter bank which calculates signal levels at each band + */ + filter_bank(st, in_buf, level, pOverflow); + + return (vad_decision(st, level, pow_sum, pOverflow)); +} + + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad2.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad2.cpp new file mode 100644 index 0000000..ecd1cf0 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/vad2.cpp @@ -0,0 +1,1231 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: vad2.cpp + Functions: + +------------------------------------------------------------------------------ + MODULE DESCRIPTION + + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "typedef.h" +#include "cnst.h" +#include "log2.h" +#include "pow2.h" +#include "sub.h" +#include "l_shr_r.h" +#include "abs_s.h" +#include "norm_s.h" +#include "shl.h" +#include "l_add.h" +#include "shr_r.h" +#include "add.h" +#include "mult.h" +#include "l_shr.h" +#include "mpy_32_16.h" +#include "l_mac.h" +#include "l_extract.h" +#include "l_sub.h" +#include "l_mult.h" +#include "round.h" +#include "shr.h" +#include "l_shl.h" +#include "mult_r.h" +#include "div_s.h" +#include "oscl_mem.h" + + +#include "vad2.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; LOCAL VARIABLE DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + +/* + * The channel table is defined below. In this table, the + * lower and higher frequency coefficients for each of the 16 + * channels are specified. The table excludes the coefficients + * with numbers 0 (DC), 1, and 64 (Foldover frequency). + */ + +const Word16 ch_tbl[NUM_CHAN][2] = +{ + + {2, 3}, + {4, 5}, + {6, 7}, + {8, 9}, + {10, 11}, + {12, 13}, + {14, 16}, + {17, 19}, + {20, 22}, + {23, 26}, + {27, 30}, + {31, 35}, + {36, 41}, + {42, 48}, + {49, 55}, + {56, 63} + +}; + +/* channel energy scaling table - allows efficient division by number + * of DFT bins in the channel: 1/2, 1/3, 1/4, etc. + */ + +const Word16 ch_tbl_sh[NUM_CHAN] = +{ + 16384, 16384, 16384, 16384, 16384, 16384, 10923, 10923, + 10923, 8192, 8192, 6554, 5461, 4681, 4681, 4096 +}; + +/* + * The voice metric table is defined below. It is a non- + * linear table with a deadband near zero. It maps the SNR + * index (quantized SNR value) to a number that is a measure + * of voice quality. + */ + +const Word16 vm_tbl[90] = +{ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 13, 14, 15, + 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 24, + 24, 25, 26, 27, 28, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50 +}; + +/* hangover as a function of peak SNR (3 dB steps) */ +const Word16 hangover_table[20] = +{ + 30, 30, 30, 30, 30, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 8, 8, 8 +}; + +/* burst sensitivity as a function of peak SNR (3 dB steps) */ +const Word16 burstcount_table[20] = +{ + 8, 8, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4 +}; + +/* voice metric sensitivity as a function of peak SNR (3 dB steps) */ +const Word16 vm_threshold_table[20] = +{ + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 40, 51, 71, 100, 139, 191, 257, 337, 432 +}; + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: fn10Log10 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + L_Input -- Word32 -- (scaled as 31-fbits,fbits) + fbits -- Word16 -- number of fractional bits on input + + Outputs: + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + output -- Word16 -- (scaled as 7,8) + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + PURPOSE: + The purpose of this function is to take the 10*log base 10 of input and + divide by 128 and return; i.e. output = 10*log10(input)/128 (scaled as 7,8) + + DESCRIPTION: + + 10*log10(x)/128 = 10*(log10(2) * (log2(x<<fbits)-log2(1<<fbits)) >> 7 + = 3.0103 * (log2(x<<fbits) - fbits) >> 7 + = ((3.0103/4.0 * (log2(x<<fbits) - fbits) << 2) >> 7 + = (3.0103/4.0 * (log2(x<<fbits) - fbits) >> 5 + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 fn10Log10(Word32 L_Input, Word16 fbits, Flag *pOverflow) +{ + + Word16 integer; /* Integer part of Log2. (range: 0<=val<=30) */ + Word16 fraction; /* Fractional part of Log2. (range: 0<=val<1) */ + + Word32 Ltmp; + Word16 tmp; + + Log2(L_Input, &integer, &fraction, pOverflow); + + integer = sub(integer, fbits, pOverflow); + + /* 24660 = 10*log10(2)/4 scaled 0,15 */ + Ltmp = Mpy_32_16(integer, fraction, 24660, pOverflow); + + /* extra shift for 30,1 => 15,0 extract correction */ + Ltmp = L_shr_r(Ltmp, 5 + 1, pOverflow); + + tmp = (Word16) Ltmp; + + return (tmp); +} + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: block_norm +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + in -- array of type Word16 -- pointer to data sequence to be normalised + length -- Word16 -- number of elements in data sequence + headroom -- Word16 -- number of headroom bits + + Outputs: + out -- array of type Word16 -- normalised output data sequence + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + Word16 -- number of bits sequence was left shifted + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + The purpose of this function is block normalise the input data sequence + + 1) Search for maximum absolute valued data element + 2) Normalise the max element with "headroom" + 3) Transfer/shift the input sequence to the output buffer + 4) Return the number of left shifts + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION + + An input sequence of all zeros will return the maximum + number of left shifts allowed, NOT the value returned + by a norm_s(0) call, since it desired to associate an + all zeros sequence with low energy. +------------------------------------------------------------------------------ +*/ + +Word16 block_norm( + Word16 * in, + Word16 * out, + Word16 length, + Word16 headroom, + Flag *pOverflow) +{ + + Word16 i; + Word16 max; + Word16 scnt; + Word16 adata; + + max = abs_s(in[0]); + + for (i = 1; i < length; i++) + { + adata = abs_s(in[i]); + + if (adata > max) + { + max = adata; + } + } + if (max != 0) + { + scnt = sub(norm_s(max), headroom, pOverflow); + for (i = 0; i < length; i++) + { + out[i] = shl(in[i], scnt, pOverflow); + } + } + else + { + scnt = sub(16, headroom, pOverflow); + for (i = 0; i < length; i++) + { + out[i] = 0; + } + } + return (scnt); +} + + + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad2 +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + farray_ptr -- array of type Word16, length 80 (input array) + vadState2 -- pointer to vadState2 state structure + + Outputs: + vadState2 -- pointer to vadState2 state structure -- + state variables are updated + pOverflow -- pointer to type Flag -- overflow indicator + + Returns: + Word16 + VAD(m) - two successive calls to vad2() yield + the VAD decision for the 20 ms frame: + VAD_flag = VAD(m-1) || VAD(m) + + Global Variables Used: + + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function provides the Voice Activity Detection function option 2 + for the Adaptive Multi-rate (AMR) codec. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 vad2(Word16 * farray_ptr, vadState2 * st, Flag *pOverflow) +{ + + /* State tables that use 22,9 or 27,4 scaling for ch_enrg[] */ + + const Word16 noise_floor_chan[2] = {NOISE_FLOOR_CHAN_0, NOISE_FLOOR_CHAN_1}; + const Word16 min_chan_enrg[2] = {MIN_CHAN_ENRG_0, MIN_CHAN_ENRG_1}; + const Word16 ine_noise[2] = {INE_NOISE_0, INE_NOISE_1}; + const Word16 fbits[2] = {FRACTIONAL_BITS_0, FRACTIONAL_BITS_1}; + const Word16 state_change_shift_r[2] = {STATE_1_TO_0_SHIFT_R, STATE_0_TO_1_SHIFT_R}; + + /* Energy scale table given 30,1 input scaling (also account for -6 dB shift on input) */ + const Word16 enrg_norm_shift[2] = {(FRACTIONAL_BITS_0 - 1 + 2), (FRACTIONAL_BITS_1 - 1 + 2)}; + + + /* Automatic variables */ + + Word32 Lenrg; /* scaled as 30,1 */ + Word32 Ltne; /* scaled as 22,9 */ + Word32 Ltce; /* scaled as 22,9 or 27,4 */ + + Word16 tne_db; /* scaled as 7,8 */ + Word16 tce_db; /* scaled as 7,8 */ + + Word16 input_buffer[FRM_LEN]; /* used for block normalising input data */ + Word16 data_buffer[FFT_LEN]; /* used for in-place FFT */ + + Word16 ch_snr[NUM_CHAN]; /* scaled as 7,8 */ + Word16 ch_snrq; /* scaled as 15,0 (in 0.375 dB steps) */ + Word16 vm_sum; /* scaled as 15,0 */ + Word16 ch_enrg_dev; /* scaled as 7,8 */ + + Word32 Lpeak; /* maximum channel energy */ + Word16 p2a_flag; /* flag to indicate spectral peak-to-average ratio > 10 dB */ + + Word16 ch_enrg_db[NUM_CHAN]; /* scaled as 7,8 */ + Word16 ch_noise_db; /* scaled as 7,8 */ + + Word16 alpha; /* scaled as 0,15 */ + Word16 one_m_alpha; /* scaled as 0,15 */ + Word16 update_flag; /* set to indicate a background noise estimate update */ + + Word16 i; + Word16 j; + Word16 j1; + Word16 j2; /* Scratch variables */ + + Word16 hi1; + Word16 lo1; + + Word32 Ltmp; + Word32 Ltmp1; + Word32 Ltmp2; + Word16 tmp; + + Word16 normb_shift; /* block norm shift count */ + + Word16 ivad; /* intermediate VAD decision (return value) */ + Word16 tsnrq; /* total signal-to-noise ratio (quantized 3 dB steps) scaled as 15,0 */ + Word16 xt; /* instantaneous frame SNR in dB, scaled as 7,8 */ + + Word16 state_change; + + + /* Increment frame counter */ + st->Lframe_cnt = L_add(st->Lframe_cnt, 1, pOverflow); + + /* Block normalize the input */ + normb_shift = block_norm(farray_ptr, input_buffer, FRM_LEN, FFT_HEADROOM, pOverflow); + + /* Pre-emphasize the input data and store in the data buffer with the appropriate offset */ + for (i = 0; i < DELAY; i++) + { + data_buffer[i] = 0; + } + + st->pre_emp_mem = shr_r(st->pre_emp_mem, sub(st->last_normb_shift, normb_shift, pOverflow), pOverflow); + st->last_normb_shift = normb_shift; + + data_buffer[DELAY] = add(input_buffer[0], mult(PRE_EMP_FAC, st->pre_emp_mem, pOverflow), pOverflow); + + for (i = DELAY + 1, j = 1; i < DELAY + FRM_LEN; i++, j++) + { + data_buffer[i] = add(input_buffer[j], mult(PRE_EMP_FAC, input_buffer[j-1], pOverflow), pOverflow); + } + st->pre_emp_mem = input_buffer[FRM_LEN-1]; + + for (i = DELAY + FRM_LEN; i < FFT_LEN; i++) + { + data_buffer[i] = 0; + } + + + /* Perform FFT on the data buffer */ + r_fft(data_buffer, pOverflow); + + + /* Use normb_shift factor to determine the scaling of the energy estimates */ + state_change = 0; + if (st->shift_state == 0) + { + if (normb_shift <= (-FFT_HEADROOM + 2)) + { + state_change = 1; + st->shift_state = 1; + } + } + else + { + if (normb_shift >= (-FFT_HEADROOM + 5)) + { + state_change = 1; + st->shift_state = 0; + } + } + + /* Scale channel energy estimate */ + if (state_change) + { + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + st->Lch_enrg[i] = + L_shr( + st->Lch_enrg[i], + state_change_shift_r[st->shift_state], + pOverflow); + } + } + + + /* Estimate the energy in each channel */ + if (st->Lframe_cnt == 1) + { + alpha = 32767; + one_m_alpha = 0; + } + else + { + alpha = CEE_SM_FAC; + one_m_alpha = ONE_MINUS_CEE_SM_FAC; + } + + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + Lenrg = 0; + j1 = ch_tbl[i][0]; + j2 = ch_tbl[i][1]; + + for (j = j1; j <= j2; j++) + { + Lenrg = L_mac( + Lenrg, + data_buffer[2 * j], + data_buffer[2 * j], + pOverflow); + + Lenrg = L_mac( + Lenrg, + data_buffer[2 * j + 1], + data_buffer[2 * j + 1], + pOverflow); + } + + /* Denorm energy & scale 30,1 according to the state */ + tmp = shl(normb_shift, 1, pOverflow); + tmp = sub(tmp, enrg_norm_shift[st->shift_state], pOverflow); + Lenrg = L_shr_r(Lenrg, tmp, pOverflow); + + /* integrate over time: + * e[i] = (1-alpha)*e[i] + alpha*enrg/num_bins_in_chan + */ + tmp = mult(alpha, ch_tbl_sh[i], pOverflow); + L_Extract(Lenrg, &hi1, &lo1, pOverflow); + Ltmp = Mpy_32_16(hi1, lo1, tmp, pOverflow); + + L_Extract(st->Lch_enrg[i], &hi1, &lo1, pOverflow); + + Ltmp1 = Mpy_32_16(hi1, lo1, one_m_alpha, pOverflow); + st->Lch_enrg[i] = L_add(Ltmp, Ltmp1, pOverflow); + + if (st->Lch_enrg[i] < min_chan_enrg[st->shift_state]) + { + st->Lch_enrg[i] = min_chan_enrg[st->shift_state]; + } + + } + + + /* Compute the total channel energy estimate (Ltce) */ + Ltce = 0; + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + Ltce = + L_add( + Ltce, + st->Lch_enrg[i], + pOverflow); + } + + + /* Calculate spectral peak-to-average ratio, set flag if p2a > 10 dB */ + Lpeak = 0; + + /* Sine waves not valid for low frequencies */ + for (i = LO_CHAN + 2; i <= HI_CHAN; i++) + { + if (L_sub(st->Lch_enrg [i], Lpeak, pOverflow) > 0) + { + Lpeak = st->Lch_enrg [i]; + } + } + + /* Set p2a_flag if peak (dB) > average channel energy (dB) + 10 dB */ + /* Lpeak > Ltce/num_channels * 10^(10/10) */ + /* Lpeak > (10/16)*Ltce */ + + L_Extract(Ltce, &hi1, &lo1, pOverflow); + Ltmp = Mpy_32_16(hi1, lo1, 20480, pOverflow); + if (L_sub(Lpeak, Ltmp, pOverflow) > 0) + { + p2a_flag = TRUE; + } + else + { + p2a_flag = FALSE; + } + + + /* Initialize channel noise estimate to either the channel energy or fixed level */ + /* Scale the energy appropriately to yield state 0 (22,9) scaling for noise */ + if (st->Lframe_cnt <= 4) + { + if (p2a_flag == TRUE) + { + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + st->Lch_noise[i] = INE_NOISE_0; + } + } + else + { + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + if (st->Lch_enrg[i] < ine_noise[st->shift_state]) + { + st->Lch_noise[i] = INE_NOISE_0; + } + else + { + if (st->shift_state == 1) + { + st->Lch_noise[i] = + L_shr( + st->Lch_enrg[i], + state_change_shift_r[0], + pOverflow); + } + else + { + st->Lch_noise[i] = st->Lch_enrg[i]; + } + } + } + } + } + + + /* Compute the channel energy (in dB), the channel SNRs, and the sum of voice metrics */ + vm_sum = 0; + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + ch_enrg_db[i] = + fn10Log10( + st->Lch_enrg[i], + fbits[st->shift_state], + pOverflow); + + ch_noise_db = + fn10Log10( + st->Lch_noise[i], + FRACTIONAL_BITS_0, + pOverflow); + + ch_snr[i] = sub(ch_enrg_db[i], ch_noise_db, pOverflow); + + /* quantize channel SNR in 3/8 dB steps (scaled 7,8 => 15,0) */ + /* ch_snr = pv_round((snr/(3/8))>>8) */ + /* = pv_round(((0.6667*snr)<<2)>>8) */ + /* = pv_round((0.6667*snr)>>6) */ + + tmp = mult(21845, ch_snr[i], pOverflow); + + ch_snrq = shr_r(tmp, 6, pOverflow); + + /* Accumulate the sum of voice metrics */ + if (ch_snrq < 89) + { + if (ch_snrq > 0) + { + j = ch_snrq; + } + else + { + j = 0; + } + } + else + { + j = 89; + } + vm_sum = add(vm_sum, vm_tbl[j], pOverflow); + } + + + /* Initialize NOMINAL peak voice energy and average noise energy, calculate instantaneous SNR */ + if (st->Lframe_cnt <= 4 || st->fupdate_flag == TRUE) + { + /* tce_db = (96 - 22 - 10*log10(64) (due to FFT)) scaled as 7,8 */ + tce_db = 14320; + st->negSNRvar = 0; + st->negSNRbias = 0; + + /* Compute the total noise estimate (Ltne) */ + Ltne = 0; + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + Ltne = L_add(Ltne, st->Lch_noise[i], pOverflow); + } + + /* Get total noise in dB */ + tne_db = + fn10Log10( + Ltne, + FRACTIONAL_BITS_0, + pOverflow); + + /* Initialise instantaneous and long-term peak signal-to-noise ratios */ + xt = sub(tce_db, tne_db, pOverflow); + st->tsnr = xt; + } + else + { + /* Calculate instantaneous frame signal-to-noise ratio */ + /* xt = 10*log10( sum(2.^(ch_snr*0.1*log2(10)))/length(ch_snr) ) */ + Ltmp1 = 0; + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + /* Ltmp2 = ch_snr[i] * 0.1 * log2(10); (ch_snr scaled as 7,8) */ + Ltmp2 = L_mult(ch_snr[i], 10885, pOverflow); + Ltmp2 = L_shr(Ltmp2, 8, pOverflow); + + L_Extract(Ltmp2, &hi1, &lo1, pOverflow); + hi1 = add(hi1, 3, pOverflow); /* 2^3 to compensate for negative SNR */ + + Ltmp2 = Pow2(hi1, lo1, pOverflow); + + Ltmp1 = L_add(Ltmp1, Ltmp2, pOverflow); + } + xt = + fn10Log10( + Ltmp1, + 4 + 3, + pOverflow); /* average by 16, inverse compensation 2^3 */ + + /* Estimate long-term "peak" SNR */ + if (xt > st->tsnr) + { + Ltmp1 = L_mult(29491, st->tsnr, pOverflow); + Ltmp2 = L_mult(3277, xt, pOverflow); + Ltmp1 = L_add(Ltmp1, Ltmp2, pOverflow); + + /* tsnr = 0.9*tsnr + 0.1*xt; */ + st->tsnr = pv_round(Ltmp1, pOverflow); + } + /* else if (xt > 0.625*tsnr) */ + else + { + tmp = mult(20480, st->tsnr, pOverflow); + tmp = sub(xt, tmp, pOverflow); + + if (tmp > 0) + { + /* tsnr = 0.998*tsnr + 0.002*xt; */ + Ltmp1 = L_mult(32702, st->tsnr, pOverflow); + Ltmp2 = L_mult(66, xt, pOverflow); + Ltmp1 = L_add(Ltmp1, Ltmp2, pOverflow); + + st->tsnr = pv_round(Ltmp1, pOverflow); + } + } + } + + /* Quantize the long-term SNR in 3 dB steps, limit to 0 <= tsnrq <= 19 */ + tmp = mult(st->tsnr, 10923, pOverflow); + tsnrq = shr(tmp, 8, pOverflow); + + /* tsnrq = min(19, max(0, tsnrq)); */ + if (tsnrq > 19) + { + tsnrq = 19; + } + else if (tsnrq < 0) + { + tsnrq = 0; + } + + /* Calculate the negative SNR sensitivity bias */ + if (xt < 0) + { + /* negSNRvar = 0.99*negSNRvar + 0.01*xt*xt; */ + /* xt scaled as 7,8 => xt*xt scaled as 14,17, shift to 7,8 and round */ + Ltmp1 = L_mult(xt, xt, pOverflow); + Ltmp1 = L_shl(Ltmp1, 7, pOverflow); + tmp = pv_round(Ltmp1, pOverflow); + + Ltmp1 = L_mult(32440, st->negSNRvar, pOverflow); + Ltmp2 = L_mult(328, tmp, pOverflow); + Ltmp1 = L_add(Ltmp1, Ltmp2, pOverflow); + + st->negSNRvar = pv_round(Ltmp1, pOverflow); + + /* if (negSNRvar > 4.0) negSNRvar = 4.0; */ + if (st->negSNRvar > 1024) + { + st->negSNRvar = 1024; + } + + /* negSNRbias = max(12.0*(negSNRvar - 0.65), 0.0); */ + tmp = sub(st->negSNRvar, 166, pOverflow); + tmp = shl(tmp, 4, pOverflow); + tmp = mult_r(tmp, 24576, pOverflow); + + if (tmp < 0) + { + st->negSNRbias = 0; + } + else + { + st->negSNRbias = shr(tmp, 8, pOverflow); + } + } + + + /* Determine VAD as a function of the voice metric sum and quantized SNR */ + + tmp = add(vm_threshold_table[tsnrq], st->negSNRbias, pOverflow); + + if (vm_sum > tmp) + { + ivad = 1; + st->burstcount = add(st->burstcount, 1, pOverflow); + if (st->burstcount > burstcount_table[tsnrq]) + { + st->hangover = hangover_table[tsnrq]; + } + } + else + { + st->burstcount = 0; + st->hangover = sub(st->hangover, 1, pOverflow); + if (st->hangover <= 0) + { + ivad = 0; + st->hangover = 0; + } + else + { + ivad = 1; + } + } + + + /* Calculate log spectral deviation */ + ch_enrg_dev = 0; + if (st->Lframe_cnt == 1) + { + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + st->ch_enrg_long_db[i] = ch_enrg_db[i]; + } + } + else + { + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + tmp = sub(st->ch_enrg_long_db[i], ch_enrg_db[i], pOverflow); + tmp = abs_s(tmp); + + ch_enrg_dev = add(ch_enrg_dev, tmp, pOverflow); + } + } + + /* + * Calculate long term integration constant as + * a function of instantaneous SNR + * (i.e., high SNR (tsnr dB) -> slower integration (alpha = HIGH_ALPHA), + * low SNR (0 dB) -> faster integration (alpha = LOW_ALPHA) + */ + + /* alpha = HIGH_ALPHA - ALPHA_RANGE * (tsnr - xt) + * ---------------------------------------------- + * tsnr, low <= alpha <= high + */ + tmp = sub(st->tsnr, xt, pOverflow); + if (tmp <= 0 || st->tsnr <= 0) + { + alpha = HIGH_ALPHA; + one_m_alpha = 32768L - HIGH_ALPHA; + } + else if (tmp > st->tsnr) + { + alpha = LOW_ALPHA; + one_m_alpha = 32768L - LOW_ALPHA; + } + else + { + tmp = div_s(tmp, st->tsnr); + tmp = mult(ALPHA_RANGE, tmp, pOverflow); + alpha = sub(HIGH_ALPHA, tmp, pOverflow); + one_m_alpha = sub(32767, alpha, pOverflow); + } + + /* Calc long term log spectral energy */ + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + Ltmp1 = L_mult(one_m_alpha, ch_enrg_db[i], pOverflow); + Ltmp2 = L_mult(alpha, st->ch_enrg_long_db[i], pOverflow); + + Ltmp1 = L_add(Ltmp1, Ltmp2, pOverflow); + st->ch_enrg_long_db[i] = pv_round(Ltmp1, pOverflow); + } + + + /* Set or clear the noise update flags */ + update_flag = FALSE; + st->fupdate_flag = FALSE; + if (vm_sum <= UPDATE_THLD) + { + if (st->burstcount == 0) + { + update_flag = TRUE; + st->update_cnt = 0; + } + } + else if (L_sub(Ltce, noise_floor_chan[st->shift_state], pOverflow) > 0) + { + if (ch_enrg_dev < DEV_THLD) + { + if (p2a_flag == FALSE) + { + if (st->LTP_flag == FALSE) + { + st->update_cnt = add(st->update_cnt, 1, pOverflow); + if (st->update_cnt >= UPDATE_CNT_THLD) + { + update_flag = TRUE; + st->fupdate_flag = TRUE; + } + } + } + } + } + if (st->update_cnt == st->last_update_cnt) + { + st->hyster_cnt = add(st->hyster_cnt, 1, pOverflow); + } + else + { + st->hyster_cnt = 0; + } + + st->last_update_cnt = st->update_cnt; + + if (st->hyster_cnt > HYSTER_CNT_THLD) + { + st->update_cnt = 0; + } + + + /* Conditionally update the channel noise estimates */ + if (update_flag == TRUE) + { + /* Check shift state */ + if (st->shift_state == 1) + { + /* get factor to shift ch_enrg[] + * from state 1 to 0 (noise always state 0) + */ + tmp = state_change_shift_r[0]; + } + else + { + /* No shift if already state 0 */ + tmp = 0; + } + + /* Update noise energy estimate */ + for (i = LO_CHAN; i <= HI_CHAN; i++) + { + /* integrate over time: en[i] = (1-alpha)*en[i] + alpha*e[n] */ + /* (extract with shift compensation for state 1) */ + + Ltmp1 = L_shr(st->Lch_enrg[i], tmp, pOverflow); + L_Extract(Ltmp1, &hi1, &lo1, pOverflow); + + Ltmp = Mpy_32_16(hi1, lo1, CNE_SM_FAC, pOverflow); + + L_Extract(st->Lch_noise[i], &hi1, &lo1, pOverflow); + + Ltmp1 = Mpy_32_16(hi1, lo1, ONE_MINUS_CNE_SM_FAC, pOverflow); + st->Lch_noise[i] = L_add(Ltmp, Ltmp1, pOverflow); + + /* Limit low level noise */ + if (st->Lch_noise[i] <= MIN_NOISE_ENRG_0) + { + st->Lch_noise[i] = MIN_NOISE_ENRG_0; + } + } + } + + return(ivad); +} /* end of vad2 () */ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad2_init +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- double pointer to type vadState2 -- pointer to memory to + be initialized. + + Outputs: + state -- points to initalized area in memory. + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Allocates state memory and initializes state memory + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ +Word16 vad2_init(vadState2 **state) +{ + vadState2* s; + + if (state == (vadState2 **) NULL) + { + return -1; + } + *state = NULL; + + /* allocate memory */ + if ((s = (vadState2 *) oscl_malloc(sizeof(vadState2))) == NULL) + { + return -1; + } + + vad2_reset(s); + + *state = s; + + return 0; +} + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad2_reset +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- pointer to type vadState1 -- State struct + + Outputs: + state -- pointer to type vadState1 -- State struct + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + Purpose: Resets state memory to zero + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +Word16 vad2_reset(vadState2 * st) +{ + Word16 i; + Word16 *ptr; + + if (st == (vadState2 *) NULL) + { + return -1; + } + ptr = (Word16 *)st; + + for (i = 0; i < sizeof(vadState2) / 2; i++) + { + *ptr++ = 0; + } + + return 0; +} /* end of vad2_reset () */ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: vad2_exit +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + state -- pointer to type vadState1 -- State struct + + Outputs: + None + + Returns: + None + + Global Variables Used: + None + + Local Variables Needed: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + The memory used for state memory is freed + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + vad2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +void vad2_exit(vadState2 **state) +{ + if (state == NULL || *state == NULL) + { + return; + } + + /* deallocate memory */ + oscl_free(*state); + *state = NULL; + + return; +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/weight_a.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/weight_a.cpp new file mode 100644 index 0000000..98382b8 --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/weight_a.cpp @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + + Filename: weight_a.cpp + +------------------------------------------------------------------------------ +*/ + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "weight_a.h" +#include "typedef.h" +#include "cnst.h" + +/*---------------------------------------------------------------------------- +; MACROS +; Define module specific macros here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; DEFINES +; Include all pre-processor statements here. Include conditional +; compile variables also. +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL FUNCTION DEFINITIONS +; Function Prototype declaration +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; LOCAL STORE/BUFFER/POINTER DEFINITIONS +; Variable declaration - defined here and used outside this module +----------------------------------------------------------------------------*/ + + +/* +------------------------------------------------------------------------------ + FUNCTION NAME: Weight_Ai +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + a = LPC coefficients (Word16) + fac = Spectral expansion factors (Word16) + a_exp = Spectral expanded LPC coefficients (Word16) + + Outputs: + a_exp points to the updated spectral expanded LPC coefficients + + Returns: + None. + + Global Variables Used: + None. + + Local Variables Needed: + None. + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + This function calculates the spectral expansion for the LP coefficients of + order M. + a_exp[i] = a[i] * fac[i-1] ; i=1..M + +------------------------------------------------------------------------------ + REQUIREMENTS + + None. + +------------------------------------------------------------------------------ + REFERENCES + + weight_a.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 + +------------------------------------------------------------------------------ + PSEUDO-CODE + +void Weight_Ai ( + Word16 a[], // (i) : a[M+1] LPC coefficients (M=10) + const Word16 fac[], // (i) : Spectral expansion factors. + Word16 a_exp[] // (o) : Spectral expanded LPC coefficients +) +{ + Word16 i; + a_exp[0] = a[0]; + + for (i = 1; i <= M; i++) + { + a_exp[i] = pv_round (L_mult (a[i], fac[i - 1])); + } + return; +} + +------------------------------------------------------------------------------ + CAUTION [optional] + [State any special notes, constraints or cautions for users of this function] + +------------------------------------------------------------------------------ +*/ + +OSCL_EXPORT_REF void Weight_Ai( + Word16 a[], /* (i) : a[M+1] LPC coefficients (M=10) */ + const Word16 fac[], /* (i) : Spectral expansion factors. */ + Word16 a_exp[] /* (o) : Spectral expanded LPC coefficients */ +) +{ + register Word16 i; + + *(a_exp) = *(a); + + for (i = M; i >= 1; i--) + { + a_exp += 1; + a += 1; + fac += 1; + *(a_exp) = (Word16)((((Word32) * (a)) * *(fac - 1) + + 0x00004000L) >> 15); + } + + return; +} + diff --git a/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/window_tab.cpp b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/window_tab.cpp new file mode 100644 index 0000000..14ecf2e --- /dev/null +++ b/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/src/window_tab.cpp @@ -0,0 +1,244 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 1998-2009 PacketVideo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ +/**************************************************************************************** +Portions of this file are derived from the following 3GPP standard: + + 3GPP TS 26.073 + ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec + Available from http://www.3gpp.org + +(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) +Permission to distribute, modify and use this file under the standard license +terms listed above has been obtained from the copyright holder. +****************************************************************************************/ +/* + Filename: window_tab.cpp + +------------------------------------------------------------------------------ + INPUT AND OUTPUT DEFINITIONS + + Inputs: + None + + Local Stores/Buffers/Pointers Needed: + None + + Global Stores/Buffers/Pointers Needed: + None + + Outputs: + None + + Pointers and Buffers Modified: + None + + Local Stores Modified: + None + + Global Stores Modified: + None + +------------------------------------------------------------------------------ + FUNCTION DESCRIPTION + + File : window.tab + Purpose : Hamming_cos window for LPC analysis. + +------------------------------------------------------------------------------ + REQUIREMENTS + + None + +------------------------------------------------------------------------------ + REFERENCES + + None + +------------------------------------------------------------------------------ + PSEUDO-CODE + + +------------------------------------------------------------------------------ +*/ + + +/*---------------------------------------------------------------------------- +; INCLUDES +----------------------------------------------------------------------------*/ +#include "window_tab.h" + +/*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +extern "C" +{ +#endif + + /*---------------------------------------------------------------------------- + ; MACROS + ; Define module specific macros here + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; DEFINES + ; Include all pre-processor statements here. Include conditional + ; compile variables also. + ----------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------- + ; LOCAL FUNCTION DEFINITIONS + ; Function Prototype declaration + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; LOCAL STORE/BUFFER/POINTER DEFINITIONS + ; Variable declaration - defined here and used outside this module + ----------------------------------------------------------------------------*/ + /************************************************************************* + * + * Hamming_cos windows for LPC analysis. + * + *************************************************************************/ + + /* window for non-EFR modesm; uses 40 samples lookahead */ + + const Word16 window_200_40[L_WINDOW] = + { + 2621, 2623, 2629, 2638, 2651, 2668, 2689, 2713, 2741, 2772, + 2808, 2847, 2890, 2936, 2986, 3040, 3097, 3158, 3223, 3291, + 3363, 3438, 3517, 3599, 3685, 3774, 3867, 3963, 4063, 4166, + 4272, 4382, 4495, 4611, 4731, 4853, 4979, 5108, 5240, 5376, + 5514, 5655, 5800, 5947, 6097, 6250, 6406, 6565, 6726, 6890, + 7057, 7227, 7399, 7573, 7750, 7930, 8112, 8296, 8483, 8672, + 8863, 9057, 9252, 9450, 9650, 9852, 10055, 10261, 10468, 10677, + 10888, 11101, 11315, 11531, 11748, 11967, 12187, 12409, 12632, 12856, + 13082, 13308, 13536, 13764, 13994, 14225, 14456, 14688, 14921, 15155, + 15389, 15624, 15859, 16095, 16331, 16568, 16805, 17042, 17279, 17516, + 17754, 17991, 18228, 18465, 18702, 18939, 19175, 19411, 19647, 19882, + 20117, 20350, 20584, 20816, 21048, 21279, 21509, 21738, 21967, 22194, + 22420, 22644, 22868, 23090, 23311, 23531, 23749, 23965, 24181, 24394, + 24606, 24816, 25024, 25231, 25435, 25638, 25839, 26037, 26234, 26428, + 26621, 26811, 26999, 27184, 27368, 27548, 27727, 27903, 28076, 28247, + 28415, 28581, 28743, 28903, 29061, 29215, 29367, 29515, 29661, 29804, + 29944, 30081, 30214, 30345, 30472, 30597, 30718, 30836, 30950, 31062, + 31170, 31274, 31376, 31474, 31568, 31659, 31747, 31831, 31911, 31988, + 32062, 32132, 32198, 32261, 32320, 32376, 32428, 32476, 32521, 32561, + 32599, 32632, 32662, 32688, 32711, 32729, 32744, 32755, 32763, 32767, + 32767, 32741, 32665, 32537, 32359, 32129, 31850, 31521, 31143, 30716, + 30242, 29720, 29151, 28538, 27879, 27177, 26433, 25647, 24821, 23957, + 23055, 22117, 21145, 20139, 19102, 18036, 16941, 15820, 14674, 13505, + 12315, 11106, 9879, 8637, 7381, 6114, 4838, 3554, 2264, 971 + }; + + + /* window for EFR, first two subframes, no lookahead */ + + const Word16 window_160_80[L_WINDOW] = + { + 2621, 2624, 2633, 2648, 2668, 2695, 2727, 2765, 2809, 2859, + 2915, 2976, 3043, 3116, 3194, 3279, 3368, 3464, 3565, 3671, + 3783, 3900, 4023, 4151, 4285, 4423, 4567, 4716, 4870, 5029, + 5193, 5362, 5535, 5714, 5897, 6084, 6277, 6473, 6674, 6880, + 7089, 7303, 7521, 7742, 7968, 8197, 8430, 8667, 8907, 9151, + 9398, 9648, 9902, 10158, 10417, 10680, 10945, 11212, 11482, 11755, + 12030, 12307, 12586, 12867, 13150, 13435, 13722, 14010, 14299, 14590, + 14882, 15175, 15469, 15764, 16060, 16356, 16653, 16950, 17248, 17546, + 17844, 18141, 18439, 18736, 19033, 19330, 19625, 19920, 20214, 20507, + 20799, 21090, 21380, 21668, 21954, 22239, 22522, 22803, 23083, 23360, + 23635, 23907, 24177, 24445, 24710, 24972, 25231, 25488, 25741, 25991, + 26238, 26482, 26722, 26959, 27192, 27422, 27647, 27869, 28087, 28300, + 28510, 28715, 28916, 29113, 29305, 29493, 29676, 29854, 30028, 30197, + 30361, 30519, 30673, 30822, 30966, 31105, 31238, 31366, 31489, 31606, + 31718, 31825, 31926, 32021, 32111, 32195, 32273, 32346, 32413, 32475, + 32530, 32580, 32624, 32662, 32695, 32721, 32742, 32756, 32765, 32767, + 32767, 32756, 32720, 32661, 32578, 32471, 32341, 32188, 32012, 31813, + 31592, 31349, 31084, 30798, 30492, 30165, 29818, 29453, 29068, 28666, + 28247, 27810, 27358, 26891, 26408, 25913, 25404, 24883, 24350, 23807, + 23255, 22693, 22124, 21548, 20965, 20378, 19786, 19191, 18593, 17994, + 17395, 16796, 16199, 15604, 15012, 14424, 13842, 13265, 12696, 12135, + 11582, 11039, 10507, 9986, 9477, 8981, 8499, 8031, 7579, 7143, + 6723, 6321, 5937, 5571, 5225, 4898, 4591, 4305, 4041, 3798, + 3577, 3378, 3202, 3048, 2918, 2812, 2729, 2669, 2633, 2621 + }; + + /* window for EFR, last two subframes, no lookahead */ + + const Word16 window_232_8[L_WINDOW] = + { + 2621, 2623, 2627, 2634, 2644, 2656, 2671, 2689, 2710, 2734, + 2760, 2789, 2821, 2855, 2893, 2933, 2975, 3021, 3069, 3120, + 3173, 3229, 3288, 3350, 3414, 3481, 3550, 3622, 3697, 3774, + 3853, 3936, 4021, 4108, 4198, 4290, 4385, 4482, 4582, 4684, + 4788, 4895, 5004, 5116, 5230, 5346, 5464, 5585, 5708, 5833, + 5960, 6090, 6221, 6355, 6491, 6629, 6769, 6910, 7054, 7200, + 7348, 7498, 7649, 7803, 7958, 8115, 8274, 8434, 8597, 8761, + 8926, 9093, 9262, 9432, 9604, 9778, 9952, 10129, 10306, 10485, + 10665, 10847, 11030, 11214, 11399, 11586, 11773, 11962, 12152, 12342, + 12534, 12727, 12920, 13115, 13310, 13506, 13703, 13901, 14099, 14298, + 14497, 14698, 14898, 15100, 15301, 15504, 15706, 15909, 16112, 16316, + 16520, 16724, 16928, 17132, 17337, 17541, 17746, 17950, 18155, 18359, + 18564, 18768, 18972, 19175, 19379, 19582, 19785, 19987, 20189, 20390, + 20591, 20792, 20992, 21191, 21390, 21588, 21785, 21981, 22177, 22372, + 22566, 22759, 22951, 23143, 23333, 23522, 23710, 23897, 24083, 24268, + 24451, 24633, 24814, 24994, 25172, 25349, 25525, 25699, 25871, 26042, + 26212, 26380, 26546, 26711, 26874, 27035, 27195, 27353, 27509, 27664, + 27816, 27967, 28115, 28262, 28407, 28550, 28691, 28830, 28967, 29102, + 29234, 29365, 29493, 29619, 29743, 29865, 29985, 30102, 30217, 30330, + 30440, 30548, 30654, 30757, 30858, 30956, 31052, 31146, 31237, 31326, + 31412, 31495, 31576, 31655, 31730, 31804, 31874, 31942, 32008, 32071, + 32131, 32188, 32243, 32295, 32345, 32392, 32436, 32477, 32516, 32552, + 32585, 32615, 32643, 32668, 32690, 32709, 32726, 32740, 32751, 32759, + 32765, 32767, 32767, 32097, 30112, 26895, 22576, 17333, 11380, 4962 + }; + + /*---------------------------------------------------------------------------- + ; EXTERNAL FUNCTION REFERENCES + ; Declare functions defined elsewhere and referenced in this module + ----------------------------------------------------------------------------*/ + + + /*---------------------------------------------------------------------------- + ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES + ; Declare variables used in this module but defined elsewhere + ----------------------------------------------------------------------------*/ + + + /*--------------------------------------------------------------------------*/ +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- +; FUNCTION CODE +----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- +; Define all local variables +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Function body here +----------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------- +; Return nothing or data or data pointer +----------------------------------------------------------------------------*/ + |