FreeCalypso > hg > gsm-codec-lib
annotate miscutil/amrts-pcm8-compact.c @ 556:18aca50d68df default tip
doc/Calypso-TCH-downlink: update for FR1 BFI-with-data
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 11 Oct 2024 01:54:00 +0000 |
parents | 7c50864deaff |
children |
rev | line source |
---|---|
469
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The set of AMR test sequences shipped by 3GPP as TS 26.074 includes |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * not only linear PCM (13-bit left-justified) and AMR-encoded files, |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * but also 8-bit PCM sequences in both A-law and mu-law. However, |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * those PCM8 sequences are shipped in a stupid and inconvenient format: |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * each 8-bit PCM sample is expanded to a 16-bit word, written in LE |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * byte order. This utility converts a PCM8 test sequence file |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * from this weird format into sane PCM8 format with one byte per sample. |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * For this conversion, it does not matter whether the PCM8 test sequence |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * in question is A-law or mu-law. |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 */ |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdio.h> |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdlib.h> |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 main(argc, argv) |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char **argv; |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 FILE *inf, *outf; |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int cdat, cpad; |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (argc != 3) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fprintf(stderr, "usage: %s in-file out-file\n", argv[0]); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 inf = fopen(argv[1], "r"); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!inf) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror(argv[1]); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 outf = fopen(argv[2], "w"); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!outf) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 perror(argv[2]); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 for (;;) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 cdat = getc(inf); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (cdat < 0) |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 break; |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 cpad = getc(inf); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (cpad < 0) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fprintf(stderr, "error: %s has odd length\n", argv[1]); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 exit(1); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (cpad != 0) { |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(stderr, |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 "error: presumed padding byte in %s is not 0\n", |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 argv[1]); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 putc(cdat, outf); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fclose(outf); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(0); |
7c50864deaff
amrts-pcm8-compact program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |