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

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

Issue 2925123003: Revert of Conversational speech tool, simualtor + unit tests (Closed)
Patch Set: Created 3 years, 6 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) {
29 FindSpeakerNames(); 28 FindSpeakerNames();
30 if (CreateAudioTrackReaders()) 29 CreateAudioTrackReaders();
31 valid_ = CheckTiming(); 30 valid_ = CheckTiming();
32 } 31 }
33 32
34 MultiEndCall::~MultiEndCall() = default; 33 MultiEndCall::~MultiEndCall() = default;
35 34
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
36 void MultiEndCall::FindSpeakerNames() { 57 void MultiEndCall::FindSpeakerNames() {
37 RTC_DCHECK(speaker_names_.empty()); 58 RTC_DCHECK(speaker_names_.empty());
38 for (const Turn& turn : timing_) { 59 for (const Turn& turn : timing_) {
39 speaker_names_.emplace(turn.speaker_name); 60 speaker_names_.emplace(turn.speaker_name);
40 } 61 }
41 } 62 }
42 63
43 bool MultiEndCall::CreateAudioTrackReaders() { 64 void MultiEndCall::CreateAudioTrackReaders() {
44 RTC_DCHECK(audiotrack_readers_.empty()); 65 RTC_DCHECK(audiotrack_readers_.empty());
45 sample_rate_hz_ = 0; // Sample rate will be set when reading the first track.
46 for (const Turn& turn : timing_) { 66 for (const Turn& turn : timing_) {
47 auto it = audiotrack_readers_.find(turn.audiotrack_file_name); 67 auto it = audiotrack_readers_.find(turn.audiotrack_file_name);
48 if (it != audiotrack_readers_.end()) 68 if (it != audiotrack_readers_.end())
49 continue; 69 continue;
50 70
51 // Instance Pathname to retrieve the full path to the audiotrack file. 71 // Instance Pathname to retrieve the full path to the audiotrack file.
52 const rtc::Pathname audiotrack_file_path( 72 const rtc::Pathname audiotrack_file_path(
53 audiotracks_path_, turn.audiotrack_file_name); 73 audiotracks_path_, turn.audiotrack_file_name);
54 74
55 // Map the audiotrack file name to a new instance of WavReaderInterface. 75 // Map the audiotrack file name to a new instance of WavReaderInterface.
56 std::unique_ptr<WavReaderInterface> wavreader = 76 std::unique_ptr<WavReaderInterface> wavreader =
57 wavreader_abstract_factory_->Create(audiotrack_file_path.pathname()); 77 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
71 audiotrack_readers_.emplace( 78 audiotrack_readers_.emplace(
72 turn.audiotrack_file_name, std::move(wavreader)); 79 turn.audiotrack_file_name, std::move(wavreader));
73 } 80 }
74
75 return true;
76 } 81 }
77 82
78 bool MultiEndCall::CheckTiming() { 83 bool MultiEndCall::CheckTiming() {
79 struct Interval { 84 struct Interval {
80 size_t begin; 85 size_t begin;
81 size_t end; 86 size_t end;
82 }; 87 };
83 size_t number_of_turns = timing_.size(); 88 size_t number_of_turns = timing_.size();
84 auto millisecond_to_samples = [](int ms, int sr) -> int { 89 auto millisecond_to_samples = [](int ms, int sr) -> int {
85 // Truncation may happen if the sampling rate is not an integer multiple 90 // Truncation may happen if the sampling rate is not an integer multiple
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return false; 186 return false;
182 } 187 }
183 } 188 }
184 189
185 return true; 190 return true;
186 } 191 }
187 192
188 } // namespace conversational_speech 193 } // namespace conversational_speech
189 } // namespace test 194 } // namespace test
190 } // namespace webrtc 195 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698