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

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

Issue 2692333002: Optionally disable APM limiter in AudioMixer. (Closed)
Patch Set: UpdateFrame to initialize data in AudioFrame. Created 3 years, 10 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
« no previous file with comments | « webrtc/modules/audio_mixer/frame_combiner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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_mixer/frame_combiner.h"
12
13 #include <numeric>
14 #include <sstream>
15 #include <string>
16
17 #include "webrtc/base/checks.h"
18 #include "webrtc/test/gtest.h"
19
20 namespace webrtc {
21
22 namespace {
23 std::string ProduceDebugText(int sample_rate_hz,
24 int number_of_channels,
25 int number_of_sources) {
26 std::ostringstream ss;
27 ss << "Sample rate: " << sample_rate_hz << " ";
28 ss << "Number of channels: " << number_of_channels << " ";
29 ss << "Number of sources: " << number_of_sources;
30 return ss.str();
31 }
32
33 AudioFrame frame1;
34 AudioFrame frame2;
35 AudioFrame audio_frame_for_mixing;
36
37 void SetUpFrames(int sample_rate_hz, int number_of_channels) {
38 for (auto* frame : {&frame1, &frame2}) {
39 frame->UpdateFrame(-1, 0, nullptr,
40 rtc::CheckedDivExact(sample_rate_hz, 100),
41 sample_rate_hz, AudioFrame::kNormalSpeech,
42 AudioFrame::kVadActive, number_of_channels);
43 }
44 }
45 } // namespace
46
47 TEST(FrameCombiner, BasicApiCallsLimiter) {
48 FrameCombiner combiner(true);
49 for (const int rate : {8000, 16000, 32000, 48000}) {
50 for (const int number_of_channels : {1, 2}) {
51 const std::vector<AudioFrame*> all_frames = {&frame1, &frame2};
52 SetUpFrames(rate, number_of_channels);
53
54 for (const int number_of_frames : {0, 1, 2}) {
55 ProduceDebugText(rate, number_of_channels, number_of_frames);
ivoc 2017/02/21 09:59:16 Why is this debug string created and not used in a
56 const std::vector<AudioFrame*> frames_to_combine(
57 all_frames.begin(), all_frames.begin() + number_of_frames);
58 combiner.Combine(frames_to_combine, number_of_channels, rate,
59 &audio_frame_for_mixing);
60 }
61 }
62 }
63 }
64
65 // No APM limiter means no AudioProcessing::NativeRate restriction
66 // on rate. The rate has to be divisible by 100 since we use
67 // 10 ms frames, though.
68 TEST(FrameCombiner, BasicApiCallsNoLimiter) {
69 FrameCombiner combiner(false);
70 for (const int rate : {8000, 10000, 11000, 32000, 44100}) {
71 for (const int number_of_channels : {1, 2}) {
72 const std::vector<AudioFrame*> all_frames = {&frame1, &frame2};
73 SetUpFrames(rate, number_of_channels);
74
75 for (const int number_of_frames : {0, 1, 2}) {
76 ProduceDebugText(rate, number_of_channels, number_of_frames);
77 const std::vector<AudioFrame*> frames_to_combine(
78 all_frames.begin(), all_frames.begin() + number_of_frames);
79 combiner.Combine(frames_to_combine, number_of_channels, rate,
80 &audio_frame_for_mixing);
81 }
82 }
83 }
84 }
85
86 TEST(FrameCombiner, CombiningZeroFramesShouldProduceSilence) {
87 FrameCombiner combiner(false);
88 for (const int rate : {8000, 10000, 11000, 32000, 44100}) {
89 for (const int number_of_channels : {1, 2}) {
90 ProduceDebugText(rate, number_of_channels, 0);
91
92 const std::vector<AudioFrame*> frames_to_combine;
93 combiner.Combine(frames_to_combine, number_of_channels, rate,
94 &audio_frame_for_mixing);
95
96 const std::vector<int16_t> mixed_data(
97 audio_frame_for_mixing.data_,
98 audio_frame_for_mixing.data_ + number_of_channels * rate / 100);
99
100 const std::vector<int16_t> expected(number_of_channels * rate / 100, 0);
101 EXPECT_EQ(mixed_data, expected);
102 }
103 }
104 }
105
106 TEST(FrameCombiner, CombiningOneFrameShouldNotChangeFrame) {
107 FrameCombiner combiner(false);
108 for (const int rate : {8000, 10000, 11000, 32000, 44100}) {
109 for (const int number_of_channels : {1, 2}) {
110 ProduceDebugText(rate, number_of_channels, 1);
111
112 SetUpFrames(rate, number_of_channels);
113 std::iota(frame1.data_, frame1.data_ + number_of_channels * rate / 100,
ivoc 2017/02/21 09:59:16 Looks like an interesting function, I wasn't aware
aleloi 2017/02/21 10:16:57 Well spotted, thanks! The calls should be surround
114 0);
115 const std::vector<AudioFrame*> frames_to_combine = {&frame1};
116 combiner.Combine(frames_to_combine, number_of_channels, rate,
117 &audio_frame_for_mixing);
118
119 const std::vector<int16_t> mixed_data(
120 audio_frame_for_mixing.data_,
121 audio_frame_for_mixing.data_ + number_of_channels * rate / 100);
122
123 std::vector<int16_t> expected(number_of_channels * rate / 100);
124 std::iota(expected.begin(), expected.end(), 0);
125 EXPECT_EQ(mixed_data, expected);
126 }
127 }
128 }
129
130 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/frame_combiner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698