comparison hrutil/encode.c @ 628:c53ce88d67a7

hrutil: new program gsmhr-encode
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Mar 2026 05:49:23 +0000
parents
children
comparison
equal deleted inserted replaced
627:45e727b53da1 628:c53ce88d67a7
1 /*
2 * This file is the main module for gsmhr-encode utility. This utility
3 * is intended to serve as the "user-friendly" speech encoder for GSM-HR,
4 * reading speech input in WAV format and emitting GSM-HR output in
5 * TW-TS-005 Annex B hex format.
6 */
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <unistd.h>
14 #include "../libgsmhr1/tw_gsmhr.h"
15 #include "../libtest/wavreader.h"
16 #include "../libtest/wavrdhelp.h"
17
18 main(argc, argv)
19 char **argv;
20 {
21 char *infname, *outfname;
22 void *wav;
23 FILE *outf;
24 struct gsmhr_encoder_state *state;
25 int16_t pcm[160];
26 int16_t prm_out[GSMHR_NUM_PARAMS_ENC];
27 int opt, rc, dtx = 0, emit_5993 = 0;
28 extern int optind;
29
30 while ((opt = getopt(argc, argv, "dx")) != EOF) {
31 switch (opt) {
32 case 'd':
33 dtx = 1;
34 continue;
35 case 'x':
36 emit_5993 = 1;
37 continue;
38 default:
39 usage:
40 fprintf(stderr,
41 "usage: %s [-d] [-x] input.wav output.hex\n",
42 argv[0]);
43 exit(1);
44 }
45 }
46 if (argc != optind + 2)
47 goto usage;
48 infname = argv[optind];
49 outfname = argv[optind+1];
50
51 wav = wav_read_open(infname);
52 if (!wav) {
53 perror(infname);
54 exit(1);
55 }
56 rc = wavrd_check_header(wav, infname);
57 if (rc < 0)
58 exit(1); /* error msg already printed */
59 outf = fopen(outfname, "w");
60 if (!outf) {
61 perror(outfname);
62 exit(1);
63 }
64 state = gsmhr_encoder_create(dtx);
65 if (!state) {
66 perror("gsmhr_encoder_create()");
67 exit(1);
68 }
69 for (;;) {
70 rc = wavrd_get_pcm_block(wav, pcm);
71 if (!rc)
72 break;
73 gsmhr_encode_frame(state, pcm, prm_out);
74 emit_cod_to_tw5b(outf, prm_out, emit_5993);
75 }
76 fclose(outf);
77 exit(0);
78 }