FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/enc_main.c @ 450:16bc3036cc84
LICENSE: acknowledge libtwamr origin from ETSI/3GPP
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 10 May 2024 01:48:20 +0000 |
parents | 2a094af3d384 |
children | 4c9222d95647 |
rev | line source |
---|---|
419
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C module is the top level entity for our stateful encoder engine. |
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> |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "tw_amr.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "namespace.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "typedef.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "cnst.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "cod_amr.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "pre_proc.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "sid_sync.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "e_homing.h" |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 struct amr_encoder_state { |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 cod_amrState cod; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 Pre_ProcessState pre; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 sid_syncState sid; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 }; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct amr_encoder_state *amr_encoder_create(int dtx, int use_vad2) |
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 struct amr_encoder_state *st; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 st = malloc(sizeof(struct amr_encoder_state)); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (st) |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 amr_encoder_reset(st, dtx, use_vad2); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return st; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 void amr_encoder_reset(struct amr_encoder_state *st, int dtx, int use_vad2) |
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 cod_amr_reset(&st->cod, dtx, use_vad2); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 Pre_Process_reset(&st->pre); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 sid_sync_reset(&st->sid); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 void amr_encode_frame(struct amr_encoder_state *st, enum Mode mode, |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 const int16_t *pcm, struct amr_param_frame *frame) |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 Word16 new_speech[L_FRAME], syn[L_FRAME]; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 enum Mode used_mode; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 enum TXFrameType tx_type; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 Word16 i; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* input */ |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 for (i = 0; i < L_FRAME; i++) |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 new_speech[i] = pcm[i] & 0xFFF8; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 Pre_Process(&st->pre, new_speech, L_FRAME); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 /* main process */ |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 cod_amr(&st->cod, mode, new_speech, frame->param, &used_mode, syn); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 sid_sync(&st->sid, used_mode, &tx_type); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 frame->type = tx_type; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (tx_type != TX_NO_DATA) |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 frame->mode = mode; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 else |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 frame->mode = 0xFF; |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 /* encoder homing */ |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (encoder_homing_frame_test(pcm)) |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 amr_encoder_reset(st, st->cod.dtx, st->cod.vadSt.use_vad2); |
2a094af3d384
libtwamr: implement encoder top level
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |