blob: 7a9d126103061b141486b67d6f61dab9d97e3599 [file] [log] [blame]
Alex Loiko153f11e2018-02-16 12:39:00 +01001/*
2 * Copyright 2018 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/include/audio_frame_view.h"
12
13#include "modules/audio_processing/audio_buffer.h"
14#include "test/gtest.h"
15
Alex Loikof55babc2018-05-14 12:39:32 +020016namespace webrtc {
Alex Loiko153f11e2018-02-16 12:39:00 +010017TEST(AudioFrameTest, ConstructFromAudioBuffer) {
18 constexpr int kSampleRateHz = 48000;
19 constexpr int kNumChannels = 2;
20 constexpr float kFloatConstant = 1272.f;
21 constexpr float kIntConstant = 17252;
22 const webrtc::StreamConfig stream_config(kSampleRateHz, kNumChannels, false);
23 webrtc::AudioBuffer buffer(
24 stream_config.num_frames(), stream_config.num_channels(),
25 stream_config.num_frames(), stream_config.num_channels(),
26 stream_config.num_frames());
27
28 AudioFrameView<float> non_const_view(
29 buffer.channels_f(), buffer.num_channels(), buffer.num_frames());
30 // Modification is allowed.
31 non_const_view.channel(0)[0] = kFloatConstant;
32 EXPECT_EQ(buffer.channels_f()[0][0], kFloatConstant);
33
34 AudioFrameView<const float> const_view(
35 buffer.channels_f(), buffer.num_channels(), buffer.num_frames());
36 // Modification is not allowed.
37 // const_view.channel(0)[0] = kFloatConstant;
38
39 // Assignment is allowed.
40 AudioFrameView<const float> other_const_view = non_const_view;
41 static_cast<void>(other_const_view);
42
Alex Loikoa0262da2018-02-16 13:58:45 +010043 // But not the other way. The following will fail:
Alex Loiko153f11e2018-02-16 12:39:00 +010044 // non_const_view = other_const_view;
45
46 AudioFrameView<int16_t> non_const_int16_view(
47 buffer.channels(), buffer.num_channels(), buffer.num_frames());
48 non_const_int16_view.channel(0)[0] = kIntConstant;
49 EXPECT_EQ(buffer.channels()[0][0], kIntConstant);
50}
Alex Loikof55babc2018-05-14 12:39:32 +020051} // namespace webrtc