Bump to WebRTC M120 release
Some API deprecation -- ExperimentalAgc and ExperimentalNs are gone. We're continuing to carry iSAC even though it's gone upstream, but maybe we'll want to drop that soon.
This commit is contained in:
		| @@ -20,42 +20,6 @@ | ||||
| #include "rtc_base/checks.h" | ||||
|  | ||||
| namespace webrtc { | ||||
| namespace { | ||||
| // These checks were factored out into a non-templatized function | ||||
| // due to problems with clang on Windows in debug builds. | ||||
| // For some reason having the DCHECKs inline in the template code | ||||
| // caused the compiler to generate code that threw off the linker. | ||||
| // TODO(tommi): Re-enable when we've figured out what the problem is. | ||||
| // http://crbug.com/615050 | ||||
| void CheckValidInitParams(int src_sample_rate_hz, | ||||
|                           int dst_sample_rate_hz, | ||||
|                           size_t num_channels) { | ||||
| // The below checks are temporarily disabled on WEBRTC_WIN due to problems | ||||
| // with clang debug builds. | ||||
| #if !defined(WEBRTC_WIN) && defined(__clang__) | ||||
|   RTC_DCHECK_GT(src_sample_rate_hz, 0); | ||||
|   RTC_DCHECK_GT(dst_sample_rate_hz, 0); | ||||
|   RTC_DCHECK_GT(num_channels, 0); | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void CheckExpectedBufferSizes(size_t src_length, | ||||
|                               size_t dst_capacity, | ||||
|                               size_t num_channels, | ||||
|                               int src_sample_rate, | ||||
|                               int dst_sample_rate) { | ||||
| // The below checks are temporarily disabled on WEBRTC_WIN due to problems | ||||
| // with clang debug builds. | ||||
| // TODO(tommi): Re-enable when we've figured out what the problem is. | ||||
| // http://crbug.com/615050 | ||||
| #if !defined(WEBRTC_WIN) && defined(__clang__) | ||||
|   const size_t src_size_10ms = src_sample_rate * num_channels / 100; | ||||
|   const size_t dst_size_10ms = dst_sample_rate * num_channels / 100; | ||||
|   RTC_DCHECK_EQ(src_length, src_size_10ms); | ||||
|   RTC_DCHECK_GE(dst_capacity, dst_size_10ms); | ||||
| #endif | ||||
| } | ||||
| }  // namespace | ||||
|  | ||||
| template <typename T> | ||||
| PushResampler<T>::PushResampler() | ||||
| @@ -68,7 +32,11 @@ template <typename T> | ||||
| int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz, | ||||
|                                          int dst_sample_rate_hz, | ||||
|                                          size_t num_channels) { | ||||
|   CheckValidInitParams(src_sample_rate_hz, dst_sample_rate_hz, num_channels); | ||||
|   // These checks used to be factored out of this template function due to | ||||
|   // Windows debug build issues with clang. http://crbug.com/615050 | ||||
|   RTC_DCHECK_GT(src_sample_rate_hz, 0); | ||||
|   RTC_DCHECK_GT(dst_sample_rate_hz, 0); | ||||
|   RTC_DCHECK_GT(num_channels, 0); | ||||
|  | ||||
|   if (src_sample_rate_hz == src_sample_rate_hz_ && | ||||
|       dst_sample_rate_hz == dst_sample_rate_hz_ && | ||||
| @@ -109,8 +77,12 @@ int PushResampler<T>::Resample(const T* src, | ||||
|                                size_t src_length, | ||||
|                                T* dst, | ||||
|                                size_t dst_capacity) { | ||||
|   CheckExpectedBufferSizes(src_length, dst_capacity, num_channels_, | ||||
|                            src_sample_rate_hz_, dst_sample_rate_hz_); | ||||
|   // These checks used to be factored out of this template function due to | ||||
|   // Windows debug build issues with clang. http://crbug.com/615050 | ||||
|   const size_t src_size_10ms = (src_sample_rate_hz_ / 100) * num_channels_; | ||||
|   const size_t dst_size_10ms = (dst_sample_rate_hz_ / 100) * num_channels_; | ||||
|   RTC_DCHECK_EQ(src_length, src_size_10ms); | ||||
|   RTC_DCHECK_GE(dst_capacity, dst_size_10ms); | ||||
|  | ||||
|   if (src_sample_rate_hz_ == dst_sample_rate_hz_) { | ||||
|     // The old resampler provides this memcpy facility in the case of matching | ||||
|   | ||||
| @@ -63,12 +63,12 @@ size_t PushSincResampler::Resample(const float* source, | ||||
|   // request through Run(). | ||||
|   // | ||||
|   // If this wasn't done, SincResampler would call Run() twice on the first | ||||
|   // pass, and we'd have to introduce an entire |source_frames| of delay, rather | ||||
|   // pass, and we'd have to introduce an entire `source_frames` of delay, rather | ||||
|   // than the minimum half kernel. | ||||
|   // | ||||
|   // It works out that ChunkSize() is exactly the amount of output we need to | ||||
|   // request in order to prime the buffer with a single Run() request for | ||||
|   // |source_frames|. | ||||
|   // `source_frames`. | ||||
|   if (first_pass_) | ||||
|     resampler_->Resample(resampler_->ChunkSize(), destination); | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,6 @@ | ||||
| #include <memory> | ||||
|  | ||||
| #include "common_audio/resampler/sinc_resampler.h" | ||||
| #include "rtc_base/constructor_magic.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
| @@ -33,11 +32,14 @@ class PushSincResampler : public SincResamplerCallback { | ||||
|   PushSincResampler(size_t source_frames, size_t destination_frames); | ||||
|   ~PushSincResampler() override; | ||||
|  | ||||
|   // Perform the resampling. |source_frames| must always equal the | ||||
|   // |source_frames| provided at construction. |destination_capacity| must be | ||||
|   // at least as large as |destination_frames|. Returns the number of samples | ||||
|   PushSincResampler(const PushSincResampler&) = delete; | ||||
|   PushSincResampler& operator=(const PushSincResampler&) = delete; | ||||
|  | ||||
|   // Perform the resampling. `source_frames` must always equal the | ||||
|   // `source_frames` provided at construction. `destination_capacity` must be | ||||
|   // at least as large as `destination_frames`. Returns the number of samples | ||||
|   // provided in destination (for convenience, since this will always be equal | ||||
|   // to |destination_frames|). | ||||
|   // to `destination_frames`). | ||||
|   size_t Resample(const int16_t* source, | ||||
|                   size_t source_frames, | ||||
|                   int16_t* destination, | ||||
| @@ -72,8 +74,6 @@ class PushSincResampler : public SincResamplerCallback { | ||||
|  | ||||
|   // Used to assert we are only requested for as much data as is available. | ||||
|   size_t source_available_; | ||||
|  | ||||
|   RTC_DISALLOW_COPY_AND_ASSIGN(PushSincResampler); | ||||
| }; | ||||
|  | ||||
| }  // namespace webrtc | ||||
|   | ||||
| @@ -916,7 +916,6 @@ int Resampler::Push(const int16_t* samplesIn, | ||||
|       outLen = (lengthIn * 8) / 11; | ||||
|       free(tmp_mem); | ||||
|       return 0; | ||||
|       break; | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -80,7 +80,7 @@ | ||||
| // 8) Else, if we're not on the second load, goto (4). | ||||
| // | ||||
| // Note: we're glossing over how the sub-sample handling works with | ||||
| // |virtual_source_idx_|, etc. | ||||
| // `virtual_source_idx_`, etc. | ||||
|  | ||||
| // MSVC++ requires this to be set before any other includes to get M_PI. | ||||
| #define _USE_MATH_DEFINES | ||||
| @@ -102,7 +102,7 @@ namespace webrtc { | ||||
| namespace { | ||||
|  | ||||
| double SincScaleFactor(double io_ratio) { | ||||
|   // |sinc_scale_factor| is basically the normalized cutoff frequency of the | ||||
|   // `sinc_scale_factor` is basically the normalized cutoff frequency of the | ||||
|   // low-pass filter. | ||||
|   double sinc_scale_factor = io_ratio > 1.0 ? 1.0 / io_ratio : 1.0; | ||||
|  | ||||
| @@ -126,8 +126,8 @@ void SincResampler::InitializeCPUSpecificFeatures() { | ||||
| #if defined(WEBRTC_HAS_NEON) | ||||
|   convolve_proc_ = Convolve_NEON; | ||||
| #elif defined(WEBRTC_ARCH_X86_FAMILY) | ||||
|   // Using AVX2 instead of SSE2 when AVX2 supported. | ||||
|   if (GetCPUInfo(kAVX2)) | ||||
|   // Using AVX2 instead of SSE2 when AVX2/FMA3 supported. | ||||
|   if (GetCPUInfo(kAVX2) && GetCPUInfo(kFMA3)) | ||||
|     convolve_proc_ = Convolve_AVX2; | ||||
|   else if (GetCPUInfo(kSSE2)) | ||||
|     convolve_proc_ = Convolve_SSE; | ||||
| @@ -238,7 +238,7 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) { | ||||
|   io_sample_rate_ratio_ = io_sample_rate_ratio; | ||||
|  | ||||
|   // Optimize reinitialization by reusing values which are independent of | ||||
|   // |sinc_scale_factor|.  Provides a 3x speedup. | ||||
|   // `sinc_scale_factor`.  Provides a 3x speedup. | ||||
|   const double sinc_scale_factor = SincScaleFactor(io_sample_rate_ratio_); | ||||
|   for (size_t offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) { | ||||
|     for (size_t i = 0; i < kKernelSize; ++i) { | ||||
| @@ -268,8 +268,8 @@ void SincResampler::Resample(size_t frames, float* destination) { | ||||
|   const double current_io_ratio = io_sample_rate_ratio_; | ||||
|   const float* const kernel_ptr = kernel_storage_.get(); | ||||
|   while (remaining_frames) { | ||||
|     // |i| may be negative if the last Resample() call ended on an iteration | ||||
|     // that put |virtual_source_idx_| over the limit. | ||||
|     // `i` may be negative if the last Resample() call ended on an iteration | ||||
|     // that put `virtual_source_idx_` over the limit. | ||||
|     // | ||||
|     // Note: The loop construct here can severely impact performance on ARM | ||||
|     // or when built with clang.  See https://codereview.chromium.org/18566009/ | ||||
| @@ -278,7 +278,7 @@ void SincResampler::Resample(size_t frames, float* destination) { | ||||
|          i > 0; --i) { | ||||
|       RTC_DCHECK_LT(virtual_source_idx_, block_size_); | ||||
|  | ||||
|       // |virtual_source_idx_| lies in between two kernel offsets so figure out | ||||
|       // `virtual_source_idx_` lies in between two kernel offsets so figure out | ||||
|       // what they are. | ||||
|       const int source_idx = static_cast<int>(virtual_source_idx_); | ||||
|       const double subsample_remainder = virtual_source_idx_ - source_idx; | ||||
| @@ -288,16 +288,16 @@ void SincResampler::Resample(size_t frames, float* destination) { | ||||
|       const int offset_idx = static_cast<int>(virtual_offset_idx); | ||||
|  | ||||
|       // We'll compute "convolutions" for the two kernels which straddle | ||||
|       // |virtual_source_idx_|. | ||||
|       // `virtual_source_idx_`. | ||||
|       const float* const k1 = kernel_ptr + offset_idx * kKernelSize; | ||||
|       const float* const k2 = k1 + kKernelSize; | ||||
|  | ||||
|       // Ensure |k1|, |k2| are 32-byte aligned for SIMD usage.  Should always be | ||||
|       // Ensure `k1`, `k2` are 32-byte aligned for SIMD usage.  Should always be | ||||
|       // true so long as kKernelSize is a multiple of 32. | ||||
|       RTC_DCHECK_EQ(0, reinterpret_cast<uintptr_t>(k1) % 32); | ||||
|       RTC_DCHECK_EQ(0, reinterpret_cast<uintptr_t>(k2) % 32); | ||||
|  | ||||
|       // Initialize input pointer based on quantized |virtual_source_idx_|. | ||||
|       // Initialize input pointer based on quantized `virtual_source_idx_`. | ||||
|       const float* const input_ptr = r1_ + source_idx; | ||||
|  | ||||
|       // Figure out how much to weight each kernel's "convolution". | ||||
|   | ||||
| @@ -18,15 +18,14 @@ | ||||
|  | ||||
| #include <memory> | ||||
|  | ||||
| #include "rtc_base/constructor_magic.h" | ||||
| #include "rtc_base/gtest_prod_util.h" | ||||
| #include "rtc_base/memory/aligned_malloc.h" | ||||
| #include "rtc_base/system/arch.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
| // Callback class for providing more data into the resampler.  Expects |frames| | ||||
| // of data to be rendered into |destination|; zero padded if not enough frames | ||||
| // Callback class for providing more data into the resampler.  Expects `frames` | ||||
| // of data to be rendered into `destination`; zero padded if not enough frames | ||||
| // are available to satisfy the request. | ||||
| class SincResamplerCallback { | ||||
|  public: | ||||
| @@ -53,10 +52,10 @@ class SincResampler { | ||||
|   static const size_t kKernelStorageSize = | ||||
|       kKernelSize * (kKernelOffsetCount + 1); | ||||
|  | ||||
|   // Constructs a SincResampler with the specified |read_cb|, which is used to | ||||
|   // acquire audio data for resampling.  |io_sample_rate_ratio| is the ratio | ||||
|   // of input / output sample rates.  |request_frames| controls the size in | ||||
|   // frames of the buffer requested by each |read_cb| call.  The value must be | ||||
|   // Constructs a SincResampler with the specified `read_cb`, which is used to | ||||
|   // acquire audio data for resampling.  `io_sample_rate_ratio` is the ratio | ||||
|   // of input / output sample rates.  `request_frames` controls the size in | ||||
|   // frames of the buffer requested by each `read_cb` call.  The value must be | ||||
|   // greater than kKernelSize.  Specify kDefaultRequestSize if there are no | ||||
|   // request size constraints. | ||||
|   SincResampler(double io_sample_rate_ratio, | ||||
| @@ -64,11 +63,14 @@ class SincResampler { | ||||
|                 SincResamplerCallback* read_cb); | ||||
|   virtual ~SincResampler(); | ||||
|  | ||||
|   // Resample |frames| of data from |read_cb_| into |destination|. | ||||
|   SincResampler(const SincResampler&) = delete; | ||||
|   SincResampler& operator=(const SincResampler&) = delete; | ||||
|  | ||||
|   // Resample `frames` of data from `read_cb_` into `destination`. | ||||
|   void Resample(size_t frames, float* destination); | ||||
|  | ||||
|   // The maximum size in frames that guarantees Resample() will only make a | ||||
|   // single call to |read_cb_| for more data. | ||||
|   // single call to `read_cb_` for more data. | ||||
|   size_t ChunkSize() const; | ||||
|  | ||||
|   size_t request_frames() const { return request_frames_; } | ||||
| @@ -77,12 +79,12 @@ class SincResampler { | ||||
|   // not call while Resample() is in progress. | ||||
|   void Flush(); | ||||
|  | ||||
|   // Update |io_sample_rate_ratio_|.  SetRatio() will cause a reconstruction of | ||||
|   // Update `io_sample_rate_ratio_`.  SetRatio() will cause a reconstruction of | ||||
|   // the kernels used for resampling.  Not thread safe, do not call while | ||||
|   // Resample() is in progress. | ||||
|   // | ||||
|   // TODO(ajm): Use this in PushSincResampler rather than reconstructing | ||||
|   // SincResampler.  We would also need a way to update |request_frames_|. | ||||
|   // SincResampler.  We would also need a way to update `request_frames_`. | ||||
|   void SetRatio(double io_sample_rate_ratio); | ||||
|  | ||||
|   float* get_kernel_for_testing() { return kernel_storage_.get(); } | ||||
| @@ -97,11 +99,11 @@ class SincResampler { | ||||
|   // Selects runtime specific CPU features like SSE.  Must be called before | ||||
|   // using SincResampler. | ||||
|   // TODO(ajm): Currently managed by the class internally. See the note with | ||||
|   // |convolve_proc_| below. | ||||
|   // `convolve_proc_` below. | ||||
|   void InitializeCPUSpecificFeatures(); | ||||
|  | ||||
|   // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are | ||||
|   // linearly interpolated using |kernel_interpolation_factor|.  On x86 and ARM | ||||
|   // Compute convolution of `k1` and `k2` over `input_ptr`, resultant sums are | ||||
|   // linearly interpolated using `kernel_interpolation_factor`.  On x86 and ARM | ||||
|   // the underlying implementation is chosen at run time. | ||||
|   static float Convolve_C(const float* input_ptr, | ||||
|                           const float* k1, | ||||
| @@ -136,7 +138,7 @@ class SincResampler { | ||||
|   // Source of data for resampling. | ||||
|   SincResamplerCallback* read_cb_; | ||||
|  | ||||
|   // The size (in samples) to request from each |read_cb_| execution. | ||||
|   // The size (in samples) to request from each `read_cb_` execution. | ||||
|   const size_t request_frames_; | ||||
|  | ||||
|   // The number of source frames processed per pass. | ||||
| @@ -155,25 +157,23 @@ class SincResampler { | ||||
|   // Data from the source is copied into this buffer for each processing pass. | ||||
|   std::unique_ptr<float[], AlignedFreeDeleter> input_buffer_; | ||||
|  | ||||
| // Stores the runtime selection of which Convolve function to use. | ||||
| // TODO(ajm): Move to using a global static which must only be initialized | ||||
| // once by the user. We're not doing this initially, because we don't have | ||||
| // e.g. a LazyInstance helper in webrtc. | ||||
|   // Stores the runtime selection of which Convolve function to use. | ||||
|   // TODO(ajm): Move to using a global static which must only be initialized | ||||
|   // once by the user. We're not doing this initially, because we don't have | ||||
|   // e.g. a LazyInstance helper in webrtc. | ||||
|   typedef float (*ConvolveProc)(const float*, | ||||
|                                 const float*, | ||||
|                                 const float*, | ||||
|                                 double); | ||||
|   ConvolveProc convolve_proc_; | ||||
|  | ||||
|   // Pointers to the various regions inside |input_buffer_|.  See the diagram at | ||||
|   // Pointers to the various regions inside `input_buffer_`.  See the diagram at | ||||
|   // the top of the .cc file for more information. | ||||
|   float* r0_; | ||||
|   float* const r1_; | ||||
|   float* const r2_; | ||||
|   float* r3_; | ||||
|   float* r4_; | ||||
|  | ||||
|   RTC_DISALLOW_COPY_AND_ASSIGN(SincResampler); | ||||
| }; | ||||
|  | ||||
| }  // namespace webrtc | ||||
|   | ||||
| @@ -25,7 +25,7 @@ float SincResampler::Convolve_AVX2(const float* input_ptr, | ||||
|   __m256 m_sums1 = _mm256_setzero_ps(); | ||||
|   __m256 m_sums2 = _mm256_setzero_ps(); | ||||
|  | ||||
|   // Based on |input_ptr| alignment, we need to use loadu or load.  Unrolling | ||||
|   // Based on `input_ptr` alignment, we need to use loadu or load.  Unrolling | ||||
|   // these loops has not been tested or benchmarked. | ||||
|   bool aligned_input = (reinterpret_cast<uintptr_t>(input_ptr) & 0x1F) == 0; | ||||
|   if (!aligned_input) { | ||||
|   | ||||
| @@ -27,7 +27,7 @@ float SincResampler::Convolve_SSE(const float* input_ptr, | ||||
|   __m128 m_sums1 = _mm_setzero_ps(); | ||||
|   __m128 m_sums2 = _mm_setzero_ps(); | ||||
|  | ||||
|   // Based on |input_ptr| alignment, we need to use loadu or load.  Unrolling | ||||
|   // Based on `input_ptr` alignment, we need to use loadu or load.  Unrolling | ||||
|   // these loops hurt performance in local testing. | ||||
|   if (reinterpret_cast<uintptr_t>(input_ptr) & 0x0F) { | ||||
|     for (size_t i = 0; i < kKernelSize; i += 4) { | ||||
|   | ||||
| @@ -15,7 +15,6 @@ | ||||
| #define COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_ | ||||
|  | ||||
| #include "common_audio/resampler/sinc_resampler.h" | ||||
| #include "rtc_base/constructor_magic.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
| @@ -24,7 +23,7 @@ namespace webrtc { | ||||
| // resampler for the specific sample rate conversion being used. | ||||
| class SinusoidalLinearChirpSource : public SincResamplerCallback { | ||||
|  public: | ||||
|   // |delay_samples| can be used to insert a fractional sample delay into the | ||||
|   // `delay_samples` can be used to insert a fractional sample delay into the | ||||
|   // source.  It will produce zeros until non-negative time is reached. | ||||
|   SinusoidalLinearChirpSource(int sample_rate, | ||||
|                               size_t samples, | ||||
| @@ -33,12 +32,16 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { | ||||
|  | ||||
|   ~SinusoidalLinearChirpSource() override {} | ||||
|  | ||||
|   SinusoidalLinearChirpSource(const SinusoidalLinearChirpSource&) = delete; | ||||
|   SinusoidalLinearChirpSource& operator=(const SinusoidalLinearChirpSource&) = | ||||
|       delete; | ||||
|  | ||||
|   void Run(size_t frames, float* destination) override; | ||||
|  | ||||
|   double Frequency(size_t position); | ||||
|  | ||||
|  private: | ||||
|   enum { kMinFrequency = 5 }; | ||||
|   static constexpr int kMinFrequency = 5; | ||||
|  | ||||
|   int sample_rate_; | ||||
|   size_t total_samples_; | ||||
| @@ -46,8 +49,6 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { | ||||
|   double k_; | ||||
|   size_t current_index_; | ||||
|   double delay_samples_; | ||||
|  | ||||
|   RTC_DISALLOW_COPY_AND_ASSIGN(SinusoidalLinearChirpSource); | ||||
| }; | ||||
|  | ||||
| }  // namespace webrtc | ||||
|   | ||||
		Reference in New Issue
	
	Block a user