Added a bitexactness test for the noise suppressor.
This CL also extracts part of the functionality used
in the bitexactness test for the high-pass filter into
a separate file in order to be able to reuse that
functionality in bitexactness tests for the other
submodules in APM (including the bitexactness test for
the noise suppressor).
BUG=wertc:5336
Review URL: https://codereview.webrtc.org/1783203002
Cr-Commit-Position: refs/heads/master@{#12061}
diff --git a/webrtc/modules/audio_processing/high_pass_filter_bitexactness_unittest.cc b/webrtc/modules/audio_processing/high_pass_filter_bitexactness_unittest.cc
index 161677b..ba53bfa 100644
--- a/webrtc/modules/audio_processing/high_pass_filter_bitexactness_unittest.cc
+++ b/webrtc/modules/audio_processing/high_pass_filter_bitexactness_unittest.cc
@@ -14,52 +14,11 @@
#include "webrtc/modules/audio_processing/audio_buffer.h"
#include "webrtc/modules/audio_processing/high_pass_filter_impl.h"
#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
namespace webrtc {
namespace {
-// Test to see whether two vectors are identical and report any
-// differences.
-::testing::AssertionResult AssertVectorsNotEqual(
- const char* m_expr,
- const char* n_expr,
- const std::vector<float>& output,
- const std::vector<float>& reference) {
- // Compare the output in the reference in a soft manner.
- bool equal = true;
- const float threshold = 1.0f / 32768.0f;
- for (size_t k = 0; k < reference.size(); ++k) {
- if (fabs(output[k] - reference[k]) > threshold) {
- equal = false;
- break;
- }
- }
-
- // If the vectors are deemed not to be similar, return a report of the
- // difference.
- if (!equal) {
- // Lambda function that produces a formatted string with the data in the
- // vector.
- auto print_vector_in_c_format = [](std::vector<float> v,
- size_t num_values_to_print) {
- std::string s = "{ ";
- for (size_t k = 0; k < num_values_to_print; ++k) {
- s += std::to_string(v[k]) + "f";
- s += (k < (num_values_to_print - 1)) ? ", " : "";
- }
- return s + " }";
- };
-
- return ::testing::AssertionFailure()
- << "Actual: " << print_vector_in_c_format(output, reference.size())
- << std::endl
- << std::endl
- << "Expected: "
- << print_vector_in_c_format(reference, reference.size())
- << std::endl;
- }
- return ::testing::AssertionSuccess();
-}
// Process one frame of data and produce the output.
std::vector<float> ProcessOneFrame(const std::vector<float>& frame_input,
@@ -72,8 +31,9 @@
test::CopyVectorToAudioBuffer(stream_config, frame_input, &audio_buffer);
high_pass_filter->ProcessCaptureAudio(&audio_buffer);
- std::vector<float> frame_output =
- test::ExtractVectorFromAudioBuffer(stream_config, &audio_buffer);
+ std::vector<float> frame_output;
+ test::ExtractVectorFromAudioBuffer(stream_config, &audio_buffer,
+ &frame_output);
return frame_output;
}
@@ -122,7 +82,9 @@
reference_frame_length);
}
- EXPECT_PRED_FORMAT2(AssertVectorsNotEqual, output_to_verify, reference);
+ const float kTolerance = 1.0f / 32768.0f;
+ EXPECT_TRUE(test::BitExactFrame(reference_frame_length, num_channels,
+ reference, output_to_verify, kTolerance));
}
// Method for forming a vector out of an array.
diff --git a/webrtc/modules/audio_processing/noise_suppression_bitexactness_unittest.cc b/webrtc/modules/audio_processing/noise_suppression_bitexactness_unittest.cc
new file mode 100644
index 0000000..38551d3
--- /dev/null
+++ b/webrtc/modules/audio_processing/noise_suppression_bitexactness_unittest.cc
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include <vector>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/array_view.h"
+#include "webrtc/modules/audio_processing/audio_buffer.h"
+#include "webrtc/modules/audio_processing/noise_suppression_impl.h"
+#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
+
+namespace webrtc {
+namespace {
+
+const int kNumFramesToProcess = 1000;
+
+// Process one frame of data and produce the output.
+void ProcessOneFrame(int sample_rate_hz,
+ AudioBuffer* capture_buffer,
+ NoiseSuppressionImpl* noise_suppressor) {
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
+ capture_buffer->SplitIntoFrequencyBands();
+ }
+
+ noise_suppressor->AnalyzeCaptureAudio(capture_buffer);
+ noise_suppressor->ProcessCaptureAudio(capture_buffer);
+
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
+ capture_buffer->MergeFrequencyBands();
+ }
+}
+
+// Processes a specified amount of frames, verifies the results and reports
+// any errors.
+void RunBitexactnessTest(int sample_rate_hz,
+ size_t num_channels,
+ NoiseSuppressionImpl::Level level,
+ float speech_probability_reference,
+ rtc::ArrayView<const float> noise_estimate_reference,
+ rtc::ArrayView<const float> output_reference) {
+ rtc::CriticalSection crit_capture;
+ NoiseSuppressionImpl noise_suppressor(&crit_capture);
+ noise_suppressor.Initialize(num_channels, sample_rate_hz);
+ noise_suppressor.Enable(true);
+ noise_suppressor.set_level(level);
+
+ int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
+ const StreamConfig capture_config(sample_rate_hz, num_channels, false);
+ AudioBuffer capture_buffer(
+ capture_config.num_frames(), capture_config.num_channels(),
+ capture_config.num_frames(), capture_config.num_channels(),
+ capture_config.num_frames());
+ test::InputAudioFile capture_file(
+ test::GetApmCaptureTestVectorFileName(sample_rate_hz));
+ std::vector<float> capture_input(samples_per_channel * num_channels);
+ for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
+ ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
+ &capture_file, capture_input);
+
+ test::CopyVectorToAudioBuffer(capture_config, capture_input,
+ &capture_buffer);
+
+ ProcessOneFrame(sample_rate_hz, &capture_buffer, &noise_suppressor);
+ }
+
+ // Extract test results.
+ std::vector<float> capture_output;
+ test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
+ &capture_output);
+ float speech_probability = noise_suppressor.speech_probability();
+ std::vector<float> noise_estimate = noise_suppressor.NoiseEstimate();
+
+ const float kTolerance = 1.0f / 32768.0f;
+ EXPECT_FLOAT_EQ(speech_probability_reference, speech_probability);
+ EXPECT_TRUE(test::BitExactVector(noise_estimate_reference, noise_estimate,
+ kTolerance));
+
+ // Compare the output with the reference. Only the first values of the output
+ // from last frame processed are compared in order not having to specify all
+ // preceeding frames as testvectors. As the algorithm being tested has a
+ // memory, testing only the last frame implicitly also tests the preceeding
+ // frames.
+ EXPECT_TRUE(test::BitExactFrame(
+ capture_config.num_frames(), capture_config.num_channels(),
+ output_reference, capture_output, kTolerance));
+}
+
+} // namespace
+
+TEST(NoiseSuppresionBitExactnessTest, Mono8kHzLow) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.797542f, 6.488125f, 14.995160f};
+ const float kOutputReference[] = {0.003510f, 0.004517f, 0.004669f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.797542f, 6.488125f, 14.995160f};
+ const float kOutputReference[] = {0.003510f, 0.004517f, 0.004669f};
+#else
+ const float kSpeechProbabilityReference = 0.73421317f;
+ const float kNoiseEstimateReference[] = {0.035866f, 0.100382f, 0.229889f};
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+#endif
+
+ RunBitexactnessTest(8000, 1, NoiseSuppression::Level::kLow,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono16kHzLow) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.475060f, 6.130507f, 14.030761f};
+ const float kOutputReference[] = {0.003449f, 0.004334f, 0.004303f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.475060f, 6.130507f, 14.030761f};
+ const float kOutputReference[] = {0.003449f, 0.004334f, 0.004303f};
+#else
+ const float kSpeechProbabilityReference = 0.71672988f;
+ const float kNoiseEstimateReference[] = {0.065653f, 0.198662f, 0.477870f};
+ const float kOutputReference[] = {0.003574f, 0.004494f, 0.004499f};
+#endif
+
+ RunBitexactnessTest(16000, 1, NoiseSuppression::Level::kLow,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono32kHzLow) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.480526f, 6.169749f, 14.102388f};
+ const float kOutputReference[] = {0.001679f, 0.002411f, 0.002594f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.480526f, 6.169749f, 14.102388f};
+ const float kOutputReference[] = {0.001679f, 0.002411f, 0.002594f};
+#else
+ const float kSpeechProbabilityReference = 0.67999554f;
+ const float kNoiseEstimateReference[] = {0.065606f, 0.215971f, 0.455931f};
+ const float kOutputReference[] = {0.001221f, 0.001984f, 0.002228f};
+#endif
+
+ RunBitexactnessTest(32000, 1, NoiseSuppression::Level::kLow,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono48kHzLow) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.504498f, 6.068024f, 13.058871f};
+ const float kOutputReference[] = {-0.013185f, -0.012769f, -0.012023f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.504498f, 6.068024f, 13.058871f};
+ const float kOutputReference[] = {-0.013185f, -0.012769f, -0.012023f};
+#else
+ const float kSpeechProbabilityReference = 0.70645678f;
+ const float kNoiseEstimateReference[] = {0.066186f, 0.210660f, 0.402548f};
+ const float kOutputReference[] = {-0.013062f, -0.012657f, -0.011934f};
+#endif
+
+ RunBitexactnessTest(48000, 1, NoiseSuppression::Level::kLow,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Stereo16kHzLow) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {9.757937f, 12.392158f, 11.317673f};
+ const float kOutputReference[] = {-0.011108f, -0.007904f, -0.012390f,
+ -0.002441f, 0.000855f, -0.003204f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {10.079447f, 11.849465f, 10.667051f};
+ const float kOutputReference[] = {-0.011108f, -0.007904f, -0.012390f,
+ -0.002472f, 0.000916f, -0.003235f};
+#else
+ const float kSpeechProbabilityReference = 0.67230678f;
+ const float kNoiseEstimateReference[] = {0.298195f, 0.345745f, 0.320528f};
+ const float kOutputReference[] = {-0.011459f, -0.008110f, -0.012728f,
+ -0.002399f, 0.001018f, -0.003189f};
+#endif
+
+ RunBitexactnessTest(16000, 2, NoiseSuppression::Level::kLow,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono16kHzModerate) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {1.004436f, 3.711453f, 9.602631f};
+ const float kOutputReference[] = {0.004669f, 0.005524f, 0.005432f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {1.095946f, 3.351643f, 8.167248f};
+ const float kOutputReference[] = {0.004669f, 0.005615f, 0.005585f};
+#else
+ const float kSpeechProbabilityReference = 0.70897013f;
+ const float kNoiseEstimateReference[] = {0.066269f, 0.199999f, 0.476885f};
+ const float kOutputReference[] = {0.004513f, 0.005590f, 0.005614f};
+#endif
+
+ RunBitexactnessTest(16000, 1, NoiseSuppression::Level::kModerate,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono16kHzHigh) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {1.023022f, 3.759059f, 9.614030f};
+ const float kOutputReference[] = {0.004639f, 0.005402f, 0.005310f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {1.114510f, 3.410356f, 8.262188f};
+ const float kOutputReference[] = {0.004547f, 0.005432f, 0.005402f};
+#else
+ const float kSpeechProbabilityReference = 0.70106733f;
+ const float kNoiseEstimateReference[] = {0.067901f, 0.204835f, 0.481723f};
+ const float kOutputReference[] = {0.004394f, 0.005406f, 0.005416f};
+#endif
+
+ RunBitexactnessTest(16000, 1, NoiseSuppression::Level::kHigh,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+TEST(NoiseSuppresionBitExactnessTest, Mono16kHzVeryHigh) {
+#if defined(WEBRTC_ARCH_ARM64)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.614974f, 6.041980f, 14.029047f};
+ const float kOutputReference[] = {0.004273f, 0.005127f, 0.005188f};
+#elif defined(WEBRTC_ARCH_ARM)
+ const float kSpeechProbabilityReference = -4.0f;
+ const float kNoiseEstimateReference[] = {2.614974f, 6.041980f, 14.029047f};
+ const float kOutputReference[] = {0.004273f, 0.005127f, 0.005188f};
+#else
+ const float kSpeechProbabilityReference = 0.70281971f;
+ const float kNoiseEstimateReference[] = {0.068797f, 0.205191f, 0.481312f};
+ const float kOutputReference[] = {0.004321f, 0.005247f, 0.005263f};
+#endif
+
+ RunBitexactnessTest(16000, 1, NoiseSuppression::Level::kVeryHigh,
+ kSpeechProbabilityReference, kNoiseEstimateReference,
+ kOutputReference);
+}
+
+} // namespace webrtc
diff --git a/webrtc/modules/audio_processing/test/audio_buffer_tools.cc b/webrtc/modules/audio_processing/test/audio_buffer_tools.cc
index a8cb09c..46ee61d 100644
--- a/webrtc/modules/audio_processing/test/audio_buffer_tools.cc
+++ b/webrtc/modules/audio_processing/test/audio_buffer_tools.cc
@@ -10,10 +10,12 @@
#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
+#include <string.h>
+
namespace webrtc {
namespace test {
-void SetupFrame(StreamConfig stream_config,
+void SetupFrame(const StreamConfig& stream_config,
std::vector<float*>* frame,
std::vector<float>* frame_samples) {
frame_samples->resize(stream_config.num_channels() *
@@ -25,30 +27,28 @@
}
void CopyVectorToAudioBuffer(const StreamConfig& stream_config,
- const std::vector<float>& source,
+ rtc::ArrayView<const float> source,
AudioBuffer* destination) {
std::vector<float*> input;
std::vector<float> input_samples;
SetupFrame(stream_config, &input, &input_samples);
- RTC_DCHECK_EQ(input_samples.size(), source.size());
- input_samples = source;
+ RTC_CHECK_EQ(input_samples.size(), source.size());
+ memcpy(input_samples.data(), source.data(),
+ source.size() * sizeof(source[0]));
destination->CopyFrom(&input[0], stream_config);
}
-std::vector<float> ExtractVectorFromAudioBuffer(
- const StreamConfig& stream_config,
- AudioBuffer* source) {
+void ExtractVectorFromAudioBuffer(const StreamConfig& stream_config,
+ AudioBuffer* source,
+ std::vector<float>* destination) {
std::vector<float*> output;
- std::vector<float> output_samples;
- SetupFrame(stream_config, &output, &output_samples);
+ SetupFrame(stream_config, &output, destination);
source->CopyTo(stream_config, &output[0]);
-
- return output_samples;
}
} // namespace test
diff --git a/webrtc/modules/audio_processing/test/audio_buffer_tools.h b/webrtc/modules/audio_processing/test/audio_buffer_tools.h
index 654691c..1fac758 100644
--- a/webrtc/modules/audio_processing/test/audio_buffer_tools.h
+++ b/webrtc/modules/audio_processing/test/audio_buffer_tools.h
@@ -12,6 +12,7 @@
#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_BUFFER_TOOLS_H_
#include <vector>
+#include "webrtc/base/array_view.h"
#include "webrtc/modules/audio_processing/audio_buffer.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
@@ -20,13 +21,13 @@
// Copies a vector into an audiobuffer.
void CopyVectorToAudioBuffer(const StreamConfig& stream_config,
- const std::vector<float>& source,
+ rtc::ArrayView<const float> source,
AudioBuffer* destination);
// Extracts a vector from an audiobuffer.
-std::vector<float> ExtractVectorFromAudioBuffer(
- const StreamConfig& stream_config,
- AudioBuffer* source);
+void ExtractVectorFromAudioBuffer(const StreamConfig& stream_config,
+ AudioBuffer* source,
+ std::vector<float>* destination);
} // namespace test
} // namespace webrtc
diff --git a/webrtc/modules/audio_processing/test/bitexactness_tools.cc b/webrtc/modules/audio_processing/test/bitexactness_tools.cc
new file mode 100644
index 0000000..965820c
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/bitexactness_tools.cc
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
+
+#include <math.h>
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include "webrtc/base/array_view.h"
+#include "webrtc/test/testsupport/fileutils.h"
+
+namespace webrtc {
+namespace test {
+
+std::string GetApmRenderTestVectorFileName(int sample_rate_hz) {
+ switch (sample_rate_hz) {
+ case 8000:
+ return ResourcePath("far8_stereo", "pcm");
+ case 16000:
+ return ResourcePath("far16_stereo", "pcm");
+ case 32000:
+ return ResourcePath("far32_stereo", "pcm");
+ case 48000:
+ return ResourcePath("far48_stereo", "pcm");
+ default:
+ RTC_DCHECK(false);
+ }
+ return "";
+}
+
+std::string GetApmCaptureTestVectorFileName(int sample_rate_hz) {
+ switch (sample_rate_hz) {
+ case 8000:
+ return ResourcePath("near8_stereo", "pcm");
+ case 16000:
+ return ResourcePath("near16_stereo", "pcm");
+ case 32000:
+ return ResourcePath("near32_stereo", "pcm");
+ case 48000:
+ return ResourcePath("near48_stereo", "pcm");
+ default:
+ RTC_DCHECK(false);
+ }
+ return "";
+}
+
+void ReadFloatSamplesFromStereoFile(size_t samples_per_channel,
+ size_t num_channels,
+ InputAudioFile* stereo_pcm_file,
+ rtc::ArrayView<float> data) {
+ RTC_DCHECK_EQ(data.size(), samples_per_channel * num_channels);
+ std::vector<int16_t> read_samples(samples_per_channel * 2);
+ stereo_pcm_file->Read(samples_per_channel * 2, read_samples.data());
+
+ // Convert samples to float and discard any channels not needed.
+ for (size_t sample = 0; sample < samples_per_channel; ++sample) {
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ data[sample * num_channels + channel] =
+ read_samples[sample * 2 + channel] / 32768.0f;
+ }
+ }
+}
+
+::testing::AssertionResult BitExactFrame(size_t samples_per_channel,
+ size_t num_channels,
+ rtc::ArrayView<const float> reference,
+ rtc::ArrayView<const float> output,
+ float tolerance) {
+ // Form vectors to compare the reference to. Only the first values of the
+ // outputs are compared in order not having to specify all preceeding frames
+ // as testvectors.
+ const size_t reference_frame_length =
+ rtc::CheckedDivExact(reference.size(), num_channels);
+
+ std::vector<float> output_to_verify;
+ for (size_t channel_no = 0; channel_no < num_channels; ++channel_no) {
+ output_to_verify.insert(output_to_verify.end(),
+ output.begin() + channel_no * samples_per_channel,
+ output.begin() + channel_no * samples_per_channel +
+ reference_frame_length);
+ }
+
+ return BitExactVector(reference, output_to_verify, tolerance);
+}
+
+::testing::AssertionResult BitExactVector(rtc::ArrayView<const float> reference,
+ rtc::ArrayView<const float> output,
+ float tolerance) {
+ // The vectors are deemed to be bitexact only if
+ // a) output have a size at least as long as the reference.
+ // b) the samples in the reference are bitexact with the corresponding samples
+ // in the output.
+
+ bool equal = true;
+ if (output.size() < reference.size()) {
+ equal = false;
+ } else {
+ // Compare the first samples in the vectors.
+ for (size_t k = 0; k < reference.size(); ++k) {
+ if (fabs(output[k] - reference[k]) > tolerance) {
+ equal = false;
+ break;
+ }
+ }
+ }
+
+ if (equal) {
+ return ::testing::AssertionSuccess();
+ }
+
+ // Lambda function that produces a formatted string with the data in the
+ // vector.
+ auto print_vector_in_c_format = [](rtc::ArrayView<const float> v,
+ size_t num_values_to_print) {
+ std::string s = "{ ";
+ for (size_t k = 0; k < std::min(num_values_to_print, v.size()); ++k) {
+ s += std::to_string(v[k]) + "f";
+ s += (k < (num_values_to_print - 1)) ? ", " : "";
+ }
+ return s + " }";
+ };
+
+ // If the vectors are deemed not to be similar, return a report of the
+ // difference.
+ return ::testing::AssertionFailure()
+ << std::endl
+ << " Actual values : "
+ << print_vector_in_c_format(output,
+ std::min(output.size(), reference.size()))
+ << std::endl
+ << " Expected values: "
+ << print_vector_in_c_format(reference, reference.size()) << std::endl;
+}
+
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/modules/audio_processing/test/bitexactness_tools.h b/webrtc/modules/audio_processing/test/bitexactness_tools.h
new file mode 100644
index 0000000..a66a3f4
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/bitexactness_tools.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_BITEXACTNESS_TOOLS_H_
+#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_BITEXACTNESS_TOOLS_H_
+
+#include <string>
+
+#include "webrtc/base/array_view.h"
+#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace webrtc {
+namespace test {
+
+// Returns test vector to use for the render signal in an
+// APM bitexactness test.
+std::string GetApmRenderTestVectorFileName(int sample_rate_hz);
+
+// Returns test vector to use for the capture signal in an
+// APM bitexactness test.
+std::string GetApmCaptureTestVectorFileName(int sample_rate_hz);
+
+// Extract float samples from a pcm file.
+void ReadFloatSamplesFromStereoFile(size_t samples_per_channel,
+ size_t num_channels,
+ InputAudioFile* stereo_pcm_file,
+ rtc::ArrayView<float> data);
+
+// Verifies a frame against a reference and returns the results as an
+// AssertionResult.
+::testing::AssertionResult BitExactFrame(size_t samples_per_channel,
+ size_t num_channels,
+ rtc::ArrayView<const float> reference,
+ rtc::ArrayView<const float> output,
+ float tolerance);
+
+// Verifies a vector against a reference and returns the results as an
+// AssertionResult.
+::testing::AssertionResult BitExactVector(rtc::ArrayView<const float> reference,
+ rtc::ArrayView<const float> output,
+ float tolerance);
+
+} // namespace test
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_BITEXACTNESS_TOOLS_H_
diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp
index 5abf6af..596ffc7 100644
--- a/webrtc/modules/modules.gyp
+++ b/webrtc/modules/modules.gyp
@@ -441,9 +441,12 @@
'audio_processing/audio_processing_impl_locking_unittest.cc',
'audio_processing/audio_processing_impl_unittest.cc',
'audio_processing/high_pass_filter_bitexactness_unittest.cc',
+ 'audio_processing/noise_suppression_bitexactness_unittest.cc',
'audio_processing/test/audio_buffer_tools.cc',
'audio_processing/test/audio_buffer_tools.h',
'audio_processing/test/audio_processing_unittest.cc',
+ 'audio_processing/test/bitexactness_tools.cc',
+ 'audio_processing/test/bitexactness_tools.h',
'audio_processing/test/debug_dump_replayer.cc',
'audio_processing/test/debug_dump_replayer.h',
'audio_processing/test/debug_dump_test.cc',