12 #ifndef ROC_AUDIO_SAMPLE_SPEC_H_
13 #define ROC_AUDIO_SAMPLE_SPEC_H_
89 size_t default_sample_rate);
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Channel set. Multi-word bitmask with bits corresponding to enabled channels. Meaning of each channel ...
Sample specification. Describes sample rate and channels.
double stream_timestamp_2_ms(packet::stream_timestamp_t sts_duration) const
Convert stream timestamp to milliseconds.
SampleFormat sample_format() const
Get sample format.
void set_channel_set(const ChannelSet &channel_set)
Set channel set.
SampleSpec(size_t sample_rate, PcmFormat pcm_fmt, const ChannelSet &channel_set)
Construct specification with parameters.
size_t ns_2_samples_overall(core::nanoseconds_t ns_duration) const
Convert nanoseconds duration to number of samples for all channels.
core::nanoseconds_t fract_samples_overall_2_ns(float n_samples) const
Convert number of samples (possibly non-integer) to nanoseconds.
core::nanoseconds_t stream_timestamp_delta_2_ns(packet::stream_timestamp_diff_t sts_delta) const
Convert stream timestamp delta to nanoseconds delta.
bool operator==(const SampleSpec &other) const
Check two specifications for equality.
bool is_valid() const
Check if sample spec has non-zero rate and valid channel set.
core::nanoseconds_t stream_timestamp_2_ns(packet::stream_timestamp_t sts_duration) const
Convert stream timestamp to nanoseconds.
bool is_empty() const
Check if sample spec has a zero rate, empty channel set, and invalid_format.
SampleSpec(size_t sample_rate, PcmFormat pcm_fmt, ChannelLayout channel_layout, ChannelOrder channel_order, ChannelMask channel_mask)
Construct specification with parameters.
void clear()
Unset all fields.
void use_defaults(PcmFormat default_pcm_fmt, ChannelLayout default_channel_layout, ChannelOrder default_channel_order, ChannelMask default_channel_mask, size_t default_sample_rate)
Set missing fields from provided defaults.
void set_pcm_format(PcmFormat pcm_fmt)
Set PCM format.
double stream_timestamp_delta_2_ms(packet::stream_timestamp_diff_t sts_duration) const
Convert stream timestamp delta to milliseconds.
size_t stream_timestamp_2_bytes(packet::stream_timestamp_t duration) const
Convert stream timestamp to byte size.
void set_sample_format(SampleFormat sample_fmt)
Set sample format.
size_t num_channels() const
Get number enabled channels in channel set.
SampleSpec()
Construct empty specification.
core::nanoseconds_t bytes_2_ns(size_t n_bytes) const
Convert byte size to nanosecond duration.
size_t sample_rate() const
Get sample rate.
bool operator!=(const SampleSpec &other) const
Check two specifications for equality.
const ChannelSet & channel_set() const
Get channel set.
void set_sample_rate(size_t sample_rate)
Set sample rate.
core::nanoseconds_t samples_overall_2_ns(size_t n_samples) const
Convert number of samples for all channels to nanoseconds duration.
core::nanoseconds_t samples_per_chan_2_ns(size_t n_samples) const
Convert number of samples per channel to nanoseconds duration.
core::nanoseconds_t fract_samples_per_chan_2_ns(float n_samples) const
Convert (possibly fractional) number samples per channel to nanoseconds duration.
packet::stream_timestamp_t ns_2_stream_timestamp(core::nanoseconds_t ns_duration) const
Convert nanoseconds delta to stream timestamp.
packet::stream_timestamp_diff_t ns_2_stream_timestamp_delta(core::nanoseconds_t ns_delta) const
Convert nanoseconds delta to stream timestamp delta.
packet::stream_timestamp_t bytes_2_stream_timestamp(size_t n_bytes) const
Convert byte size to stream timestamp.
PcmFormat pcm_format() const
Get PCM format.
size_t ns_2_samples_per_chan(core::nanoseconds_t ns_duration) const
Convert nanoseconds duration to number of samples per channel.
ChannelSet & channel_set()
Get mutable channel set.
size_t ns_2_bytes(core::nanoseconds_t duration) const
Convert nanosecond duration to byte size.
bool is_raw() const
Check if samples are in raw format.
void format_sample_spec(const SampleSpec &sample_spec, core::StringBuilder &bld)
Format sample spec to string.
SampleFormat
Sample format. Defines representation of samples in memory. Does not define sample rate and channel s...
ChannelLayout
Channel layout. Defines meaning of channels in ChannelSet. ChannelMapper uses channel layout to decid...
uint32_t ChannelMask
Channel mask.
ROC_ATTR_NODISCARD bool parse_sample_spec(const char *str, SampleSpec &result)
Parse sample spec from string.
PcmFormat
PCM format. Defines PCM sample coding and endian.
ChannelOrder
Surround channel order.
int64_t nanoseconds_t
Nanoseconds.
uint32_t stream_timestamp_t
Packet stream timestamp.
int32_t stream_timestamp_diff_t
Packet stream timestamp delta.
Commonly used types and functions.
Various units used in packets.