11 int main(int argc, char *argv[])
16 int chunk, total_out, status, c;
17 int input_avail, output_avail;
23 strm.bit_per_sample = 8;
25 strm.segment_size = 2;
26 strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
29 while ((c = getopt (argc, argv, "cb:B:S:")) != -1)
33 chunk = 2 * atoi(optarg);
36 strm.bit_per_sample = atoi(optarg);
39 strm.segment_size = atoi(optarg);
46 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
47 else if (isprint (optopt))
48 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
51 "Unknown option character `\\x%x'.\n",
64 fprintf(stderr, "Usage: %s [ -c ] [ -b chunksize ] name\n", argv[0]);
68 out = (uint8_t *)malloc(chunk);
69 in = (uint8_t *)malloc(chunk);
72 if (in == NULL || out == NULL)
75 if (ae_encode_init(&strm) != AE_OK)
80 strm.avail_out = chunk;
86 if ((infp = fopen(infn, "r")) == NULL)
95 outfn = malloc(strlen(infn) + 4);
99 sprintf(outfn, "%s.aee", infn);
101 if ((outfp = fopen(outfn, "w")) == NULL)
105 while(input_avail || output_avail)
107 if (strm.avail_in == 0 && input_avail)
109 strm.avail_in = fread(in, 1, chunk, infp);
110 if (strm.avail_in != chunk)
112 strm.next_in = (uint8_t *)in;
115 if ((status = ae_encode(&strm, AE_NO_FLUSH)) != AE_OK)
117 fprintf(stderr, "error is %i\n", status);
121 if (strm.total_out - total_out > 0)
123 fwrite(out, strm.total_out - total_out, 1, outfp);
124 total_out = strm.total_out;
127 strm.avail_out = chunk;
136 if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK)
138 fprintf(stderr, "error is %i\n", status);
142 if (strm.total_out - total_out > 0)
144 fwrite(out, strm.total_out - total_out, 1, outfp);
147 ae_encode_end(&strm);