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

📄 encoder.java

📁 java处理声音文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					  | ((xmc[6] & 0x7) << 2)					  | ((xmc[7] >> 1) & 0x3));		frame[index++]  = (byte) (((xmc[7] & 0x1) << 7)		/* 11 */					  | ((xmc[8] & 0x7) << 4)					  | ((xmc[9] & 0x7) << 1)					  | ((xmc[10] >> 2) & 0x1));		frame[index++]  = (byte) ((((xmc[10] & 0x3) << 6)	/* 12 */					   | ((xmc[11] & 0x7) << 3)					   | (xmc[12] & 0x7)));		frame[index++]  = (byte) (((Nc[1] & 0x7F) << 1)		/* 13 */					  | ((bc[1] >> 1) & 0x1));		frame[index++]  = (byte) (((bc[1] & 0x1) << 7)		/* 14 */					  | ((Mc[1] & 0x3) << 5)					  | ((xmaxc[1] >> 1) & 0x1F));		frame[index++]  = (byte) (((xmaxc[1] & 0x1) << 7)	/* 15 */					  | ((xmc[13] & 0x7) << 4)					  | ((xmc[14] & 0x7) << 1)					  | ((xmc[15] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[15] & 0x3) << 6)					  | ((xmc[16] & 0x7) << 3)					  | (xmc[17] & 0x7));		frame[index++]  = (byte) (((xmc[18] & 0x7) << 5)					  | ((xmc[19] & 0x7) << 2)					  | ((xmc[20] >> 1) & 0x3));		frame[index++]  = (byte) (((xmc[20] & 0x1) << 7)					  | ((xmc[21] & 0x7) << 4)					  | ((xmc[22] & 0x7) << 1)					  | ((xmc[23] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[23] & 0x3) << 6)					  | ((xmc[24] & 0x7) << 3)					  | (xmc[25] & 0x7));		frame[index++]  = (byte) (((Nc[2] & 0x7F) << 1)		/* 20 */					  | ((bc[2] >> 1) & 0x1));		frame[index++]  = (byte) (((bc[2] & 0x1) << 7)					  | ((Mc[2] & 0x3) << 5)					  | ((xmaxc[2] >> 1) & 0x1F));		frame[index++]  = (byte) (((xmaxc[2] & 0x1) << 7)					  | ((xmc[26] & 0x7) << 4)					  | ((xmc[27] & 0x7) << 1)					  | ((xmc[28] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[28] & 0x3) << 6)					  | ((xmc[29] & 0x7) << 3)					  | (xmc[30] & 0x7));		frame[index++]  = (byte) (((xmc[31] & 0x7) << 5)					  | ((xmc[32] & 0x7) << 2)					  | ((xmc[33] >> 1) & 0x3));		frame[index++]  = (byte) (((xmc[33] & 0x1) << 7)					  | ((xmc[34] & 0x7) << 4)					  | ((xmc[35] & 0x7) << 1)					  | ((xmc[36] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[36] & 0x3) << 6)					  | ((xmc[37] & 0x7) << 3)					  | (xmc[38] & 0x7));		frame[index++]  = (byte) (((Nc[3] & 0x7F) << 1)					  | ((bc[3] >> 1) & 0x1));		frame[index++]  = (byte) (((bc[3] & 0x1) << 7)					  | ((Mc[3] & 0x3) << 5)					  | ((xmaxc[3] >> 1) & 0x1F));		frame[index++]  = (byte) (((xmaxc[3] & 0x1) << 7)					  | ((xmc[39] & 0x7) << 4)					  | ((xmc[40] & 0x7) << 1)					  | ((xmc[41] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[41] & 0x3) << 6)	/* 30 */					  | ((xmc[42] & 0x7) << 3)					  | (xmc[43] & 0x7));		frame[index++]  = (byte) (((xmc[44] & 0x7) << 5)	/* 31 */					  | ((xmc[45] & 0x7) << 2)					  | ((xmc[46] >> 1) & 0x3));		frame[index++]  = (byte) (((xmc[46] & 0x1) << 7)	/* 32 */					  | ((xmc[47] & 0x7) << 4)					  | ((xmc[48] & 0x7) << 1)					  | ((xmc[49] >> 2) & 0x1));		frame[index++]  = (byte) (((xmc[49] & 0x3) << 6)	/* 33 */					  | ((xmc[50] & 0x7) << 3)					  | (xmc[51] & 0x7)); 	}	private void Gsm_Coder_java()	{		int     xmc_point = 0;		int	Nc_bc_index = 0;		int	xmaxc_Mc_index = 0;		int	dp_dpp_point_dp0 = 120;		short[] ep = new short[40];		short[] e  = new short[50];		short[] so = new short[160];		Gsm_Preprocess(so);		lpc_Obj.Gsm_LPC_Analysis(so, LARc);		sh_term_Obj.Gsm_Short_Term_Analysis_Filter(g_s, LARc, so);		short[] dp  = g_s.getDp0();		short[] dpp = dp;		for( int k = 0; k <= 3; k++, xmc_point += 13 )		{			lg_term_Obj.Gsm_Long_Term_Predictor(				so,      /* d    [0..39] IN    */				k*40,	 /* so   entry point   */				e,       /* e+5  [0..39] OUT   */				dp,      /* Referance to Gsm_State dp0 */				dpp,     /* Referance to Gsm_State dp0 */				dp_dpp_point_dp0, /* Where to start the dp0 ref */				Nc,      /* [0..3] coded LTP gain   	 OUT */				bc,      /* [0..3] RPE grid selection    OUT */				Nc_bc_index++ /* The current referance point for Nc & bc */				);			rpe_Obj.Gsm_RPE_Encoding 				(e,      /* e + 5 ][0..39][ IN/OUT */				 xmaxc,  /* [0..3] Coded maximum amplitude  OUT     */				 Mc,     /* [0..3] coded LTP gain           OUT     */				 xmaxc_Mc_index++, /* The current referance point   */				 xmc,    /* [13*4] normalized RPE samples   OUT     */				 xmc_point /* The current referance point for xmc   */ );			for( int i = 0; i <= 39; i++ )			{				dp[ i + dp_dpp_point_dp0 ] = Add.GSM_ADD( e[5 + i], 									  dpp[i + dp_dpp_point_dp0] );			}			g_s.setDp0(dp);			dp_dpp_point_dp0 += 40;		}        		for( int i = 0; i < 120; i++ )		{			g_s.setDp0Indexed(i, g_s.getDp0Indexed( (160 + i) ));		}	}	private void Gsm_Preprocess(short[] so)	/* [0..159] 	IN/OUT	*/		throws IllegalArgumentException	{		int index = 0, so_index = 0;		short z1 = g_s.getZ1();		int L_z2 = g_s.getL_z2();		int   mp = g_s.getMp();		short s1 = 0, msp = 0, lsp = 0, temp = 0, SO = 0;		int   L_s2 = 0, L_temp = 0;		int   k = 160;		while (k != 0)		{			k--;			/*  4.2.1   Downscaling of the input signal			 */			SO = (short)(Add.SASR((short)input_signal[index++], (short)3) << 2);			if ( ! (SO >= -0x4000) )			{ 	/* downscaled by     */				throw new IllegalArgumentException					("Gsm_Preprocess: SO = "					 +SO+" is out of range. Sould be >= -0x4000 ");			}			if ( ! (SO <=  0x3FFC) )			{	/* previous routine. */				throw new IllegalArgumentException					("Gsm_Preprocess: SO = "					 +SO+" is out of range. Sould be <= 0x3FFC ");			}			/*  4.2.2   Offset compensation			 * 			 *  This part implements a high-pass filter and requires extended			 *  arithmetic precision for the recursive part of this filter.			 *  The input of this procedure is the array so[0...159] and the			 *  output the array sof[ 0...159 ].			 */			/*   Compute the non-recursive part			 */			s1 = (short) (SO - z1);	/* s1 = gsm_sub( *so, z1 ); */			z1 = SO;			if(s1 == Gsm_Def.MIN_WORD)			{				throw new IllegalArgumentException					("Gsm_Preprocess: s1 = "					 +s1+" is out of range. ");			}			/*   Compute the recursive part			 */			L_s2 = s1;			L_s2 <<= 15;			/*   Execution of a 31 bv 16 bits multiplication			 */			msp = Add.SASR( L_z2, 15 );			/* gsm_L_sub(L_z2,(msp<<15)); */			lsp = (short) (L_z2 - ((int) (msp << 15))); 			L_s2  += Add.GSM_MULT_R( lsp, (short) 32735 );			L_temp = (int)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/			L_z2   = Add.GSM_L_ADD( L_temp, L_s2 );			/*    Compute sof[k] with rounding			 */			L_temp = Add.GSM_L_ADD( L_z2, 16384 );			/*   4.2.3  Preemphasis			 */			msp   = Add.GSM_MULT_R( (short) mp, (short) -28180 );			mp    = Add.SASR( L_temp, 15 );			so[so_index++] = Add.GSM_ADD( (short) mp, msp );		}		g_s.setZ1(z1);		g_s.setL_z2(L_z2);		g_s.setMp(mp);	}	/* Write the encoded bytes to the stream. */	private void ulaw_output(FileOutputStream out)		throws IOException	{		int i = 0;		byte output = 0;		for (i = 0; i < frame.length; i++)		{			out.write(frame[i]);		}	}	/**	 * Used for debugging. 	 *	 * @param g_s The Gsm_State object to be viewed.	 */	private void dump_Gsm_State(Gsm_State g_s)	{		g_s.dump_Gsm_State();	}	/*	 * This is the encoding matrix. 	 *	 * Java does not have an unsigned short, ie. 16 bits, so	 * I will use the upper 16 bits of the integer. This wastes	 * a little memory although I do not think it will cause a	 * problem.	 */	private static final int u2s[] =	{		33280, 34308, 35336, 36364, 37393, 38421, 39449, 40477,		41505, 42534, 43562, 44590, 45618, 46647, 47675, 48703,		49474, 49988, 50503, 51017, 51531, 52045, 52559, 53073,		53587, 54101, 54616, 55130, 55644, 56158, 56672, 57186,		57572, 57829, 58086, 58343, 58600, 58857, 59114, 59371,		59628, 59885, 60142, 60399, 60656, 60913, 61171, 61428,		61620, 61749, 61877, 62006, 62134, 62263, 62392, 62520,		62649, 62777, 62906, 63034, 63163, 63291, 63420, 63548,		63645, 63709, 63773, 63838, 63902, 63966, 64030, 64095,		64159, 64223, 64287, 64352, 64416, 64480, 64544, 64609,		64657, 64689, 64721, 64753, 64785, 64818, 64850, 64882,		64914, 64946, 64978, 65010, 65042, 65075, 65107, 65139,		65163, 65179, 65195, 65211, 65227, 65243, 65259, 65275,		65291, 65308, 65324, 65340, 65356, 65372, 65388, 65404,		65416, 65424, 65432, 65440, 65448, 65456, 65464, 65472,		65480, 65488, 65496, 65504, 65512, 65520, 65528,     0,		32256, 31228, 30200, 29172, 28143, 27115, 26087, 25059,		24031, 23002, 21974, 20946, 19918, 18889, 17861, 16833,		16062, 15548, 15033, 14519, 14005, 13491, 12977, 12463,		11949, 11435, 10920, 10406,  9892,  9378,  8864,  8350,		7964,  7707,  7450,  7193,  6936,  6679,  6422,  6165,		5908,  5651,  5394,  5137,  4880,  4623,  4365,  4108,		3916,  3787,  3659,  3530,  3402,  3273,  3144,  3016,		2887,  2759,  2630,  2502,  2373,  2245,  2116,  1988,		1891,  1827,  1763,  1698,  1634,  1570,  1506,  1441,		1377,  1313,  1249,  1184,  1120,  1056,   992,   927,		879,   847,   815,   783,   751,   718,   686,   654,		622,   590,   558,   526,   494,   461,   429,   397,		373,   357,   341,   325,   309,   293,   277,   261,		245,   228,   212,   196,   180,   164,   148,   132,		120,   112,   104,    96,    88,    80,    72,    64,		56,    48,    40,    32,    24,    16,    8,      0	};}

⌨️ 快捷键说明

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