OLD | NEW |
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 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" | 11 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <string.h> | 15 #include <string.h> |
16 | 16 |
17 #include "webrtc/modules/audio_processing/utility/delay_estimator.h" | 17 #include "webrtc/modules/audio_processing/utility/delay_estimator.h" |
18 #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h" | 18 #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h" |
19 #include "webrtc/system_wrappers/include/compile_assert_c.h" | |
20 | 19 |
21 // Only bit |kBandFirst| through bit |kBandLast| are processed and | 20 // Only bit |kBandFirst| through bit |kBandLast| are processed and |
22 // |kBandFirst| - |kBandLast| must be < 32. | 21 // |kBandFirst| - |kBandLast| must be < 32. |
23 enum { kBandFirst = 12 }; | 22 enum { kBandFirst = 12 }; |
24 enum { kBandLast = 43 }; | 23 enum { kBandLast = 43 }; |
25 | 24 |
26 static __inline uint32_t SetBit(uint32_t in, int pos) { | 25 static __inline uint32_t SetBit(uint32_t in, int pos) { |
27 uint32_t mask = (1 << pos); | 26 uint32_t mask = (1 << pos); |
28 uint32_t out = (in | mask); | 27 uint32_t out = (in | mask); |
29 | 28 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 self->binary_farend = NULL; | 136 self->binary_farend = NULL; |
138 | 137 |
139 free(self); | 138 free(self); |
140 } | 139 } |
141 | 140 |
142 void* WebRtc_CreateDelayEstimatorFarend(int spectrum_size, int history_size) { | 141 void* WebRtc_CreateDelayEstimatorFarend(int spectrum_size, int history_size) { |
143 DelayEstimatorFarend* self = NULL; | 142 DelayEstimatorFarend* self = NULL; |
144 | 143 |
145 // Check if the sub band used in the delay estimation is small enough to fit | 144 // Check if the sub band used in the delay estimation is small enough to fit |
146 // the binary spectra in a uint32_t. | 145 // the binary spectra in a uint32_t. |
147 COMPILE_ASSERT(kBandLast - kBandFirst < 32); | 146 static_assert(kBandLast - kBandFirst < 32, ""); |
148 | 147 |
149 if (spectrum_size >= kBandLast) { | 148 if (spectrum_size >= kBandLast) { |
150 self = malloc(sizeof(DelayEstimatorFarend)); | 149 self = static_cast<DelayEstimatorFarend*>( |
| 150 malloc(sizeof(DelayEstimatorFarend))); |
151 } | 151 } |
152 | 152 |
153 if (self != NULL) { | 153 if (self != NULL) { |
154 int memory_fail = 0; | 154 int memory_fail = 0; |
155 | 155 |
156 // Allocate memory for the binary far-end spectrum handling. | 156 // Allocate memory for the binary far-end spectrum handling. |
157 self->binary_farend = WebRtc_CreateBinaryDelayEstimatorFarend(history_size); | 157 self->binary_farend = WebRtc_CreateBinaryDelayEstimatorFarend(history_size); |
158 memory_fail |= (self->binary_farend == NULL); | 158 memory_fail |= (self->binary_farend == NULL); |
159 | 159 |
160 // Allocate memory for spectrum buffers. | 160 // Allocate memory for spectrum buffers. |
161 self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType)); | 161 self->mean_far_spectrum = |
| 162 static_cast<SpectrumType*>(malloc(spectrum_size * sizeof(SpectrumType)))
; |
162 memory_fail |= (self->mean_far_spectrum == NULL); | 163 memory_fail |= (self->mean_far_spectrum == NULL); |
163 | 164 |
164 self->spectrum_size = spectrum_size; | 165 self->spectrum_size = spectrum_size; |
165 | 166 |
166 if (memory_fail) { | 167 if (memory_fail) { |
167 WebRtc_FreeDelayEstimatorFarend(self); | 168 WebRtc_FreeDelayEstimatorFarend(self); |
168 self = NULL; | 169 self = NULL; |
169 } | 170 } |
170 } | 171 } |
171 | 172 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 self->binary_handle = NULL; | 269 self->binary_handle = NULL; |
269 | 270 |
270 free(self); | 271 free(self); |
271 } | 272 } |
272 | 273 |
273 void* WebRtc_CreateDelayEstimator(void* farend_handle, int max_lookahead) { | 274 void* WebRtc_CreateDelayEstimator(void* farend_handle, int max_lookahead) { |
274 DelayEstimator* self = NULL; | 275 DelayEstimator* self = NULL; |
275 DelayEstimatorFarend* farend = (DelayEstimatorFarend*) farend_handle; | 276 DelayEstimatorFarend* farend = (DelayEstimatorFarend*) farend_handle; |
276 | 277 |
277 if (farend_handle != NULL) { | 278 if (farend_handle != NULL) { |
278 self = malloc(sizeof(DelayEstimator)); | 279 self = static_cast<DelayEstimator*>(malloc(sizeof(DelayEstimator))); |
279 } | 280 } |
280 | 281 |
281 if (self != NULL) { | 282 if (self != NULL) { |
282 int memory_fail = 0; | 283 int memory_fail = 0; |
283 | 284 |
284 // Allocate memory for the farend spectrum handling. | 285 // Allocate memory for the farend spectrum handling. |
285 self->binary_handle = | 286 self->binary_handle = |
286 WebRtc_CreateBinaryDelayEstimator(farend->binary_farend, max_lookahead); | 287 WebRtc_CreateBinaryDelayEstimator(farend->binary_farend, max_lookahead); |
287 memory_fail |= (self->binary_handle == NULL); | 288 memory_fail |= (self->binary_handle == NULL); |
288 | 289 |
289 // Allocate memory for spectrum buffers. | 290 // Allocate memory for spectrum buffers. |
290 self->mean_near_spectrum = malloc(farend->spectrum_size * | 291 self->mean_near_spectrum = static_cast<SpectrumType*>( |
291 sizeof(SpectrumType)); | 292 malloc(farend->spectrum_size * sizeof(SpectrumType))); |
292 memory_fail |= (self->mean_near_spectrum == NULL); | 293 memory_fail |= (self->mean_near_spectrum == NULL); |
293 | 294 |
294 self->spectrum_size = farend->spectrum_size; | 295 self->spectrum_size = farend->spectrum_size; |
295 | 296 |
296 if (memory_fail) { | 297 if (memory_fail) { |
297 WebRtc_FreeDelayEstimator(self); | 298 WebRtc_FreeDelayEstimator(self); |
298 self = NULL; | 299 self = NULL; |
299 } | 300 } |
300 } | 301 } |
301 | 302 |
(...skipping 19 matching lines...) Expand all Loading... |
321 return 0; | 322 return 0; |
322 } | 323 } |
323 | 324 |
324 int WebRtc_SoftResetDelayEstimator(void* handle, int delay_shift) { | 325 int WebRtc_SoftResetDelayEstimator(void* handle, int delay_shift) { |
325 DelayEstimator* self = (DelayEstimator*) handle; | 326 DelayEstimator* self = (DelayEstimator*) handle; |
326 assert(self != NULL); | 327 assert(self != NULL); |
327 return WebRtc_SoftResetBinaryDelayEstimator(self->binary_handle, delay_shift); | 328 return WebRtc_SoftResetBinaryDelayEstimator(self->binary_handle, delay_shift); |
328 } | 329 } |
329 | 330 |
330 int WebRtc_set_history_size(void* handle, int history_size) { | 331 int WebRtc_set_history_size(void* handle, int history_size) { |
331 DelayEstimator* self = handle; | 332 DelayEstimator* self = static_cast<DelayEstimator*>(handle); |
332 | 333 |
333 if ((self == NULL) || (history_size <= 1)) { | 334 if ((self == NULL) || (history_size <= 1)) { |
334 return -1; | 335 return -1; |
335 } | 336 } |
336 return WebRtc_AllocateHistoryBufferMemory(self->binary_handle, history_size); | 337 return WebRtc_AllocateHistoryBufferMemory(self->binary_handle, history_size); |
337 } | 338 } |
338 | 339 |
339 int WebRtc_history_size(const void* handle) { | 340 int WebRtc_history_size(const void* handle) { |
340 const DelayEstimator* self = handle; | 341 const DelayEstimator* self = static_cast<const DelayEstimator*>(handle); |
341 | 342 |
342 if (self == NULL) { | 343 if (self == NULL) { |
343 return -1; | 344 return -1; |
344 } | 345 } |
345 if (self->binary_handle->farend->history_size != | 346 if (self->binary_handle->farend->history_size != |
346 self->binary_handle->history_size) { | 347 self->binary_handle->history_size) { |
347 // Non matching history sizes. | 348 // Non matching history sizes. |
348 return -1; | 349 return -1; |
349 } | 350 } |
350 return self->binary_handle->history_size; | 351 return self->binary_handle->history_size; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 477 } |
477 | 478 |
478 return WebRtc_binary_last_delay(self->binary_handle); | 479 return WebRtc_binary_last_delay(self->binary_handle); |
479 } | 480 } |
480 | 481 |
481 float WebRtc_last_delay_quality(void* handle) { | 482 float WebRtc_last_delay_quality(void* handle) { |
482 DelayEstimator* self = (DelayEstimator*) handle; | 483 DelayEstimator* self = (DelayEstimator*) handle; |
483 assert(self != NULL); | 484 assert(self != NULL); |
484 return WebRtc_binary_last_delay_quality(self->binary_handle); | 485 return WebRtc_binary_last_delay_quality(self->binary_handle); |
485 } | 486 } |
OLD | NEW |