⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns127.c

📁 完整的EVRC压缩解压缩算法源码,附带一个简单的例子程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
Each of the companies; Lucent, Motorola, Nokia, and Qualcomm (hereinafter 
referred to individually as "Source" or collectively as "Sources") do 
hereby state:

To the extent to which the Source(s) may legally and freely do so, the 
Source(s), upon submission of a Contribution, grant(s) a free, 
irrevocable, non-exclusive, license to the Third Generation Partnership 
Project 2 (3GPP2) and its Organizational Partners: ARIB, CCSA, TIA, TTA, 
and TTC, under the Source's copyright or copyright license rights in the 
Contribution, to, in whole or in part, copy, make derivative works, 
perform, display and distribute the Contribution and derivative works 
thereof consistent with 3GPP2's and each Organizational Partner's 
policies and procedures, with the right to (i) sublicense the foregoing 
rights consistent with 3GPP2's and each Organizational Partner's  policies 
and procedures and (ii) copyright and sell, if applicable) in 3GPP2's name 
or each Organizational Partner's name any 3GPP2 or transposed Publication 
even though this Publication may contain the Contribution or a derivative 
work thereof.  The Contribution shall disclose any known limitations on 
the Source's rights to license as herein provided.

When a Contribution is submitted by the Source(s) to assist the 
formulating groups of 3GPP2 or any of its Organizational Partners, it 
is proposed to the Committee as a basis for discussion and is not to 
be construed as a binding proposal on the Source(s).  The Source(s) 
specifically reserve(s) the right to amend or modify the material 
contained in the Contribution. Nothing contained in the Contribution 
shall, except as herein expressly provided, be construed as conferring 
by implication, estoppel or otherwise, any license or right under (i) 
any existing or later issuing patent, whether or not the use of 
information in the document necessarily employs an invention of any 
existing or later issued patent, (ii) any copyright, (iii) any 
trademark, or (iv) any other intellectual property right.

With respect to the Software necessary for the practice of any or 
all Normative portions of the Enhanced Variable Rate Codec (EVRC) as 
it exists on the date of submittal of this form, should the EVRC be 
approved as a Specification or Report by 3GPP2, or as a transposed 
Standard by any of the 3GPP2's Organizational Partners, the Source(s) 
state(s) that a worldwide license to reproduce, use and distribute the 
Software, the license rights to which are held by the Source(s), will 
be made available to applicants under terms and conditions that are 
reasonable and non-discriminatory, which may include monetary compensation, 
and only to the extent necessary for the practice of any or all of the 
Normative portions of the EVRC or the field of use of practice of the 
EVRC Specification, Report, or Standard.  The statement contained above 
is irrevocable and shall be binding upon the Source(s).  In the event 
the rights of the Source(s) in and to copyright or copyright license 
rights subject to such commitment are assigned or transferred, the 
Source(s) shall notify the assignee or transferee of the existence of 
such commitments.
*******************************************************************/
 
/*======================================================================*/
/*     Enhanced Variable Rate Codec - Bit-Exact C Specification         */
/*     Copyright (C) 1997-1998 Telecommunications Industry Association. */
/*     All rights reserved.                                             */
/*----------------------------------------------------------------------*/
/* Note:  Reproduction and use of this software for the design and      */
/*     development of North American Wideband CDMA Digital              */
/*     Cellular Telephony Standards is authorized by the TIA.           */
/*     The TIA does not authorize the use of this software for any      */
/*     other purpose.                                                   */
/*                                                                      */
/*     The availability of this software does not provide any license   */
/*     by implication, estoppel, or otherwise under any patent rights   */
/*     of TIA member companies or others covering any use of the        */
/*     contents herein.                                                 */
/*                                                                      */
/*     Any copies of this software or derivative works must include     */
/*     this and all other proprietary notices.                          */
/*======================================================================*/
/* ns127.c */
/*****************************************************************
*
* EVRC Noise Suppression
*
* Input:  The input to the function is a Shortword pointer to the
*         array of data to be noise suppressed.
*
* Output: There is no return value.  The input array is replaced
*         with the noise suppressed values.
*
*
* Written by:                   Tenkasi V. Ramabadran
* Date:                         December 28, 1994
*
* Last Modified:		James Ashley
* Date:				November 7, 1996
*
* Version    Date      Description
*
*   1.0    12/01/95    Released to TIA TR45.5.1.1
*   1.1    02/14/96    Init Noise to first 4 frames      
*   1.2    02/19/96    Bug fix in frame_cnt declaration  
*          03/27/96    Revised for Fixed Point Calculations
*          05/28/96    Adjust thresholds for -6 dB input level,
*                      add block_norm/denorm around FFT/IFFT,
*                      general scaling cleanup.
*   1.3    08/09/96    Adjusted thresholds to 0dB input level, 
*                      Modified block_denormalization to provide 6 db adjustment.
*   1.4    10/15/96    Apply block_norm call to farray_ptr instead of data_buffer
*                      (fixes high level input problems). (JPA)
*   1.5    11/07/96    Fix bug in block_norm(). (JPA)
*****************************************************************/
#include <stdio.h>

