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

Side by Side Diff: webrtc/modules/audio_processing/test/bitexactness_tools.cc

Issue 1841213002: Renamed the test::BitExactFrame method to test::VectorDifferenceBounded. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Changed name of one of the vector comparison methods Created 4 years, 8 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
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // Convert samples to float and discard any channels not needed. 64 // Convert samples to float and discard any channels not needed.
65 for (size_t sample = 0; sample < samples_per_channel; ++sample) { 65 for (size_t sample = 0; sample < samples_per_channel; ++sample) {
66 for (size_t channel = 0; channel < num_channels; ++channel) { 66 for (size_t channel = 0; channel < num_channels; ++channel) {
67 data[sample * num_channels + channel] = 67 data[sample * num_channels + channel] =
68 read_samples[sample * 2 + channel] / 32768.0f; 68 read_samples[sample * 2 + channel] / 32768.0f;
69 } 69 }
70 } 70 }
71 } 71 }
72 72
73 ::testing::AssertionResult BitExactFrame(size_t samples_per_channel, 73 ::testing::AssertionResult StackedFrameDifferenceBounded(
74 size_t num_channels, 74 size_t samples_per_channel,
75 rtc::ArrayView<const float> reference, 75 size_t num_channels,
76 rtc::ArrayView<const float> output, 76 rtc::ArrayView<const float> reference,
77 float tolerance) { 77 rtc::ArrayView<const float> output,
78 float element_error_bound) {
78 // Form vectors to compare the reference to. Only the first values of the 79 // Form vectors to compare the reference to. Only the first values of the
79 // outputs are compared in order not having to specify all preceeding frames 80 // outputs are compared in order not having to specify all preceeding frames
80 // as testvectors. 81 // as testvectors.
81 const size_t reference_frame_length = 82 const size_t reference_frame_length =
82 rtc::CheckedDivExact(reference.size(), num_channels); 83 rtc::CheckedDivExact(reference.size(), num_channels);
83 84
84 std::vector<float> output_to_verify; 85 std::vector<float> output_to_verify;
85 for (size_t channel_no = 0; channel_no < num_channels; ++channel_no) { 86 for (size_t channel_no = 0; channel_no < num_channels; ++channel_no) {
86 output_to_verify.insert(output_to_verify.end(), 87 output_to_verify.insert(output_to_verify.end(),
87 output.begin() + channel_no * samples_per_channel, 88 output.begin() + channel_no * samples_per_channel,
88 output.begin() + channel_no * samples_per_channel + 89 output.begin() + channel_no * samples_per_channel +
89 reference_frame_length); 90 reference_frame_length);
90 } 91 }
91 92
92 return BitExactVector(reference, output_to_verify, tolerance); 93 return VectorDifferenceBounded(reference, output_to_verify,
94 element_error_bound);
93 } 95 }
94 96
95 ::testing::AssertionResult BitExactVector(rtc::ArrayView<const float> reference, 97 ::testing::AssertionResult VectorDifferenceBounded(
96 rtc::ArrayView<const float> output, 98 rtc::ArrayView<const float> reference,
97 float tolerance) { 99 rtc::ArrayView<const float> output,
100 float element_error_bound) {
98 // The vectors are deemed to be bitexact only if 101 // The vectors are deemed to be bitexact only if
99 // a) output have a size at least as long as the reference. 102 // a) output have a size at least as long as the reference.
100 // b) the samples in the reference are bitexact with the corresponding samples 103 // b) the samples in the reference are bitexact with the corresponding samples
101 // in the output. 104 // in the output.
102 105
103 bool equal = true; 106 bool equal = true;
104 if (output.size() < reference.size()) { 107 if (output.size() < reference.size()) {
105 equal = false; 108 equal = false;
106 } else { 109 } else {
107 // Compare the first samples in the vectors. 110 // Compare the first samples in the vectors.
108 for (size_t k = 0; k < reference.size(); ++k) { 111 for (size_t k = 0; k < reference.size(); ++k) {
109 if (fabs(output[k] - reference[k]) > tolerance) { 112 if (fabs(output[k] - reference[k]) > element_error_bound) {
110 equal = false; 113 equal = false;
111 break; 114 break;
112 } 115 }
113 } 116 }
114 } 117 }
115 118
116 if (equal) { 119 if (equal) {
117 return ::testing::AssertionSuccess(); 120 return ::testing::AssertionSuccess();
118 } 121 }
119 122
(...skipping 16 matching lines...) Expand all
136 << " Actual values : " 139 << " Actual values : "
137 << print_vector_in_c_format(output, 140 << print_vector_in_c_format(output,
138 std::min(output.size(), reference.size())) 141 std::min(output.size(), reference.size()))
139 << std::endl 142 << std::endl
140 << " Expected values: " 143 << " Expected values: "
141 << print_vector_in_c_format(reference, reference.size()) << std::endl; 144 << print_vector_in_c_format(reference, reference.size()) << std::endl;
142 } 145 }
143 146
144 } // namespace test 147 } // namespace test
145 } // namespace webrtc 148 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698