HephAudio v3.1.0
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
AudioChannelLayout.h
Go to the documentation of this file.
1#pragma once
2#include "HephAudioShared.h"
3#include <cstdint>
4#include <vector>
5
11#define HEPHAUDIO_CH_MASK_MONO (HephAudio::AudioChannelMask::FrontCenter)
12
17#define HEPHAUDIO_CH_MASK_STEREO (HephAudio::AudioChannelMask::FrontLeft | HephAudio::AudioChannelMask::FrontRight)
18
24#define HEPHAUDIO_CH_MASK_2_POINT_1 (HEPHAUDIO_CH_MASK_STEREO | HephAudio::AudioChannelMask::LowFrequency)
25
31#define HEPHAUDIO_CH_MASK_2_1 (HEPHAUDIO_CH_MASK_STEREO | HephAudio::AudioChannelMask::BackCenter)
32
38#define HEPHAUDIO_CH_MASK_SURROUND (HEPHAUDIO_CH_MASK_STEREO | HephAudio::AudioChannelMask::FrontCenter)
39
46#define HEPHAUDIO_CH_MASK_3_POINT_1 (HEPHAUDIO_CH_MASK_SURROUND | HephAudio::AudioChannelMask::LowFrequency)
47
54#define HEPHAUDIO_CH_MASK_4_POINT_0 (HEPHAUDIO_CH_MASK_SURROUND | HephAudio::AudioChannelMask::BackCenter)
55
62#define HEPHAUDIO_CH_MASK_2_2 (HEPHAUDIO_CH_MASK_STEREO | HephAudio::AudioChannelMask::SideLeft | HephAudio::AudioChannelMask::SideRight)
63
70#define HEPHAUDIO_CH_MASK_QUAD (HEPHAUDIO_CH_MASK_STEREO | HephAudio::AudioChannelMask::BackLeft | HephAudio::AudioChannelMask::BackRight)
71
79#define HEPHAUDIO_CH_MASK_4_POINT_1 (HEPHAUDIO_CH_MASK_4_POINT_0 | HephAudio::AudioChannelMask::LowFrequency)
80
88#define HEPHAUDIO_CH_MASK_5_POINT_0 (HEPHAUDIO_CH_MASK_SURROUND | HephAudio::AudioChannelMask::SideLeft | HephAudio::AudioChannelMask::SideRight)
89
97#define HEPHAUDIO_CH_MASK_5_POINT_0_BACK (HEPHAUDIO_CH_MASK_SURROUND | HephAudio::AudioChannelMask::BackLeft | HephAudio::AudioChannelMask::BackRight)
98
107#define HEPHAUDIO_CH_MASK_5_POINT_1 (HEPHAUDIO_CH_MASK_5_POINT_0 | HephAudio::AudioChannelMask::LowFrequency)
108
117#define HEPHAUDIO_CH_MASK_5_POINT_1_BACK (HEPHAUDIO_CH_MASK_5_POINT_0_BACK | HephAudio::AudioChannelMask::LowFrequency)
118
127#define HEPHAUDIO_CH_MASK_6_POINT_0 (HEPHAUDIO_CH_MASK_5_POINT_0 | HephAudio::AudioChannelMask::BackCenter)
128
137#define HEPHAUDIO_CH_MASK_6_POINT_0_FRONT (HEPHAUDIO_CH_MASK_2_2 | HephAudio::AudioChannelMask::FrontLeftOfCenter | HephAudio::AudioChannelMask::FrontRightOfCenter)
138
147#define HEPHAUDIO_CH_MASK_HEXAGONAL (HEPHAUDIO_CH_MASK_5_POINT_0_BACK | HephAudio::AudioChannelMask::BackCenter)
148
158#define HEPHAUDIO_CH_MASK_6_POINT_1 (HEPHAUDIO_CH_MASK_5_POINT_1 | HephAudio::AudioChannelMask::BackCenter)
159
169#define HEPHAUDIO_CH_MASK_6_POINT_1_BACK (HEPHAUDIO_CH_MASK_5_POINT_1_BACK | HephAudio::AudioChannelMask::BackCenter)
170
180#define HEPHAUDIO_CH_MASK_6_POINT_1_FRONT (HEPHAUDIO_CH_MASK_6_POINT_0_FRONT | HephAudio::AudioChannelMask::LowFrequency)
181
191#define HEPHAUDIO_CH_MASK_7_POINT_0 (HEPHAUDIO_CH_MASK_5_POINT_0 | HephAudio::AudioChannelMask::BackLeft | HephAudio::AudioChannelMask::BackRight)
192
202#define HEPHAUDIO_CH_MASK_7_POINT_0_FRONT (HEPHAUDIO_CH_MASK_5_POINT_0 | HephAudio::AudioChannelMask::FrontLeftOfCenter | HephAudio::AudioChannelMask::FrontRightOfCenter)
203
214#define HEPHAUDIO_CH_MASK_7_POINT_1 (HEPHAUDIO_CH_MASK_5_POINT_1 | HephAudio::AudioChannelMask::BackLeft | HephAudio::AudioChannelMask::BackRight)
215
226#define HEPHAUDIO_CH_MASK_7_POINT_1_WIDE (HEPHAUDIO_CH_MASK_5_POINT_1 | HephAudio::AudioChannelMask::FrontLeftOfCenter | HephAudio::AudioChannelMask::FrontRightOfCenter)
227
238#define HEPHAUDIO_CH_MASK_7_POINT_1_WIDE_BACK (HEPHAUDIO_CH_MASK_5_POINT_1_BACK | HephAudio::AudioChannelMask::FrontLeftOfCenter | HephAudio::AudioChannelMask::FrontRightOfCenter)
239
250#define HEPHAUDIO_CH_MASK_OCTAGONAL (HEPHAUDIO_CH_MASK_5_POINT_0 | HephAudio::AudioChannelMask::BackLeft | HephAudio::AudioChannelMask::BackCenter | HephAudio::AudioChannelMask::BackRight)
251
252#define HEPHAUDIO_CH_LAYOUT_MONO HephAudio::AudioChannelLayout(1, HEPHAUDIO_CH_MASK_MONO)
253#define HEPHAUDIO_CH_LAYOUT_STEREO HephAudio::AudioChannelLayout(2, HEPHAUDIO_CH_MASK_STEREO)
254#define HEPHAUDIO_CH_LAYOUT_2_POINT_1 HephAudio::AudioChannelLayout(3, HEPHAUDIO_CH_MASK_2_POINT_1)
255#define HEPHAUDIO_CH_LAYOUT_2_1 HephAudio::AudioChannelLayout(3, HEPHAUDIO_CH_MASK_2_1)
256#define HEPHAUDIO_CH_LAYOUT_SURROUND HephAudio::AudioChannelLayout(3, HEPHAUDIO_CH_MASK_SURROUND)
257#define HEPHAUDIO_CH_LAYOUT_3_POINT_1 HephAudio::AudioChannelLayout(4, HEPHAUDIO_CH_MASK_3_POINT_1)
258#define HEPHAUDIO_CH_LAYOUT_4_POINT_0 HephAudio::AudioChannelLayout(4, HEPHAUDIO_CH_MASK_4_POINT_0)
259#define HEPHAUDIO_CH_LAYOUT_2_2 HephAudio::AudioChannelLayout(4, HEPHAUDIO_CH_MASK_2_2)
260#define HEPHAUDIO_CH_LAYOUT_QUAD HephAudio::AudioChannelLayout(4, HEPHAUDIO_CH_MASK_QUAD)
261#define HEPHAUDIO_CH_LAYOUT_4_POINT_1 HephAudio::AudioChannelLayout(5, HEPHAUDIO_CH_MASK_4_POINT_1)
262#define HEPHAUDIO_CH_LAYOUT_5_POINT_0 HephAudio::AudioChannelLayout(5, HEPHAUDIO_CH_MASK_5_POINT_0)
263#define HEPHAUDIO_CH_LAYOUT_5_POINT_0_BACK HephAudio::AudioChannelLayout(5, HEPHAUDIO_CH_MASK_5_POINT_0_BACK)
264#define HEPHAUDIO_CH_LAYOUT_5_POINT_1 HephAudio::AudioChannelLayout(6, HEPHAUDIO_CH_MASK_5_POINT_1)
265#define HEPHAUDIO_CH_LAYOUT_5_POINT_1_BACK HephAudio::AudioChannelLayout(6, HEPHAUDIO_CH_MASK_5_POINT_1_BACK)
266#define HEPHAUDIO_CH_LAYOUT_6_POINT_0 HephAudio::AudioChannelLayout(6, HEPHAUDIO_CH_MASK_6_POINT_0)
267#define HEPHAUDIO_CH_LAYOUT_6_POINT_0_FRONT HephAudio::AudioChannelLayout(6, HEPHAUDIO_CH_MASK_6_POINT_0_FRONT)
268#define HEPHAUDIO_CH_LAYOUT_HEXAGONAL HephAudio::AudioChannelLayout(6, HEPHAUDIO_CH_MASK_HEXAGONAL)
269#define HEPHAUDIO_CH_LAYOUT_6_POINT_1 HephAudio::AudioChannelLayout(7, HEPHAUDIO_CH_MASK_6_POINT_1)
270#define HEPHAUDIO_CH_LAYOUT_6_POINT_1_BACK HephAudio::AudioChannelLayout(7, HEPHAUDIO_CH_MASK_6_POINT_1_BACK)
271#define HEPHAUDIO_CH_LAYOUT_6_POINT_1_FRONT HephAudio::AudioChannelLayout(7, HEPHAUDIO_CH_MASK_6_POINT_1_FRONT)
272#define HEPHAUDIO_CH_LAYOUT_7_POINT_0 HephAudio::AudioChannelLayout(7, HEPHAUDIO_CH_MASK_7_POINT_0)
273#define HEPHAUDIO_CH_LAYOUT_7_POINT_0_FRONT HephAudio::AudioChannelLayout(7, HEPHAUDIO_CH_MASK_7_POINT_0_FRONT)
274#define HEPHAUDIO_CH_LAYOUT_7_POINT_1 HephAudio::AudioChannelLayout(8, HEPHAUDIO_CH_MASK_7_POINT_1)
275#define HEPHAUDIO_CH_LAYOUT_7_POINT_1_WIDE HephAudio::AudioChannelLayout(8, HEPHAUDIO_CH_MASK_7_POINT_1_WIDE)
276#define HEPHAUDIO_CH_LAYOUT_7_POINT_1_WIDE_BACK HephAudio::AudioChannelLayout(8, HEPHAUDIO_CH_MASK_7_POINT_1_WIDE_BACK)
277#define HEPHAUDIO_CH_LAYOUT_OCTAGONAL HephAudio::AudioChannelLayout(8, HEPHAUDIO_CH_MASK_OCTAGONAL)
278
279
280namespace HephAudio
281{
287 {
288 Unknown = 0,
289 FrontLeft = 0x1,
290 FrontRight = 0x2,
291 FrontCenter = 0x4,
292 LowFrequency = 0x8,
293 BackLeft = 0x10,
294 BackRight = 0x20,
295 FrontLeftOfCenter = 0x40,
296 FrontRightOfCenter = 0x80,
297 BackCenter = 0x100,
298 SideLeft = 0x200,
299 SideRight = 0x400,
300 TopCenter = 0x800,
301 TopFrontLeft = 0x1000,
302 TopFrontCenter = 0x2000,
303 TopFrontRight = 0x4000,
304 TopBackLeft = 0x8000,
305 TopBackCenter = 0x10000,
306 TopBackRight = 0x20000
307 };
308
309
310 inline constexpr AudioChannelMask operator|(const AudioChannelMask& lhs, const AudioChannelMask& rhs)
311 {
312 return (AudioChannelMask)(((int)lhs) | ((int)rhs));
313 }
314
315 inline constexpr AudioChannelMask& operator|=(AudioChannelMask& lhs, const AudioChannelMask& rhs)
316 {
317 lhs = lhs | rhs;
318 return lhs;
319 }
320
321 inline constexpr AudioChannelMask operator&(const AudioChannelMask& lhs, const AudioChannelMask& rhs)
322 {
323 return (AudioChannelMask)(((int)lhs) & ((int)rhs));
324 }
325
326 inline constexpr AudioChannelMask& operator&=(AudioChannelMask& lhs, const AudioChannelMask& rhs)
327 {
328 lhs = lhs & rhs;
329 return lhs;
330 }
331
337 {
342 uint16_t count;
343
349
352
359 constexpr AudioChannelLayout(uint16_t count, AudioChannelMask mask) : count(count), mask(mask) {}
360
361 constexpr bool operator==(const AudioChannelLayout& rhs) const
362 {
363 return this->count == rhs.count && this->mask == rhs.mask;
364 }
365
366 constexpr bool operator!=(const AudioChannelLayout& rhs) const
367 {
368 return !((*this) == rhs);
369 }
370
375 static constexpr AudioChannelMask DefaultChannelMask(uint16_t channelCount)
376 {
377 switch (channelCount)
378 {
379 case 1:
381 case 2:
383 case 3:
385 case 4:
387 case 5:
389 case 6:
391 case 7:
393 case 8:
395 default:
396 return AudioChannelMask::Unknown;
397 }
398 }
399
404 static constexpr AudioChannelLayout DefaultChannelLayout(uint16_t channelCount)
405 {
406 return AudioChannelLayout(channelCount, AudioChannelLayout::DefaultChannelMask(channelCount));
407 }
408
413 static constexpr uint16_t GetChannelCount(AudioChannelMask mask)
414 {
415 uint16_t channelCount = 0;
416 uint32_t mask32 = (uint32_t)mask;
417 for (size_t i = 0; i < 32; i++)
418 {
419 if (mask32 & 1)
420 {
421 channelCount++;
422 }
423 mask32 >>= 1;
424 }
425 return channelCount;
426 }
427
432 static constexpr uint16_t GetChannelCount(const AudioChannelLayout& layout)
433 {
434 return AudioChannelLayout::GetChannelCount(layout.mask);
435 }
436
441 static std::vector<AudioChannelMask> GetChannelMapping(AudioChannelMask mask);
442
447 static std::vector<AudioChannelMask> GetChannelMapping(const AudioChannelLayout& layout);
448 };
449}
#define HEPHAUDIO_CH_MASK_4_POINT_0
Definition AudioChannelLayout.h:54
#define HEPHAUDIO_CH_MASK_5_POINT_1
Definition AudioChannelLayout.h:107
#define HEPHAUDIO_CH_MASK_SURROUND
Definition AudioChannelLayout.h:38
#define HEPHAUDIO_CH_MASK_STEREO
Definition AudioChannelLayout.h:17
#define HEPHAUDIO_CH_MASK_7_POINT_1
Definition AudioChannelLayout.h:214
#define HEPHAUDIO_CH_MASK_MONO
Definition AudioChannelLayout.h:11
#define HEPHAUDIO_CH_MASK_5_POINT_0
Definition AudioChannelLayout.h:88
AudioChannelMask
Definition AudioChannelLayout.h:287
#define HEPHAUDIO_CH_MASK_7_POINT_0
Definition AudioChannelLayout.h:191
#define HEPH_API
Definition HephShared.h:124
stores information about the channel layout.
Definition AudioChannelLayout.h:337
static constexpr uint16_t GetChannelCount(AudioChannelMask mask)
Definition AudioChannelLayout.h:413
static constexpr uint16_t GetChannelCount(const AudioChannelLayout &layout)
Definition AudioChannelLayout.h:432
static constexpr AudioChannelMask DefaultChannelMask(uint16_t channelCount)
Definition AudioChannelLayout.h:375
static std::vector< AudioChannelMask > GetChannelMapping(const AudioChannelLayout &layout)
static constexpr AudioChannelLayout DefaultChannelLayout(uint16_t channelCount)
Definition AudioChannelLayout.h:404
constexpr AudioChannelLayout()
Definition AudioChannelLayout.h:351
constexpr AudioChannelLayout(uint16_t count, AudioChannelMask mask)
Definition AudioChannelLayout.h:359
static std::vector< AudioChannelMask > GetChannelMapping(AudioChannelMask mask)
uint16_t count
Definition AudioChannelLayout.h:342
AudioChannelMask mask
Definition AudioChannelLayout.h:348