FP Perception 0.1.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
fp_perception::SpeakerAudioDriver Class Reference

SpeakerAudioDriver class for handling audio output to a speaker. More...

#include <speaker_audio_driver.hpp>

Inheritance diagram for fp_perception::SpeakerAudioDriver:
Inheritance graph
[legend]
Collaboration diagram for fp_perception::SpeakerAudioDriver:
Collaboration graph
[legend]

Public Member Functions

 SpeakerAudioDriver ()
 Constructor for SpeakerAudioDriver.
 
 ~SpeakerAudioDriver () override
 Destructor for SpeakerAudioDriver.
 
void initialize (const rclcpp::Node::SharedPtr &node) override
 Initialize the driver.
 
void deinitialize () override
 Stop driver streaming. This function stops the audio stream and closes it. It also terminates the PortAudio library.
 
void play (const audio_data &input_data) override
 Set the latest audio data to the driver. This function sends the latest audio data to the speaker driver.
 
void enqueuePlayback (const audio_data &input_data) override
 
void stopPlayback () override
 
void play_internal (const audio_data &input_data, bool wait_for_drain)
 
void test () override
 Read test/mic_test.wav and play it through the speaker.
 
- Public Member Functions inherited from fp_perception::DriverBase
virtual ~DriverBase ()=default
 
virtual std::string getName () const
 Get the name of the driver.
 
void check_directory (std::string folder_name)
 Check if the test directory exists, create it if not.
 
const std::filesystem::path check_file (const std::string &file_name)
 

Protected Member Functions

int fill_output_buffer (void *output_buffer, unsigned long frames_per_buffer, PaStreamCallbackFlags status_flags)
 
void queue_data (audio_data input_data, const std::string &stream_key, bool wait_for_drain)
 
void wait_for_playback_drain ()
 
void setup_diagnostics ()
 
void produce_diagnostics (diagnostic_updater::DiagnosticStatusWrapper &status)
 
- Protected Member Functions inherited from fp_perception::DriverBase
void initialize_base (const rclcpp::Node::SharedPtr &node)
 Initializer base driver in place of constructor due to plugin semantics.
 
bool diagnostics_enabled () const
 
void enable_diagnostics (const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1))
 
void disable_diagnostics ()
 

Static Protected Member Functions

static int pa_output_callback (const void *input_buffer, void *output_buffer, unsigned long frames_per_buffer, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data)
 
static std::vector< int16_t > resample_linear_interleaved (const std::vector< int16_t > &input, int channels, int input_rate, int output_rate)
 

Protected Attributes

int device_id_
 
std::string device_name_
 
PaError err = paNoError
 
int sample_rate_
 
int channels_
 
std::string test_file_path_
 
std::map< std::string, PaStream * > stream_dict_
 
std::deque< int16_t > playback_queue_
 
std::mutex playback_mutex_
 
std::condition_variable playback_cv_
 
std::atomic< uint64_t > underrun_count_ { 0 }
 
std::atomic< uint64_t > callback_lock_miss_count_ { 0 }
 
- Protected Attributes inherited from fp_perception::DriverBase
rclcpp::Node::SharedPtr node_
 ROS node for the driver.
 
std::string name_
 Name of the driver.
 
std::mutex buffer_mutex_
 Mutex to protect access to the driver data.
 
std::condition_variable buffer_cv_
 Condition variable to notify when new data is available.
 
std::atomic< bool > is_running_ { false }
 Flag to indicate if the driver thread is running.
 
bool diagnostics_enabled_ { false }
 Flag to enable standard ROS diagnostics publishing.
 
std::unique_ptr< diagnostic_updater::Updater > diagnostics_updater_
 
rclcpp::TimerBase::SharedPtr diagnostics_timer_
 

Detailed Description

SpeakerAudioDriver class for handling audio output to a speaker.

This class is responsible for managing the audio output to a speaker using PortAudio. It provides methods to start and stop the audio stream, as well as play audio data.

Constructor & Destructor Documentation

◆ SpeakerAudioDriver()

fp_perception::SpeakerAudioDriver::SpeakerAudioDriver ( )
inline

Constructor for SpeakerAudioDriver.

Initializes the PortAudio library and prepares the audio stream.

◆ ~SpeakerAudioDriver()

fp_perception::SpeakerAudioDriver::~SpeakerAudioDriver ( )
inlineoverride

Destructor for SpeakerAudioDriver.

Stops the audio stream and terminates the PortAudio library.

Member Function Documentation

◆ deinitialize()

void fp_perception::SpeakerAudioDriver::deinitialize ( )
inlineoverridevirtual

