Chromium Code Reviews

Side by Side Diff: webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h

Issue 1868143002: Convert CNG into C++ and remove it from AudioDecoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed issues from comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 11
12 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_ 12 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
13 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_ 13 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
14 14
15 #include <stddef.h> 15 #include <cstddef>
16
17 #include "webrtc/base/array_view.h"
18 #include "webrtc/base/buffer.h"
16 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
17 20
18 #ifdef __cplusplus 21 #define WEBRTC_CNG_MAX_LPC_ORDER 12
ossu 2016/04/14 08:56:30 Since this is shared (and used to size the arrays
kwiberg-webrtc 2016/04/14 09:42:48 I don't have a suggestion that I would be happy wi
hlundin-webrtc 2016/04/14 15:20:51 Leave it.
19 extern "C" {
20 #endif
21 22
22 #define WEBRTC_CNG_MAX_LPC_ORDER 12 23 namespace webrtc {
23 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640
24 24
25 /* Define Error codes. */ 25 class ComfortNoiseDecoder {
26 public:
27 ComfortNoiseDecoder();
28 ~ComfortNoiseDecoder() = default;
26 29
27 /* 6100 Encoder */ 30 ComfortNoiseDecoder(const ComfortNoiseDecoder&) = delete;
28 #define CNG_ENCODER_NOT_INITIATED 6120 31 ComfortNoiseDecoder& operator=(const ComfortNoiseDecoder&) = delete;
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 32
35 typedef struct WebRtcCngEncInst CNG_enc_inst; 33 void Reset();
36 typedef struct WebRtcCngDecInst CNG_dec_inst;
37 34
38 /**************************************************************************** 35 // Updates the CN state when a new SID packet arrives.
39 * WebRtcCng_CreateEnc/Dec(...) 36 // |sid| is a view of the SID packet without the headers.
40 * 37 void UpdateSid(rtc::ArrayView<const uint8_t> sid);
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 38
52 /**************************************************************************** 39 // Generates comfort noise.
53 * WebRtcCng_InitEnc/Dec(...) 40 // |out_data| will be filled with samples - its size determines the number of
54 * 41 // samples generated. When |new_period| is true, CNG history will be reset
55 * This function initializes a instance 42 // before any audio is generated. Returns |false| if outData is too large.
kwiberg-webrtc 2016/04/14 09:42:48 As you said, you no longer tell callers what "too
ossu 2016/04/15 11:56:10 So I expect this to be 10ms of samples. Right now,
56 * 43 bool Generate(rtc::ArrayView<int16_t> out_data, bool new_period);
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 44
71 int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, 45 private:
72 int16_t quality); 46 uint32_t dec_seed_;
73 void WebRtcCng_InitDec(CNG_dec_inst* cng_inst); 47 int32_t dec_target_energy_;
48 int32_t dec_used_energy_;
49 int16_t dec_target_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
50 int16_t dec_used_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
51 int16_t dec_filtstate_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
52 int16_t dec_filtstateLow_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
53 uint16_t dec_order_;
54 int16_t dec_target_scale_factor_; /* Q29 */
55 int16_t dec_used_scale_factor_; /* Q29 */
56 };
74 57
75 /**************************************************************************** 58 class ComfortNoiseEncoder {
76 * WebRtcCng_FreeEnc/Dec(...) 59 public:
77 * 60 // Creates a comfort noise encoder.
78 * These functions frees the dynamic memory of a specified instance 61 // |fs| selects sample rate: 8000 for narrowband or 16000 for wideband.
79 * 62 // |interval| sets the interval at which to generate SID data (in ms).
80 * Input: 63 // |quality| selects the number of refl. coeffs. Maximum allowed is 12.
81 * - cng_inst : Pointer to created instance that should be freed 64 ComfortNoiseEncoder(int fs, int interval, int quality);
82 * 65 ~ComfortNoiseEncoder() = default;
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 66
89 /**************************************************************************** 67 ComfortNoiseEncoder(const ComfortNoiseEncoder&) = delete;
90 * WebRtcCng_Encode(...) 68 ComfortNoiseEncoder& operator=(const ComfortNoiseEncoder&) = delete;
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 69
110 /**************************************************************************** 70 // Resets the comfort noise encoder to its initial state.
111 * WebRtcCng_UpdateSid(...) 71 // Parameters are set as during construction.
112 * 72 void Reset(int fs, int interval, int quality);
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 73
126 /**************************************************************************** 74 // Analyzes background noise from |speech| and puts coefficients in |output|.
kwiberg-webrtc 2016/04/14 09:42:48 appends coefficients to
ossu 2016/04/15 11:56:10 Good point!
127 * WebRtcCng_Generate(...) 75 // Returns the number of coefficients generated.
128 * 76 // If |force_sid| is true, a SID frame is forced and the internal sid interval
129 * These functions generates CN data when needed 77 // counter is reset.
130 * 78 size_t Encode(rtc::ArrayView<const int16_t> speech,
131 * Input: 79 bool force_sid,
132 * - cng_inst : Pointer to created instance that should be freed 80 rtc::Buffer* output);
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 81
143 /***************************************************************************** 82 private:
144 * WebRtcCng_GetErrorCodeEnc/Dec(...) 83 size_t enc_nrOfCoefs_;
145 * 84 int enc_sampfreq_;
146 * This functions can be used to check the error code of a CNG instance. When 85 int16_t enc_interval_;
147 * a function returns -1 a error code will be set for that instance. The 86 int16_t enc_msSinceSid_;
148 * function below extract the code of the last error that occurred in the 87 int32_t enc_Energy_;
149 * specified instance. 88 int16_t enc_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
150 * 89 int32_t enc_corrVector_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
151 * Input: 90 uint32_t enc_seed_;
152 * - CNG_inst : CNG enc/dec instance 91 };
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 92
159 #ifdef __cplusplus 93 } // namespace webrtc
160 }
161 #endif
162 94
163 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_ 95 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
OLDNEW

Powered by Google App Engine