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

Side by Side Diff: webrtc/modules/audio_processing/test/conversational_speech/multiend_call.cc

Issue 2790933002: Conversational speech tool, simualtor + unit tests (Closed)
Patch Set: Using AppendFolder() to build paths to folders Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 "webrtc/base/logging.h" 13 #include "webrtc/base/logging.h"
14 #include "webrtc/base/pathutils.h" 14 #include "webrtc/base/pathutils.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 namespace test { 17 namespace test {
18 namespace conversational_speech { 18 namespace conversational_speech {
19 19
20 MultiEndCall::MultiEndCall( 20 MultiEndCall::MultiEndCall(
21 rtc::ArrayView<const Turn> timing, const std::string& audiotracks_path, 21 rtc::ArrayView<const Turn> timing, const std::string& audiotracks_path,
22 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory) 22 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory)
23 : timing_(timing), audiotracks_path_(audiotracks_path), 23 : timing_(timing), audiotracks_path_(audiotracks_path),
24 wavreader_abstract_factory_(std::move(wavreader_abstract_factory)) { 24 wavreader_abstract_factory_(std::move(wavreader_abstract_factory)),
25 valid_(false) {
25 FindSpeakerNames(); 26 FindSpeakerNames();
26 CreateAudioTrackReaders(); 27 if (CreateAudioTrackReaders())
27 valid_ = CheckTiming(); 28 valid_ = CheckTiming();
28 } 29 }
29 30
30 MultiEndCall::~MultiEndCall() = default; 31 MultiEndCall::~MultiEndCall() = default;
31 32
32 const std::set<std::string>& MultiEndCall::speaker_names() const { 33 const std::set<std::string>& MultiEndCall::speaker_names() const {
33 return speaker_names_; 34 return speaker_names_;
34 } 35 }
35 36
36 const std::map<std::string, std::unique_ptr<WavReaderInterface>>& 37 const std::map<std::string, std::unique_ptr<WavReaderInterface>>&
37 MultiEndCall::audiotrack_readers() const { 38 MultiEndCall::audiotrack_readers() const {
38 return audiotrack_readers_; 39 return audiotrack_readers_;
39 } 40 }
40 41
41 bool MultiEndCall::valid() const { 42 bool MultiEndCall::valid() const {
42 return valid_; 43 return valid_;
43 } 44 }
44 45
46 int MultiEndCall::sample_rate() const {
47 return sample_rate_;
48 }
49
45 std::size_t MultiEndCall::total_duration_samples() const { 50 std::size_t MultiEndCall::total_duration_samples() const {
46 return total_duration_samples_; 51 return total_duration_samples_;
47 } 52 }
48 53
49 const std::vector<MultiEndCall::SpeakingTurn>& MultiEndCall::speaking_turns() 54 const std::vector<MultiEndCall::SpeakingTurn>& MultiEndCall::speaking_turns()
50 const { 55 const {
51 return speaking_turns_; 56 return speaking_turns_;
52 } 57 }
53 58
54 void MultiEndCall::FindSpeakerNames() { 59 void MultiEndCall::FindSpeakerNames() {
55 RTC_DCHECK(speaker_names_.empty()); 60 RTC_DCHECK(speaker_names_.empty());
56 for (const Turn& turn : timing_) { 61 for (const Turn& turn : timing_) {
57 speaker_names_.emplace(turn.speaker_name); 62 speaker_names_.emplace(turn.speaker_name);
58 } 63 }
59 } 64 }
60 65
61 void MultiEndCall::CreateAudioTrackReaders() { 66 bool MultiEndCall::CreateAudioTrackReaders() {
62 RTC_DCHECK(audiotrack_readers_.empty()); 67 RTC_DCHECK(audiotrack_readers_.empty());
68 sample_rate_ = 0; // Sample rate will be set when reading the first track.
63 for (const Turn& turn : timing_) { 69 for (const Turn& turn : timing_) {
64 auto it = audiotrack_readers_.find(turn.audiotrack_file_name); 70 auto it = audiotrack_readers_.find(turn.audiotrack_file_name);
65 if (it != audiotrack_readers_.end()) 71 if (it != audiotrack_readers_.end())
66 continue; 72 continue;
67 73
68 // Instance Pathname to retrieve the full path to the audiotrack file. 74 // Instance Pathname to retrieve the full path to the audiotrack file.
69 const rtc::Pathname audiotrack_file_path( 75 const rtc::Pathname audiotrack_file_path(
70 audiotracks_path_, turn.audiotrack_file_name); 76 audiotracks_path_, turn.audiotrack_file_name);
71 77
72 // Map the audiotrack file name to a new instance of WavReaderInterface. 78 // Map the audiotrack file name to a new instance of WavReaderInterface.
73 std::unique_ptr<WavReaderInterface> wavreader = 79 std::unique_ptr<WavReaderInterface> wavreader =
74 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname()); 80 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname());
81
82 if (sample_rate_ == 0) {
83 sample_rate_ = wavreader->SampleRate();
84 } else if (sample_rate_ != wavreader->SampleRate()) {
85 LOG(LS_ERROR) << "all the audio tracks should have the same sample rate";
86 return false;
87 }
88
89 if (wavreader->NumChannels() != 1) {
90 LOG(LS_ERROR) << "only mono audio tracks supported";
91 return false;
92 }
93
75 audiotrack_readers_.emplace( 94 audiotrack_readers_.emplace(
76 turn.audiotrack_file_name, std::move(wavreader)); 95 turn.audiotrack_file_name, std::move(wavreader));
77 } 96 }
97
98 return true;
78 } 99 }
79 100
80 bool MultiEndCall::CheckTiming() { 101 bool MultiEndCall::CheckTiming() {
81 struct Interval { 102 struct Interval {
82 std::size_t begin; 103 std::size_t begin;
83 std::size_t end; 104 std::size_t end;
84 }; 105 };
85 std::size_t number_of_turns = timing_.size(); 106 std::size_t number_of_turns = timing_.size();
86 auto millisecond_to_samples = [](int ms, int sr) -> int { 107 auto millisecond_to_samples = [](int ms, int sr) -> int {
87 return ms * sr / 1000; 108 return ms * sr / 1000;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (previous_interval.end > interval.begin) { 203 if (previous_interval.end > interval.begin) {
183 return true; 204 return true;
184 } 205 }
185 } 206 }
186 return false; 207 return false;
187 } 208 }
188 209
189 } // namespace conversational_speech 210 } // namespace conversational_speech
190 } // namespace test 211 } // namespace test
191 } // namespace webrtc 212 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698