1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_ 12 #define MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_ 13 14 #include <stddef.h> 15 16 #include <map> 17 #include <memory> 18 #include <set> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "api/array_view.h" 24 #include "modules/audio_processing/test/conversational_speech/timing.h" 25 #include "modules/audio_processing/test/conversational_speech/wavreader_abstract_factory.h" 26 #include "modules/audio_processing/test/conversational_speech/wavreader_interface.h" 27 #include "rtc_base/constructor_magic.h" 28 29 namespace webrtc { 30 namespace test { 31 namespace conversational_speech { 32 33 class MultiEndCall { 34 public: 35 struct SpeakingTurn { 36 // Constructor required in order to use std::vector::emplace_back(). SpeakingTurnSpeakingTurn37 SpeakingTurn(std::string new_speaker_name, 38 std::string new_audiotrack_file_name, 39 size_t new_begin, 40 size_t new_end, 41 int gain) 42 : speaker_name(std::move(new_speaker_name)), 43 audiotrack_file_name(std::move(new_audiotrack_file_name)), 44 begin(new_begin), 45 end(new_end), 46 gain(gain) {} 47 std::string speaker_name; 48 std::string audiotrack_file_name; 49 size_t begin; 50 size_t end; 51 int gain; 52 }; 53 54 MultiEndCall( 55 rtc::ArrayView<const Turn> timing, 56 const std::string& audiotracks_path, 57 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory); 58 ~MultiEndCall(); 59 speaker_names()60 const std::set<std::string>& speaker_names() const { return speaker_names_; } 61 const std::map<std::string, std::unique_ptr<WavReaderInterface>>& audiotrack_readers()62 audiotrack_readers() const { 63 return audiotrack_readers_; 64 } valid()65 bool valid() const { return valid_; } sample_rate()66 int sample_rate() const { return sample_rate_hz_; } total_duration_samples()67 size_t total_duration_samples() const { return total_duration_samples_; } speaking_turns()68 const std::vector<SpeakingTurn>& speaking_turns() const { 69 return speaking_turns_; 70 } 71 72 private: 73 // Finds unique speaker names. 74 void FindSpeakerNames(); 75 76 // Creates one WavReader instance for each unique audiotrack. It returns false 77 // if the audio tracks do not have the same sample rate or if they are not 78 // mono. 79 bool CreateAudioTrackReaders(); 80 81 // Validates the speaking turns timing information. Accepts cross-talk, but 82 // only up to 2 speakers. Rejects unordered turns and self cross-talk. 83 bool CheckTiming(); 84 85 rtc::ArrayView<const Turn> timing_; 86 const std::string& audiotracks_path_; 87 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory_; 88 std::set<std::string> speaker_names_; 89 std::map<std::string, std::unique_ptr<WavReaderInterface>> 90 audiotrack_readers_; 91 bool valid_; 92 int sample_rate_hz_; 93 size_t total_duration_samples_; 94 std::vector<SpeakingTurn> speaking_turns_; 95 96 RTC_DISALLOW_COPY_AND_ASSIGN(MultiEndCall); 97 }; 98 99 } // namespace conversational_speech 100 } // namespace test 101 } // namespace webrtc 102 103 #endif // MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_ 104