OLD | NEW |
---|---|
(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) { | |
hlundin-webrtc
2017/02/20 14:16:31
I cannot see that the actual data_ in the AudioFra
aleloi
2017/02/20 15:21:37
Good point! Done.
| |
38 for (auto* frame : {&frame1, &frame2}) { | |
39 frame->sample_rate_hz_ = sample_rate_hz; | |
40 frame->num_channels_ = number_of_channels; | |
41 frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100); | |
42 } | |
43 } | |
44 } // namespace | |
45 | |
46 TEST(FrameCombiner, BasicApiCallsLimiter) { | |
47 FrameCombiner combiner(true); | |
48 for (const int rate : {8000, 16000, 32000, 48000}) { | |
49 for (const int number_of_channels : {1, 2}) { | |
50 const std::vector<AudioFrame*> all_frames = {&frame1, &frame2}; | |
51 SetUpFrames(rate, number_of_channels); | |
52 | |
53 for (const int number_of_frames : {0, 1, 2}) { | |
54 ProduceDebugText(rate, number_of_channels, number_of_frames); | |
55 const std::vector<AudioFrame*> frames_to_combine( | |
56 all_frames.begin(), all_frames.begin() + number_of_frames); | |
57 combiner.Combine(frames_to_combine, number_of_channels, rate, | |
58 &audio_frame_for_mixing); | |
59 } | |
60 } | |
61 } | |
62 } | |
63 | |
64 // No APM limiter means no AudioProcessing::NativeRate restriction | |
65 // on rate. The rate has to be divisible by 100 since we use | |
66 // 10 ms frames, though. | |
67 TEST(FrameCombiner, BasicApiCallsNoLimiter) { | |
68 FrameCombiner combiner(false); | |
69 for (const int rate : {8000, 10000, 11000, 32000, 44100}) { | |
70 for (const int number_of_channels : {1, 2}) { | |
71 const std::vector<AudioFrame*> all_frames = {&frame1, &frame2}; | |
72 SetUpFrames(rate, number_of_channels); | |
73 | |
74 for (const int number_of_frames : {0, 1, 2}) { | |
75 ProduceDebugText(rate, number_of_channels, number_of_frames); | |
76 const std::vector<AudioFrame*> frames_to_combine( | |
77 all_frames.begin(), all_frames.begin() + number_of_frames); | |
78 combiner.Combine(frames_to_combine, number_of_channels, rate, | |
79 &audio_frame_for_mixing); | |
80 } | |
81 } | |
82 } | |
83 } | |
84 | |
85 TEST(FrameCombiner, CombiningZeroFramesShouldProduceSilence) { | |
86 FrameCombiner combiner(false); | |
87 for (const int rate : {8000, 10000, 11000, 32000, 44100}) { | |
88 for (const int number_of_channels : {1, 2}) { | |
89 ProduceDebugText(rate, number_of_channels, 0); | |
90 | |
91 const std::vector<AudioFrame*> frames_to_combine; | |
92 combiner.Combine(frames_to_combine, number_of_channels, rate, | |
93 &audio_frame_for_mixing); | |
94 | |
95 const std::vector<int16_t> mixed_data( | |
96 audio_frame_for_mixing.data_, | |
97 audio_frame_for_mixing.data_ + number_of_channels * rate / 100); | |
98 | |
99 const std::vector<int16_t> expected(number_of_channels * rate / 100, 0); | |
100 EXPECT_EQ(mixed_data, expected); | |
101 } | |
102 } | |
103 } | |
104 | |
105 TEST(FrameCombiner, CombiningOneFrameShouldNotChangeFrame) { | |
106 FrameCombiner combiner(false); | |
107 for (const int rate : {8000, 10000, 11000, 32000, 44100}) { | |
108 for (const int number_of_channels : {1, 2}) { | |
109 ProduceDebugText(rate, number_of_channels, 1); | |
110 | |
111 SetUpFrames(rate, number_of_channels); | |
112 std::iota(frame1.data_, frame1.data_ + number_of_channels * rate / 100, | |
hlundin-webrtc
2017/02/20 14:16:32
Didn't know about std::iota. Nice.
| |
113 0); | |
114 const std::vector<AudioFrame*> frames_to_combine = {&frame1}; | |
115 combiner.Combine(frames_to_combine, number_of_channels, rate, | |
116 &audio_frame_for_mixing); | |
117 | |
118 const std::vector<int16_t> mixed_data( | |
119 audio_frame_for_mixing.data_, | |
120 audio_frame_for_mixing.data_ + number_of_channels * rate / 100); | |
121 | |
122 std::vector<int16_t> expected(number_of_channels * rate / 100); | |
123 std::iota(expected.begin(), expected.end(), 0); | |
124 EXPECT_EQ(mixed_data, expected); | |
125 } | |
126 } | |
127 } | |
128 | |
129 } // namespace webrtc | |
OLD | NEW |