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

Unified Diff: media/base/multi_channel_resampler_unittest.cc

Issue 10701049: Add MultiChannelResampler wrapper for SincResampler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial Commit! Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: media/base/multi_channel_resampler_unittest.cc
diff --git a/media/base/multi_channel_resampler_unittest.cc b/media/base/multi_channel_resampler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..30d1266b37938e77d4e8d1d1048472b7eb8f61b2
--- /dev/null
+++ b/media/base/multi_channel_resampler_unittest.cc
@@ -0,0 +1,149 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/base/multi_channel_resampler.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+// Just test a basic resampling case. The SincResampler unit test will take
+// care of accuracy testing; we just need to check that multichannel works as
+// expected within some tolerance.
+static const float kScaleFactor = 44100.0 / 48000.0;
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 probably need 'f's to disambiguate double-vs-float
DaleCurtis 2012/07/03 03:02:57 Done.
+
+// Simulate large and small sample requests used by the different audio paths.
+static const int kHighLatencySize = 8192;
+// Low latency buffers show a larger error than high latency ones. Which makes
+// sense since each error represents a larger portion of the total request.
+static const int kLowLatencySize = 128;
+
+// Test fill value.
+static const float kFillValue = 0.1;
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 needs 'f' suffix
DaleCurtis 2012/07/03 03:02:57 Done.
+
+// Chosen arbitrarily on what each resampler reported during testing.
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 s/on/based on/
DaleCurtis 2012/07/03 03:02:57 Done.
+static const double kLowLatencyMaxRMSError = 0.001;
+static const double kLowLatencyMaxError = 0.0068;
+static const double kHighLatencyMaxRMSError = 0.00013;
+static const double kHighLatencyMaxError = 0.0068;
+
+
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 extra \n
DaleCurtis 2012/07/03 03:02:57 Done.
+class MultiChannelProviderTest
+ : public MultiChannelResampler::MultiChannelAudioSourceProvider,
+ public ::testing::Test {
+ public:
+ MultiChannelProviderTest() {}
+ virtual ~MultiChannelProviderTest() {
+ if (!audio_data_.empty()) {
+ for (size_t i = 0; i < audio_data_.size(); ++i)
+ delete [] audio_data_[i];
+ audio_data_.clear();
+ }
+ }
+
+ void InitializeAudioData(int channels, int frames) {
+ frames_ = frames;
+ audio_data_.reserve(channels);
+ for (int i = 0; i < channels; ++i) {
+ audio_data_.push_back(new float[frames]);
+
+ // Zero initialize so we can be sure every value has been provided.
+ memset(audio_data_[i], 0, sizeof(*audio_data_[i]) * frames);
+ }
+ }
+
+ // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just
+ // fills the provided audio_data with |kFillValue|.
+ virtual void ProvideInput(const std::vector<float*>& audio_data,
+ int number_of_frames) OVERRIDE {
+ EXPECT_EQ(audio_data.size(), audio_data_.size());
+ for (size_t i = 0; i < audio_data.size(); ++i)
+ for (int j = 0; j < number_of_frames; ++j)
+ audio_data[i][j] = kFillValue;
+ }
+
+ void MultiChannelTest(int channels, int frames, double expected_max_rms_error,
+ double expected_max_error) {
+ InitializeAudioData(channels, frames);
+ scoped_ptr<MultiChannelResampler> resampler(new MultiChannelResampler(
+ this, kScaleFactor, channels));
+ resampler->Resample(audio_data_, frames);
+ TestValues(expected_max_rms_error, expected_max_error);
+ }
+
+ void HighLatencyTest(int channels) {
+ MultiChannelTest(channels, kHighLatencySize, kHighLatencyMaxRMSError,
+ kHighLatencyMaxError);
+ }
+
+ void LowLatencyTest(int channels) {
+ MultiChannelTest(channels, kLowLatencySize, kLowLatencyMaxRMSError,
+ kLowLatencyMaxError);
+ }
+
+ void TestValues(double expected_max_rms_error, double expected_max_error ) {
+ // Calculate Root-Mean-Square-Error for the resampling.
+ double max_error = 0.0;
+ double sum_of_squares = 0.0;
+ for (size_t i = 0; i < audio_data_.size(); ++i) {
+ for (int j = 0; j < frames_; ++j) {
+ // Ensure all values are accounted for.
+ ASSERT_NE(audio_data_[i][j], 0);
+
+ double error = fabs(audio_data_[i][j] - kFillValue);
+ max_error = std::max(max_error, error);
+ sum_of_squares += error * error;
+ }
+ }
+
+ double rms_error = sqrt(
+ sum_of_squares / (frames_ * audio_data_.size()));
+
+ EXPECT_LE(rms_error, expected_max_rms_error);
+ EXPECT_LE(max_error, expected_max_error);
+ }
+
+ protected:
+ int frames_;
+ std::vector<float*> audio_data_;
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 scoped* to avoid dtor work
DaleCurtis 2012/07/03 03:02:57 Can't due to RenderCallback interface.
+
+ DISALLOW_COPY_AND_ASSIGN(MultiChannelProviderTest);
+};
+
+TEST_F(MultiChannelProviderTest, MultiChannel_1_HighLatency) {
Ami GONE FROM CHROMIUM 2012/06/30 20:12:14 Any reason not to use parameterized gtest?
DaleCurtis 2012/07/03 03:02:57 Done.
+ HighLatencyTest(1);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_2_HighLatency) {
+ HighLatencyTest(2);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_6_HighLatency) {
+ HighLatencyTest(6);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_8_HighLatency) {
+ HighLatencyTest(8);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_1_LowLatency) {
+ LowLatencyTest(1);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_2_LowLatency) {
+ LowLatencyTest(2);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_6_LowLatency) {
+ LowLatencyTest(6);
+}
+
+TEST_F(MultiChannelProviderTest, MultiChannel_8_LowLatency) {
+ LowLatencyTest(8);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698