blob: 0f0e5cd5205cf15352a60392b05dd97062451e96 [file] [log] [blame]
peah01973632016-03-03 11:21:51 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/test/audio_buffer_tools.h"
peah01973632016-03-03 11:21:51 -080012
peah55850012016-03-19 18:01:09 -070013#include <string.h>
14
peah01973632016-03-03 11:21:51 -080015namespace webrtc {
16namespace test {
17
peah55850012016-03-19 18:01:09 -070018void SetupFrame(const StreamConfig& stream_config,
peah01973632016-03-03 11:21:51 -080019 std::vector<float*>* frame,
20 std::vector<float>* frame_samples) {
21 frame_samples->resize(stream_config.num_channels() *
22 stream_config.num_frames());
23 frame->resize(stream_config.num_channels());
24 for (size_t ch = 0; ch < stream_config.num_channels(); ++ch) {
25 (*frame)[ch] = &(*frame_samples)[ch * stream_config.num_frames()];
26 }
27}
28
29void CopyVectorToAudioBuffer(const StreamConfig& stream_config,
peah55850012016-03-19 18:01:09 -070030 rtc::ArrayView<const float> source,
peah01973632016-03-03 11:21:51 -080031 AudioBuffer* destination) {
32 std::vector<float*> input;
33 std::vector<float> input_samples;
34
35 SetupFrame(stream_config, &input, &input_samples);
36
peah55850012016-03-19 18:01:09 -070037 RTC_CHECK_EQ(input_samples.size(), source.size());
38 memcpy(input_samples.data(), source.data(),
39 source.size() * sizeof(source[0]));
peah01973632016-03-03 11:21:51 -080040
41 destination->CopyFrom(&input[0], stream_config);
42}
43
peah55850012016-03-19 18:01:09 -070044void ExtractVectorFromAudioBuffer(const StreamConfig& stream_config,
45 AudioBuffer* source,
46 std::vector<float>* destination) {
peah01973632016-03-03 11:21:51 -080047 std::vector<float*> output;
peah01973632016-03-03 11:21:51 -080048
peah55850012016-03-19 18:01:09 -070049 SetupFrame(stream_config, &output, destination);
peah01973632016-03-03 11:21:51 -080050
51 source->CopyTo(stream_config, &output[0]);
peah01973632016-03-03 11:21:51 -080052}
53
54} // namespace test
55} // namespace webrtc