| 539 | |
| 540 | template <typename Functor> |
| 541 | decltype(auto) FlexASIO::WithStreamParameters(bool inputEnabled, bool outputEnabled, double sampleRate, PaTime defaultSuggestedLatency, Functor functor) const |
| 542 | { |
| 543 | Log() << "FlexASIO::WithStreamParameters(inputEnabled = " << inputEnabled << ", outputEnabled = " << outputEnabled << ", sampleRate = " << sampleRate << ")"; |
| 544 | |
| 545 | auto exclusivity = hostApi.info.type == paWDMKS ? StreamExclusivity::EXCLUSIVE : StreamExclusivity::SHARED; |
| 546 | |
| 547 | PaStreamParameters common_parameters = { 0 }; |
| 548 | common_parameters.sampleFormat = paNonInterleaved; |
| 549 | common_parameters.hostApiSpecificStreamInfo = NULL; |
| 550 | common_parameters.suggestedLatency = defaultSuggestedLatency; |
| 551 | |
| 552 | PaWasapiStreamInfo common_wasapi_stream_info = { 0 }; |
| 553 | if (hostApi.info.type == paWASAPI) { |
| 554 | common_wasapi_stream_info.size = sizeof(common_wasapi_stream_info); |
| 555 | common_wasapi_stream_info.hostApiType = paWASAPI; |
| 556 | common_wasapi_stream_info.version = 1; |
| 557 | common_wasapi_stream_info.flags = 0; |
| 558 | } |
| 559 | |
| 560 | PaStreamParameters input_parameters = common_parameters; |
| 561 | PaWasapiStreamInfo input_wasapi_stream_info = common_wasapi_stream_info; |
| 562 | if (inputEnabled) |
| 563 | { |
| 564 | input_parameters.device = inputDevice->index; |
| 565 | input_parameters.channelCount = GetInputChannelCount(); |
| 566 | input_parameters.sampleFormat |= inputSampleType->pa; |
| 567 | if (config.input.suggestedLatencySeconds.has_value()) input_parameters.suggestedLatency = *config.input.suggestedLatencySeconds; |
| 568 | if (hostApi.info.type == paWASAPI) |
| 569 | { |
| 570 | if (inputChannelMask != 0) |
| 571 | { |
| 572 | input_wasapi_stream_info.flags |= paWinWasapiUseChannelMask; |
| 573 | input_wasapi_stream_info.channelMask = inputChannelMask; |
| 574 | } |
| 575 | Log() << "Using " << (config.input.wasapiExclusiveMode ? "exclusive" : "shared") << " mode for input WASAPI stream"; |
| 576 | if (config.input.wasapiExclusiveMode) { |
| 577 | input_wasapi_stream_info.flags |= paWinWasapiExclusive; |
| 578 | exclusivity = StreamExclusivity::EXCLUSIVE; |
| 579 | } |
| 580 | Log() << (config.input.wasapiAutoConvert ? "Enabling" : "Disabling") << " auto-conversion for input WASAPI stream"; |
| 581 | if (config.input.wasapiAutoConvert) { |
| 582 | input_wasapi_stream_info.flags |= paWinWasapiAutoConvert; |
| 583 | } |
| 584 | Log() << (config.input.wasapiExplicitSampleFormat ? "Enabling" : "Disabling") << " explicit sample format for input WASAPI stream"; |
| 585 | if (config.input.wasapiExplicitSampleFormat) { |
| 586 | input_wasapi_stream_info.flags |= paWinWasapiExplicitSampleFormat; |
| 587 | } |
| 588 | input_parameters.hostApiSpecificStreamInfo = &input_wasapi_stream_info; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | PaStreamParameters output_parameters = common_parameters; |
| 593 | PaWasapiStreamInfo output_wasapi_stream_info = common_wasapi_stream_info; |
| 594 | if (outputEnabled) |
| 595 | { |
| 596 | output_parameters.device = outputDevice->index; |
| 597 | output_parameters.channelCount = GetOutputChannelCount(); |
| 598 | output_parameters.sampleFormat |= outputSampleType->pa; |