comparison frtest/encode.c @ 14:69ed7af28473

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