blob: 5bd51cee817c0bd16e665289984777caa40de468 [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
16TEST(AudioFrameTest, ConstructFromAudioBuffer) {
17 constexpr int kSampleRateHz = 48000;
18 constexpr int kNumChannels = 2;
19 constexpr float kFloatConstant = 1272.f;
20 constexpr float kIntConstant = 17252;
21 const webrtc::StreamConfig stream_config(kSampleRateHz, kNumChannels, false);
22 webrtc::AudioBuffer buffer(
23 stream_config.num_frames(), stream_config.num_channels(),
24 stream_config.num_frames(), stream_config.num_channels(),
25 stream_config.num_frames());
26
27 AudioFrameView<float> non_const_view(
28 buffer.channels_f(), buffer.num_channels(), buffer.num_frames());
29 // Modification is allowed.
30 non_const_view.channel(0)[0] = kFloatConstant;
31 EXPECT_EQ(buffer.channels_f()[0][0], kFloatConstant);
32
33 AudioFrameView<const float> const_view(
34 buffer.channels_f(), buffer.num_channels(), buffer.num_frames());
35 // Modification is not allowed.
36 // const_view.channel(0)[0] = kFloatConstant;
37
38 // Assignment is allowed.
39 AudioFrameView<const float> other_const_view = non_const_view;
40 static_cast<void>(other_const_view);
41
42 // But not the other way.
43 // non_const_view = other_const_view;
44
45 AudioFrameView<int16_t> non_const_int16_view(
46 buffer.channels(), buffer.num_channels(), buffer.num_frames());
47 non_const_int16_view.channel(0)[0] = kIntConstant;
48 EXPECT_EQ(buffer.channels()[0][0], kIntConstant);
49}