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

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: map iterators simplified Created 3 years, 7 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 <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 const std::set<std::string>& MultiEndCall::speaker_names() const {
36 return speaker_names_; 37 return speaker_names_;
37 } 38 }
38 39
39 const std::map<std::string, std::unique_ptr<WavReaderInterface>>& 40 const std::map<std::string, std::unique_ptr<WavReaderInterface>>&
40 MultiEndCall::audiotrack_readers() const { 41 MultiEndCall::audiotrack_readers() const {
41 return audiotrack_readers_; 42 return audiotrack_readers_;
42 } 43 }
43 44
44 bool MultiEndCall::valid() const { 45 bool MultiEndCall::valid() const {
45 return valid_; 46 return valid_;
46 } 47 }
47 48
49 int MultiEndCall::sample_rate() const {
50 return sample_rate_;
51 }
52
48 size_t MultiEndCall::total_duration_samples() const { 53 size_t MultiEndCall::total_duration_samples() const {
49 return total_duration_samples_; 54 return total_duration_samples_;
50 } 55 }
51 56
52 const std::vector<MultiEndCall::SpeakingTurn>& MultiEndCall::speaking_turns() 57 const std::vector<MultiEndCall::SpeakingTurn>& MultiEndCall::speaking_turns()
53 const { 58 const {
54 return speaking_turns_; 59 return speaking_turns_;
55 } 60 }
56 61
57 void MultiEndCall::FindSpeakerNames() { 62 void MultiEndCall::FindSpeakerNames() {
58 RTC_DCHECK(speaker_names_.empty()); 63 RTC_DCHECK(speaker_names_.empty());
59 for (const Turn& turn : timing_) { 64 for (const Turn& turn : timing_) {
60 speaker_names_.emplace(turn.speaker_name); 65 speaker_names_.emplace(turn.speaker_name);
61 } 66 }
62 } 67 }
63 68
64 void MultiEndCall::CreateAudioTrackReaders() { 69 bool MultiEndCall::CreateAudioTrackReaders() {
65 RTC_DCHECK(audiotrack_readers_.empty()); 70 RTC_DCHECK(audiotrack_readers_.empty());
71 sample_rate_ = 0; // Sample rate will be set when reading the first track.
66 for (const Turn& turn : timing_) { 72 for (const Turn& turn : timing_) {
67 auto it = audiotrack_readers_.find(turn.audiotrack_file_name); 73 auto it = audiotrack_readers_.find(turn.audiotrack_file_name);
68 if (it != audiotrack_readers_.end()) 74 if (it != audiotrack_readers_.end())
minyue-webrtc 2017/05/16 15:05:16 If this is supposed to be incremental, why doesn't
AleBzk 2017/05/17 12:49:37 Here I check if the audio track file has already b
69 continue; 75 continue;
70 76
71 // Instance Pathname to retrieve the full path to the audiotrack file. 77 // Instance Pathname to retrieve the full path to the audiotrack file.
72 const rtc::Pathname audiotrack_file_path( 78 const rtc::Pathname audiotrack_file_path(
73 audiotracks_path_, turn.audiotrack_file_name); 79 audiotracks_path_, turn.audiotrack_file_name);
74 80
75 // Map the audiotrack file name to a new instance of WavReaderInterface. 81 // Map the audiotrack file name to a new instance of WavReaderInterface.
76 std::unique_ptr<WavReaderInterface> wavreader = 82 std::unique_ptr<WavReaderInterface> wavreader =
77 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname()); 83 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname());
84
85 if (sample_rate_ == 0) {
86 sample_rate_ = wavreader->SampleRate();
87 } else if (sample_rate_ != wavreader->SampleRate()) {
88 LOG(LS_ERROR) << "all the audio tracks should have the same sample rate";
minyue-webrtc 2017/05/16 15:05:16 "A"ll and add full stop at the end of the sentence
AleBzk 2017/05/17 12:49:37 Done.
89 return false;
90 }
91
92 if (wavreader->NumChannels() != 1) {
93 LOG(LS_ERROR) << "only mono audio tracks supported";
minyue-webrtc 2017/05/16 15:05:16 "O"nly and full stop.
AleBzk 2017/05/17 12:49:37 Done.
94 return false;
95 }
96
78 audiotrack_readers_.emplace( 97 audiotrack_readers_.emplace(
minyue-webrtc 2017/05/16 15:05:16 Is this emplace allowed? try a few trybots.
AleBzk 2017/05/17 12:49:37 No need to try. This line was landed in a previous
minyue-webrtc 2017/05/18 13:35:13 Acknowledged.
79 turn.audiotrack_file_name, std::move(wavreader)); 98 turn.audiotrack_file_name, std::move(wavreader));
80 } 99 }
100
101 return true;
81 } 102 }
82 103
83 bool MultiEndCall::CheckTiming() { 104 bool MultiEndCall::CheckTiming() {
84 struct Interval { 105 struct Interval {
85 size_t begin; 106 size_t begin;
86 size_t end; 107 size_t end;
87 }; 108 };
88 size_t number_of_turns = timing_.size(); 109 size_t number_of_turns = timing_.size();
89 auto millisecond_to_samples = [](int ms, int sr) -> int { 110 auto millisecond_to_samples = [](int ms, int sr) -> int {
90 // Truncation may happen if the sampling rate is not an integer multiple 111 // Truncation may happen if the sampling rate is not an integer multiple
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return false; 207 return false;
187 } 208 }
188 } 209 }
189 210
190 return true; 211 return true;
191 } 212 }
192 213
193 } // namespace conversational_speech 214 } // namespace conversational_speech
194 } // namespace test 215 } // namespace test
195 } // namespace webrtc 216 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698