comparison efrtest/encode.c @ 121:b51295fcbbae

gsmefr-encode utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Dec 2022 03:17:58 +0000
parents frtest/encode.c@69ed7af28473
children
comparison
equal deleted inserted replaced
120:bd832a456339 121:b51295fcbbae
1 /*
2 * This file is the main module for gsmefr-encode utility.
3 */
4
5 #include <stdio.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "../libgsmefr/gsm_efr.h"
11 #include "../libtest/wavreader.h"
12 #include "../libtest/wavrdhelp.h"
13
14 main(argc, argv)
15 char **argv;
16 {
17 char *infname, *outfname;
18 void *wav;
19 FILE *binf;
20 struct EFR_encoder_state *state;
21 int16_t pcm[160];
22 uint8_t frame[EFR_RTP_FRAME_LEN];
23 int dtx, rc;
24
25 if (argc == 3 && argv[1][0] != '-') {
26 dtx = 0;
27 infname = argv[1];
28 outfname = argv[2];
29 } else if (argc == 4 && !strcmp(argv[1], "-d")) {
30 dtx = 1;
31 infname = argv[2];
32 outfname = argv[3];
33 } else {
34 fprintf(stderr, "usage: %s [-d] input.wav output.gsmx\n",
35 argv[0]);
36 exit(1);
37 }
38 wav = wav_read_open(infname);
39 if (!wav) {
40 perror(infname);
41 exit(1);
42 }
43 rc = wavrd_check_header(wav, infname);
44 if (rc < 0)
45 exit(1); /* error msg already printed */
46 binf = fopen(outfname, "w");
47 if (!binf) {
48 perror(outfname);
49 exit(1);
50 }
51 state = EFR_encoder_create(dtx);
52 if (!state) {
53 perror("EFR_encoder_create()");
54 exit(1);
55 }
56 for (;;) {
57 rc = wavrd_get_pcm_block(wav, pcm);
58 if (!rc)
59 break;
60 EFR_encode_frame(state, pcm, frame, (int *) 0, (int *) 0);
61 fwrite(frame, 1, sizeof frame, binf);
62 }
63 fclose(binf);
64 exit(0);
65 }