annotate libgsmefr/dec_main.c @ 94:d80e9f12a1d1

libgsmefr: decoder main function put together
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 26 Nov 2022 18:52:49 +0000
parents
children 18866c0354ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
94
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains our GSM EFR decoder main function, EFR_decode_params(),
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * that stands at the boundary between our public interface and the guts of
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * ETSI-based codec.
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "gsm_efr.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "typedef.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "namespace.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "cnst.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "codec.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "sig_proc.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "memops.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "dec_state.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "d_homing.h"
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 /* These constants define the number of consecutive parameters
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 that function decoder_homing_frame_test() checks */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #define WHOLE_FRAME 57
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define TO_FIRST_SUBFRAME 18
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 void EFR_decode_params(struct EFR_decoder_state *st, const int16_t *params,
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int bfi, int SID_flag, int TAF, int16_t *pcm_out)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 Word16 *synth = st->synth_buf + M;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 Word16 Az_dec[AZ_SIZE];
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 Word16 i, temp;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 Word16 reset_flag;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (!bfi) /* BFI == 0, perform DHF check */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (st->reset_flag_old) /* Check for second and further
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 successive DHF (to first subfr.) */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 reset_flag = decoder_homing_frame_test (params,
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 TO_FIRST_SUBFRAME);
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 else
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 reset_flag = 0;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 else /* BFI==1, bypass DHF check (frame
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 is taken as not being a DHF) */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 reset_flag = 0;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (reset_flag && st->reset_flag_old)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 /* Force the output to be the encoder homing frame pattern */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (i = 0; i < L_FRAME; i++)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 synth[i] = EHF_MASK;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 else
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 /* Synthesis */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Decoder_12k2 (st, bfi, params, synth, Az_dec, TAF, SID_flag);
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Post_Filter (st, synth, Az_dec); /* Post-filter */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 for (i = 0; i < L_FRAME; i++)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* Upscale the 15 bit linear PCM to 16 bits,
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 then truncate to 13 bits */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 temp = synth[i] << 1;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 synth[i] = temp & 0xfff8;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 } /* else */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Copy (synth, pcm_out, L_FRAME);
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 /* BFI == 0, perform check for first DHF (whole frame) */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!bfi && !st->reset_flag_old)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 reset_flag = decoder_homing_frame_test (params, WHOLE_FRAME);
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (reset_flag)
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 /* Bring the decoder and receive DTX to the home state */
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 EFR_decoder_reset(st);
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 } else {
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 st->reset_flag_old = 0;
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
d80e9f12a1d1 libgsmefr: decoder main function put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }