OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 | |
12 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_ | |
13 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_ | |
14 | |
15 #include <stddef.h> | |
16 #include "webrtc/typedefs.h" | |
17 | |
18 #ifdef __cplusplus | |
19 extern "C" { | |
20 #endif | |
21 | |
22 #define WEBRTC_CNG_MAX_LPC_ORDER 12 | |
23 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640 | |
24 | |
25 /* Define Error codes. */ | |
26 | |
27 /* 6100 Encoder */ | |
28 #define CNG_ENCODER_NOT_INITIATED 6120 | |
29 #define CNG_DISALLOWED_LPC_ORDER 6130 | |
30 #define CNG_DISALLOWED_FRAME_SIZE 6140 | |
31 #define CNG_DISALLOWED_SAMPLING_FREQUENCY 6150 | |
32 /* 6200 Decoder */ | |
33 #define CNG_DECODER_NOT_INITIATED 6220 | |
34 | |
35 typedef struct WebRtcCngEncInst CNG_enc_inst; | |
36 typedef struct WebRtcCngDecInst CNG_dec_inst; | |
37 | |
38 /**************************************************************************** | |
39 * WebRtcCng_CreateEnc/Dec(...) | |
40 * | |
41 * These functions create an instance to the specified structure | |
42 * | |
43 * Input: | |
44 * - XXX_inst : Pointer to created instance that should be created | |
45 * | |
46 * Return value : 0 - Ok | |
47 * -1 - Error | |
48 */ | |
49 int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst); | |
50 int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst); | |
51 | |
52 /**************************************************************************** | |
53 * WebRtcCng_InitEnc/Dec(...) | |
54 * | |
55 * This function initializes a instance | |
56 * | |
57 * Input: | |
58 * - cng_inst : Instance that should be initialized | |
59 * | |
60 * - fs : 8000 for narrowband and 16000 for wideband | |
61 * - interval : generate SID data every interval ms | |
62 * - quality : Number of refl. coefs, maximum allowed is 12 | |
63 * | |
64 * Output: | |
65 * - cng_inst : Initialized instance | |
66 * | |
67 * Return value : 0 - Ok | |
68 * -1 - Error | |
69 */ | |
70 | |
71 int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, | |
72 int16_t quality); | |
73 void WebRtcCng_InitDec(CNG_dec_inst* cng_inst); | |
74 | |
75 /**************************************************************************** | |
76 * WebRtcCng_FreeEnc/Dec(...) | |
77 * | |
78 * These functions frees the dynamic memory of a specified instance | |
79 * | |
80 * Input: | |
81 * - cng_inst : Pointer to created instance that should be freed | |
82 * | |
83 * Return value : 0 - Ok | |
84 * -1 - Error | |
85 */ | |
86 int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst); | |
87 int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst); | |
88 | |
89 /**************************************************************************** | |
90 * WebRtcCng_Encode(...) | |
91 * | |
92 * These functions analyzes background noise | |
93 * | |
94 * Input: | |
95 * - cng_inst : Pointer to created instance | |
96 * - speech : Signal to be analyzed | |
97 * - nrOfSamples : Size of speech vector | |
98 * - forceSID : not zero to force SID frame and reset | |
99 * | |
100 * Output: | |
101 * - bytesOut : Nr of bytes to transmit, might be 0 | |
102 * | |
103 * Return value : 0 - Ok | |
104 * -1 - Error | |
105 */ | |
106 int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | |
107 size_t nrOfSamples, uint8_t* SIDdata, | |
108 size_t* bytesOut, int16_t forceSID); | |
109 | |
110 /**************************************************************************** | |
111 * WebRtcCng_UpdateSid(...) | |
112 * | |
113 * These functions updates the CN state, when a new SID packet arrives | |
114 * | |
115 * Input: | |
116 * - cng_inst : Pointer to created instance that should be freed | |
117 * - SID : SID packet, all headers removed | |
118 * - length : Length in bytes of SID packet | |
119 * | |
120 * Return value : 0 - Ok | |
121 * -1 - Error | |
122 */ | |
123 int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID, | |
124 size_t length); | |
125 | |
126 /**************************************************************************** | |
127 * WebRtcCng_Generate(...) | |
128 * | |
129 * These functions generates CN data when needed | |
130 * | |
131 * Input: | |
132 * - cng_inst : Pointer to created instance that should be freed | |
133 * - outData : pointer to area to write CN data | |
134 * - nrOfSamples : How much data to generate | |
135 * - new_period : >0 if a new period of CNG, will reset history | |
136 * | |
137 * Return value : 0 - Ok | |
138 * -1 - Error | |
139 */ | |
140 int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData, | |
141 size_t nrOfSamples, int16_t new_period); | |
142 | |
143 /***************************************************************************** | |
144 * WebRtcCng_GetErrorCodeEnc/Dec(...) | |
145 * | |
146 * This functions can be used to check the error code of a CNG instance. When | |
147 * a function returns -1 a error code will be set for that instance. The | |
148 * function below extract the code of the last error that occurred in the | |
149 * specified instance. | |
150 * | |
151 * Input: | |
152 * - CNG_inst : CNG enc/dec instance | |
153 * | |
154 * Return value : Error code | |
155 */ | |
156 int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst); | |
157 int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst); | |
158 | |
159 #ifdef __cplusplus | |
160 } | |
161 #endif | |
162 | |
163 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_ | |
OLD | NEW |