Zao SDK for Jetson / libzep API リファレンス  1.0.0.0 (2023-05-08)
PcmFormat.hpp
1 #ifndef ZEP_AUDIO_PCM_FORMAT_HPP_
2 #define ZEP_AUDIO_PCM_FORMAT_HPP_
3 
4 #include <memory>
5 #include <string>
6 
7 namespace zep {
8 namespace audio {
9 
13 class PcmFormat {
14  public:
19  PcmFormat() noexcept {}
20 
27  PcmFormat(int sampling_rate, unsigned channel_mask) noexcept {
28  SetSamplingRate(sampling_rate);
29  SetChannelMask(channel_mask);
30  }
31 
35  int GetSamplingRate() const noexcept { return sampling_rate_; }
36 
42  void SetSamplingRate(int new_value) noexcept { sampling_rate_ = new_value; }
43 
47  enum ChannelBits : unsigned {
48  kLeftChannel = (1u << 0),
49  kRightChannel = (1u << 1),
50  kStereo = kLeftChannel | kRightChannel,
51  };
52 
58  unsigned GetChannelMask() const noexcept { return channel_mask_; }
59 
65  void SetChannelMask(unsigned new_value) noexcept {
66  channel_mask_ = new_value;
67  }
68 
73  int GetNumOfChannels() const noexcept {
74  auto mask = channel_mask_;
75  int num_of_channels = 0;
76  while (mask) {
77  if (mask & 1) {
78  ++num_of_channels;
79  }
80  mask >>= 1;
81  }
82  return num_of_channels;
83  }
84 
92  bool operator==(const PcmFormat& other) const noexcept {
93  return sampling_rate_ == other.sampling_rate_ &&
94  channel_mask_ == other.channel_mask_;
95  }
96 
104  bool operator!=(const PcmFormat& other) const noexcept {
105  return !(*this == other);
106  }
107 
108  private:
112  int sampling_rate_ = 0;
113 
117  unsigned channel_mask_ = 0u;
118 };
119 
120 } // namespace audio
121 } // namespace zep
122 
123 #endif // ZEP_AUDIO_PCM_FORMAT_HPP_
ZEP SDK用名前空間
Definition: FactoryInterface.hpp:10
void SetSamplingRate(int new_value) noexcept
サンプリングレート(Hz単位)を設定する。
Definition: PcmFormat.hpp:42
bool operator!=(const PcmFormat &other) const noexcept
PcmFormat同士を非等値比較する
Definition: PcmFormat.hpp:104
void SetChannelMask(unsigned new_value) noexcept
チャンネルマスクを設定する。
Definition: PcmFormat.hpp:65
PcmFormat() noexcept
PcmFormatオブジェクトをデフォルト構築する。
Definition: PcmFormat.hpp:19
PcmFormat(int sampling_rate, unsigned channel_mask) noexcept
PcmFormatオブジェクトを初期値付きで構築する。
Definition: PcmFormat.hpp:27
int GetNumOfChannels() const noexcept
チャンネル数を取得する。
Definition: PcmFormat.hpp:73
PCM音声のフォーマット
Definition: PcmFormat.hpp:13
unsigned GetChannelMask() const noexcept
チャンネルマスクを取得する。
Definition: PcmFormat.hpp:58
bool operator==(const PcmFormat &other) const noexcept
PcmFormat同士を等値比較する
Definition: PcmFormat.hpp:92
ChannelBits
チャンネルマスクの値定義
Definition: PcmFormat.hpp:47
int GetSamplingRate() const noexcept
サンプリングレート(Hz単位)を取得する。
Definition: PcmFormat.hpp:35