Apollo 10.0
自动驾驶开放平台
apollo::drivers::microphone::MicrophoneComponent类 参考

#include <microphone_component.h>

类 apollo::drivers::microphone::MicrophoneComponent 继承关系图:
apollo::drivers::microphone::MicrophoneComponent 的协作图:

Public 成员函数

bool Init () override
 
 ~MicrophoneComponent ()
 
- Public 成员函数 继承自 apollo::cyber::Component< M0, M1, M2, M3 >
 Component ()
 
 ~Component () override
 
bool Initialize (const ComponentConfig &config) override
 init the component by protobuf object.
 
bool Process (const std::shared_ptr< M0 > &msg0, const std::shared_ptr< M1 > &msg1, const std::shared_ptr< M2 > &msg2, const std::shared_ptr< M3 > &msg3)
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const TimerComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
virtual void Clear ()
 
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Nodenode_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 microphone_component.h44 行定义.

构造及析构函数说明

◆ ~MicrophoneComponent()

apollo::drivers::microphone::MicrophoneComponent::~MicrophoneComponent ( )

在文件 microphone_component.cc102 行定义.

102 {
103 delete[] buffer_;
104 if (running_.load()) {
105 running_.exchange(false);
106 async_result_.wait();
107 }
108}

成员函数说明

◆ Init()

bool apollo::drivers::microphone::MicrophoneComponent::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 microphone_component.cc23 行定义.

23 {
24 microphone_config_ptr_ = std::make_shared<MicrophoneConfig>();
26 microphone_config_ptr_.get())) {
27 return false;
28 }
29 AINFO << "Microphone config: " << microphone_config_ptr_->DebugString();
30
31 // new microphone device
32 microphone_device_ptr_.reset(new Respeaker());
33 microphone_device_ptr_->init(microphone_config_ptr_);
34
35 // dump config, calculate size and reserve buffer for audio
36 n_channels_ = microphone_config_ptr_->channel_type_size();
37 sample_width_ = microphone_config_ptr_->sample_width();
38 // chunk_: number of frames per chunk; chunk_size_: number of bytes per chunk
39 chunk_ = microphone_config_ptr_->chunk();
40 n_chunk_ = static_cast<int>(
41 std::ceil(microphone_config_ptr_->sample_rate() *
42 microphone_config_ptr_->record_seconds() / chunk_));
43 chunk_size_ = chunk_ * n_channels_ * sample_width_;
44 buffer_ = new char[chunk_size_];
45 if (buffer_ == nullptr) {
46 AERROR << "System new memory error, size:" << chunk_size_;
47 return false;
48 }
49
50 // assemble AudioData -- fill microphone_config, allocate memory for
51 // channel_data
52 audio_data_ptr_.reset(new AudioData());
53 std::string config;
54 microphone_config_ptr_->SerializeToString(&config);
55 audio_data_ptr_->mutable_microphone_config()->ParseFromString(config);
56 audio_data_ptr_->mutable_header()->set_frame_id(
57 microphone_config_ptr_->frame_id());
58
59 ChannelData *channel_data = nullptr;
60 int channel_size = n_chunk_ * chunk_ * sample_width_;
61 for (int i = 0; i < n_channels_; ++i) {
62 channel_data = audio_data_ptr_->add_channel_data();
63 channel_data->set_channel_type(microphone_config_ptr_->channel_type(i));
64 channel_data->mutable_data()->resize(channel_size);
65 channel_data_ptrs_.push_back(channel_data->mutable_data());
66 }
67
68 writer_ptr_ =
69 node_->CreateWriter<AudioData>(microphone_config_ptr_->channel_name());
70 async_result_ = cyber::Async(&MicrophoneComponent::run, this);
71 return true;
72}
std::shared_ptr< Node > node_
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

该类的文档由以下文件生成: