libivon 0.1.0
Voice-over-IP library
Loading...
Searching...
No Matches
ivon::AudioWrapper Class Reference

Consumer-facing C++ wrapper around the libivon audio C ABI. More...

#include <ivon_audio_wrapper.hpp>

Inheritance diagram for ivon::AudioWrapper:
ivon::IAudio

Classes

struct  Config
 Configuration for creating an audio processor. More...
 
struct  NonOwning
 Tag type for constructing a non-owning wrapper around an existing handle. More...
 

Public Types

using OutputFrame = AudioOutputFrame
 Structured output frame info returned by try_read_output().
 
using PcmSourceCallback = ::ivon::PcmSourceCallback
 Set the PCM source callback.
 
using PreDspCallback = IAudio::PreDspCallback
 
using PostSpatialCallback = IAudio::PostSpatialCallback
 
using PostMixCallback = IAudio::PostMixCallback
 
- Public Types inherited from ivon::IAudio
using SpeakingEventCallback = std::function< void(const ivon_speaking_event_t &event)>
 
using PreDspCallback = std::function< ivon_dsp_action_t(ivon_pre_dsp_context_t &ctx)>
 
using PostSpatialCallback = std::function< ivon_dsp_action_t(ivon_post_spatial_context_t &ctx)>
 
using PostMixCallback = std::function< ivon_dsp_action_t(ivon_post_mix_context_t &ctx)>
 

Public Member Functions

 AudioWrapper (const Config &cfg)
 Construct a wrapper and create the underlying audio processor.
 
 AudioWrapper (ivon_audio_t handle, NonOwning) noexcept
 Construct a non-owning wrapper around an existing handle.
 
 ~AudioWrapper ()
 
 AudioWrapper (const AudioWrapper &)=delete
 
AudioWrapperoperator= (const AudioWrapper &)=delete
 
 AudioWrapper (AudioWrapper &&)=delete
 
AudioWrapperoperator= (AudioWrapper &&)=delete
 
void start () override
 Start the audio processor (tick coordinator + worker threads).
 
void stop () override
 Stop the audio processor and all worker threads.
 
bool is_running () const noexcept override
 Check if the audio processor is running.
 
int pcm_frame_size () const noexcept override
 Get the PCM frame size in samples per channel.
 
int output_channels () const noexcept override
 Get the number of output channels (e.g. 1 = mono, 2 = stereo).
 
bool submit_packet (uint64_t sender_id, const unsigned char *data, size_t len) override
 Submit a received audio packet for decoding.
 
bool submit_packet (uint64_t sender_id, uint64_t group_id, const unsigned char *data, size_t len) override
 Submit a received audio packet with a group tag.
 
OutputFrame try_read_output (float *pcm_out, size_t max_samples) override
 Try to read a mixed output frame.
 
void set_pcm_source (PcmSourceCallback cb) override
 Set the PCM source callback for local audio capture.
 
void start_speaking (ivon_speaking_mode_t mode=IVON_SPEAKING_MODE_PTT) override
 Start speaking. The PCM source callback will begin firing.
 
void stop_speaking () override
 Stop speaking. The PCM source callback will stop firing.
 
bool is_speaking () const noexcept override
 Check if currently speaking.
 
size_t try_read_packet (unsigned char *data_out, size_t max_len) override
 Try to read an encoded packet for transmission.
 
void on_speaking_event (SpeakingEventCallback cb) override
 Set callback for remote speaking state changes (start/stop).
 
void on_pre_dsp (PreDspCallback cb) override
 Set pre-DSP callback invoked per sender before spatial processing.
 
void on_post_spatial (PostSpatialCallback cb) override
 Set post-spatial callback invoked per sender after spatial processing.
 
void on_post_mix (PostMixCallback cb) override
 Set post-mix callback invoked on the final mixed output frame.
 
void set_sender_gain (uint64_t sender_id, float gain) override
 Set per-sender gain. 1.0 = unity, 0.0 = silence.
 
void set_sender_muted (uint64_t sender_id, bool muted) override
 Mute or unmute a sender. Muted senders are excluded from the mix.
 
uint64_t current_tick () const noexcept override
 Get the current tick counter (incremented once per audio frame).
 
