RetroArch
audiodefs.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. All rights reserved.
4  *
5  * File: audiodefs.h
6  * Content: Basic constants and data types for audio work.
7  *
8  * Remarks: This header file defines all of the audio format constants and
9  * structures required for XAudio2 and XACT work. Providing these
10  * in a single location avoids certain dependency problems in the
11  * legacy audio headers (mmreg.h, mmsystem.h, ksmedia.h).
12  *
13  * NOTE: Including the legacy headers after this one may cause a
14  * compilation error, because they define some of the same types
15  * defined here without preprocessor guards to avoid multiple
16  * definitions. If a source file needs one of the old headers,
17  * it must include it before including audiodefs.h.
18  *
19  ***************************************************************************/
20 
21 #ifndef __AUDIODEFS_INCLUDED__
22 #define __AUDIODEFS_INCLUDED__
23 
24 #include <windef.h> // For WORD, DWORD, etc.
25 
26 #pragma pack(push, 1) // Pack structures to 1-byte boundaries
27 
28 
29 /**************************************************************************
30  *
31  * WAVEFORMATEX: Base structure for many audio formats. Format-specific
32  * extensions can be defined for particular formats by using a non-zero
33  * cbSize value and adding extra fields to the end of this structure.
34  *
35  ***************************************************************************/
36 
37 #ifndef _WAVEFORMATEX_
38 
39  #define _WAVEFORMATEX_
40  typedef struct tWAVEFORMATEX
41  {
42  WORD wFormatTag; // Integer identifier of the format
43  WORD nChannels; // Number of audio channels
44  DWORD nSamplesPerSec; // Audio sample rate
45  DWORD nAvgBytesPerSec; // Bytes per second (possibly approximate)
46  WORD nBlockAlign; // Size in bytes of a sample block (all channels)
47  WORD wBitsPerSample; // Size in bits of a single per-channel sample
48  WORD cbSize; // Bytes of extra data appended to this struct
49  } WAVEFORMATEX;
50 
51 #endif
52 
53 // Defining pointer types outside of the #if block to make sure they are
54 // defined even if mmreg.h or mmsystem.h is #included before this file
55 
58 
59 
60 /**************************************************************************
61  *
62  * WAVEFORMATEXTENSIBLE: Extended version of WAVEFORMATEX that should be
63  * used as a basis for all new audio formats. The format tag is replaced
64  * with a GUID, allowing new formats to be defined without registering a
65  * format tag with Microsoft. There are also new fields that can be used
66  * to specify the spatial positions for each channel and the bit packing
67  * used for wide samples (e.g. 24-bit PCM samples in 32-bit containers).
68  *
69  ***************************************************************************/
70 
71 #ifndef _WAVEFORMATEXTENSIBLE_
72 
73  #define _WAVEFORMATEXTENSIBLE_
74  typedef struct
75  {
76  WAVEFORMATEX Format; // Base WAVEFORMATEX data
77  union
78  {
79  WORD wValidBitsPerSample; // Valid bits in each sample container
80  WORD wSamplesPerBlock; // Samples per block of audio data; valid
81  // if wBitsPerSample=0 (but rarely used).
82  WORD wReserved; // Zero if neither case above applies.
83  } Samples;
84  DWORD dwChannelMask; // Positions of the audio channels
85  GUID SubFormat; // Format identifier GUID
87 
88 #endif
89 
92 
93 
94 
95 /**************************************************************************
96  *
97  * Define the most common wave format tags used in WAVEFORMATEX formats.
98  *
99  ***************************************************************************/
100 
101 #ifndef WAVE_FORMAT_PCM // Pulse Code Modulation
102 
103  // If WAVE_FORMAT_PCM is not defined, we need to define some legacy types
104  // for compatibility with the Windows mmreg.h / mmsystem.h header files.
105 
106  // Old general format structure (information common to all formats)
107  typedef struct waveformat_tag
108  {
110  WORD nChannels;
115 
116  // Specific format structure for PCM data
117  typedef struct pcmwaveformat_tag
118  {
122 
123  #define WAVE_FORMAT_PCM 0x0001
124 
125 #endif
126 
127 #ifndef WAVE_FORMAT_ADPCM // Microsoft Adaptive Differental PCM
128 
129  // Replicate the Microsoft ADPCM type definitions from mmreg.h.
130 
131  typedef struct adpcmcoef_tag
132  {
133  short iCoef1;
134  short iCoef2;
135  } ADPCMCOEFSET;
136 
137  #pragma warning(push)
138  #pragma warning(disable:4200) // Disable zero-sized array warnings
139 
140  typedef struct adpcmwaveformat_tag {
143  WORD wNumCoef;
144  ADPCMCOEFSET aCoef[]; // Always 7 coefficient pairs for MS ADPCM
145  } ADPCMWAVEFORMAT;
146 
147  #pragma warning(pop)
148 
149  #define WAVE_FORMAT_ADPCM 0x0002
150 
151 #endif
152 
153 // Other frequently used format tags
154 
155 #ifndef WAVE_FORMAT_UNKNOWN
156  #define WAVE_FORMAT_UNKNOWN 0x0000 // Unknown or invalid format tag
157 #endif
158 
159 #ifndef WAVE_FORMAT_IEEE_FLOAT
160  #define WAVE_FORMAT_IEEE_FLOAT 0x0003 // 32-bit floating-point
161 #endif
162 
163 #ifndef WAVE_FORMAT_MPEGLAYER3
164  #define WAVE_FORMAT_MPEGLAYER3 0x0055 // ISO/MPEG Layer3
165 #endif
166 
167 #ifndef WAVE_FORMAT_DOLBY_AC3_SPDIF
168  #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092 // Dolby Audio Codec 3 over S/PDIF
169 #endif
170 
171 #ifndef WAVE_FORMAT_WMAUDIO2
172  #define WAVE_FORMAT_WMAUDIO2 0x0161 // Windows Media Audio
173 #endif
174 
175 #ifndef WAVE_FORMAT_WMAUDIO3
176  #define WAVE_FORMAT_WMAUDIO3 0x0162 // Windows Media Audio Pro
177 #endif
178 
179 #ifndef WAVE_FORMAT_WMASPDIF
180  #define WAVE_FORMAT_WMASPDIF 0x0164 // Windows Media Audio over S/PDIF
181 #endif
182 
183 #ifndef WAVE_FORMAT_EXTENSIBLE
184  #define WAVE_FORMAT_EXTENSIBLE 0xFFFE // All WAVEFORMATEXTENSIBLE formats
185 #endif
186 
187 
188 /**************************************************************************
189  *
190  * Define the most common wave format GUIDs used in WAVEFORMATEXTENSIBLE
191  * formats. Note that including the Windows ksmedia.h header after this
192  * one will cause build problems; this cannot be avoided, since ksmedia.h
193  * defines these macros without preprocessor guards.
194  *
195  ***************************************************************************/
196 
197 #if defined(__cplusplus) && defined(_MSC_VER) // uuid() and __uuidof() are only available in C++
198 
199  #ifndef KSDATAFORMAT_SUBTYPE_PCM
200  struct __declspec(uuid("00000001-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_PCM_STRUCT;
201  #define KSDATAFORMAT_SUBTYPE_PCM __uuidof(KSDATAFORMAT_SUBTYPE_PCM_STRUCT)
202  #endif
203 
204  #ifndef KSDATAFORMAT_SUBTYPE_ADPCM
205  struct __declspec(uuid("00000002-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_ADPCM_STRUCT;
206  #define KSDATAFORMAT_SUBTYPE_ADPCM __uuidof(KSDATAFORMAT_SUBTYPE_ADPCM_STRUCT)
207  #endif
208 
209  #ifndef KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
210  struct __declspec(uuid("00000003-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_STRUCT;
211  #define KSDATAFORMAT_SUBTYPE_IEEE_FLOAT __uuidof(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_STRUCT)
212  #endif
213 
214 #endif
215 
216 
217 /**************************************************************************
218  *
219  * Speaker positions used in the WAVEFORMATEXTENSIBLE dwChannelMask field.
220  *
221  ***************************************************************************/
222 
223 #ifndef SPEAKER_FRONT_LEFT
224  #define SPEAKER_FRONT_LEFT 0x00000001
225  #define SPEAKER_FRONT_RIGHT 0x00000002
226  #define SPEAKER_FRONT_CENTER 0x00000004
227  #define SPEAKER_LOW_FREQUENCY 0x00000008
228  #define SPEAKER_BACK_LEFT 0x00000010
229  #define SPEAKER_BACK_RIGHT 0x00000020
230  #define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040
231  #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
232  #define SPEAKER_BACK_CENTER 0x00000100
233  #define SPEAKER_SIDE_LEFT 0x00000200
234  #define SPEAKER_SIDE_RIGHT 0x00000400
235  #define SPEAKER_TOP_CENTER 0x00000800
236  #define SPEAKER_TOP_FRONT_LEFT 0x00001000
237  #define SPEAKER_TOP_FRONT_CENTER 0x00002000
238  #define SPEAKER_TOP_FRONT_RIGHT 0x00004000
239  #define SPEAKER_TOP_BACK_LEFT 0x00008000
240  #define SPEAKER_TOP_BACK_CENTER 0x00010000
241  #define SPEAKER_TOP_BACK_RIGHT 0x00020000
242  #define SPEAKER_RESERVED 0x7FFC0000
243  #define SPEAKER_ALL 0x80000000
244  #define _SPEAKER_POSITIONS_
245 #endif
246 
247 #ifndef SPEAKER_STEREO
248  #define SPEAKER_MONO (SPEAKER_FRONT_CENTER)
249  #define SPEAKER_STEREO (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
250  #define SPEAKER_2POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY)
251  #define SPEAKER_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_CENTER)
252  #define SPEAKER_QUAD (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT)
253  #define SPEAKER_4POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT)
254  #define SPEAKER_5POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT)
255  #define SPEAKER_7POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER)
256  #define SPEAKER_5POINT1_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT)
257  #define SPEAKER_7POINT1_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT)
258 #endif
259 
260 
261 #pragma pack(pop)
262 
263 #endif // #ifndef __AUDIODEFS_INCLUDED__
const WAVEFORMATEX * LPCWAVEFORMATEX
Definition: audiodefs.h:57
Definition: audiodefs.h:117
short iCoef1
Definition: audiodefs.h:133
WAVEFORMAT wf
Definition: audiodefs.h:119
struct waveformat_tag * NPWAVEFORMAT
WAVEFORMATEX * PWAVEFORMATEX
Definition: audiodefs.h:56
interface __declspec(uuid("A410B984-9839-4819-A0BE-2856AE6B3ADB")) IXAPO
WAVEFORMATEX wfx
Definition: audiodefs.h:141
WORD wNumCoef
Definition: audiodefs.h:143
WORD nBlockAlign
Definition: audiodefs.h:46
WORD wValidBitsPerSample
Definition: audiodefs.h:79
DWORD nSamplesPerSec
Definition: audiodefs.h:44
WORD cbSize
Definition: audiodefs.h:48
const WAVEFORMATEXTENSIBLE * LPCWAVEFORMATEXTENSIBLE
Definition: audiodefs.h:91
struct waveformat_tag WAVEFORMAT
struct waveformat_tag * PWAVEFORMAT
WORD wFormatTag
Definition: audiodefs.h:42
ADPCMCOEFSET aCoef[]
Definition: audiodefs.h:144
struct pcmwaveformat_tag * NPPCMWAVEFORMAT
WORD nChannels
Definition: audiodefs.h:43
const WAVEFORMATEX * PCWAVEFORMATEX
Definition: audiodefs.h:57
struct adpcmwaveformat_tag ADPCMWAVEFORMAT
DWORD nAvgBytesPerSec
Definition: audiodefs.h:45
DWORD nAvgBytesPerSec
Definition: audiodefs.h:112
WAVEFORMATEX * NPWAVEFORMATEX
Definition: audiodefs.h:56
Definition: audiodefs.h:74
GUID SubFormat
Definition: audiodefs.h:85
WORD wReserved
Definition: audiodefs.h:82
const WAVEFORMATEXTENSIBLE * PCWAVEFORMATEXTENSIBLE
Definition: audiodefs.h:91
WORD nChannels
Definition: audiodefs.h:110
Definition: audiodefs.h:140
struct adpcmcoef_tag ADPCMCOEFSET
struct pcmwaveformat_tag * PPCMWAVEFORMAT
struct tWAVEFORMATEX WAVEFORMATEX
struct pcmwaveformat_tag * LPPCMWAVEFORMAT
WORD wBitsPerSample
Definition: audiodefs.h:47
Definition: audiodefs.h:107
WAVEFORMATEX * LPWAVEFORMATEX
Definition: audiodefs.h:56
WAVEFORMATEXTENSIBLE * PWAVEFORMATEXTENSIBLE
Definition: audiodefs.h:90
Definition: audiodefs.h:40
#define FAR
Definition: zconf.h:327
WORD nBlockAlign
Definition: audiodefs.h:113
DWORD nSamplesPerSec
Definition: audiodefs.h:111
WAVEFORMATEX Format
Definition: audiodefs.h:76
DWORD dwChannelMask
Definition: audiodefs.h:84
Definition: audiodefs.h:131
WORD wBitsPerSample
Definition: audiodefs.h:120
struct waveformat_tag * LPWAVEFORMAT
WORD wSamplesPerBlock
Definition: audiodefs.h:142
WAVEFORMATEXTENSIBLE * LPWAVEFORMATEXTENSIBLE
Definition: audiodefs.h:90
WORD wFormatTag
Definition: audiodefs.h:109
short iCoef2
Definition: audiodefs.h:134
struct pcmwaveformat_tag PCMWAVEFORMAT
WORD wSamplesPerBlock
Definition: audiodefs.h:80