diff --git a/PInvoke/CoreAudio/AudioClient.cs b/PInvoke/CoreAudio/AudioClient.cs index 32a089a9..22690259 100644 --- a/PInvoke/CoreAudio/AudioClient.cs +++ b/PInvoke/CoreAudio/AudioClient.cs @@ -1,13 +1,18 @@ using System; using System.Runtime.InteropServices; using Vanara.InteropServices; -using static Vanara.PInvoke.Winmm; +using static Vanara.PInvoke.WinMm; namespace Vanara.PInvoke { /// Functions, structures and constants from Windows Core Audio Api. public static partial class CoreAudio { + public const uint WM_APP_SESSION_DUCKED = 0x8000; + public const uint WM_APP_SESSION_UNDUCKED = 0x8001; + public const uint WM_APP_GRAPHNOTIFY = 0x8002; + public const uint WM_APP_SESSION_VOLUME_CHANGED = 0x8003; + /// The _AUDCLNT_BUFFERFLAGS enumeration defines flags that indicate the status of an audio endpoint buffer. /// /// The IAudioCaptureClient::GetBuffer and IAudioRenderClient::ReleaseBuffer methods use the constants defined in the @@ -1205,7 +1210,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-getmixformat HRESULT GetMixFormat( // WAVEFORMATEX **ppDeviceFormat ); [PreserveSig] - HRESULT GetMixFormat(out SafeCoTaskMemHandle ppDeviceFormat); + HRESULT GetMixFormat(out SafeCoTaskMemStruct ppDeviceFormat); /// /// The GetDevicePeriod method retrieves the length of the periodic interval separating successive processing passes by @@ -1367,7 +1372,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-seteventhandle HRESULT // SetEventHandle( HANDLE eventHandle ); - void SetEventHandle(IntPtr eventHandle); + void SetEventHandle(HEVENT eventHandle); /// The GetService method accesses additional services from the audio client object. /// @@ -2245,7 +2250,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-getmixformat HRESULT GetMixFormat( // WAVEFORMATEX **ppDeviceFormat ); [PreserveSig] - new HRESULT GetMixFormat(out SafeCoTaskMemHandle ppDeviceFormat); + new HRESULT GetMixFormat(out SafeCoTaskMemStruct ppDeviceFormat); /// /// The GetDevicePeriod method retrieves the length of the periodic interval separating successive processing passes by @@ -2407,7 +2412,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-seteventhandle HRESULT // SetEventHandle( HANDLE eventHandle ); - new void SetEventHandle(IntPtr eventHandle); + new void SetEventHandle(HEVENT eventHandle); /// The GetService method accesses additional services from the audio client object. /// @@ -3327,7 +3332,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-getmixformat HRESULT GetMixFormat( // WAVEFORMATEX **ppDeviceFormat ); [PreserveSig] - new HRESULT GetMixFormat(out SafeCoTaskMemHandle ppDeviceFormat); + new HRESULT GetMixFormat(out SafeCoTaskMemStruct ppDeviceFormat); /// /// The GetDevicePeriod method retrieves the length of the periodic interval separating successive processing passes by @@ -3489,7 +3494,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-seteventhandle HRESULT // SetEventHandle( HANDLE eventHandle ); - new void SetEventHandle(IntPtr eventHandle); + new void SetEventHandle(HEVENT eventHandle); /// The GetService method accesses additional services from the audio client object. /// @@ -3719,7 +3724,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient3-getcurrentsharedmodeengineperiod // HRESULT GetCurrentSharedModeEnginePeriod( WAVEFORMATEX **ppFormat, UINT32 *pCurrentPeriodInFrames ); - void GetCurrentSharedModeEnginePeriod(out SafeCoTaskMemHandle ppFormat, out uint pCurrentPeriodInFrames); + void GetCurrentSharedModeEnginePeriod(out SafeCoTaskMemStruct ppFormat, out uint pCurrentPeriodInFrames); /// Initializes a shared stream with the specified periodicity. /// @@ -4702,64 +4707,12 @@ namespace Vanara.PInvoke /// Note The values returned by this method are instantaneous values and may be invalid immediately after the call returns /// if, for example, another audio client sets the periodicity or format to a different value. /// - public static (WAVEFORMATEX ppFormat, uint pCurrentPeriodInFrames) GetCurrentSharedModeEnginePeriod(this IAudioClient3 client) + public static (SafeCoTaskMemStruct ppFormat, uint pCurrentPeriodInFrames) GetCurrentSharedModeEnginePeriod(this IAudioClient3 client) { client.GetCurrentSharedModeEnginePeriod(out var fmt, out var fr); - using (fmt) - return (fmt.ToStructure(), fr); + return (fmt, fr); } - /// - /// The GetMixFormat method retrieves the stream format that the audio engine uses for its internal processing of shared-mode streams. - /// - /// The client. - /// A variable into which the method writes the address of the mix format. - /// - /// - /// The client can call this method before calling the IAudioClient::Initialize method. When creating a shared-mode stream for an - /// audio endpoint device, the Initialize method always accepts the stream format obtained from a GetMixFormat call on - /// the same device. - /// - /// - /// The mix format is the format that the audio engine uses internally for digital processing of shared-mode streams. This format is - /// not necessarily a format that the audio endpoint device supports. Thus, the caller might not succeed in creating an - /// exclusive-mode stream with a format obtained by calling GetMixFormat. - /// - /// - /// For example, to facilitate digital audio processing, the audio engine might use a mix format that represents samples as - /// floating-point values. If the device supports only integer PCM samples, then the engine converts the samples to or from integer - /// PCM values at the connection between the device and the engine. However, to avoid resampling, the engine might use a mix format - /// with a sample rate that the device supports. - /// - /// - /// To determine whether the Initialize method can create a shared-mode or exclusive-mode stream with a particular format, - /// call the IAudioClient::IsFormatSupported method. - /// - /// - /// By itself, a WAVEFORMATEX structure cannot specify the mapping of channels to speaker positions. In addition, although - /// WAVEFORMATEX specifies the size of the container for each audio sample, it cannot specify the number of bits of precision - /// in a sample (for example, 20 bits of precision in a 24-bit container). However, the WAVEFORMATEXTENSIBLE structure can - /// specify both the mapping of channels to speakers and the number of bits of precision in each sample. For this reason, the - /// GetMixFormat method retrieves a format descriptor that is in the form of a WAVEFORMATEXTENSIBLE structure instead - /// of a standalone WAVEFORMATEX structure. Through the ppDeviceFormat parameter, the method outputs a pointer to the - /// WAVEFORMATEX structure that is embedded at the start of this WAVEFORMATEXTENSIBLE structure. For more information - /// about WAVEFORMATEX and WAVEFORMATEXTENSIBLE, see the Windows DDK documentation. - /// - /// - /// For more information about the GetMixFormat method, see Device Formats. For code examples that call GetMixFormat, - /// see the following topics: - /// - /// - /// - /// Rendering a Stream - /// - /// - /// Capturing a Stream - /// - /// - /// - public static WAVEFORMATEX GetMixFormat(this IAudioClient client) { var hr = client.GetMixFormat(out var mem); return hr.Succeeded && !mem.IsInvalid ? mem.ToStructure() : throw hr.GetException(); } - /// The GetService method accesses additional services from the audio client object. /// The client. ///