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