24 microphone_config_ptr_ = std::make_shared<MicrophoneConfig>();
26 microphone_config_ptr_.get())) {
29 AINFO <<
"Microphone config: " << microphone_config_ptr_->DebugString();
32 microphone_device_ptr_.reset(
new Respeaker());
33 microphone_device_ptr_->init(microphone_config_ptr_);
36 n_channels_ = microphone_config_ptr_->channel_type_size();
37 sample_width_ = microphone_config_ptr_->sample_width();
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_;
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());
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());
69 node_->CreateWriter<
AudioData>(microphone_config_ptr_->channel_name());
70 async_result_ = cyber::Async(&MicrophoneComponent::run,
this);