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

📄 fec_code.c

📁 MELPe 1200 bps, fixed point
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ================================================================== */
/*                                                                    */ 
/*    Microsoft Speech coder     ANSI-C Source Code                   */
/*    SC1200 1200 bps speech coder                                    */
/*    Fixed Point Implementation      Version 7.0                     */
/*    Copyright (C) 2000, Microsoft Corp.                             */
/*    All rights reserved.                                            */
/*                                                                    */ 
/* ================================================================== */

/*

2.4 kbps MELP Proposed Federal Standard speech coder

Fixed-point C code, version 1.0

Copyright (c) 1998, Texas Instruments, Inc.

Texas Instruments has intellectual property rights on the MELP
algorithm.	The Texas Instruments contact for licensing issues for
commercial and non-government use is William Gordon, Director,
Government Contracts, Texas Instruments Incorporated, Semiconductor
Group (phone 972 480 7442).

The fixed-point version of the voice codec Mixed Excitation Linear
Prediction (MELP) is based on specifications on the C-language software
simulation contained in GSM 06.06 which is protected by copyright and
is the property of the European Telecommunications Standards Institute
(ETSI). This standard is available from the ETSI publication office
tel. +33 (0)4 92 94 42 58. ETSI has granted a license to United States
Department of Defense to use the C-language software simulation contained
in GSM 06.06 for the purposes of the development of a fixed-point
version of the voice codec Mixed Excitation Linear Prediction (MELP).
Requests for authorization to make other use of the GSM 06.06 or
otherwise distribute or modify them need to be addressed to the ETSI
Secretariat fax: +33 493 65 47 16.

*/

#include "sc1200.h"
#include "mathhalf.h"
#include "mat_lib.h"


/* Compiler constants */
#define UV_PIND			0                             /* Unvoiced pitch index */
#define INVAL_PIND		1                              /* Invalid pitch index */
#define BEP_CORR		-1                    /* "Correct" bit error position */
#define BEP_UNCORR		-2              /* "Uncorrectable" bit error position */

static Shortword	codewd74[7];
static Shortword	codewd84[8];
static Shortword	codewd_13x9[13];

/* (7,4) Hamming code tables.  Parity generator matrix. */
static const Shortword  pmat74[3][4] = {
	{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}
};

/* Syndrome table. */
static const Shortword	syntab74[8] = {BEP_CORR, 6, 5, 2, 4, 1, 0, 3};

/* (8,4) extended Hamming code tables.  Parity generator matrix. */
static const Shortword  pmat84[4][4] = {
	{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}, {1, 1, 1, 0}
};

/* Syndrome->error position lookup table. */
static const Shortword  syntab84[16] = {
	BEP_CORR,   7,          6,          BEP_UNCORR,
	5,          BEP_UNCORR, BEP_UNCORR, 2,
	4,          BEP_UNCORR, BEP_UNCORR, 1,
	BEP_UNCORR, 0,          3,          BEP_UNCORR
};

/* Pitch index encoding table.  Reserve Hamming weight 0,1 words for unvoiced */
/* pitch value.  Reserve Hamming weight 2 words for invalid (protect against  */
/* single bit voiced pitch errors.  Assign voiced pitch codes to values       */
/* having Hamming weight > 2.                                                 */

static const Shortword		pitch_enc[PIT_QLEV + 1] = {
	0x0,	/* UV_PIND */
	0x7,	/* 1 (first pitch QL - note offset) */
	0xB,	/* 2 */
	0xD,	/* 3 */
	0xE,	/* 4 */
	0xF,	/* 5 */
	0x13,	/* 6 */
	0x15,	/* 7 */
	0x16,	/* 8 */
	0x17,	/* 9 */
	0x19,	/* 10 */
	0x1A,	/* 11 */
	0x1B,	/* 12 */
	0x1C,	/* 13 */
	0x1D,	/* 14 */
	0x1E,	/* 15 */
	0x1F,	/* 16 */
	0x23,	/* 17 */
	0x25,	/* 18 */
	0x26,	/* 19 */
	0x27,	/* 20 */
	0x29,	/* 21 */
	0x2A,	/* 22 */
	0x2B,	/* 23 */
	0x2C,	/* 24 */
	0x2D,	/* 25 */
	0x2E,	/* 26 */
	0x2F,	/* 27 */
	0x31,	/* 28 */
	0x32,	/* 29 */
	0x33,	/* 30 */
	0x34,	/* 31 */
	0x35,	/* 32 */
	0x36,	/* 33 */
	0x37,	/* 34 */
	0x38,	/* 35 */
	0x39,	/* 36 */
	0x3A,	/* 37 */
	0x3B,	/* 38 */
	0x3C,	/* 39 */
	0x3D,	/* 40 */
	0x3E,	/* 41 */
	0x3F,	/* 42 */
	0x43,	/* 43 */
	0x45,	/* 44 */
	0x46,	/* 45 */
	0x47,	/* 46 */
	0x49,	/* 47 */
	0x4A,	/* 48 */
	0x4B,	/* 49 */
	0x4C,	/* 50 */
	0x4D,	/* 51 */
	0x4E,	/* 52 */
	0x4F,	/* 53 */
	0x51,	/* 54 */
	0x52,	/* 55 */
	0x53,	/* 56 */
	0x54,	/* 57 */
	0x55,	/* 58 */
	0x56,	/* 59 */
	0x57,	/* 60 */
	0x58,	/* 61 */
	0x59,	/* 62 */
	0x5A,	/* 63 */
	0x5B,	/* 64 */
	0x5C,	/* 65 */
	0x5D,	/* 66 */
	0x5E,	/* 67 */
	0x5F,	/* 68 */
	0x61,	/* 69 */
	0x62,	/* 70 */
	0x63,	/* 71 */
	0x64,	/* 72 */
	0x65,	/* 73 */
	0x66,	/* 74 */
	0x67,	/* 75 */
	0x68,	/* 76 */
	0x69,	/* 77 */
	0x6A,	/* 78 */
	0x6B,	/* 79 */
	0x6C,	/* 80 */
	0x6D,	/* 81 */
	0x6E,	/* 82 */
	0x6F,	/* 83 */
	0x70,	/* 84 */
	0x71,	/* 85 */
	0x72,	/* 86 */
	0x73,	/* 87 */
	0x74,	/* 88 */
	0x75,	/* 89 */
	0x76,	/* 90 */
	0x77,	/* 91 */
	0x78,	/* 92 */
	0x79,	/* 93 */
	0x7A,	/* 94 */
	0x7B,	/* 95 */
	0x7C,	/* 96 */
	0x7D,	/* 97 */
	0x7E,	/* 98 */
	0x7F	/* 99 */
};

const Shortword		low_rate_pitch_enc[4][PIT_QLEV] = {
{0},                                                             /* All zeros */
{                                                             /* for UUV (6,7)*/
	 63,  95, 111, 119, 123, 125, 126, 159, 175, 183,
	187, 189, 190, 207, 215, 219, 221, 222, 231, 235,
	237, 238, 243, 245, 246, 249, 250, 252, 287, 303,
	311, 315, 317, 318, 335, 343, 347, 349, 350, 359,
	363, 365, 366, 371, 373, 374, 377, 378, 380, 399,
	407, 411, 413, 414, 423, 427, 429, 430, 435, 437,
	438, 441, 442, 444, 455, 459, 461, 462, 467, 469,
	470, 473, 474, 476, 483, 485, 486, 489, 490, 492,
	497, 498, 500, 504, 127, 191, 223, 239, 247, 251,
	253, 254, 319, 351, 367, 375, 379, 381, 382
},
{                                                              /* for UVU (4) */
	 15,  23,  27,  29,  30,  39,  43,  45,  46,  51,
	 53,  54,  57,  58,  60,  71,  75,  77,  78,  83,
	 85,  86,  89,  90,  92,  99, 101, 102, 105, 106,
	108, 113, 114, 116, 120, 135, 139, 141, 142, 147,
	149, 150, 153, 154, 156, 163, 165, 166, 169, 170,
	172, 177, 178, 180, 184, 195, 197, 198, 201, 202,
	204, 209, 210, 212, 216, 225, 226, 228, 232, 240,
	263, 267, 269, 270, 275, 277, 278, 281, 282, 284,
	291, 293, 294, 297, 298, 300, 305, 306, 308, 312,
	323, 325, 326, 329, 330, 332, 337, 338, 340
},
{                                                              /* for VUU (5) */
	 31,  47,  55,  59,  61,  62,  79,  87,  91,  93,
	 94, 103, 107, 109, 110, 115, 117, 118, 121, 122,
	124, 143, 151, 155, 157, 158, 167, 171, 173, 174,
	179, 181, 182, 185, 186, 188, 199, 203, 205, 206,
	211, 213, 214, 217, 218, 220, 227, 229, 230, 233,
	234, 236, 241, 242, 244, 248, 271, 279, 283, 285,
	286, 295, 299, 301, 302, 307, 309, 310, 313, 314,
	316, 327, 331, 333, 334, 339, 341, 342, 345, 346,
	348, 355, 357, 358, 361, 362, 364, 369, 370, 372,
	376, 391, 395, 397, 398, 403, 405, 406, 409
}
};

