Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

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: Converted WebRtcCng to C++ Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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"
16 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
17 19
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define WEBRTC_CNG_MAX_LPC_ORDER 12 20 #define WEBRTC_CNG_MAX_LPC_ORDER 12
23 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640 21 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640
hlundin-webrtc 2016/04/13 07:05:24 This is only used inside the class, right? Make it
ossu 2016/04/13 11:57:07 It is used inside both, to check that the data inp
24 22
25 /* Define Error codes. */ 23 namespace webrtc {
26 24
27 /* 6100 Encoder */ 25 class ComfortNoiseDecoder {
28 #define CNG_ENCODER_NOT_INITIATED 6120 26 public:
29 #define CNG_DISALLOWED_LPC_ORDER 6130 27 ComfortNoiseDecoder();
30 #define CNG_DISALLOWED_FRAME_SIZE 6140 28 ~ComfortNoiseDecoder() = default;
31 #define CNG_DISALLOWED_SAMPLING_FREQUENCY 6150
32 /* 6200 Decoder */
33 #define CNG_DECODER_NOT_INITIATED 6220
34 29
35 typedef struct WebRtcCngEncInst CNG_enc_inst; 30 ComfortNoiseDecoder(const ComfortNoiseDecoder&) = delete;
36 typedef struct WebRtcCngDecInst CNG_dec_inst; 31 ComfortNoiseDecoder& operator=(const ComfortNoiseDecoder&) = delete;
kwiberg-webrtc 2016/04/12 13:35:31 We have a macro for this in constructormagic.h: RT
ossu 2016/04/12 13:54:49 There's been conversations on c-style, where using
hlundin-webrtc 2016/04/13 07:05:24 Don't leave them as copyable. Use either way to ba
ossu 2016/04/13 11:57:07 Alright, no copying!
37 32
38 /**************************************************************************** 33 void Reset();
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 34
52 /**************************************************************************** 35 /* Update the CN state when a new SID packet arrives.
hlundin-webrtc 2016/04/13 07:05:24 Updates... Also, I think you should make these blo
ossu 2016/04/13 11:57:07 Acknowledged.
53 * WebRtcCng_InitEnc/Dec(...) 36 * |SID| is a view of the SID packet without the headers.
54 * 37 */
55 * This function initializes a instance 38 void UpdateSid(rtc::ArrayView<const uint8_t> SID);
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 39
71 int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, 40 /* Generate comfort noise.
hlundin-webrtc 2016/04/13 07:05:23 Generates...
ossu 2016/04/13 11:57:06 Acknowledged.
72 int16_t quality); 41 * |outData| will be filled with samples - its size determines the number of
hlundin-webrtc 2016/04/13 07:05:24 out_data
ossu 2016/04/13 11:57:06 Acknowledged.
73 void WebRtcCng_InitDec(CNG_dec_inst* cng_inst); 42 * samples generated. When |new_period| is true, CNG history will be reset
43 * before any audio is generated. Returns |false| if outData is too large
44 * (larger than WEBRTC_CNG_MAX_OUTSIZE_ORDER).
45 */
46 bool Generate(rtc::ArrayView<int16_t> outData, bool new_period);
hlundin-webrtc 2016/04/13 07:05:24 Change order of parameters. Input params go before
hlundin-webrtc 2016/04/13 07:05:24 out_data
ossu 2016/04/13 11:57:07 Acknowledged.
74 47
75 /**************************************************************************** 48 private:
76 * WebRtcCng_FreeEnc/Dec(...) 49 uint32_t dec_seed_;
77 * 50 int32_t dec_target_energy_;
78 * These functions frees the dynamic memory of a specified instance 51 int32_t dec_used_energy_;
79 * 52 int16_t dec_target_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
80 * Input: 53 int16_t dec_used_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
81 * - cng_inst : Pointer to created instance that should be freed 54 int16_t dec_filtstate_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
82 * 55 int16_t dec_filtstateLow_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
83 * Return value : 0 - Ok 56 uint16_t dec_order_;
84 * -1 - Error 57 int16_t dec_target_scale_factor_; /* Q29 */
85 */ 58 int16_t dec_used_scale_factor_; /* Q29 */
86 int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst); 59 };
87 int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst);
88 60
89 /**************************************************************************** 61 class ComfortNoiseEncoder {
90 * WebRtcCng_Encode(...) 62 public:
91 * 63 // Create a comfort noise encoder.
hlundin-webrtc 2016/04/13 07:05:24 Creates...
ossu 2016/04/13 11:57:07 Acknowledged.
92 * These functions analyzes background noise 64 // |fs| selects sample rate: 8000 for narrowband and 16000 for wideband
hlundin-webrtc 2016/04/13 07:05:24 End all sentences with .
ossu 2016/04/13 11:57:06 Acknowledged.
93 * 65 // |interval| sets the interval at which to generate SID data (in ms)
94 * Input: 66 // |quality| selects the number of refl. coeffs. Maximum allowed is 12
95 * - cng_inst : Pointer to created instance 67 ComfortNoiseEncoder(int fs, int interval, int quality);
96 * - speech : Signal to be analyzed 68 ~ComfortNoiseEncoder() = default;
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 ComfortNoiseEncoder(const ComfortNoiseEncoder&) = delete;
111 * WebRtcCng_UpdateSid(...) 71 ComfortNoiseEncoder& operator=(const ComfortNoiseEncoder&) = delete;
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 72
126 /**************************************************************************** 73 // Reset the comfort noise encoder to its initial state.
hlundin-webrtc 2016/04/13 07:05:23 Resets...
ossu 2016/04/13 11:57:06 Acknowledged.
127 * WebRtcCng_Generate(...) 74 // Parameters are set as during construction.
128 * 75 void Reset(int fs, int interval, int quality);
kwiberg-webrtc 2016/04/12 13:35:31 Is this necessary? Can't the callers just make a n
ossu 2016/04/12 13:54:49 There was some code that used InitEnc before, so I
kwiberg-webrtc 2016/04/14 09:42:48 Yes please.
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 76
143 /***************************************************************************** 77 // Analyze background noise from |speech| and put coefficients in |output|.
hlundin-webrtc 2016/04/13 07:05:23 puts...
hlundin-webrtc 2016/04/13 07:05:23 Analyzes...
144 * WebRtcCng_GetErrorCodeEnc/Dec(...) 78 // Returns the number of coefficients generated, or -1 if too much input is
145 * 79 // provided. If |forceSID| is true, a SID frame is forced and the encoder
hlundin-webrtc 2016/04/13 07:05:24 force_sid
146 * This functions can be used to check the error code of a CNG instance. When 80 // reset.
147 * a function returns -1 a error code will be set for that instance. The 81 // TODO(ossu): Clarify this behavior. Does it reset before or after encoding?
hlundin-webrtc 2016/04/13 07:05:24 I don't think it should reset all of the encoder s
148 * function below extract the code of the last error that occurred in the 82 // TODO(ossu): Should it fail if given too much input? Can't it just ignore
149 * specified instance. 83 // the rest?
hlundin-webrtc 2016/04/13 07:05:24 Or maybe just DCHECK?
ossu 2016/04/13 11:57:06 DCHECK works. Is the right size always 640 or does
150 * 84 int Encode(rtc::ArrayView<const int16_t> speech,
151 * Input: 85 rtc::ArrayView<uint8_t> output,
152 * - CNG_inst : CNG enc/dec instance 86 bool forceSID);
kwiberg-webrtc 2016/04/12 13:35:31 Consider outputting to an rtc::Buffer* instead, so
ossu 2016/04/12 13:54:49 Acknowledged.
hlundin-webrtc 2016/04/13 07:05:24 force_sid
ossu 2016/04/13 11:57:07 Acknowledged. Also, I guess force_sid should go be
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 87
159 #ifdef __cplusplus 88 private:
160 } 89 size_t enc_nrOfCoefs_;
161 #endif 90 int enc_sampfreq_;
91 int16_t enc_interval_;
92 int16_t enc_msSinceSID_;
93 int32_t enc_Energy_;
94 int16_t enc_reflCoefs_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
95 int32_t enc_corrVector_[WEBRTC_CNG_MAX_LPC_ORDER + 1];
96 uint32_t enc_seed_;
97 };
98
99 } // namespace webrtc
162 100
163 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_ 101 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698