|
1 | 1 | use crate::{ |
2 | 2 | error::ResultExt, |
3 | 3 | host::{com::ComString, ErrorCallbackArc}, |
4 | | - BufferSize, Data, DeviceDescription, DeviceDescriptionBuilder, DeviceDirection, DeviceId, |
5 | | - DeviceType, Error, ErrorKind, FrameCount, InputCallbackInfo, InterfaceType, OutputCallbackInfo, |
6 | | - SampleFormat, SampleRate, StreamConfig, SupportedBufferSize, SupportedStreamConfig, |
7 | | - SupportedStreamConfigRange, COMMON_SAMPLE_RATES, |
| 4 | + AudioProcessing, BufferSize, Data, DeviceDescription, DeviceDescriptionBuilder, |
| 5 | + DeviceDirection, DeviceId, DeviceType, Error, ErrorKind, FrameCount, InputCallbackInfo, |
| 6 | + InterfaceType, OutputCallbackInfo, SampleFormat, SampleRate, StreamConfig, SupportedBufferSize, |
| 7 | + SupportedStreamConfig, SupportedStreamConfigRange, COMMON_SAMPLE_RATES, |
8 | 8 | }; |
9 | 9 |
|
10 | 10 | impl From<Audio::EDataFlow> for DeviceDirection { |
@@ -665,6 +665,7 @@ impl Device { |
665 | 665 | channels: format.channels, |
666 | 666 | sample_rate, |
667 | 667 | buffer_size: BufferSize::Default, |
| 668 | + audio_processing: AudioProcessing::Default, |
668 | 669 | }, |
669 | 670 | sample_format, |
670 | 671 | ) { |
@@ -783,6 +784,18 @@ impl Device { |
783 | 784 | .build_audioclient(activation_timeout) |
784 | 785 | .context("failed to build audio client")?; |
785 | 786 |
|
| 787 | + if config.audio_processing == AudioProcessing::PreferRaw { |
| 788 | + if let Ok(audio_client2) = audio_client.cast::<Audio::IAudioClient2>() { |
| 789 | + // Disable audio processing if `PreferRaw` is set and the interface supports it. |
| 790 | + let props = Audio::AudioClientProperties { |
| 791 | + cbSize: std::mem::size_of::<Audio::AudioClientProperties>() as u32, |
| 792 | + Options: Audio::AUDCLNT_STREAMOPTIONS_RAW, |
| 793 | + ..Default::default() |
| 794 | + }; |
| 795 | + audio_client2.SetClientProperties(&props).ok(); |
| 796 | + } |
| 797 | + } |
| 798 | + |
786 | 799 | // Note: Buffer size validation is not needed here - `IAudioClient::Initialize` |
787 | 800 | // will return `AUDCLNT_E_BUFFER_SIZE_ERROR` if the buffer size is not supported. |
788 | 801 | let buffer_duration = buffer_size_to_duration(&config.buffer_size, config.sample_rate); |
@@ -898,6 +911,18 @@ impl Device { |
898 | 911 | .build_audioclient(activation_timeout) |
899 | 912 | .context("failed to build audio client")?; |
900 | 913 |
|
| 914 | + if config.audio_processing == AudioProcessing::PreferRaw { |
| 915 | + if let Ok(audio_client2) = audio_client.cast::<Audio::IAudioClient2>() { |
| 916 | + // Disable audio processing if `PreferRaw` is set and the interface supports it. |
| 917 | + let props = Audio::AudioClientProperties { |
| 918 | + cbSize: std::mem::size_of::<Audio::AudioClientProperties>() as u32, |
| 919 | + Options: Audio::AUDCLNT_STREAMOPTIONS_RAW, |
| 920 | + ..Default::default() |
| 921 | + }; |
| 922 | + audio_client2.SetClientProperties(&props).ok(); |
| 923 | + } |
| 924 | + } |
| 925 | + |
901 | 926 | // Note: Buffer size validation is not needed here - `IAudioClient::Initialize` |
902 | 927 | // will return `AUDCLNT_E_BUFFER_SIZE_ERROR` if the buffer size is not supported. |
903 | 928 | let buffer_duration = buffer_size_to_duration(&config.buffer_size, config.sample_rate); |
|
0 commit comments