xref: /aosp_15_r20/external/libgsm/src/code.c (revision 8ec969cea971fe25ff2d3933a5a9f8504f8e86c9)
1*8ec969ceSTreehugger Robot /*
2*8ec969ceSTreehugger Robot  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3*8ec969ceSTreehugger Robot  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
4*8ec969ceSTreehugger Robot  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5*8ec969ceSTreehugger Robot  */
6*8ec969ceSTreehugger Robot 
7*8ec969ceSTreehugger Robot /* $Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/code.c,v 1.3 1996/07/02 09:59:05 jutta Exp $ */
8*8ec969ceSTreehugger Robot 
9*8ec969ceSTreehugger Robot #include	"config.h"
10*8ec969ceSTreehugger Robot 
11*8ec969ceSTreehugger Robot 
12*8ec969ceSTreehugger Robot #ifdef	HAS_STRING_H
13*8ec969ceSTreehugger Robot #include	<string.h>
14*8ec969ceSTreehugger Robot #else
15*8ec969ceSTreehugger Robot #	include "proto.h"
16*8ec969ceSTreehugger Robot 	extern char	* memcpy P((char *, char *, int));
17*8ec969ceSTreehugger Robot #endif
18*8ec969ceSTreehugger Robot 
19*8ec969ceSTreehugger Robot #include	"private.h"
20*8ec969ceSTreehugger Robot #include	"gsm.h"
21*8ec969ceSTreehugger Robot #include	"proto.h"
22*8ec969ceSTreehugger Robot 
23*8ec969ceSTreehugger Robot /*
24*8ec969ceSTreehugger Robot  *  4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER
25*8ec969ceSTreehugger Robot  */
26*8ec969ceSTreehugger Robot 
27*8ec969ceSTreehugger Robot void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc),
28*8ec969ceSTreehugger Robot 
29*8ec969ceSTreehugger Robot 	struct gsm_state	* S,
30*8ec969ceSTreehugger Robot 
31*8ec969ceSTreehugger Robot 	word	* s,	/* [0..159] samples		  	IN	*/
32*8ec969ceSTreehugger Robot 
33*8ec969ceSTreehugger Robot /*
34*8ec969ceSTreehugger Robot  * The RPE-LTD coder works on a frame by frame basis.  The length of
35*8ec969ceSTreehugger Robot  * the frame is equal to 160 samples.  Some computations are done
36*8ec969ceSTreehugger Robot  * once per frame to produce at the output of the coder the
37*8ec969ceSTreehugger Robot  * LARc[1..8] parameters which are the coded LAR coefficients and
38*8ec969ceSTreehugger Robot  * also to realize the inverse filtering operation for the entire
39*8ec969ceSTreehugger Robot  * frame (160 samples of signal d[0..159]).  These parts produce at
40*8ec969ceSTreehugger Robot  * the output of the coder:
41*8ec969ceSTreehugger Robot  */
42*8ec969ceSTreehugger Robot 
43*8ec969ceSTreehugger Robot 	word	* LARc,	/* [0..7] LAR coefficients		OUT	*/
44*8ec969ceSTreehugger Robot 
45*8ec969ceSTreehugger Robot /*
46*8ec969ceSTreehugger Robot  * Procedure 4.2.11 to 4.2.18 are to be executed four times per
47*8ec969ceSTreehugger Robot  * frame.  That means once for each sub-segment RPE-LTP analysis of
48*8ec969ceSTreehugger Robot  * 40 samples.  These parts produce at the output of the coder:
49*8ec969ceSTreehugger Robot  */
50*8ec969ceSTreehugger Robot 
51*8ec969ceSTreehugger Robot 	word	* Nc,	/* [0..3] LTP lag			OUT 	*/
52*8ec969ceSTreehugger Robot 	word	* bc,	/* [0..3] coded LTP gain		OUT 	*/
53*8ec969ceSTreehugger Robot 	word	* Mc,	/* [0..3] RPE grid selection		OUT     */
54*8ec969ceSTreehugger Robot 	word	* xmaxc,/* [0..3] Coded maximum amplitude	OUT	*/
55*8ec969ceSTreehugger Robot 	word	* xMc	/* [13*4] normalized RPE samples	OUT	*/
56*8ec969ceSTreehugger Robot )
57*8ec969ceSTreehugger Robot {
58*8ec969ceSTreehugger Robot 	int	k;
59*8ec969ceSTreehugger Robot 	word	* dp  = S->dp0 + 120;	/* [ -120...-1 ] */
60*8ec969ceSTreehugger Robot 	word	* dpp = dp;		/* [ 0...39 ]	 */
61*8ec969ceSTreehugger Robot 
62*8ec969ceSTreehugger Robot 	word	so[160];
63*8ec969ceSTreehugger Robot 
64*8ec969ceSTreehugger Robot 	Gsm_Preprocess			(S, s, so);
65*8ec969ceSTreehugger Robot 	Gsm_LPC_Analysis		(S, so, LARc);
66*8ec969ceSTreehugger Robot 	Gsm_Short_Term_Analysis_Filter	(S, LARc, so);
67*8ec969ceSTreehugger Robot 
68*8ec969ceSTreehugger Robot 	for (k = 0; k <= 3; k++, xMc += 13) {
69*8ec969ceSTreehugger Robot 
70*8ec969ceSTreehugger Robot 		Gsm_Long_Term_Predictor	( S,
71*8ec969ceSTreehugger Robot 					 so+k*40, /* d      [0..39] IN	*/
72*8ec969ceSTreehugger Robot 					 dp,	  /* dp  [-120..-1] IN	*/
73*8ec969ceSTreehugger Robot 					S->e + 5, /* e      [0..39] OUT	*/
74*8ec969ceSTreehugger Robot 					dpp,	  /* dpp    [0..39] OUT */
75*8ec969ceSTreehugger Robot 					 Nc++,
76*8ec969ceSTreehugger Robot 					 bc++);
77*8ec969ceSTreehugger Robot 
78*8ec969ceSTreehugger Robot 		Gsm_RPE_Encoding	( S,
79*8ec969ceSTreehugger Robot 					S->e + 5,/* e	  ][0..39][ IN/OUT */
80*8ec969ceSTreehugger Robot 					  xmaxc++, Mc++, xMc );
81*8ec969ceSTreehugger Robot 		/*
82*8ec969ceSTreehugger Robot 		 * Gsm_Update_of_reconstructed_short_time_residual_signal
83*8ec969ceSTreehugger Robot 		 *			( dpp, S->e + 5, dp );
84*8ec969ceSTreehugger Robot 		 */
85*8ec969ceSTreehugger Robot 
86*8ec969ceSTreehugger Robot 		{ register int i;
87*8ec969ceSTreehugger Robot 		  register longword ltmp;
88*8ec969ceSTreehugger Robot 		  for (i = 0; i <= 39; i++)
89*8ec969ceSTreehugger Robot 			dp[ i ] = GSM_ADD( S->e[5 + i], dpp[i] );
90*8ec969ceSTreehugger Robot 		}
91*8ec969ceSTreehugger Robot 		dp  += 40;
92*8ec969ceSTreehugger Robot 		dpp += 40;
93*8ec969ceSTreehugger Robot 
94*8ec969ceSTreehugger Robot 	}
95*8ec969ceSTreehugger Robot 	(void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
96*8ec969ceSTreehugger Robot 		120 * sizeof(*S->dp0) );
97*8ec969ceSTreehugger Robot }
98