Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/lspc/lspc.h

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 14 янв. 2018 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_LSPC_LSPC_H_
23 #define LSP_PLUG_IN_FMT_LSPC_LSPC_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/common/types.h>
27
28 namespace lsp
29 {
30 namespace lspc
31 {
32 /** @note All data is stored in big-endian format!
33 * Common file structure:
34 *
35 * 1. Header
36 * 2. Chunk
37 * 3. Chunk
38 * 4. Chunk
39 * ...
40 * N. Chunk
41 *
42 * Each chunk represents the potion of the stream and has the following structure:
43 * 1. Chunk header
44 * 2. Payload
45 *
46 * Each chunk header identifies the type of chunk and unique identifier of the stream
47 * associated with the chunk. Additionally, it holds size of payload data and flags
48 * like the indicator of last chunk in the stream.
49 */
50
51 #pragma pack(push, 1)
52 typedef uint32_t chunk_magic_t; // Chunk magic (type) code
53 typedef uint32_t chunk_id_t; // Chunk identifier
54
55 typedef struct root_header_t
56 {
57 uint32_t magic; // Magic number, should be LSPC_ROOT_MAGIC
58 uint16_t version; // Header version
59 uint16_t size; // Size of header
60 uint32_t reserved[4]; // Some reserved data
61 } root_header_t;
62
63 typedef struct chunk_header_t
64 {
65 uint32_t magic; // Chunk type, should be identical for each chunk
66 uint32_t uid; // Unique chunk identifier within file
67 uint32_t flags; // Chunk flags
68 uint32_t size; // The size of chunk data after header
69 } chunk_header_t;
70
71 typedef struct header_t
72 {
73 uint32_t size; // Size of header
74 uint16_t version; // Version of header
75 } header_t;
76
77 typedef struct lspc_chunk_raw_header_t
78 {
79 header_t common; // Common header data
80 uint8_t data[]; // header contents
81 } chunk_raw_header_t;
82
83 typedef struct chunk_audio_header_t // Magic number: LSPC_CHUNK_AUDIO
84 {
85 header_t common; // Common header data
86 uint8_t channels; // Number of channels
87 uint8_t sample_format; // Sample format (see lspc_sample_format_t)
88 uint32_t sample_rate; // Sample rate
89 uint32_t codec; // Codec used (see lspc_codec_t)
90 uint64_t frames; // Overall number of frames in file
91 int64_t offset; // Offset with which to load the frames (since header v.1, deprecated since header v.2)
92 uint32_t reserved[4]; // Some reserved data
93 } chunk_audio_header_t;
94
95 typedef struct chunk_audio_profile_t // Magic number: LSPC_CHUNK_PROFILE
96 {
97 header_t common; // Common header data
98 uint16_t pad; // Padding (reserved), should be zero
99 chunk_id_t chunk_id; // Chunk identifier related to the audio profile
100 uint32_t chirp_order; // Chirp order
101 float alpha; // The chirp parameter alpha, a float value
102 double beta; // The chirp parameter beta, a double value
103 double gamma; // The chirp parameter gamma, a double value
104 double delta; // The chirp parameter delta, a double value
105 double initial_freq; // The chirp initial frequency
106 double final_freq; // The chirp final frequency
107 int64_t skip; // Frame to skip for linear response loading (since header v.2)
108 uint32_t reserved[6]; // Some reserved data for future use
109 } chunk_audio_profile_t;
110
111 typedef struct chunk_text_config_t // Magic number: LSPC_CHUNK_TEXT_CONFIG
112 {
113 header_t common; // Common header data
114 uint16_t pad; // Padding (reserved), should be zero
115 } chunk_text_config_t;
116
117 typedef struct chunk_path_t // Magic number: LSPC_CHUNK_PATH
118 {
119 header_t common; // Common header data
120 uint16_t path_size; // Size of the path string in bytes
121 uint32_t flags; // Path flags (see path_flags_t)
122 chunk_id_t chunk_id; // Identifier of the related chunk that contains the data
123 } chunk_path_t;
124
125 typedef struct chunk_plain_data_t // Magic number: LSPC_CHUNK_PLAIN_DATA
126 {
127 header_t common; // Common header data
128 uint16_t pad; // Padding (reserved), should be zero
129 } chunk_plain_data_t;
130
131 #pragma pack(pop)
132
133 // Different chunk types
134 #define LSPC_ROOT_MAGIC 0x4C535043 /* 'LSPC' - magic number for the root LSPC header */
135 #define LSPC_CHUNK_AUDIO 0x41554449 /* 'AUDI' - magic number for the audio data chunk */
136 #define LSPC_CHUNK_PROFILE 0x50524F46 /* 'PROF' - magic number for the profile data chunk */
137 #define LSPC_CHUNK_TEXT_CONFIG 0x54434647 /* 'TCFG' - magic number for the text configuration file */
138 #define LSPC_CHUNK_PATH 0x50415448 /* 'PATH' - magic number for the file descriptor */
139 #define LSPC_CHUNK_PLAIN_DATA 0x44415441 /* 'DATA' - magic number for some plain data */
140
141 // Chunk flags
142 #define LSPC_CHUNK_FLAG_LAST (1 << 0)
143
144 // Different kinds of sample format
145 enum lspc_sample_format_t
146 {
147 SAMPLE_FMT_U8LE = 0x00,
148 SAMPLE_FMT_U8BE = 0x01,
149 SAMPLE_FMT_S8LE = 0x02,
150 SAMPLE_FMT_S8BE = 0x03,
151 SAMPLE_FMT_U16LE = 0x04,
152 SAMPLE_FMT_U16BE = 0x05,
153 SAMPLE_FMT_S16LE = 0x06,
154 SAMPLE_FMT_S16BE = 0x07,
155 SAMPLE_FMT_U24LE = 0x08,
156 SAMPLE_FMT_U24BE = 0x09,
157 SAMPLE_FMT_S24LE = 0x0a,
158 SAMPLE_FMT_S24BE = 0x0b,
159 SAMPLE_FMT_U32LE = 0x0c,
160 SAMPLE_FMT_U32BE = 0x0d,
161 SAMPLE_FMT_S32LE = 0x0e,
162 SAMPLE_FMT_S32BE = 0x0f,
163 SAMPLE_FMT_F32LE = 0x10,
164 SAMPLE_FMT_F32BE = 0x11,
165 SAMPLE_FMT_F64LE = 0x12,
166 SAMPLE_FMT_F64BE = 0x13
167 };
168
169 #define LSPC_SAMPLE_FMT_IS_LE(x) (!(x & 1))
170 #define LSPC_SAMPLE_FMT_IS_BE(x) (x & 1)
171 #ifdef ARCH_LE /* Little-endian architecture */
172 #define LSPC_SAMPLE_FMT_NEED_REVERSE(x) LSPC_SAMPLE_FMT_IS_BE(x)
173 #else /* Big-endian architecture */
174 #define LSPC_SAMPLE_FMT_NEED_REVERSE(x) LSPC_SAMPLE_FMT_IS_LE(x)
175 #endif /* ARCH_LE */
176
177 // Different codec types
178 enum lspc_codec_t
179 {
180 CODEC_PCM = 0 // PCM data
181 };
182
183 // Different path flags
184 enum path_flags_t
185 {
186 PATH_DIR = 1 << 0 // Pathname is a directory
187 };
188
189 typedef struct chunk_info_t
190 {
191 uint32_t magic; // Chunk magic number
192 chunk_id_t chunk_id; // Chunk identifier
193 wsize_t position; // Chunk position in the file
194 wsize_t size; // Overall size of the payload in the chunk
195 } chunk_info_t;
196
197 typedef struct audio_parameters_t
198 {
199 size_t channels; // Number of channels
200 size_t sample_format; // Sample format
201 size_t sample_rate; // Sample rate
202 size_t codec; // Codec used
203 wsize_t frames; // Overall number of frames in file
204 } audio_parameters_t;
205
206 typedef struct audio_format_t
207 {
208 size_t sample_format; // Sample format
209 size_t sample_rate; // Sample rate
210 size_t codec; // Codec used
211 } audio_format_t;
212
213 typedef struct path_entry_t
214 {
215 char *path; // Path entry
216 uint32_t flags; // Path flag
217 chunk_id_t chunk_id; // Referenced chunk identifier
218 } path_entry_t;
219
220 } /* namespace lspc */
221 } /* namespace lsp */
222
223 #endif /* LSP_PLUG_IN_FMT_LSPC_LSPC_H_ */