2 * Copyright 1996 by Jutta Degener and Carsten Bormann, Technische
3 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
9 /* Generate code to pack a bit array from a name:#bits description,
18 /* This module goes back to one Jeff Chilton used for his implementation
19 * of the #49 WAV GSM format. (In his original patch 8, it replaced
22 * In Microsoft's WAV #49 version of the GSM format, two 32 1/2
23 * byte GSM frames are packed together to make one WAV frame, and
24 * the GSM parameters are packed into bytes right-to-left rather
27 * That is, where toast's GSM format writes
29 * aaaaaabb bbbbcccc cdddddee ...
30 * ___1____ ___2____ ___3____
32 * for parameters a (6 bits), b (6 bits), c (5 bits), d (5 bits), e ..
35 * bbaaaaaa ccccbbbb eedddddc ...
36 * ___1____ ___2____ ___3____
38 * (This format looks a lot prettier if one pictures octets coming
39 * in through a fifo queue from the left, rather than waiting in the
40 * right-hand remainder of a C array.)
43 #define WORD_BITS 16 /* sizeof(uword) * CHAR_BIT on the
44 * target architecture---if this isn't 16,
45 * you're in trouble with this library anyway.
48 #define BYTE_BITS 8 /* CHAR_BIT on the target architecture---
49 * if this isn't 8, you're in *deep* trouble.
52 void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
54 struct spex * sp = s_spex;
57 printf("uword sr = 0;\n");
59 for (; n_spex > 0; n_spex--, sp++) {
62 * new var value unused
65 * [____________xxxxxx**********]
69 printf("sr = sr >> %d | %s << %d;\n",
72 WORD_BITS - sp->varsize);
76 while (n_in >= BYTE_BITS) {
77 printf("*c++ = sr >> %d;\n",
83 while (n_in >= BYTE_BITS) {
84 printf("*c++ = sr >> %d;\n", WORD_BITS - n_in);
89 fprintf(stderr, "warning: %d bits left over\n", n_in);