Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
sample_spec.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_audio/sample_spec.h
10//! @brief Sample specifications.
11
12#ifndef ROC_AUDIO_SAMPLE_SPEC_H_
13#define ROC_AUDIO_SAMPLE_SPEC_H_
14
15#include "roc_audio/sample.h"
16#include "roc_core/time.h"
17#include "roc_packet/units.h"
18
19namespace roc {
20namespace audio {
21
22//! Sample stream specification.
23//! Defines sample rate and channel layout.
25public:
26 //! Default constructor.
28
29 //! Constructor with sample rate and channel mask.
31
32 //! @name Equality
33 //! @{
34
35 //! Check two specifications for equality.
36 bool operator==(const SampleSpec& other) const;
37
38 //! Check two specifications for equality.
39 bool operator!=(const SampleSpec& other) const;
40
41 // @}
42
43 //! @name Getters and setters
44 //! @{
45
46 //! Get sample rate.
47 size_t sample_rate() const;
48
49 //! Set sample rate.
51
52 //! Get channel mask.
54
55 //! Get number of channels.
56 size_t num_channels() const;
57
58 //! Set channel mask.
60
61 // @}
62
63 //! @name Nanosecond duration
64 //! @{
65
66 //! Convert nanoseconds duration to number of samples per channel.
67 size_t ns_2_samples_per_chan(core::nanoseconds_t ns_duration) const;
68
69 //! Convert number of samples per channel to nanoseconds duration.
71
72 //! Convert nanoseconds duration to number of samples for all channels.
73 size_t ns_2_samples_overall(core::nanoseconds_t ns_duration) const;
74
75 //! Convert number of samples for all channels to nanoseconds duration.
77
78 // @}
79
80 //! @name RTP timestamp
81 //! @{
82
83 //! Convert nanoseconds delta to RTP timestamp delta.
84 //! @note
85 //! Same as ns_2_samples_per_chan(), but supports negative deltas.
87
88 //! Convert RTP timestamp delta to nanoseconds delta.
89 //! @note
90 //! Same as samples_per_chan_2_ns(), but supports negative deltas.
92
93 // @}
94
95private:
96 size_t sample_rate_;
97 packet::channel_mask_t channel_mask_;
98 size_t num_channels_;
99};
100
101} // namespace audio
102} // namespace roc
103
104#endif // ROC_AUDIO_SAMPLE_SPEC_H_
Sample stream specification. Defines sample rate and channel layout.
Definition sample_spec.h:24
size_t ns_2_samples_overall(core::nanoseconds_t ns_duration) const
Convert nanoseconds duration to number of samples for all channels.
packet::timestamp_diff_t ns_2_rtp_timestamp(core::nanoseconds_t ns_delta) const
Convert nanoseconds delta to RTP timestamp delta.
bool operator==(const SampleSpec &other) const
Check two specifications for equality.
SampleSpec(size_t sample_rate, packet::channel_mask_t channel_mask)
Constructor with sample rate and channel mask.
size_t num_channels() const
Get number of channels.
SampleSpec()
Default constructor.
packet::channel_mask_t channel_mask() const
Get channel mask.
size_t sample_rate() const
Get sample rate.
bool operator!=(const SampleSpec &other) const
Check two specifications for equality.
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.
size_t ns_2_samples_per_chan(core::nanoseconds_t ns_duration) const
Convert nanoseconds duration to number of samples per channel.
core::nanoseconds_t rtp_timestamp_2_ns(packet::timestamp_diff_t rtp_delta) const
Convert RTP timestamp delta to nanoseconds delta.
void set_channel_mask(packet::channel_mask_t channel_mask)
Set channel mask.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition units.h:94
int32_t timestamp_diff_t
Audio packet timestamps difference.
Definition units.h:28
Root namespace.
Audio sample.
Time definitions.
Various units used in packets.