6 * Usage : encode [-3|4|5] [-a|u|l] < infile > outfile
13 * Pack output codes into bytes and write them to stdout.
14 * Returns 1 if there is residual output, else returns 0.
21 static unsigned int out_buffer = 0;
22 static int out_bits = 0;
23 unsigned char out_byte;
25 out_buffer |= (code << out_bits);
28 out_byte = out_buffer & 0xff;
31 fwrite(&out_byte, sizeof (char), 1, stdout);
33 return (out_bits > 0);
41 struct g72x_state state;
42 unsigned char sample_char;
52 g72x_init_state(&state);
54 /* Set defaults to u-law input, G.721 output */
55 in_coding = AUDIO_ENCODING_ULAW;
56 in_size = sizeof (char);
57 in_buf = (unsigned *)&sample_char;
58 enc_routine = g721_encoder;
61 /* Process encoding argument, if any */
62 while ((argc > 1) && (argv[1][0] == '-')) {
65 enc_routine = g723_24_encoder;
69 enc_routine = g721_encoder;
73 enc_routine = g723_40_encoder;
77 in_coding = AUDIO_ENCODING_ULAW;
78 in_size = sizeof (char);
79 in_buf = (unsigned *)&sample_char;
82 in_coding = AUDIO_ENCODING_ALAW;
83 in_size = sizeof (char);
84 in_buf = (unsigned *)&sample_char;
87 in_coding = AUDIO_ENCODING_LINEAR;
88 in_size = sizeof (short);
89 in_buf = (unsigned *)&sample_short;
92 fprintf(stderr, "CCITT ADPCM Encoder -- usage:\n");
93 fprintf(stderr, "\tencode [-3|4|5] [-a|u|l] < infile > outfile\n");
94 fprintf(stderr, "where:\n");
95 fprintf(stderr, "\t-3\tGenerate G.723 24kbps (3-bit) data\n");
96 fprintf(stderr, "\t-4\tGenerate G.721 32kbps (4-bit) data [default]\n");
97 fprintf(stderr, "\t-5\tGenerate G.723 40kbps (5-bit) data\n");
98 fprintf(stderr, "\t-a\tProcess 8-bit A-law input data\n");
99 fprintf(stderr, "\t-u\tProcess 8-bit u-law input data [default]\n");
100 fprintf(stderr, "\t-l\tProcess 16-bit linear PCM input data\n");
107 /* Read input file and process */
108 while (fread(in_buf, in_size, 1, stdin) == 1) {
109 code = (*enc_routine)(in_size == 2 ? sample_short : sample_char,
111 resid = pack_output(code, enc_bits);
114 /* Write zero codes until all residual codes are written out */
116 resid = pack_output(0, enc_bits);