/* Pitch index decoding table.  Hamming weight 1 codes map to UV_PIND,        */
/* allowing for 1-bit error correction of unvoiced marker.	Hamming weight 2  */
/* codes map to INVAL_PIND, protecting against 1-bit errors in voiced pitches */
/* creating false unvoiced condition.                                         */

static const Shortword		pitch_dec[1 << PIT_BITS] = {
                                                /* pitch index decoding table */
	UV_PIND,	/* 0x0 */
	UV_PIND,	/* 0x1 */
	UV_PIND,	/* 0x2 */
	INVAL_PIND,	/* 0x3 */
	UV_PIND,	/* 0x4 */
	INVAL_PIND,	/* 0x5 */
	INVAL_PIND,	/* 0x6 */
	2,			/* 0x7 */
	UV_PIND,	/* 0x8 */
	INVAL_PIND,	/* 0x9 */
	INVAL_PIND,	/* 0xA */
	3,			/* 0xB */
	INVAL_PIND,	/* 0xC */
	4,			/* 0xD */
	5,			/* 0xE */
	6,			/* 0xF */
	UV_PIND,	/* 0x10 */
	INVAL_PIND,	/* 0x11 */
	INVAL_PIND,	/* 0x12 */
	7,			/* 0x13 */
	INVAL_PIND,	/* 0x14 */
	8,			/* 0x15 */
	9,			/* 0x16 */
	10,			/* 0x17 */
	INVAL_PIND,	/* 0x18 */
	11,			/* 0x19 */
	12,			/* 0x1A */
	13,			/* 0x1B */
	14,			/* 0x1C */
	15,			/* 0x1D */
	16,			/* 0x1E */
	17,			/* 0x1F */
	UV_PIND,	/* 0x20 */
	INVAL_PIND,	/* 0x21 */
	INVAL_PIND,	/* 0x22 */
	18,			/* 0x23 */
	INVAL_PIND,	/* 0x24 */
	19,			/* 0x25 */
	20,			/* 0x26 */
	21,			/* 0x27 */
	INVAL_PIND,	/* 0x28 */
	22,			/* 0x29 */
	23,			/* 0x2A */
	24,			/* 0x2B */
	25,			/* 0x2C */
	26,			/* 0x2D */
	27,			/* 0x2E */
	28,			/* 0x2F */
	INVAL_PIND,	/* 0x30 */
	29,			/* 0x31 */
	30,			/* 0x32 */
	31,			/* 0x33 */
	32,			/* 0x34 */
	33,			/* 0x35 */
	34,			/* 0x36 */
	35,			/* 0x37 */
	36,			/* 0x38 */
	37,			/* 0x39 */
	38,			/* 0x3A */
	39,			/* 0x3B */
	40,			/* 0x3C */
	41,			/* 0x3D */
	42,			/* 0x3E */
	43,			/* 0x3F */
	UV_PIND,	/* 0x40 */
	INVAL_PIND,	/* 0x41 */
	INVAL_PIND,	/* 0x42 */
	44,			/* 0x43 */
	INVAL_PIND,	/* 0x44 */
	45,			/* 0x45 */
	46,			/* 0x46 */
	47,			/* 0x47 */
	INVAL_PIND,	/* 0x48 */
	48,			/* 0x49 */
	49,			/* 0x4A */
	50,			/* 0x4B */
	51,			/* 0x4C */
	52,			/* 0x4D */
	53,			/* 0x4E */
	54,			/* 0x4F */
	INVAL_PIND,	/* 0x50 */
	55,			/* 0x51 */
	56,			/* 0x52 */
	57,			/* 0x53 */
	58,			/* 0x54 */
	59,			/* 0x55 */
	60,			/* 0x56 */
	61,			/* 0x57 */
	62,			/* 0x58 */
	63,			/* 0x59 */
	64,			/* 0x5A */
	65,			/* 0x5B */
	66,			/* 0x5C */
	67,			/* 0x5D */
	68,			/* 0x5E */
	69,			/* 0x5F */
	INVAL_PIND,	/* 0x60 */
	70,			/* 0x61 */
	71,			/* 0x62 */
	72,			/* 0x63 */
	73,			/* 0x64 */
	74,			/* 0x65 */
	75,			/* 0x66 */
	76,			/* 0x67 */
	77,			/* 0x68 */
	78,			/* 0x69 */
	79,			/* 0x6A */
	80,			/* 0x6B */
	81,			/* 0x6C */
	82,			/* 0x6D */
	83,			/* 0x6E */
	84,			/* 0x6F */
	85,			/* 0x70 */
	86,			/* 0x71 */
	87,			/* 0x72 */
	88,			/* 0x73 */
	89,			/* 0x74 */
	90,			/* 0x75 */
	91,			/* 0x76 */
	92,			/* 0x77 */
	93,			/* 0x78 */
	94,			/* 0x79 */
	95,			/* 0x7A */
	96,			/* 0x7B */
	97,			/* 0x7C */
	98,			/* 0x7D */
	99,			/* 0x7E */
	100 		/* 0x7F */
};

