VirtualBox

source: vbox/trunk/include/iprt/formats/riff.h@ 103224

Last change on this file since 103224 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: riff.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Resource Interchange File Format (RIFF), WAVE, ++.
4 */
5
6/*
7 * Copyright (C) 2021-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_formats_riff_h
38#define IPRT_INCLUDED_formats_riff_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/types.h>
44#include <iprt/assertcompile.h>
45
46
47/** @defgroup grp_rt_formats_riff RIFF & WAVE structures and definitions
48 * @ingroup grp_rt_formats
49 * @{
50 */
51
52/**
53 * Resource interchange file format (RIFF) file header.
54 */
55typedef struct RTRIFFHDR
56{
57 /** The 'RIFF' magic (RTRIFFHDR_MAGIC). */
58 uint32_t uMagic;
59 /** The file size. */
60 uint32_t cbFile;
61 /** The file type. */
62 uint32_t uFileType;
63} RTRIFFHDR;
64AssertCompileSize(RTRIFFHDR, 12);
65/** Pointer to a RIFF file header. */
66typedef RTRIFFHDR *PRTRIFFHDR;
67
68/** Magic value for RTRIFFHDR::uMagic ('RIFF'). */
69#define RTRIFFHDR_MAGIC RT_BE2H_U32_C(0x52494646)
70
71/** @name RIFF file types (RTRIFFHDR::uFileType)
72 * @{ */
73/** RIFF file type: WAVE (audio) */
74#define RTRIFF_FILE_TYPE_WAVE RT_BE2H_U32_C(0x57415645)
75/** RIFF file type: AVI (video) */
76#define RTRIFF_FILE_TYPE_AVI RT_BE2H_U32_C(0x41564920)
77/** @} */
78
79/**
80 * A RIFF chunk.
81 */
82typedef struct RTRIFFCHUNK
83{
84 /** The chunk magic (four character code). */
85 uint32_t uMagic;
86 /** The size of the chunk minus this header. */
87 uint32_t cbChunk;
88} RTRIFFCHUNK;
89AssertCompileSize(RTRIFFCHUNK, 8);
90/** Pointer to a RIFF chunk. */
91typedef RTRIFFCHUNK *PRTRIFFCHUNK;
92
93/**
94 * A RIFF list.
95 */
96typedef struct RTRIFFLIST
97{
98 /** The list indicator (RTRIFFLIST_MAGIC). */
99 uint32_t uMagic;
100 /** The size of the chunk minus this header. */
101 uint32_t cbChunk;
102 /** The list type (four character code). */
103 uint32_t uListType;
104} RTRIFFLIST;
105AssertCompileSize(RTRIFFLIST, 12);
106/** Pointer to a RIFF list. */
107typedef RTRIFFLIST *PRTRIFFLIST;
108/** Magic value for RTRIFFLIST::uMagic ('LIST'). */
109#define RTRIFFLIST_MAGIC RT_BE2H_U32_C(0x4c495354)
110
111/** Generic 'INFO' list type. */
112#define RTRIFFLIST_TYPE_INFO RT_BE2H_U32_C(0x494e464f)
113
114
115/**
116 * Wave file format (WAVEFORMATEX w/o cbSize).
117 * @see RTRIFFWAVEFMTCHUNK.
118 */
119typedef struct RTRIFFWAVEFMT
120{
121 /** Audio format tag. */
122 uint16_t uFormatTag;
123 /** Number of channels. */
124 uint16_t cChannels;
125 /** Sample rate. */
126 uint32_t uHz;
127 /** Byte rate (= uHz * cChannels * cBitsPerSample / 8) */
128 uint32_t cbRate;
129 /** Frame size (aka block alignment). */
130 uint16_t cbFrame;
131 /** Number of bits per sample. */
132 uint16_t cBitsPerSample;
133} RTRIFFWAVEFMT;
134AssertCompileSize(RTRIFFWAVEFMT, 16);
135/** Pointer to a wave file format structure. */
136typedef RTRIFFWAVEFMT *PRTRIFFWAVEFMT;
137
138/**
139 * Extensible wave file format (WAVEFORMATEXTENSIBLE).
140 * @see RTRIFFWAVEFMTEXTCHUNK.
141 */
142#pragma pack(4) /* Override the uint64_t effect from RTUUID, so we can safely put it after RTRIFFHDR in a structure. */
143typedef struct RTRIFFWAVEFMTEXT
144{
145 /** The coreformat structure. */
146 RTRIFFWAVEFMT Core;
147 /** Number of bytes of extra information after the core. */
148 uint16_t cbExtra;
149 /** Number of valid bits per sample. */
150 uint16_t cValidBitsPerSample;
151 /** The channel mask. */
152 uint32_t fChannelMask;
153 /** The GUID of the sub-format. */
154 RTUUID SubFormat;
155} RTRIFFWAVEFMTEXT;
156#pragma pack()
157AssertCompileSize(RTRIFFWAVEFMTEXT, 16+2+22);
158/** Pointer to an extensible wave file format structure. */
159typedef RTRIFFWAVEFMTEXT *PRTRIFFWAVEFMTEXT;
160
161/** RTRIFFWAVEFMT::uFormatTag value for PCM (WDK: WAVE_FORMAT_PCM). */
162#define RTRIFFWAVEFMT_TAG_PCM UINT16_C(0x0001)
163/** RTRIFFWAVEFMT::uFormatTag value for extensible wave files (WDK: WAVE_FORMAT_EXTENSIBLE). */
164#define RTRIFFWAVEFMT_TAG_EXTENSIBLE UINT16_C(0xfffe)
165
166/** Typical RTRIFFWAVEFMTEXT::cbExtra value (min). */
167#define RTRIFFWAVEFMTEXT_EXTRA_SIZE UINT16_C(22)
168
169/** @name Channel IDs for RTRIFFWAVEFMTEXT::fChannelMask.
170 * @{ */
171#define RTRIFFWAVEFMTEXT_CH_ID_FL RT_BIT_32(0) /**< Front left. */
172#define RTRIFFWAVEFMTEXT_CH_ID_FR RT_BIT_32(1) /**< Front right. */
173#define RTRIFFWAVEFMTEXT_CH_ID_FC RT_BIT_32(2) /**< Front center */
174#define RTRIFFWAVEFMTEXT_CH_ID_LFE RT_BIT_32(3) /**< Low frequency */
175#define RTRIFFWAVEFMTEXT_CH_ID_BL RT_BIT_32(4) /**< Back left. */
176#define RTRIFFWAVEFMTEXT_CH_ID_BR RT_BIT_32(5) /**< Back right. */
177#define RTRIFFWAVEFMTEXT_CH_ID_FLC RT_BIT_32(6) /**< Front left of center. */
178#define RTRIFFWAVEFMTEXT_CH_ID_FLR RT_BIT_32(7) /**< Front right of center. */
179#define RTRIFFWAVEFMTEXT_CH_ID_BC RT_BIT_32(8) /**< Back center. */
180#define RTRIFFWAVEFMTEXT_CH_ID_SL RT_BIT_32(9) /**< Side left. */
181#define RTRIFFWAVEFMTEXT_CH_ID_SR RT_BIT_32(10) /**< Side right. */
182#define RTRIFFWAVEFMTEXT_CH_ID_TC RT_BIT_32(11) /**< Top center. */
183#define RTRIFFWAVEFMTEXT_CH_ID_TFL RT_BIT_32(12) /**< Top front left. */
184#define RTRIFFWAVEFMTEXT_CH_ID_TFC RT_BIT_32(13) /**< Top front center. */
185#define RTRIFFWAVEFMTEXT_CH_ID_TFR RT_BIT_32(14) /**< Top front right. */
186#define RTRIFFWAVEFMTEXT_CH_ID_TBL RT_BIT_32(15) /**< Top back left. */
187#define RTRIFFWAVEFMTEXT_CH_ID_TBC RT_BIT_32(16) /**< Top back center. */
188#define RTRIFFWAVEFMTEXT_CH_ID_TBR RT_BIT_32(17) /**< Top back right. */
189/** @} */
190
191/** RTRIFFWAVEFMTEXT::SubFormat UUID string for PCM. */
192#define RTRIFFWAVEFMTEXT_SUBTYPE_PCM "00000001-0000-0010-8000-00aa00389b71"
193
194
195/**
196 * Wave file format chunk.
197 */
198typedef struct RTRIFFWAVEFMTCHUNK
199{
200 /** Chunk header with RTRIFFWAVEFMT_MAGIC as magic. */
201 RTRIFFCHUNK Chunk;
202 /** The wave file format. */
203 RTRIFFWAVEFMT Data;
204} RTRIFFWAVEFMTCHUNK;
205AssertCompileSize(RTRIFFWAVEFMTCHUNK, 8+16);
206/** Pointer to a wave file format chunk. */
207typedef RTRIFFWAVEFMTCHUNK *PRTRIFFWAVEFMTCHUNK;
208/** Magic value for RTRIFFWAVEFMTCHUNK and RTRIFFWAVEFMTEXTCHUNK ('fmt '). */
209#define RTRIFFWAVEFMT_MAGIC RT_BE2H_U32_C(0x666d7420)
210
211/**
212 * Extensible wave file format chunk.
213 */
214typedef struct RTRIFFWAVEFMTEXTCHUNK
215{
216 /** Chunk header with RTRIFFWAVEFMT_MAGIC as magic. */
217 RTRIFFCHUNK Chunk;
218 /** The wave file format. */
219 RTRIFFWAVEFMTEXT Data;
220} RTRIFFWAVEFMTEXTCHUNK;
221AssertCompileSize(RTRIFFWAVEFMTEXTCHUNK, 8+16+2+22);
222/** Pointer to a wave file format chunk. */
223typedef RTRIFFWAVEFMTEXTCHUNK *PRTRIFFWAVEFMTEXTCHUNK;
224
225
226/**
227 * Wave file data chunk.
228 */
229typedef struct RTRIFFWAVEDATACHUNK
230{
231 /** Chunk header with RTRIFFWAVEFMT_MAGIC as magic. */
232 RTRIFFCHUNK Chunk;
233 /** Variable sized sample data. */
234 uint8_t abData[RT_FLEXIBLE_ARRAY_IN_NESTED_UNION];
235} RTRIFFWAVEDATACHUNK;
236
237/** Magic value for RTRIFFWAVEFMT::uMagic ('data'). */
238#define RTRIFFWAVEDATACHUNK_MAGIC RT_BE2H_U32_C(0x64617461)
239
240
241/** Magic value padding chunks ('PAD '). */
242#define RTRIFFPADCHUNK_MAGIC RT_BE2H_U32_C(0x50414420)
243
244/** @} */
245
246#endif /* !IPRT_INCLUDED_formats_riff_h */
247
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette