Apollo  6.0
Open source self driving car software
respeaker.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 <memory>
20 #include <string>
21 
22 #include <google/protobuf/message.h>
23 #include <portaudio.h>
24 #include "cyber/cyber.h"
25 #include "modules/drivers/microphone/proto/microphone_config.pb.h"
26 
27 namespace apollo {
28 namespace drivers {
29 namespace microphone {
30 
31 using apollo::drivers::microphone::config::MicrophoneConfig;
32 
33 /* An incomplete version of PA Stream used only for respeaker as input.
34  * Refer to http://portaudio.com/docs/v19-doxydocs/ for more information
35  */
36 class Stream {
37  private:
38  PaStream *pastream_ptr_;
39  PaStreamParameters *input_parameters_ptr_;
40 
41  public:
42  Stream() {}
43  ~Stream();
44  void init_stream(int rate, int channels, int chunk, int input_device_index,
45  PaSampleFormat format);
46  void read_stream(int n_frames, char *buffer) const;
47 };
48 
49 class Respeaker {
50  private:
51  std::unique_ptr<Stream> stream_ptr_;
52  const PaDeviceInfo *get_device_info(const PaDeviceIndex index) const;
53  const PaDeviceIndex host_api_device_index_to_device_index(
54  const PaHostApiIndex host_api, const int host_api_device_index) const;
55  const PaHostApiInfo *get_host_api_info(const PaHostApiIndex index) const;
56  const PaDeviceIndex get_respeaker_index() const;
57  const PaSampleFormat get_format_from_width(int width,
58  bool is_unsigned = true) const;
59 
60  public:
61  Respeaker() {}
62  ~Respeaker();
63  void init(const std::shared_ptr<const MicrophoneConfig> &microphone_config);
64  void read_stream(int n_frames, char *buffer) const;
65 };
66 
67 } // namespace microphone
68 } // namespace drivers
69 } // namespace apollo
void read_stream(int n_frames, char *buffer) const
Definition: respeaker.h:49
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: respeaker.h:36
void init_stream(int rate, int channels, int chunk, int input_device_index, PaSampleFormat format)
Stream()
Definition: respeaker.h:42
Respeaker()
Definition: respeaker.h:61