xref: /aosp_15_r20/external/libgsm/tls/sour.c (revision 8ec969cea971fe25ff2d3933a5a9f8504f8e86c9)
1*8ec969ceSTreehugger Robot /*
2*8ec969ceSTreehugger Robot  * Copyright 1996 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*/
8*8ec969ceSTreehugger Robot 
9*8ec969ceSTreehugger Robot /* Generate code to pack a bit array from a name:#bits description,
10*8ec969ceSTreehugger Robot  * WAV #49 style.
11*8ec969ceSTreehugger Robot  */
12*8ec969ceSTreehugger Robot 
13*8ec969ceSTreehugger Robot #include	<stdio.h>
14*8ec969ceSTreehugger Robot #include	"taste.h"
15*8ec969ceSTreehugger Robot #include	"proto.h"
16*8ec969ceSTreehugger Robot #include	<limits.h>
17*8ec969ceSTreehugger Robot 
18*8ec969ceSTreehugger Robot /* This module goes back to one Jeff Chilton used for his implementation
19*8ec969ceSTreehugger Robot  * of the #49 WAV GSM format.  (In his original patch 8, it replaced
20*8ec969ceSTreehugger Robot  * bitter.c.)
21*8ec969ceSTreehugger Robot  *
22*8ec969ceSTreehugger Robot  * In Microsoft's WAV #49 version of the GSM format, two 32 1/2
23*8ec969ceSTreehugger Robot  * byte GSM frames are packed together to make one WAV frame, and
24*8ec969ceSTreehugger Robot  * the GSM parameters are packed into bytes right-to-left rather
25*8ec969ceSTreehugger Robot  * than left-to-right.
26*8ec969ceSTreehugger Robot  *
27*8ec969ceSTreehugger Robot  * That is, where toast's GSM format writes
28*8ec969ceSTreehugger Robot  *
29*8ec969ceSTreehugger Robot  * 	aaaaaabb bbbbcccc cdddddee ...
30*8ec969ceSTreehugger Robot  *	___1____ ___2____ ___3____
31*8ec969ceSTreehugger Robot  *
32*8ec969ceSTreehugger Robot  *  for parameters a (6 bits), b (6 bits), c (5 bits), d (5 bits), e ..
33*8ec969ceSTreehugger Robot  *  the WAV format has
34*8ec969ceSTreehugger Robot  *
35*8ec969ceSTreehugger Robot  * 	bbaaaaaa ccccbbbb eedddddc ...
36*8ec969ceSTreehugger Robot  *	___1____ ___2____ ___3____
37*8ec969ceSTreehugger Robot  *
38*8ec969ceSTreehugger Robot  *  (This format looks a lot prettier if one pictures octets coming
39*8ec969ceSTreehugger Robot  *  in through a fifo queue from the left, rather than waiting in the
40*8ec969ceSTreehugger Robot  *  right-hand remainder of a C array.)
41*8ec969ceSTreehugger Robot  */
42*8ec969ceSTreehugger Robot 
43*8ec969ceSTreehugger Robot #define WORD_BITS	16	/* sizeof(uword) * CHAR_BIT on the
44*8ec969ceSTreehugger Robot 				 * target architecture---if this isn't 16,
45*8ec969ceSTreehugger Robot 				 * you're in trouble with this library anyway.
46*8ec969ceSTreehugger Robot 				 */
47*8ec969ceSTreehugger Robot 
48*8ec969ceSTreehugger Robot #define BYTE_BITS	 8	/* CHAR_BIT on the target architecture---
49*8ec969ceSTreehugger Robot 				 * if this isn't 8, you're in *deep* trouble.
50*8ec969ceSTreehugger Robot 				 */
51*8ec969ceSTreehugger Robot 
52*8ec969ceSTreehugger Robot void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
53*8ec969ceSTreehugger Robot {
54*8ec969ceSTreehugger Robot 	struct spex	* sp = s_spex;
55*8ec969ceSTreehugger Robot 	int		  n_in = 0;
56*8ec969ceSTreehugger Robot 
57*8ec969ceSTreehugger Robot 	printf("uword sr = 0;\n");
58*8ec969ceSTreehugger Robot 
59*8ec969ceSTreehugger Robot 	for (; n_spex > 0; n_spex--, sp++) {
60*8ec969ceSTreehugger Robot 
61*8ec969ceSTreehugger Robot 		/*	insert       old
62*8ec969ceSTreehugger Robot 		 *	new var	     value     unused
63*8ec969ceSTreehugger Robot 		 *	here
64*8ec969ceSTreehugger Robot 		 *
65*8ec969ceSTreehugger Robot 		 *	[____________xxxxxx**********]
66*8ec969ceSTreehugger Robot 		 *
67*8ec969ceSTreehugger Robot 		 *	<----- n_in ------>
68*8ec969ceSTreehugger Robot 		 */
69*8ec969ceSTreehugger Robot 		printf("sr = sr >> %d | %s << %d;\n",
70*8ec969ceSTreehugger Robot 			sp->varsize,
71*8ec969ceSTreehugger Robot 			sp->var,
72*8ec969ceSTreehugger Robot 			WORD_BITS - sp->varsize);
73*8ec969ceSTreehugger Robot 
74*8ec969ceSTreehugger Robot 		n_in += sp->varsize;
75*8ec969ceSTreehugger Robot 
76*8ec969ceSTreehugger Robot 		while (n_in >= BYTE_BITS) {
77*8ec969ceSTreehugger Robot 			printf("*c++ = sr >> %d;\n",
78*8ec969ceSTreehugger Robot 				WORD_BITS - n_in);
79*8ec969ceSTreehugger Robot 			n_in -= BYTE_BITS;
80*8ec969ceSTreehugger Robot 		}
81*8ec969ceSTreehugger Robot 	}
82*8ec969ceSTreehugger Robot 
83*8ec969ceSTreehugger Robot 	while (n_in >= BYTE_BITS) {
84*8ec969ceSTreehugger Robot 		printf("*c++ = sr >> %d;\n", WORD_BITS - n_in);
85*8ec969ceSTreehugger Robot 		n_in -= BYTE_BITS;
86*8ec969ceSTreehugger Robot 	}
87*8ec969ceSTreehugger Robot 
88*8ec969ceSTreehugger Robot 	if (n_in > 0) {
89*8ec969ceSTreehugger Robot 		fprintf(stderr, "warning: %d bits left over\n", n_in);
90*8ec969ceSTreehugger Robot 	}
91*8ec969ceSTreehugger Robot }
92