annotate frtest/encode.c @ 32:9639a44ae2e7

dev: efr-bit-packing helper program
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 24 Nov 2022 01:41:49 +0000
parents 69ed7af28473
children f00925b533b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This file is the main module for gsmfr-encode utility.
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <gsm.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "../libtest/wavreader.h"
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "../libtest/wavrdhelp.h"
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 main(argc, argv)
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 void *wav;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *binf;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 gsm enc_state;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int16_t pcm[160];
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 uint8_t frame[33];
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int rc;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (argc != 3) {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 fprintf(stderr, "usage: %s input.wav output.gsm\n", argv[0]);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 wav = wav_read_open(argv[1]);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!wav) {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 perror(argv[1]);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 rc = wavrd_check_header(wav, argv[1]);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (rc < 0)
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1); /* error msg already printed */
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 binf = fopen(argv[2], "w");
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (!binf) {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 perror(argv[2]);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 enc_state = gsm_create();
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!enc_state) {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr, "gsm_create() failed!\n");
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (;;) {
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 rc = wavrd_get_pcm_block(wav, pcm);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!rc)
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 gsm_encode(enc_state, pcm, frame);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fwrite(frame, 1, sizeof frame, binf);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 fclose(binf);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 exit(0);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }