Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: webrtc/modules/audio_mixer/audio_frame_manipulator_unittest.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 <algorithm> 11 #include <algorithm>
12 12
13 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" 13 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h"
14 #include "webrtc/modules/include/module_common_types.h" 14 #include "webrtc/modules/include/module_common_types.h"
15 #include "webrtc/test/gtest.h" 15 #include "webrtc/test/gtest.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 namespace { 18 namespace {
19 19
20 void FillFrameWithConstants(size_t samples_per_channel, 20 void FillFrameWithConstants(size_t samples_per_channel,
21 size_t number_of_channels, 21 size_t number_of_channels,
22 int16_t value, 22 int16_t value,
23 AudioFrame* frame) { 23 AudioFrame* frame) {
24 frame->num_channels_ = number_of_channels; 24 frame->num_channels_ = number_of_channels;
25 frame->samples_per_channel_ = samples_per_channel; 25 frame->samples_per_channel_ = samples_per_channel;
26 std::fill(frame->data_, 26 int16_t* frame_data = frame->mutable_data();
27 frame->data_ + samples_per_channel * number_of_channels, value); 27 std::fill(frame_data,
28 frame_data + samples_per_channel * number_of_channels, value);
28 } 29 }
29 } // namespace 30 } // namespace
30 31
31 TEST(AudioFrameManipulator, CompareForwardRampWithExpectedResultStereo) { 32 TEST(AudioFrameManipulator, CompareForwardRampWithExpectedResultStereo) {
32 constexpr int kSamplesPerChannel = 5; 33 constexpr int kSamplesPerChannel = 5;
33 constexpr int kNumberOfChannels = 2; 34 constexpr int kNumberOfChannels = 2;
34 35
35 // Create a frame with values 5, 5, 5, ... and channels & samples as above. 36 // Create a frame with values 5, 5, 5, ... and channels & samples as above.
36 AudioFrame frame; 37 AudioFrame frame;
37 FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame); 38 FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame);
38 39
39 Ramp(0.0f, 1.0f, &frame); 40 Ramp(0.0f, 1.0f, &frame);
40 41
41 const int total_samples = kSamplesPerChannel * kNumberOfChannels; 42 const int total_samples = kSamplesPerChannel * kNumberOfChannels;
42 const int16_t expected_result[total_samples] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4}; 43 const int16_t expected_result[total_samples] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4};
44 const int16_t* frame_data = frame.data();
43 EXPECT_TRUE( 45 EXPECT_TRUE(
44 std::equal(frame.data_, frame.data_ + total_samples, expected_result)); 46 std::equal(frame_data, frame_data + total_samples, expected_result));
45 } 47 }
46 48
47 TEST(AudioFrameManipulator, CompareBackwardRampWithExpectedResultMono) { 49 TEST(AudioFrameManipulator, CompareBackwardRampWithExpectedResultMono) {
48 constexpr int kSamplesPerChannel = 5; 50 constexpr int kSamplesPerChannel = 5;
49 constexpr int kNumberOfChannels = 1; 51 constexpr int kNumberOfChannels = 1;
50 52
51 // Create a frame with values 5, 5, 5, ... and channels & samples as above. 53 // Create a frame with values 5, 5, 5, ... and channels & samples as above.
52 AudioFrame frame; 54 AudioFrame frame;
53 FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame); 55 FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame);
54 56
55 Ramp(1.0f, 0.0f, &frame); 57 Ramp(1.0f, 0.0f, &frame);
56 58
57 const int total_samples = kSamplesPerChannel * kNumberOfChannels; 59 const int total_samples = kSamplesPerChannel * kNumberOfChannels;
58 const int16_t expected_result[total_samples] = {5, 4, 3, 2, 1}; 60 const int16_t expected_result[total_samples] = {5, 4, 3, 2, 1};
61 const int16_t* frame_data = frame.data();
59 EXPECT_TRUE( 62 EXPECT_TRUE(
60 std::equal(frame.data_, frame.data_ + total_samples, expected_result)); 63 std::equal(frame_data, frame_data + total_samples, expected_result));
61 } 64 }
62 65
63 } // namespace webrtc 66 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/audio_frame_manipulator.cc ('k') | webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698