FreeCalypso > hg > vband-misc
annotate pcma2efr/gen-amr-2fr.c @ 34:307fe06fabec
dhf: generate EFR hex DHF in C form
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 14 May 2024 03:36:31 +0000 |
parents | 4f47447fd17f |
children |
rev | line source |
---|---|
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
22
f4420403219a
pcmu2efr: change linear input gen to support 2nd frame
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
2 * The code in this module takes linear_input_array[] from gen160.c |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
3 * and generates EFR-format frames by way of libtwamr encoder. |
23
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
4 * This version does a second frame pass on offsets 120-159. |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
28
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
10 #include <string.h> |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
11 #include <strings.h> |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <gsm_efr.h> |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
13 #include <tw_amr.h> |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
22
f4420403219a
pcmu2efr: change linear input gen to support 2nd frame
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
15 extern uint16_t linear_input_array[480]; |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
17 uint8_t amr_efr[160][31]; |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 void |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
20 generate_amr_efr(void) |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
22 struct amr_encoder_state *st; |
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
23 struct amr_param_frame amr_frame; |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned m; |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
26 st = amr_encoder_create(0, 0); |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!st) { |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
28 fprintf(stderr, "error: amr_encoder_create() failed\n"); |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 for (m = 0; m < 160; m++) { |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
32 amr_encoder_reset(st, 0, 0); |
22
f4420403219a
pcmu2efr: change linear input gen to support 2nd frame
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
33 amr_encode_frame(st, MR122, |
f4420403219a
pcmu2efr: change linear input gen to support 2nd frame
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
34 (const int16_t *) linear_input_array + 160 - m, |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
35 &amr_frame); |
23
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
36 if (m >= 120) { |
28
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
37 if (bcmp(amr_frame.param, amr_dhf_mr122, |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
38 EFR_NUM_PARAMS * sizeof(int16_t))) { |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
39 fprintf(stderr, |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
40 "MR122 DHF check failed on AMR-EFR first frame #%u\n", |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
41 m); |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
42 exit(1); |
4f47447fd17f
pcma2efr: starting with DHF check
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
43 } |
23
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
44 amr_encode_frame(st, MR122, |
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
45 (const int16_t *) linear_input_array + 320 - m, |
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
46 &amr_frame); |
2628a34fe75b
pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
47 } |
19
2bdcd2ed9a1c
pcmu2efr: generate AMR-EFR version
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
48 EFR_params2frame(amr_frame.param, amr_efr[m]); |
15
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 free(st); |
528eef871e23
pcmu2efr project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |