Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::audio Namespace Reference

Audio frames and audio processing. More...

Classes

class  BuiltinResampler
 Built-in resampler. More...
 
class  ChannelMapper
 Channel mapper. Converts between frames with specified channel masks. More...
 
class  ChannelMapperMatrix
 Contain conversation coefficients while mapping surround to surround. More...
 
class  ChannelMapperReader
 Channel mapper reader. Reads frames from nested reader and maps them to another channel mask. More...
 
struct  ChannelMapRule
 Defines multiplication coefficient for a pair of channels. More...
 
struct  ChannelMap
 Defines multiplication matrix for two channel masks. Instead of defining the whole matrix, it defines a list of pairs of output and input channel numbers and corresponding coefficients. Such representation allows more compact definition in the source code. The actual matrix is built by channel mapper at runtime. More...
 
struct  ChannelList
 Defines ordered list of channels. More...
 
class  ChannelMapperWriter
 Channel mapper writer. Reads frames from nested writer and maps them to another channel mask. More...
 
class  ChannelSet
 Channel set. Multi-word bitmask with bits corresponding to enabled channels. Meaning of each channel is defined by ChannelLayout. Order of serialized channels is defined by ChannelOrder. More...
 
class  channel_set_to_str
 Format ChannelSet to string. More...
 
class  DecimationResampler
 Decimating resampler. More...
 
class  Depacketizer
 Depacketizer. More...
 
class  Fanout
 Fanout. Duplicates audio stream to multiple output writers. More...
 
class  Frame
 Audio frame. More...
 
struct  FreqEstimatorConfig
 FreqEstimator tunable parameters. More...
 
class  FreqEstimator
 Evaluates sender's frequency to receivers's frequency ratio. More...
 
class  IFrameDecoder
 Audio frame decoder interface. More...
 
class  IFrameEncoder
 Audio frame encoder interface. More...
 
class  IFrameReader
 Frame reader interface. More...
 
class  IFrameWriter
 Frame writer interface. More...
 
class  IResampler
 Audio writer interface. More...
 
struct  LatencyMonitorConfig
 Parameters for latency monitor. More...
 
struct  LatencyMonitorMetrics
 Metrics of latency monitor. More...
 
class  LatencyMonitor
 Latency monitor. More...
 
class  Mixer
 Mixer. Mixes multiple input streams into one output stream. More...
 
class  NullWriter
 Null writer. More...
 
class  Packetizer
 Packetizer. More...
 
class  PcmDecoder
 PCM decoder. More...
 
class  PcmEncoder
 PCM encoder. More...
 
struct  PcmFormat
 PCM format description. More...
 
struct  PcmTraits
 PCM format meta-information. More...
 
class  PcmMapper
 PCM format mapper. Convert between PCM formats. More...
 
class  PoisonReader
 Poisons audio frames before reading them. More...
 
struct  ProfilerConfig
 Profiler Configuration Parameters. Controls profiling interval and duration of each circular buffer chunk. More...
 
class  Profiler
 Profiler The role of the profiler is to report the average processing speed (# of samples processed per time unit) during the last N seconds. We want to calculate the average processing speed efficiently (with O(1) complexity, without allocations, and as lightweight as possible). The problems with this are that we have variable-sized frames and SMA requires fixed-size chunks. To efficiently perform this calculation a ring buffer is employed. The idea behind the ring buffer is that each chunk of the buffer is the average speed of 10ms worth of samples. The ring buffer is initialized with fixed size (N * 1000)ms / (10ms) chunks. Within each chunk a weighted mean is used to calculate the average speed during those 10ms. Each frame will contribute a different number of samples to each chunk, the chunk speed is then weighted based on how many samples are contributed at what frame speed. As the chunks get populated the moving average is calculated. When the buffer is not entirely full the cumulative moving average algorithm is used and once the buffer is full the simple moving average algorithm is used. More...
 
class  ProfilingReader
 Profiling reader. More...
 
class  ProfilingWriter
 Profiling writer. More...
 
class  ResamplerMap
 Factory class for IResampler objects, according to the ResamplerBackend input. More...
 
class  ResamplerReader
 Resampler element for reading pipeline. More...
 
class  ResamplerWriter
 Resampler element for writing pipeline. More...
 
class  SampleSpec
 Sample specification. Describes sample rate and channels. More...
 
class  sample_spec_to_str
 Format SampleSpec to string. More...
 
class  SpeexResampler
 Speex resampler. More...
 
struct  WatchdogConfig
 Watchdog parameters. More...
 
class  Watchdog
 Watchdog. More...
 

Typedefs

typedef uint32_t ChannelMask
 Channel mask. More...
 
typedef float sample_t
 Audio sample. More...
 

Enumerations

enum  ChannelLayout { ChanLayout_None , ChanLayout_Surround , ChanLayout_Multitrack }
 Channel layout. Defines meaning of channels in ChannelSet. ChannelMapper uses channel layout to decide how to perform mapping. More...
 
enum  ChannelOrder { ChanOrder_None , ChanOrder_Smpte , ChanOrder_Alsa , ChanOrder_Max }
 Surround channel order. More...
 
enum  ChannelPosition {
  ChanPos_FrontLeft , ChanPos_FrontCenter , ChanPos_FrontRight , ChanPos_SideLeft ,
  ChanPos_SideRight , ChanPos_BackLeft , ChanPos_BackCenter , ChanPos_BackRight ,
  ChanPos_TopFrontLeft , ChanPos_TopFrontRight , ChanPos_TopMidLeft , ChanPos_TopMidRight ,
  ChanPos_TopBackLeft , ChanPos_TopBackRight , ChanPos_LowFrequency , ChanPos_Max
}
 Surround channel position. More...
 
enum  FreqEstimatorProfile { FreqEstimatorProfile_Responsive , FreqEstimatorProfile_Gradual }
 FreqEstimator paremeter preset. More...
 
enum  PcmCode {
  PcmCode_SInt8 , PcmCode_UInt8 , PcmCode_SInt16 , PcmCode_UInt16 ,
  PcmCode_SInt18 , PcmCode_UInt18 , PcmCode_SInt18_3 , PcmCode_UInt18_3 ,
  PcmCode_SInt18_4 , PcmCode_UInt18_4 , PcmCode_SInt20 , PcmCode_UInt20 ,
  PcmCode_SInt20_3 , PcmCode_UInt20_3 , PcmCode_SInt20_4 , PcmCode_UInt20_4 ,
  PcmCode_SInt24 , PcmCode_UInt24 , PcmCode_SInt24_4 , PcmCode_UInt24_4 ,
  PcmCode_SInt32 , PcmCode_UInt32 , PcmCode_SInt64 , PcmCode_UInt64 ,
  PcmCode_Float32 , PcmCode_Float64 , PcmCode_Max
}
 PCM sample binary code. More...
 
enum  PcmEndian { PcmEndian_Native , PcmEndian_Big , PcmEndian_Little }
 PCM sample endianess. More...
 
enum  ResamplerBackend { ResamplerBackend_Default , ResamplerBackend_Builtin , ResamplerBackend_Speex , ResamplerBackend_SpeexDec }
 Resampler backends. More...
 
enum  ResamplerProfile { ResamplerProfile_Low , ResamplerProfile_Medium , ResamplerProfile_High }
 Resampler parameters presets. More...
 

Functions

const char * channel_layout_to_str (ChannelLayout)
 Get string name of channel layout. More...
 
const char * channel_order_to_str (ChannelOrder)
 Get string name of channel order. More...
 
const char * channel_position_to_str (ChannelPosition)
 Get string name of channel position. More...
 
void format_channel_set (const ChannelSet &ch_set, core::StringBuilder &bld)
 Format ChannelSet to string. More...
 
const char * fe_profile_to_str (FreqEstimatorProfile profile)
 Get string name of FreqEstimator profile. More...
 
const char * pcm_format_to_str (const PcmFormat &fmt)
 Get string name of PCM format. More...
 
ROC_ATTR_NODISCARD bool pcm_format_parse (const char *str, PcmFormat &fmt)
 Parse PCM format from string name. More...
 
PcmTraits pcm_format_traits (const PcmFormat &fmt)
 Get traits for PCM format. More...
 
const char * resampler_backend_to_str (ResamplerBackend)
 Get string name of resampler backend. More...
 

Variables

const size_t chan_map_count = 40
 Number of defined channel mappings. More...
 
const ChannelMap chan_maps [chan_map_count]
 Defines list of mappings between all supported surround channel mask pairs. Channel mapper will search for appropriate mapping in this list, based on input and output channel masks. More...
 
const ChannelList chan_orders [ChanOrder_Max]
 Defines mapping of channel order identifier to list of channel positions in corresponding order. More...
 
const double fe_decim_h [fe_decim_len]
 Impulse response of decimation filter with factor of 10. More...
 
const double fe_decim_h_gain
 Filters gain, sum(fe_decim_h). More...
 
const PcmFormat SampleFormat
 Sample format description. More...
 
const sample_t SampleMin
 Minimum possible value of a sample. More...
 
const sample_t SampleMax
 Maximum possible value of a sample. More...
 

Detailed Description

Audio frames and audio processing.

Typedef Documentation

◆ ChannelMask

typedef uint32_t roc::audio::ChannelMask

Channel mask.

Remarks
Used to construct short channel sets (up to 32 channels) for ChanLayout_Surround layout.

Definition at line 144 of file channel_defs.h.

◆ sample_t

typedef float roc::audio::sample_t

Audio sample.

Definition at line 22 of file sample.h.

Enumeration Type Documentation

◆ ChannelLayout

Channel layout. Defines meaning of channels in ChannelSet. ChannelMapper uses channel layout to decide how to perform mapping.

Enumerator
ChanLayout_None 

Channel layout is not set.

Remarks
This is never valid and indicates that ChannelSet is not fully initialized.
ChanLayout_Surround 

Multi-channel mono / stereo / surround sound.

Remarks
The meaning of channel index is defined by ChannelPosition enum. Channels are mapped according to their position in space, e.g. if top-left channel is missing, it can be mixed from front-left and side-left channels.
ChanLayout_Multitrack 

Multi-channel multi-track sound.

Remarks
There is no special meaning of channels, they are considered to be independent tracks. Channels are mapped according to their numbers; channel N is mapped to channel N and nothing else.

Definition at line 23 of file channel_defs.h.

◆ ChannelOrder

Surround channel order.

Remarks
Should be used with ChannelLayout_Surround. Defines order in which channels from ChannelSet are (de)serialized.
Enumerator
ChanOrder_None 

Channel order is not set.

Remarks
For ChanLayout_Surround, this is never valid and indicates that ChannelSet is not fully initialized. For ChanLayout_Multitrack, in contrast, this is the only valid value.
ChanOrder_Smpte 

ITU/SMPTE channel order. Order: FL, FR, FC, LFE, BL, BR, BC, SL, SR, TFL, TFR, TBL, TBR, TML, TMR.

Remarks
This order is actually a superset of what is defined by SMPTE, but when fileterd by actual masks like 5.1 or 7.1, it produces orderings equal to what is defined in the standard. When used with masks 2.x - 5.x (but not 6.x), it is also compatible with the channel order from AIFF-C, which is used by default in RTP/AVP, as defined in RFC 3551.
ChanOrder_Alsa 

ALSA channel order. Order: FL, FR, BL, BR, FC, LFE, SL, SR, BC.

Remarks
This order is used by ALSA hardware devices. ALSA supports only 9 channels.
ChanOrder_Max 

Maximum value of enum.

Definition at line 49 of file channel_defs.h.

◆ ChannelPosition

Surround channel position.

Remarks
Should be used with ChannelLayout_Surround. Defines meaning of channel indicies for mono / stereo / surround sound.
Note
Despide mono, stereo, and 3.x technically are not surround layouts, in the code base they are considered a special case of surround.
Enumerator
ChanPos_FrontLeft 

Front left (FL).

ChanPos_FrontCenter 

Front center (FC).

ChanPos_FrontRight 

Front right (FR).

ChanPos_SideLeft 

Side left (SL).

ChanPos_SideRight 

Side right (SR).

ChanPos_BackLeft 

Back left (BL).

ChanPos_BackCenter 

Back center (BC).

ChanPos_BackRight 

Back right (BR).

ChanPos_TopFrontLeft 

Top front left (TFL).

ChanPos_TopFrontRight 

Top front right (TFR).

ChanPos_TopMidLeft 

Top middle left (TML).

ChanPos_TopMidRight 

Top middle right (TMR).

ChanPos_TopBackLeft 

Top rear left (TBL).

ChanPos_TopBackRight 

Top rear right (TBR).

ChanPos_LowFrequency 

Low frequency speaker (LFE).

Remarks
Placed anywhere. Also known as "subwoofer" or "SW" speaker.
ChanPos_Max 

Maximum value of enum.

Definition at line 86 of file channel_defs.h.

◆ FreqEstimatorProfile

FreqEstimator paremeter preset.

Enumerator
FreqEstimatorProfile_Responsive 

Fast and responsive tuning. Good for lower network latency and jitter.

FreqEstimatorProfile_Gradual 

Slow and smooth tuning. Good for higher network latency and jitter.

Definition at line 24 of file freq_estimator.h.

◆ PcmCode

PCM sample binary code.

Enumerator
PcmCode_SInt8 

8-bit signed integer.

PcmCode_UInt8 

8-bit unsigned integer.

PcmCode_SInt16 

16-bit signed integer.

PcmCode_UInt16 

16-bit unsigned integer.

PcmCode_SInt18 

18-bit signed integer (2.25 bytes).

PcmCode_UInt18 

18-bit unsigned integer (2.25 bytes).

PcmCode_SInt18_3 

18-bit signed integer, in low bits of 3-byte container.

PcmCode_UInt18_3 

18-bit unsigned integer, in low bits of 3-byte container.

PcmCode_SInt18_4 

18-bit signed integer, in low bits of 4-byte container.

PcmCode_UInt18_4 

18-bit unsigned integer, in low bits of 4-byte container.

PcmCode_SInt20 

20-bit signed integer (2.5 bytes).

PcmCode_UInt20 

20-bit unsigned integer (2.5 bytes).

PcmCode_SInt20_3 

20-bit signed integer, in low bits of 3-byte container.

PcmCode_UInt20_3 

20-bit unsigned integer, in low bits of 3-byte container.

PcmCode_SInt20_4 

20-bit signed integer, in low bits of 4-byte container.

PcmCode_UInt20_4 

20-bit unsigned integer, in low bits of 4-byte container.

PcmCode_SInt24 

24-bit signed integer (3 bytes).

PcmCode_UInt24 

24-bit unsigned integer (3 bytes).

PcmCode_SInt24_4 

24-bit signed integer, in low bits of 4-byte container.

PcmCode_UInt24_4 

24-bit unsigned integer, in low bits of 4-byte container.

PcmCode_SInt32 

32-bit signed integer.

PcmCode_UInt32 

32-bit unsigned integer.

PcmCode_SInt64 

64-bit signed integer.

PcmCode_UInt64 

64-bit unsigned integer.

PcmCode_Float32 

32-bit IEEE-754 float in range [-1.0; +1.0].

PcmCode_Float64 

64-bit IEEE-754 float in range [-1.0; +1.0].

PcmCode_Max 

Maximum value.

Definition at line 22 of file pcm_format.h.

◆ PcmEndian

PCM sample endianess.

Enumerator
PcmEndian_Native 

Endian native to current CPU.

PcmEndian_Big 

Big endian.

PcmEndian_Little 

Little endian.

Definition at line 54 of file pcm_format.h.

◆ ResamplerBackend

Resampler backends.

Enumerator
ResamplerBackend_Default 

Default backend. Resolved to one of other backends, depending on what is enabled at build time.

ResamplerBackend_Builtin 

Built-in resampler. High precision, high quality, slow.

ResamplerBackend_Speex 

SpeexDSP resampler. Low precision, high quality, fast. May be disabled at build time.

ResamplerBackend_SpeexDec 

Combined SpeexDSP + decimating resampler. Tolerable precision, tolerable quality, fast. May be disabled at build time.

Definition at line 19 of file resampler_backend.h.

◆ ResamplerProfile

Resampler parameters presets.

Enumerator
ResamplerProfile_Low 

Low quality, fast speed.

ResamplerProfile_Medium 

Medium quality, medium speed.

ResamplerProfile_High 

Hight quality, low speed.

Definition at line 19 of file resampler_profile.h.

Function Documentation

◆ channel_layout_to_str()

const char* roc::audio::channel_layout_to_str ( ChannelLayout  )

Get string name of channel layout.

◆ channel_order_to_str()

const char* roc::audio::channel_order_to_str ( ChannelOrder  )

Get string name of channel order.

◆ channel_position_to_str()

const char* roc::audio::channel_position_to_str ( ChannelPosition  )

Get string name of channel position.

◆ fe_profile_to_str()

const char* roc::audio::fe_profile_to_str ( FreqEstimatorProfile  profile)

Get string name of FreqEstimator profile.

◆ format_channel_set()

void roc::audio::format_channel_set ( const ChannelSet ch_set,
core::StringBuilder bld 
)

Format ChannelSet to string.

◆ pcm_format_parse()

ROC_ATTR_NODISCARD bool roc::audio::pcm_format_parse ( const char *  str,
PcmFormat fmt 
)

Parse PCM format from string name.

◆ pcm_format_to_str()

const char* roc::audio::pcm_format_to_str ( const PcmFormat fmt)

Get string name of PCM format.

◆ pcm_format_traits()

PcmTraits roc::audio::pcm_format_traits ( const PcmFormat fmt)

Get traits for PCM format.

◆ resampler_backend_to_str()

const char* roc::audio::resampler_backend_to_str ( ResamplerBackend  )

Get string name of resampler backend.

Variable Documentation

◆ chan_map_count

const size_t roc::audio::chan_map_count = 40

Number of defined channel mappings.

Definition at line 50 of file channel_mapper_table.h.

◆ chan_maps

const ChannelMap roc::audio::chan_maps[chan_map_count]
extern

Defines list of mappings between all supported surround channel mask pairs. Channel mapper will search for appropriate mapping in this list, based on input and output channel masks.

◆ chan_orders

const ChannelList roc::audio::chan_orders[ChanOrder_Max]
extern

Defines mapping of channel order identifier to list of channel positions in corresponding order.

◆ fe_decim_h

const double roc::audio::fe_decim_h[fe_decim_len]
extern

Impulse response of decimation filter with factor of 10.

◆ fe_decim_h_gain

const double roc::audio::fe_decim_h_gain
extern

Filters gain, sum(fe_decim_h).

◆ SampleFormat

const PcmFormat roc::audio::SampleFormat
extern

Sample format description.

◆ SampleMax

const sample_t roc::audio::SampleMax
extern

Maximum possible value of a sample.

◆ SampleMin

const sample_t roc::audio::SampleMin
extern

Minimum possible value of a sample.