diff options
| author | Vincent Billet <billet.vincent@free.fr> | 2025-05-26 21:17:44 +0200 |
|---|---|---|
| committer | Vincent Billet <billet.vincent@free.fr> | 2025-05-26 21:17:44 +0200 |
| commit | b775b4a1f180a4d4f17ba9529f628ca5ebd65f87 (patch) | |
| tree | 165bdd0058c153563e026a6392c90bd1eae15a89 /vendor | |
| parent | ee132b39d414714f22809f38a4bb536e3e0d181f (diff) | |
Create() rework; comments tweaks; +hrtfapoapi
Diffstat (limited to 'vendor')
| -rw-r--r-- | vendor/windows/XAudio2/hrtfapoapi.odin | 149 | ||||
| -rw-r--r-- | vendor/windows/XAudio2/x3daudio.odin | 121 | ||||
| -rw-r--r-- | vendor/windows/XAudio2/xapo.odin | 167 | ||||
| -rw-r--r-- | vendor/windows/XAudio2/xapofx.odin | 4 | ||||
| -rw-r--r-- | vendor/windows/XAudio2/xaudio2.odin | 92 | ||||
| -rw-r--r-- | vendor/windows/XAudio2/xaudio2fx.odin | 15 |
6 files changed, 307 insertions, 241 deletions
diff --git a/vendor/windows/XAudio2/hrtfapoapi.odin b/vendor/windows/XAudio2/hrtfapoapi.odin new file mode 100644 index 000000000..45f1cdb42 --- /dev/null +++ b/vendor/windows/XAudio2/hrtfapoapi.odin @@ -0,0 +1,149 @@ +#+build windows + +package windows_xaudio2 + +import win "core:sys/windows" + +foreign import hrtf "system:hrtfapo.lib" + +HRTF_MAX_GAIN_LIMIT :: 12.0 +HRTF_MIN_GAIN_LIMIT :: -96.0 +HRTF_MIN_UNITY_GAIN_DISTANCE :: 0.05 +HRTF_DEFAULT_UNITY_GAIN_DISTANCE :: 1.0 +HRTF_DEFAULT_CUTOFF_DISTANCE :: 3.402823466e+38 + +//! Represents a position in 3D space, using a right-handed coordinate system. +HrtfPosition :: struct { + x: f32, + y: f32, + z: f32, +} + +//! Indicates the orientation of an HRTF directivity object. This is a row-major 3x3 rotation matrix. +HrtfOrientation :: struct { + element: [9]f32, +} + +//! Indicates one of several stock directivity patterns. +HrtfDirectivityType :: enum i32 { + //! The sound emission is in all directions. + OmniDirectional = 0, + //! The sound emission is a cardiod shape. + Cardioid, + //! The sound emission is a cone. + Cone, +} + +//! Indicates one of several stock environment types. +HrtfEnvironment :: enum i32 { + //! A small room. + Small = 0, + //! A medium-sized room. + Medium, + //! A large enclosed space. + Large, + //! An outdoor space. + Outdoors, +} + +//! Base directivity pattern descriptor. Describes the type of directivity applied to a sound. +//! The scaling parameter is used to interpolate between directivity behavior and omnidirectional, it determines how much attenuation is applied to the source outside of the directivity pattern and controls how directional the source is. +HrtfDirectivity :: struct { + //! Indicates the type of directivity. + type: HrtfDirectivityType, + //! A normalized value between zero and one. Specifies the amount of linear interpolation between omnidirectional sound and the full directivity pattern, where 0 is fully omnidirectional and 1 is fully directional. + scaling: f32, +} + +//! Describes a cardioid directivity pattern. +HrtfDirectivityCardioid :: struct { + //! Descriptor for the cardioid pattern. The type parameter must be set to HrtfDirectivityType.Cardioid. + directivity: HrtfDirectivity, + //! Order controls the shape of the cardioid. The higher order the shape, the narrower it is. Must be greater than 0 and less than or equal to 32. + order: f32, +} + +//! Describes a cone directivity. +//! Attenuation is 0 inside the inner cone. +//! Attenuation is linearly interpolated between the inner cone, which is defined by innerAngle, and the outer cone, which is defined by outerAngle. +HrtfDirectivityCone :: struct { + //! Descriptor for the cone pattern. The type parameter must be set to HrtfDirectivityType.Cone. + directivity: HrtfDirectivity, + //! Angle, in radians, that defines the inner cone. Must be between 0 and TAU. + innerAngle: f32, + //! Angle, in radians, that defines the outer cone. Must be between 0 and TAU. + outerAngle: f32, +} + +//! Indicates a distance-based decay type applied to a sound. +HrtfDistanceDecayType :: enum i32 { + //! Simulates natural decay with distance, as constrained by minimum and maximum gain distance limits. Drops to silence at rolloff distance. + NaturalDecay = 0, + //! Used to set up a custom gain curve, within the maximum and minimum gain limit. + CustomDecay, +} + +//! Describes a distance-based decay behavior. +HrtfDistanceDecay :: struct { + //! The type of decay behavior, natural or custom. + type: HrtfDistanceDecayType, + //! The maximum gain limit applied at any distance. Applies to both natural and custom decay. This value is specified in dB, with a range from -96 to 12 inclusive. The default value is 12 dB. + maxGain: f32, + //! The minimum gain limit applied at any distance. Applies to both natural and custom decay. This value is specified in dB, with a range from -96 to 12 inclusive. The default value is -96 dB. + minGain: f32, + //! The distance at which the gain is 0dB. Applies to natural decay only. This value is specified in meters, with a range from 0.05 to infinity (max(f32)). The default value is 1 meter. + unityGainDistance: f32, + //! The distance at which output is silent. Applies to natural decay only. This value is specified in meters, with a range from zero (non-inclusive) to infinity (max(f32)). The default value is infinity. + cutoffDistance: f32, +} + +//! Specifies parameters used to initialize HRTF. +//! Instances of the XAPO interface are created by using the CreateHrtfApo() API: +//! ```CreateHrtfApo :: proc(pInit: HrtfApoInit, ppXapo: ^^IXAPO) -> HRESULT``` +HrtfApoInit :: struct { + //! The decay type. If you pass in nil, the default value will be used. The default is natural decay. + distanceDecay: ^HrtfDistanceDecay, + //! The directivity type. If you pass in nil, the default value will be used. The default directivity is omni-directional. + directivity: ^HrtfDirectivity, +} + +//! Creates an instance of the XAPO object. +//! Format requirements: +//! * Input: mono, 48 kHz, 32-bit float PCM. +//! * Output: stereo, 48 kHz, 32-bit float PCM. +//! Audio is processed in blocks of 1024 samples. +//! Returns: +//! S_OK for success, any other value indicates failure. +//! Returns E_NOTIMPL on unsupported platforms. +@(default_calling_convention="system") +foreign hrtf { + CreateHrtfApo :: proc( + //! Pointer to an HrtfApoInit struct. Specifies parameters for XAPO interface initialization. + #by_ptr init: HrtfApoInit, + //! Returns the new instance of the XAPO interface. + xApo: ^^IXAPO, + ) -> HRESULT --- +} + +//! The interface used to set parameters that control how HRTF is applied to a sound. +IXAPOHrtfParameters_UUID_STRING :: "15B3CD66-E9DE-4464-B6E6-2BC3CF63D455" +IXAPOHrtfParameters_UUID := &win.IID{0x15B3CD66, 0xE9DE, 0x4464, {0xB6, 0xE6, 0x2B, 0xC3, 0xCF, 0x63, 0xD4, 0x55}} +IXAPOHrtfParameters :: struct #raw_union { + #subtype iunknown: IUnknown, + using ixapohrtfparameters_vtable: ^IXAPOHrtfParameters_VTable, +} +IXAPOHrtfParameters_VTable :: struct { + using iunknown_vtable: IUnknown_VTable, + + // HRTF params + //! The position of the sound relative to the listener. + SetSourcePosition: proc "system" (this: ^IXAPOHrtfParameters, position: ^HrtfPosition) -> HRESULT, + //! The rotation matrix for the source orientation, with respect to the listener's frame of reference (the listener's coordinate system). + SetSourceOrientation: proc "system" (this: ^IXAPOHrtfParameters, orientation: ^HrtfOrientation) -> HRESULT, + //! The custom direct path gain value for the current source position. Valid only for sounds played with the HrtfDistanceDecayType. Custom decay type. + SetSourceGain: proc "system" (this: ^IXAPOHrtfParameters, gain: f32) -> HRESULT, + + // Distance cue params + //! Selects the acoustic environment to simulate. + SetEnvironment: proc "system" (this: ^IXAPOHrtfParameters, environment: HrtfEnvironment) -> HRESULT, +} diff --git a/vendor/windows/XAudio2/x3daudio.odin b/vendor/windows/XAudio2/x3daudio.odin index 27c4dc9fa..c24e627e2 100644 --- a/vendor/windows/XAudio2/x3daudio.odin +++ b/vendor/windows/XAudio2/x3daudio.odin @@ -1,7 +1,7 @@ #+build windows /* NOTES: - 1. Definition of terms: + 1. Definition of terms: LFE: Low Frequency Effect -- always omnidirectional. LPF: Low Pass Filter, divided into two classifications: Direct -- Applied to the direct signal path, @@ -9,15 +9,15 @@ Reverb -- Applied to the reverb signal path, used for occlusion effects only. - 2. Volume level is expressed as a linear amplitude scaler: - 1.0f represents no attenuation applied to the original signal, - 0.5f denotes an attenuation of 6dB, and 0.0f results in silence. - Amplification (volume > 1.0f) is also allowed, and is not clamped. + 2. Volume level is expressed as a linear amplitude scaler: + 1.0 represents no attenuation applied to the original signal, + 0.5 denotes an attenuation of 6dB, and 0.0 results in silence. + Amplification (volume > 1.0) is also allowed, and is not clamped. - LPF values range from 1.0f representing all frequencies pass through, - to 0.0f which results in silence as all frequencies are filtered out. + LPF values range from 1.0 representing all frequencies pass through, + to 0.0 which results in silence as all frequencies are filtered out. - 3. X3DAudio uses a left-handed Cartesian coordinate system with values + 3. X3DAudio uses a left-handed Cartesian coordinate system with values on the x-axis increasing from left to right, on the y-axis from bottom to top, and on the z-axis from near to far. Azimuths are measured clockwise from a given reference direction. @@ -29,7 +29,7 @@ Metric constants are supplied only as a convenience. Distance is calculated using the Euclidean norm formula. - 4. Only real values are permissible with functions using 32-bit + 4. Only real values are permissible with functions using 32-bit float parameters -- NAN and infinite values are not accepted. All computation occurs in 32-bit precision mode. */ @@ -37,34 +37,13 @@ package windows_xaudio2 import "core:math" +import win "core:sys/windows" foreign import xa2 "system:xaudio2.lib" +SPEAKER_FLAGS :: win.SPEAKER_FLAGS + //--------------<D-E-F-I-N-I-T-I-O-N-S>-------------------------------------// -// speaker geometry configuration flags, specifies assignment of channels to speaker positions, defined as per WAVEFORMATEXTENSIBLE.dwChannelMask -SPEAKER_FLAGS :: distinct bit_set[SPEAKER_FLAG; u32] -SPEAKER_FLAG :: enum u32 { - FRONT_LEFT = 0, - FRONT_RIGHT = 1, - FRONT_CENTER = 2, - LOW_FREQUENCY = 3, - BACK_LEFT = 4, - BACK_RIGHT = 5, - FRONT_LEFT_OF_CENTER = 6, - FRONT_RIGHT_OF_CENTER = 7, - BACK_CENTER = 8, - SIDE_LEFT = 9, - SIDE_RIGHT = 10, - TOP_CENTER = 11, - TOP_FRONT_LEFT = 12, - TOP_FRONT_CENTER = 13, - TOP_FRONT_RIGHT = 14, - TOP_BACK_LEFT = 15, - TOP_BACK_CENTER = 16, - TOP_BACK_RIGHT = 17, - //RESERVED = 0x7FFC0000, // bit mask locations reserved for future use - ALL = 31, // used to specify that any possible permutation of speaker configurations -} // standard speaker geometry configurations, used with Initialize SPEAKER_MONO :: SPEAKER_FLAGS{.FRONT_CENTER} @@ -100,7 +79,7 @@ CALCULATE_FLAG :: enum u32 { } //--------------<D-A-T-A---T-Y-P-E-S>---------------------------------------// -VECTOR :: [3]f32 // float 3D vector +VECTOR :: distinct [3]f32 // float 3D vector // instance handle of precalculated constants HANDLE :: distinct [HANDLE_BYTESIZE]byte @@ -108,75 +87,74 @@ HANDLE :: distinct [HANDLE_BYTESIZE]byte // Distance curve point: // Defines a DSP setting at a given normalized distance. DISTANCE_CURVE_POINT :: struct #packed { - Distance: f32, // normalized distance, must be within [0.0f, 1.0f] + Distance: f32, // normalized distance, must be within [0.0, 1.0] DSPSetting: f32, // DSP setting } // Distance curve: // A piecewise curve made up of linear segments used to define DSP behaviour with respect to normalized distance. // -// Note that curve point distances are normalized within [0.0f, 1.0f]. +// Note that curve point distances are normalized within [0.0, 1.0]. // EMITTER.CurveDistanceScaler must be used to scale the normalized distances to user-defined world units. -// For distances beyond CurveDistanceScaler * 1.0f, pPoints[PointCount-1].DSPSetting is used as the DSP setting. +// For distances beyond CurveDistanceScaler * 1.0, pPoints[PointCount-1].DSPSetting is used as the DSP setting. // // All distance curve spans must be such that: // pPoints[k-1].DSPSetting + ((pPoints[k].DSPSetting-pPoints[k-1].DSPSetting) / (pPoints[k].Distance-pPoints[k-1].Distance)) * (pPoints[k].Distance-pPoints[k-1].Distance) != NAN or infinite values // For all points in the distance curve where 1 <= k < PointCount. DISTANCE_CURVE :: struct #packed { - pPoints: [^]DISTANCE_CURVE_POINT `fmt:"v,PointCount"`, // distance curve point array, must have at least PointCount elements with no duplicates and be sorted in ascending order with respect to Distance - PointCount: u32, // number of distance curve points, must be >= 2 as all distance curves must have at least two endpoints, defining DSP settings at 0.0f and 1.0f normalized distance + pPoints: [^]DISTANCE_CURVE_POINT `fmt:"v,PointCount"`, // distance curve point array, must have at least PointCount elements with no duplicates and be sorted in ascending order with respect to Distance + PointCount: u32, // number of distance curve points, must be >= 2 as all distance curves must have at least two endpoints, defining DSP settings at 0.0 and 1.0 normalized distance } Default_LinearCurvePoints := [2]DISTANCE_CURVE_POINT{{0.0, 1.0}, {1.0, 0.0}} Default_LinearCurve := DISTANCE_CURVE{&Default_LinearCurvePoints[0], 2} +// Cone: +// Specifies directionality for a listener or single-channel emitter by modifying DSP behaviour with respect to its front orientation. +// This is modeled using two sound cones: an inner cone and an outer cone. On/within the inner cone, DSP settings are scaled by the inner values. +// On/beyond the outer cone, DSP settings are scaled by the outer values. If on both the cones, DSP settings are scaled by the inner values only. +// Between the two cones, the scaler is linearly interpolated between the inner and outer values. Set both cone angles to 0 or TAU for omnidirectionality using only the outer or inner values respectively. CONE :: struct #packed { - InnerAngle: f32, // inner cone angle in radians, must be within [0.0f, TAU] - OuterAngle: f32, // outer cone angle in radians, must be within [InnerAngle, TAU] - - InnerVolume: f32, // volume level scaler on/within inner cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used - OuterVolume: f32, // volume level scaler on/beyond outer cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used - InnerLPF: f32, // LPF (both direct and reverb paths) coefficient subtrahend on/within inner cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used - OuterLPF: f32, // LPF (both direct and reverb paths) coefficient subtrahend on/beyond outer cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used - InnerReverb: f32, // reverb send level scaler on/within inner cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used - OuterReverb: f32, // reverb send level scaler on/beyond outer cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used + InnerAngle: f32, // inner cone angle in radians, must be within [0.0, TAU] + OuterAngle: f32, // outer cone angle in radians, must be within [InnerAngle, TAU] + + InnerVolume: f32, // volume level scaler on/within inner cone, used only for matrix calculations, must be within [0.0, 2.0] when used + OuterVolume: f32, // volume level scaler on/beyond outer cone, used only for matrix calculations, must be within [0.0, 2.0] when used + InnerLPF: f32, // LPF (both direct and reverb paths) coefficient subtrahend on/within inner cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0, 1.0] when used + OuterLPF: f32, // LPF (both direct and reverb paths) coefficient subtrahend on/beyond outer cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0, 1.0] when used + InnerReverb: f32, // reverb send level scaler on/within inner cone, used only for reverb calculations, must be within [0.0, 2.0] when used + OuterReverb: f32, // reverb send level scaler on/beyond outer cone, used only for reverb calculations, must be within [0.0, 2.0] when used } Default_DirectionalCone := CONE{math.PI / 2, math.PI, 1.0, 0.708, 0.0, 0.25, 0.708, 1.0} // Listener: // Defines a point of 3D audio reception. -// // The cone is directed by the listener's front orientation. LISTENER :: struct #packed { - OrientFront: VECTOR, // orientation of front direction, used only for matrix and delay calculations or listeners with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used - OrientTop: VECTOR, // orientation of top direction, used only for matrix and delay calculations, must be orthonormal with OrientFront when used + OrientFront: VECTOR, // orientation of front direction, used only for matrix and delay calculations or listeners with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used + OrientTop: VECTOR, // orientation of top direction, used only for matrix and delay calculations, must be orthonormal with OrientFront when used - Position: VECTOR, // position in user-defined world units, does not affect Velocity - Velocity: VECTOR, // velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position + Position: VECTOR, // position in user-defined world units, does not affect Velocity + Velocity: VECTOR, // velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position - pCone: ^CONE, // sound cone, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality + pCone: ^CONE, // sound cone, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, nil specifies omnidirectionality } // Emitter: // Defines a 3D audio source, divided into two classifications: -// // Single-point -- For use with single-channel sounds. // Positioned at the emitter base, i.e. the channel radius and azimuth are ignored if the number of channels == 1. -// // May be omnidirectional or directional using a cone. // The cone originates from the emitter base position, and is directed by the emitter's front orientation. -// // Multi-point -- For use with multi-channel sounds. // Each non-LFE channel is positioned using an azimuth along the channel radius with respect to the front orientation vector in the plane orthogonal to the top orientation vector. // An azimuth of TAU specifies a channel is an LFE. Such channels are positioned at the emitter base and are calculated with respect to pLFECurve only, never pVolumeCurve. -// // Multi-point emitters are always omnidirectional, i.e. the cone is ignored if the number of channels > 1. -// // Note that many properties are shared among all channel points, locking certain behaviour with respect to the emitter base position. // For example, doppler shift is always calculated with respect to the emitter base position and so is constant for all its channel points. // Distance curve calculations are also with respect to the emitter base position, with the curves being calculated independently of each other. // For instance, volume and LFE calculations do not affect one another. EMITTER :: struct #packed { - pCone: ^CONE, // sound cone, used only with single-channel emitters for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality + pCone: ^CONE, // sound cone, used only with single-channel emitters for matrix, LPF (both direct and reverb paths), and reverb calculations, nil specifies omnidirectionality OrientFront: VECTOR, // orientation of front direction, used only for emitter angle calculations or with multi-channel emitters for matrix calculations or single-channel emitters with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used OrientTop: VECTOR, // orientation of top direction, used only with multi-channel emitters for matrix calculations, must be orthonormal with OrientFront when used @@ -184,26 +162,25 @@ EMITTER :: struct #packed { Position: VECTOR, // position in user-defined world units, does not affect Velocity Velocity: VECTOR, // velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position - InnerRadius: f32, // inner radius, must be within [0.0f, max(f32)] - InnerRadiusAngle: f32, // inner radius angle, must be within [0.0f, PI/4.0) + InnerRadius: f32, // inner radius, must be within [0.0, max(f32)] + InnerRadiusAngle: f32, // inner radius angle, must be within [0.0, PI/4.0) - ChannelCount: u32, // number of sound channels, must be > 0 - ChannelRadius: f32, // channel radius, used only with multi-channel emitters for matrix calculations, must be >= 0.0f when used - pChannelAzimuths: [^]f32 `fmt:"v,ChannelCount"`, // channel azimuth array, used only with multi-channel emitters for matrix calculations, contains positions of each channel expressed in radians along the channel radius with respect to the front orientation vector in the plane orthogonal to the top orientation vector, or TAU to specify an LFE channel, must have at least ChannelCount elements, all within [0.0f, TAU] when used + ChannelCount: u32, // number of sound channels, must be > 0 + ChannelRadius: f32, // channel radius, used only with multi-channel emitters for matrix calculations, must be >= 0.0 when used + pChannelAzimuths: [^]f32 `fmt:"v,ChannelCount"`, // channel azimuth array, used only with multi-channel emitters for matrix calculations, contains positions of each channel expressed in radians along the channel radius with respect to the front orientation vector in the plane orthogonal to the top orientation vector, or TAU to specify an LFE channel, must have at least ChannelCount elements, all within [0.0, TAU] when used - pVolumeCurve: ^DISTANCE_CURVE, // volume level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation - pLFECurve: ^DISTANCE_CURVE, // LFE level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation - pLPFDirectCurve: ^DISTANCE_CURVE, // LPF direct-path coefficient distance curve, used only for LPF direct-path calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.75f] - pLPFReverbCurve: ^DISTANCE_CURVE, // LPF reverb-path coefficient distance curve, used only for LPF reverb-path calculations, NULL specifies the default curve: [0.0f,0.75f], [1.0f,0.75f] - pReverbCurve: ^DISTANCE_CURVE, // reverb send level distance curve, used only for reverb calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.0f] + pVolumeCurve: ^DISTANCE_CURVE, // volume level distance curve, used only for matrix calculations, nil specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation + pLFECurve: ^DISTANCE_CURVE, // LFE level distance curve, used only for matrix calculations, nil specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation + pLPFDirectCurve: ^DISTANCE_CURVE, // LPF direct-path coefficient distance curve, used only for LPF direct-path calculations, nil specifies the default curve: [0.0,1.0], [1.0,0.75] + pLPFReverbCurve: ^DISTANCE_CURVE, // LPF reverb-path coefficient distance curve, used only for LPF reverb-path calculations, nil specifies the default curve: [0.0,0.75], [1.0,0.75] + pReverbCurve: ^DISTANCE_CURVE, // reverb send level distance curve, used only for reverb calculations, nil specifies the default curve: [0.0,1.0], [1.0,0.0] CurveDistanceScaler: f32, // curve distance scaler, used to scale normalized distance curves to user-defined world units and/or exaggerate their effect, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, must be within [min(f32), max(f32)] when used - DopplerScaler: f32, // doppler shift scaler, used to exaggerate doppler shift effect, used only for doppler calculations, must be within [0.0f, max(f32)] when used + DopplerScaler: f32, // doppler shift scaler, used to exaggerate doppler shift effect, used only for doppler calculations, must be within [0.0, max(f32)] when used } // DSP settings: // Receives results from a call to Calculate to be sent to the low-level audio rendering API for 3D signal processing. -// // The user is responsible for allocating the matrix coefficient table, delay time array, and initializing the channel counts when used. DSP_SETTINGS :: struct #packed { pMatrixCoefficients: [^]f32, // [inout] matrix coefficient table, receives an array representing the volume level used to send from source channel S to destination channel D, stored as pMatrixCoefficients[SrcChannelCount * D + S], must have at least SrcChannelCount*DstChannelCount elements diff --git a/vendor/windows/XAudio2/xapo.odin b/vendor/windows/XAudio2/xapo.odin index 54fb420ca..510eeb514 100644 --- a/vendor/windows/XAudio2/xapo.odin +++ b/vendor/windows/XAudio2/xapo.odin @@ -1,75 +1,45 @@ #+build windows /* NOTES: - 1. Definition of terms: + 1. Definition of terms: DSP: Digital Signal Processing. - CBR: Constant BitRate -- DSP that consumes a constant number of - input samples to produce an output sample. - For example, a 22kHz to 44kHz resampler is CBR DSP. - Even though the number of input to output samples differ, - the ratio between input to output rate remains constant. - All user-defined XAPOs are assumed to be CBR as - XAudio2 only allows CBR DSP to be added to an effect chain. + CBR: Constant BitRate -- DSP that consumes a constant number of input samples to produce an output sample. + For example, a 22kHz to 44kHz resampler is CBR DSP. Even though the number of input to output samples differ, the ratio between input to output rate remains constant. + All user-defined XAPOs are assumed to be CBR as XAudio2 only allows CBR DSP to be added to an effect chain. XAPO: Cross-platform Audio Processing Object -- - a thin wrapper that manages DSP code, allowing it - to be easily plugged into an XAudio2 effect chain. + a thin wrapper that manages DSP code, allowing it to be easily plugged into an XAudio2 effect chain. - Frame: A block of samples, one per channel, - to be played simultaneously. + Frame: A block of samples, one per channel, to be played simultaneously. E.g. a mono stream has one sample per frame. - In-Place: Processing such that the input buffer equals the - output buffer (i.e. input data modified directly). - This form of processing is generally more efficient - than using separate memory for input and output. - However, an XAPO may not perform format conversion - when processing in-place. + In-Place: Processing such that the input buffer equals the output buffer (i.e. input data modified directly). + This form of processing is generally more efficient than using separate memory for input and output. + However, an XAPO may not perform format conversion when processing in-place. - 2. XAPO member variables are divided into three classifications: - Immutable: Set once via IXAPO.Initialize and remain - constant during the lifespan of the XAPO. + 2. XAPO member variables are divided into three classifications: + Immutable: Set once via IXAPO.Initialize and remain constant during the lifespan of the XAPO. Locked: May change before the XAPO is locked via - IXAPO.LockForProcess but remain constant - until IXAPO.UnlockForProcess is called. - - Dynamic: May change from one processing pass to the next, - usually via IXAPOParameters.SetParameters. - XAPOs should assign reasonable defaults to their dynamic - variables during IXAPO.Initialize/LockForProcess so - that calling IXAPOParameters.SetParameters is not - required before processing begins. - - When implementing an XAPO, determine the type of each variable and - initialize them in the appropriate method. Immutable variables are - generally preferable over locked which are preferable over dynamic. - That is, one should strive to minimize XAPO state changes for - best performance, maintainability, and ease of use. - - 3. To minimize glitches, the realtime audio processing thread must - not block. XAPO methods called by the realtime thread are commented - as non-blocking and therefore should not use blocking synchronization, - allocate memory, access the disk, etc. The XAPO interfaces were - designed to allow an effect implementer to move such operations - into other methods called on an application controlled thread. - - 4. Extending functionality is accomplished through the addition of new - COM interfaces. For example, if a new member is added to a parameter - structure, a new interface using the new structure should be added, - leaving the original interface unchanged. - This ensures consistent communication between future versions of - XAudio2 and various versions of XAPOs that may exist in an application. - - 5. All audio data is interleaved in XAudio2. - The default audio format for an effect chain is WAVE_FORMAT_IEEE_FLOAT. + IXAPO.LockForProcess but remain constant until IXAPO.UnlockForProcess is called. + + Dynamic: May change from one processing pass to the next, usually via IXAPOParameters.SetParameters. + XAPOs should assign reasonable defaults to their dynamic variables during IXAPO.Initialize/LockForProcess so that calling IXAPOParameters.SetParameters is not required before processing begins. + + When implementing an XAPO, determine the type of each variable and initialize them in the appropriate method. Immutable variables are generally preferable over locked which are preferable over dynamic. + That is, one should strive to minimize XAPO state changes for best performance, maintainability, and ease of use. - 6. User-defined XAPOs should assume all input and output buffers are - 16-byte aligned. + 3. To minimize glitches, the realtime audio processing thread must not block. XAPO methods called by the realtime thread are commented as non-blocking and therefore should not use blocking synchronization, allocate memory, access the disk, etc. + The XAPO interfaces were designed to allow an effect implementer to move such operations into other methods called on an application controlled thread. + + 4. Extending functionality is accomplished through the addition of new COM interfaces. For example, if a new member is added to a parameter structure, a new interface using the new structure should be added, leaving the original interface unchanged. + This ensures consistent communication between future versions of XAudio2 and various versions of XAPOs that may exist in an application. + + 5. All audio data is interleaved in XAudio2. + The default audio format for an effect chain is WAVE_FORMAT_IEEE_FLOAT. - 7. See XAPOBase.odin for an XAPO base class which provides a default - implementation for most of the interface methods defined below. */ + 6. User-defined XAPOs should assume all input and output buffers are 16-byte aligned. */ package windows_xaudio2 @@ -77,8 +47,7 @@ import win "core:sys/windows" //--------------<D-E-F-I-N-I-T-I-O-N-S>-------------------------------------// -// XAPO error codes -FORMAT_UNSUPPORTED := win.MAKE_HRESULT(win.SEVERITY.ERROR, 0x897, 0x01) // requested audio format unsupported +FORMAT_UNSUPPORTED := win.MAKE_HRESULT(win.SEVERITY.ERROR, win.FACILITY.XAPO, 0x01) // requested audio format unsupported // supported number of channels (samples per frame) range XAPO_MIN_CHANNELS :: 1 @@ -111,11 +80,11 @@ XAPO_FLAG :: enum u32 { // XAPO must be run in-place. Use this flag only if your DSP implementation cannot process separate input and output buffers. // If set, the following flags must also be set: - // XAPO_FLAG_CHANNELS_MUST_MATCH - // XAPO_FLAG_FRAMERATE_MUST_MATCH - // XAPO_FLAG_BITSPERSAMPLE_MUST_MATCH - // XAPO_FLAG_BUFFERCOUNT_MUST_MATCH - // XAPO_FLAG_INPLACE_SUPPORTED + // CHANNELS_MUST_MATCH + // FRAMERATE_MUST_MATCH + // BITSPERSAMPLE_MUST_MATCH + // BUFFERCOUNT_MUST_MATCH + // INPLACE_SUPPORTED // Multiple input and output buffers may be used with in-place XAPOs, though the input buffer count must equal the output buffer count. // When multiple input/output buffers are used, the XAPO may assume input buffer [N] equals output buffer [N] for in-place processing. INPLACE_REQUIRED = 5, @@ -139,18 +108,18 @@ XAPO_REGISTRATION_PROPERTIES :: struct #packed { Flags: XAPO_FLAGS, // XAPO property flags, describes supported input/output configuration MinInputBufferCount: u32, // minimum number of input buffers required for processing, can be 0 MaxInputBufferCount: u32, // maximum number of input buffers supported for processing, must be >= MinInputBufferCount - MinOutputBufferCount: u32, // minimum number of output buffers required for processing, can be 0, must match MinInputBufferCount when XAPO_FLAG_BUFFERCOUNT_MUST_MATCH used - MaxOutputBufferCount: u32, // maximum number of output buffers supported for processing, must be >= MinOutputBufferCount, must match MaxInputBufferCount when XAPO_FLAG_BUFFERCOUNT_MUST_MATCH used + MinOutputBufferCount: u32, // minimum number of output buffers required for processing, can be 0, must match MinInputBufferCount when XAPO_FLAG.BUFFERCOUNT_MUST_MATCH used + MaxOutputBufferCount: u32, // maximum number of output buffers supported for processing, must be >= MinOutputBufferCount, must match MaxInputBufferCount when XAPO_FLAG.BUFFERCOUNT_MUST_MATCH used } // LockForProcess buffer parameters: // Defines buffer parameters that remain constant while an XAPO is locked. -// Used with IXAPO::LockForProcess. +// Used with IXAPO.LockForProcess. // For CBR XAPOs, MaxFrameCount is the only number of frames -// IXAPO::Process would have to handle for the respective buffer. +// IXAPO.Process would have to handle for the respective buffer. XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS :: struct #packed { pFormat: ^WAVEFORMATEX, // buffer audio format - MaxFrameCount: u32, // maximum number of frames in respective buffer that IXAPO::Process would have to handle, irrespective of dynamic variable settings, can be 0 + MaxFrameCount: u32, // maximum number of frames in respective buffer that IXAPO.Process would have to handle, irrespective of dynamic variable settings, can be 0 } // Buffer flags: @@ -161,31 +130,25 @@ XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS :: struct #packed { // If silent, the XAPO may simply set the flag on the output buffer to silent and return, optimizing out the work of processing silent data: XAPOs that generate silence for any reason may set the buffer's flag accordingly rather than writing out silent frames to the buffer itself. // The flags represent what should be assumed is in the respective buffer. The flags may not reflect what is actually stored in memory. XAPO_BUFFER_FLAGS :: enum i32 { - XAPO_BUFFER_SILENT, // silent data should be assumed, respective memory may be uninitialized - XAPO_BUFFER_VALID, // arbitrary data should be assumed (may or may not be silent frames), respective memory initialized + SILENT, // silent data should be assumed, respective memory may be uninitialized + VALID, // arbitrary data should be assumed (may or may not be silent frames), respective memory initialized } // Process buffer parameters: -// Defines buffer parameters that may change from one -// processing pass to the next. Used with IXAPO::Process. -// +// Defines buffer parameters that may change from one processing pass to the next. Used with IXAPO.Process. // Note the byte size of the respective buffer must be at least: -// XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount * XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.pFormat->nBlockAlign -// -// Although the audio format and maximum size of the respective -// buffer is locked (defined by XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS), -// the actual memory address of the buffer given is permitted to change -// from one processing pass to the next. -// -// For CBR XAPOs, ValidFrameCount is constant while locked and equals -// the respective XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount. +// XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount * XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.pFormat.nBlockAlign +// Although the audio format and maximum size of the respective buffer is locked (defined by XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS), the actual memory address of the buffer given is permitted to change from one processing pass to the next. +// For CBR XAPOs, ValidFrameCount is constant while locked and equals the respective XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount. XAPO_PROCESS_BUFFER_PARAMETERS :: struct #packed { - pBuffer: rawptr, // audio data buffer, must be non-NULL + pBuffer: rawptr, // audio data buffer, must be non-nil BufferFlags: XAPO_BUFFER_FLAGS, // describes assumed content of pBuffer, does not affect ValidFrameCount ValidFrameCount: u32, // number of frames of valid data, must be within respective [0, XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount], always XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS.MaxFrameCount for CBR/user-defined XAPOs, does not affect BufferFlags } -XAPOFree :: win.CoTaskMemFree +// Used by IXAPO methods that must allocate arbitrary sized structures such as WAVEFORMATEX that are subsequently returned to the application. +XAPOAlloc :: win.CoTaskMemAlloc +XAPOFree :: win.CoTaskMemFree IXAPO_UUID_STRING :: "A410B984-9839-4819-A0BE-2856AE6B3ADB" IXAPO_UUID := &win.IID{0xA410B984, 0x9839, 0x4819, {0xA0, 0xBE, 0x28, 0x56, 0xAE, 0x6B, 0x3A, 0xDB}} @@ -214,11 +177,11 @@ IXAPO_VTable :: struct { // PARAMETERS: // pOutputFormat - [in] output format known to be supported // pRequestedInputFormat - [in] input format to examine - // ppSupportedInputFormat - [out] receives pointer to nearest input format supported if not NULL and input/output configuration unsupported, use XAPOFree to free structure, left untouched on any failure except XAPO_E_FORMAT_UNSUPPORTED + // ppSupportedInputFormat - [out] receives pointer to nearest input format supported if not nil and input/output configuration unsupported, use XAPOFree to free structure, left untouched on any failure except FORMAT_UNSUPPORTED // RETURN VALUE: // COM error code, including: // S_OK - input/output configuration supported, ppSupportedInputFormat left untouched - // FORMAT_UNSUPPORTED - input/output configuration unsupported, ppSupportedInputFormat receives pointer to nearest input format supported if not NULL + // FORMAT_UNSUPPORTED - input/output configuration unsupported, ppSupportedInputFormat receives pointer to nearest input format supported if not nil // E_INVALIDARG - either audio format invalid, ppSupportedInputFormat left untouched IsInputFormatSupported: proc "system" (this: ^IXAPO, pOutputFormat: ^WAVEFORMATEX, pRequestedInputFormat: ^WAVEFORMATEX, ppSupportedInputFormat: ^^WAVEFORMATEX) -> HRESULT, @@ -232,11 +195,11 @@ IXAPO_VTable :: struct { // PARAMETERS: // pInputFormat - [in] input format known to be supported // pRequestedOutputFormat - [in] output format to examine - // ppSupportedOutputFormat - [out] receives pointer to nearest output format supported if not NULL and input/output configuration unsupported, use XAPOFree to free structure, left untouched on any failure except XAPO_E_FORMAT_UNSUPPORTED + // ppSupportedOutputFormat - [out] receives pointer to nearest output format supported if not nil and input/output configuration unsupported, use XAPOFree to free structure, left untouched on any failure except FORMAT_UNSUPPORTED // RETURN VALUE: // COM error code, including: // S_OK - input/output configuration supported, ppSupportedOutputFormat left untouched - // FORMAT_UNSUPPORTED - input/output configuration unsupported, ppSupportedOutputFormat receives pointer to nearest output format supported if not NULL + // FORMAT_UNSUPPORTED - input/output configuration unsupported, ppSupportedOutputFormat receives pointer to nearest output format supported if not nil // E_INVALIDARG - either audio format invalid, ppSupportedOutputFormat left untouched IsOutputFormatSupported: proc "system" (this: ^IXAPO, pInputFormat: ^WAVEFORMATEX, pRequestedOutputFormat: ^WAVEFORMATEX, ppSupportedOutputFormat: ^^WAVEFORMATEX) -> HRESULT, @@ -246,10 +209,10 @@ IXAPO_VTable :: struct { // The contents of pData are defined by the XAPO. // Immutable variables (constant during the lifespan of the XAPO) should be set once via this method. // Once initialized, an XAPO cannot be initialized again. - // An XAPO should be initialized before passing it to XAudio2 as part of an effect chain. XAudio2 will not call this method; it exists for future content-driven initialization. + // An XAPO should be initialized before passing it to XAudio2 as part of an effect chain. XAudio2 will not call this method; it exists for future content-driven initialization. // PARAMETERS: - // pData - [in] effect-specific initialization parameters, may be NULL if DataByteSize == 0 - // DataByteSize - [in] size of pData in bytes, may be 0 if pData is NULL + // pData - [in] effect-specific initialization parameters, may be nil if DataByteSize == 0 + // DataByteSize - [in] size of pData in bytes, may be 0 if pData is nil // RETURN VALUE: // COM error code Initialize: proc "system" (this: ^IXAPO, pData: rawptr, DataByteSize: u32) -> HRESULT, @@ -279,9 +242,9 @@ IXAPO_VTable :: struct { // Once locked, an XAPO cannot be locked again until UnLockForProcess is called. // PARAMETERS: // InputLockedParameterCount - [in] number of input buffers, must be within [XAPO_REGISTRATION_PROPERTIES.MinInputBufferCount, XAPO_REGISTRATION_PROPERTIES.MaxInputBufferCount] - // pInputLockedParameters - [in] array of input locked buffer parameter structures, may be NULL if InputLockedParameterCount == 0, otherwise must have InputLockedParameterCount elements - // OutputLockedParameterCount - [in] number of output buffers, must be within [XAPO_REGISTRATION_PROPERTIES.MinOutputBufferCount, XAPO_REGISTRATION_PROPERTIES.MaxOutputBufferCount], must match InputLockedParameterCount when XAPO_FLAG_BUFFERCOUNT_MUST_MATCH used - // pOutputLockedParameters - [in] array of output locked buffer parameter structures, may be NULL if OutputLockedParameterCount == 0, otherwise must have OutputLockedParameterCount elements + // pInputLockedParameters - [in] array of input locked buffer parameter structures, may be nil if InputLockedParameterCount == 0, otherwise must have InputLockedParameterCount elements + // OutputLockedParameterCount - [in] number of output buffers, must be within [XAPO_REGISTRATION_PROPERTIES.MinOutputBufferCount, XAPO_REGISTRATION_PROPERTIES.MaxOutputBufferCount], must match InputLockedParameterCount when XAPO_FLAG.BUFFERCOUNT_MUST_MATCH used + // pOutputLockedParameters - [in] array of output locked buffer parameter structures, may be nil if OutputLockedParameterCount == 0, otherwise must have OutputLockedParameterCount elements // RETURN VALUE: // COM error code LockForProcess: proc "system" (this: ^IXAPO, InputLockedParameterCount: u32, pInputLockedParameters: [^]XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS, OutputLockedParameterCount: u32, pOutputLockedParameters: [^]XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS) -> HRESULT, @@ -303,16 +266,16 @@ IXAPO_VTable :: struct { // ppInputProcessParameters will not necessarily be the same as ppOutputProcessParameters for in-place processing, rather the pBuffer members of each will point to the same memory. // Multiple input/output buffers may be used with in-place XAPOs, though the input buffer count must equal the output buffer count. // When multiple input/output buffers are used with in-place XAPOs, the XAPO may assume input buffer [N] equals output buffer [N]. - // When IsEnabled is FALSE, the XAPO should process thru. Thru processing means an XAPO should not apply its normal processing to the given input/output buffers during Process. - // It should instead pass data from input to output with as little modification possible. Effects that perform format conversion should continue to do so. + // When IsEnabled is false, the XAPO should process thru. Thru processing means an XAPO should not apply its normal processing to the given input/output buffers during Process. + // It should instead pass data from input to output with as little modification possible. Effects that perform format conversion should continue to do so. // The effect must ensure transitions between normal and thru processing do not introduce discontinuities into the signal. // XAudio2 calls this method only if the XAPO is locked. This method should not block as it is called from the realtime thread. // PARAMETERS: // InputProcessParameterCount - [in] number of input buffers, matches respective InputLockedParameterCount parameter given to LockForProcess - // pInputProcessParameters - [in] array of input process buffer parameter structures, may be NULL if InputProcessParameterCount == 0, otherwise must have InputProcessParameterCount elements + // pInputProcessParameters - [in] array of input process buffer parameter structures, may be nil if InputProcessParameterCount == 0, otherwise must have InputProcessParameterCount elements // OutputProcessParameterCount - [in] number of output buffers, matches respective OutputLockedParameterCount parameter given to LockForProcess - // pOutputProcessParameters - [in/out] array of output process buffer parameter structures, may be NULL if OutputProcessParameterCount == 0, otherwise must have OutputProcessParameterCount elements - // IsEnabled - [in] TRUE to process normally, FALSE to process thru + // pOutputProcessParameters - [in/out] array of output process buffer parameter structures, may be nil if OutputProcessParameterCount == 0, otherwise must have OutputProcessParameterCount elements + // IsEnabled - [in] true to process normally, false to process thru // RETURN VALUE: // void Process: proc "system" (this: ^IXAPO, InputProcessParameterCount: u32, pInputProcessParameters: [^]XAPO_PROCESS_BUFFER_PARAMETERS, OutputProcessParameterCount: u32, pOutputProcessParameters: [^]XAPO_PROCESS_BUFFER_PARAMETERS, IsEnabled: b32), @@ -358,7 +321,7 @@ IXAPOParameters_VTable :: struct { // This method may only be called on the realtime thread; no synchronization between it and IXAPO.Process is necessary. // This method should not block as it is called from the realtime thread. // PARAMETERS: - // pParameters - [in] effect-specific parameter block, must be != NULL + // pParameters - [in] effect-specific parameter block, must be != nil // ParameterByteSize - [in] size of pParameters in bytes, must be > 0 // RETURN VALUE: // void @@ -369,7 +332,7 @@ IXAPOParameters_VTable :: struct { // REMARKS: // Unlike SetParameters, XAudio2 does not call this method on the realtime thread. Thus, the XAPO must protect variables shared with SetParameters/Process using appropriate synchronization. // PARAMETERS: - // pParameters - [out] receives effect-specific parameter block, must be != NULL + // pParameters - [out] receives effect-specific parameter block, must be != nil // ParameterByteSize - [in] size of pParameters in bytes, must be > 0 // RETURN VALUE: // void diff --git a/vendor/windows/XAudio2/xapofx.odin b/vendor/windows/XAudio2/xapofx.odin index 5c4c8c7ec..5ab9d57a8 100644 --- a/vendor/windows/XAudio2/xapofx.odin +++ b/vendor/windows/XAudio2/xapofx.odin @@ -132,7 +132,7 @@ FXECHO_PARAMETERS :: struct #packed { @(default_calling_convention="cdecl") foreign xa2 { // creates instance of requested XAPO, use Release to free instance - // pInitData - [in] effect-specific initialization parameters, may be NULL if InitDataByteSize == 0 - // InitDataByteSize - [in] size of pInitData in bytes, may be 0 if pInitData is NULL + // pInitData - [in] effect-specific initialization parameters, may be nil if InitDataByteSize == 0 + // InitDataByteSize - [in] size of pInitData in bytes, may be 0 if pInitData is nil CreateFX :: proc(clsid: win.REFCLSID, pEffect: ^^IUnknown, pInitDat: rawptr = nil, InitDataByteSize: u32 = 0) -> HRESULT --- } diff --git a/vendor/windows/XAudio2/xaudio2.odin b/vendor/windows/XAudio2/xaudio2.odin index 078ec4095..6187b63fe 100644 --- a/vendor/windows/XAudio2/xaudio2.odin +++ b/vendor/windows/XAudio2/xaudio2.odin @@ -11,6 +11,8 @@ package windows_xaudio2 import win "core:sys/windows" import "core:math" +foreign import xa2 "system:xaudio2.lib" + HRESULT :: win.HRESULT IUnknown :: win.IUnknown IUnknown_VTable :: win.IUnknown_VTable @@ -93,8 +95,8 @@ DEVICE_INVALIDATED :: HRESULT(-2003435516) // 0x88960004 An audio device be **************************************************************************/ // Used in Create, specifies which CPU(s) to use. -PROCESSOR_FLAGS :: distinct bit_set[PROCESOR_FLAG; u32] -PROCESOR_FLAG :: enum u32 { +PROCESSOR_FLAGS :: distinct bit_set[PROCESSOR_FLAG; u32] +PROCESSOR_FLAG :: enum u32 { Processor1 = 0, Processor2 = 1, Processor3 = 2, @@ -128,7 +130,7 @@ PROCESOR_FLAG :: enum u32 { Processor31 = 30, Processor32 = 31, } - +//ANY_PROCESSOR :: 0xffffffff USE_DEFAULT_PROCESSOR :: PROCESSOR_FLAGS{} // Returned by IXAudio2Voice.GetVoiceDetails @@ -147,8 +149,8 @@ SEND_DESCRIPTOR :: struct #packed { // Used in the voice creation functions and in IXAudio2Voice.SetOutputVoices VOICE_SENDS :: struct #packed { - SendCount: u32, // Number of sends from this voice. - pSends: [^]SEND_DESCRIPTOR, // Array of SendCount send descriptors. + SendCount: u32, // Number of sends from this voice. + pSends: [^]SEND_DESCRIPTOR `fmt:"v,SendCount"`, // Array of SendCount send descriptors. } // Used in EFFECT_CHAIN below @@ -160,8 +162,8 @@ EFFECT_DESCRIPTOR :: struct #packed { // Used in the voice creation functions and in IXAudio2Voice.SetEffectChain EFFECT_CHAIN :: struct #packed { - EffectCount: u32, // Number of effects in this voice's effect chain. - pEffectDescriptors: [^]EFFECT_DESCRIPTOR, // Array of effect descriptors. + EffectCount: u32, // Number of effects in this voice's effect chain. + pEffectDescriptors: [^]EFFECT_DESCRIPTOR `fmt:"v,EffectCount"`, // Array of effect descriptors. } // Used in FILTER_PARAMETERS below @@ -183,28 +185,28 @@ FILTER_PARAMETERS :: struct #packed { // Used in IXAudio2SourceVoice.SubmitSourceBuffer BUFFER :: struct #packed { - Flags: FLAGS, // Either 0 or END_OF_STREAM. - AudioBytes: u32, // Size of the audio data buffer in bytes. - pAudioData: [^]byte, // Pointer to the audio data buffer. - PlayBegin: u32, // First sample in this buffer to be played. - PlayLength: u32, // Length of the region to be played in samples, or 0 to play the whole buffer. - LoopBegin: u32, // First sample of the region to be looped. - LoopLength: u32, // Length of the desired loop region in samples, or 0 to loop the entire buffer. - LoopCount: u32, // Number of times to repeat the loop region, or LOOP_INFINITE to loop forever. - pContext: rawptr, // Context value to be passed back in callbacks. + Flags: FLAGS, // Either 0 or END_OF_STREAM. + AudioBytes: u32, // Size of the audio data buffer in bytes. + pAudioData: [^]byte `fmt:"v,AudioBytes"`, // Pointer to the audio data buffer. + PlayBegin: u32, // First sample in this buffer to be played. + PlayLength: u32, // Length of the region to be played in samples, or 0 to play the whole buffer. + LoopBegin: u32, // First sample of the region to be looped. + LoopLength: u32, // Length of the desired loop region in samples, or 0 to loop the entire buffer. + LoopCount: u32, // Number of times to repeat the loop region, or LOOP_INFINITE to loop forever. + pContext: rawptr, // Context value to be passed back in callbacks. } // Used in IXAudio2SourceVoice.SubmitSourceBuffer when submitting XWMA data. // NOTE: If an XWMA sound is submitted in more than one buffer, each buffer's pDecodedPacketCumulativeBytes[PacketCount-1] value must be subtracted from all the entries in the next buffer's pDecodedPacketCumulativeBytes array. // And whether a sound is submitted in more than one buffer or not, the final buffer of the sound should use the END_OF_STREAM flag, or else the client must call IXAudio2SourceVoice.Discontinuity after submitting it. BUFFER_WMA :: struct #packed { - pDecodedPacketCumulativeBytes: [^]u32, // Decoded packet's cumulative size array. Each element is the number of bytes accumulated when the corresponding XWMA packet is decoded in order. The array must have PacketCount elements. - PacketCount: u32, // Number of XWMA packets submitted. Must be >= 1 and divide evenly into BUFFER.AudioBytes. + pDecodedPacketCumulativeBytes: [^]u32 `fmt:"v,PacketCount"`, // Decoded packet's cumulative size array. Each element is the number of bytes accumulated when the corresponding XWMA packet is decoded in order. The array must have PacketCount elements. + PacketCount: u32, // Number of XWMA packets submitted. Must be >= 1 and divide evenly into BUFFER.AudioBytes. } // Returned by IXAudio2SourceVoice.GetState VOICE_STATE :: struct #packed { - pCurrentBufferContext: rawptr, // The pContext value provided in the BUFFER that is currently being processed, or NULL if there are no buffers in the queue. + pCurrentBufferContext: rawptr, // The pContext value provided in the BUFFER that is currently being processed, or nil if there are no buffers in the queue. BuffersQueued: u32, // Number of buffers currently queued on the voice (including the one that is being processed). SamplesPlayed: u64, // Total number of samples produced by the voice since it began processing the current audio stream. If VOICE_NOSAMPLESPLAYED is specified in the call to IXAudio2SourceVoice.GetState, this member will not be calculated, saving CPU. } @@ -336,8 +338,7 @@ IXAudio2_VTable :: struct { StopEngine: proc "system" (this: ^IXAudio2), // NAME: IXAudio2.CommitChanges - // DESCRIPTION: Atomically applies a set of operations previously tagged - // with a given identifier. + // DESCRIPTION: Atomically applies a set of operations previously tagged with a given identifier. // ARGUMENTS: // OperationSet - Identifier of the set of operations to be applied. CommitChanges: proc "system" (this: ^IXAudio2, OperationSet: u32) -> HRESULT, @@ -352,7 +353,7 @@ IXAudio2_VTable :: struct { // DESCRIPTION: Configures XAudio2's debug output (in debug builds only). // ARGUMENTS: // pDebugConfiguration - Structure describing the debug output behavior. - // pReserved - Optional parameter; must be NULL. + // pReserved - Optional parameter; must be nil. SetDebugConfiguration: proc "system" (this: ^IXAudio2, pDebugConfiguration: ^DEBUG_CONFIGURATION, pReserved: rawptr = nil), } @@ -399,8 +400,7 @@ IXAudio2Voice_VTable :: struct { GetVoiceDetails: proc "system" (this: ^IXAudio2Voice, pVoiceDetails: ^VOICE_DETAILS), // NAME: IXAudio2Voice.SetOutputVoices - // DESCRIPTION: Replaces the set of submix/mastering voices that receive - // this voice's output. + // DESCRIPTION: Replaces the set of submix/mastering voices that receive this voice's output. // ARGUMENTS: // pSendList - Optional list of voices this voice should send audio to. SetOutputVoices: proc "system" (this: ^IXAudio2Voice, pSendList: [^]VOICE_SENDS) -> HRESULT, @@ -709,37 +709,15 @@ IXAudio2VoiceCallback_VTable :: struct { * * Flags - Flags specifying the XAudio2 object's behavior. * - * XAudio2Processor - A PROCESSOR_FLAGS value that specifies the hardware threads (Xbox) or processors (Windows) that XAudio2 will use. + * Processor - A PROCESSOR_FLAGS value that specifies the hardware threads (Xbox) or processors (Windows) that XAudio2 will use. * Note that XAudio2 supports concurrent processing on multiple threads, using any combination of PROCESSOR_FLAGS flags. * The values are platform-specific; platform-independent code can use USE_DEFAULT_PROCESSOR to use the default on each platform. * **************************************************************************/ -Create :: proc "stdcall" (ppXAudio2: ^^IXAudio2, Flags: FLAGS = {}, XAudio2Processor: PROCESSOR_FLAGS = {.Processor1}) -> HRESULT { - CreateWithVersionInfoFunc :: #type proc "c" (a0: ^^IXAudio2, a1: FLAGS, a2: PROCESSOR_FLAGS, a3: win.DWORD) -> HRESULT - CreateInfoFunc :: #type proc "c" (a0: ^^IXAudio2, a1: FLAGS, a2: PROCESSOR_FLAGS) -> HRESULT - - dll_Instance: win.HMODULE - create_with_version_info: CreateWithVersionInfoFunc - create_info: CreateInfoFunc - - if dll_Instance == nil { - dll_Instance = win.LoadLibraryExW(win.L("xaudio2_9.dll"), nil, {.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS}) - if dll_Instance == nil { - return HRESULT(win.GetLastError()) - } - create_with_version_info = cast(CreateWithVersionInfoFunc)win.GetProcAddress(dll_Instance, "XAudio2CreateWithVersionInfo") - if create_with_version_info == nil { - create_info = cast(CreateInfoFunc)win.GetProcAddress(dll_Instance, "XAudio2Create") - if create_info == nil { - return HRESULT(win.GetLastError()) - } - } - } - if create_with_version_info != nil { - return create_with_version_info(ppXAudio2, Flags, XAudio2Processor, 0x0A000010) - } - return create_info(ppXAudio2, Flags, XAudio2Processor) +@(default_calling_convention="system", link_prefix="XAudio2") +foreign xa2 { + Create :: proc(ppXaudio2: ^^IXAudio2, Flags: FLAGS = {}, Processor: PROCESSOR_FLAGS = {.Processor1}) -> HRESULT --- } /************************************************************************** @@ -749,12 +727,12 @@ Create :: proc "stdcall" (ppXAudio2: ^^IXAudio2, Flags: FLAGS = {}, XAudio2Proce **************************************************************************/ // Calculate the argument to SetVolume from a decibel value -DecibelsToAmplitudeRatio :: proc "contextless" (Decibels: f32) -> f32 { +DecibelsToAmplitudeRatio :: #force_inline proc "contextless" (Decibels: f32) -> f32 { return math.pow_f32(10.0, Decibels / 20.0) } // Recover a volume in decibels from an amplitude factor -AmplitudeRatioToDecibels :: proc "contextless" (Volume: f32) -> f32 { +AmplitudeRatioToDecibels :: #force_inline proc "contextless" (Volume: f32) -> f32 { if Volume == 0 { return min(f32) } @@ -762,14 +740,14 @@ AmplitudeRatioToDecibels :: proc "contextless" (Volume: f32) -> f32 { } // Calculate the argument to SetFrequencyRatio from a semitone value -SemitonesToFrequencyRatio :: proc "contextless" (Semitones: f32) -> f32 { +SemitonesToFrequencyRatio :: #force_inline proc "contextless" (Semitones: f32) -> f32 { // FrequencyRatio = 2 ^ Octaves // = 2 ^ (Semitones / 12) return math.pow_f32(2.0, Semitones / 12.0) } // Recover a pitch in semitones from a frequency ratio -FrequencyRatioToSemitones :: proc "contextless" (FrequencyRatio: f32) -> f32 { +FrequencyRatioToSemitones :: #force_inline proc "contextless" (FrequencyRatio: f32) -> f32 { // Semitones = 12 * log2(FrequencyRatio) // = 12 * log2(10) * log10(FrequencyRatio) return 12.0 * math.log2_f32(FrequencyRatio) @@ -779,7 +757,7 @@ FrequencyRatioToSemitones :: proc "contextless" (FrequencyRatio: f32) -> f32 { // Use CutoffFrequencyToOnePoleCoefficient() for one-pole filter types. // Note that the highest CutoffFrequency supported is SampleRate/6. // Higher values of CutoffFrequency will return MAX_FILTER_FREQUENCY. -CutoffFrequencyToRadians :: proc "contextless" (CutoffFrequency: f32, SampleRate: u32) -> f32 { +CutoffFrequencyToRadians :: #force_inline proc "contextless" (CutoffFrequency: f32, SampleRate: u32) -> f32 { if u32(CutoffFrequency * 6.0) >= SampleRate { return MAX_FILTER_FREQUENCY } @@ -787,14 +765,14 @@ CutoffFrequencyToRadians :: proc "contextless" (CutoffFrequency: f32, SampleRate } // Convert from radian frequencies back to absolute frequencies in Hertz -RadiansToCutoffFrequency :: proc "contextless" (Radians: f32, SampleRate: f32) -> f32 { +RadiansToCutoffFrequency :: #force_inline proc "contextless" (Radians: f32, SampleRate: f32) -> f32 { return SampleRate * math.asin_f32(Radians / 2.0) / math.PI } // Convert from filter cutoff frequencies expressed in Hertz to the filter coefficients used with FILTER_PARAMETERS.Frequency, // LowPassOnePoleFilter and HighPassOnePoleFilter filter types only. // Use CutoffFrequencyToRadians() for state-variable filter types. -CutoffFrequencyToOnePoleCoefficient :: proc "contextless" (CutoffFrequency: f32, SampleRate: u32) -> f32 { +CutoffFrequencyToOnePoleCoefficient :: #force_inline proc "contextless" (CutoffFrequency: f32, SampleRate: u32) -> f32 { if u32(CutoffFrequency) >= SampleRate { return MAX_FILTER_FREQUENCY } diff --git a/vendor/windows/XAudio2/xaudio2fx.odin b/vendor/windows/XAudio2/xaudio2fx.odin index 1449ed4ea..f77cf061d 100644 --- a/vendor/windows/XAudio2/xaudio2fx.odin +++ b/vendor/windows/XAudio2/xaudio2fx.odin @@ -10,8 +10,7 @@ foreign import xa2 "system:xaudio2.lib" * * Effect creation functions. * - * On Xbox the application can link with the debug library to use the debug - * functionality. + * On Xbox the application can link with the debug library to use the debug functionality. * **************************************************************************/ @@ -32,9 +31,9 @@ foreign xa2 { // The user is responsible for allocating pPeakLevels, pRMSLevels, and initializing ChannelCount accordingly. // The volume meter does not support SetEffectParameters(). VOLUMEMETER_LEVELS :: struct #packed { - pPeakLevels: [^]f32 `fmt:"v,ChannelCount"`, // Peak levels table: receives maximum absolute level for each channel over a processing pass, may be NULL if pRMSLevls != NULL, otherwise must have at least ChannelCount elements. - pRMSLevels: [^]f32 `fmt:"v,ChannelCount"`, // Root mean square levels table: receives RMS level for each channel over a processing pass, may be NULL if pPeakLevels != NULL, otherwise must have at least ChannelCount elements. - ChannelCount: u32, // Number of channels being processed by the volume meter APO + pPeakLevels: [^]f32 `fmt:"v,ChannelCount"`, // Peak levels table: receives maximum absolute level for each channel over a processing pass, may be nil if pRMSLevls != nil, otherwise must have at least ChannelCount elements. + pRMSLevels: [^]f32 `fmt:"v,ChannelCount"`, // Root mean square levels table: receives RMS level for each channel over a processing pass, may be nil if pPeakLevels != nil, otherwise must have at least ChannelCount elements. + ChannelCount: u32, // Number of channels being processed by the volume meter APO } /************************************************************************** @@ -87,7 +86,7 @@ REVERB_PARAMETERS :: struct #packed { Density: f32, // [0, 100] (percentage) RoomSize: f32, // [1, 100] in feet // component control - DisableLateField: b32, // TRUE to disable late field reflections + DisableLateField: b32, // true to disable late field reflections } // Maximum, minimum and default values for the parameters above @@ -244,13 +243,13 @@ ReverbConvertI3DL2ToNative :: proc "contextless" (pI3DL2: ^REVERB_I3DL2_PARAMETE if pI3DL2.DecayHFRatio >= 1.0 { index := i32(-4.0 * math.log10_f32(pI3DL2.DecayHFRatio)) - if index < -8 { index = -8 } + if index < -8 do index = -8 pNative.LowEQGain = byte((index < 0) ? index + 8 : 8) pNative.HighEQGain = 8 pNative.DecayTime = pI3DL2.DecayTime * pI3DL2.DecayHFRatio } else { index := i32(4.0 * math.log10_f32(pI3DL2.DecayHFRatio)) - if index < -8 { index = -8 } + if index < -8 do index = -8 pNative.LowEQGain = 8 pNative.HighEQGain = byte((index < 0) ? index + 8 : 8) pNative.DecayTime = pI3DL2.DecayTime |