Skip to content

Commit cbc7feb

Browse files
committed
updated webrtc
1 parent f369cdf commit cbc7feb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2336
-1003
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ python:
44
- "3.3"
55
- "3.4"
66
- "3.5"
7+
- "3.6"
8+
- "3.7"
79
# command to install dependencies
810
install: "pip install -e .[dev]"
911
# command to run tests

cbits/pywebrtcvad.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ static void vad_free(PyObject* vadptr)
1717

1818
static PyObject* vad_create(PyObject *self, PyObject *args)
1919
{
20-
VadInst *handle;
21-
PyObject *vadptr;
22-
if (WebRtcVad_Create(&handle)) {
23-
return NULL;
24-
}
25-
vadptr = PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
20+
VadInst *handle = WebRtcVad_Create();
21+
PyObject *vadptr = PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
2622
return Py_BuildValue("O", vadptr);
2723
}
2824

cbits/webrtc/common_audio/signal_processing/complex_fft.c

+13-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "webrtc/common_audio/signal_processing/complex_fft_tables.h"
1919
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
20+
#include "webrtc/rtc_base/system/arch.h"
2021

2122
#define CFFTSFT 14
2223
#define CFFTRND 1
@@ -126,18 +127,16 @@ int WebRtcSpl_ComplexFFT(int16_t frfi[], int stages, int mode)
126127
[wri]"r"(wri),
127128
[cfftrnd]"r"(CFFTRND));
128129
#else
129-
tr32 = WEBRTC_SPL_MUL_16_16(wr, frfi[2 * j])
130-
- WEBRTC_SPL_MUL_16_16(wi, frfi[2 * j + 1]) + CFFTRND;
130+
tr32 = wr * frfi[2 * j] - wi * frfi[2 * j + 1] + CFFTRND;
131131

132-
ti32 = WEBRTC_SPL_MUL_16_16(wr, frfi[2 * j + 1])
133-
+ WEBRTC_SPL_MUL_16_16(wi, frfi[2 * j]) + CFFTRND;
132+
ti32 = wr * frfi[2 * j + 1] + wi * frfi[2 * j] + CFFTRND;
134133
#endif
135134

136135
tr32 >>= 15 - CFFTSFT;
137136
ti32 >>= 15 - CFFTSFT;
138137

139-
qr32 = ((int32_t)frfi[2 * i]) << CFFTSFT;
140-
qi32 = ((int32_t)frfi[2 * i + 1]) << CFFTSFT;
138+
qr32 = ((int32_t)frfi[2 * i]) * (1 << CFFTSFT);
139+
qi32 = ((int32_t)frfi[2 * i + 1]) * (1 << CFFTSFT);
141140

142141
frfi[2 * j] = (int16_t)(
143142
(qr32 - tr32 + CFFTRND2) >> (1 + CFFTSFT));
@@ -159,15 +158,16 @@ int WebRtcSpl_ComplexFFT(int16_t frfi[], int stages, int mode)
159158

160159
int WebRtcSpl_ComplexIFFT(int16_t frfi[], int stages, int mode)
161160
{
162-
int i, j, l, k, istep, n, m, scale, shift;
161+
size_t i, j, l, istep, n, m;
162+
int k, scale, shift;
163163
int16_t wr, wi;
164164
int32_t tr32, ti32, qr32, qi32;
165165
int32_t tmp32, round2;
166166

167167
/* The 1024-value is a constant given from the size of kSinTable1024[],
168168
* and should not be changed depending on the input parameter 'stages'
169169
*/
170-
n = 1 << stages;
170+
n = ((size_t)1) << stages;
171171
if (n > 1024)
172172
return -1;
173173

@@ -183,7 +183,7 @@ int WebRtcSpl_ComplexIFFT(int16_t frfi[], int stages, int mode)
183183
shift = 0;
184184
round2 = 8192;
185185

186-
tmp32 = (int32_t)WebRtcSpl_MaxAbsValueW16(frfi, 2 * n);
186+
tmp32 = WebRtcSpl_MaxAbsValueW16(frfi, 2 * n);
187187
if (tmp32 > 13573)
188188
{
189189
shift++;
@@ -270,17 +270,15 @@ int WebRtcSpl_ComplexIFFT(int16_t frfi[], int stages, int mode)
270270
);
271271
#else
272272

273-
tr32 = WEBRTC_SPL_MUL_16_16(wr, frfi[2 * j])
274-
- WEBRTC_SPL_MUL_16_16(wi, frfi[2 * j + 1]) + CIFFTRND;
273+
tr32 = wr * frfi[2 * j] - wi * frfi[2 * j + 1] + CIFFTRND;
275274

276-
ti32 = WEBRTC_SPL_MUL_16_16(wr, frfi[2 * j + 1])
277-
+ WEBRTC_SPL_MUL_16_16(wi, frfi[2 * j]) + CIFFTRND;
275+
ti32 = wr * frfi[2 * j + 1] + wi * frfi[2 * j] + CIFFTRND;
278276
#endif
279277
tr32 >>= 15 - CIFFTSFT;
280278
ti32 >>= 15 - CIFFTSFT;
281279

282-
qr32 = ((int32_t)frfi[2 * i]) << CIFFTSFT;
283-
qi32 = ((int32_t)frfi[2 * i + 1]) << CIFFTSFT;
280+
qr32 = ((int32_t)frfi[2 * i]) * (1 << CIFFTSFT);
281+
qi32 = ((int32_t)frfi[2 * i + 1]) * (1 << CIFFTSFT);
284282

285283
frfi[2 * j] = (int16_t)(
286284
(qr32 - tr32 + round2) >> (shift + CIFFTSFT));

cbits/webrtc/common_audio/signal_processing/complex_fft_tables.h

+118-134
Large diffs are not rendered by default.

cbits/webrtc/common_audio/signal_processing/cross_correlation.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
1515
const int16_t* seq1,
1616
const int16_t* seq2,
17-
int16_t dim_seq,
18-
int16_t dim_cross_correlation,
19-
int16_t right_shifts,
20-
int16_t step_seq2) {
21-
int i = 0, j = 0;
17+
size_t dim_seq,
18+
size_t dim_cross_correlation,
19+
int right_shifts,
20+
int step_seq2) {
21+
size_t i = 0, j = 0;
2222

2323
for (i = 0; i < dim_cross_correlation; i++) {
24-
*cross_correlation = 0;
25-
/* Unrolling doesn't seem to improve performance. */
26-
for (j = 0; j < dim_seq; j++) {
27-
*cross_correlation += (seq1[j] * seq2[step_seq2 * i + j]) >> right_shifts;
28-
}
29-
cross_correlation++;
24+
int32_t corr = 0;
25+
for (j = 0; j < dim_seq; j++)
26+
corr += (seq1[j] * seq2[j]) >> right_shifts;
27+
seq2 += step_seq2;
28+
*cross_correlation++ = corr;
3029
}
3130
}

cbits/webrtc/common_audio/signal_processing/division_operations.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
25+
#include "webrtc/rtc_base/sanitizer.h"
2526

2627
uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den)
2728
{
@@ -97,7 +98,8 @@ int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den)
9798
return div;
9899
}
99100

100-
int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
101+
int32_t RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486
102+
WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
101103
{
102104
int16_t approx, tmp_hi, tmp_low, num_hi, num_low;
103105
int32_t tmpW32;
@@ -106,19 +108,18 @@ int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
106108
// result in Q14 (Note: 3FFFFFFF = 0.5 in Q30)
107109

108110
// tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30)
109-
tmpW32 = (WEBRTC_SPL_MUL_16_16(den_hi, approx) << 1)
110-
+ ((WEBRTC_SPL_MUL_16_16(den_low, approx) >> 15) << 1);
111+
tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);
111112
// tmpW32 = den * approx
112113

113114
tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx))
115+
// UBSan: 2147483647 - -2 cannot be represented in type 'int'
114116

115117
// Store tmpW32 in hi and low format
116118
tmp_hi = (int16_t)(tmpW32 >> 16);
117119
tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);
118120

119121
// tmpW32 = 1/den in Q29
120-
tmpW32 = ((WEBRTC_SPL_MUL_16_16(tmp_hi, approx) + (WEBRTC_SPL_MUL_16_16(tmp_low, approx)
121-
>> 15)) << 1);
122+
tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1;
122123

123124
// 1/den in hi and low format
124125
tmp_hi = (int16_t)(tmpW32 >> 16);
@@ -130,8 +131,8 @@ int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
130131

131132
// num * (1/den) by 32 bit multiplication (result in Q28)
132133

133-
tmpW32 = (WEBRTC_SPL_MUL_16_16(num_hi, tmp_hi) + (WEBRTC_SPL_MUL_16_16(num_hi, tmp_low)
134-
>> 15) + (WEBRTC_SPL_MUL_16_16(num_low, tmp_hi) >> 15));
134+
tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) +
135+
(num_low * tmp_hi >> 15);
135136

136137
// Put result in Q31 (convert from Q28)
137138
tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#include "webrtc/common_audio/signal_processing/dot_product_with_scale.h"
12+
13+
#include "webrtc/rtc_base/numerics/safe_conversions.h"
14+
15+
int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
16+
const int16_t* vector2,
17+
size_t length,
18+
int scaling) {
19+
int64_t sum = 0;
20+
size_t i = 0;
21+
22+
/* Unroll the loop to improve performance. */
23+
for (i = 0; i + 3 < length; i += 4) {
24+
sum += (vector1[i + 0] * vector2[i + 0]) >> scaling;
25+
sum += (vector1[i + 1] * vector2[i + 1]) >> scaling;
26+
sum += (vector1[i + 2] * vector2[i + 2]) >> scaling;
27+
sum += (vector1[i + 3] * vector2[i + 3]) >> scaling;
28+
}
29+
for (; i < length; i++) {
30+
sum += (vector1[i] * vector2[i]) >> scaling;
31+
}
32+
33+
return rtc::saturated_cast<int32_t>(sum);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2017 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+
#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_
12+
#define COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_
13+
14+
#include <stdint.h>
15+
#include <string.h>
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
// Calculates the dot product between two (int16_t) vectors.
22+
//
23+
// Input:
24+
// - vector1 : Vector 1
25+
// - vector2 : Vector 2
26+
// - vector_length : Number of samples used in the dot product
27+
// - scaling : The number of right bit shifts to apply on each term
28+
// during calculation to avoid overflow, i.e., the
29+
// output will be in Q(-|scaling|)
30+
//
31+
// Return value : The dot product in Q(-scaling)
32+
int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
33+
const int16_t* vector2,
34+
size_t length,
35+
int scaling);
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif // __cplusplus
40+
#endif // COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_

cbits/webrtc/common_audio/signal_processing/downsample_fast.c

+26-9
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,45 @@
1010

1111
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
1212

13+
#include "webrtc/rtc_base/checks.h"
14+
#include "webrtc/rtc_base/sanitizer.h"
15+
1316
// TODO(Bjornv): Change the function parameter order to WebRTC code style.
1417
// C version of WebRtcSpl_DownsampleFast() for generic platforms.
1518
int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
16-
int data_in_length,
19+
size_t data_in_length,
1720
int16_t* data_out,
18-
int data_out_length,
21+
size_t data_out_length,
1922
const int16_t* __restrict coefficients,
20-
int coefficients_length,
23+
size_t coefficients_length,
2124
int factor,
22-
int delay) {
23-
int i = 0;
24-
int j = 0;
25+
size_t delay) {
26+
int16_t* const original_data_out = data_out;
27+
size_t i = 0;
28+
size_t j = 0;
2529
int32_t out_s32 = 0;
26-
int endpos = delay + factor * (data_out_length - 1) + 1;
30+
size_t endpos = delay + factor * (data_out_length - 1) + 1;
2731

2832
// Return error if any of the running conditions doesn't meet.
29-
if (data_out_length <= 0 || coefficients_length <= 0
33+
if (data_out_length == 0 || coefficients_length == 0
3034
|| data_in_length < endpos) {
3135
return -1;
3236
}
3337

38+
rtc_MsanCheckInitialized(coefficients, sizeof(coefficients[0]),
39+
coefficients_length);
40+
3441
for (i = delay; i < endpos; i += factor) {
3542
out_s32 = 2048; // Round value, 0.5 in Q12.
3643

3744
for (j = 0; j < coefficients_length; j++) {
38-
out_s32 += coefficients[j] * data_in[i - j]; // Q12.
45+
// Negative overflow is permitted here, because this is
46+
// auto-regressive filters, and the state for each batch run is
47+
// stored in the "negative" positions of the output vector.
48+
rtc_MsanCheckInitialized(&data_in[(ptrdiff_t) i - (ptrdiff_t) j],
49+
sizeof(data_in[0]), 1);
50+
// out_s32 is in Q12 domain.
51+
out_s32 += coefficients[j] * data_in[(ptrdiff_t) i - (ptrdiff_t) j];
3952
}
4053

4154
out_s32 >>= 12; // Q0.
@@ -44,5 +57,9 @@ int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
4457
*data_out++ = WebRtcSpl_SatW32ToW16(out_s32);
4558
}
4659

60+
RTC_DCHECK_EQ(original_data_out + data_out_length, data_out);
61+
rtc_MsanCheckInitialized(original_data_out, sizeof(original_data_out[0]),
62+
data_out_length);
63+
4764
return 0;
4865
}

cbits/webrtc/common_audio/signal_processing/energy.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717

1818
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
1919

20-
int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor)
20+
int32_t WebRtcSpl_Energy(int16_t* vector,
21+
size_t vector_length,
22+
int* scale_factor)
2123
{
2224
int32_t en = 0;
23-
int i;
24-
int scaling = WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length);
25-
int looptimes = vector_length;
25+
size_t i;
26+
int scaling =
27+
WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length);
28+
size_t looptimes = vector_length;
2629
int16_t *vectorptr = vector;
2730

2831
for (i = 0; i < looptimes; i++)
2932
{
30-
en += WEBRTC_SPL_MUL_16_16_RSFT(*vectorptr, *vectorptr, scaling);
31-
vectorptr++;
33+
en += (*vectorptr * *vectorptr) >> scaling;
34+
vectorptr++;
3235
}
3336
*scale_factor = scaling;
3437

cbits/webrtc/common_audio/signal_processing/get_scaling_square.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
1919

2020
int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
21-
int in_vector_length,
22-
int times)
21+
size_t in_vector_length,
22+
size_t times)
2323
{
24-
int16_t nbits = WebRtcSpl_GetSizeInBits(times);
25-
int i;
24+
int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times);
25+
size_t i;
2626
int16_t smax = -1;
2727
int16_t sabs;
2828
int16_t *sptr = in_vector;
2929
int16_t t;
30-
int looptimes = in_vector_length;
30+
size_t looptimes = in_vector_length;
3131

3232
for (i = looptimes; i > 0; i--)
3333
{

0 commit comments

Comments
 (0)