/* Includes */
#include "mathevrc.h"
#include "mathdp31.h"
#include "mathadv.h"

/* Defines */
#define         FRM_LEN                 80
#define         DELAY                   24
#define         FFT_LEN                 128

#define         NUM_CHAN                16
#define         LO_CHAN                 0
#define         MID_CHAN                5
#define         HI_CHAN                 15

#define         TRUE                    1
#define         FALSE                   0

#define         UPDATE_THLD             35
#define         METRIC_THLD             45
#define         INDEX_THLD              12
#define         SETBACK_THLD            12
#define         SNR_THLD                6
#define         INDEX_CNT_THLD          5
#define         HYSTER_CNT_THLD         6
#define         UPDATE_CNT_THLD         50

/* Define the following if 0db input to ns */
#define		INPUT_0_DB
#ifdef		INPUT_MINUS_6_DB

#define         NOISE_FLOOR_CHAN        64	/* 1.0/4 scaled as 23,8 */
#define         MIN_CHAN_ENRG           4	/* 0.0625/4 scaled as 23,8 */
#define         MIN_NOISE_ENRG          4	/* 0.0625/4 scaled as 23,8 */
#define         INE_CHAN                1024	/* 16.0/4 scaled as 23,8 */
#define         INE_NOISE               1024	/* 16.0/4 scaled as 23,8 */

#define         HIGH_TCE_DB             1408	/* 44.0 scaled as 10,5 */
#define         LOW_TCE_DB              768	/* 24.0 scaled as 10,5 */

#endif
#ifdef		INPUT_0_DB

#define         NOISE_FLOOR_CHAN        256	/* 1.0 scaled as 23,8 */
#define         MIN_CHAN_ENRG           16	/* 0.0625 scaled as 23,8 */
#define         MIN_NOISE_ENRG          16	/* 0.0625 scaled as 23,8 */
#define         INE_CHAN                4096	/* 16.0 scaled as 23,8 */
#define         INE_NOISE               4096	/* 16.0 scaled as 23,8 */

#define         HIGH_TCE_DB             1600	/* 50.0 scaled as 10,5 */
#define         LOW_TCE_DB              960	/* 30.0 scaled as 10,5 */

#endif



#define         TCE_RANGE               (HIGH_TCE_DB - LOW_TCE_DB)
#define         HIGH_ALPHA_S5_10        1023
#define         LOW_ALPHA_S5_10         511
#define         HIGH_ALPHA              32440	/* 0.99 scaled as 0,15 */
#define         LOW_ALPHA               16383	/* 0.50 scaled as 0,15 */

#define         ALPHA_RANGE             (HIGH_ALPHA - LOW_ALPHA)
#define         ALPHA_RAN_DIV_TCE_RAN   803		/* (0.99 - 0.50) / 20 scaled as 0,15 */
#define         DEV_THLD                896		/* 28.0 scaled as 10,5 */
#define         PRE_EMP_FAC             -26214	/* -0.8 scaled as 0,15 */
#define         CEE_SM_FAC              1181116006	/* 0.55 scaled as 0,31 */
#define         ONE_MINUS_CEE_SM_FAC    966367642	/* 0.55 scaled as 0,31 */
#define         MIN_GAIN                -27262976	/* (-13.0) scaled as 11,20 */
#define         GAIN_SLOPE              14879	/* 0.45 scaled as 0,15 */
#define         CNE_SM_FAC              3277	/* 0.1 scaled as 0,15 */

