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 |
11 #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_ca
ll.h" | 11 #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_ca
ll.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <iterator> | 14 #include <iterator> |
15 | 15 |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/pathutils.h" | 17 #include "webrtc/base/pathutils.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace test { | 20 namespace test { |
21 namespace conversational_speech { | 21 namespace conversational_speech { |
22 | 22 |
23 MultiEndCall::MultiEndCall( | 23 MultiEndCall::MultiEndCall( |
24 rtc::ArrayView<const Turn> timing, const std::string& audiotracks_path, | 24 rtc::ArrayView<const Turn> timing, const std::string& audiotracks_path, |
25 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory) | 25 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory) |
26 : timing_(timing), audiotracks_path_(audiotracks_path), | 26 : timing_(timing), audiotracks_path_(audiotracks_path), |
27 wavreader_abstract_factory_(std::move(wavreader_abstract_factory)) { | 27 wavreader_abstract_factory_(std::move(wavreader_abstract_factory)), |
| 28 valid_(false) { |
28 FindSpeakerNames(); | 29 FindSpeakerNames(); |
29 CreateAudioTrackReaders(); | 30 if (CreateAudioTrackReaders()) |
30 valid_ = CheckTiming(); | 31 valid_ = CheckTiming(); |
31 } | 32 } |
32 | 33 |
33 MultiEndCall::~MultiEndCall() = default; | 34 MultiEndCall::~MultiEndCall() = default; |
34 | 35 |
35 const std::set<std::string>& MultiEndCall::speaker_names() const { | |
36 return speaker_names_; | |
37 } | |
38 | |
39 const std::map<std::string, std::unique_ptr<WavReaderInterface>>& | |
40 MultiEndCall::audiotrack_readers() const { | |
41 return audiotrack_readers_; | |
42 } | |
43 | |
44 bool MultiEndCall::valid() const { | |
45 return valid_; | |
46 } | |
47 | |
48 size_t MultiEndCall::total_duration_samples() const { | |
49 return total_duration_samples_; | |
50 } | |
51 | |
52 const std::vector<MultiEndCall::SpeakingTurn>& MultiEndCall::speaking_turns() | |
53 const { | |
54 return speaking_turns_; | |
55 } | |
56 | |
57 void MultiEndCall::FindSpeakerNames() { | 36 void MultiEndCall::FindSpeakerNames() { |
58 RTC_DCHECK(speaker_names_.empty()); | 37 RTC_DCHECK(speaker_names_.empty()); |
59 for (const Turn& turn : timing_) { | 38 for (const Turn& turn : timing_) { |
60 speaker_names_.emplace(turn.speaker_name); | 39 speaker_names_.emplace(turn.speaker_name); |
61 } | 40 } |
62 } | 41 } |
63 | 42 |
64 void MultiEndCall::CreateAudioTrackReaders() { | 43 bool MultiEndCall::CreateAudioTrackReaders() { |
65 RTC_DCHECK(audiotrack_readers_.empty()); | 44 RTC_DCHECK(audiotrack_readers_.empty()); |
| 45 sample_rate_hz_ = 0; // Sample rate will be set when reading the first track. |
66 for (const Turn& turn : timing_) { | 46 for (const Turn& turn : timing_) { |
67 auto it = audiotrack_readers_.find(turn.audiotrack_file_name); | 47 auto it = audiotrack_readers_.find(turn.audiotrack_file_name); |
68 if (it != audiotrack_readers_.end()) | 48 if (it != audiotrack_readers_.end()) |
69 continue; | 49 continue; |
70 | 50 |
71 // Instance Pathname to retrieve the full path to the audiotrack file. | 51 // Instance Pathname to retrieve the full path to the audiotrack file. |
72 const rtc::Pathname audiotrack_file_path( | 52 const rtc::Pathname audiotrack_file_path( |
73 audiotracks_path_, turn.audiotrack_file_name); | 53 audiotracks_path_, turn.audiotrack_file_name); |
74 | 54 |
75 // Map the audiotrack file name to a new instance of WavReaderInterface. | 55 // Map the audiotrack file name to a new instance of WavReaderInterface. |
76 std::unique_ptr<WavReaderInterface> wavreader = | 56 std::unique_ptr<WavReaderInterface> wavreader = |
77 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname()); | 57 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname()); |
| 58 |
| 59 if (sample_rate_hz_ == 0) { |
| 60 sample_rate_hz_ = wavreader->SampleRate(); |
| 61 } else if (sample_rate_hz_ != wavreader->SampleRate()) { |
| 62 LOG(LS_ERROR) << "All the audio tracks should have the same sample rate."; |
| 63 return false; |
| 64 } |
| 65 |
| 66 if (wavreader->NumChannels() != 1) { |
| 67 LOG(LS_ERROR) << "Only mono audio tracks supported."; |
| 68 return false; |
| 69 } |
| 70 |
78 audiotrack_readers_.emplace( | 71 audiotrack_readers_.emplace( |
79 turn.audiotrack_file_name, std::move(wavreader)); | 72 turn.audiotrack_file_name, std::move(wavreader)); |
80 } | 73 } |
| 74 |
| 75 return true; |
81 } | 76 } |
82 | 77 |
83 bool MultiEndCall::CheckTiming() { | 78 bool MultiEndCall::CheckTiming() { |
84 struct Interval { | 79 struct Interval { |
85 size_t begin; | 80 size_t begin; |
86 size_t end; | 81 size_t end; |
87 }; | 82 }; |
88 size_t number_of_turns = timing_.size(); | 83 size_t number_of_turns = timing_.size(); |
89 auto millisecond_to_samples = [](int ms, int sr) -> int { | 84 auto millisecond_to_samples = [](int ms, int sr) -> int { |
90 // Truncation may happen if the sampling rate is not an integer multiple | 85 // Truncation may happen if the sampling rate is not an integer multiple |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 return false; | 181 return false; |
187 } | 182 } |
188 } | 183 } |
189 | 184 |
190 return true; | 185 return true; |
191 } | 186 } |
192 | 187 |
193 } // namespace conversational_speech | 188 } // namespace conversational_speech |
194 } // namespace test | 189 } // namespace test |
195 } // namespace webrtc | 190 } // namespace webrtc |
OLD | NEW |