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