int64_t max_drift_us () const noexcept override
 Get the maximum clock drift in microseconds since the last reset.
 
uint64_t dropped_ticks () const noexcept override
 Get the total number of dropped (late) ticks.
 
ivon_audio_stats_t get_stats () const noexcept override
 Get aggregate statistics snapshot.
 
ivon_audio_t handle () const noexcept
 
- Public Member Functions inherited from ivon::IAudio
virtual ~IAudio ()=default
 

Detailed Description

Consumer-facing C++ wrapper around the libivon audio C ABI.

RAII handle: the constructor creates the processor, the destructor destroys it. Non-copyable, non-moveable; use std::unique_ptr for deferred initialization or ownership transfer.

All methods delegate to the corresponding ivon_audio_* C function.

Member Typedef Documentation

◆ OutputFrame

Structured output frame info returned by try_read_output().

◆ PcmSourceCallback

Set the PCM source callback.

Parameters
cbCalled once per audio frame while speaking. Receives a span of float to fill with mono PCM. Return true if audio was provided, false for silence.

◆ PostMixCallback

◆ PostSpatialCallback

◆ PreDspCallback

Constructor & Destructor Documentation

◆ AudioWrapper() [1/4]

ivon::AudioWrapper::AudioWrapper ( const Config cfg)
inlineexplicit

Construct a wrapper and create the underlying audio processor.

Exceptions
std::runtime_errorif creation fails.

◆ AudioWrapper() [2/4]

ivon::AudioWrapper::AudioWrapper ( ivon_audio_t  handle,
NonOwning   
)
inlineexplicitnoexcept

Construct a non-owning wrapper around an existing handle.

◆ ~AudioWrapper()

ivon::AudioWrapper::~AudioWrapper ( )
inline

◆ AudioWrapper() [3/4]

ivon::AudioWrapper::AudioWrapper ( const AudioWrapper )
delete

◆ AudioWrapper() [4/4]

ivon::AudioWrapper::AudioWrapper ( AudioWrapper &&  )
delete

Member Function Documentation

◆ current_tick()

uint64_t ivon::AudioWrapper::current_tick ( ) const
inlineoverridevirtualnoexcept

Get the current tick counter (incremented once per audio frame).

Implements ivon::IAudio.

◆ dropped_ticks()

uint64_t ivon::AudioWrapper::dropped_ticks ( ) const
inlineoverridevirtualnoexcept

Get the total number of dropped (late) ticks.

Implements ivon::IAudio.

◆ get_stats()

ivon_audio_stats_t ivon::AudioWrapper::get_stats ( ) const
inlineoverridevirtualnoexcept

Get aggregate statistics snapshot.

Returns decoder, encoder, and pipeline counters. Values are approximate while the processor is running.

Implements ivon::IAudio.

◆ handle()

ivon_audio_t ivon::AudioWrapper::handle ( ) const
inlinenoexcept

◆ is_running()

bool ivon::AudioWrapper::is_running ( ) const
inlineoverridevirtualnoexcept

Check if the audio processor is running.

Implements ivon::IAudio.

◆ is_speaking()

bool ivon::AudioWrapper::is_speaking ( ) const
inlineoverridevirtualnoexcept

Check if currently speaking.

Implements ivon::IAudio.

◆ max_drift_us()

int64_t ivon::AudioWrapper::max_drift_us ( ) const
inlineoverridevirtualnoexcept

Get the maximum clock drift in microseconds since the last reset.

Implements ivon::IAudio.

◆ on_post_mix()

void ivon::AudioWrapper::on_post_mix ( PostMixCallback  cb)
inlineoverridevirtual

Set post-mix callback invoked on the final mixed output frame.

Implements ivon::IAudio.

◆ on_post_spatial()

void ivon::AudioWrapper::on_post_spatial ( PostSpatialCallback  cb)
inlineoverridevirtual

Set post-spatial callback invoked per sender after spatial processing.

Implements ivon::IAudio.

◆ on_pre_dsp()

void ivon::AudioWrapper::on_pre_dsp ( PreDspCallback  cb)
inlineoverridevirtual

Set pre-DSP callback invoked per sender before spatial processing.

