2
0

pa_win_waveformat.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #ifndef PA_WIN_WAVEFORMAT_H
  2. #define PA_WIN_WAVEFORMAT_H
  3. /*
  4. * PortAudio Portable Real-Time Audio Library
  5. * Windows WAVEFORMAT* data structure utilities
  6. * portaudio.h should be included before this file.
  7. *
  8. * Copyright (c) 2007 Ross Bencina
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining
  11. * a copy of this software and associated documentation files
  12. * (the "Software"), to deal in the Software without restriction,
  13. * including without limitation the rights to use, copy, modify, merge,
  14. * publish, distribute, sublicense, and/or sell copies of the Software,
  15. * and to permit persons to whom the Software is furnished to do so,
  16. * subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be
  19. * included in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  25. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  26. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. */
  29. /*
  30. * The text above constitutes the entire PortAudio license; however,
  31. * the PortAudio community also makes the following non-binding requests:
  32. *
  33. * Any person wishing to distribute modifications to the Software is
  34. * requested to send the modifications to the original developer so that
  35. * they can be incorporated into the canonical version. It is also
  36. * requested that these non-binding requests be included along with the
  37. * license above.
  38. */
  39. /** @file
  40. @ingroup public_header
  41. @brief Windows specific PortAudio API extension and utilities header file.
  42. */
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /*
  47. The following #defines for speaker channel masks are the same
  48. as those in ksmedia.h, except with PAWIN_ prepended, KSAUDIO_ removed
  49. in some cases, and casts to PaWinWaveFormatChannelMask added.
  50. */
  51. typedef unsigned long PaWinWaveFormatChannelMask;
  52. /* Speaker Positions: */
  53. #define PAWIN_SPEAKER_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1)
  54. #define PAWIN_SPEAKER_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x2)
  55. #define PAWIN_SPEAKER_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x4)
  56. #define PAWIN_SPEAKER_LOW_FREQUENCY ((PaWinWaveFormatChannelMask)0x8)
  57. #define PAWIN_SPEAKER_BACK_LEFT ((PaWinWaveFormatChannelMask)0x10)
  58. #define PAWIN_SPEAKER_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20)
  59. #define PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER ((PaWinWaveFormatChannelMask)0x40)
  60. #define PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER ((PaWinWaveFormatChannelMask)0x80)
  61. #define PAWIN_SPEAKER_BACK_CENTER ((PaWinWaveFormatChannelMask)0x100)
  62. #define PAWIN_SPEAKER_SIDE_LEFT ((PaWinWaveFormatChannelMask)0x200)
  63. #define PAWIN_SPEAKER_SIDE_RIGHT ((PaWinWaveFormatChannelMask)0x400)
  64. #define PAWIN_SPEAKER_TOP_CENTER ((PaWinWaveFormatChannelMask)0x800)
  65. #define PAWIN_SPEAKER_TOP_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1000)
  66. #define PAWIN_SPEAKER_TOP_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x2000)
  67. #define PAWIN_SPEAKER_TOP_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x4000)
  68. #define PAWIN_SPEAKER_TOP_BACK_LEFT ((PaWinWaveFormatChannelMask)0x8000)
  69. #define PAWIN_SPEAKER_TOP_BACK_CENTER ((PaWinWaveFormatChannelMask)0x10000)
  70. #define PAWIN_SPEAKER_TOP_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20000)
  71. /* Bit mask locations reserved for future use */
  72. #define PAWIN_SPEAKER_RESERVED ((PaWinWaveFormatChannelMask)0x7FFC0000)
  73. /* Used to specify that any possible permutation of speaker configurations */
  74. #define PAWIN_SPEAKER_ALL ((PaWinWaveFormatChannelMask)0x80000000)
  75. /* DirectSound Speaker Config */
  76. #define PAWIN_SPEAKER_DIRECTOUT 0
  77. #define PAWIN_SPEAKER_MONO (PAWIN_SPEAKER_FRONT_CENTER)
  78. #define PAWIN_SPEAKER_STEREO (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT)
  79. #define PAWIN_SPEAKER_QUAD (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  80. PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT)
  81. #define PAWIN_SPEAKER_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  82. PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_BACK_CENTER)
  83. #define PAWIN_SPEAKER_5POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  84. PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
  85. PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT)
  86. #define PAWIN_SPEAKER_7POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  87. PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
  88. PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \
  89. PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER | PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER)
  90. #define PAWIN_SPEAKER_5POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  91. PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
  92. PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT)
  93. #define PAWIN_SPEAKER_7POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
  94. PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
  95. PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \
  96. PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT)
  97. /*
  98. According to the Microsoft documentation:
  99. The following are obsolete 5.1 and 7.1 settings (they lack side speakers). Note this means
  100. that the default 5.1 and 7.1 settings (KSAUDIO_SPEAKER_5POINT1 and KSAUDIO_SPEAKER_7POINT1 are
  101. similarly obsolete but are unchanged for compatibility reasons).
  102. */
  103. #define PAWIN_SPEAKER_5POINT1_BACK PAWIN_SPEAKER_5POINT1
  104. #define PAWIN_SPEAKER_7POINT1_WIDE PAWIN_SPEAKER_7POINT1
  105. /* DVD Speaker Positions */
  106. #define PAWIN_SPEAKER_GROUND_FRONT_LEFT PAWIN_SPEAKER_FRONT_LEFT
  107. #define PAWIN_SPEAKER_GROUND_FRONT_CENTER PAWIN_SPEAKER_FRONT_CENTER
  108. #define PAWIN_SPEAKER_GROUND_FRONT_RIGHT PAWIN_SPEAKER_FRONT_RIGHT
  109. #define PAWIN_SPEAKER_GROUND_REAR_LEFT PAWIN_SPEAKER_BACK_LEFT
  110. #define PAWIN_SPEAKER_GROUND_REAR_RIGHT PAWIN_SPEAKER_BACK_RIGHT
  111. #define PAWIN_SPEAKER_TOP_MIDDLE PAWIN_SPEAKER_TOP_CENTER
  112. #define PAWIN_SPEAKER_SUPER_WOOFER PAWIN_SPEAKER_LOW_FREQUENCY
  113. /*
  114. PaWinWaveFormat is defined here to provide compatibility with
  115. compilation environments which don't have headers defining
  116. WAVEFORMATEXTENSIBLE (e.g. older versions of MSVC, Borland C++ etc.
  117. The fields for WAVEFORMATEX and WAVEFORMATEXTENSIBLE are declared as an
  118. unsigned char array here to avoid clients who include this file having
  119. a dependency on windows.h and mmsystem.h, and also to to avoid having
  120. to write separate packing pragmas for each compiler.
  121. */
  122. #define PAWIN_SIZEOF_WAVEFORMATEX 18
  123. #define PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE (PAWIN_SIZEOF_WAVEFORMATEX + 22)
  124. typedef struct{
  125. unsigned char fields[ PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE ];
  126. unsigned long extraLongForAlignment; /* ensure that compiler aligns struct to DWORD */
  127. } PaWinWaveFormat;
  128. /*
  129. WAVEFORMATEXTENSIBLE fields:
  130. union {
  131. WORD wValidBitsPerSample;
  132. WORD wSamplesPerBlock;
  133. WORD wReserved;
  134. } Samples;
  135. DWORD dwChannelMask;
  136. GUID SubFormat;
  137. */
  138. #define PAWIN_INDEXOF_WVALIDBITSPERSAMPLE (PAWIN_SIZEOF_WAVEFORMATEX+0)
  139. #define PAWIN_INDEXOF_DWCHANNELMASK (PAWIN_SIZEOF_WAVEFORMATEX+2)
  140. #define PAWIN_INDEXOF_SUBFORMAT (PAWIN_SIZEOF_WAVEFORMATEX+6)
  141. /*
  142. Valid values to pass for the waveFormatTag PaWin_InitializeWaveFormatEx and
  143. PaWin_InitializeWaveFormatExtensible functions below. These must match
  144. the standard Windows WAVE_FORMAT_* values.
  145. */
  146. #define PAWIN_WAVE_FORMAT_PCM (1)
  147. #define PAWIN_WAVE_FORMAT_IEEE_FLOAT (3)
  148. #define PAWIN_WAVE_FORMAT_DOLBY_AC3_SPDIF (0x0092)
  149. #define PAWIN_WAVE_FORMAT_WMA_SPDIF (0x0164)
  150. /*
  151. returns PAWIN_WAVE_FORMAT_PCM or PAWIN_WAVE_FORMAT_IEEE_FLOAT
  152. depending on the sampleFormat parameter.
  153. */
  154. int PaWin_SampleFormatToLinearWaveFormatTag( PaSampleFormat sampleFormat );
  155. /*
  156. Use the following two functions to initialize the waveformat structure.
  157. */
  158. void PaWin_InitializeWaveFormatEx( PaWinWaveFormat *waveFormat,
  159. int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate );
  160. void PaWin_InitializeWaveFormatExtensible( PaWinWaveFormat *waveFormat,
  161. int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate,
  162. PaWinWaveFormatChannelMask channelMask );
  163. /* Map a channel count to a speaker channel mask */
  164. PaWinWaveFormatChannelMask PaWin_DefaultChannelMask( int numChannels );
  165. #ifdef __cplusplus
  166. }
  167. #endif /* __cplusplus */
  168. #endif /* PA_WIN_WAVEFORMAT_H */