OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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 <string> | |
12 #include <vector> | |
13 | |
14 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | |
15 #include "webrtc/modules/audio_processing/aec3/block_framer.h" | |
hlundin-webrtc
2016/12/22 10:23:56
This one should go first.
https://google.github.io
peah-webrtc
2016/12/22 16:40:03
Done.
| |
16 #include "webrtc/test/gtest.h" | |
17 | |
18 namespace webrtc { | |
19 namespace { | |
20 | |
21 void SetupSubFrameView(std::vector<std::vector<float>>* sub_frame, | |
22 std::vector<rtc::ArrayView<float>>* sub_frame_view) { | |
23 for (size_t k = 0; k < sub_frame_view->size(); ++k) { | |
24 (*sub_frame_view)[k] = | |
25 rtc::ArrayView<float>(&(*sub_frame)[k][0], (*sub_frame)[k].size()); | |
26 } | |
27 } | |
28 | |
29 float ComputeSampleValue(size_t chunk_counter, | |
30 size_t chunk_size, | |
31 size_t band, | |
32 size_t sample_index, | |
33 int offset) { | |
34 float value = | |
35 static_cast<int>(chunk_counter * chunk_size + sample_index) + offset; | |
36 return value > 0 ? 5000 * band + value : 0; | |
37 } | |
38 | |
39 bool VerifySubFrame(size_t sub_frame_counter, | |
40 int offset, | |
41 const std::vector<rtc::ArrayView<float>>& sub_frame_view) { | |
42 for (size_t k = 0; k < sub_frame_view.size(); ++k) { | |
43 for (size_t i = 0; i < sub_frame_view[k].size(); ++i) { | |
44 const float reference_value = | |
45 ComputeSampleValue(sub_frame_counter, kSubFrameLength, k, i, offset); | |
46 if (reference_value != sub_frame_view[k][i]) { | |
47 return false; | |
48 } | |
49 } | |
50 } | |
51 return true; | |
52 } | |
53 | |
54 void FillBlock(size_t block_counter, std::vector<std::vector<float>>* block) { | |
55 for (size_t k = 0; k < block->size(); ++k) { | |
56 for (size_t i = 0; i < (*block)[0].size(); ++i) { | |
57 (*block)[k][i] = ComputeSampleValue(block_counter, kBlockSize, k, i, 0); | |
58 } | |
59 } | |
60 } | |
61 | |
62 // Verifies that the BlockFramer is able to produce the expected frame content. | |
63 void RunFramerTest(int sample_rate_hz) { | |
64 constexpr size_t kNumSubFramesToProcess = 2; | |
65 const size_t num_bands = NumBandsForRate(sample_rate_hz); | |
66 | |
67 std::vector<std::vector<float>> block(num_bands, | |
68 std::vector<float>(kBlockSize, 0.f)); | |
69 std::vector<std::vector<float>> output_sub_frame( | |
70 num_bands, std::vector<float>(kSubFrameLength, 0.f)); | |
71 std::vector<rtc::ArrayView<float>> output_sub_frame_view(num_bands); | |
72 SetupSubFrameView(&output_sub_frame, &output_sub_frame_view); | |
73 BlockFramer framer(num_bands); | |
74 | |
75 size_t block_index = 0; | |
76 for (size_t sub_frame_index = 0; sub_frame_index < kNumSubFramesToProcess; | |
77 ++sub_frame_index) { | |
78 FillBlock(block_index++, &block); | |
79 framer.InsertBlockAndExtractSubFrame(block, &output_sub_frame_view); | |
80 EXPECT_TRUE(VerifySubFrame(sub_frame_index, -64, output_sub_frame_view)); | |
81 | |
82 if ((sub_frame_index + 1) % 4 == 0) { | |
83 FillBlock(block_index++, &block); | |
84 framer.InsertBlock(block); | |
85 } | |
86 } | |
87 } | |
88 | |
89 } // namespace | |
90 | |
91 TEST(BlockFramer, FrameBitexactness) { | |
92 for (auto rate : {8000, 16000, 32000, 48000}) { | |
93 std::ostringstream ss; | |
94 ss << "Sample rate: " << rate; | |
95 SCOPED_TRACE(ss.str()); | |
96 RunFramerTest(rate); | |
97 } | |
98 } | |
hlundin-webrtc
2016/12/22 10:23:56
You are testing the "good use case", but you are n
peah-webrtc
2016/12/22 16:40:03
Done.
| |
99 | |
100 } // namespace webrtc | |
OLD | NEW |