Apollo  6.0
Open source self driving car software
microphone_component.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <atomic>
20 #include <cmath>
21 #include <future>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "cyber/cyber.h"
28 #include "modules/drivers/microphone/proto/audio.pb.h"
29 #include "modules/drivers/microphone/proto/microphone_config.pb.h"
31 
32 namespace apollo {
33 namespace drivers {
34 namespace microphone {
35 
36 using apollo::common::util::FillHeader;
40 using apollo::drivers::microphone::config::AudioData;
41 using apollo::drivers::microphone::config::ChannelData;
42 using apollo::drivers::microphone::config::MicrophoneConfig;
43 
44 class MicrophoneComponent : public Component<> {
45  public:
46  bool Init() override;
48 
49  private:
50  void run();
51  void fill_channel_data(int chunk_i);
52 
53  // Configuration
54  int n_chunks_, n_channels_, chunk_, chunk_size_, n_chunk_,
55  sample_width_;
56 
57  // class data
58  std::shared_ptr<AudioData> audio_data_ptr_;
59  std::shared_ptr<Writer<AudioData>> writer_ptr_;
60  std::unique_ptr<Respeaker> microphone_device_ptr_;
61  std::vector<std::string *> channel_data_ptrs_;
62  std::shared_ptr<MicrophoneConfig> microphone_config_ptr_;
63  char *buffer_;
64 
65  std::future<void> async_result_;
66  std::atomic<bool> running_ = {false};
67 };
68 
70 } // namespace microphone
71 } // namespace drivers
72 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Reader subscribes a channel, it has two main functions:
Definition: reader.h:68
Some string util functions.
Definition: microphone_component.h:44
#define CYBER_REGISTER_COMPONENT(name)
Definition: component.h:551
The Component can process up to four channels of messages. The message type is specified when the com...
Definition: component.h:58
apollo::cyber::Writer< T > Writer
Definition: sensor_canbus.h:67