HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_stream_format.hpp
1// Copyright Take Vos 2021-2022.
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 "../macros.hpp"
10#include <bit>
11#include <array>
12
13hi_export_module(hikogui.audio.audio_stream_format);
14
15hi_export namespace hi { inline namespace v1 {
16
17hi_export constexpr auto common_sample_rates = std::array{
18 uint32_t{8000},
19 uint32_t{16000},
20 uint32_t{32000},
21 uint32_t{44100},
22 uint32_t{47952},
23 uint32_t{48000},
24 uint32_t{48048},
25 uint32_t{88200},
26 uint32_t{95904},
27 uint32_t{96000},
28 uint32_t{96096},
29 uint32_t{176400},
30 uint32_t{191808},
31 uint32_t{192000},
32 uint32_t{192192},
33 uint32_t{352800},
34 uint32_t{383616},
35 uint32_t{384000},
36 uint32_t{384384}};
37
40hi_export struct audio_stream_format {
41 pcm_format format = {};
42 uint32_t sample_rate = 0;
43 uint16_t num_channels = 0;
44 hi::speaker_mapping speaker_mapping = hi::speaker_mapping::none;
45
46 constexpr audio_stream_format() noexcept = default;
47 constexpr audio_stream_format(audio_stream_format const &) noexcept = default;
48 constexpr audio_stream_format(audio_stream_format &&) noexcept = default;
49 constexpr audio_stream_format &operator=(audio_stream_format const &) noexcept = default;
50 constexpr audio_stream_format &operator=(audio_stream_format &&) noexcept = default;
51
52 [[nodiscard]] constexpr audio_stream_format(
53 pcm_format format,
54 uint32_t sample_rate,
55 uint16_t num_channels,
56 hi::speaker_mapping speaker_mapping = hi::speaker_mapping::none) noexcept :
57 format(format), sample_rate(sample_rate), num_channels(num_channels), speaker_mapping(speaker_mapping)
58 {
59 }
60
61 [[nodiscard]] constexpr bool empty() const noexcept
62 {
63 return format.empty();
64 }
65
66 constexpr explicit operator bool() const noexcept
67 {
68 return not empty();
69 }
70
71 [[nodiscard]] constexpr bool holds_invariant() const noexcept
72 {
73 if (popcount(speaker_mapping) != 0 and num_channels != popcount(speaker_mapping)) {
74 return false;
75 }
76 return true;
77 }
78};
79
80}} // namespace hi::inline v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The format of a stream of audio.
Definition audio_stream_format.hpp:40
Definition pcm_format.hpp:18