LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
livekit::AudioFrame Class Reference

Represents a raw PCM audio frame with interleaved int16 samples. More...

#include <audio_frame.h>

Public Member Functions

 AudioFrame (std::vector< std::int16_t > data, int sample_rate, int num_channels, int samples_per_channel)
 
const std::vector< std::int16_t > & data () const noexcept
 
std::vector< std::int16_t > & data () noexcept
 
std::size_t total_samples () const noexcept
 Number of samples in the buffer (per all channels).
 
int sample_rate () const noexcept
 Sample rate in Hz.
 
int num_channels () const noexcept
 Number of channels.
 
int samples_per_channel () const noexcept
 Samples per channel.
 
double duration () const noexcept
 Duration in seconds (samples_per_channel / sample_rate).
 
std::string to_string () const
 A human-readable description.
 

Static Public Member Functions

static AudioFrame create (int sample_rate, int num_channels, int samples_per_channel)
 
static AudioFrame fromOwnedInfo (const proto::OwnedAudioFrameBuffer &owned)
 

Protected Member Functions

proto::AudioFrameBufferInfo toProto () const
 

Friends

class AudioSource
 

Detailed Description

Represents a raw PCM audio frame with interleaved int16 samples.

AudioFrame holds decoded audio data along with metadata such as sample rate, number of channels, and samples per channel. It is used for capturing and processing audio in the LiveKit SDK.

Constructor & Destructor Documentation

◆ AudioFrame()

livekit::AudioFrame::AudioFrame ( std::vector< std::int16_t >  data,
int  sample_rate,
int  num_channels,
int  samples_per_channel 
)

Construct an AudioFrame from raw PCM samples.

Parameters
dataInterleaved PCM samples (int16).
sample_rateSample rate (Hz).
num_channelsNumber of channels.
samples_per_channelNumber of samples per channel.

Throws std::invalid_argument if the data size is inconsistent with num_channels * samples_per_channel.

Member Function Documentation

◆ create()

static AudioFrame livekit::AudioFrame::create ( int  sample_rate,
int  num_channels,
int  samples_per_channel 
)
static

Create a new zero-initialized AudioFrame instance.

◆ fromOwnedInfo()

static AudioFrame livekit::AudioFrame::fromOwnedInfo ( const proto::OwnedAudioFrameBuffer &  owned)
static

Construct an AudioFrame by copying data out of an OwnedAudioFrameBuffer.


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