audiodefs.h 10 KB

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