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