audio_common for ROS 2
Loading...
Searching...
No Matches
audio_player_node.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2024 Miguel Ángel González Santamarta
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef AUDIO_COMMON__AUDIO_PLAYER_NODE
24#define AUDIO_COMMON__AUDIO_PLAYER_NODE
25
26#include <memory>
27#include <portaudio.h>
28#include <rclcpp/rclcpp.hpp>
29
30#include "audio_common_msgs/msg/audio_stamped.hpp"
31
32namespace audio_common {
33
34class AudioPlayerNode : public rclcpp::Node {
35public:
37 ~AudioPlayerNode() override;
38
39private:
40 // ROS 2 subscription for audio messages
41 rclcpp::Subscription<audio_common_msgs::msg::AudioStamped>::SharedPtr
43
44 // PortAudio stream dictionary
45 std::unordered_map<std::string, PaStream *> stream_dict_;
46
47 // Parameters
50
51 // Methods
52 void
53 audio_callback(const audio_common_msgs::msg::AudioStamped::SharedPtr msg);
54 template <typename T>
55 void write_data(const std::vector<T> &data, int channels, int chunk,
56 const std::string &stream_key);
57};
58
59} // namespace audio_common
60
61#endif
std::unordered_map< std::string, PaStream * > stream_dict_
Definition audio_player_node.hpp:45
rclcpp::Subscription< audio_common_msgs::msg::AudioStamped >::SharedPtr audio_sub_
Definition audio_player_node.hpp:42
int channels_
Definition audio_player_node.hpp:48
AudioPlayerNode()
Definition audio_player_node.cpp:38
void write_data(const std::vector< T > &data, int channels, int chunk, const std::string &stream_key)
Definition audio_player_node.cpp:140
int device_
Definition audio_player_node.hpp:49
~AudioPlayerNode() override
Definition audio_player_node.cpp:65
void audio_callback(const audio_common_msgs::msg::AudioStamped::SharedPtr msg)
Definition audio_player_node.cpp:74
Definition audio_capturer_node.hpp:32