const Shortword		low_rate_pitch_dec[PITCH_VQ_SIZE] = {
	UV_PIND,	/*   0 */
	UV_PIND,	/*   1 */
	UV_PIND,	/*   2 */
	INVAL_PIND,	/*   3 */
	UV_PIND,	/*   4 */
	INVAL_PIND,	/*   5 */
	INVAL_PIND,	/*   6 */
	INVAL_PIND,	/*   7 */
	UV_PIND,	/*   8 */
	INVAL_PIND,	/*   9 */
	INVAL_PIND,	/*  10 */
	INVAL_PIND,	/*  11 */
	INVAL_PIND,	/*  12 */
	INVAL_PIND,	/*  13 */
	INVAL_PIND,	/*  14 */
	2,			/*  15 */ /* UVU */
	UV_PIND,	/*  16 */
	INVAL_PIND,	/*  17 */
	INVAL_PIND,	/*  18 */
	INVAL_PIND,	/*  19 */
	INVAL_PIND,	/*  20 */
	INVAL_PIND,	/*  21 */
	INVAL_PIND,	/*  22 */
	3,			/*  23 */ /* UVU */
	INVAL_PIND,	/*  24 */
	INVAL_PIND,	/*  25 */
	INVAL_PIND,	/*  26 */
	4,			/*  27 */ /* UVU */
	INVAL_PIND,	/*  28 */
	5,			/*  29 */ /* UVU */
	6,			/*  30 */ /* UVU */
	2,			/*  31 */ /* VUU */
	UV_PIND,	/*  32 */
	INVAL_PIND,	/*  33 */
	INVAL_PIND,	/*  34 */
	INVAL_PIND,	/*  35 */
	INVAL_PIND,	/*  36 */
	INVAL_PIND,	/*  37 */
	INVAL_PIND,	/*  38 */
	7,			/*  39 */ /* UVU */
	INVAL_PIND,	/*  40 */
	INVAL_PIND,	/*  41 */
	INVAL_PIND,	/*  42 */
	8,			/*  43 */ /* UVU */
	INVAL_PIND,	/*  44 */
	9,			/*  45 */ /* UVU */
	10,			/*  46 */ /* UVU */
	3,			/*  47 */ /* VUU */
	INVAL_PIND,	/*  48 */
	INVAL_PIND,	/*  49 */
	INVAL_PIND,	/*  50 */
	11,			/*  51 */ /* UVU */
	INVAL_PIND,	/*  52 */
	12,			/*  53 */ /* UVU */
	13,			/*  54 */ /* UVU */
	4,			/*  55 */ /* VUU */
	INVAL_PIND,	/*  56 */
	14,			/*  57 */ /* UVU */
	15,			/*  58 */ /* UVU */
	5,			/*  59 */ /* VUU */
	16,			/*  60 */ /* UVU */
	6,			/*  61 */ /* VUU */
	7,			/*  62 */ /* VUU */
	2,			/*  63 */ /* UUV */
	UV_PIND,	/*  64 */
	INVAL_PIND,	/*  65 */

⌨️ 快捷键说明

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