Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / include / gc_pred.h
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30
31  Filename: gc_pred.h
32
33 ------------------------------------------------------------------------------
34  INCLUDE DESCRIPTION
35
36       File             : gc_pred.h
37       Purpose          : codebook gain MA prediction
38
39 ------------------------------------------------------------------------------
40 */
41
42 #ifndef _GC_PRED_H_
43 #define _GC_PRED_H_
44 #define gc_pred_h "$Id $"
45
46 /*----------------------------------------------------------------------------
47 ; INCLUDES
48 ----------------------------------------------------------------------------*/
49 #include "typedef.h"
50 #include "mode.h"
51
52
53 /*--------------------------------------------------------------------------*/
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58
59     /*----------------------------------------------------------------------------
60     ; MACROS
61     ; [Define module specific macros here]
62     ----------------------------------------------------------------------------*/
63
64     /*----------------------------------------------------------------------------
65     ; DEFINES
66     ; [Include all pre-processor statements here.]
67     ----------------------------------------------------------------------------*/
68
69     /*----------------------------------------------------------------------------
70     ; EXTERNAL VARIABLES REFERENCES
71     ; [Declare variables used in this module but defined elsewhere]
72     ----------------------------------------------------------------------------*/
73
74     /*----------------------------------------------------------------------------
75     ; SIMPLE TYPEDEF'S
76     ----------------------------------------------------------------------------*/
77
78     /*----------------------------------------------------------------------------
79     ; ENUMERATED TYPEDEF'S
80     ----------------------------------------------------------------------------*/
81
82     /*----------------------------------------------------------------------------
83     ; STRUCTURES TYPEDEF'S
84     ----------------------------------------------------------------------------*/
85     typedef struct
86     {
87         Word16 past_qua_en[4];         /* normal MA predictor memory,         Q10 */
88         /* (contains 20*log10(qua_err))            */
89         Word16 past_qua_en_MR122[4];   /* MA predictor memory for MR122 mode, Q10 */
90         /* (contains log2(qua_err))                */
91     } gc_predState;
92
93     /*----------------------------------------------------------------------------
94     ; GLOBAL FUNCTION DEFINITIONS
95     ; [List function prototypes here]
96     ----------------------------------------------------------------------------*/
97
98     OSCL_IMPORT_REF Word16 gc_pred_reset(gc_predState *st);
99     /* reset of codebook gain MA predictor state (i.e. set state memory to zero)
100        returns 0 on success
101      */
102     void gc_pred_exit(gc_predState **st);
103     /* de-initialize codebook gain MA predictor state (i.e. free state struct)
104        stores NULL in *st
105      */
106
107     void
108     gc_pred_copy(
109         gc_predState *st_src,  /* i : State struct                           */
110         gc_predState *st_dest  /* o : State struct                           */
111     );
112
113     /*
114      * FUNCTION:  gc_pred()
115      * PURPOSE: MA prediction of the innovation energy
116      *          (in dB/(20*log10(2))) with mean  removed).
117      */
118     OSCL_IMPORT_REF void gc_pred(
119         gc_predState *st,   /* i/o: State struct                           */
120         enum Mode mode,     /* i  : AMR mode                               */
121         Word16 *code,       /* i  : innovative codebook vector (L_SUBFR)   */
122         /*      MR122: Q12, other modes: Q13           */
123         Word16 *exp_gcode0, /* o  : exponent of predicted gain factor, Q0  */
124         Word16 *frac_gcode0,/* o  : fraction of predicted gain factor  Q15 */
125         Word16 *exp_en,     /* o  : exponent of innovation energy,     Q0  */
126         /*      (only calculated for MR795)            */
127         Word16 *frac_en,    /* o  : fraction of innovation energy,     Q15 */
128         /*      (only calculated for MR795)            */
129         Flag   *pOverflow
130     );
131
132     /*
133      * FUNCTION:  gc_pred_update()
134      * PURPOSE: update MA predictor with last quantized energy
135      */
136     OSCL_IMPORT_REF void gc_pred_update(
137         gc_predState *st,      /* i/o: State struct                     */
138         Word16 qua_ener_MR122, /* i  : quantized energy for update, Q10 */
139         /*      (log2(qua_err))                  */
140         Word16 qua_ener        /* i  : quantized energy for update, Q10 */
141         /*      (20*log10(qua_err))              */
142     );
143
144     /*
145      * FUNCTION:  gc_pred_average_limited()
146      * PURPOSE: get average of MA predictor state values (with a lower limit)
147      *          [used in error concealment]
148      */
149     OSCL_IMPORT_REF void gc_pred_average_limited(
150         gc_predState *st,       /* i: State struct                    */
151         Word16 *ener_avg_MR122, /* o: averaged quantized energy,  Q10 */
152         /*    (log2(qua_err))                 */
153         Word16 *ener_avg,       /* o: averaged quantized energy,  Q10 */
154         /*    (20*log10(qua_err))             */
155         Flag   *pOverflow
156     );
157
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif  /* _GC_PRED_H_ */
164
165
166