| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 15 matching lines...) Expand all Loading... |
| 26 // - A is the first speaking, B is the second one, | 26 // - A is the first speaking, B is the second one, |
| 27 // - each character after the speaker's letter indicates a time unit (e.g., 100 | 27 // - each character after the speaker's letter indicates a time unit (e.g., 100 |
| 28 // ms), | 28 // ms), |
| 29 // - "*" indicates speaking, "." listening, | 29 // - "*" indicates speaking, "." listening, |
| 30 // - numbers indicate the turn index in std::vector<Turn>. | 30 // - numbers indicate the turn index in std::vector<Turn>. |
| 31 // | 31 // |
| 32 // Note that the same speaker can appear in multiple lines in order to depict | 32 // Note that the same speaker can appear in multiple lines in order to depict |
| 33 // cases in which there are wrong offsets leading to self cross-talk (which is | 33 // cases in which there are wrong offsets leading to self cross-talk (which is |
| 34 // rejected). | 34 // rejected). |
| 35 | 35 |
| 36 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 37 #define _USE_MATH_DEFINES |
| 38 |
| 36 #include <stdio.h> | 39 #include <stdio.h> |
| 40 #include <cmath> |
| 37 #include <map> | 41 #include <map> |
| 38 #include <memory> | 42 #include <memory> |
| 39 | 43 |
| 40 #include "webrtc/base/logging.h" | 44 #include "webrtc/base/logging.h" |
| 45 #include "webrtc/base/pathutils.h" |
| 46 #include "webrtc/common_audio/wav_file.h" |
| 41 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" | 47 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" |
| 42 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der_factory.h" | 48 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der_factory.h" |
| 43 #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_ca
ll.h" | 49 #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_ca
ll.h" |
| 44 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" | 50 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" |
| 51 #include "webrtc/modules/audio_processing/test/conversational_speech/wavreader_f
actory.h" |
| 45 #include "webrtc/test/gmock.h" | 52 #include "webrtc/test/gmock.h" |
| 46 #include "webrtc/test/gtest.h" | 53 #include "webrtc/test/gtest.h" |
| 47 #include "webrtc/test/testsupport/fileutils.h" | 54 #include "webrtc/test/testsupport/fileutils.h" |
| 48 | 55 |
| 49 namespace webrtc { | 56 namespace webrtc { |
| 50 namespace test { | 57 namespace test { |
| 51 namespace { | 58 namespace { |
| 52 | 59 |
| 53 using conversational_speech::LoadTiming; | 60 using conversational_speech::LoadTiming; |
| 54 using conversational_speech::SaveTiming; | 61 using conversational_speech::SaveTiming; |
| 55 using conversational_speech::MockWavReaderFactory; | 62 using conversational_speech::MockWavReaderFactory; |
| 56 using conversational_speech::MultiEndCall; | 63 using conversational_speech::MultiEndCall; |
| 57 using conversational_speech::Turn; | 64 using conversational_speech::Turn; |
| 58 using conversational_speech::WavReaderAbstractFactory; | 65 using conversational_speech::WavReaderFactory; |
| 59 | 66 |
| 60 const char* const audiotracks_path = "/path/to/audiotracks"; | 67 const char* const audiotracks_path = "/path/to/audiotracks"; |
| 61 const char* const timing_filepath = "/path/to/timing_file.txt"; | 68 const char* const timing_filepath = "/path/to/timing_file.txt"; |
| 62 const char* const output_path = "/path/to/output_dir"; | 69 const char* const output_path = "/path/to/output_dir"; |
| 63 | 70 |
| 64 const std::vector<Turn> expected_timing = { | 71 const std::vector<Turn> expected_timing = { |
| 65 {"A", "a1", 0}, | 72 {"A", "a1", 0}, |
| 66 {"B", "b1", 0}, | 73 {"B", "b1", 0}, |
| 67 {"A", "a2", 100}, | 74 {"A", "a2", 100}, |
| 68 {"B", "b2", -200}, | 75 {"B", "b2", -200}, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 }; | 89 }; |
| 83 const MockWavReaderFactory::Params& kDefaultMockWavReaderFactoryParams = | 90 const MockWavReaderFactory::Params& kDefaultMockWavReaderFactoryParams = |
| 84 kDefaultMockWavReaderFactoryParamsMap.at("t500"); | 91 kDefaultMockWavReaderFactoryParamsMap.at("t500"); |
| 85 | 92 |
| 86 std::unique_ptr<MockWavReaderFactory> CreateMockWavReaderFactory() { | 93 std::unique_ptr<MockWavReaderFactory> CreateMockWavReaderFactory() { |
| 87 return std::unique_ptr<MockWavReaderFactory>( | 94 return std::unique_ptr<MockWavReaderFactory>( |
| 88 new MockWavReaderFactory(kDefaultMockWavReaderFactoryParams, | 95 new MockWavReaderFactory(kDefaultMockWavReaderFactoryParams, |
| 89 kDefaultMockWavReaderFactoryParamsMap)); | 96 kDefaultMockWavReaderFactoryParamsMap)); |
| 90 } | 97 } |
| 91 | 98 |
| 99 void CreateSineWavFile(const std::string& filepath, |
| 100 const MockWavReaderFactory::Params& params, |
| 101 float frequency = 440.0f) { |
| 102 // Create samples. |
| 103 constexpr double two_pi = 2.0 * M_PI; |
| 104 std::vector<int16_t> samples(params.num_samples); |
| 105 for (std::size_t i = 0; i < params.num_samples; ++i) { |
| 106 // TODO(alessiob): the produced tone is not pure, improve. |
| 107 samples[i] = std::lround(32767.0f * std::sin( |
| 108 two_pi * i * frequency / params.sample_rate)); |
| 109 } |
| 110 |
| 111 // Write samples. |
| 112 WavWriter wav_writer(filepath, params.sample_rate, params.num_channels); |
| 113 wav_writer.WriteSamples(samples.data(), params.num_samples); |
| 114 } |
| 115 |
| 92 } // namespace | 116 } // namespace |
| 93 | 117 |
| 94 using testing::_; | 118 using testing::_; |
| 95 | 119 |
| 96 // TODO(alessiob): Remove fixture once conversational_speech fully implemented | 120 // TODO(alessiob): Remove fixture once conversational_speech fully implemented |
| 97 // and replace TEST_F with TEST. | 121 // and replace TEST_F with TEST. |
| 98 class ConversationalSpeechTest : public testing::Test { | 122 class ConversationalSpeechTest : public testing::Test { |
| 99 public: | 123 public: |
| 100 ConversationalSpeechTest() { | 124 ConversationalSpeechTest() { |
| 101 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | 125 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 kDefaultMockWavReaderFactoryParamsMap)); | 504 kDefaultMockWavReaderFactoryParamsMap)); |
| 481 | 505 |
| 482 // There are two unique audio tracks to read. | 506 // There are two unique audio tracks to read. |
| 483 EXPECT_CALL(*mock_wavreader_factory, Create(_)).Times(2); | 507 EXPECT_CALL(*mock_wavreader_factory, Create(_)).Times(2); |
| 484 | 508 |
| 485 conversational_speech::MultiEndCall multiend_call( | 509 conversational_speech::MultiEndCall multiend_call( |
| 486 timing, audiotracks_path, std::move(mock_wavreader_factory)); | 510 timing, audiotracks_path, std::move(mock_wavreader_factory)); |
| 487 EXPECT_FALSE(multiend_call.valid()); | 511 EXPECT_FALSE(multiend_call.valid()); |
| 488 } | 512 } |
| 489 | 513 |
| 514 TEST_F(ConversationalSpeechTest, MultiEndCallWavReaderAdaptorSine) { |
| 515 // Parameters with which wav files are created. |
| 516 constexpr int duration_seconds = 5; |
| 517 const int sample_rates[] = {8000, 11025, 16000, 22050, 32000, 44100, 48000}; |
| 518 |
| 519 for (int sample_rate : sample_rates) { |
| 520 const rtc::Pathname temp_filename( |
| 521 OutputPath(), "TempSineWavFile_" + std::to_string(sample_rate) |
| 522 + ".wav"); |
| 523 |
| 524 // Write wav file. |
| 525 const std::size_t num_samples = duration_seconds * sample_rate; |
| 526 MockWavReaderFactory::Params params = {sample_rate, 1u, num_samples}; |
| 527 CreateSineWavFile(temp_filename.pathname(), params); |
| 528 LOG(LS_VERBOSE) << "wav file @" << sample_rate << " Hz created (" |
| 529 << num_samples << " samples)"; |
| 530 |
| 531 // Load wav file and check if params match. |
| 532 WavReaderFactory wav_reader_factory; |
| 533 auto wav_reader = wav_reader_factory.Create(temp_filename.pathname()); |
| 534 EXPECT_EQ(sample_rate, wav_reader->SampleRate()); |
| 535 EXPECT_EQ(1u, wav_reader->NumChannels()); |
| 536 EXPECT_EQ(num_samples, wav_reader->NumSamples()); |
| 537 |
| 538 // Clean up. |
| 539 remove(temp_filename.pathname().c_str()); |
| 540 } |
| 541 } |
| 542 |
| 490 } // namespace test | 543 } // namespace test |
| 491 } // namespace webrtc | 544 } // namespace webrtc |
| OLD | NEW |