FreeCalypso > hg > gsm-codec-lib
annotate libgsmfr2/full_dec.c @ 416:48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 03:15:19 +0000 |
parents | 4db5fc10fd1a |
children | f3246d109e2d |
rev | line source |
---|---|
279
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the "full decoder" functionality of libgsmfr2: |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * first the Rx DTX handler, then the regular GSM 06.10 decoder. This full |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * decoder also implements the optional homing feature, resetting both |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * components upon receiving DHF. |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "tw_gsmfr.h" |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "typedef.h" |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "ed_state.h" |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "pp_state.h" |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 struct gsmfr_fulldec_state { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 struct gsmfr_0610_state dec_0610; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 struct gsmfr_preproc_state rx_dtx; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int is_homed; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 }; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct gsmfr_fulldec_state *gsmfr_fulldec_create(void) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct gsmfr_fulldec_state *st; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 st = malloc(sizeof(struct gsmfr_fulldec_state)); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (st) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 gsmfr_fulldec_reset(st); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return st; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 void gsmfr_fulldec_reset(struct gsmfr_fulldec_state *st) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 gsmfr_0610_reset(&st->dec_0610); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 gsmfr_preproc_reset(&st->rx_dtx); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 st->is_homed = 1; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void emit_ehf_output(int16_t *pcm_out) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 unsigned n; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (n = 0; n < 160; n++) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 pcm_out[n] = 0x0008; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 void gsmfr_fulldec_good_frame(struct gsmfr_fulldec_state *st, |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 const uint8_t *frame_in, int16_t *pcm_out) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 uint8_t frame_mod[GSMFR_RTP_FRAME_LEN]; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (st->is_homed && !memcmp(frame_in, gsmfr_decoder_homing_frame, 12)) { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 emit_ehf_output(pcm_out); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 memcpy(frame_mod, frame_in, GSMFR_RTP_FRAME_LEN); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 gsmfr_preproc_good_frame(&st->rx_dtx, frame_mod); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 gsmfr_0610_decode_frame(&st->dec_0610, frame_mod, pcm_out); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (!memcmp(frame_in, gsmfr_decoder_homing_frame, GSMFR_RTP_FRAME_LEN)) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 gsmfr_fulldec_reset(st); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 else |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 st->is_homed = 0; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 void gsmfr_fulldec_bfi(struct gsmfr_fulldec_state *st, int taf, |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 int16_t *pcm_out) |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 uint8_t frame_mod[GSMFR_RTP_FRAME_LEN]; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (st->is_homed) { |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 memset(pcm_out, 0, sizeof(int16_t) * 160); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return; |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 gsmfr_preproc_bfi(&st->rx_dtx, taf, frame_mod); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 gsmfr_0610_decode_frame(&st->dec_0610, frame_mod, pcm_out); |
4db5fc10fd1a
libgsmfr2: implement full decoder
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |