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

📄 rom_enc.h

📁 实现了录音,放音功能!在evc4.0下编译功过,wince5.0下能正常录音,放音,暂停录放音!
💻 H
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************/
/*                                                                       */
/* Copyright (c) 2000-2004 Linuos Design                                 */
/*                                     领驰设计中心  版权所有 2000-2004  */
/*                                                                       */
/* PROPRIETARY RIGHTS of Linuos Design  are involved in the subject      */
/* matter of this material.  All manufacturing, reproduction, use, and   */
/* sales rights pertaining to this subject matter are governed by the    */
/* license agreement.  The recipient of this software implicitly accepts */ 
/* the terms of the license.                                             */
/* 本软件文档资料是领驰设计中心的资产,任何人士阅读和使用本资料必须获得   */
/* 相应的书面授权,承担保密责任和接受相应的法律约束.                      */
/*                                                                       */
/*************************************************************************/

/*
* ===================================================================
*  TS 26.104
*  REL-5 V5.4.0 2004-03
*  REL-6 V6.1.0 2004-03
*  3GPP AMR Floating-point Speech Codec
* ===================================================================
*
*/

/*
* rom_enc.h
*
*
* Project:
*    AMR Floating-Point Codec
*
* Contains:
*    This file contains all the tables needed by AMR encoder functions.
*
*/
#ifndef _ROM_ENC_H_
#define _ROM_ENC_H_


//#include "typedef.h"
//#include "sp_enc.h"
#include <windows.h>
#include <stdlib.h>

#define LP_ORDER                  10              /* Order of LP filter */
#define LP_ORDER_PLUS             (LP_ORDER+1)    /* Order of LP filter + 1 */
#define LP_WINDOW                 240             /* Window size in LP analysis */
#define LP_ANAY_SIZE              40              /* Overhead in LP analysis */
#define LTPG_MEM_SIZE             5               /* number of stored past LTP coding gains + 1 */
#define AVG_PITGAN                7               /* old pitch gains in average calculation */
#define DTX_HIST_SIZE             8               /* DTX history size */
#define AMR_FRAME_MAX             32
#define SPCH_BUF_SIZE             320             /* Total size of speech buffer. */
#define FRAME_SIZE                160             /* Frame size */
#define FRAME_SIZE_BY2            80              /* Frame size divided by 2 */
#define SUBFRM_SIZE               40              /* Subframe size */
#define CODEVEC_LEN               40              /* codevector length */
#define PIT_MAX                   143             /* Maximum pitch lag */
#define PIT_MIN                   20              /* Minimum pitch lag */
#define PIT_MIN_MR122             18              /* Minimum pitch lag (MR122 mode) */
#define INTERPOL_LEN              (10+1)          /* Length of filter for interpolation */
#define NB_PREDTAPS               4               /* number of prediction taps */
#define PIT_SHARP_MIN             0               /* Minimum value of pitch sharpening */
#define MAX_PRM_SIZE              57              /* max. num. of params */
#define INTER_SRCH_LEN            4               /* Length of filter for CL LTP search interpolation */
#define CLIP_PITGAN               0.95F           /* Pitch gain clipping */
#define UP_SAMP_MAX               6
#define NB_TRACK                  5               /* number of tracks */
#define NB_TRACK_MR102            4               /* number of tracks mode mr102 */
#define STEP                      5               /* codebook step size */
#define STEP_MR102                4               /* codebook step size mode mr102 */
#define LP_ORDER_BY2              LP_ORDER/2      /* Order of LP filter divided by 2 */

#define SCALE_LSP_FREQ            (float)(4000.0/3.141592654)
#define SCALE_FREQ_LSP            (float)(3.141592654/4000.0)
#define SLOPE1_WGHT_LSF           (float)((3.347-1.8)/(450.0-0.0))
#define SLOPE2_WGHT_LSF           (float)((1.8-1.0)/(1500.0-450.0))

#define FRAME_LEN                 160              /* Length (samples) of the input frame          */
#define NB_SUBBDS_VAD             9                /* Number of sub-bands used by VAD              */
#define INV_COMPLEN               3641             /* 1.0/NB_SUBBDS_VAD*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                  0.65F            /* Threshold for tone detection   */

/* Constants for background spectrum update */
#define ALPHA_UP1                 (float)(1.0 - 0.95)  /* Normal update, upwards:   */
#define ALPHA_DOWN1               (float)(1.0 - 0.936) /* Normal update, downwards  */
#define ALPHA_UP2                 (float)(1.0 - 0.985) /* Forced update, upwards    */
#define ALPHA_DOWN2               (float)(1.0 - 0.943) /* Forced update, downwards  */
#define ALPHA3                    (float)(1.0 - 0.95)  /* Update downwards          */
#define ALPHA4                    (float)(1.0 - 0.9)   /* For stationary estimation */
#define ALPHA5                    (float)(1.0 - 0.5)   /* 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                 (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               (INT32)15000/2    /* If input power is lower,                    */
/*     VAD is set to 0                         */
#define POW_PITCH_THR             (INT32)343040/2   /* If input power is lower, pitch              */
/*     detection is ignored                    */

#define POW_COMPLEX_THR           (INT32)15000/2    /* If input power is lower, complex            */
/* flags  value for previous frame  is un-set  */
/*
* VAD Constants
*/

/* Constants for the filter bank */
#define LEVEL_SHIFT               0                        /* scaling                                  */
#define COEFF3                    (float)13363/32768     /* coefficient for the 3rd order filter     */
#define COEFF5_1                  (float)21955/32768     /* 1st coefficient the for 5th order filter */
#define COEFF5_2                  (float)6390/32768      /* 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    0.6F              /* threshold for adapt stopping high */
#define CVAD_THRESH_ADAPT_LOW     0.5F              /* threshold for adapt stopping low */
#define CVAD_THRESH_IN_NOISE      0.65F * 32768.0F  /* threshold going into speech on
a INT16 term basis */
#define CVAD_THRESH_HANG          0.70F             /* threshold */
#define CVAD_HANG_LIMIT           (INT16)(100)      /* 2 second estimation time */
#define CVAD_HANG_LENGTH          (INT16)(250)      /* 5 second hangover */

#define CVAD_LOWPOW_RESET         0.40F             /* init in low power segment */
#define CVAD_MIN_CORR             0.40F             /* lowest adaptation value */

#define CVAD_BURST                20                /* speech burst length for speech reset */
#define CVAD_ADAPT_SLOW           1.0F - 0.98F      /* threshold for slow adaption */
#define CVAD_ADAPT_FAST           1.0F - 0.92F      /* threshold for fast adaption */
#define CVAD_ADAPT_REALLY_FAST    1.0F - 0.80F      /* threshold for really fast adaption */

static const float gamma1[LP_ORDER] =
{
	0.9400024414063F,
		0.8836059570313F,
		0.8305969238281F,
		0.78076171875F,
		0.7339172363281F,
		0.6898803710938F,
		0.6484985351563F,
		0.6095886230469F,
		0.5730285644531F,
		0.5386352539063F
};

/*
*  gamma1 for the 12k2 coder
*/
static const float gamma1_12k2[LP_ORDER] =
{
	0.8999938964844F,
		0.8099975585938F,
		0.72900390625F,
		0.6560974121094F,
		0.5904846191406F,
		0.5314331054688F,
		0.478271484375F,
		0.4304504394531F,
		0.3873901367188F,
		0.3486633300781F
};
static const float gamma2[LP_ORDER] =
{
	0.6000061035156F,
		0.3600158691406F,
		0.2160034179688F,
		0.1296081542969F,
		0.0777587890625F,
		0.04666137695313F,
		0.02798461914063F,
		0.01678466796875F,
		0.01007080078125F,
		0.00604248046875F
};

/* same in fixed-point */
static const INT32 inter6[61] =
{
	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
};

static const INT16 startPos1[2] =
{
	1,
		3
};

static const INT16 startPos2[4] =
{
	0,
		1,
		2,
		4
};

static const INT16 startPos[2 * 4 * 2] =
{
	0,
		2,
		0,
		3,
		0,
		2,
		0,
		3,
		1,
		3,
		2,
		4,
		1,
		4,
		1,
		4
};

/* Scalar quantization tables of the pitch gain and the codebook gain. */
#define NB_QUA_PITCH 16

static const float qua_gain_pitch[NB_QUA_PITCH] =
{
	0.0F,
		0.20001220703125F,
		0.400146484375F,
		0.5F,
		0.5999755859375F,
		0.70001220703125F,
		0.75F,
		0.79998779296875F,
		0.8499755859375F,
		0.9000244140625F,
		0.95001220703125F,
		1.0F,
		1.04998779296875F,
		1.0999755859375F,
		1.1500244140625F,
		1.20001220703125F
};

static const float qua_gain_pitch_MR122[NB_QUA_PITCH] =
{
	0.0F,
		0.199951171875F,
		0.400146484375F,
		0.5F,
		0.599853515625F,
		0.699951171875F,
		0.75F,
		0.7998046875F,
		0.849853515625F,
		0.89990234375F,
		0.949951171875F,
		1.0F,
		1.0498046875F,
		1.099853515625F,
		1.14990234375F,
		1.199951171875F
};

#define NB_QUA_CODE 32
static const float gain_factor[NB_QUA_CODE] =
{
	/* gain factor (g_fac) */
	0.0776367F,
		0.100586F,
		0.130859F,
		0.170410F,
		0.204590F,
		0.235352F,
		0.270508F,
		0.311035F,
		0.357910F,
		0.411133F,
		0.473145F,
		0.543945F,
		0.625488F,
		0.719238F,
		0.827148F,
		0.951172F,
		1.09424F,
		1.25830F,
		1.44678F,
		1.66406F,
		1.91357F,
		2.20068F,
		2.53076F,
		2.91016F,
		3.34717F,
		3.84912F,
		4.42627F,
		5.09033F,
		6.10840F,
		7.94092F,
		10.3232F,
		13.4204F
};






static const INT8 gray[8] =
{
	0,
		1,
		3,
		2,
		6,
		4,
		5,
		7
};

/*
* grid[0] = 1.0;
* grid[61] = -1.0;
* for (i = 1; i < 61; i++)
*    grid[i] = (float)cos((6.283185307*i)/(2.0*60));
*/
static const float grid[61] =
{
	1.00000F,
		0.998630F,
		0.994522F,
		0.987688F,
		0.978148F,
		0.965926F,
		0.951057F,
		0.933580F,
		0.913545F,
		0.891007F,
		0.866025F,
		0.838671F,
		0.809017F,
		0.777146F,
		0.743145F,
		0.707107F,
		0.669131F,
		0.629320F,
		0.587785F,
		0.544639F,
		0.500000F,
		0.453990F,
		0.406737F,
		0.358368F,
		0.309017F,
		0.258819F,
		0.207912F,
		0.156434F,
		0.104528F,
		0.0523360F,
		4.48966e-011F,
		- 0.0523360F,
		- 0.104528F,
		- 0.156434F,
		- 0.207912F,
		- 0.258819F,
		- 0.309017F,
		- 0.358368F,
		- 0.406737F,
		- 0.453990F,
		- 0.500000F,
		- 0.544639F,
		- 0.587785F,
		- 0.629320F,
		- 0.669131F,
		- 0.707107F,
		- 0.743145F,
		- 0.777146F,
		- 0.809017F,
		- 0.838671F,
		- 0.866025F,
		- 0.891007F,
		- 0.913545F,
		- 0.933580F,
		- 0.951057F,
		- 0.965926F,
		- 0.978148F,
		- 0.987688F,
		- 0.994522F,
		- 0.998630F,
		- 1.00000F
};

/*
* 1/6 resolution interpolation filter  (-3 dB at 3600 Hz)
* Note: The IS641 (7.4) 1/3 resolution filter is simply a subsampled
*       version of the 1/6 resolution filter, i.e. it uses
*       every second coefficient:
*
*       b24[k](1/3) = b24[2*k](1/6), 0 <= k <= 3*INTER_SRCH_LEN
*/
static const float b24[UP_SAMP_MAX*INTER_SRCH_LEN+1] =
{
	0.900848F,
		0.864136F,
		0.760071F,
		0.605408F,
		0.424072F,
		0.242462F,
		0.0840759F,
		- 0.0343933F,
		- 0.105560F,
		- 0.131348F,
		- 0.121124F,
		- 0.0884705F,
		- 0.0476379F,
		- 0.0102539F,
		0.0162964F,
		0.0296021F,
		0.0312195F,
		0.0251160F,
		0.0157471F,
		0.00671387F,
		0.000000F,
		- 0.00399780F,
		- 0.00592041F,
		- 0.00656128F,
		0.000000F
};

/* initialization table for lsp history in DTX */
static const float lsp_init_data[LP_ORDER] =
{
	0.9595F,
		0.8413F,
		0.6549F,
		0.4154F,
		0.1423F,
		- 0.1423F,
		- 0.4154F,
		- 0.6549F,
		- 0.8413F,
		- 0.9595F
};

#define PAST_RQ_INIT_SIZE 8

/* initalization table for MA predictor in dtx mode */
static const float past_rq_init[80] =
{
	-62.9883F, -77.6367F, -107.178F, -154.785F, -160.156F, -188.721F, -173.584F, -122.559F,
		-65.4297F, -47.1191F, -0.488281F, 30.5176F, 29.7852F, -9.52148F, -2.19727F, 25.6348F,
		31.4941F, 69.0918F, 90.8203F, 140.381F, -67.627F, -79.1016F, -48.0957F, -118.896F,
		-108.643F, -88.3789F, -71.2891F, -6.5918F, 43.2129F, 132.568F, 83.4961F, 126.221F,
		125.977F, 31.7383F, 6.5918F, -25.3906F, -29.2969F, -34.1797F, -18.0664F, -13.6719F,
		-137.695F, -230.225F, -371.094F, -235.596F, -198.73F, -128.418F, -78.6133F, -0.488281F,
		38.8184F, 160.4F, -76.1719F, -69.3359F, -94.2383F, -145.752F, -120.361F, -128.418F,
		-102.051F, -55.9082F, 25.6348F, 109.619F, -135.986F, -212.402F, -262.451F, -224.365F,
		-231.934F, -183.594F, -173.096F, -77.1484F, 15.1367F, 118.652F, -76.6602F, -46.6309F,
		-49.5605F, -80.5664F, -39.0625F, -25.1465F, -12.4512F, 31.9824F, 82.5195F, 125.732F
};

/* LSF means ->normalize frequency domain */

static const float mean_lsf_3[10] =
{
	377.441F,
		554.688F,
		922.363F,
		1339.84F,
		1702.15F,
		2046.39F,
		2452.88F,
		2741.46F,
		3116.70F,
		3348.14F,
};

static const float mean_lsf_5[10] =
{
	337.891F,
		507.080F,
		834.961F,
		1247.07F,
		1646.00F,
		1982.91F,
		2407.96F,
		2708.01F,
		3104.00F,
		3344.97F,
};

/* LSF prediction factors (not in MR122) */
static const float pred_fac[10] =
{
	0.291626F,
		0.328644F,
		0.383636F,
		0.405640F,
		0.438873F,
		0.355560F,
		0.323120F,
		0.298065F,
		0.262238F,
		0.197876F
};