#define         ONE_MINUS_CNE_SM_FAC    (32767-CNE_SM_FAC)
#define         DE_EMP_FAC              26214	/* 0.8 scaled as 0,15 */
#define         LOG_OFFSET              626255212	/* 9.3319 scaled as 5,26 */
#define         ONE_OVER_20             1638	/* 1/20 scaled as 0,15 */
#define         TEN_S5_10               10270	/* 10.0 scaled as 5,10 */
#define         CONST_0_1875_S10_21     393216	/* 0.1875 scaled as 10,21 */
#define         CONST_2_667_S5_10       2731	/* 2.667 scaled as 5,10 */

#define         FFT_HEADROOM            2
#define         IFFT_HEADROOM           4

/* Local functions */

Shortword block_norm(Shortword * data, Shortword size, Shortword headroom)
{

	Shortword i, max, scnt, adata;

	max = abs(data[0]);
	for (i = 1; i < size; i++)
	{
		adata = abs(data[i]);
		if (adata > max)
			max = adata;
	}
	scnt = norm_s(max) - headroom;
	for (i = 0; i < size; i++)
	{
		data[i] = shift_r(data[i], scnt);
	}
	return (scnt);

}

void block_denorm(Shortword * data, Shortword size, Shortword scnt)
{

	Shortword i;

	for (i = 0; i < size; i++)
	{
		data[i] = shift_r(data[i], negate(scnt));
	}
	return;

}

/* The noise supression function */
void noise_suprs(Shortword * farray_ptr)
{

/*
 * 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).  For
 * these coefficients, the gain is always set at 1.0 (0 dB).
 */

	static Shortword 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}

	};

	static Shortword ch_tbl_sh[NUM_CHAN][2] =
	{

		{TRUE, 1},
		{TRUE, 1},
		{TRUE, 1},
		{TRUE, 1},
		{TRUE, 1},
		{TRUE, 1},
		{FALSE, 10922},
		{FALSE, 10922},
		{FALSE, 10922},
		{TRUE, 2},
		{TRUE, 2},
		{FALSE, 6553},
		{FALSE, 5462},
		{FALSE, 4681},
		{FALSE, 4681},
		{TRUE, 3}

	};

/*
 * 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.
 */

	static int 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

	};

	static Shortword window[DELAY + FRM_LEN] =
	{

		35, 315, 869, 1690, 2761, 4066, 5581, 7281, 9137,
		11117, 13187, 15312, 17455, 19580, 21650, 23630,
		25486, 27186, 28701, 30006, 31077, 31898, 32452,
		32732, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32767, 32767, 32767, 32767, 32767, 32767,
		32767, 32732, 32452, 31898, 31077, 30006, 28701,
		27186, 25486, 23630, 21650, 19580, 17455, 15312,
		13187, 11117, 9137, 7281, 5581, 4066, 2761, 1690,
		869, 315, 35

	};

	static Shortword first = TRUE;
	static Shortword pre_emp_mem;
	static Shortword de_emp_mem;
	static Shortword overlap[FFT_LEN - FRM_LEN];
	static Shortword ch_gain[FFT_LEN / 2];	/* scaled as 0,15 */
	static Shortword update_cnt;
	static Shortword window_overlap[DELAY];
	static Shortword hyster_cnt;
	static Shortword last_update_cnt;
	static Shortword ch_enrg_long_db[NUM_CHAN];		/* scaled as 10,5  */

	static Longword frame_cnt;
	static Longword ch_enrg[NUM_CHAN];	/* scaled as 23,8 */
	static Longword ch_noise[NUM_CHAN];		/* scaled as 15,16 (change to 23,8) */

	static Shortword last_normb_shift;		/* last block norm shift count */

	Longword enrg;				/* scaled as 30,1 */
	Longword tne;				/* scaled as 15,16 (change to 23,8) */
	Longword tce;				/* scaled as 23,8 */
	Longword gain;				/* scaled as 11,20 */

	Shortword data_buffer[FFT_LEN];
	Shortword ch_snr[NUM_CHAN];	/* scaled as 15,0 */
	Shortword ftmp2;			/* scaled as 0,15 */
	Shortword vm_sum;			/* scaled as 15,0 */
	Shortword ch_enrg_dev;		/* scaled as 10,5 */
	Shortword ch_enrg_db[NUM_CHAN];		/* scaled as 10,5 */
	Shortword alpha;			/* scaled as 0,15 */

	int i, j, j1, j2;
	int update_flag, modify_flag, index_cnt;

	Longword Ltmp, Ltmp1, Ltmp2, Ltmp3;
	Shortword tmp, tmp1, tmp2, norm_shift, norm_shift1;

	Shortword normb_shift;		/* block norm shift count */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -