comparison libtwamr/sid_sync.c @ 402:a8b73b1c5b19

libtwamr: integrate sid_sync.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 19:58:22 +0000
parents
children
comparison
equal deleted inserted replaced
401:59655481e45b 402:a8b73b1c5b19
1 /*
2 *****************************************************************************
3 *
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5 * R99 Version 3.3.0
6 * REL-4 Version 4.1.0
7 *
8 *****************************************************************************
9 *
10 * File : sid_sync.c
11 *
12 *****************************************************************************
13 */
14 /*
15 *****************************************************************************
16 * MODULE INCLUDE FILE AND VERSION ID
17 *****************************************************************************
18 */
19 #include "namespace.h"
20 #include "sid_sync.h"
21
22 /*
23 *****************************************************************************
24 * INCLUDE FILES
25 *****************************************************************************
26 */
27 #include "tw_amr.h"
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31
32 /*
33 *****************************************************************************
34 * LOCAL VARIABLES AND TABLES
35 *****************************************************************************
36 */
37
38 /*
39 *****************************************************************************
40 * PUBLIC PROGRAM CODE
41 *****************************************************************************
42 */
43
44 void sid_sync_reset (sid_syncState *st)
45 {
46 st->sid_update_rate = 8;
47 st->sid_update_counter = 3;
48 st->sid_handover_debt = 0;
49 st->prev_ft = TX_SPEECH_GOOD;
50 }
51
52 int sid_sync_set_handover_debt (sid_syncState *st,
53 Word16 debtFrames)
54 {
55 /* debtFrames >= 0 */
56 st->sid_handover_debt = debtFrames;
57 return 0;
58 }
59
60 void sid_sync (sid_syncState *st, enum Mode mode,
61 enum TXFrameType *tx_frame_type)
62 {
63 if (mode == MRDTX)
64 {
65 st->sid_update_counter--;
66 if (st->prev_ft == TX_SPEECH_GOOD)
67 {
68 *tx_frame_type = TX_SID_FIRST;
69 st->sid_update_counter = 3;
70 }
71 else
72 {
73 /* TX_SID_UPDATE or TX_NO_DATA */
74 if ((st->sid_handover_debt > 0) &&
75 (st->sid_update_counter > 2) )
76 {
77 /* ensure extra updates are properly delayed after
78 a possible SID_FIRST */
79 *tx_frame_type = TX_SID_UPDATE;
80 st->sid_handover_debt--;
81 }
82 else
83 {
84 if (st->sid_update_counter == 0)
85 {
86 *tx_frame_type = TX_SID_UPDATE;
87 st->sid_update_counter = st->sid_update_rate;
88 } else {
89 *tx_frame_type = TX_NO_DATA;
90 }
91 }
92 }
93 }
94 else
95 {
96 st->sid_update_counter = st->sid_update_rate ;
97 *tx_frame_type = TX_SPEECH_GOOD;
98 }
99 st->prev_ft = *tx_frame_type;
100 }