MicrophoneAudioDriver class for handling audio input from a microphone.
More...
#include <microphone_audio_driver.hpp>
|
| | MicrophoneAudioDriver () |
| | Constructor for MicrophoneAudioDriver.
|
| |
| | ~MicrophoneAudioDriver () override |
| | Start the audio stream.
|
| |
| 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.
|
| |
| audio_data | readChunk () override |
| | Get latest audio data from the driver as a stream. This function reads audio data from the microphone stream and returns it as a fp_perception::audio_data. Best approach is to use this to get a certain amount of audio data by repeatedly calling this function until enough data is collected.
|
| |
| void | test () override |
| | Test the driver.
|
| |
| virtual audio_data | readBufferedAudio (int duration_seconds) |
| |
| 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) |
| |
|
| static int | pa_input_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) |
| |
MicrophoneAudioDriver class for handling audio input from a microphone.
This class is responsible for managing the audio input from a microphone using PortAudio. It provides methods to start and stop the audio stream, as well as retrieve audio data.
◆ MicrophoneAudioDriver()
| fp_perception::MicrophoneAudioDriver::MicrophoneAudioDriver |
( |
| ) |
|
|
inline |
◆ ~MicrophoneAudioDriver()
| fp_perception::MicrophoneAudioDriver::~MicrophoneAudioDriver |
( |
| ) |
|
|
inlineoverride |
Start the audio stream.
This function starts the audio stream using PortAudio.
◆ capture_input_buffer()
| int fp_perception::MicrophoneAudioDriver::capture_input_buffer |
( |
const void * |
input_buffer, |
|
|
unsigned long |
frames_per_buffer, |
|
|
PaStreamCallbackFlags |
status_flags |
|
) |
| |
|
inlineprotected |
◆ deinitialize()
| void fp_perception::MicrophoneAudioDriver::deinitialize |
( |
| ) |
|
|
inlineoverridevirtual |
Stop driver streaming. This function stops the audio stream and closes it. It also terminates the PortAudio library.
Implements fp_perception::DriverBase.
◆ initialize()
| void fp_perception::MicrophoneAudioDriver::initialize |
( |
const rclcpp::Node::SharedPtr & |
node | ) |
|
|
inlineoverridevirtual |
Initialize the driver.
This function should be overridden in derived classes to provide specific initialization.
- Parameters
-
| node | Shared pointer to the ROS node |
Reimplemented from fp_perception::DriverBase.
◆ pa_input_callback()
| static int fp_perception::MicrophoneAudioDriver::pa_input_callback |
( |
const void * |
input_buffer, |
|
|
void * |
output_buffer, |
|
|
unsigned long |
frames_per_buffer, |
|
|
const PaStreamCallbackTimeInfo * |
time_info, |
|
|
PaStreamCallbackFlags |
status_flags, |
|
|
void * |
user_data |
|
) |
| |
|
inlinestaticprotected |
◆ produce_diagnostics()
| void fp_perception::MicrophoneAudioDriver::produce_diagnostics |
( |
diagnostic_updater::DiagnosticStatusWrapper & |
status | ) |
|
|
inlineprotected |
◆ read_samples_locked()
| void fp_perception::MicrophoneAudioDriver::read_samples_locked |
( |
int16_t * |
destination, |
|
|
size_t |
sample_count |
|
) |
| |
|
inlineprotected |
◆ readChunk()
| audio_data fp_perception::MicrophoneAudioDriver::readChunk |
( |
| ) |
|
|
inlineoverridevirtual |
Get latest audio data from the driver as a stream. This function reads audio data from the microphone stream and returns it as a fp_perception::audio_data. Best approach is to use this to get a certain amount of audio data by repeatedly calling this function until enough data is collected.
- Returns
- fp_perception::audio_data The latest audio chunk(s) from the driver.
- Exceptions
-
Implements fp_perception::AudioSourceDriver.
◆ resample_linear_interleaved()
| static std::vector< int16_t > fp_perception::MicrophoneAudioDriver::resample_linear_interleaved |
( |
const std::vector< int16_t > & |
input, |
|
|
int |
channels, |
|
|
int |
input_rate, |
|
|
int |
output_rate |
|
) |
| |
|
inlinestaticprotected |
◆ setup_diagnostics()
| void fp_perception::MicrophoneAudioDriver::setup_diagnostics |
( |
| ) |
|
|
inlineprotected |
◆ test()
| void fp_perception::MicrophoneAudioDriver::test |
( |
| ) |
|
|
inlineoverridevirtual |
Test the driver.
This function is used to test the driver functionality. It can be overridden in derived classes.
Reimplemented from fp_perception::DriverBase.
◆ write_samples_locked()
| void fp_perception::MicrophoneAudioDriver::write_samples_locked |
( |
const int16_t * |
samples, |
|
|
size_t |
sample_count |
|
) |
| |
|
inlineprotected |
◆ audio_buffer_
| std::vector<int16_t> fp_perception::MicrophoneAudioDriver::audio_buffer_ |
|
protected |
◆ buffer_size_
| int fp_perception::MicrophoneAudioDriver::buffer_size_ { 0 } |
|
protected |
◆ buffered_sample_count_
| size_t fp_perception::MicrophoneAudioDriver::buffered_sample_count_ { 0 } |
|
protected |
◆ capture_buffer_window_
| int fp_perception::MicrophoneAudioDriver::capture_buffer_window_ |
|
protected |
◆ capture_sample_rate_
| int fp_perception::MicrophoneAudioDriver::capture_sample_rate_ { 0 } |
|
protected |
◆ channels_
| int fp_perception::MicrophoneAudioDriver::channels_ |
|
protected |
◆ chunk_size_
| unsigned long fp_perception::MicrophoneAudioDriver::chunk_size_ |
|
protected |
◆ device_id_
| int fp_perception::MicrophoneAudioDriver::device_id_ |
|
protected |
◆ device_name_
| std::string fp_perception::MicrophoneAudioDriver::device_name_ |
|
protected |
◆ dropped_callback_chunks_
| std::atomic<uint64_t> fp_perception::MicrophoneAudioDriver::dropped_callback_chunks_ { 0 } |
|
protected |
◆ err
| PaError fp_perception::MicrophoneAudioDriver::err = paNoError |
|
protected |
◆ input_overflow_count_
| std::atomic<uint64_t> fp_perception::MicrophoneAudioDriver::input_overflow_count_ { 0 } |
|
protected |
◆ read_index_
| size_t fp_perception::MicrophoneAudioDriver::read_index_ { 0 } |
|
protected |
◆ sample_rate_
| int fp_perception::MicrophoneAudioDriver::sample_rate_ |
|
protected |
◆ stream_
| PaStream* fp_perception::MicrophoneAudioDriver::stream_ |
|
protected |
◆ timeout_sec_
| int fp_perception::MicrophoneAudioDriver::timeout_sec_ { -1 } |
|
protected |
◆ write_index_
| size_t fp_perception::MicrophoneAudioDriver::write_index_ { 0 } |
|
protected |
The documentation for this class was generated from the following file: