HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_stream_format.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "pcm_format.hpp"
8#include "speaker_mapping.hpp"
9#include <bit>
10
11namespace hi::inline v1 {
12
16 pcm_format format = {};
17 uint32_t sample_rate = 0;
18 uint16_t num_channels = 0;
19 hi::speaker_mapping speaker_mapping = hi::speaker_mapping::none;
20
21 constexpr audio_stream_format() noexcept = default;
22 constexpr audio_stream_format(audio_stream_format const &) noexcept = default;
23 constexpr audio_stream_format(audio_stream_format &&) noexcept = default;
24 constexpr audio_stream_format &operator=(audio_stream_format const &) noexcept = default;
25 constexpr audio_stream_format &operator=(audio_stream_format &&) noexcept = default;
26
27 [[nodiscard]] constexpr audio_stream_format(
28 pcm_format format,
29 uint32_t sample_rate,
30 uint16_t num_channels,
31 hi::speaker_mapping speaker_mapping = hi::speaker_mapping::none) noexcept :
32 format(format), sample_rate(sample_rate), num_channels(num_channels), speaker_mapping(speaker_mapping)
33 {
34 }
35
36 [[nodiscard]] constexpr bool empty() const noexcept
37 {
38 return format.empty();
39 }
40
41 constexpr explicit operator bool() const noexcept
42 {
43 return not empty();
44 }
45
46 [[nodiscard]] constexpr bool holds_invariant() const noexcept
47 {
48 if (popcount(speaker_mapping) != 0 and num_channels != popcount(speaker_mapping)) {
49 return false;
50 }
51 return true;
52 }
53};
54
55} // namespace hi::inline v1
The format of a stream of audio.
Definition audio_stream_format.hpp:15
Definition pcm_format.hpp:16