RAVENNAKIT
Loading...
Searching...
No Matches
audio_encoding.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3 * Project: RAVENNAKIT (RAVENNA / AES67 / ST2110-30 SDK)
4 * Copyright (c) 2024-2025 Sound on Digital
5 *
6 * This file is part of RAVENNAKIT.
7 *
8 * RAVENNAKIT is dual-licensed:
9 * 1) Under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version (the "AGPL License"); and
12 * 2) Under a commercial license from Sound on Digital, for customers who
13 * cannot (or do not wish to) comply with the AGPL License terms.
14 *
15 * If you obtained this file under the AGPL License, you may redistribute it
16 * and/or modify it under the terms of the AGPL License. See the LICENSE
17 * file in the project root for details.
18 *
19 * For commercial licensing, support, and other inquiries, please visit:
20 *
21 * https://ravennakit.com
22 *
23 */
24
25#pragma once
26
27#include <cstdint>
28#include <optional>
29#include <cstring>
30
31namespace rav {
32
43
47inline uint8_t audio_encoding_bytes_per_sample(const AudioEncoding encoding) {
48 switch (encoding) {
51 return 1;
53 return 2;
55 return 3;
58 return 4;
60 return 8;
62 default:
63 return 0;
64 }
65}
66
70inline uint8_t audio_encoding_ground_value(const AudioEncoding encoding) {
71 switch (encoding) {
73 return 0x80;
81 default:
82 return 0;
83 }
84}
85
86inline const char* to_string(const AudioEncoding encoding) {
87 switch (encoding) {
89 return "undefined";
91 return "pcm_s8";
93 return "pcm_u8";
95 return "pcm_s16";
97 return "pcm_s24";
99 return "pcm_s32";
101 return "pcm_f32";
103 return "pcm_f64";
104 default:
105 return "unknown";
106 }
107}
108
109inline std::optional<AudioEncoding> audio_encoding_from_string(const char* str) {
110 if (!str) {
111 return std::nullopt;
112 }
113 if (std::strcmp(str, "pcm_s8") == 0) {
115 }
116 if (std::strcmp(str, "pcm_u8") == 0) {
118 }
119 if (std::strcmp(str, "pcm_s16") == 0) {
121 }
122 if (std::strcmp(str, "pcm_s24") == 0) {
124 }
125 if (std::strcmp(str, "pcm_s32") == 0) {
127 }
128 if (std::strcmp(str, "pcm_f32") == 0) {
130 }
131 if (std::strcmp(str, "pcm_f64") == 0) {
133 }
134 if (std::strcmp(str, "undefined") == 0) {
136 }
137 return std::nullopt;
138}
139
140} // namespace rav
uint8_t audio_encoding_ground_value(const AudioEncoding encoding)
const char * to_string(const AudioEncoding encoding)
uint8_t audio_encoding_bytes_per_sample(const AudioEncoding encoding)
std::optional< AudioEncoding > audio_encoding_from_string(const char *str)