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

Unified Diff: webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc

Issue 2774423005: Conversational Speech tool, WavReaderAdaptor and unit test (Closed)
Patch Set: Created 3 years, 9 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: webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc
diff --git a/webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc b/webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc
index 1b06b0ae9b62799803f6d803ca04a9c111a0c3ce..f13c19a31c033dc5b2e634d1a5c539b627473240 100644
--- a/webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc
+++ b/webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc
@@ -33,15 +33,20 @@
// cases in which there are wrong offsets leading to self cross-talk (which is
// rejected).
+#define _USE_MATH_DEFINES
kwiberg-webrtc 2017/03/28 17:52:45 A comment on what effect this has, and on which he
AleBzk 2017/03/29 08:56:44 Done.
+
#include <stdio.h>
+#include <cmath>
#include <map>
#include <memory>
#include "webrtc/base/logging.h"
+#include "webrtc/base/pathutils.h"
#include "webrtc/modules/audio_processing/test/conversational_speech/config.h"
#include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.h"
#include "webrtc/modules/audio_processing/test/conversational_speech/multiend_call.h"
#include "webrtc/modules/audio_processing/test/conversational_speech/timing.h"
+#include "webrtc/modules/audio_processing/test/conversational_speech/wavreader_adaptor.h"
#include "webrtc/test/gmock.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/testsupport/fileutils.h"
@@ -56,6 +61,7 @@ using conversational_speech::MockWavReaderFactory;
using conversational_speech::MultiEndCall;
using conversational_speech::Turn;
using conversational_speech::WavReaderAbstractFactory;
+using conversational_speech::WavReaderAdaptor;
const char* const audiotracks_path = "/path/to/audiotracks";
const char* const timing_filepath = "/path/to/timing_file.txt";
@@ -95,6 +101,23 @@ std::unique_ptr<MockWavReaderFactory> CreateMockWavReaderFactory() {
kDefaultMockWavReaderFactoryParamsMap));
}
+void CreateSineWavFile(const std::string& filepath,
+ const MockWavReaderFactory::Params& params,
+ float frequency = 440.0f) {
+ // Create samples.
+ const double two_pi = 2.0 * M_PI;
kwiberg-webrtc 2017/03/28 17:52:45 constexpr
AleBzk 2017/03/29 08:56:44 Done.
+ std::unique_ptr<int16_t[]> samples(new int16_t[params.num_samples]);
kwiberg-webrtc 2017/03/28 17:52:45 It's easier to avoid bugs if you use e.g. a std::v
AleBzk 2017/03/29 08:56:44 Done.
+ for (std::size_t i = 0; i < params.num_samples; ++i) {
+ // TODO(alessiob): the produced tone is not pure, improve.
+ samples[i] = std::lround(32767.0f * std::sin(
+ two_pi * i * frequency / params.sample_rate));
+ }
+
+ // Write samples.
+ WavWriter wav_writer(filepath, params.sample_rate, params.num_channels);
+ wav_writer.WriteSamples(samples.get(), params.num_samples);
+}
+
} // namespace
class ConversationalSpeechTest : public testing::Test {
@@ -435,5 +458,33 @@ TEST_F(ConversationalSpeechTest, MultiEndCallSetupLongSequenceInvalid) {
EXPECT_FALSE(multiend_call.valid());
}
+TEST_F(ConversationalSpeechTest, MultiEndCallWavReaderAdaptorSine) {
+ // Parameters with which wav files are created.
+ constexpr int duration_seconds = 5;
+ const int sample_rates[] = {8000, 11025, 16000, 22050, 32000, 44100, 48000};
+
+ for (int sample_rate : sample_rates) {
+ const rtc::Pathname temp_filename(
+ OutputPath(), "TempSineWavFile_" + std::to_string(sample_rate)
+ + ".wav");
+
+ // Write wav file.
+ std::size_t num_samples = duration_seconds * sample_rate;
kwiberg-webrtc 2017/03/28 17:52:44 const?
AleBzk 2017/03/29 08:56:44 Done.
+ MockWavReaderFactory::Params params = {sample_rate, 1u, num_samples};
+ CreateSineWavFile(temp_filename.pathname(), params);
+ LOG(LS_VERBOSE) << "wav file @" << sample_rate << " Hz created ("
+ << num_samples << " samples)";
+
+ // Load wav file and check if params match.
+ WavReaderAdaptor wav_reader_adaptor(temp_filename.pathname());
+ EXPECT_EQ(sample_rate, wav_reader_adaptor.sample_rate());
+ EXPECT_EQ(1u, wav_reader_adaptor.num_channels());
+ EXPECT_EQ(num_samples, wav_reader_adaptor.num_samples());
+
+ // Clean up.
+ remove(temp_filename.pathname().c_str());
+ }
+}
+
} // namespace test
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698