echo_canceller_test_tools.cc (1593B)
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 #include "modules/audio_processing/test/echo_canceller_test_tools.h" 12 13 #include <algorithm> 14 #include <cstddef> 15 16 #include "api/array_view.h" 17 #include "rtc_base/checks.h" 18 #include "rtc_base/random.h" 19 20 namespace webrtc { 21 22 void RandomizeSampleVector(Random* random_generator, ArrayView<float> v) { 23 RandomizeSampleVector(random_generator, v, 24 /*amplitude=*/32767.f); 25 } 26 27 void RandomizeSampleVector(Random* random_generator, 28 ArrayView<float> v, 29 float amplitude) { 30 for (auto& v_k : v) { 31 v_k = 2 * amplitude * random_generator->Rand<float>() - amplitude; 32 } 33 } 34 35 template <typename T> 36 void DelayBuffer<T>::Delay(ArrayView<const T> x, ArrayView<T> x_delayed) { 37 RTC_DCHECK_EQ(x.size(), x_delayed.size()); 38 if (buffer_.empty()) { 39 std::copy(x.begin(), x.end(), x_delayed.begin()); 40 } else { 41 for (size_t k = 0; k < x.size(); ++k) { 42 x_delayed[k] = buffer_[next_insert_index_]; 43 buffer_[next_insert_index_] = x[k]; 44 next_insert_index_ = (next_insert_index_ + 1) % buffer_.size(); 45 } 46 } 47 } 48 49 template class DelayBuffer<float>; 50 template class DelayBuffer<int>; 51 } // namespace webrtc