Implements ivon::IAudio.

◆ on_speaking_event()

void ivon::AudioWrapper::on_speaking_event ( SpeakingEventCallback  cb)
inlineoverridevirtual

Set callback for remote speaking state changes (start/stop).

Implements ivon::IAudio.

◆ operator=() [1/2]

AudioWrapper & ivon::AudioWrapper::operator= ( AudioWrapper &&  )
delete

◆ operator=() [2/2]

AudioWrapper & ivon::AudioWrapper::operator= ( const AudioWrapper )
delete

◆ output_channels()

int ivon::AudioWrapper::output_channels ( ) const
inlineoverridevirtualnoexcept

Get the number of output channels (e.g. 1 = mono, 2 = stereo).

Implements ivon::IAudio.

◆ pcm_frame_size()

int ivon::AudioWrapper::pcm_frame_size ( ) const
inlineoverridevirtualnoexcept

Get the PCM frame size in samples per channel.

Implements ivon::IAudio.

◆ set_pcm_source()

void ivon::AudioWrapper::set_pcm_source ( PcmSourceCallback  cb)
inlineoverridevirtual

Set the PCM source callback for local audio capture.

Implements ivon::IAudio.

◆ set_sender_gain()

void ivon::AudioWrapper::set_sender_gain ( uint64_t  sender_id,
float  gain 
)
inlineoverridevirtual

Set per-sender gain. 1.0 = unity, 0.0 = silence.

Implements ivon::IAudio.

◆ set_sender_muted()

void ivon::AudioWrapper::set_sender_muted ( uint64_t  sender_id,
bool  muted 
)
inlineoverridevirtual

Mute or unmute a sender. Muted senders are excluded from the mix.

Implements ivon::IAudio.

◆ start()

void ivon::AudioWrapper::start ( )
inlineoverridevirtual

Start the audio processor (tick coordinator + worker threads).

Implements ivon::IAudio.

◆ start_speaking()

void ivon::AudioWrapper::start_speaking ( ivon_speaking_mode_t  mode = IVON_SPEAKING_MODE_PTT)
inlineoverridevirtual

Start speaking. The PCM source callback will begin firing.

Implements ivon::IAudio.

◆ stop()

void ivon::AudioWrapper::stop ( )
inlineoverridevirtual

Stop the audio processor and all worker threads.

Implements ivon::IAudio.

◆ stop_speaking()

void ivon::AudioWrapper::stop_speaking ( )
inlineoverridevirtual

Stop speaking. The PCM source callback will stop firing.

Implements ivon::IAudio.

◆ submit_packet() [1/2]

bool ivon::AudioWrapper::submit_packet ( uint64_t  sender_id,
const unsigned char *  data,
size_t  len 
)
inlineoverridevirtual

Submit a received audio packet for decoding.

Returns
true if the packet was accepted.

Implements ivon::IAudio.

◆ submit_packet() [2/2]

bool ivon::AudioWrapper::submit_packet ( uint64_t  sender_id,
uint64_t  group_id,
const unsigned char *  data,
size_t  len 
)
inlineoverridevirtual

Submit a received audio packet with a group tag.

Parameters
sender_idUnique identifier for the sender.
group_idGroup the packet belongs to (0 = untagged).
dataAudio payload bytes.
lenLength of the payload in bytes.
Returns
true if the packet was accepted.

Implements ivon::IAudio.

◆ try_read_output()

OutputFrame ivon::AudioWrapper::try_read_output ( float *  pcm_out,
size_t  max_samples 
)
inlineoverridevirtual

Try to read a mixed output frame.

Parameters
pcm_outBuffer for interleaved float PCM.
max_samplesMaximum float samples the buffer can hold.
Returns
OutputFrame descriptor — check .valid.

Implements ivon::IAudio.

◆ try_read_packet()

size_t ivon::AudioWrapper::try_read_packet ( unsigned char *  data_out,
size_t  max_len 
)
inlineoverridevirtual

Try to read an encoded packet for transmission.

Parameters
data_outBuffer for encoded bytes.
max_lenMaximum bytes the buffer can hold.
Returns
Number of bytes written, 0 if no packet available.

Implements ivon::IAudio.


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