annotate libtwamr/dec_main.c @ 555:62943a1ad64e

doc/FR1-Rx-DTX-detail: grammar fix
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 11 Oct 2024 00:22:47 +0000
parents 357d1faad55d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
2 * This C module is the top level entity for our stateful decoder engine.
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdint.h>
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
7 #include <string.h>
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "tw_amr.h"
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "namespace.h"
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "typedef.h"
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "cnst.h"
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
12 #include "dec_amr.h"
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
13 #include "pstfilt.h"
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
14 #include "post_pro.h"
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
15 #include "bitno.h"
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
17 struct amr_decoder_state {
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
18 Decoder_amrState dec;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
19 Post_FilterState pstfilt;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
20 Post_ProcessState posthp;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
21 enum Mode prev_mode;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
22 Flag is_homed;
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 };
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
25 struct amr_decoder_state *amr_decoder_create(void)
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
27 struct amr_decoder_state *st;
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
29 st = malloc(sizeof(struct amr_decoder_state));
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (st)
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
31 amr_decoder_reset(st);
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return st;
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
35 void amr_decoder_reset(struct amr_decoder_state *st)
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
37 Decoder_amr_reset(&st->dec, 0);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
38 Post_Filter_reset(&st->pstfilt);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
39 Post_Process_reset(&st->posthp);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
40 st->prev_mode = (enum Mode) 0;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
41 st->is_homed = 1;
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
44 void amr_decode_frame(struct amr_decoder_state *st,
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
45 const struct amr_param_frame *frame, int16_t *pcm)
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
47 enum Mode mode;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
48 Word16 parm[MAX_PRM_SIZE];
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
49 Word16 Az_dec[AZ_SIZE];
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 Word16 i;
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
52 /* fast home state handling needs to be first */
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
53 if (st->is_homed && amr_check_dhf(frame, 1)) {
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
54 for (i = 0; i < L_FRAME; i++)
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
55 pcm[i] = EHF_MASK;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
56 return;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
57 }
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
58 /* "unpack" into internal form */
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
59 if (frame->type == RX_NO_DATA)
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
60 mode = st->prev_mode;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
61 else {
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
62 mode = frame->mode & 7;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
63 st->prev_mode = mode;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
64 }
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
65 memcpy(parm, frame->param, prmno[mode] * sizeof(int16_t));
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
66 /* now we can call the guts of the decoder */
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
67 Decoder_amr(&st->dec, mode, parm, frame->type, pcm, Az_dec);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
68 Post_Filter(&st->pstfilt, mode, pcm, Az_dec);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
69 Post_Process(&st->posthp, pcm, L_FRAME);
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
70 /*
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
71 * The 3 lsbs of each speech sample typically won't be all 0
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
72 * out of Post_Process(), hence we have to clear them explicitly
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
73 * to maintain overall bit-exact operation.
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
74 */
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 for (i = 0; i < L_FRAME; i++)
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
76 pcm[i] &= 0xFFF8;
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
77 /* final check for full DHF */
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
78 if (amr_check_dhf(frame, 0))
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
79 amr_decoder_reset(st);
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 else
427
357d1faad55d libtwamr: implement decoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents: 419
diff changeset
81 st->is_homed = 0;
419
2a094af3d384 libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }