1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 14 янв. 2018 г. 7 * 8 * lsp-plugins 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-plugins 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-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef CORE_FILES_LSPC_LSPC_H_ 23 #define CORE_FILES_LSPC_LSPC_H_ 24 25 #include <core/types.h> 26 27 namespace lsp 28 { 29 /** @note All data is stored in big-endian format! 30 * Common file structure: 31 * 32 * 1. Header 33 * 2. Chunk 34 * 3. Chunk 35 * 4. Chunk 36 * ... 37 * N. Chunk 38 */ 39 40 #pragma pack(push, 1) 41 typedef struct lspc_root_header_t 42 { 43 uint32_t magic; // Magic number, should be 'LSPC' 44 uint16_t version; // Header version 45 uint16_t size; // Size of header 46 uint32_t reserved[4]; // Some reserved data 47 } lspc_root_header_t; 48 49 typedef struct lspc_chunk_header_t 50 { 51 uint32_t magic; // Chunk type, should be identical for each chunk 52 uint32_t uid; // Unique chunk identifier within file 53 uint32_t flags; // Chunk flags 54 uint32_t size; // The size of chunk data after header 55 } lspc_chunk_header_t; 56 57 typedef struct lspc_header_t 58 { 59 uint32_t size; // Size of header 60 uint16_t version; // Version of header 61 } lspc_chunk_common_header_t; 62 63 typedef struct lspc_chunk_raw_header_t 64 { 65 lspc_header_t common; // Common header data 66 uint8_t data[]; // header contents 67 } lspc_chunk_raw_header_t; 68 69 typedef struct lspc_chunk_audio_header_t // Magic number: 'LCAH' 70 { 71 lspc_header_t common; // Common header data 72 uint8_t channels; // Number of channels 73 uint8_t sample_format; // Sample format 74 uint32_t sample_rate; // Sample rate 75 uint32_t codec; // Codec used 76 uint64_t frames; // Overall number of frames in file 77 int64_t offset; // Offset with which to load the frames (since header v.1, deprecated since header v.2) 78 uint32_t reserved[4]; // Some reserved data 79 } lspc_chunk_audio_header_t; 80 81 typedef struct lspc_chunk_audio_profile_t // Magic number: 'LCAP' 82 { 83 lspc_header_t common; // Common header data 84 uint16_t pad; // Padding (reserved) 85 uint32_t chunk_id; // Chunk identifier related to the audio profile 86 uint32_t chirp_order; // Chirp order 87 float alpha; // The chirp parameter alpha, a float value 88 double beta; // The chirp parameter beta, a double value 89 double gamma; // The chirp parameter gamma, a double value 90 double delta; // The chirp parameter delta, a double value 91 double initial_freq; // The chirp initial frequency 92 double final_freq; // The chirp final frequency 93 int64_t skip; // Frame to skip for linear response loading (since header v.2) 94 uint32_t reserved[6]; // Some reserved data for future use 95 } lspc_chunk_audio_profile_t; 96 97 #pragma pack(pop) 98 99 // Different chunk types 100 #define LSPC_ROOT_MAGIC 0x4C535043 101 #define LSPC_CHUNK_AUDIO 0x41554449 102 #define LSPC_CHUNK_PROFILE 0x50524F46 103 104 // Chunk flags 105 #define LSPC_CHUNK_FLAG_LAST (1 << 0) 106 107 // Different kinds of sample format 108 #define LSPC_SAMPLE_FMT_U8LE 0x00 109 #define LSPC_SAMPLE_FMT_U8BE 0x01 110 #define LSPC_SAMPLE_FMT_S8LE 0x02 111 #define LSPC_SAMPLE_FMT_S8BE 0x03 112 #define LSPC_SAMPLE_FMT_U16LE 0x04 113 #define LSPC_SAMPLE_FMT_U16BE 0x05 114 #define LSPC_SAMPLE_FMT_S16LE 0x06 115 #define LSPC_SAMPLE_FMT_S16BE 0x07 116 #define LSPC_SAMPLE_FMT_U24LE 0x08 117 #define LSPC_SAMPLE_FMT_U24BE 0x09 118 #define LSPC_SAMPLE_FMT_S24LE 0x0a 119 #define LSPC_SAMPLE_FMT_S24BE 0x0b 120 #define LSPC_SAMPLE_FMT_U32LE 0x0c 121 #define LSPC_SAMPLE_FMT_U32BE 0x0d 122 #define LSPC_SAMPLE_FMT_S32LE 0x0e 123 #define LSPC_SAMPLE_FMT_S32BE 0x0f 124 #define LSPC_SAMPLE_FMT_F32LE 0x10 125 #define LSPC_SAMPLE_FMT_F32BE 0x11 126 #define LSPC_SAMPLE_FMT_F64LE 0x12 127 #define LSPC_SAMPLE_FMT_F64BE 0x13 128 129 typedef struct lspc_audio_parameters_t 130 { 131 size_t channels; // Number of channels 132 size_t sample_format; // Sample format 133 size_t sample_rate; // Sample rate 134 size_t codec; // Codec used 135 wsize_t frames; // Overall number of frames in file 136 } lspc_audio_parameters_t; 137 138 #define LSPC_SAMPLE_FMT_IS_LE(x) (!(x & 1)) 139 #define LSPC_SAMPLE_FMT_IS_BE(x) (x & 1) 140 #ifdef ARCH_LE /* Little-endian architecture */ 141 #define LSPC_SAMPLE_FMT_NEED_REVERSE(x) LSPC_SAMPLE_FMT_IS_BE(x) 142 #else /* Big-endian architecture */ 143 #define LSPC_SAMPLE_FMT_NEED_REVERSE(x) LSPC_SAMPLE_FMT_IS_LE(x) 144 #endif /* ARCH_LE */ 145 146 // Different codec types 147 #define LSPC_CODEC_PCM 0 148 149 } /* lsp */ 150 151 #endif /* CORE_FILES_LSPC_LSPC_H_ */ 152