OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/test/audio_buffer_tools.h" | 11 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" |
12 | 12 |
| 13 #include <string.h> |
| 14 |
13 namespace webrtc { | 15 namespace webrtc { |
14 namespace test { | 16 namespace test { |
15 | 17 |
16 void SetupFrame(StreamConfig stream_config, | 18 void SetupFrame(const StreamConfig& stream_config, |
17 std::vector<float*>* frame, | 19 std::vector<float*>* frame, |
18 std::vector<float>* frame_samples) { | 20 std::vector<float>* frame_samples) { |
19 frame_samples->resize(stream_config.num_channels() * | 21 frame_samples->resize(stream_config.num_channels() * |
20 stream_config.num_frames()); | 22 stream_config.num_frames()); |
21 frame->resize(stream_config.num_channels()); | 23 frame->resize(stream_config.num_channels()); |
22 for (size_t ch = 0; ch < stream_config.num_channels(); ++ch) { | 24 for (size_t ch = 0; ch < stream_config.num_channels(); ++ch) { |
23 (*frame)[ch] = &(*frame_samples)[ch * stream_config.num_frames()]; | 25 (*frame)[ch] = &(*frame_samples)[ch * stream_config.num_frames()]; |
24 } | 26 } |
25 } | 27 } |
26 | 28 |
27 void CopyVectorToAudioBuffer(const StreamConfig& stream_config, | 29 void CopyVectorToAudioBuffer(const StreamConfig& stream_config, |
28 const std::vector<float>& source, | 30 rtc::ArrayView<const float> source, |
29 AudioBuffer* destination) { | 31 AudioBuffer* destination) { |
30 std::vector<float*> input; | 32 std::vector<float*> input; |
31 std::vector<float> input_samples; | 33 std::vector<float> input_samples; |
32 | 34 |
33 SetupFrame(stream_config, &input, &input_samples); | 35 SetupFrame(stream_config, &input, &input_samples); |
34 | 36 |
35 RTC_DCHECK_EQ(input_samples.size(), source.size()); | 37 RTC_CHECK_EQ(input_samples.size(), source.size()); |
36 input_samples = source; | 38 memcpy(input_samples.data(), source.data(), |
| 39 source.size() * sizeof(source[0])); |
37 | 40 |
38 destination->CopyFrom(&input[0], stream_config); | 41 destination->CopyFrom(&input[0], stream_config); |
39 } | 42 } |
40 | 43 |
41 std::vector<float> ExtractVectorFromAudioBuffer( | 44 void ExtractVectorFromAudioBuffer(const StreamConfig& stream_config, |
42 const StreamConfig& stream_config, | 45 AudioBuffer* source, |
43 AudioBuffer* source) { | 46 std::vector<float>* destination) { |
44 std::vector<float*> output; | 47 std::vector<float*> output; |
45 std::vector<float> output_samples; | |
46 | 48 |
47 SetupFrame(stream_config, &output, &output_samples); | 49 SetupFrame(stream_config, &output, destination); |
48 | 50 |
49 source->CopyTo(stream_config, &output[0]); | 51 source->CopyTo(stream_config, &output[0]); |
50 | |
51 return output_samples; | |
52 } | 52 } |
53 | 53 |
54 } // namespace test | 54 } // namespace test |
55 } // namespace webrtc | 55 } // namespace webrtc |
OLD | NEW |