comparison libtwamr/enc_main.c @ 419:2a094af3d384

libtwamr: implement encoder top level
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 07 May 2024 04:51:04 +0000
parents
children 4c9222d95647
comparison
equal deleted inserted replaced
418:93d6c6960a46 419:2a094af3d384
1 /*
2 * This C module is the top level entity for our stateful encoder engine.
3 */
4
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include "tw_amr.h"
8 #include "namespace.h"
9 #include "typedef.h"
10 #include "cnst.h"
11 #include "cod_amr.h"
12 #include "pre_proc.h"
13 #include "sid_sync.h"
14 #include "e_homing.h"
15
16 struct amr_encoder_state {
17 cod_amrState cod;
18 Pre_ProcessState pre;
19 sid_syncState sid;
20 };
21
22 struct amr_encoder_state *amr_encoder_create(int dtx, int use_vad2)
23 {
24 struct amr_encoder_state *st;
25
26 st = malloc(sizeof(struct amr_encoder_state));
27 if (st)
28 amr_encoder_reset(st, dtx, use_vad2);
29 return st;
30 }
31
32 void amr_encoder_reset(struct amr_encoder_state *st, int dtx, int use_vad2)
33 {
34 cod_amr_reset(&st->cod, dtx, use_vad2);
35 Pre_Process_reset(&st->pre);
36 sid_sync_reset(&st->sid);
37 }
38
39 void amr_encode_frame(struct amr_encoder_state *st, enum Mode mode,
40 const int16_t *pcm, struct amr_param_frame *frame)
41 {
42 Word16 new_speech[L_FRAME], syn[L_FRAME];
43 enum Mode used_mode;
44 enum TXFrameType tx_type;
45 Word16 i;
46
47 /* input */
48 for (i = 0; i < L_FRAME; i++)
49 new_speech[i] = pcm[i] & 0xFFF8;
50 Pre_Process(&st->pre, new_speech, L_FRAME);
51
52 /* main process */
53 cod_amr(&st->cod, mode, new_speech, frame->param, &used_mode, syn);
54 sid_sync(&st->sid, used_mode, &tx_type);
55 frame->type = tx_type;
56 if (tx_type != TX_NO_DATA)
57 frame->mode = mode;
58 else
59 frame->mode = 0xFF;
60
61 /* encoder homing */
62 if (encoder_homing_frame_test(pcm))
63 amr_encoder_reset(st, st->cod.dtx, st->cod.vadSt.use_vad2);
64 }