OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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/modules/audio_processing/test/simulator_buffers.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace test { |
| 18 |
| 19 SimulatorBuffers::SimulatorBuffers(int render_input_sample_rate_hz, |
| 20 int capture_input_sample_rate_hz, |
| 21 int render_output_sample_rate_hz, |
| 22 int capture_output_sample_rate_hz, |
| 23 size_t num_render_input_channels, |
| 24 size_t num_capture_input_channels, |
| 25 size_t num_render_output_channels, |
| 26 size_t num_capture_output_channels) { |
| 27 Random rand_gen(42); |
| 28 CreateConfigAndBuffer(render_input_sample_rate_hz, num_render_input_channels, |
| 29 &rand_gen, &render_input_buffer, &render_input_config, |
| 30 &render_input, &render_input_samples); |
| 31 |
| 32 CreateConfigAndBuffer(render_output_sample_rate_hz, |
| 33 num_render_output_channels, &rand_gen, |
| 34 &render_output_buffer, &render_output_config, |
| 35 &render_output, &render_output_samples); |
| 36 |
| 37 CreateConfigAndBuffer(capture_input_sample_rate_hz, |
| 38 num_capture_input_channels, &rand_gen, |
| 39 &capture_input_buffer, &capture_input_config, |
| 40 &capture_input, &capture_input_samples); |
| 41 |
| 42 CreateConfigAndBuffer(capture_output_sample_rate_hz, |
| 43 num_capture_output_channels, &rand_gen, |
| 44 &capture_output_buffer, &capture_output_config, |
| 45 &capture_output, &capture_output_samples); |
| 46 |
| 47 UpdateInputBuffers(); |
| 48 } |
| 49 |
| 50 SimulatorBuffers::~SimulatorBuffers() = default; |
| 51 |
| 52 void SimulatorBuffers::CreateConfigAndBuffer( |
| 53 int sample_rate_hz, |
| 54 size_t num_channels, |
| 55 Random* rand_gen, |
| 56 std::unique_ptr<AudioBuffer>* buffer, |
| 57 StreamConfig* config, |
| 58 std::vector<float*>* buffer_data, |
| 59 std::vector<float>* buffer_data_samples) { |
| 60 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); |
| 61 *config = StreamConfig(sample_rate_hz, num_channels, false); |
| 62 buffer->reset(new AudioBuffer(config->num_frames(), config->num_channels(), |
| 63 config->num_frames(), config->num_channels(), |
| 64 config->num_frames())); |
| 65 |
| 66 buffer_data_samples->resize(samples_per_channel * num_channels); |
| 67 for (auto& v : *buffer_data_samples) { |
| 68 v = rand_gen->Rand<float>(); |
| 69 } |
| 70 |
| 71 buffer_data->resize(num_channels); |
| 72 for (size_t ch = 0; ch < num_channels; ++ch) { |
| 73 (*buffer_data)[ch] = &(*buffer_data_samples)[ch * samples_per_channel]; |
| 74 } |
| 75 } |
| 76 |
| 77 void SimulatorBuffers::UpdateInputBuffers() { |
| 78 test::CopyVectorToAudioBuffer(capture_input_config, capture_input_samples, |
| 79 capture_input_buffer.get()); |
| 80 test::CopyVectorToAudioBuffer(render_input_config, render_input_samples, |
| 81 render_input_buffer.get()); |
| 82 } |
| 83 |
| 84 } // namespace test |
| 85 } // namespace webrtc |
OLD | NEW |