|
225 | 225 | PaError Pa_GetSampleSize( PaSampleFormat format );
|
226 | 226 | void Pa_Sleep( long msec );
|
227 | 227 |
|
| 228 | +/* pa_win_waveformat.h */ |
| 229 | +
|
| 230 | +typedef unsigned long PaWinWaveFormatChannelMask; |
| 231 | +
|
228 | 232 | /* pa_asio.h */
|
229 | 233 |
|
230 | 234 | #define paAsioUseChannelSelectors 0x01
|
|
237 | 241 | unsigned long flags;
|
238 | 242 | int *channelSelectors;
|
239 | 243 | } PaAsioStreamInfo;
|
| 244 | +
|
| 245 | +/* pa_win_wasapi.h */ |
| 246 | +
|
| 247 | +typedef enum PaWasapiFlags |
| 248 | +{ |
| 249 | + paWinWasapiExclusive = 1, |
| 250 | + paWinWasapiRedirectHostProcessor = 2, |
| 251 | + paWinWasapiUseChannelMask = 4, |
| 252 | + paWinWasapiPolling = 8, |
| 253 | + paWinWasapiThreadPriority = 16 |
| 254 | +} PaWasapiFlags; |
| 255 | +
|
| 256 | +typedef void (*PaWasapiHostProcessorCallback) ( |
| 257 | + void *inputBuffer, long inputFrames, |
| 258 | + void *outputBuffer, long outputFrames, void *userData); |
| 259 | +
|
| 260 | +typedef enum PaWasapiThreadPriority |
| 261 | +{ |
| 262 | + eThreadPriorityNone = 0, |
| 263 | + eThreadPriorityAudio, |
| 264 | + eThreadPriorityCapture, |
| 265 | + eThreadPriorityDistribution, |
| 266 | + eThreadPriorityGames, |
| 267 | + eThreadPriorityPlayback, |
| 268 | + eThreadPriorityProAudio, |
| 269 | + eThreadPriorityWindowManager |
| 270 | +} PaWasapiThreadPriority; |
| 271 | +
|
| 272 | +typedef enum PaWasapiStreamCategory |
| 273 | +{ |
| 274 | + eAudioCategoryOther = 0, |
| 275 | + eAudioCategoryCommunications = 3, |
| 276 | + eAudioCategoryAlerts = 4, |
| 277 | + eAudioCategorySoundEffects = 5, |
| 278 | + eAudioCategoryGameEffects = 6, |
| 279 | + eAudioCategoryGameMedia = 7, |
| 280 | + eAudioCategoryGameChat = 8, |
| 281 | + eAudioCategorySpeech = 9, |
| 282 | + eAudioCategoryMovie = 10, |
| 283 | + eAudioCategoryMedia = 11 |
| 284 | +} PaWasapiStreamCategory; |
| 285 | +
|
| 286 | +typedef enum PaWasapiStreamOption |
| 287 | +{ |
| 288 | + eStreamOptionNone = 0, |
| 289 | + eStreamOptionRaw = 1, |
| 290 | + eStreamOptionMatchFormat = 2 |
| 291 | +} PaWasapiStreamOption; |
| 292 | +
|
| 293 | +typedef struct PaWasapiStreamInfo |
| 294 | +{ |
| 295 | + unsigned long size; |
| 296 | + PaHostApiTypeId hostApiType; |
| 297 | + unsigned long version; |
| 298 | + unsigned long flags; |
| 299 | + PaWinWaveFormatChannelMask channelMask; |
| 300 | + PaWasapiHostProcessorCallback hostProcessorOutput; |
| 301 | + PaWasapiHostProcessorCallback hostProcessorInput; |
| 302 | + PaWasapiThreadPriority threadPriority; |
| 303 | + PaWasapiStreamCategory streamCategory; |
| 304 | + PaWasapiStreamOption streamOption; |
| 305 | +} PaWasapiStreamInfo; |
240 | 306 | """)
|
241 | 307 |
|
242 | 308 | try:
|
@@ -2052,7 +2118,7 @@ class default(object):
|
2052 | 2118 |
|
2053 | 2119 | See Also
|
2054 | 2120 | --------
|
2055 |
| - AsioSettings |
| 2121 | + AsioSettings, WasapiSettings |
2056 | 2122 |
|
2057 | 2123 | """
|
2058 | 2124 |
|
@@ -2222,6 +2288,47 @@ def __init__(self, channel_selectors):
|
2222 | 2288 | channelSelectors=self._selectors))
|
2223 | 2289 |
|
2224 | 2290 |
|
| 2291 | +class WasapiSettings(object): |
| 2292 | + |
| 2293 | + def __init__(self, exclusive=False): |
| 2294 | + """WASAPI-specific input/output settings. |
| 2295 | +
|
| 2296 | + Objects of this class can be used as *extra_settings* argument |
| 2297 | + to `Stream()` (and variants) or as `default.extra_settings`. |
| 2298 | + They can also be used in `check_input_settings()` and |
| 2299 | + `check_output_settings()`. |
| 2300 | +
|
| 2301 | + Parameters |
| 2302 | + ---------- |
| 2303 | + exclusive : bool |
| 2304 | + Exclusive mode allows to deliver audio data directly to |
| 2305 | + hardware bypassing software mixing. |
| 2306 | +
|
| 2307 | + Examples |
| 2308 | + -------- |
| 2309 | + Setting exclusive mode when calling `play()`: |
| 2310 | +
|
| 2311 | + >>> import sounddevice as sd |
| 2312 | + >>> wasapi_exclusive = sd.WasapiSettings(exclusive=True) |
| 2313 | + >>> sd.play(..., extra_settings=wasapi_exclusive) |
| 2314 | +
|
| 2315 | + Setting exclusive mode as default: |
| 2316 | +
|
| 2317 | + >>> sd.default.extra_settings = wasapi_exclusive |
| 2318 | + >>> sd.play(...) |
| 2319 | +
|
| 2320 | + """ |
| 2321 | + flags = 0x0 |
| 2322 | + if exclusive: |
| 2323 | + flags |= paWinWasapiExclusive |
| 2324 | + self._streaminfo = _ffi.new('PaWasapiStreamInfo*', dict( |
| 2325 | + size=_ffi.sizeof('PaWasapiStreamInfo'), |
| 2326 | + hostApiType=_lib.paWASAPI, |
| 2327 | + version=1, |
| 2328 | + flags=flags, |
| 2329 | + )) |
| 2330 | + |
| 2331 | + |
2225 | 2332 | class _CallbackContext(object):
|
2226 | 2333 | """Helper class for re-use in play()/rec()/playrec() callbacks."""
|
2227 | 2334 |
|
|
0 commit comments