Stop driver streaming. This function stops the audio stream and closes it. It also terminates the PortAudio library.

Implements fp_perception::DriverBase.

◆ enqueuePlayback()

void fp_perception::SpeakerAudioDriver::enqueuePlayback ( const audio_data input_data)
inlineoverridevirtual

Reimplemented from fp_perception::AudioSinkDriver.

◆ fill_output_buffer()

int fp_perception::SpeakerAudioDriver::fill_output_buffer ( void *  output_buffer,
unsigned long  frames_per_buffer,
PaStreamCallbackFlags  status_flags 
)
inlineprotected

◆ initialize()

void fp_perception::SpeakerAudioDriver::initialize ( const rclcpp::Node::SharedPtr &  node)
inlineoverridevirtual

Initialize the driver.

This function should be overridden in derived classes to provide specific initialization.

Parameters
nodeShared pointer to the ROS node

Reimplemented from fp_perception::DriverBase.

◆ pa_output_callback()

static int fp_perception::SpeakerAudioDriver::pa_output_callback ( const void *  input_buffer,
void *  output_buffer,
unsigned long  frames_per_buffer,
const PaStreamCallbackTimeInfo *  time_info,
PaStreamCallbackFlags  status_flags,
void *  user_data 
)
inlinestaticprotected

◆ play()

void fp_perception::SpeakerAudioDriver::play ( const audio_data input_data)
inlineoverridevirtual

Set the latest audio data to the driver. This function sends the latest audio data to the speaker driver.

Parameters
inputThe latest audio data to the driver in the form of const std::vector<std::vector<int16_t>>&.
Exceptions
fp_perception_exceptionif not implemented in derived classes

Implements fp_perception::AudioSinkDriver.

◆ play_internal()

void fp_perception::SpeakerAudioDriver::play_internal ( const audio_data input_data,
bool  wait_for_drain 
)
inline

◆ produce_diagnostics()

void fp_perception::SpeakerAudioDriver::produce_diagnostics ( diagnostic_updater::DiagnosticStatusWrapper &  status)
inlineprotected

◆ queue_data()

void fp_perception::SpeakerAudioDriver::queue_data ( audio_data  input_data,
const std::string &  stream_key,
bool  wait_for_drain 
)
inlineprotected

◆ resample_linear_interleaved()

static std::vector< int16_t > fp_perception::SpeakerAudioDriver::resample_linear_interleaved ( const std::vector< int16_t > &  input,
int  channels,
int  input_rate,
int  output_rate 
)
inlinestaticprotected

◆ setup_diagnostics()

void fp_perception::SpeakerAudioDriver::setup_diagnostics ( )
inlineprotected

◆ stopPlayback()

void fp_perception::SpeakerAudioDriver::stopPlayback ( )
inlineoverridevirtual

Reimplemented from fp_perception::AudioSinkDriver.

◆ test()

void fp_perception::SpeakerAudioDriver::test ( )
inlineoverridevirtual

Read test/mic_test.wav and play it through the speaker.

Reimplemented from fp_perception::DriverBase.

◆ wait_for_playback_drain()

void fp_perception::SpeakerAudioDriver::wait_for_playback_drain ( )
inlineprotected

Member Data Documentation

◆ callback_lock_miss_count_

std::atomic<uint64_t> fp_perception::SpeakerAudioDriver::callback_lock_miss_count_ { 0 }
protected

◆ channels_

int fp_perception::SpeakerAudioDriver::channels_
protected

◆ device_id_

int fp_perception::SpeakerAudioDriver::device_id_
protected

◆ device_name_

std::string fp_perception::SpeakerAudioDriver::device_name_
protected

◆ err

PaError fp_perception::SpeakerAudioDriver::err = paNoError
protected

◆ playback_cv_

std::condition_variable fp_perception::SpeakerAudioDriver::playback_cv_
protected

◆ playback_mutex_

std::mutex fp_perception::SpeakerAudioDriver::playback_mutex_
protected

◆ playback_queue_

std::deque<int16_t> fp_perception::SpeakerAudioDriver::playback_queue_
protected

◆ sample_rate_

int fp_perception::SpeakerAudioDriver::sample_rate_
protected

◆ stream_dict_

std::map<std::string, PaStream*> fp_perception::SpeakerAudioDriver::stream_dict_
protected

◆ test_file_path_

std::string fp_perception::SpeakerAudioDriver::test_file_path_
protected

◆ underrun_count_

std::atomic<uint64_t> fp_perception::SpeakerAudioDriver::underrun_count_ { 0 }
protected

The documentation for this class was generated from the following file: