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 #include <vector> | |
hlundin-webrtc
2016/06/27 11:21:16
Space before.
peah-webrtc
2016/06/27 22:51:49
Done.
| |
11 | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "webrtc/base/array_view.h" | |
14 #include "webrtc/modules/audio_processing/audio_buffer.h" | |
15 #include "webrtc/modules/audio_processing/include/audio_processing.h" | |
16 #include "webrtc/modules/audio_processing/level_controller/level_controller.h" | |
17 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" | |
18 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" | |
19 | |
20 namespace webrtc { | |
21 namespace { | |
22 | |
23 const int kNumFramesToProcess = 1000; | |
24 | |
25 // Processes a specified amount of frames, verifies the results and reports | |
26 // any errors. | |
27 void RunBitexactnessTest(int sample_rate_hz, | |
28 size_t num_channels, | |
29 rtc::ArrayView<const float> output_reference) { | |
30 LevelController level_controller; | |
31 level_controller.Initialize(sample_rate_hz, num_channels); | |
32 | |
33 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); | |
34 const StreamConfig capture_config(sample_rate_hz, num_channels, false); | |
35 AudioBuffer capture_buffer( | |
36 capture_config.num_frames(), capture_config.num_channels(), | |
37 capture_config.num_frames(), capture_config.num_channels(), | |
38 capture_config.num_frames()); | |
39 test::InputAudioFile capture_file( | |
40 test::GetApmCaptureTestVectorFileName(sample_rate_hz)); | |
41 std::vector<float> capture_input(samples_per_channel * num_channels); | |
42 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | |
43 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels, | |
44 &capture_file, capture_input); | |
45 | |
46 test::CopyVectorToAudioBuffer(capture_config, capture_input, | |
47 &capture_buffer); | |
48 | |
49 level_controller.Process(&capture_buffer); | |
50 } | |
51 | |
52 // Extract test results. | |
53 std::vector<float> capture_output; | |
54 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer, | |
55 &capture_output); | |
56 | |
57 // Compare the output with the reference. Only the first values of the output | |
58 // from last frame processed are compared in order not having to specify all | |
59 // preceeding frames as testvectors. As the algorithm being tested has a | |
60 // memory, testing only the last frame implicitly also tests the preceeding | |
hlundin-webrtc
2016/06/27 11:21:16
preceeding -> preceding
peah-webrtc
2016/06/27 22:51:49
Done.
| |
61 // frames. | |
62 // TODO(peah): Activate bitexactness test | |
hlundin-webrtc
2016/06/27 11:21:16
I suggest you disable the tests by prepending DISA
peah-webrtc
2016/06/27 22:51:49
Good point!
Done.
| |
63 /* | |
64 EXPECT_TRUE(test::VerifyDeinterleavedArray( | |
65 capture_config.num_frames(), capture_config.num_channels(), | |
66 output_reference, capture_output, kVectorElementErrorBound)); | |
67 */ | |
68 } | |
69 | |
70 } // namespace | |
71 | |
72 // TODO(peah): Add test vectors. | |
73 TEST(LevelControlBitExactnessTest, Mono8kHzLow) { | |
hlundin-webrtc
2016/06/27 11:21:16
What does "low" mean?
peah-webrtc
2016/06/27 22:51:49
Don't know. Must be a type. Removed that.
Done.
| |
74 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
75 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference); | |
76 } | |
77 | |
78 TEST(LevelControlBitExactnessTest, Mono16kHzLow) { | |
79 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
80 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference); | |
81 } | |
82 | |
83 TEST(LevelControlBitExactnessTest, Mono32kHzLow) { | |
84 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
85 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference); | |
86 } | |
87 | |
88 TEST(LevelControlBitExactnessTest, Mono48kHzLow) { | |
89 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
90 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference); | |
91 } | |
92 | |
93 TEST(LevelControlBitExactnessTest, Stereo8kHzLow) { | |
94 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
95 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference); | |
96 } | |
97 | |
98 TEST(LevelControlBitExactnessTest, Stereo16kHzLow) { | |
99 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
100 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference); | |
101 } | |
102 | |
103 TEST(LevelControlBitExactnessTest, Stereo32kHzLow) { | |
104 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
105 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference); | |
106 } | |
107 | |
108 TEST(LevelControlBitExactnessTest, Stereo48kHzLow) { | |
109 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; | |
110 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference); | |
111 } | |
112 | |
113 } // namespace webrtc | |
OLD | NEW |