/* codebooks from IS641 */
#define DICO1_SIZE_3  256
#define DICO2_SIZE_3  512
#define DICO3_SIZE_3  512
static const float dico1_lsf_3[] =
{
   	1.46484F,
		20.0195F,
		-31.9824F,
		37.5977F,
		-13.6719F,
		-179.443F,
		44.6777F,
		-15.8691F,
		-64.6973F,
		2.19727F,
		-51.2695F,
		-88.1348F,
		27.5879F,
		175.293F,
		443.604F,
		246.582F,
		296.387F,
		384.033F,
		209.229F,
		325.439F,
		555.664F,
		201.904F,
		382.813F,
		471.924F,
		175.049F,
		485.596F,
		538.574F,
		204.590F,
		286.133F,
		445.068F,
		176.025F,
		244.141F,
		525.879F,
		69.8242F,
		116.211F,
		368.408F,
		-60.3027F,
		-129.639F,
		56.1523F,
		35.8887F,
		-20.0195F,
		138.916F,
		6.34766F,
		-43.2129F,
		-230.469F,
		-6.59180F,
		-66.6504F,
		168.945F,
		-40.0391F,
		-64.4531F,
		-44.6777F,
		54.6875F,
		192.871F,
		253.662F,
		219.482F,
		230.957F,
		146.729F,
		118.408F,
		188.232F,
		280.762F,
		127.930F,
		165.283F,
		220.459F,
		-34.1797F,
		91.5527F,
		189.941F,
		100.098F,
		165.039F,
		104.736F,
		73.4863F,
		129.395F,
		246.338F,
		175.537F,
		157.715F,
		9.27734F,
		55.1758F,
		89.5996F,
		9.76563F,
		35.4004F,
		-10.9863F,
		-123.291F,
		70.8008F,
		29.5410F,
		-29.5410F,
		73.7305F,
		31.0059F,
		40.5273F,
		-30.2734F,
		-93.5059F,
		-233.398F,
		-87.4023F,
		-111.084F,
		-238.525F,
		174.561F,
		214.355F,
		218.262F,
		238.770F,
		225.342F,
		51.5137F,
		116.455F,
		66.4063F,
		15.6250F,
		45.8984F,
		-19.0430F,
		4.15039F,
		-34.9121F,
		-15.8691F,
		9.27734F,
		156.982F,
		143.066F,
		151.611F,
		-32.7148F,
		-104.004F,
		-158.936F,
		84.7168F,
		133.057F,
		688.477F,
		290.039F,
		665.527F,
		596.191F,
		34.6680F,
		-19.5313F,
		423.584F,
		69.0918F,
		31.7383F,
		112.549F,
		-63.9648F,
		-97.4121F,
		-279.541F,
		-100.342F,
		37.8418F,
		104.980F,
		80.3223F,
		91.5527F,
		190.186F,
		12.9395F,
		-55.1758F,
		-33.9355F,
		-31.4941F,
		-57.6172F,
		410.645F,
		69.5801F,
		181.641F,
		323.975F,
		180.176F,
		170.166F,
		406.250F,
		76.1719F,
		99.8535F,
		64.9414F,
		79.3457F,
		175.781F,
		32.9590F,
		0.244141F,
		53.9551F,
		110.596F,
		1.95313F,
		49.5605F,
		35.4004F,
		72.9980F,
		156.250F,
		185.547F,
		7.08008F,
		114.258F,
		155.762F,
		25.1465F,
		104.736F,
		92.5293F,
		102.539F,
		232.910F,
		227.539F,
		323.730F,
		295.410F,
		307.129F,
		171.875F,
		247.070F,
		281.250F,
		-40.5273F,
		-108.398F,
		-64.9414F,
		-77.1484F,
		-31.7383F,
		-91.7969F,
		46.6309F,
		281.006F,
		464.844F,
		-58.5938F,
		-132.568F,
		-307.617F,
		-27.3438F,
		65.4297F,
		294.678F,
		17.0898F,
		259.277F,
		386.475F,
		67.8711F,
		332.031F,
		384.277F,
		-62.9883F,
		-66.4063F,
		-187.500F,
		4.63867F,
		137.451F,
		546.875F,
		-0.732422F,
		-64.6973F,
		32.9590F,
		-72.0215F,
		-144.287F,
		-94.7266F,
		34.1797F,
		86.4258F,
		-50.2930F,
		-63.4766F,
		-123.047F,
		-194.092F,
		-105.713F,
		-175.293F,
		-322.021F,
		26.6113F,
		80.8105F,
		234.863F,
		-104.736F,
		-21.2402F,
		159.180F,
		-72.2656F,
		104.004F,
		248.779F,
		-58.3496F,
		189.209F,
		207.764F,
		119.385F,
		325.684F,
		261.963F,
		-81.5430F,
		-81.0547F,
		6.10352F,
		132.568F,
		294.434F,
		441.162F,
		79.5898F,
		14.8926F,
		177.490F,
		141.113F,
		207.275F,
		343.018F,
		-50.7813F,
		-67.6270F,
		80.3223F,
		-37.1094F,
		15.6250F,
		163.330F,
		-105.957F,
		-165.527F,

⌨️ 快捷键说明

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