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_a
daptor.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; | |
59 | 65 |
60 const char* const audiotracks_path = "/path/to/audiotracks"; | 66 const char* const audiotracks_path = "/path/to/audiotracks"; |
61 const char* const timing_filepath = "/path/to/timing_file.txt"; | 67 const char* const timing_filepath = "/path/to/timing_file.txt"; |
62 const char* const output_path = "/path/to/output_dir"; | 68 const char* const output_path = "/path/to/output_dir"; |
63 | 69 |
64 const std::vector<Turn> expected_timing = { | 70 const std::vector<Turn> expected_timing = { |
65 {"A", "a1", 0}, | 71 {"A", "a1", 0}, |
66 {"B", "b1", 0}, | 72 {"B", "b1", 0}, |
67 {"A", "a2", 100}, | 73 {"A", "a2", 100}, |
68 {"B", "b2", -200}, | 74 {"B", "b2", -200}, |
(...skipping 19 matching lines...) Expand all Loading... |
88 {"t500", kMockWavReaderFactoryParams500ms}, | 94 {"t500", kMockWavReaderFactoryParams500ms}, |
89 {"t1000", kMockWavReaderFactoryParams1000ms}, | 95 {"t1000", kMockWavReaderFactoryParams1000ms}, |
90 }; | 96 }; |
91 | 97 |
92 std::unique_ptr<MockWavReaderFactory> CreateMockWavReaderFactory() { | 98 std::unique_ptr<MockWavReaderFactory> CreateMockWavReaderFactory() { |
93 return std::unique_ptr<MockWavReaderFactory>( | 99 return std::unique_ptr<MockWavReaderFactory>( |
94 new MockWavReaderFactory(kDefaultMockWavReaderFactoryParams, | 100 new MockWavReaderFactory(kDefaultMockWavReaderFactoryParams, |
95 kDefaultMockWavReaderFactoryParamsMap)); | 101 kDefaultMockWavReaderFactoryParamsMap)); |
96 } | 102 } |
97 | 103 |
| 104 void CreateSineWavFile(const std::string& filepath, |
| 105 const MockWavReaderFactory::Params& params, |
| 106 float frequency = 440.0f) { |
| 107 // Create samples. |
| 108 constexpr double two_pi = 2.0 * M_PI; |
| 109 std::vector<int16_t> samples(params.num_samples); |
| 110 for (std::size_t i = 0; i < params.num_samples; ++i) { |
| 111 // TODO(alessiob): the produced tone is not pure, improve. |
| 112 samples[i] = std::lround(32767.0f * std::sin( |
| 113 two_pi * i * frequency / params.sample_rate)); |
| 114 } |
| 115 |
| 116 // Write samples. |
| 117 WavWriter wav_writer(filepath, params.sample_rate, params.num_channels); |
| 118 wav_writer.WriteSamples(samples.data(), params.num_samples); |
| 119 } |
| 120 |
98 } // namespace | 121 } // namespace |
99 | 122 |
100 class ConversationalSpeechTest : public testing::Test { | 123 class ConversationalSpeechTest : public testing::Test { |
101 public: | 124 public: |
102 ConversationalSpeechTest() { | 125 ConversationalSpeechTest() { |
103 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | 126 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); |
104 } | 127 } |
105 }; | 128 }; |
106 | 129 |
107 TEST_F(ConversationalSpeechTest, Settings) { | 130 TEST_F(ConversationalSpeechTest, Settings) { |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 kDefaultMockWavReaderFactoryParamsMap)); | 451 kDefaultMockWavReaderFactoryParamsMap)); |
429 | 452 |
430 // There are two unique audio tracks to read. | 453 // There are two unique audio tracks to read. |
431 EXPECT_CALL(*mock_wavreader_factory, Create(testing::_)).Times(2); | 454 EXPECT_CALL(*mock_wavreader_factory, Create(testing::_)).Times(2); |
432 | 455 |
433 conversational_speech::MultiEndCall multiend_call( | 456 conversational_speech::MultiEndCall multiend_call( |
434 timing, audiotracks_path, std::move(mock_wavreader_factory)); | 457 timing, audiotracks_path, std::move(mock_wavreader_factory)); |
435 EXPECT_FALSE(multiend_call.valid()); | 458 EXPECT_FALSE(multiend_call.valid()); |
436 } | 459 } |
437 | 460 |
| 461 TEST_F(ConversationalSpeechTest, MultiEndCallWavReaderAdaptorSine) { |
| 462 // Parameters with which wav files are created. |
| 463 constexpr int duration_seconds = 5; |
| 464 const int sample_rates[] = {8000, 11025, 16000, 22050, 32000, 44100, 48000}; |
| 465 |
| 466 for (int sample_rate : sample_rates) { |
| 467 const rtc::Pathname temp_filename( |
| 468 OutputPath(), "TempSineWavFile_" + std::to_string(sample_rate) |
| 469 + ".wav"); |
| 470 |
| 471 // Write wav file. |
| 472 const std::size_t num_samples = duration_seconds * sample_rate; |
| 473 MockWavReaderFactory::Params params = {sample_rate, 1u, num_samples}; |
| 474 CreateSineWavFile(temp_filename.pathname(), params); |
| 475 LOG(LS_VERBOSE) << "wav file @" << sample_rate << " Hz created (" |
| 476 << num_samples << " samples)"; |
| 477 |
| 478 // Load wav file and check if params match. |
| 479 auto wav_reader_adaptor = conversational_speech::CreateWavReaderAdaptor( |
| 480 temp_filename.pathname()); |
| 481 EXPECT_EQ(sample_rate, wav_reader_adaptor->sample_rate()); |
| 482 EXPECT_EQ(1u, wav_reader_adaptor->num_channels()); |
| 483 EXPECT_EQ(num_samples, wav_reader_adaptor->num_samples()); |
| 484 |
| 485 // Clean up. |
| 486 remove(temp_filename.pathname().c_str()); |
| 487 } |
| 488 } |
| 489 |
438 } // namespace test | 490 } // namespace test |
439 } // namespace webrtc | 491 } // namespace webrtc |
OLD | NEW |