using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke; /// Functions, structures and constants from Windows Core Audio Api. public static partial class CoreAudio { /// Specifies the shape in which sound is emitted by an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ne-spatialaudiohrtf-spatialaudiohrtfdirectivitytype typedef enum // SpatialAudioHrtfDirectivityType { SpatialAudioHrtfDirectivity_OmniDirectional, SpatialAudioHrtfDirectivity_Cardioid, // SpatialAudioHrtfDirectivity_Cone } ; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "3A1426B5-F4FF-4CF0-9E0A-3096371B3D2E")] public enum SpatialAudioHrtfDirectivityType { /// The sound is emitted in all directions. SpatialAudioHrtfDirectivity_OmniDirectional, /// The sound is emitted in a cardioid shape. SpatialAudioHrtfDirectivity_Cardioid, /// The sound is emitted in a cone shape. SpatialAudioHrtfDirectivity_Cone, } /// /// Specifies the type of decay applied over distance from the position of an ISpatialAudioObjectForHrtf to the position of the listener. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ne-spatialaudiohrtf-spatialaudiohrtfdistancedecaytype typedef enum // SpatialAudioHrtfDistanceDecayType { SpatialAudioHrtfDistanceDecay_NaturalDecay, SpatialAudioHrtfDistanceDecay_CustomDecay } ; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "EF4ACEB1-E802-4337-AA76-467BCB90D7C6")] public enum SpatialAudioHrtfDistanceDecayType { /// /// A natural decay over distance, as constrained by minimum and maximum gain distance limits. The output drops to silent at the /// distance specified by SpatialAudioHrtfDistanceDecay.CutoffDistance. /// SpatialAudioHrtfDistanceDecay_NaturalDecay, /// A custom gain curve, within the maximum and minimum gain limit. SpatialAudioHrtfDistanceDecay_CustomDecay, } /// Specifies the type of acoustic environment that is simulated when audio is processed for an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ne-spatialaudiohrtf-spatialaudiohrtfenvironmenttype typedef enum // SpatialAudioHrtfEnvironmentType { SpatialAudioHrtfEnvironment_Small, SpatialAudioHrtfEnvironment_Medium, // SpatialAudioHrtfEnvironment_Large, SpatialAudioHrtfEnvironment_Outdoors, SpatialAudioHrtfEnvironment_Average } ; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "017FC8D4-2B74-4B13-AF5B-D7FFF97A7E45")] public enum SpatialAudioHrtfEnvironmentType { /// A small room. SpatialAudioHrtfEnvironment_Small, /// A medium-sized room. SpatialAudioHrtfEnvironment_Medium, /// A large room. SpatialAudioHrtfEnvironment_Large, /// An outdoor space. SpatialAudioHrtfEnvironment_Outdoors, /// Reserved for Microsoft use. Apps should not use this value. SpatialAudioHrtfEnvironment_Average, } /// /// /// Represents an object that provides audio data to be rendered from a position in 3D space, relative to the user, a head-relative /// transfer function (HRTF). Spatial audio objects can be static or dynamic, which you specify with the type parameter to the /// ISpatialAudioObjectRenderStreamForHrtf::ActivateSpatialAudioObjectForHrtf method. Dynamic audio objects can be placed in an arbitrary /// position in space and can be moved over time. Static audio objects are assigned to one or more channels, defined in the /// AudioObjectType enumeration, that each correlate to a fixed speaker location that may be a physical or a virtualized speaker /// /// /// This interface is a part of Windows Sonic, Microsoft’s audio platform for more immersive audio which includes integrated spatial /// sound on Xbox and Windows. /// /// /// Note Many of the methods provided by this interface are implemented in the inherited ISpatialAudioObjectBase interface. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nn-spatialaudiohrtf-ispatialaudioobjectforhrtf [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "E69F1D09-B937-4BCC-A040-18EF8A838289")] [ComImport, Guid("D7436ADE-1978-4E14-ABA0-555BD8EB83B4"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ISpatialAudioObjectForHrtf : ISpatialAudioObjectBase { /// Gets a buffer that is used to supply the audio data for the ISpatialAudioObject. /// The buffer into which audio data is written. /// /// The length of the buffer in bytes. This length will be the value returned in the frameCountPerBuffer parameter to /// ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects multiplied by the value of the nBlockAlign field of the /// WAVEFORMATEX structure passed in the SpatialAudioObjectRenderStreamActivationParams parameter to ISpatialAudioClient::ActivateSpatialAudioStream. /// /// /// /// The first time GetBuffer is called after the ISpatialAudioObject is activated with a call /// ISpatialAudioObjectRenderStream::ActivateSpatialAudioObject, lifetime of the spatial audio object starts. To keep the spatial /// audio object alive after that, this GetBuffer must be called on every processing pass (between calls to /// ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects and ISpatialAudioObjectRenderStream::EndUpdatingAudioObjects). If /// GetBuffer is not called within an audio processing pass, SetEndOfStream is called implicitly on the audio object to /// deactivate, and the audio object can only be reused after calling Release on the object and then reactivating the object by /// calling ActivateSpatialAudioObject again. /// /// /// The pointers retrieved by GetBuffer should not be used after ISpatialAudioObjectRenderStream::EndUpdatingAudioObjects has /// been called. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectbase-getbuffer // HRESULT GetBuffer( BYTE **buffer, UINT32 *bufferLength ); new void GetBuffer(out IntPtr buffer, out uint bufferLength); /// /// Instructs the system that the final block of audio data has been submitted for the ISpatialAudioObject so that the object can be /// deactivated and it's resources reused. /// /// /// The number of audio frames in the audio buffer that should be included in the final processing pass. This number may be smaller /// than or equal to the value returned in the frameCountPerBuffer parameter to ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects. /// /// /// /// If the method succeeds, it returns S_OK. If it fails, possible return codes include, but are not limited to, the values shown in /// the following table. /// /// /// /// Return code /// Description /// /// /// SPTLAUDCLNT_E_OUT_OF_ORDER /// ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects was not called before the call to SetEndOfStream. /// /// /// SPTLAUDCLNT_E_RESOURCES_INVALIDATED /// /// SetEndOfStream was called either explicitly or implicitly in a previous audio processing pass. SetEndOfStream is called /// implicitly by the system if GetBuffer is not called within an audio processing pass (between calls to /// ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects and ISpatialAudioObjectRenderStream::EndUpdatingAudioObjects). /// /// /// /// /// Call Release after calling SetEndOfStream to make free the audio object resources for future use. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectbase-setendofstream // HRESULT SetEndOfStream( UINT32 frameCount ); new void SetEndOfStream([In] uint frameCount); /// Gets a boolean value indicating whether the ISpatialAudioObject is valid. /// TRUE if the audio object is currently valid; otherwise, FALSE. /// /// If this value is false, you should call Release to make the audio object resource available in the future. /// /// IsActive will be set to false after SetEndOfStream is called implicitly or explicitly. SetEndOfStream is called /// implicitly by the system if GetBuffer is not called within an audio processing pass (between calls to /// ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects and ISpatialAudioObjectRenderStream::EndUpdatingAudioObjects). /// /// /// The rendering engine will also deactivate the audio object, setting IsActive to false, when audio object resources become /// unavailable. In this case, a notification is sent via ISpatialAudioObjectRenderStreamNotify before the object is deactivated. The /// value returned in the availableDynamicObjectCount parameter to ISpatialAudioObjectRenderStream::BeginUpdatingAudioObjects /// indicates how many objects will be processed for each pass. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectbase-isactive // HRESULT IsActive( BOOL *isActive ); [return: MarshalAs(UnmanagedType.Bool)] new bool IsActive(); /// /// Gets a value specifying the type of audio object that is represented by the ISpatialAudioObject. This value indicates if the /// object is dynamic or static. If the object is static, one and only one of the static audio channel values to which the object is /// assigned is returned. /// /// A value specifying the type of audio object that is represented /// /// Set the type of the audio object with the type parameter to the ISpatialAudioObjectRenderStream::ActivateSpatialAudioObject method. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectbase-getaudioobjecttype // HRESULT GetAudioObjectType( AudioObjectType *audioObjectType ); new AudioObjectType GetAudioObjectType(); /// /// Sets the position in 3D space, relative to the listener, from which the ISpatialAudioObjectForHrtf audio data will be rendered. /// /// /// The x position of the audio object, in meters, relative to the listener. Positive values are to the right of the listener and /// negative values are to the left. /// /// /// The y position of the audio object, in meters, relative to the listener. Positive values are above the listener and negative /// values are below. /// /// /// The z position of the audio object, in meters, relative to the listener. Positive values are behind the listener and negative /// values are in front. /// /// /// /// This method can only be called on a ISpatialAudioObjectForHrtf that is of type AudioObjectType_Dynamic. Set the type of /// the audio object with the type parameter to the ISpatialAudioObjectRenderStreamForHrtf::ActivateSpatialAudioObjectForHrtf method. /// /// /// Position values use a right-handed Cartesian coordinate system, where each unit represents 1 meter. The coordinate system is /// relative to the listener where the origin (x=0.0, y=0.0, z=0.0) represents the center point between the listener's ears. /// /// /// If SetPosition is never called, the origin (x=0.0, y=0.0, z=0.0) is used as the default position. After SetPosition /// is called, the position that is set will be used for the audio object until the position is changed with another call to SetPosition. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setposition // HRESULT SetPosition( float x, float y, float z ); void SetPosition([In] float x, [In] float y, [In] float z); /// Sets the gain for the ISpatialAudioObjectForHrtf. /// The gain for the ISpatialAudioObjectForHrtf. /// /// /// This is valid only for spatial audio objects configured to use the SpatialAudioHrtfDistanceDecay_CustomDecay decay type. Set the /// decay type of an ISpatialAudioObjectForHrtf object by calling SetDistanceDecay. Set the default decay type for an all objects in /// an HRTF render stream by setting the DistanceDecay field of the SpatialAudioHrtfActivationParams passed into ISpatialAudioClient::ActivateSpatialAudioStream. /// /// /// If SetGain is never called, the default value of 0.0 is used. After SetGain is called, the gain that is set will be /// used for the audio object until the gain is changed with another call to SetGain. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setgain HRESULT // SetGain( float gain ); void SetGain([In] float gain); /// /// Sets the orientation in 3D space, relative to the listener's frame of reference, from which the ISpatialAudioObjectForHrtf audio /// data will be rendered. /// /// An array of floats defining row-major 3x3 rotation matrix. /// /// If SetOrientation is never called, the default value of an identity matrix is used. After SetOrientation is called, /// the orientation that is set will be used for the audio object until the orientation is changed with another call to SetOrientation. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setorientation // HRESULT SetOrientation( const SpatialAudioHrtfOrientation *orientation ); void SetOrientation(in SpatialAudioHrtfOrientation orientation); /// Sets the type of acoustic environment that is simulated when audio is processed for the ISpatialAudioObjectForHrtf. /// /// A value specifying the type of acoustic environment that is simulated when audio is processed for the ISpatialAudioObjectForHrtf. /// /// If SetEnvironment is not called, the default value of SpatialAudioHrtfEnvironment_Small is used. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setenvironment // HRESULT SetEnvironment( SpatialAudioHrtfEnvironmentType environment ); void SetEnvironment([In] SpatialAudioHrtfEnvironmentType environment); /// /// Sets the decay model that is applied over distance from the position of an ISpatialAudioObjectForHrtf to the position of the listener. /// /// The decay model. /// If SetEnvironment is not called, the default values are used. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setdistancedecay // HRESULT SetDistanceDecay( SpatialAudioHrtfDistanceDecay *distanceDecay ); void SetDistanceDecay(in SpatialAudioHrtfDistanceDecay distanceDecay); /// Sets the spatial audio directivity model for the ISpatialAudioObjectForHrtf. /// /// The spatial audio directivity model. This value can be one of the following structures: /// /// /// SpatialAudioHrtfDirectivity /// /// /// SpatialAudioHrtfDirectivityCardioid /// /// /// SpatialAudioHrtfDirectivityCone /// /// /// /// /// /// The SpatialAudioHrtfDirectivity structure represents an omnidirectional model that can be linearly interpolated with a cardioid /// or cone model. /// /// /// If SetDirectivity is not called, the default type of SpatialAudioHrtfDirectivity_OmniDirectional is used with no interpolation. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectforhrtf-setdirectivity // HRESULT SetDirectivity( SpatialAudioHrtfDirectivityUnion *directivity ); void SetDirectivity(in SpatialAudioHrtfDirectivityUnion directivity); } /// /// /// Provides methods for controlling an Hrtf spatial audio object render stream, including starting, stopping, and resetting the stream. /// Also provides methods for activating new ISpatialAudioObjectForHrtf instances and notifying the system when you are beginning and /// ending the process of updating activated spatial audio objects and data. /// /// /// This interface is a part of Windows Sonic, Microsoft’s audio platform for more immersive audio which includes integrated spatial /// sound on Xbox and Windows. /// /// /// /// Note Many of the methods provided by this interface are implemented in the inherited ISpatialAudioObjectRenderStreamBase interface. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nn-spatialaudiohrtf-ispatialaudioobjectrenderstreamforhrtf [ComImport, Guid("E08DEEF9-5363-406E-9FDC-080EE247BBE0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ISpatialAudioObjectRenderStreamForHrtf : ISpatialAudioObjectRenderStreamBase { /// Gets the number of dynamic spatial audio objects that are currently available. /// The number of dynamic spatial audio objects that are currently available. /// /// /// A dynamic ISpatialAudioObject is one that was activated by setting the type parameter to the ActivateSpatialAudioObject method to /// AudioObjectType_Dynamic. The system has a limit of the maximum number of dynamic spatial audio objects that can be /// activated at one time. Call Release on an ISpatialAudioObject when it is no longer being used to free up the resource to /// create new dynamic spatial audio objects. /// /// /// You should not call this method after streaming has started, as the value is already provided by /// ISpatialAudioObjectRenderStreamBase::BeginUpdatingAudioObjects. This method should only be called before streaming has started, /// which occurs after ISpatialAudioObjectRenderStreamBase::Start is called. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-getavailabledynamicobjectcount // HRESULT GetAvailableDynamicObjectCount( UINT32 *value ); new uint GetAvailableDynamicObjectCount(); /// Gets additional services from the ISpatialAudioObjectRenderStream. /// /// The interface ID for the requested service. The client should set this parameter to one of the following REFIID values: /// IID_IAudioClock /// IID_IAudioClock2 /// IID_IAudioStreamVolume /// /// /// Pointer to a pointer variable into which the method writes the address of an instance of the requested interface. Through this /// method, the caller obtains a counted reference to the interface. The caller is responsible for releasing the interface, when it /// is no longer needed, by calling the interface's Release method. If the GetService call fails, *ppv is NULL. /// /// /// /// If the method succeeds, it returns S_OK. If it fails, possible return codes include, but are not limited to, the values shown in /// the following table. /// /// /// /// Return code /// Description /// /// /// E_POINTER /// Parameter ppv is NULL. /// /// /// SPTLAUDCLNT_E_DESTROYED /// The ISpatialAudioClient associated with the spatial audio stream has been destroyed. /// /// /// AUDCLNT_E_DEVICE_INVALIDATED /// /// The audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, /// disabled, removed, or otherwise made unavailable for use. /// /// /// /// SPTLAUDCLNT_E_INTERNAL /// An internal error has occurred. /// /// /// AUDCLNT_E_UNSUPPORTED_FORMAT /// The media associated with the spatial audio stream uses an unsupported format. /// /// /// /// /// The GetService method supports the following service interfaces: /// /// /// IAudioClock /// /// /// IAudioClock2 /// /// /// IAudioStreamVolume /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-getservice // HRESULT GetService( REFIID riid, void **service ); [PreserveSig] new HRESULT GetService(in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] out object service); /// Starts the spatial audio stream. /// /// /// Starting the stream causes data flow between the endpoint buffer and the audio engine. The first time this method is called, the /// stream's audio clock position will be at 0. Otherwise, the clock resumes from its position at the time that the stream was last /// paused with a call to Stop. Call Reset to reset the clock position to 0 and cause all active ISpatialAudioObject instances to be revoked. /// /// The stream must have been previously stopped with a call to Stop or the method will fail and return SPTLAUDCLNT_E_STREAM_NOT_STOPPED. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-start // HRESULT Start(); new void Start(); /// Stops a running audio stream. /// /// Stopping stream causes data to stop flowing between the endpoint buffer and the audio engine. You can consider this operation to /// pause the stream because it leaves the stream's audio clock at its current stream position and does not reset it to 0. A /// subsequent call to Start causes the stream to resume running from the current position. Call Reset to reset the clock position to /// 0 and cause all active ISpatialAudioObject instances to be revoked. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-stop // HRESULT Stop(); new void Stop(); /// Reset a stopped audio stream. /// /// /// Resetting the audio stream flushes all pending data and resets the audio clock stream position to 0. Resetting the stream also /// causes all active ISpatialAudioObject instances to be revoked. A subsequent call to Start causes the stream to start from 0 position. /// /// The stream must have been previously stopped with a call to Stop or the method will fail and return SPTLAUDCLNT_E_STREAM_NOT_STOPPED. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-reset // HRESULT Reset(); new void Reset(); /// /// Puts the system into the state where audio object data can be submitted for processing and the ISpatialAudioObject state can be modified. /// /// /// The number of dynamic audio objects that are available to be rendered for the current processing pass. All allocated static audio /// objects can be rendered in every pass. For information on audio object types, see AudioObjectType. /// /// The size, in audio frames, of the buffer returned by GetBuffer. /// /// /// This method must be called each time the event passed in the SpatialAudioObjectRenderStreamActivationParams to /// ISpatialAudioClient::ActivateSpatialAudioStream is signaled, even if there no audio object data to submit. /// /// /// For each BeginUpdatingAudioObjects call, there should be a corresponding call to EndUpdatingAudioObjects call. If /// BeginUpdatingAudioObjects is called twice without a call EndUpdatingAudioObjects between them, the second call to /// BeginUpdatingAudioObjects will return SPTLAUDCLNT_E_OUT_OF_ORDER. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-beginupdatingaudioobjects // HRESULT BeginUpdatingAudioObjects( UINT32 *availableDynamicObjectCount, UINT32 *frameCountPerBuffer ); new void BeginUpdatingAudioObjects(out uint availableDynamicObjectCount, out uint frameCountPerBuffer); /// Notifies the system that the app has finished supplying audio data for the spatial audio objects activated with ActivateSpatialAudioObject. /// The pointers retrieved with ISpatialAudioObjectBase::GetBuffer can no longer be used after this method is called. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudioclient/nf-spatialaudioclient-ispatialaudioobjectrenderstreambase-endupdatingaudioobjects // HRESULT EndUpdatingAudioObjects(); new void EndUpdatingAudioObjects(); /// Activates an ISpatialAudioObjectForHrtf for audio rendering. /// /// The type of audio object to activate. For dynamic audio objects, this value must be AudioObjectType_Dynamic. For static /// audio objects, specify one of the static audio channel values from the enumeration. Specifying AudioObjectType_None will /// produce an audio object that is not spatialized. /// /// Receives a pointer to the activated interface. /// /// A dynamic ISpatialAudioObjectForHrtf is one that was activated by setting the type parameter to the /// ActivateSpatialAudioObjectForHrtf method to AudioObjectType_Dynamic. The client has a limit of the maximum number /// of dynamic spatial audio objects that can be activated at one time. After the limit has been reached, attempting to activate /// additional audio objects will result in this method returning an SPTLAUDCLNT_E_NO_MORE_OBJECTS error. To avoid this, call Release /// on each dynamic ISpatialAudioObjectForHrtf after it is no longer being used to free up the resource so that it can be /// reallocated. See ISpatialAudioObjectgBase::IsActive and ISpatialAudioObjectgBase::SetEndOfStream for more information on the /// managing the lifetime of spatial audio objects. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/nf-spatialaudiohrtf-ispatialaudioobjectrenderstreamforhrtf-activatespatialaudioobjectforhrtf // HRESULT ActivateSpatialAudioObjectForHrtf( AudioObjectType type, ISpatialAudioObjectForHrtf **audioObject ); ISpatialAudioObjectForHrtf ActivateSpatialAudioObjectForHrtf([In] AudioObjectType type); } /// Specifies the activation parameters for an ISpatialAudioRenderStreamForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfactivationparams typedef // struct SpatialAudioHrtfActivationParams { const WAVEFORMATEX *ObjectFormat; AudioObjectType StaticObjectTypeMask; UINT32 // MinDynamicObjectCount; UINT32 MaxDynamicObjectCount; AUDIO_STREAM_CATEGORY Category; HANDLE EventHandle; // ISpatialAudioObjectRenderStreamNotify *NotifyObject; SpatialAudioHrtfDistanceDecay *DistanceDecay; SpatialAudioHrtfDirectivityUnion // *Directivity; SpatialAudioHrtfEnvironmentType *Environment; SpatialAudioHrtfOrientation // *Orientation; } SpatialAudioHrtfActivationParams; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "6A549BFB-993A-4A20-AFAB-B38D03EAE35C")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfActivationParams { /// /// Format descriptor for spatial audio objects associated with the stream. All objects must have the same format and must be of type /// WAVEFORMATEX or WAVEFORMATEXTENSIBLE. /// public IntPtr /*WAVEFORMATEX*/ ObjectFormat; /// /// A bitwise combination of AudioObjectType values indicating the set of static spatial audio channels that will be allowed /// by the activated stream. /// public AudioObjectType StaticObjectTypeMask; /// /// The minimum number of concurrent dynamic objects. If this number of dynamic audio objects can't be activated simultaneously, no /// dynamic audio objects will be activated. /// public uint MinDynamicObjectCount; /// The maximum number of concurrent dynamic objects that can be activated with ISpatialAudioRenderStreamForHrtf. public uint MaxDynamicObjectCount; /// The category of the audio stream and its spatial audio objects. public AUDIO_STREAM_CATEGORY Category; /// /// The event that will signal the client to provide more audio data. This handle will be duplicated internally before it is used. /// public HEVENT EventHandle; /// /// The object that provides notifications for spatial audio clients to respond to changes in the state of an /// ISpatialAudioRenderStreamForHrtf. This object is used to notify clients that the number of dynamic spatial audio objects that can /// be activated concurrently is about to change. /// [MarshalAs(UnmanagedType.Interface)] public ISpatialAudioObjectRenderStreamNotify NotifyObject; /// /// Optional default value for the decay model used for ISpatialAudioObjectForHrtf objects associated with the stream. nullptr /// if unused. /// public IntPtr /*SpatialAudioHrtfDistanceDecay*/ DistanceDecay; /// /// Optional default value for the spatial audio directivity model used for ISpatialAudioObjectForHrtf objects associated with the /// stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfDirectivityUnion*/ Directivity; /// /// Optional default value for the type of environment that is simulated when audio is processed for ISpatialAudioObjectForHrtf /// objects associated with the stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfEnvironmentType*/ Environment; /// /// Optional default value for the orientation of ISpatialAudioObjectForHrtf objects associated with the stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfOrientation*/ Orientation; } /// /// Represents activation parameters for a spatial audio render stream, extending SpatialAudioHrtfActivationParams (spatialaudiohrtf.h) /// with the ability to specify stream options. /// /// The following example demostrates activating a spatial audio render stream for HRTF with stream options. // https://learn.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfactivationparams2 typedef // struct SpatialAudioHrtfActivationParams2 { const WAVEFORMATEX *ObjectFormat; AudioObjectType StaticObjectTypeMask; UINT32 // MinDynamicObjectCount; UINT32 MaxDynamicObjectCount; AUDIO_STREAM_CATEGORY Category; HANDLE EventHandle; // ISpatialAudioObjectRenderStreamNotify *NotifyObject; SpatialAudioHrtfDistanceDecay *DistanceDecay; SpatialAudioHrtfDirectivityUnion // *Directivity; SpatialAudioHrtfEnvironmentType *Environment; SpatialAudioHrtfOrientation *Orientation; SPATIAL_AUDIO_STREAM_OPTIONS // Options; } SpatialAudioHrtfActivationParams2; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "NS:spatialaudiohrtf.SpatialAudioHrtfActivationParams2")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfActivationParams2 { /// /// Format descriptor for spatial audio objects associated with the stream. All objects must have the same format and must be of type /// WAVEFORMATEX or WAVEFORMATEXTENSIBLE. /// public IntPtr /*WAVEFORMATEX*/ ObjectFormat; /// /// A bitwise combination of AudioObjectType values indicating the set of static spatial audio channels that will be allowed /// by the activated stream. /// public AudioObjectType StaticObjectTypeMask; /// /// The minimum number of concurrent dynamic objects. If this number of dynamic audio objects can't be activated simultaneously, no /// dynamic audio objects will be activated. /// public uint MinDynamicObjectCount; /// The maximum number of concurrent dynamic objects that can be activated with ISpatialAudioRenderStreamForHrtf. public uint MaxDynamicObjectCount; /// The category of the audio stream and its spatial audio objects. public AUDIO_STREAM_CATEGORY Category; /// /// The event that will signal the client to provide more audio data. This handle will be duplicated internally before it is used. /// public HEVENT EventHandle; /// /// The object that provides notifications for spatial audio clients to respond to changes in the state of an /// ISpatialAudioRenderStreamForHrtf. This object is used to notify clients that the number of dynamic spatial audio objects that can /// be activated concurrently is about to change. /// [MarshalAs(UnmanagedType.Interface)] public ISpatialAudioObjectRenderStreamNotify NotifyObject; /// /// Optional default value for the decay model used for ISpatialAudioObjectForHrtf objects associated with the stream. nullptr /// if unused. /// public IntPtr /*SpatialAudioHrtfDistanceDecay*/ DistanceDecay; /// /// Optional default value for the spatial audio directivity model used for ISpatialAudioObjectForHrtf objects associated with the /// stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfDirectivityUnion*/ Directivity; /// /// Optional default value for the type of environment that is simulated when audio is processed for ISpatialAudioObjectForHrtf /// objects associated with the stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfEnvironmentType*/ Environment; /// /// Optional default value for the orientation of ISpatialAudioObjectForHrtf objects associated with the stream. nullptr if unused. /// public IntPtr /*SpatialAudioHrtfOrientation*/ Orientation; /// A member of the SPATIAL_AUDIO_STREAM_OPTIONS emumeration, specifying options for the activated audio stream. public SPATIAL_AUDIO_STREAM_OPTIONS Options; } /// /// Represents an omnidirectional model for an ISpatialAudioObjectForHrtf. The omnidirectional emission is interpolated linearly with the /// directivity model specified in the Type field based on the value of the Scaling field. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfdirectivity typedef struct // SpatialAudioHrtfDirectivity { SpatialAudioHrtfDirectivityType Type; float Scaling; } SpatialAudioHrtfDirectivity; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "A3D149E0-F2C1-47C7-8858-35C5F51C7F75")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfDirectivity { /// The type of shape in which sound is emitted by an ISpatialAudioObjectForHrtf. public SpatialAudioHrtfDirectivityType Type; /// /// The amount of linear interpolation applied between omnidirectional sound and the directivity specified in the Type field. /// This is a normalized value between 0 and 1.0 where 0 is omnidirectional and 1.0 is full directivity using the specified type. /// public float Scaling; } /// Represents a cardioid-shaped directivity model for an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfdirectivitycardioid typedef // struct SpatialAudioHrtfDirectivityCardioid { SpatialAudioHrtfDirectivity directivity; float Order; } SpatialAudioHrtfDirectivityCardioid; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "71E2E152-14DC-472B-B582-82D4412EAA85")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfDirectivityCardioid { /// A structure that expresses the direction in which sound is emitted by an ISpatialAudioObjectForHrtf. public SpatialAudioHrtfDirectivity directivity; /// The order of the cardioid. public float Order; } /// Represents a cone-shaped directivity model for an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfdirectivitycone typedef struct // SpatialAudioHrtfDirectivityCone { SpatialAudioHrtfDirectivity directivity; float InnerAngle; float OuterAngle; } SpatialAudioHrtfDirectivityCone; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "C34F26C2-4979-4C06-8EAC-64547745238F")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfDirectivityCone { /// A structure that expresses the direction in which sound is emitted by an ISpatialAudioObjectForHrtf. public SpatialAudioHrtfDirectivity directivity; /// The inner angle of the cone. public float InnerAngle; /// The outer angle of the cone. public float OuterAngle; } /// Defines a spatial audio directivity model for an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfdirectivityunion typedef union // SpatialAudioHrtfDirectivityUnion { SpatialAudioHrtfDirectivityCone Cone; SpatialAudioHrtfDirectivityCardioid Cardiod; // SpatialAudioHrtfDirectivity Omni; } SpatialAudioHrtfDirectivityUnion; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "BBBE4B0B-59C2-44E0-9BB4-B10CE5CE12E3")] [StructLayout(LayoutKind.Explicit)] public struct SpatialAudioHrtfDirectivityUnion { /// A cone-shaped directivity model [FieldOffset(0)] public SpatialAudioHrtfDirectivityCone Cone; /// [FieldOffset(0)] public SpatialAudioHrtfDirectivityCardioid Cardiod; /// An omni-direction directivity model that can be interpolated linearly with one of the other directivity models. [FieldOffset(0)] public SpatialAudioHrtfDirectivity Omni; } /// /// Represents the decay model that is applied over distance from the position of an ISpatialAudioObjectForHrtf to the position of the listener. /// // https://docs.microsoft.com/en-us/windows/win32/api/spatialaudiohrtf/ns-spatialaudiohrtf-spatialaudiohrtfdistancedecay typedef struct // SpatialAudioHrtfDistanceDecay { SpatialAudioHrtfDistanceDecayType Type; float MaxGain; float MinGain; float UnityGainDistance; float // CutoffDistance; } SpatialAudioHrtfDistanceDecay; [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "2EBAE322-2A5F-4610-B64F-F1B8CE2DFD2D")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfDistanceDecay { /// The type of decay, natural or custom. The default value for this field is SpatialAudioHrtfDistanceDecay_NaturalDecay. public SpatialAudioHrtfDistanceDecayType Type; /// public float MaxGain; /// public float MinGain; /// public float UnityGainDistance; /// public float CutoffDistance; } /// Represents the orientation of an ISpatialAudioObjectForHrtf. // https://docs.microsoft.com/en-us/windows/win32/coreaudio/spatialaudiohrtforientation [PInvokeData("spatialaudiohrtf.h", MSDNShortId = "BDC1C409-F461-4903-A411-3F0647C59DBA")] [StructLayout(LayoutKind.Sequential)] public struct SpatialAudioHrtfOrientation { /// A row-major 3x3 rotation matrix. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] public float[] Orientation; } }